summaryrefslogtreecommitdiffstats
path: root/test/evp_test.c
diff options
context:
space:
mode:
authorPauli <pauli@openssl.org>2021-05-24 06:16:44 +0200
committerPauli <pauli@openssl.org>2021-05-25 09:23:50 +0200
commit36b6db08fe3dbb58ba2a45a6170f21b5149dfe26 (patch)
treed690d037fa6ce1a0149f714a0782d41a4da398a2 /test/evp_test.c
parentdoc: document the MAC block size getter (diff)
downloadopenssl-36b6db08fe3dbb58ba2a45a6170f21b5149dfe26.tar.xz
openssl-36b6db08fe3dbb58ba2a45a6170f21b5149dfe26.zip
test: add evp_tests for the MAC size and block size
Reviewed-by: Richard Levitte <levitte@openssl.org> Reviewed-by: Tomas Mraz <tomas@openssl.org> (Merged from https://github.com/openssl/openssl/pull/15427)
Diffstat (limited to 'test/evp_test.c')
-rw-r--r--test/evp_test.c44
1 files changed, 42 insertions, 2 deletions
diff --git a/test/evp_test.c b/test/evp_test.c
index abb0485459..bf4777eb56 100644
--- a/test/evp_test.c
+++ b/test/evp_test.c
@@ -1033,6 +1033,10 @@ typedef struct mac_data_st {
int xof;
/* Collection of controls */
STACK_OF(OPENSSL_STRING) *controls;
+ /* Output size */
+ int output_size;
+ /* Block size */
+ int block_size;
} MAC_DATA;
static int mac_test_init(EVP_TEST *t, const char *alg)
@@ -1076,6 +1080,7 @@ static int mac_test_init(EVP_TEST *t, const char *alg)
mdat->mac_name = OPENSSL_strdup(alg);
mdat->mac = mac;
mdat->controls = sk_OPENSSL_STRING_new_null();
+ mdat->output_size = mdat->block_size = -1;
t->data = mdat;
return 1;
}
@@ -1130,6 +1135,18 @@ static int mac_test_parse(EVP_TEST *t,
if (strcmp(keyword, "Ctrl") == 0)
return sk_OPENSSL_STRING_push(mdata->controls,
OPENSSL_strdup(value)) != 0;
+ if (strcmp(keyword, "OutputSize") == 0) {
+ mdata->output_size = atoi(value);
+ if (mdata->output_size < 0)
+ return -1;
+ return 1;
+ }
+ if (strcmp(keyword, "BlockSize") == 0) {
+ mdata->block_size = atoi(value);
+ if (mdata->block_size < 0)
+ return -1;
+ return 1;
+ }
return 0;
}
@@ -1271,8 +1288,8 @@ static int mac_test_run_mac(EVP_TEST *t)
EVP_MAC_CTX *ctx = NULL;
unsigned char *got = NULL;
size_t got_len;
- int i;
- OSSL_PARAM params[21];
+ int i, block_size = -1, output_size = -1;
+ OSSL_PARAM params[21], sizes[3], *psizes = sizes;
size_t params_n = 0;
size_t params_n_allocstart = 0;
const OSSL_PARAM *defined_params =
@@ -1364,6 +1381,29 @@ static int mac_test_run_mac(EVP_TEST *t)
t->err = "MAC_INIT_ERROR";
goto err;
}
+ if (expected->output_size >= 0)
+ *psizes++ = OSSL_PARAM_construct_int(OSSL_MAC_PARAM_SIZE,
+ &output_size);
+ if (expected->block_size >= 0)
+ *psizes++ = OSSL_PARAM_construct_int(OSSL_MAC_PARAM_BLOCK_SIZE,
+ &block_size);
+ if (psizes != sizes) {
+ *psizes = OSSL_PARAM_construct_end();
+ if (!TEST_true(EVP_MAC_CTX_get_params(ctx, sizes))) {
+ t->err = "INTERNAL_ERROR";
+ goto err;
+ }
+ if (expected->output_size >= 0
+ && !TEST_int_eq(output_size, expected->output_size)) {
+ t->err = "TEST_FAILURE";
+ goto err;
+ }
+ if (expected->block_size >= 0
+ && !TEST_int_eq(block_size, expected->block_size)) {
+ t->err = "TEST_FAILURE";
+ goto err;
+ }
+ }
if (!EVP_MAC_update(ctx, expected->input, expected->input_len)) {
t->err = "MAC_UPDATE_ERROR";
goto err;