Skip to content

Commit

Permalink
ascon-aead: add benchmarking
Browse files Browse the repository at this point in the history
  • Loading branch information
julek-wolfssl committed Dec 23, 2024
1 parent 0893c9e commit 3f44e85
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 2 deletions.
73 changes: 71 additions & 2 deletions wolfcrypt/benchmark/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -673,7 +673,8 @@
#define BENCH_BLAKE2B 0x00008000
#define BENCH_BLAKE2S 0x00010000
#define BENCH_SM3 0x00020000
#define BENCH_ASCON_HASH256 0x00040000
#define BENCH_ASCON_HASH256 0x00040000
#define BENCH_ASCON_AEAD128 0x00080000

/* MAC algorithms. */
#define BENCH_CMAC 0x00000001
Expand Down Expand Up @@ -886,6 +887,9 @@ static const bench_alg bench_cipher_opt[] = {
#endif
#ifndef NO_DES3
{ "-des", BENCH_DES },
#endif
#ifdef HAVE_ASCON
{ "-ascon-aead", BENCH_ASCON_AEAD128 },
#endif
{ NULL, 0 }
};
Expand Down Expand Up @@ -955,7 +959,7 @@ static const bench_alg bench_digest_opt[] = {
{ "-blake2s", BENCH_BLAKE2S },
#endif
#ifdef HAVE_ASCON
{ "-ascon-hash", BENCH_ASCON_HASH256 },
{ "-ascon-hash", BENCH_ASCON_HASH256 },
#endif
{ NULL, 0 }
};
Expand Down Expand Up @@ -3344,6 +3348,10 @@ static void* benchmarks_do(void* args)
#endif
}
#endif
#ifdef HAVE_ASCON
if (bench_all || (bench_cipher_algs & BENCH_ASCON_AEAD128))
bench_ascon_aead();
#endif
#ifndef NO_MD5
if (bench_all || (bench_digest_algs & BENCH_MD5)) {
#ifndef NO_SW_BENCH
Expand Down Expand Up @@ -6104,6 +6112,67 @@ void bench_chacha20_poly1305_aead(void)
}
#endif /* HAVE_CHACHA && HAVE_POLY1305 */

#ifdef HAVE_ASCON

void bench_ascon_aead(void)
{
#define ASCON_AD (byte*)"ADADADADAD"
#define ASCON_AD_SZ XSTR_SIZEOF(ASCON_AD)
double start;
int ret = 0, i, count;
WC_DECLARE_VAR(authTag, byte, ASCON_AEAD128_TAG_SZ, HEAP_HINT);
WC_DECLARE_VAR(enc, wc_AsconAEAD128, 1, HEAP_HINT);
DECLARE_MULTI_VALUE_STATS_VARS()

WC_ALLOC_VAR(authTag, byte, ASCON_AEAD128_TAG_SZ, HEAP_HINT);
XMEMSET(authTag, 0, ASCON_AEAD128_TAG_SZ);

WC_ALLOC_VAR(enc, wc_AsconAEAD128, 1, HEAP_HINT);
XMEMSET(enc, 0, sizeof(wc_AsconAEAD128));

bench_stats_start(&count, &start);
do {
for (i = 0; i < numBlocks; i++) {
ret = wc_AsconAEAD128_Init(enc);
if (ret == 0)
ret = wc_AsconAEAD128_SetKey(enc, bench_key);
if (ret == 0)
ret = wc_AsconAEAD128_SetNonce(enc, bench_iv);
if (ret == 0)
ret = wc_AsconAEAD128_SetAD(enc, ASCON_AD, ASCON_AD_SZ);
if (ret == 0) {
ret = wc_AsconAEAD128_EncryptUpdate(enc, bench_cipher,
bench_plain, bench_size);
}
if (ret == 0)
ret = wc_AsconAEAD128_EncryptFinal(enc, authTag);
wc_AsconAEAD128_Deinit(enc);

if (ret != 0) {
printf("ASCON-AEAD error: %d\n", ret);
goto exit;
}
RECORD_MULTI_VALUE_STATS();
}
count += i;
} while (bench_stats_check(start)
#ifdef MULTI_VALUE_STATISTICS
|| runs < minimum_runs
#endif
);

bench_stats_sym_finish("ASCON-AEAD", 0, count, bench_size, start, ret);
#ifdef MULTI_VALUE_STATISTICS
bench_multi_value_stats(max, min, sum, squareSum, runs);
#endif

exit:

WC_FREE_VAR(authTag, HEAP_HINT);
WC_FREE_VAR(enc, HEAP_HINT);
}

#endif /* HAVE_ASCON */

#ifndef NO_MD5
void bench_md5(int useDeviceID)
Expand Down
1 change: 1 addition & 0 deletions wolfcrypt/benchmark/benchmark.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ void bench_camellia(void);
void bench_sm4_cbc(void);
void bench_sm4_gcm(void);
void bench_sm4_ccm(void);
void bench_ascon_aead(void);
void bench_md5(int useDeviceID);
void bench_sha(int useDeviceID);
void bench_sha224(int useDeviceID);
Expand Down

0 comments on commit 3f44e85

Please sign in to comment.