diff options
Diffstat (limited to 'test/evp_test.c')
-rw-r--r-- | test/evp_test.c | 39 |
1 files changed, 39 insertions, 0 deletions
diff --git a/test/evp_test.c b/test/evp_test.c index 7a5b9345e0..5aed3cfa8f 100644 --- a/test/evp_test.c +++ b/test/evp_test.c @@ -1133,6 +1133,8 @@ typedef struct mac_data_st { size_t salt_len; /* XOF mode? */ int xof; + /* Reinitialization fails */ + int no_reinit; /* Collection of controls */ STACK_OF(OPENSSL_STRING) *controls; /* Output size */ @@ -1245,6 +1247,8 @@ static int mac_test_parse(EVP_TEST *t, return parse_bin(value, &mdata->output, &mdata->output_len); if (strcmp(keyword, "XOF") == 0) return mdata->xof = 1; + if (strcmp(keyword, "NoReinit") == 0) + return mdata->no_reinit = 1; if (strcmp(keyword, "Ctrl") == 0) return sk_OPENSSL_STRING_push(mdata->controls, OPENSSL_strdup(value)) != 0; @@ -1408,6 +1412,7 @@ static int mac_test_run_mac(EVP_TEST *t) const OSSL_PARAM *defined_params = EVP_MAC_settable_ctx_params(expected->mac); int xof; + int reinit = 1; if (expected->alg == NULL) TEST_info("Trying the EVP_MAC %s test", expected->mac_name); @@ -1518,6 +1523,7 @@ static int mac_test_run_mac(EVP_TEST *t) goto err; } } + retry: if (!EVP_MAC_update(ctx, expected->input, expected->input_len)) { t->err = "MAC_UPDATE_ERROR"; goto err; @@ -1552,6 +1558,39 @@ static int mac_test_run_mac(EVP_TEST *t) goto err; } } + if (reinit--) { + OSSL_PARAM ivparams[2] = { OSSL_PARAM_END, OSSL_PARAM_END }; + int ret; + + /* If the MAC uses IV, we have to set it again */ + if (expected->iv != NULL) { + ivparams[0] = + OSSL_PARAM_construct_octet_string(OSSL_MAC_PARAM_IV, + expected->iv, + expected->iv_len); + ivparams[1] = OSSL_PARAM_construct_end(); + } + ERR_set_mark(); + ret = EVP_MAC_init(ctx, NULL, 0, ivparams); + if (expected->no_reinit) { + if (ret) { + ERR_clear_last_mark(); + t->err = "MAC_REINIT_SHOULD_FAIL"; + goto err; + } + } else if (ret) { + ERR_clear_last_mark(); + OPENSSL_free(got); + got = NULL; + goto retry; + } else { + ERR_clear_last_mark(); + t->err = "MAC_REINIT_ERROR"; + goto err; + } + /* If reinitialization fails, it is unsupported by the algorithm */ + ERR_pop_to_mark(); + } t->err = NULL; /* Test the EVP_Q_mac interface as well */ |