Skip to content

Commit

Permalink
test/mac: fix the invalid key size used in native k-mac tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pushkarnk committed Sep 13, 2024
1 parent 318fb43 commit 48e5519
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/main/native/c/mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static void set_params(EVP_MAC_CTX *ctx, mac_params *params) {
}
_params[n_params] = OSSL_PARAM_construct_end();
if (0 == EVP_MAC_CTX_set_params(ctx, _params)) {
ERR_print_errors_fp(stdout);
ERR_print_errors_fp(stderr);
}
}

Expand All @@ -55,7 +55,7 @@ mac_context *mac_init(char *algorithm, byte *key, size_t key_length, mac_params
EVP_MAC_CTX *ctx = EVP_MAC_CTX_new(mac);
EVP_MAC_free(mac);
if (NULL == ctx) {
ERR_print_errors_fp(stdout);
ERR_print_errors_fp(stderr);
free_mac_context(new_ctx);
return NULL;
}
Expand All @@ -64,7 +64,7 @@ mac_context *mac_init(char *algorithm, byte *key, size_t key_length, mac_params
set_params(new_ctx->ctx, params);
}
if (0 == EVP_MAC_init(new_ctx->ctx, (const unsigned char*)key, key_length, NULL)) {
ERR_print_errors_fp(stdout);
ERR_print_errors_fp(stderr);
free_mac_context(new_ctx);
return NULL;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/MacTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public void testHMAC_SHA3_512() throws Exception {
@Test
public void testKMAC_128() throws Exception {
runTest("KMAC-128",
new SecretKeySpec(Arrays.copyOfRange(key, 0, 4), "KMAC-128"),
new SecretKeySpec(Arrays.copyOfRange(key, 0, 16), "KMAC-128"),
"KMAC128");
}

Expand Down
4 changes: 2 additions & 2 deletions src/test/native/mac.c
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ static unsigned char data[] =

void run_test(mac_context *ctx) {
if (NULL == ctx) {
printf("FAILED (Couldn't init CMAC)\n");
printf("FAILED (Couldn't init MAC)\n");
}

if(0 == (mac_update(ctx, data, sizeof(data)))) {
Expand Down Expand Up @@ -117,7 +117,7 @@ void test_gmac(OSSL_LIB_CTX *libctx) {

void test_kmac128(OSSL_LIB_CTX *libctx) {
printf("Testing KMAC-128: ");
mac_context *ctx = mac_init("KMAC-128", key, 4, NULL);
mac_context *ctx = mac_init("KMAC-128", key, 16, NULL);
run_test(ctx);
free_mac_context(ctx);
}
Expand Down

0 comments on commit 48e5519

Please sign in to comment.