]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - test_src/main-sha1-test.c
introducing the tweak on skein
[avr-crypto-lib.git] / test_src / main-sha1-test.c
index 1dc476c4c0cc420d0de777fc58f615971015f397..cde507b81873527801ee83196bff7dd9d05a4738 100644 (file)
 */
 /*
  * SHA-1 test-suit
- * 
+ *
 */
 
 #include "config.h"
 #include "serial-tools.h"
-#include "uart.h"
+#include "uart_i.h"
 #include "debug.h"
 
 #include "sha1.h"
 #include "nessie_hash_test.h"
-#include "performance_test.h"
+#include "hfal_sha1.h"
+#include "hfal-performance.h"
 
 #include <stdint.h>
 #include <string.h>
 
 char* algo_name = "SHA-1";
 
+const hfdesc_t* algolist[] PROGMEM = {
+       (hfdesc_t*)&sha1_desc,
+       NULL
+};
 /*****************************************************************************
  *  additional validation-functions                                                                                     *
  *****************************************************************************/
@@ -53,7 +58,7 @@ void testrun_nessie_sha1(void){
        nessie_hash_ctx.hash_next = (nessie_hash_next_fpt)sha1_nextBlock;
        nessie_hash_ctx.hash_last = (nessie_hash_last_fpt)sha1_lastBlock;
        nessie_hash_ctx.hash_conv = (nessie_hash_conv_fpt)sha1_ctx2hash;
-       
+
        nessie_hash_run();
 }
 
@@ -69,18 +74,39 @@ void sha1_ctx_dump(sha1_ctx_t *s){
                cli_hexdump(&(s->h[i]), 4);
        }
        cli_putstr("\r\nlength"); cli_hexdump(&i, 8);
-} 
+}
 
 void testrun_sha1(void){
        sha1_hash_t hash;
        sha1(&hash,"abc",3*8);
-       cli_putstr("\r\nsha1(\"abc\") = \r\n\t");
+       cli_putstr_P(PSTR("\r\nsha1(\"abc\") = \r\n\t"));
+       cli_hexdump(hash,SHA1_HASH_BITS/8);
+
+       sha1(&hash,"\0\0\0\0\0\0\0\0", 8*8);
+       cli_putstr_P(PSTR("\r\nsha1(8 x 0x00) = \r\n\t"));
+       cli_hexdump(hash,SHA1_HASH_BITS/8);
+/*
+   Len = 496
+   Msg = 46fe5ed326c8fe376fcc92dc9e2714e2240d3253b105ad
+         fbb256ff7a19bc40975c604ad7c0071c4fd78a7cb64786
+         e1bece548fa4833c04065fe593f6fb10
+   MD  = f220a7457f4588d639dc21407c942e9843f8e26b
+*/
+       sha1(&hash,"\x46\xfe\x5e\xd3\x26\xc8\xfe\x37"
+                  "\x6f\xcc\x92\xdc\x9e\x27\x14\xe2"
+                  "\x24\x0d\x32\x53\xb1\x05\xad\xfb"
+                  "\xb2\x56\xff\x7a\x19\xbc\x40\x97"
+                  "\x5c\x60\x4a\xd7\xc0\x07\x1c\x4f"
+                  "\xd7\x8a\x7c\xb6\x47\x86\xe1\xbe"
+                  "\xce\x54\x8f\xa4\x83\x3c\x04\x06"
+                  "\x5f\xe5\x93\xf6\xfb\x10", 496);
+       cli_putstr_P(PSTR("\r\nsha1(tv_496) = \r\n\t"));
        cli_hexdump(hash,SHA1_HASH_BITS/8);
-       
+
        sha1(&hash,"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",448);
-       cli_putstr("\r\nsha1(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") = \r\n\t");
+//     cli_putstr_P(PSTR("\r\nsha1(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") = \r\n\t"));
        cli_hexdump(hash,SHA1_HASH_BITS/8);
-       
+/*
        cli_putstr("\r\nsha1(1,000,000 * 'a') = \r\n\t");
        {
                uint8_t block[SHA1_BLOCK_BITS/8];
@@ -88,14 +114,14 @@ void testrun_sha1(void){
                sha1_ctx_t s;
                memset(block,'a',SHA1_BLOCK_BITS/8);
                sha1_init(&s);
-               for(i=0;i<15625; ++i){ /* (1000000/(SHA1_BLOCK_BITS/8)) */
+               for(i=0;i<15625; ++i){ / * (1000000/(SHA1_BLOCK_BITS/8)) * /
                        sha1_nextBlock(&s, block);
                }
                sha1_lastBlock(&s,block,0);
                sha1_ctx2hash(&hash, &s);
        }
        cli_hexdump(hash,SHA1_HASH_BITS/8);
-       
+*/
 
        cli_putstr("\r\nx");
 }
@@ -105,54 +131,21 @@ void testrun_sha1_2(void){
        sha1_ctx_t ctx;
        sha1_hash_t hash;
        sha1(&hash,"",0);
-       cli_putstr("\r\nsha1(NULL) = \r\n\t");
+       cli_putstr_P(PSTR("\r\nsha1(NULL) = \r\n\t"));
        cli_hexdump(hash,SHA1_HASH_BYTES);
 
        memset(hash, 0, SHA1_HASH_BYTES);
 
        sha1_init(&ctx);
        sha1_lastBlock(&ctx, "", 0);
-       sha1_ctx2hash(&hash, &ctx); 
-       cli_putstr("\r\nsha1(NULL) = \r\n\t");
+       sha1_ctx2hash(&hash, &ctx);
+       cli_putstr_P(PSTR("\r\nsha1(NULL) = \r\n\t"));
        cli_hexdump(hash,SHA1_HASH_BYTES);
 }
 
 
 void testrun_performance_sha1(void){
-       uint64_t t;
-       char str[16];
-       uint8_t data[32];
-       sha1_ctx_t ctx;
-       
-       calibrateTimer();
-       print_overhead();
-       
-       memset(data, 0, 32);
-       
-       startTimer(1);
-       sha1_init(&ctx);
-       t = stopTimer();
-       cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
-       ultoa((unsigned long)t, str, 10);
-       cli_putstr(str);
-       
-       
-       startTimer(1);
-       sha1_nextBlock(&ctx, data);
-       t = stopTimer();
-       cli_putstr_P(PSTR("\r\n\tone-block time: "));
-       ultoa((unsigned long)t, str, 10);
-       cli_putstr(str);
-       
-       
-       startTimer(1);
-       sha1_lastBlock(&ctx, data, 0);
-       t = stopTimer();
-       cli_putstr_P(PSTR("\r\n\tlast block time: "));
-       ultoa((unsigned long)t, str, 10);
-       cli_putstr(str);
-       
-       cli_putstr_P(PSTR("\r\n"));
+       hfal_performance_multiple(algolist);
 }
 
 
@@ -184,18 +177,13 @@ cmdlist_entry_t cmdlist[] PROGMEM = {
        { NULL,                NULL, NULL}
 };
 
-const hfdesc_t* algolist[] PROGMEM = {
-       (hfdesc_t*)&sha1_desc,
-       NULL
-};
-
 int main (void){
        DEBUG_INIT();
-       
-       cli_rx = uart_getc;
-       cli_tx = uart_putc;      
+
+       cli_rx = (cli_rx_fpt)uart0_getc;
+       cli_tx = (cli_tx_fpt)uart0_putc;
        shavs_algolist=(hfdesc_t**)algolist;
-       shavs_algo=(hfdesc_t*)&sha1_desc;       
+       shavs_algo=(hfdesc_t*)&sha1_desc;
        for(;;){
                cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
                cli_putstr(algo_name);