SEC: move SHA-1 benchmark into generic file.
authorrasky <rasky@38d2e660-2303-0410-9eaa-f027e97ec537>
Fri, 24 Sep 2010 13:08:47 +0000 (13:08 +0000)
committerrasky <rasky@38d2e660-2303-0410-9eaa-f027e97ec537>
Fri, 24 Sep 2010 13:08:47 +0000 (13:08 +0000)
git-svn-id: https://src.develer.com/svnoss/bertos/trunk@4297 38d2e660-2303-0410-9eaa-f027e97ec537

bertos/sec/benchmarks.c [new file with mode: 0644]
bertos/sec/benchmarks.h [new file with mode: 0644]
bertos/sec/hash/sha1.c

diff --git a/bertos/sec/benchmarks.c b/bertos/sec/benchmarks.c
new file mode 100644 (file)
index 0000000..f5fbd79
--- /dev/null
@@ -0,0 +1,24 @@
+#include "benchmarks.h"
+#include <sec/hash.h>
+#include <drv/timer.h>
+#include <string.h>
+
+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) {
+               hash_begin(h);
+               for (int i=0; i<numk*2; ++i)
+                       hash_update(h, buf, 512);
+               hash_final(h);
+       }
+
+       t = timer_clock() - t;
+
+       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));
+}
diff --git a/bertos/sec/benchmarks.h b/bertos/sec/benchmarks.h
new file mode 100644 (file)
index 0000000..e6fc789
--- /dev/null
@@ -0,0 +1,8 @@
+#ifndef SEC_BENCHMARKS_H
+#define SEC_BENCHMARKS_H
+
+#include <sec/hash.h>
+
+void hash_benchmark(Hash *h, const char *hname, int numk);
+
+#endif /* SEC_BENCHMARKS_H */
index d9dc5c860764cf5b3fc080263e320c4b40342db2..0f0aba50fdff5d8ae10b849c5b2afeaf2841e01a 100644 (file)
@@ -254,46 +254,3 @@ void SHA1_init(SHA1_Context* ctx)
        ctx->h.update = SHA1_update;
        ctx->h.final = SHA1_final;
 }
-
-#include <drv/timer.h>
-
-void SHA1_benchmark(int numk)
-{
-       SHA1_Context context;
-       SHA1_init(&context);
-
-       static uint8_t buf[512];
-       memset(buf, 0x12, sizeof(buf));
-
-       ticks_t t = timer_clock();
-
-       for (int j=0;j<64;++j) {
-               SHA1_begin(&context.h);
-               for (int i=0; i<numk*2; ++i)
-                       SHA1_update(&context.h, buf, 512);
-               SHA1_final(&context.h);
-       }
-
-       t = timer_clock() - t;
-
-       utime_t usec = ticks_to_us(t) / 64;
-       kprintf("%s @ %dMhz: SHA1 of %dKiB of data: %lu.%lu ms\n", CPU_CORE_NAME, CPU_FREQ/1000000, numk, (usec/1000), (usec % 1000));
-}
-
-#if 0
-/*
-Test Vectors (from FIPS PUB 180-1)
-"abc"
-  A9993E36 4706816A BA3E2571 7850C26C 9CD0D89D
-"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq"
-  84983E44 1C3BD26E BAAE4AA1 F95129E5 E54670F1
-A million repetitions of "a"
-  34AA973C D4C4DAA4 F61EEB2B DBAD2731 6534016F
-*/
-
-int main(int argc, char** argv)
-{
-       SHA1_test();
-}
-
-#endif