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 8b1e96b89d..b846a59553 100644 --- a/test/evp_test.c +++ b/test/evp_test.c @@ -1153,6 +1153,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 */ @@ -1265,6 +1267,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; @@ -1428,6 +1432,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); @@ -1538,6 +1543,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; @@ -1572,6 +1578,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 */ |