Skip to content

Commit

Permalink
ChaCha20, Poly1305 ASM for MSVC
Browse files Browse the repository at this point in the history
Make ChaCha20 and Poly1305 asm available for MSVC.
  • Loading branch information
SparkiDev committed May 1, 2024
1 parent 9d79135 commit aab97fe
Show file tree
Hide file tree
Showing 17 changed files with 3,093 additions and 526 deletions.
3 changes: 3 additions & 0 deletions IDE/WIN/user_settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@
#if 0
#define HAVE_INTEL_AVX2
#endif

#define USE_INTEL_CHACHA_SPEEDUP
#define USE_INTEL_POLY1305_SPEEDUP
#endif

/* Single Precision Support for RSA/DH 1024/2048/3072 and
Expand Down
68 changes: 49 additions & 19 deletions wolfcrypt/benchmark/benchmark.c
Original file line number Diff line number Diff line change
Expand Up @@ -1917,6 +1917,7 @@ static int numBlocks = NUM_BLOCKS;
static word32 bench_size = BENCH_SIZE;
static int base2 = 1;
static int digest_stream = 1;
static int encrypt_only = 0;

#ifdef MULTI_VALUE_STATISTICS
static int minimum_runs = 0;
Expand Down Expand Up @@ -5767,27 +5768,54 @@ void bench_chacha(void)
XMEMSET(enc, 0, sizeof(ChaCha));
wc_Chacha_SetKey(enc, bench_key, 16);

bench_stats_start(&count, &start);
do {
for (i = 0; i < numBlocks; i++) {
ret = wc_Chacha_SetIV(enc, bench_iv, 0);
if (ret < 0) {
printf("wc_Chacha_SetIV error: %d\n", ret);
goto exit;
if (encrypt_only) {
ret = wc_Chacha_SetIV(enc, bench_iv, 0);
if (ret < 0) {
printf("wc_Chacha_SetIV error: %d\n", ret);
goto exit;
}
bench_stats_start(&count, &start);
do {
for (i = 0; i < numBlocks; i++) {
ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
bench_size);
if (ret < 0) {
printf("wc_Chacha_Process error: %d\n", ret);
goto exit;
}
RECORD_MULTI_VALUE_STATS();
}
ret = wc_Chacha_Process(enc, bench_cipher, bench_plain, bench_size);
if (ret < 0) {
printf("wc_Chacha_Process error: %d\n", ret);
goto exit;
count += i;
} while (bench_stats_check(start)
#ifdef MULTI_VALUE_STATISTICS
|| runs < minimum_runs
#endif
);
}
else {
bench_stats_start(&count, &start);
do {
for (i = 0; i < numBlocks; i++) {
ret = wc_Chacha_SetIV(enc, bench_iv, 0);
if (ret < 0) {
printf("wc_Chacha_SetIV error: %d\n", ret);
goto exit;
}
ret = wc_Chacha_Process(enc, bench_cipher, bench_plain,
bench_size);
if (ret < 0) {
printf("wc_Chacha_Process error: %d\n", ret);
goto exit;
}
RECORD_MULTI_VALUE_STATS();
}
RECORD_MULTI_VALUE_STATS();
}
count += i;
} while (bench_stats_check(start)
#ifdef MULTI_VALUE_STATISTICS
|| runs < minimum_runs
#endif
);
count += i;
} while (bench_stats_check(start)
#ifdef MULTI_VALUE_STATISTICS
|| runs < minimum_runs
#endif
);
}

bench_stats_sym_finish("CHACHA", 0, count, bench_size, start, 0);
#ifdef MULTI_VALUE_STATISTICS
Expand Down Expand Up @@ -13419,6 +13447,8 @@ int wolfcrypt_benchmark_main(int argc, char** argv)
#endif
else if (string_matches(argv[1], "-dgst_full"))
digest_stream = 0;
else if (string_matches(argv[1], "-enc_only"))
encrypt_only = 1;
#ifndef NO_RSA
else if (string_matches(argv[1], "-rsa_sign"))
rsa_sign_verify = 1;
Expand Down
Loading

0 comments on commit aab97fe

Please sign in to comment.