Skip to content

Commit

Permalink
Add processing by chunks to mac tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xhanulik committed Mar 22, 2024
1 parent 910bfca commit 2b4c986
Showing 1 changed file with 32 additions and 8 deletions.
40 changes: 32 additions & 8 deletions test/evp_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -1524,6 +1524,7 @@ static int mac_test_run_pkey(EVP_TEST *t)
unsigned char *got = NULL;
size_t got_len;
int i;
size_t input_len, donelen;

/* We don't do XOF mode via PKEY */
if (expected->xof)
Expand Down Expand Up @@ -1593,10 +1594,21 @@ static int mac_test_run_pkey(EVP_TEST *t)
t->err = "EVPPKEYCTXCTRL_ERROR";
goto err;
}
if (!EVP_DigestSignUpdate(mctx, expected->input, expected->input_len)) {
t->err = "DIGESTSIGNUPDATE_ERROR";
goto err;
}
input_len = expected->input_len;
donelen = 0;
do {
size_t current_len = (size_t) data_chunk_size;

if (data_chunk_size == 0 || (size_t) data_chunk_size > input_len)
current_len = input_len;
if (!EVP_DigestSignUpdate(mctx, expected->input + donelen, current_len)) {
t->err = "DIGESTSIGNUPDATE_ERROR";
goto err;
}
donelen += current_len;
input_len -= current_len;
} while (input_len > 0);

if (!EVP_DigestSignFinal(mctx, NULL, &got_len)) {
t->err = "DIGESTSIGNFINAL_LENGTH_ERROR";
goto err;
Expand Down Expand Up @@ -1637,6 +1649,7 @@ static int mac_test_run_mac(EVP_TEST *t)
EVP_MAC_settable_ctx_params(expected->mac);
int xof;
int reinit = 1;
size_t input_len, donelen ;

if (expected->alg == NULL)
TEST_info("Trying the EVP_MAC %s test", expected->mac_name);
Expand Down Expand Up @@ -1783,10 +1796,21 @@ static int mac_test_run_mac(EVP_TEST *t)
}
}
retry:
if (!EVP_MAC_update(ctx, expected->input, expected->input_len)) {
t->err = "MAC_UPDATE_ERROR";
goto err;
}
input_len = expected->input_len;
donelen = 0;
do {
size_t current_len = (size_t) data_chunk_size;

if (data_chunk_size == 0 || (size_t) data_chunk_size > input_len)
current_len = input_len;
if (!EVP_MAC_update(ctx, expected->input + donelen, current_len)) {
t->err = "MAC_UPDATE_ERROR";
goto err;
}
donelen += current_len;
input_len -= current_len;
} while (input_len > 0);

xof = expected->xof;
if (xof) {
if (!TEST_ptr(got = OPENSSL_malloc(expected->output_len))) {
Expand Down

0 comments on commit 2b4c986

Please sign in to comment.