mirror of
https://github.com/jedisct1/libsodium.git
synced 2026-08-25 08:37:13 +09:00
Decryption functions can now accept a NULL pointer for the output
This checks the MAC without writing the decrypted message.
This commit is contained in:
@@ -787,9 +787,14 @@ crypto_aead_aes256gcm_decrypt_detached_afternm(unsigned char *m, unsigned char *
|
||||
d |= (mac[i] ^ (T[i] ^ accum[15 - i]));
|
||||
}
|
||||
if (d != 0) {
|
||||
memset(m, 0, mlen);
|
||||
if (m != NULL) {
|
||||
memset(m, 0, mlen);
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
if (m == NULL) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
n2[3] = 0U;
|
||||
COUNTER_INC2(n2);
|
||||
|
||||
@@ -198,6 +198,9 @@ crypto_aead_chacha20poly1305_decrypt_detached(unsigned char *m,
|
||||
(void) sizeof(int[sizeof computed_mac == 16U ? 1 : -1]);
|
||||
ret = crypto_verify_16(computed_mac, mac);
|
||||
sodium_memzero(computed_mac, sizeof computed_mac);
|
||||
if (m == NULL) {
|
||||
return ret;
|
||||
}
|
||||
if (ret != 0) {
|
||||
memset(m, 0, mlen);
|
||||
return -1;
|
||||
@@ -279,6 +282,9 @@ crypto_aead_chacha20poly1305_ietf_decrypt_detached(unsigned char *m,
|
||||
(void) sizeof(int[sizeof computed_mac == 16U ? 1 : -1]);
|
||||
ret = crypto_verify_16(computed_mac, mac);
|
||||
sodium_memzero(computed_mac, sizeof computed_mac);
|
||||
if (m == NULL) {
|
||||
return ret;
|
||||
}
|
||||
if (ret != 0) {
|
||||
memset(m, 0, mlen);
|
||||
return -1;
|
||||
|
||||
@@ -96,6 +96,9 @@ crypto_secretbox_open_detached(unsigned char *m, const unsigned char *c,
|
||||
sodium_memzero(subkey, sizeof subkey);
|
||||
return -1;
|
||||
}
|
||||
if (m == NULL) {
|
||||
return 0;
|
||||
}
|
||||
if (((uintptr_t) c >= (uintptr_t) m &&
|
||||
(uintptr_t) c - (uintptr_t) m < clen) ||
|
||||
((uintptr_t) m >= (uintptr_t) c &&
|
||||
|
||||
Reference in New Issue
Block a user