]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - hfal-performance.c
changing performance measurment of blockciphers to bcal
[avr-crypto-lib.git] / hfal-performance.c
index 391fac8508a0b857bb3f02f76a66119518ec4a9a..c64e7e962fbed888c528d8bfb64ad199a6a6b212 100644 (file)
@@ -22,7 +22,7 @@
  * \email   daniel.otte@rub.de
  * \date    2009-05-10
  * \license GPLv3 or later
- * 
+ *
  */
 
 #include "hfal-performance.h"
@@ -36,7 +36,7 @@
 
 
 static
-void printvalue(unsigned int v){
+void printvalue(unsigned long v){
        char str[20];
        int i;
        ultoa(v, str, 10);
@@ -53,45 +53,79 @@ void hfal_performance(const hfdesc_t* hd){
        uint8_t data[(hf.blocksize_b+7)/8];
        uint8_t digest[(hf.hashsize_b+7)/8];
        uint64_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);
-       
-       startTimer(1);
-       hf.init(&ctx);
-       t = stopTimer();
+
+       t=0;
+       for(i=0; i<32; ++i){
+               startTimer(0);
+               START_TIMER;
+               hf.init(&ctx);
+               STOP_TIMER;
+               t += stopTimer();
+               if(i!=31 && hf.free){
+                       hf.free(&ctx)
+               }
+       }
+       t>>=5;
        cli_putstr_P(PSTR("\r\n    init (cycles):      "));
        printvalue(t);
-       
-       startTimer(1);
-       hf.nextBlock(&ctx, data);
-       t = stopTimer();
+
+       t=0;
+       for(i=0; i<32; ++i){
+               startTimer(0);
+               START_TIMER;
+               hf.nextBlock(&ctx, data);
+               STOP_TIMER;
+               t += stopTimer();
+       }
+       t>>=5;
        cli_putstr_P(PSTR("\r\n    nextBlock (cycles): "));
        printvalue(t);
-       
-       startTimer(1);
-       hf.lastBlock(&ctx, data, 0);
-       t = stopTimer();
+
+       t=0;
+       for(i=0; i<32; ++i){
+               startTimer(0);
+               START_TIMER;
+               hf.lastBlock(&ctx, data, 0);
+               STOP_TIMER;
+               t += stopTimer();
+       }
+       t>>=5;
        cli_putstr_P(PSTR("\r\n    lastBlock (cycles): "));
        printvalue(t);
-       
-       startTimer(1);
-       hf.ctx2hash(digest, &ctx);
-       t = stopTimer();
+
+       t=0;
+       for(i=0; i<32; ++i){
+               startTimer(0);
+               START_TIMER;
+               hf.ctx2hash(digest, &ctx);
+               STOP_TIMER;
+               t += stopTimer();
+       }
+       t>>=5;
        cli_putstr_P(PSTR("\r\n    ctx2hash (cycles):  "));
        printvalue(t);
+
+       if(hf.free){
+               hf.free(&ctx);
+       }
 }
 
 
@@ -99,8 +133,10 @@ void hfal_performance_multiple(const hfdesc_t** hd_list){
        const hfdesc_t* hd;
        for(;;){
                hd = (void*)pgm_read_word(hd_list);
-               if(!hd)
+               if(!hd){
+                       cli_putstr_P(PSTR("\r\n\r\n End of performance figures\r\n"));
                        return;
+               }
                hfal_performance(hd);
                hd_list = (void*)((uint8_t*)hd_list + 2);
        }