mirror of
https://github.com/wolfSSL/wolfssl.git
synced 2025-08-02 20:24:39 +02:00
Added benchmark for the RNG.
This commit is contained in:
@@ -84,6 +84,7 @@
|
|||||||
#ifdef HAVE_NTRU
|
#ifdef HAVE_NTRU
|
||||||
#include "libntruencrypt/ntru_crypto.h"
|
#include "libntruencrypt/ntru_crypto.h"
|
||||||
#endif
|
#endif
|
||||||
|
#include <wolfssl/wolfcrypt/random.h>
|
||||||
|
|
||||||
#if defined(WOLFSSL_MDK_ARM)
|
#if defined(WOLFSSL_MDK_ARM)
|
||||||
extern FILE * wolfSSL_fopen(const char *fname, const char *mode) ;
|
extern FILE * wolfSSL_fopen(const char *fname, const char *mode) ;
|
||||||
@@ -174,6 +175,7 @@ void bench_ed25519KeySign(void);
|
|||||||
void bench_ntru(void);
|
void bench_ntru(void);
|
||||||
void bench_ntruKeyGen(void);
|
void bench_ntruKeyGen(void);
|
||||||
#endif
|
#endif
|
||||||
|
void bench_rng(void);
|
||||||
|
|
||||||
double current_time(int);
|
double current_time(int);
|
||||||
|
|
||||||
@@ -290,6 +292,7 @@ int benchmark_test(void *args)
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bench_rng();
|
||||||
#ifndef NO_AES
|
#ifndef NO_AES
|
||||||
#ifdef HAVE_AES_CBC
|
#ifdef HAVE_AES_CBC
|
||||||
bench_aes(0);
|
bench_aes(0);
|
||||||
@@ -427,6 +430,51 @@ enum BenchmarkBounds {
|
|||||||
static const char blockType[] = "megs"; /* used in printf output */
|
static const char blockType[] = "megs"; /* used in printf output */
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
void bench_rng(void)
|
||||||
|
{
|
||||||
|
int ret, i;
|
||||||
|
double start, total, persec;
|
||||||
|
#ifndef HAVE_LOCAL_RNG
|
||||||
|
WC_RNG rng;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_LOCAL_RNG
|
||||||
|
ret = wc_InitRng(&rng);
|
||||||
|
if (ret < 0) {
|
||||||
|
printf("InitRNG failed\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
start = current_time(1);
|
||||||
|
BEGIN_INTEL_CYCLES
|
||||||
|
|
||||||
|
for(i = 0; i < numBlocks; i++) {
|
||||||
|
ret = wc_RNG_GenerateBlock(&rng, plain, sizeof(plain));
|
||||||
|
if (ret < 0) {
|
||||||
|
printf("wc_RNG_GenerateBlock failed %d\n", ret);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
END_INTEL_CYCLES
|
||||||
|
total = current_time(0) - start;
|
||||||
|
|
||||||
|
persec = 1 / total * numBlocks;
|
||||||
|
#ifdef BENCH_EMBEDDED
|
||||||
|
/* since using kB, convert to MB/s */
|
||||||
|
persec = persec / 1024;
|
||||||
|
#endif
|
||||||
|
printf("RNG %d %s took %5.3f seconds, %8.3f MB/s", numBlocks,
|
||||||
|
blockType, total, persec);
|
||||||
|
SHOW_INTEL_CYCLES
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
|
#ifndef HAVE_LOCAL_RNG
|
||||||
|
wc_FreeRng(&rng);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
#ifndef NO_AES
|
#ifndef NO_AES
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user