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:
Frank Denis
2016-04-11 18:33:50 +02:00
parent 80310ef56c
commit 0a590b07b2
3 changed files with 15 additions and 1 deletions
@@ -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 &&