}
/* Check that we get the same IV back */
- if (expected->iv != NULL
- && (EVP_CIPHER_flags(expected->cipher) & EVP_CIPH_CUSTOM_IV) == 0
- && !TEST_mem_eq(expected->iv, expected->iv_len,
- EVP_CIPHER_CTX_iv(ctx_base), expected->iv_len)) {
- t->err = "INVALID_IV";
- goto err;
+ if (expected->iv != NULL) {
+ /* Some (e.g., GCM) tests use IVs longer than EVP_MAX_IV_LENGTH. */
+ unsigned char iv[128];
+ if (!TEST_true(EVP_CIPHER_CTX_get_iv_state(ctx_base, iv, sizeof(iv)))
+ || ((EVP_CIPHER_flags(expected->cipher) & EVP_CIPH_CUSTOM_IV) == 0
+ && !TEST_mem_eq(expected->iv, expected->iv_len, iv,
+ expected->iv_len))) {
+ t->err = "INVALID_IV";
+ goto err;
+ }
}
/* Test that the cipher dup functions correctly if it is supported */