From 2c2d732098455b6ef9e5908ebd75238df0b2bd4c Mon Sep 17 00:00:00 2001 From: bg Date: Fri, 11 Apr 2008 02:52:10 +0000 Subject: [PATCH] +performance tests; some modifications to the Cast5-test-suit --- cast5.mk | 4 +-- main-arcfour-test.c | 1 + main-cast5-test.c | 67 ++++++++++++++++++++++++++++++++++++++------ main-serpent-test.c | 48 +++++++++++++++++++++++++++++-- nessie_common.c | 13 ++++++--- nessie_stream_test.c | 2 +- nessie_stream_test.h | 1 + performance_test.c | 60 +++++++++++++++++++++++++++++++++++++++ performance_test.h | 11 ++++++++ serpent.mk | 2 +- 10 files changed, 189 insertions(+), 20 deletions(-) create mode 100644 performance_test.c create mode 100644 performance_test.h diff --git a/cast5.mk b/cast5.mk index 2969c82..b2b671b 100644 --- a/cast5.mk +++ b/cast5.mk @@ -5,8 +5,8 @@ ALGO_NAME := CAST5 BLOCK_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := cast5.o -$(ALGO_NAME)_TEST_BIN := main-cast5-test.o debug.o uart.o serial-tools.o \ - cast5.o nessie_bc_test.o nessie_common.o +$(ALGO_NAME)_TEST_BIN := main-cast5-test.o debug.o uart.o serial-tools.o cli.o\ + cast5.o nessie_bc_test.o nessie_common.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" diff --git a/main-arcfour-test.c b/main-arcfour-test.c index 0274bd5..74e76e1 100644 --- a/main-arcfour-test.c +++ b/main-arcfour-test.c @@ -28,6 +28,7 @@ void arcfour_genctx_dummy(uint8_t* key, uint16_t keysize, void* ctx){ void testrun_nessie_arcfour(void){ nessie_stream_ctx.outsize_b = 8; /* actually unused */ nessie_stream_ctx.keysize_b = 128; /* this is theone we have refrence vectors for */ + nessie_stream_ctx.ivsize_b = (uint16_t)-1; nessie_stream_ctx.name = cipher_name; nessie_stream_ctx.ctx_size_B = sizeof(arcfour_ctx_t); nessie_stream_ctx.cipher_genctx = (nessie_stream_genctx_fpt)arcfour_genctx_dummy; diff --git a/main-cast5-test.c b/main-cast5-test.c index 6f3b18a..8a36b59 100644 --- a/main-cast5-test.c +++ b/main-cast5-test.c @@ -10,9 +10,12 @@ #include "cast5.h" #include "nessie_bc_test.h" +#include "performance_test.h" +#include "cli.h" #include #include +#include char* cipher_name = "cast-128 (cast5)"; @@ -149,12 +152,54 @@ void testrun_cast5(void){ } - +void test_performance_cast5(void){ + uint16_t i,c; + uint64_t t; + char str[6]; + uint8_t key[16], data[16]; + cast5_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, 16); + memset(data, 0, 16); + + startTimer(1); + cast5_init(&ctx, key, 128); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); + uart_hexdump(&t, 8); + + + startTimer(1); + cast5_enc(&ctx, data); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tencrypt time: ")); + uart_hexdump(&t, 8); + + + startTimer(1); + cast5_dec(&ctx, data); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tdecrypt time: ")); + uart_hexdump(&t, 8); + uart_putstr_P(PSTR("\r\n")); +} /***************************************************************************** * main * *****************************************************************************/ +typedef void(*void_fpt)(void); + int main (void){ char str[20]; @@ -162,17 +207,21 @@ int main (void){ DEBUG_INIT(); uart_putstr("\r\n"); - uart_putstr("\r\n\r\nCrypto-VS\r\nloaded and running\r\n"); -restart: + uart_putstr_P(PSTR("\r\n\r\nCrypto-VS (")); + uart_putstr(cipher_name); + uart_putstr_P(PSTR(")\r\nloaded and running\r\n")); + + PGM_P u = PSTR("nessie\0test\0performance\0"); + void_fpt v[] = {test_nessie_cast5, test_nessie_cast5, test_performance_cast5}; + while(1){ - if (!getnextwordn(str,20)) {DEBUG_S("DBG: W1\r\n"); goto error;} - if (strcmp(str, "nessie")) {DEBUG_S("DBG: 1b\r\n"); goto error;} - // testrun_cast5(); - test_nessie_cast5(); - goto restart; + if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;} + if(execcommand_d0_P(str, u, v)<0){ + uart_putstr_P(PSTR("\r\nunknown command\r\n")); + } continue; error: uart_putstr("ERROR\r\n"); - } /* while (1) */ + } } diff --git a/main-serpent-test.c b/main-serpent-test.c index c05ef17..b81cb32 100644 --- a/main-serpent-test.c +++ b/main-serpent-test.c @@ -11,9 +11,11 @@ #include "serpent.h" #include "nessie_bc_test.h" #include "cli.h" +#include "performance_test.h" #include #include +#include char* cipher_name = "Serpent"; @@ -43,7 +45,47 @@ void testrun_nessie_serpent(void){ } - +void testrun_performance_serpent(void){ + uint16_t i,c; + uint64_t t; + char str[6]; + uint8_t key[32], data[16]; + serpent_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, 32); + memset(data, 0, 16); + + startTimer(1); + serpent_genctx(key, 0, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tctx-gen time: ")); + uart_hexdump(&t, 8); + + + startTimer(1); + serpent_enc(data, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tencrypt time: ")); + uart_hexdump(&t, 8); + + + startTimer(1); + serpent_dec(data, &ctx); + t = stopTimer(); + uart_putstr_P(PSTR("\r\n\tdecrypt time: ")); + uart_hexdump(&t, 8); + uart_putstr_P(PSTR("\r\n")); +} /***************************************************************************** * main * *****************************************************************************/ @@ -59,8 +101,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_serpent, testrun_nessie_serpent}; + PGM_P u = PSTR("nessie\0test\0performance\0"); + void_fpt v[] = {testrun_nessie_serpent, testrun_nessie_serpent, testrun_performance_serpent}; while(1){ if (!getnextwordn(str,20)){DEBUG_S("DBG: W1\r\n"); goto error;} diff --git a/nessie_common.c b/nessie_common.c index 7adac82..b828052 100644 --- a/nessie_common.c +++ b/nessie_common.c @@ -141,10 +141,15 @@ void nessie_print_header(char* name, uart_putstr_P(PSTR(" bits")); } if(ivsize_b){ - uart_putstr_P(PSTR("\r\nIV size: ")); - utoa(ivsize_b, str, 10); - uart_putstr(str); - uart_putstr_P(PSTR(" bits")); + if(ivsize_b==(uint16_t)-1){ + uart_putstr_P(PSTR("\r\nNo initial value (IV) mode")); + } + { + uart_putstr_P(PSTR("\r\nIV size: ")); + utoa(ivsize_b, str, 10); + uart_putstr(str); + uart_putstr_P(PSTR(" bits")); + } } uart_putstr_P(PSTR("\r\n")); } diff --git a/nessie_stream_test.c b/nessie_stream_test.c index 3f7c778..3271d6e 100644 --- a/nessie_stream_test.c +++ b/nessie_stream_test.c @@ -129,7 +129,7 @@ void nessie_stream_run(void){ uint8_t key[(nessie_stream_ctx.keysize_b+7)/8]; nessie_print_header(nessie_stream_ctx.name, nessie_stream_ctx.keysize_b, - 0, 0, 0, 0); + 0, 0, 0, nessie_stream_ctx.ivsize_b); /* test set 1 */ set=1; nessie_print_setheader(set); diff --git a/nessie_stream_test.h b/nessie_stream_test.h index 940fb52..3722798 100644 --- a/nessie_stream_test.h +++ b/nessie_stream_test.h @@ -8,6 +8,7 @@ typedef uint8_t (*nessie_stream_genenc_fpt)(void* ctx); typedef struct nessie_stream_ctx_st{ uint16_t keysize_b; + uint16_t ivsize_b; uint16_t outsize_b; uint16_t ctx_size_B; char* name; diff --git a/performance_test.c b/performance_test.c new file mode 100644 index 0000000..91d4f1c --- /dev/null +++ b/performance_test.c @@ -0,0 +1,60 @@ +/* + * + * + * + */ + +#include +#include +#include +#include +#include "performance_test.h" + +uint32_t ovfcounter; + +uint16_t const_overhead=0; +uint16_t int_overhead=0; + +ISR(TIMER1_OVF_vect){ + ovfcounter++; +} + +void calibrateTimer(void){ + startTimer(1); + stopTimer(); + const_overhead = TCNT1; + startTimer(1); + TCNT1=0xFFFE; + ; ; ; ; +// asm volatile("NOP\n"::); asm volatile("NOP\n"::); + stopTimer(); + int_overhead = TCNT1; +} + +void startTimer(uint8_t granularity){ + TCCR1B = 0; /* stop timer */ + TCNT1 = 0; + ovfcounter = 0; + TCCR1A = 0x00; + TIMSK &= 0xC3; + TIMSK |= _BV(2); /* enable TOIE1 */ + TCCR1B = granularity & 0x7; /* start timer */ +} + +uint64_t stopTimer(void){ + TCCR1B = 0; /* stop timer */ + uint64_t ret; + ret = (ovfcounter<<16) | TCNT1; + ret -= const_overhead; + ret -= ovfcounter * int_overhead; + return ret; +} + +void getOverhead(uint16_t* constoh, uint16_t* intoh){ + *constoh = const_overhead; + *intoh = int_overhead; +} + + + + diff --git a/performance_test.h b/performance_test.h new file mode 100644 index 0000000..2243586 --- /dev/null +++ b/performance_test.h @@ -0,0 +1,11 @@ +#ifndef PERFORMANCE_TEST_H_ +#define PERFORMANCE_TEST_H_ + +#include + +void calibrateTimer(void); +void startTimer(uint8_t granularity); +uint64_t stopTimer(void); +void getOverhead(uint16_t* constoh, uint16_t* intoh); + +#endif /*PERFORMANCE_TEST_H_*/ diff --git a/serpent.mk b/serpent.mk index 0ff61a6..2d4ff89 100644 --- a/serpent.mk +++ b/serpent.mk @@ -8,7 +8,7 @@ BLOCK_CIPHERS += $(ALGO_NAME) $(ALGO_NAME)_OBJ := serpent.o serpent-sboxes-bitslice.o $(ALGO_NAME)_TEST_BIN := main-serpent-test.o debug.o uart.o serial-tools.o \ serpent.o serpent-sboxes-bitslice.o nessie_bc_test.o \ - nessie_common.o cli.o + nessie_common.o cli.o performance_test.o $(ALGO_NAME)_NESSIE_TEST := "nessie" $(ALGO_NAME)_PEROFRMANCE_TEST := "performance" -- 2.39.5