summaryrefslogtreecommitdiffstats
path: root/test/acvp_test.c
diff options
context:
space:
mode:
authorShane Lontis <shane.lontis@oracle.com>2021-05-27 18:08:53 +1000
committerShane Lontis <shane.lontis@oracle.com>2021-06-01 15:22:30 +1000
commite2311445bbfc9e2a6ff05e467cf13475b058d0a2 (patch)
treefcb1072a80cc78fdaa5dc6685a7d4d0968c21106 /test/acvp_test.c
parentd11dd381c561db5c5144e575ac6db63e07d5507b (diff)
Fix aes cfb1 so that it can operate in bit mode.
The code to handle the cipher operation was already in the provider. It just needed a OSSL_PARAM in order to set this into the algorithm. EVP_CIPHER_CTX_set_flags() has been modified to pass the OSSL_PARAM. Issue reported by Mark Powers from Acumen. Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15496)
Diffstat (limited to 'test/acvp_test.c')
-rw-r--r--test/acvp_test.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/test/acvp_test.c b/test/acvp_test.c
index 339c2fb965..84009193c2 100644
--- a/test/acvp_test.c
+++ b/test/acvp_test.c
@@ -1387,6 +1387,54 @@ err:
return res;
}
+static int aes_cfb1_bits_test(void)
+{
+ int ret = 0;
+ EVP_CIPHER *cipher = NULL;
+ EVP_CIPHER_CTX *ctx = NULL;
+ unsigned char out[16] = { 0 };
+ int outlen;
+ const OSSL_PARAM *params, *p;
+
+ static const unsigned char key[] = {
+ 0x12, 0x22, 0x58, 0x2F, 0x1C, 0x1A, 0x8A, 0x88,
+ 0x30, 0xFC, 0x18, 0xB7, 0x24, 0x89, 0x7F, 0xC0
+ };
+ static const unsigned char iv[] = {
+ 0x05, 0x28, 0xB5, 0x2B, 0x58, 0x27, 0x63, 0x5C,
+ 0x81, 0x86, 0xD3, 0x63, 0x60, 0xB0, 0xAA, 0x2B
+ };
+ static const unsigned char pt[] = {
+ 0xB4
+ };
+ static const unsigned char expected[] = {
+ 0x6C
+ };
+
+ if (!TEST_ptr(cipher = EVP_CIPHER_fetch(libctx, "AES-128-CFB1", "fips=yes")))
+ goto err;
+ if (!TEST_ptr(ctx = EVP_CIPHER_CTX_new()))
+ goto err;
+ if (!TEST_int_gt(EVP_CipherInit_ex(ctx, cipher, NULL, key, iv, 1), 0))
+ goto err;
+ if (!TEST_ptr(params = EVP_CIPHER_CTX_settable_params(ctx))
+ || !TEST_ptr(p = OSSL_PARAM_locate_const(params,
+ OSSL_CIPHER_PARAM_USE_BITS)))
+ goto err;
+ EVP_CIPHER_CTX_set_flags(ctx, EVP_CIPH_FLAG_LENGTH_BITS);
+ if (!TEST_int_gt(EVP_CipherUpdate(ctx, out, &outlen, pt, 7), 0))
+ goto err;
+ if (!TEST_int_eq(outlen, 7))
+ goto err;
+ if (!TEST_mem_eq(out, (outlen + 7) / 8, expected, sizeof(expected)))
+ goto err;
+ ret = 1;
+err:
+ EVP_CIPHER_free(cipher);
+ EVP_CIPHER_CTX_free(ctx);
+ return ret;
+}
+
int setup_tests(void)
{
char *config_file = NULL;
@@ -1411,6 +1459,7 @@ int setup_tests(void)
OSSL_SELF_TEST_set_callback(libctx, self_test_events, &self_test_args);
+ ADD_TEST(aes_cfb1_bits_test);
ADD_ALL_TESTS(cipher_enc_dec_test, OSSL_NELEM(cipher_enc_data));
ADD_ALL_TESTS(aes_ccm_enc_dec_test, OSSL_NELEM(aes_ccm_enc_data));
ADD_ALL_TESTS(aes_gcm_enc_dec_test, OSSL_NELEM(aes_gcm_enc_data));