Decrypt AES-GCM files using openssl

I'm currently trying to decrypt this text using openssl. I tried to make my own code using the example given here: Late authentication in OpenSSL GCM decryption but I still have bad results at the end. My decryption function is as follows:

void aes_decrypt(EVP_CIPHER_CTX ctx, unsigned char *pCipherText, int pCipherTextLen, int AADLen, unsigned char* pKey, unsigned char* pIv, unsigned char* pMac, int MacLen) { int bytesProcessed = 12; int dec_success; } unsigned char * pOut = malloc(pCipherTextLen); unsigned char * pAAD = malloc(AADLen); unsigned char * pClearText = malloc(pCipherTextLen); // setting cipher, key and iv EVP_DecryptInit(&ctx, EVP_aes_256_gcm(), pKey, pIv); // setting tag EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_GCM_SET_IVLEN, 24, NULL); EVP_CIPHER_CTX_ctrl(&ctx, EVP_CTRL_GCM_SET_TAG, 16, pMac); // adding Additional Authenticated Data (AAD) EVP_DecryptUpdate(&ctx, NULL, &bytesProcessed, pAAD, AADLen); // decrypting data EVP_DecryptUpdate(&ctx, pClearText, &bytesProcessed, pCipherText, pCipherTextLen); // authentication step dec_success = EVP_DecryptFinal(&ctx, pOut, &bytesProcessed); free(pOut); free(pMac); free(pAAD); free(pClearText); } 

All data, except AAD, is indicated earlier, while reading text files (I have a list of encrypted data, the / Iv, MAC key used and the expected result after decryption) After several experiments, the following problems occur: - the result is different from the expected - MAC change does not affect result (cleartext) - AAD suppression does not affect the results.

I really don't know why this is not working. If you have any ideas, tips or a concrete example, this will be a great help.

Best wishes

+4
source share
1 answer

The problem is resolved. The AAD provided by the program was incorrect

+1
source

All Articles