mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
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:
parent
212bbf2129
commit
abff19fdcc
|
@ -194,19 +194,10 @@ void new_symmetric_key(uint8_t *key)
|
||||||
randombytes(key, crypto_box_KEYBYTES);
|
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.*/
|
/* Gives a nonce guaranteed to be different from previous ones.*/
|
||||||
void new_nonce(uint8_t *nonce)
|
void new_nonce(uint8_t *nonce)
|
||||||
{
|
{
|
||||||
if (nonce_set == 0) {
|
random_nonce(nonce);
|
||||||
random_nonce(base_nonce);
|
|
||||||
nonce_set = 1;
|
|
||||||
}
|
|
||||||
|
|
||||||
increment_nonce(base_nonce);
|
|
||||||
memcpy(nonce, base_nonce, crypto_box_NONCEBYTES);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create a request to peer.
|
/* Create a request to peer.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user