Add rc2 ciphers to default provider
[openssl.git] / test / evp_test.c
index 04519545f1051692a680d04650c6958fb10121e2..d6f852913c47cfff1ba360805906c9e348c3a365 100644 (file)
@@ -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