summaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorShane Lontis <shane.lontis@oracle.com>2019-10-08 16:42:28 +1000
committerShane Lontis <shane.lontis@oracle.com>2019-10-08 16:42:28 +1000
commitf816aa47ac140c3d083416aa9c1c396096d9a92c (patch)
tree4f05808fdef6fe5a921b00739a31f8e79f8ac403 /test
parent089cb623be76b88a1eea6fcd135101037661bbc3 (diff)
Add rc2 ciphers to default provider
Reviewed-by: Richard Levitte <levitte@openssl.org> (Merged from https://github.com/openssl/openssl/pull/9991)
Diffstat (limited to 'test')
-rw-r--r--test/evp_test.c17
-rw-r--r--test/recipes/30-test_evp.t3
-rw-r--r--test/recipes/30-test_evp_data/evpciph_rc2.txt107
3 files changed, 127 insertions, 0 deletions
diff --git a/test/evp_test.c b/test/evp_test.c
index 04519545f1..d6f852913c 100644
--- a/test/evp_test.c
+++ b/test/evp_test.c
@@ -485,6 +485,7 @@ typedef struct cipher_data_st {
int aead;
unsigned char *key;
size_t key_len;
+ size_t key_bits; /* Used by RC2 */
unsigned char *iv;
unsigned int rounds;
size_t iv_len;
@@ -573,6 +574,13 @@ static int cipher_test_parse(EVP_TEST *t, const char *keyword,
return parse_bin(value, &cdat->plaintext, &cdat->plaintext_len);
if (strcmp(keyword, "Ciphertext") == 0)
return parse_bin(value, &cdat->ciphertext, &cdat->ciphertext_len);
+ if (strcmp(keyword, "KeyBits") == 0) {
+ i = atoi(value);
+ if (i < 0)
+ return -1;
+ cdat->key_bits = (size_t)i;
+ return 1;
+ }
if (cdat->aead) {
if (strcmp(keyword, "AAD") == 0) {
for (i = 0; i < AAD_NUM; i++) {
@@ -704,10 +712,19 @@ static int cipher_test_enc(EVP_TEST *t, int enc,
t->err = "INVALID_KEY_LENGTH";
goto err;
}
+ if (expected->key_bits > 0) {
+ int bits = (int)expected->key_bits;
+
+ if (!EVP_CIPHER_CTX_ctrl(ctx, EVP_CTRL_SET_RC2_KEY_BITS, bits, NULL)) {
+ t->err = "INVALID KEY BITS";
+ goto err;
+ }
+ }
if (!EVP_CipherInit_ex(ctx, NULL, NULL, expected->key, expected->iv, -1)) {
t->err = "KEY_SET_ERROR";
goto err;
}
+
/* Check that we get the same IV back */
if (expected->iv != NULL
&& (EVP_CIPHER_flags(expected->cipher) & EVP_CIPH_CUSTOM_IV) == 0
diff --git a/test/recipes/30-test_evp.t b/test/recipes/30-test_evp.t
index 7ff3a14e3e..6a2c696164 100644
--- a/test/recipes/30-test_evp.t
+++ b/test/recipes/30-test_evp.t
@@ -56,6 +56,9 @@ push @defltfiles, @rc4files unless disabled("rc4");
my @rc5files = qw( evpciph_rc5.txt );
push @defltfiles, @rc5files unless disabled("rc5");
+my @rc2files = qw( evpciph_rc2.txt );
+push @defltfiles, @rc2files unless disabled("rc2");
+
plan tests =>
($no_fips ? 0 : 1) # FIPS install test
+ (scalar(@configs) * scalar(@files))
diff --git a/test/recipes/30-test_evp_data/evpciph_rc2.txt b/test/recipes/30-test_evp_data/evpciph_rc2.txt
new file mode 100644
index 0000000000..fd82a1ce11
--- /dev/null
+++ b/test/recipes/30-test_evp_data/evpciph_rc2.txt
@@ -0,0 +1,107 @@
+#
+# Copyright 2019 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
+# in the file LICENSE in the source distribution or at
+# https://www.openssl.org/source/license.html
+
+# A valid set of RC2 test vectors could not be found for all RC2 modes - the
+# following values were generated using the deprecated cipher code, in order to
+# confirm that the new provider code is equivalent.
+Title = RC2 Test vectors
+
+Cipher = RC2-ECB
+Key = 0000000000000000
+Plaintext = 000102030405060708090A0B0C0D0E0F
+Ciphertext = a4085a9f3e710563ae3b1e8c4339122b
+
+Cipher = RC2-ECB
+Key = 0000000000000000
+KeyBits = 63
+Plaintext = 000102030405060708090A0B0C0D0E0F
+Ciphertext = b406b9037baf2d86982af542e6d70b13
+
+Cipher = RC2-CBC
+Key = 0000000000000000
+IV = 0000000000000000
+Plaintext = 000102030405060708090A0B0C0D0E0F
+Ciphertext = a4085a9f3e710563d1091a1552ba8962
+
+Cipher = RC2-CBC
+Key = 0000000000000000
+KeyBits = 63
+IV = 0000000000000000
+Plaintext = 000102030405060708090A0B0C0D0E0F
+Ciphertext = b406b9037baf2d866614ef5e55e95b8d
+
+Cipher = RC2-40-CBC
+Key = 0000000000
+IV = 0000000000000000
+Plaintext = 0102030405060708
+Ciphertext = 61ae28bcf59d1f6f
+
+Cipher = RC2-40-CBC
+Key = 0000000000
+KeyBits = 63
+IV = 0000000000000000
+Plaintext = 0102030405060708
+Ciphertext = c1d8e65290b2f06d
+
+Cipher = RC2-40-CBC
+Key = 000000000001
+IV = 0000000000000000
+Plaintext = 0102030405060708
+Ciphertext = b3ddf36b5c81b0db
+
+Cipher = RC2-64-CBC
+Key = 0000000000000000
+IV = 0000000000000000
+Plaintext = 0102030405060708
+Ciphertext = 191d1abf767bfbe7
+
+Cipher = RC2-64-CBC
+Key = 0000000000000000
+KeyBits = 63
+IV = 0000000000000000
+Plaintext = 0102030405060708
+Ciphertext = 191d1abf767bfbe7
+
+Cipher = RC2-CFB
+Key = 0000000000000000
+IV = 0000000000000000
+Plaintext = 000102030405060708090A0B0C0D0E0F
+Ciphertext = 81b5cc4d43119e987a2b526ea152f3fe
+
+Cipher = RC2-CFB
+Key = 0000000000000000
+KeyBits = 63
+IV = 0000000000000000
+Plaintext = 000102030405060708090A0B0C0D0E0F
+Ciphertext = ebb671fa972288f87cb1810b91f2ae39
+
+Cipher = RC2-OFB
+Key = 0000000000000000
+IV = 0000000000000000
+Plaintext = 000102030405060708090A0B0C0D0E0F
+Ciphertext = 81b5cc4d43119e9849bdb7ef7fb35eb7
+
+Cipher = RC2-OFB
+Key = 0000000000000000
+IV = 0000000000000000
+KeyBits = 63
+Plaintext = 000102030405060708090A0B0C0D0E0F
+Ciphertext = ebb671fa972288f8f8587d8069d61d58
+
+Cipher = RC2-OFB
+Key = 0000000000000000
+IV = 000000000000000000
+Plaintext = 000102030405060708090A0B0C0D0E0F
+Result = INVALID_IV_LENGTH
+
+#Variable key length is allowed for RC2
+Cipher = RC2-OFB
+Key = 0000000000000000000000000000000000
+IV = 0000000000000000
+Plaintext = 000102030405060708090A0B0C0D0E0F
+Ciphertext = 1df8d70bb9c66ffc37869d8ed80d796b