Increase thread safety.

randombytes() doesn't seem to have any real speed disadvantage.

Also makes people who think nonces need to be random happy.
This commit is contained in:
irungentoo 2015-03-29 13:14:13 -04:00
parent 212bbf2129
commit abff19fdcc
No known key found for this signature in database
GPG Key ID: 10349DC9BED89E98

View File

@ -194,19 +194,10 @@ void new_symmetric_key(uint8_t *key)
randombytes(key, crypto_box_KEYBYTES);
}
static uint8_t base_nonce[crypto_box_NONCEBYTES];
static uint8_t nonce_set = 0;
/* Gives a nonce guaranteed to be different from previous ones.*/
void new_nonce(uint8_t *nonce)
{
if (nonce_set == 0) {
random_nonce(base_nonce);
nonce_set = 1;
}
increment_nonce(base_nonce);
memcpy(nonce, base_nonce, crypto_box_NONCEBYTES);
random_nonce(nonce);
}
/* Create a request to peer.