]> git.cryptolib.org Git - avr-crypto-lib.git/commitdiff
+performance tests; some modifications to the Cast5-test-suit
authorbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Fri, 11 Apr 2008 02:52:10 +0000 (02:52 +0000)
committerbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Fri, 11 Apr 2008 02:52:10 +0000 (02:52 +0000)
cast5.mk
main-arcfour-test.c
main-cast5-test.c
main-serpent-test.c
nessie_common.c
nessie_stream_test.c
nessie_stream_test.h
performance_test.c [new file with mode: 0644]
performance_test.h [new file with mode: 0644]
serpent.mk

index 2969c828a7474bc5df99e68316ed32f497559fa2..b2b671b561b05794801c1f5cff9b48a6cac7f23f 100644 (file)
--- 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"
 
index 0274bd5b9a9e5f354c0536ee13c95d072362fc7f..74e76e158844e656b1635ca1b2f0d0cb9af8804a 100644 (file)
@@ -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;
index 6f3b18a71228afd9061c4d1f75e72448226f21cf..8a36b59295260e64c160eb40a9973829219e606a 100644 (file)
 
 #include "cast5.h"
 #include "nessie_bc_test.h"
+#include "performance_test.h"
+#include "cli.h"
 
 #include <stdint.h>
 #include <string.h>
+#include <stdlib.h>
 
 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) */
+       }
 }
 
index c05ef173557fc9ba25f167a50aefcd1f7d1c5d09..b81cb32af75a9708160d1d268e65a5e2c637b78b 100644 (file)
 #include "serpent.h"
 #include "nessie_bc_test.h"
 #include "cli.h"
+#include "performance_test.h"
 
 #include <stdint.h>
 #include <string.h>
+#include <stdlib.h>
 
 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;}
index 7adac8232dabf199c987e5b0d497057c464a66b6..b82805218675efd950337b94b67bb56c3693c85d 100644 (file)
@@ -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"));
 }
index 3f7c7785e89a143d5559581769816d1f6226bbc8..3271d6e578277a49ad029d9e86b8977c2f818ea5 100644 (file)
@@ -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);
index 940fb529a91b6c077c7346934b75d203bf3e256b..37227985f12307153ee89767eb935abba45d4aca 100644 (file)
@@ -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 (file)
index 0000000..91d4f1c
--- /dev/null
@@ -0,0 +1,60 @@
+/*
+ * 
+ * 
+ * 
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#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 (file)
index 0000000..2243586
--- /dev/null
@@ -0,0 +1,11 @@
+#ifndef PERFORMANCE_TEST_H_
+#define PERFORMANCE_TEST_H_
+
+#include <stdint.h>
+
+void calibrateTimer(void);
+void startTimer(uint8_t granularity);
+uint64_t stopTimer(void);
+void getOverhead(uint16_t* constoh, uint16_t* intoh);
+
+#endif /*PERFORMANCE_TEST_H_*/
index 0ff61a6dc1096844608fd8611c953824e7d3c808..2d4ff897fbb165e1beee2fd1dbfe270628c2a58c 100644 (file)
@@ -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"