I wrote a library which uses AES-GCM-128 to perform encrypt and decrypt operations. This library uses EVP functions that provide a high level interface to OpenSSL cryptographic functions.

To verify my library implementation is correct or not, I did the below test.

I took already known nonce, key, aad, plain text which I feed into my library and got a cipher text.

Now I feed the same into an online website which gave me a different output.

The cipher text generated by the website is 56d86b2c9932554f473950900f40250f and the cipher text generated by my local implementation is 6ceedef0a0f24a0fcb8f8730288f757d

The interesting thing is that if the IV is of 12 bytes, then I get the same cipher text from online website as well as my implementation. However, if I change the IV to 16 bytes, then I get different cipher text from online website as well as implementation.

I know that Using the IV longer than 96 bits causes an additional GHASH call to convert into 96 bits.

Also, the tag generated by my local implementation is always different from the one generated online even though nonce, key, aad, plain text remains same.

Can some one please help me in understanding this behavior?


1 Answer 1


Forget the other websites for comparison, you can fall into traps of inconsistent codes. Either use the OpenSSL as a comparison or better use the NIST test vectors;

GCM Test Vectors (SP 800-38D)

  • $\begingroup$ But there is no openssl cmdline support for AEAD algorithms. Regarding GCM Test Vectors - it is a good suggestion. Thank you very much. $\endgroup$ Commented Feb 19, 2021 at 11:58
  • 3
    $\begingroup$ @cpp_enthusiast yes the reason is here, however, you can still use the library $\endgroup$
    – kelalaka
    Commented Feb 19, 2021 at 12:05
  • $\begingroup$ If I pass no plain text and only pass the AAD, my EVP_EncryptFinal_ex is returning "0" which is failure. However, when I print the error, it shows no error as "EVP_EncryptFinal_ex failed - OpenSSL error: error:00000000:lib(0):func(0):reason(0)". Any ideas where it might be going wrong? $\endgroup$ Commented Feb 19, 2021 at 13:30
  • $\begingroup$ @cpp_enthusiast that kind of questions are perfect questions for Stack Overflow with encryption, OpenSSL, and c++ tags. When you ask, you should provide a minimal, working, and verifiable code so that one can investigate your problem and you can get a satisfying answer. $\endgroup$
    – kelalaka
    Commented Feb 19, 2021 at 13:36
  • $\begingroup$ Thanks for the Hint. $\endgroup$ Commented Feb 19, 2021 at 13:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.