summaryrefslogtreecommitdiff
path: root/ot_udp.c
diff options
context:
space:
mode:
authorDirk Engling <erdgeist@erdgeist.org>2021-04-20 04:05:50 +0200
committerDirk Engling <erdgeist@erdgeist.org>2021-04-20 04:05:50 +0200
commitb73b3b17ccf02337fb07f5ae78d78c2ff1dc3ccc (patch)
tree1ab5ec163419a5e6d275e0c5841e319c5a24976b /ot_udp.c
parentccef1d0ccd0965ce91b2a439866dc1bd8301883d (diff)
Use arc4random whereever we need strong entropy
Diffstat (limited to 'ot_udp.c')
-rw-r--r--ot_udp.c14
1 files changed, 13 insertions, 1 deletions
diff --git a/ot_udp.c b/ot_udp.c
index 3bf311c..6b455f3 100644
--- a/ot_udp.c
+++ b/ot_udp.c
@@ -29,13 +29,21 @@ static ot_time g_hour_of_the_key;
29 29
30static void udp_generate_rijndael_round_key() { 30static void udp_generate_rijndael_round_key() {
31 uint32_t key[16]; 31 uint32_t key[16];
32#ifdef WANT_ARC4RANDOM
33 arc4random_buf(&key[0], sizeof(key));
34#else
32 key[0] = random(); 35 key[0] = random();
33 key[1] = random(); 36 key[1] = random();
34 key[2] = random(); 37 key[2] = random();
35 key[3] = random(); 38 key[3] = random();
39#endif
36 rijndaelKeySetupEnc128( g_rijndael_round_key, (uint8_t*)key ); 40 rijndaelKeySetupEnc128( g_rijndael_round_key, (uint8_t*)key );
37 41
42#ifdef WANT_ARC4RANDOM
43 g_key_of_the_hour[0] = arc4random();
44#else
38 g_key_of_the_hour[0] = random(); 45 g_key_of_the_hour[0] = random();
46#endif
39 g_hour_of_the_key = g_now_minutes; 47 g_hour_of_the_key = g_now_minutes;
40} 48}
41 49
@@ -46,7 +54,11 @@ static void udp_make_connectionid( uint32_t connid[2], const ot_ip6 remoteip, in
46 if( g_now_minutes + 60 > g_hour_of_the_key ) { 54 if( g_now_minutes + 60 > g_hour_of_the_key ) {
47 g_hour_of_the_key = g_now_minutes; 55 g_hour_of_the_key = g_now_minutes;
48 g_key_of_the_hour[1] = g_key_of_the_hour[0]; 56 g_key_of_the_hour[1] = g_key_of_the_hour[0];
49 g_key_of_the_hour[0] = random(); 57#ifdef WANT_ARC4RANDOM
58 g_key_of_the_hour[0] = arc4random();
59#else
60 g_key_of_the_hour[0] = random();
61#endif
50 } 62 }
51 63
52 memcpy( plain, remoteip, sizeof( plain ) ); 64 memcpy( plain, remoteip, sizeof( plain ) );