diff --git a/include/crypto_error.h b/include/crypto_error.h index 1c771098..85cb3bd0 100644 --- a/include/crypto_error.h +++ b/include/crypto_error.h @@ -76,5 +76,6 @@ #define CRYPTO_LIB_ERR_IV_OUTSIDE_WINDOW (-23) #define CRYPTO_LIB_ERR_NULL_ARSN (-24) #define CRYPTO_LIB_ERR_NULL_SA (-25) +#define CRYPTO_LIB_ERR_ENCRYPTION_ERROR (-26) #endif //_crypto_error_h_ diff --git a/src/src_cryptography/src_libgcrypt/cryptography_interface_libgcrypt.template.c b/src/src_cryptography/src_libgcrypt/cryptography_interface_libgcrypt.template.c index b9567206..49988b8b 100644 --- a/src/src_cryptography/src_libgcrypt/cryptography_interface_libgcrypt.template.c +++ b/src/src_cryptography/src_libgcrypt/cryptography_interface_libgcrypt.template.c @@ -604,6 +604,7 @@ static int32_t cryptography_authenticate(uint8_t* data_out, size_t len_data_out, printf(KRED "ERROR: gcry_mac_setiv error code %d\n" RESET, gcry_error & GPG_ERR_CODE_MASK); printf(KRED "Failure: %s/%s\n", gcry_strsource(gcry_error), gcry_strerror(gcry_error)); status = CRYPTO_LIB_ERROR; + gcry_mac_close(tmp_mac_hd); return status; } } @@ -618,6 +619,7 @@ static int32_t cryptography_authenticate(uint8_t* data_out, size_t len_data_out, gcry_error & GPG_ERR_CODE_MASK); printf(KRED "Failure: %s/%s\n", gcry_strsource(gcry_error), gcry_strerror(gcry_error)); status = CRYPTO_LIB_ERROR; + gcry_mac_close(tmp_mac_hd); return status; } @@ -630,6 +632,7 @@ static int32_t cryptography_authenticate(uint8_t* data_out, size_t len_data_out, printf(KRED "ERROR: gcry_mac_read error code %d\n" RESET, gcry_error & GPG_ERR_CODE_MASK); printf(KRED "Failure: %s/%s\n", gcry_strsource(gcry_error), gcry_strerror(gcry_error)); status = CRYPTO_LIB_ERR_MAC_RETRIEVAL_ERROR; + gcry_mac_close(tmp_mac_hd); return status; } @@ -849,7 +852,7 @@ static int32_t cryptography_aead_encrypt(uint8_t* data_out, size_t len_data_out, { printf(KRED "ERROR: gcry_cipher_encrypt error code %d\n" RESET, gcry_error & GPG_ERR_CODE_MASK); printf(KRED "Failure: %s/%s\n", gcry_strsource(gcry_error), gcry_strerror(gcry_error)); - status = CRYPTO_LIB_ERROR; + status = CRYPTO_LIB_ERR_ENCRYPTION_ERROR; gcry_cipher_close(tmp_hd); return status; } @@ -866,7 +869,7 @@ static int32_t cryptography_aead_encrypt(uint8_t* data_out, size_t len_data_out, - if ( authenticate_bool == CRYPTO_TRUE ) + if (authenticate_bool == CRYPTO_TRUE) { gcry_error = gcry_cipher_gettag(tmp_hd, mac, // tag output @@ -893,8 +896,6 @@ static int32_t cryptography_aead_encrypt(uint8_t* data_out, size_t len_data_out, } gcry_cipher_close(tmp_hd); - - return status; } @@ -1009,6 +1010,5 @@ static int32_t cryptography_aead_decrypt(uint8_t* data_out, size_t len_data_out, } gcry_cipher_close(tmp_hd); - return status; }