intel / isa-l_crypto

Other
275 stars 80 forks source link

How to check if "aes_gcm_dec_128" failed to decrypt ciphertext into plaintext? #115

Closed chenqichang10-10 closed 1 year ago

chenqichang10-10 commented 1 year ago

We plan to use ISA-L crypto AES_128_GCM in HTTP/3 case. Given that a HTTP/3 endpoint receives a AES_128_GCM AEAD-protected packet whose QUIC short packet header DCID(destionation connection ID) field has been modified by an attacker, how to detect this change or fail the AEAD decryption when using aes_gcm_dec_128()?

For BoringSSL, its AES_128_GCM method EVP_AEAD_CTX_open() returns one on success and zero otherwise. So if it returns 0, then the AEAD decryption failed.

isa-l_crypto-2.24.0/include/aes_gcm.h

/**

chenqichang10-10 commented 1 year ago

OK. One can compare the aes_gcm_dec_128()'s output authentication tag against the original authentication tag carried in the received packet to check if the decryption has succeeded.

if (check_data(aead_decrypted_gcm_tag, ciphertext + plaintext_length, MAX_TAG_LEN, "auth tag")) { // decryption has failed }