summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--core/net_crypto.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/core/net_crypto.c b/core/net_crypto.c
index 270c969a..cbca250b 100644
--- a/core/net_crypto.c
+++ b/core/net_crypto.c
@@ -138,14 +138,18 @@ void increment_nonce(uint8_t * nonce)
138 } 138 }
139} 139}
140 140
141/* fill the given nonce with random bytes. 141/* fill the given nonce with random bytes. */
142 TODO: make this more optimized */
143void random_nonce(uint8_t * nonce) 142void random_nonce(uint8_t * nonce)
144{ 143{
145 uint32_t i; 144 uint32_t i, j, r, m = crypto_box_NONCEBYTES / 3, ind = 0;
146 for(i = 0; i < crypto_box_NONCEBYTES; ++i) 145 for(i = 0; i < m; ++i)
147 { 146 {
148 nonce[i] = random_int() % 256; 147 r = ranom_int();
148 for (j = 0; j < 3; j++) {
149 nonce[ind] = r % 1000 % 256;
150 r /= 1000;
151 ++ind;
152 }
149 } 153 }
150} 154}
151 155