]> git.cryptolib.org Git - avr-crypto-lib.git/commitdiff
some minor changes to performance testing code
authorbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Wed, 16 Apr 2008 20:51:10 +0000 (20:51 +0000)
committerbg <bg@b1d182e4-1ff8-0310-901f-bddb46175740>
Wed, 16 Apr 2008 20:51:10 +0000 (20:51 +0000)
cast5.c
main-cast5-test.c
main-present-test.c
main-serpent-test.c
present.mk

diff --git a/cast5.c b/cast5.c
index 34c5a78e3dc5a674ad3afabb0cb15293391ec6bb..204fe30dcc1d74c593fa9e731f7aa2b3d1c0ec03 100644 (file)
--- 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 */
index 8a36b59295260e64c160eb40a9973829219e606a..514a6359f23eea4687e0147b18926e8f51522a2e 100644 (file)
@@ -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"));
 }
 
index bcb0e5490b26449e0471057e9473d4e4cb14a40a..a58a6dd194ab66eef079bcd574790cb8d6d8127c 100644 (file)
@@ -11,7 +11,9 @@
 #include "present.h"
 #include "nessie_bc_test.h"
 #include "cli.h"
+#include "performance_test.h"
 
+#include <stdlib.h>
 #include <stdint.h>
 #include <string.h>
 
@@ -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;}
index b81cb32af75a9708160d1d268e65a5e2c637b78b..801e2b81b9ba9eac777652b83230987cab074fdb 100644 (file)
@@ -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"));
 }
 /*****************************************************************************
index eba6e78ee1999ca575f07c9972fc9d369a34be56..764acefad3e9ea0f8fd46ff1e06a813377868db4 100644 (file)
@@ -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"