summaryrefslogtreecommitdiff
path: root/core/net_crypto.c
diff options
context:
space:
mode:
authorZack <redwire@riseup.net>2013-07-21 18:35:12 -0230
committerZack <redwire@riseup.net>2013-07-21 18:35:12 -0230
commitc999fb6462af9ca64b4ba70b4daa228331d98e20 (patch)
tree41a59d53d2393c3436bf5a0603ccf6679e420c24 /core/net_crypto.c
parent550725c11a4a1f86a9e9aea13414b2222e82edbb (diff)
Implemented a faster algorithm for generating nonces
Diffstat (limited to 'core/net_crypto.c')
-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