/*
- * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 2019-2021 The OpenSSL Project Authors. All Rights Reserved.
*
* Licensed under the Apache License 2.0 (the "License"). You may not use
* this file except in compliance with the License. You can obtain a copy
&& TEST_true(EVP_EncryptUpdate(ctx, ct, ct_len, gcm_pt,
sizeof(gcm_pt)) > 0)
&& TEST_true(EVP_EncryptFinal_ex(ctx, outbuf, &outlen) > 0)
+ && TEST_int_eq(EVP_CIPHER_CTX_get_tag_length(ctx), 16)
&& TEST_true(EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_AEAD_GET_TAG, 16,
tag) > 0)
&& TEST_true(iv_gen == NULL
- || EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_GET_IV, 12, iv_gen) > 0);
+ || EVP_CIPHER_CTX_get_original_iv(ctx, iv_gen, 12));
EVP_CIPHER_CTX_free(ctx);
return ret;
}
&& TEST_true(EVP_DecryptInit_ex(ctx, EVP_aes_256_gcm(), NULL,
NULL, NULL) > 0)
&& TEST_true(EVP_DecryptInit_ex(ctx, NULL, NULL, gcm_key, iv) > 0)
+ && TEST_int_eq(EVP_CIPHER_CTX_get_tag_length(ctx), 16)
&& TEST_true(EVP_DecryptUpdate(ctx, NULL, &outlen, gcm_aad,
sizeof(gcm_aad)) > 0)
&& TEST_true(EVP_DecryptUpdate(ctx, pt, &ptlen, ct,
&& do_decrypt(gcm_iv, ct, ctlen, tag, taglen);
}
-#ifdef FIPS_MODE
+static int badkeylen_test(void)
+{
+ int ret;
+ EVP_CIPHER_CTX *ctx = NULL;
+ const EVP_CIPHER *cipher;
+
+ ret = TEST_ptr(cipher = EVP_aes_192_gcm())
+ && TEST_ptr(ctx = EVP_CIPHER_CTX_new())
+ && TEST_true(EVP_EncryptInit_ex(ctx, cipher, NULL, NULL, NULL))
+ && TEST_int_le(EVP_CIPHER_CTX_set_key_length(ctx, 2), 0);
+ EVP_CIPHER_CTX_free(ctx);
+ return ret;
+}
+
static int ivgen_test(void)
{
unsigned char iv_gen[16];
return do_encrypt(iv_gen, ct, &ctlen, tag, &taglen)
&& do_decrypt(iv_gen, ct, ctlen, tag, taglen);
}
-#endif /* FIPS_MODE */
int setup_tests(void)
{
ADD_TEST(kat_test);
-#ifdef FIPS_MODE
+ ADD_TEST(badkeylen_test);
ADD_TEST(ivgen_test);
-#endif /* FIPS_MODE */
return 1;
}