1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-19 18:15:18 -07:00

Add comments

This commit is contained in:
Frank Denis 2019-01-03 22:28:59 +01:00
parent 32385c6b9a
commit 1647f0d53a
2 changed files with 5 additions and 4 deletions

View File

@ -97,6 +97,7 @@ blake2b_init0(blake2b_state *S)
for (i = 0; i < 8; i++) { for (i = 0; i < 8; i++) {
S->h[i] = blake2b_IV[i]; S->h[i] = blake2b_IV[i];
} }
/* zero everything between .t and .last_node */
memset(S->t, 0, offsetof(blake2b_state, last_node) + sizeof(S->last_node) memset(S->t, 0, offsetof(blake2b_state, last_node) + sizeof(S->last_node)
- offsetof(blake2b_state, t)); - offsetof(blake2b_state, t));
return 0; return 0;
@ -203,7 +204,7 @@ blake2b_init_key(blake2b_state *S, const uint8_t outlen, const void *key,
{ {
uint8_t block[BLAKE2B_BLOCKBYTES]; uint8_t block[BLAKE2B_BLOCKBYTES];
memset(block, 0, BLAKE2B_BLOCKBYTES); memset(block, 0, BLAKE2B_BLOCKBYTES);
memcpy(block, key, keylen); /* keylen cannot be 0 */ memcpy(block, key, keylen); /* key and keylen cannot be 0 */
blake2b_update(S, block, BLAKE2B_BLOCKBYTES); blake2b_update(S, block, BLAKE2B_BLOCKBYTES);
sodium_memzero(block, BLAKE2B_BLOCKBYTES); /* Burn the key from stack */ sodium_memzero(block, BLAKE2B_BLOCKBYTES); /* Burn the key from stack */
} }
@ -249,7 +250,7 @@ blake2b_init_key_salt_personal(blake2b_state *S, const uint8_t outlen,
{ {
uint8_t block[BLAKE2B_BLOCKBYTES]; uint8_t block[BLAKE2B_BLOCKBYTES];
memset(block, 0, BLAKE2B_BLOCKBYTES); memset(block, 0, BLAKE2B_BLOCKBYTES);
memcpy(block, key, keylen); /* keylen cannot be 0 */ memcpy(block, key, keylen); /* key and keylen cannot be 0 */
blake2b_update(S, block, BLAKE2B_BLOCKBYTES); blake2b_update(S, block, BLAKE2B_BLOCKBYTES);
sodium_memzero(block, BLAKE2B_BLOCKBYTES); /* Burn the key from stack */ sodium_memzero(block, BLAKE2B_BLOCKBYTES); /* Burn the key from stack */
} }

View File

@ -63,8 +63,8 @@ crypto_kx_client_session_keys(unsigned char rx[crypto_kx_SESSIONKEYBYTES],
crypto_generichash_final(&h, keys, sizeof keys); crypto_generichash_final(&h, keys, sizeof keys);
sodium_memzero(&h, sizeof h); sodium_memzero(&h, sizeof h);
for (i = 0; i < crypto_kx_SESSIONKEYBYTES; i++) { for (i = 0; i < crypto_kx_SESSIONKEYBYTES; i++) {
rx[i] = keys[i]; rx[i] = keys[i]; /* rx cannot be NULL */
tx[i] = keys[i + crypto_kx_SESSIONKEYBYTES]; tx[i] = keys[i + crypto_kx_SESSIONKEYBYTES]; /* tx cannot be NULL */
} }
sodium_memzero(keys, sizeof keys); sodium_memzero(keys, sizeof keys);