From: bg Date: Wed, 16 Apr 2008 20:51:10 +0000 (+0000) Subject: some minor changes to performance testing code X-Git-Url: https://git.cryptolib.org/?a=commitdiff_plain;h=85b05e7b8648750d0077a74898733536e1b0712f;p=avr-crypto-lib.git some minor changes to performance testing code --- diff --git a/cast5.c b/cast5.c index 34c5a78..204fe30 100644 --- a/cast5.c +++ b/cast5.c @@ -102,7 +102,9 @@ void cast5_init(cast5_ctx_t* s, uint8_t* key, uint8_t keylength){ s->shortkey = (keylength<=80); /* littel endian only! */ memset(&(x[0]), 0 ,16); /* set x to zero */ - memcpy(&(x[0]), key, keylength/8); + if(keylength > 128) + keylength=128; + memcpy(&(x[0]), key, (keylength+7)/8); /* todo: merge a and b and compress the whole stuff */ diff --git a/main-cast5-test.c b/main-cast5-test.c index 8a36b59..514a635 100644 --- a/main-cast5-test.c +++ b/main-cast5-test.c @@ -176,21 +176,25 @@ void test_performance_cast5(void){ cast5_init(&ctx, key, 128); t = stopTimer(); uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); - uart_hexdump(&t, 8); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); startTimer(1); cast5_enc(&ctx, data); t = stopTimer(); uart_putstr_P(PSTR("\r\n\tencrypt time: ")); - uart_hexdump(&t, 8); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); startTimer(1); cast5_dec(&ctx, data); t = stopTimer(); uart_putstr_P(PSTR("\r\n\tdecrypt time: ")); - uart_hexdump(&t, 8); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + uart_putstr_P(PSTR("\r\n")); } diff --git a/main-present-test.c b/main-present-test.c index bcb0e54..a58a6dd 100644 --- a/main-present-test.c +++ b/main-present-test.c @@ -11,7 +11,9 @@ #include "present.h" #include "nessie_bc_test.h" #include "cli.h" +#include "performance_test.h" +#include #include #include @@ -74,6 +76,49 @@ void testrun_self_present(void){ } +void testrun_performance_present(void){ + uint16_t i,c; + uint64_t t; + char str[16]; + uint8_t key[10], data[8]; + present_ctx_t ctx; + + calibrateTimer(); + getOverhead(&c, &i); + uart_putstr_P(PSTR("\r\n\r\n=== benchmark ===")); + utoa(c, str, 10); + uart_putstr_P(PSTR("\r\n\tconst overhead: ")); + uart_putstr(str); + utoa(i, str, 10); + uart_putstr_P(PSTR("\r\n\tinterrupt overhead: ")); + uart_putstr(str); + + memset(key, 0, 10); + memset(data, 0, 8); + + startTimer(1); + present_init(key, 80, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + startTimer(1); + present_enc(data, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tencrypt time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + + startTimer(1); + present_dec(data, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tdecrypt time: ")); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + uart_putstr_P(PSTR("\r\n")); +} + /***************************************************************************** * main * *****************************************************************************/ @@ -89,8 +134,8 @@ int main (void){ uart_putstr(cipher_name); uart_putstr_P(PSTR(")\r\nloaded and running\r\n")); - PGM_P u = PSTR("nessie\0test\0"); - void_fpt v[] = {testrun_nessie_present, testrun_self_present}; + PGM_P u = PSTR("nessie\0test\0performance\0"); + void_fpt v[] = {testrun_nessie_present, testrun_self_present, testrun_performance_present}; while(1){ if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;} diff --git a/main-serpent-test.c b/main-serpent-test.c index b81cb32..801e2b8 100644 --- a/main-serpent-test.c +++ b/main-serpent-test.c @@ -48,7 +48,7 @@ void testrun_nessie_serpent(void){ void testrun_performance_serpent(void){ uint16_t i,c; uint64_t t; - char str[6]; + char str[16]; uint8_t key[32], data[16]; serpent_ctx_t ctx; @@ -69,21 +69,25 @@ void testrun_performance_serpent(void){ serpent_genctx(key, 0, &ctx); t = stopTimer(); uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); - uart_hexdump(&t, 8); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); startTimer(1); serpent_enc(data, &ctx); t = stopTimer(); uart_putstr_P(PSTR("\r\n\tencrypt time: ")); - uart_hexdump(&t, 8); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); startTimer(1); serpent_dec(data, &ctx); t = stopTimer(); uart_putstr_P(PSTR("\r\n\tdecrypt time: ")); - uart_hexdump(&t, 8); + ultoa((unsigned long)t, str, 10); + uart_putstr(str); + uart_putstr_P(PSTR("\r\n")); } /***************************************************************************** diff --git a/present.mk b/present.mk index eba6e78..764acef 100644 --- a/present.mk +++ b/present.mk @@ -7,7 +7,8 @@ BLOCK_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := present.o $(ALGO_NAME)_TEST_BIN := main-present-test.o debug.o uart.o serial-tools.o \ - present.o nessie_bc_test.o nessie_common.o cli.o + present.o nessie_bc_test.o nessie_common.o cli.o \ + performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance"