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

Don't hardcode the AEGIS tag length

This commit is contained in:
Frank Denis 2023-09-11 17:38:29 +02:00
parent 2a63dcb04f
commit b7ac85b5b7
2 changed files with 11 additions and 9 deletions

View File

@ -70,7 +70,7 @@ crypto_aead_aegis128l_encrypt(unsigned char *c, unsigned long long *clen_p, cons
k); k);
if (clen_p != NULL) { if (clen_p != NULL) {
if (ret == 0) { if (ret == 0) {
clen = mlen + 16ULL; clen = mlen + crypto_aead_aegis128l_ABYTES;
} }
*clen_p = clen; *clen_p = clen;
} }
@ -86,13 +86,14 @@ crypto_aead_aegis128l_decrypt(unsigned char *m, unsigned long long *mlen_p, unsi
unsigned long long mlen = 0ULL; unsigned long long mlen = 0ULL;
int ret = -1; int ret = -1;
if (clen >= 16ULL) { if (clen >= crypto_aead_aegis128l_ABYTES) {
ret = crypto_aead_aegis128l_decrypt_detached(m, nsec, c, clen - 16ULL, c + clen - 16ULL, ad, ret = crypto_aead_aegis128l_decrypt_detached(
adlen, npub, k); m, nsec, c, clen - crypto_aead_aegis128l_ABYTES,
c + clen - crypto_aead_aegis128l_ABYTES, ad, adlen, npub, k);
} }
if (mlen_p != NULL) { if (mlen_p != NULL) {
if (ret == 0) { if (ret == 0) {
mlen = clen - 16ULL; mlen = clen - crypto_aead_aegis128l_ABYTES;
} }
*mlen_p = mlen; *mlen_p = mlen;
} }

View File

@ -70,7 +70,7 @@ crypto_aead_aegis256_encrypt(unsigned char *c, unsigned long long *clen_p, const
crypto_aead_aegis256_encrypt_detached(c, c + mlen, NULL, m, mlen, ad, adlen, nsec, npub, k); crypto_aead_aegis256_encrypt_detached(c, c + mlen, NULL, m, mlen, ad, adlen, nsec, npub, k);
if (clen_p != NULL) { if (clen_p != NULL) {
if (ret == 0) { if (ret == 0) {
clen = mlen + 16ULL; clen = mlen + crypto_aead_aegis256_ABYTES;
} }
*clen_p = clen; *clen_p = clen;
} }
@ -86,13 +86,14 @@ crypto_aead_aegis256_decrypt(unsigned char *m, unsigned long long *mlen_p, unsig
unsigned long long mlen = 0ULL; unsigned long long mlen = 0ULL;
int ret = -1; int ret = -1;
if (clen >= 16ULL) { if (clen >= crypto_aead_aegis256_ABYTES) {
ret = crypto_aead_aegis256_decrypt_detached(m, nsec, c, clen - 16ULL, c + clen - 16ULL, ad, ret = crypto_aead_aegis256_decrypt_detached(m, nsec, c, clen - crypto_aead_aegis256_ABYTES,
c + clen - crypto_aead_aegis256_ABYTES, ad,
adlen, npub, k); adlen, npub, k);
} }
if (mlen_p != NULL) { if (mlen_p != NULL) {
if (ret == 0) { if (ret == 0) {
mlen = clen - 16ULL; mlen = clen - crypto_aead_aegis256_ABYTES;
} }
*mlen_p = mlen; *mlen_p = mlen;
} }