]> git.cryptolib.org Git - avr-crypto-lib.git/blobdiff - test_src/main-sha1-test.c
host tools for verification +testvectors
[avr-crypto-lib.git] / test_src / main-sha1-test.c
index 6f07227c03722943f459967fc6c6eae9dbb4e8ff..f4376dd549e7a09c193a855c2d9b793ac86f453c 100644 (file)
@@ -1,6 +1,6 @@
 /* main-sha1-test.c */
 /*
-    This file is part of the Crypto-avr-lib/microcrypt-lib.
+    This file is part of the AVR-Crypto-Lib.
     Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
 
     This program is free software: you can redistribute it and/or modify
@@ -34,6 +34,9 @@
 #include <string.h>
 #include <stdlib.h>
 #include "cli.h"
+#include "shavs.h"
+#include "hfal_sha1.h"
+#include "dump.h"
 
 char* algo_name = "SHA-1";
 
@@ -104,6 +107,24 @@ void testrun_sha1(void){
        uart_putstr("\r\nx");
 }
 
+
+void testrun_sha1_2(void){
+       sha1_ctx_t ctx;
+       sha1_hash_t hash;
+       sha1(&hash,"",0);
+       uart_putstr("\r\nsha1(NULL) = \r\n\t");
+       uart_hexdump(hash,SHA1_HASH_BYTES);
+
+       memset(hash, 0, SHA1_HASH_BYTES);
+
+       sha1_init(&ctx);
+       sha1_lastBlock(&ctx, "", 0);
+       sha1_ctx2hash(&hash, &ctx); 
+       uart_putstr("\r\nsha1(NULL) = \r\n\t");
+       uart_hexdump(hash,SHA1_HASH_BYTES);
+}
+
+
 void testrun_performance_sha1(void){
        uint64_t t;
        char str[16];
@@ -146,26 +167,46 @@ void testrun_performance_sha1(void){
  *  main                                                                                                                                        *
  *****************************************************************************/
 
-int main (void){
-       char str[20];
+const char nessie_str[]      PROGMEM = "nessie";
+const char test_str[]        PROGMEM = "test";
+const char test2_str[]       PROGMEM = "test2";
+const char performance_str[] PROGMEM = "performance";
+const char echo_str[]        PROGMEM = "echo";
+const char shavs_list_str[]  PROGMEM = "shavs_list";
+const char shavs_set_str[]   PROGMEM = "shavs_set";
+const char shavs_test1_str[] PROGMEM = "shavs_test1";
+const char dump_str[]        PROGMEM = "dump";
+
+
+cmdlist_entry_t cmdlist[] PROGMEM = {
+       { nessie_str,          NULL, testrun_nessie_sha1},
+       { test_str,            NULL, testrun_sha1},
+       { test2_str,           NULL, testrun_sha1_2},
+       { performance_str,     NULL, testrun_performance_sha1},
+       { echo_str,        (void*)1, (void_fpt)echo_ctrl},
+       { shavs_list_str,      NULL, shavs_listalgos},
+       { shavs_set_str,   (void*)1, (void_fpt)shavs_setalgo},
+       { shavs_test1_str,     NULL, shavs_test1},
+       { dump_str,        (void*)1, (void_fpt)dump},
+       { NULL,                NULL, NULL}
+};
+
+const hfdesc_t* algolist[] PROGMEM = {
+       (hfdesc_t*)&sha1_desc,
+       NULL
+};
 
+int main (void){
        DEBUG_INIT();
        uart_putstr("\r\n");
-
-       uart_putstr("\r\n\r\nCrypto-VS (SHA-1)\r\nloaded and running\r\n");
-
-       PGM_P    u   = PSTR("nessie\0test\0performance\0");
-       void_fpt v[] = {testrun_nessie_sha1, testrun_sha1, testrun_performance_sha1};
-
-       while(1){ 
-               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");
+       cli_rx = uart_getc;
+       cli_tx = uart_putc;      
+       shavs_algolist=(hfdesc_t**)algolist;
+       shavs_algo=(hfdesc_t*)&sha1_desc;       
+       for(;;){
+               uart_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
+               uart_putstr(algo_name);
+               uart_putstr_P(PSTR(")\r\nloaded and running\r\n"));
+               cmd_interface(cmdlist);
        }
 }
-
-