From: rasky Date: Tue, 28 Sep 2010 18:36:03 +0000 (+0000) Subject: SEC: add function to benchmark a PRNG. X-Git-Tag: 2.6.0~62 X-Git-Url: https://codewiz.org/gitweb?a=commitdiff_plain;h=d49cf5d4b33cdefaa113ec88d83ac832de179554;p=bertos.git SEC: add function to benchmark a PRNG. git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4339 38d2e660-2303-0410-9eaa-f027e97ec537 --- diff --git a/bertos/sec/benchmarks.c b/bertos/sec/benchmarks.c index f5fbd79b..afe72751 100644 --- a/bertos/sec/benchmarks.c +++ b/bertos/sec/benchmarks.c @@ -3,11 +3,11 @@ #include #include +static uint8_t buf[512]; + void hash_benchmark(Hash *h, const char *hname, int numk) { - static uint8_t buf[512]; memset(buf, 0x12, sizeof(buf)); - ticks_t t = timer_clock(); for (int j=0;j<64;++j) { @@ -22,3 +22,26 @@ void hash_benchmark(Hash *h, const char *hname, int numk) utime_t usec = ticks_to_us(t) / 64; kprintf("%s @ %ldMhz: %s of %dKiB of data: %lu.%lu ms\n", CPU_CORE_NAME, CPU_FREQ/1000000, hname, numk, (usec/1000), (usec % 1000)); } + +void prng_benchmark(PRNG *prng, const char *hname, int numbytes) +{ + memset(buf, 0x12, sizeof(buf)); + + ASSERT(sizeof(buf) >= prng_seed_len(prng)); + prng_reseed(prng, buf); + + ticks_t t = timer_clock(); + + for (int j=0;j<2048;++j) { + for (int i=0; i<(numbytes+511)/512-1; ++i) + prng_generate(prng, buf, 512); + prng_generate(prng, buf, numbytes%512); + } + + t = timer_clock() - t; + + utime_t usec = ticks_to_us(t) / 2048; + kprintf("%s @ %ldMhz: %s generation of %d random bytes: %lu.%lu ms\n", CPU_CORE_NAME, CPU_FREQ/1000000, hname, numbytes, (usec/1000), (usec % 1000)); + kprintf("Sample of random data:\n"); + kdump(buf, MIN(numbytes, 64)); +} diff --git a/bertos/sec/benchmarks.h b/bertos/sec/benchmarks.h index e6fc789a..47f45ffe 100644 --- a/bertos/sec/benchmarks.h +++ b/bertos/sec/benchmarks.h @@ -2,7 +2,9 @@ #define SEC_BENCHMARKS_H #include +#include void hash_benchmark(Hash *h, const char *hname, int numk); +void prng_benchmark(PRNG *prng, const char *hname, int numk); #endif /* SEC_BENCHMARKS_H */