Skip to content

Commit e8492b1

Browse files
committed
Zero the state afetr AES decryption
1 parent 69435b0 commit e8492b1

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/libsodium/crypto_aead/aes256gcm/aesni/aead_aes256gcm_aesni.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,15 +970,19 @@ crypto_aead_aes256gcm_decrypt_detached(unsigned char *m, unsigned char *nsec,
970970
const unsigned char *k)
971971
{
972972
CRYPTO_ALIGN(16) crypto_aead_aes256gcm_state st;
973+
int ret;
973974

974975
PREFETCH_WRITE(m);
975976
PREFETCH_READ(c);
976977
PREFETCH_READ(ad);
977978

978979
crypto_aead_aes256gcm_beforenm(&st, k);
979980

980-
return crypto_aead_aes256gcm_decrypt_detached_afternm(
981+
ret = crypto_aead_aes256gcm_decrypt_detached_afternm(
981982
m, nsec, c, clen, mac, ad, adlen, npub, (const crypto_aead_aes256gcm_state *) &st);
983+
sodium_memzero(&st, sizeof st);
984+
985+
return ret;
982986
}
983987

984988
int

src/libsodium/crypto_aead/aes256gcm/armcrypto/aead_aes256gcm_armcrypto.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -988,15 +988,19 @@ crypto_aead_aes256gcm_decrypt_detached(unsigned char *m, unsigned char *nsec,
988988
const unsigned char *k)
989989
{
990990
CRYPTO_ALIGN(16) crypto_aead_aes256gcm_state st;
991+
int ret;
991992

992993
PREFETCH_WRITE(m);
993994
PREFETCH_READ(c);
994995
PREFETCH_READ(ad);
995996

996997
crypto_aead_aes256gcm_beforenm(&st, k);
997998

998-
return crypto_aead_aes256gcm_decrypt_detached_afternm(
999+
ret = crypto_aead_aes256gcm_decrypt_detached_afternm(
9991000
m, nsec, c, clen, mac, ad, adlen, npub, (const crypto_aead_aes256gcm_state *) &st);
1001+
sodium_memzero(&st, sizeof st);
1002+
1003+
return ret;
10001004
}
10011005

10021006
int

0 commit comments

Comments
 (0)