Get rid of the diversity of names for MAC parameters
[openssl.git] / test / evp_test.c
index 2dfa8d0..17b9fc0 100644 (file)
@@ -1163,11 +1163,29 @@ static int mac_test_run_mac(EVP_TEST *t)
     }
 #endif
 
-    if (expected->alg != NULL)
-        params[params_n++] =
-            OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_ALGORITHM,
-                                             expected->alg,
-                                             strlen(expected->alg) + 1);
+    if (expected->alg != NULL) {
+        /*
+         * The underlying algorithm may be a cipher or a digest.
+         * We don't know which it is, but we can ask the MAC what it
+         * should be and bet on that.
+         */
+        if (OSSL_PARAM_locate_const(defined_params,
+                                    OSSL_MAC_PARAM_CIPHER) != NULL) {
+            params[params_n++] =
+                OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_CIPHER,
+                                                 expected->alg,
+                                                 strlen(expected->alg) + 1);
+        } else if (OSSL_PARAM_locate_const(defined_params,
+                                           OSSL_MAC_PARAM_DIGEST) != NULL) {
+            params[params_n++] =
+                OSSL_PARAM_construct_utf8_string(OSSL_MAC_PARAM_DIGEST,
+                                                 expected->alg,
+                                                 strlen(expected->alg) + 1);
+        } else {
+            t->err = "MAC_BAD_PARAMS";
+            goto err;
+        }
+    }
     if (expected->key != NULL)
         params[params_n++] =
             OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_KEY,