]> git.cryptolib.org Git - avr-crypto-lib.git/commitdiff
[performance-reports] switching to printf
authorbg <daniel.otte@rub.de>
Mon, 25 Feb 2013 13:39:23 +0000 (14:39 +0100)
committerbg <daniel.otte@rub.de>
Mon, 25 Feb 2013 13:46:28 +0000 (14:46 +0100)
arcfour/arcfour-asm.S
bcal/bcal-performance.c
hfal/hfal-performance.c
test_src/main-arcfour-test.c
test_src/performance_test.c
test_src/performance_test.h

index 63932abe2d25a87a644e8e1b3e907a9877001c1c..30769d4002f960d232eb489cffa816708dd5e507 100644 (file)
@@ -101,7 +101,7 @@ uint8_t arcfour_gen(arcfour_ctx_t *c){
 .global arcfour_gen
 
 ;== arcfour_gen ==
-;  this function initialises the context
+; this function generates a keystream byte
 ; param1: 16-bit pointer to a ctx struct
 ;      given in r25,r24
 
index b5b2db32bb0ffced00d6a9c5cdd253673634388f..3046ba468cfaa449b89204bcb0b8b4f6cc7c003e 100644 (file)
@@ -69,12 +69,12 @@ void bcal_performance(const bcdesc_t *bcd){
                return;
        calibrateTimer();
        print_overhead();
-       printf_P(PSTR("\n\n === %S"), bc.name);
-       printf_P(PSTR(" performance === \n"
-                     "    type:             blockcipher\n"
-                     "    keysize (bits):     %5"PRIu16"\n"), keysize);
-       printf_P(PSTR("    ctxsize (bytes):    %5"PRIu16"\n"), bc.ctxsize_B);
-       printf_P(PSTR("    blocksize (bits):   %5"PRIu16"\n"), bc.blocksize_b);
+       printf_P(PSTR("\n\n === %S performance === \n"
+                     "\ttype:             blockcipher\n"
+                     "\tkeysize (bits):     %5"PRIu16"\n"
+                     "\tctxsize (bytes):    %5"PRIu16"\n"
+                     "\tblocksize (bits):   %5"PRIu16"\n"),
+               bc.name, keysize, bc.ctxsize_B, bc.blocksize_b);
        uart0_flush();
        t=0;
        if(bc.init.init1){
index 192d6023a43a87c8b8108133fba9535959794ee1..481c3a2ece58fd3d0afca18750a4b28156d77f9f 100644 (file)
  *
  */
 
-#include "hfal-performance.h"
-#include "hashfunction_descriptor.h"
-#include "stack_measuring.h"
-#include "cli.h"
-#include "performance_test.h"
 #include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdio.h>
 #include <avr/pgmspace.h>
+#include "hfal-performance.h"
+#include "hashfunction_descriptor.h"
+#include "stack_measuring.h"
+#include "performance_test.h"
+#include "uart_i.h"
 
 #define PATTERN_A 0xAA
 #define PATTERN_B 0x55
 
-static
-void printvalue(unsigned long v){
-       char str[20];
-       int i;
-       ultoa(v, str, 10);
-       for(i=0; i<10-strlen(str); ++i){
-               cli_putc(' ');
-       }
-       cli_putstr(str);
-}
-
 void hfal_performance(const hfdesc_t *hd){
        hfdesc_t hf;
        memcpy_P(&hf, hd, sizeof(hfdesc_t));
        uint8_t ctx[hf.ctxsize_B];
        uint8_t data[(hf.blocksize_b+7)/8];
        uint8_t digest[(hf.hashsize_b+7)/8];
-       uint64_t t;
+       uint32_t t;
        uint8_t i;
 
        if(hf.type!=HFDESC_TYPE_HASHFUNCTION)
                return;
        calibrateTimer();
        print_overhead();
-       cli_putstr_P(PSTR("\r\n\r\n === "));
-       cli_putstr_P(hf.name);
-       cli_putstr_P(PSTR(" performance === "
-                         "\r\n    type:             hashfunction"
-                         "\r\n    hashsize (bits):    "));
-       printvalue(hf.hashsize_b);
-
-       cli_putstr_P(PSTR("\r\n    ctxsize (bytes):    "));
-       printvalue(hf.ctxsize_B);
-
-       cli_putstr_P(PSTR("\r\n    blocksize (bits):   "));
-       printvalue(hf.blocksize_b);
-
+       printf_P(PSTR("\n\n === %S performance ===\n"
+                     "\ttype:             hashfunction\n"
+                     "\thashsize (bits):    %10"PRIu16"\n"
+                     "\tctxsize (bytes):    %10"PRIu16"\n"
+                     "\tblocksize (bits):   %10"PRIu16"\n"),
+                hf.name, hf.hashsize_b, hf.ctxsize_B, hf.blocksize_b);
+       uart0_flush();
        t=0;
        for(i=0; i<32; ++i){
                startTimer(0);
@@ -87,8 +71,7 @@ void hfal_performance(const hfdesc_t *hd){
                }
        }
        t>>=5;
-       cli_putstr_P(PSTR("\r\n    init (cycles):      "));
-       printvalue(t);
+       printf_P(PSTR("\tinit (cycles):      %10"PRIu32"\n"), t);
 
        t=0;
        for(i=0; i<32; ++i){
@@ -99,8 +82,7 @@ void hfal_performance(const hfdesc_t *hd){
                t += stopTimer();
        }
        t>>=5;
-       cli_putstr_P(PSTR("\r\n    nextBlock (cycles): "));
-       printvalue(t);
+       printf_P(PSTR("\tnextBlock (cycles): %10"PRIu32"\n"), t);
 
        t=0;
        for(i=0; i<32; ++i){
@@ -111,8 +93,7 @@ void hfal_performance(const hfdesc_t *hd){
                t += stopTimer();
        }
        t>>=5;
-       cli_putstr_P(PSTR("\r\n    lastBlock (cycles): "));
-       printvalue(t);
+       printf_P(PSTR("\tlastBlock (cycles): %10"PRIu32"\n"), t);
 
        t=0;
        for(i=0; i<32; ++i){
@@ -123,8 +104,7 @@ void hfal_performance(const hfdesc_t *hd){
                t += stopTimer();
        }
        t>>=5;
-       cli_putstr_P(PSTR("\r\n    ctx2hash (cycles):  "));
-       printvalue(t);
+       printf_P(PSTR("\tctx2hash (cycles):  %10"PRIu32"\n"), t);
 
        if(hf.free){
                hf.free(&ctx);
@@ -136,15 +116,13 @@ void hfal_stacksize(const hfdesc_t *hd){
        stack_measuring_ctx_t smctx;
        memcpy_P(&hf, hd, sizeof(hfdesc_t));
        uint8_t ctx[hf.ctxsize_B];
-       uint8_t data[(hf.blocksize_b+7)/8];
-       uint8_t digest[(hf.hashsize_b+7)/8];
-       uint16_t t1, t2;
+       uint8_t data[(hf.blocksize_b + 7) / 8];
+       uint8_t digest[(hf.hashsize_b + 7) / 8];
+       size_t t1, t2;
 
        if(hf.type!=HFDESC_TYPE_HASHFUNCTION)
                return;
-       cli_putstr_P(PSTR("\r\n\r\n === "));
-       cli_putstr_P(hf.name);
-       cli_putstr_P(PSTR(" stack-usage === "));
+       printf_P(PSTR("\n === %S stack-usage ===\n"), hf.name);
 
        cli();
        stack_measure_init(&smctx, PATTERN_A);
@@ -155,9 +133,8 @@ void hfal_stacksize(const hfdesc_t *hd){
        t2 = stack_measure_final(&smctx);
        sei();
 
-       t1 = (t1>t2)?t1:t2;
-       cli_putstr_P(PSTR("\r\n    init (bytes):       "));
-       printvalue((unsigned long)t1);
+       t1 = (t1 > t2) ? t1 : t2;
+       printf_P(PSTR("\tinit (bytes):       %10"PRIu16"\n"), t1);
 
        cli();
        stack_measure_init(&smctx, PATTERN_A);
@@ -168,9 +145,8 @@ void hfal_stacksize(const hfdesc_t *hd){
        t2 = stack_measure_final(&smctx);
        sei();
 
-       t1 = (t1>t2)?t1:t2;
-       cli_putstr_P(PSTR("\r\n    nextBlock (bytes):  "));
-       printvalue((unsigned long)t1);
+       t1 = (t1 > t2) ? t1 : t2;
+       printf_P(PSTR("\tnextBlock (bytes):  %10"PRIu16"\n"), t1);
 
        cli();
        stack_measure_init(&smctx, PATTERN_A);
@@ -181,9 +157,8 @@ void hfal_stacksize(const hfdesc_t *hd){
        t2 = stack_measure_final(&smctx);
        sei();
 
-       t1 = (t1>t2)?t1:t2;
-       cli_putstr_P(PSTR("\r\n    lastBlock (bytes):  "));
-       printvalue((unsigned long)t1);
+       t1 = (t1 > t2) ? t1 : t2;
+       printf_P(PSTR("\tlastBlock (bytes):  %10"PRIu16"\n"), t1);
 
        cli();
        stack_measure_init(&smctx, PATTERN_A);
@@ -195,8 +170,7 @@ void hfal_stacksize(const hfdesc_t *hd){
        sei();
 
        t1 = (t1>t2)?t1:t2;
-       cli_putstr_P(PSTR("\r\n    ctx2hash (bytes):   "));
-       printvalue((unsigned long)t1);
+       printf_P(PSTR("\tctx2hash (bytes):   %10"PRIu16"\n"));
 
        if(hf.free){
                hf.free(&ctx);
@@ -208,7 +182,7 @@ void hfal_performance_multiple(const hfdesc_t *const *hd_list){
        for(;;){
                hd = (void*)pgm_read_word(hd_list);
                if(!hd){
-                       cli_putstr_P(PSTR("\r\n\r\n End of performance figures\r\n"));
+                       puts_P(PSTR("\n End of performance figures\n"));
                        return;
                }
                hfal_performance(hd);
index eb2e63e56dd870a4735aa3ed58749972263a48d2..dcaf2426023c588a705449a0bf785a0d0007c340 100644 (file)
@@ -45,8 +45,7 @@ void testrun_nessie_arcfour(void){
 }
 
 void testrun_performance_arcfour(void){
-       uint64_t t;
-       char str[16];
+       uint32_t t;
        uint8_t key[16];
        arcfour_ctx_t ctx;
        
@@ -55,21 +54,16 @@ void testrun_performance_arcfour(void){
        
        memset(key,  0, 16);
        
+    uart0_flush();
        startTimer(1);
        arcfour_init(key, 16, &ctx);
        t = stopTimer();
-       cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
-       ultoa((unsigned long)t, str, 10);
-       cli_putstr(str);        
-       
+       printf_P(PSTR("\tctx-gen time: %10"PRIu32"\n"), t);
+       uart0_flush();
        startTimer(1);
        arcfour_gen(&ctx);
        t = stopTimer();
-       cli_putstr_P(PSTR("\r\n\tencrypt time: "));
-       ultoa((unsigned long)t, str, 10);
-       cli_putstr(str);        
-       
-       cli_putstr_P(PSTR("\r\n"));     
+       printf_P(PSTR("\tencrypt time: %10"PRIu32"\n"), t);
 }
 
 
index b3fff709ca54b3cc0d006063708bbafd9ff5a083..3ce4910d62c1377a96f19b84ab28ffd8bd16bf57 100644 (file)
@@ -31,7 +31,7 @@
 #include <avr/io.h>
 #include <avr/interrupt.h>
 #include <avr/pgmspace.h>
-#include "cli.h"
+#include <stdio.h>
 #include "performance_test.h"
 
 
 
 static volatile uint32_t ovfcounter;
 
-static uint16_t const_overhead=0;
-static uint16_t int_overhead=0;
+static uint16_t const_overhead = 0;
+static uint16_t int_overhead = 0;
 
 ISR(TIMER1_OVF_vect){
-       ovfcounter++;
+       ++ovfcounter;
 }
 
 void calibrateTimer(void){
-       volatile uint8_t i=0;
        startTimer(1);
        stopTimer();
        const_overhead = TCNT1;
        startTimer(1);
-       TCNT1=0xFFFE;
-       i++;
+       TCNT1 = 0xFFFE;
+       asm("nop");
        stopTimer();
        int_overhead = TCNT1;
 }
@@ -85,27 +84,12 @@ void getOverhead(uint16_t *constoh, uint16_t *intoh){
        *intoh   = int_overhead;
 }
 
-void print_time_P(PGM_P s, uint64_t t){
-       char sv[16];
-       uint8_t c;
-       cli_putstr_P(PSTR("\r\n"));
-       cli_putstr_P(s);
-       ultoa((unsigned long)t, sv, 10);
-       for(c=strlen(sv); c<11; ++c){
-               cli_putc(' ');
-       }
-       cli_putstr(sv);
+void print_time_P(PGM_P s, uint32_t t){
+       printf_P(PSTR("%S%11"PRIu32), t);
 }
 
 void print_overhead(void){
-       char str[16];
-       cli_putstr_P(PSTR("\r\n\r\n=== benchmark ==="));
-       utoa(const_overhead, str, 10);
-       cli_putstr_P(PSTR("\r\n\tconst overhead:     "));
-       cli_putstr(str);
-       utoa(int_overhead, str, 10);
-       cli_putstr_P(PSTR("\r\n\tinterrupt overhead: "));
-       cli_putstr(str);
+       printf_P(PSTR("\n=== benchmark ===\n\tconst overhead:     %7"PRIu16"\n\tinterrupt overhead: %7"PRIu16"\n"), const_overhead, int_overhead);
 }
 
 
index f40a496cd1b6bf4d8510d4f069d397ee4f36a5da..867ef995af5150866c107835d2fdc1075b96f4b8 100644 (file)
@@ -33,7 +33,7 @@ void startTimer(uint8_t granularity);
 uint64_t stopTimer(void);
 void getOverhead(uint16_t *constoh, uint16_t *intoh);
 
-void print_time_P(PGM_P s, uint64_t t);
+void print_time_P(PGM_P s, uint32_t t);
 void print_overhead(void);
 
 #endif /*PERFORMANCE_TEST_H_*/