1
mirror of https://github.com/jedisct1/libsodium.git synced 2024-12-24 04:25:10 -07:00

aegis256: Support mac verification when m is NULL

Signed-off-by: Adrien Gallouët <adrien@gallouet.fr>
This commit is contained in:
Adrien Gallouët 2019-09-12 21:11:07 +00:00
parent f537541a0a
commit 0a31dd5a31
2 changed files with 16 additions and 3 deletions

View File

@ -221,14 +221,22 @@ crypto_aead_aegis256_decrypt_detached(unsigned char *m, unsigned char *nsec, con
memcpy(src, ad + i, adlen & 0xf);
crypto_aead_aegis256_enc(dst, src, state);
}
if (m != NULL) {
for (i = 0ULL; i + 16ULL <= mlen; i += 16ULL) {
crypto_aead_aegis256_dec(m + i, c + i, state);
}
} else {
for (i = 0ULL; i + 16ULL <= mlen; i += 16ULL) {
crypto_aead_aegis256_dec(dst, c + i, state);
}
}
if (mlen & 0xf) {
memset(src, 0, 16);
memcpy(src, c + i, mlen & 0xf);
crypto_aead_aegis256_dec(dst, src, state);
if (m != NULL) {
memcpy(m + i, dst, mlen & 0xf);
}
memset(dst, 0, mlen & 0xf);
state[0] = _mm_xor_si128(state[0], _mm_loadu_si128((__m128i *) dst));
}

View File

@ -2144,6 +2144,11 @@ tv(void)
printf("Verification of test vector #%u with a truncated tag failed\n",
(unsigned int) i);
}
if (i == 0 && crypto_aead_aegis256_decrypt(NULL, NULL,
NULL, ciphertext, ciphertext_len,
ad, ad_len, nonce, key) != 0) {
printf("Verification of test vector #%u's tag failed\n", (unsigned int) i);
}
if (crypto_aead_aegis256_decrypt(decrypted, &found_message_len, NULL, ciphertext,
ciphertext_len, ad, ad_len, nonce, key) != 0) {
printf("Verification of test vector #%u failed\n", (unsigned int) i);