]> git.cryptolib.org Git - avr-crypto-lib.git/blob - main-sha1-test.c
2bfbf17a9bfa782793019596644b6bf6dea12537
[avr-crypto-lib.git] / main-sha1-test.c
1 /*
2  * SHA-1 test-suit
3  * 
4 */
5
6 #include "config.h"
7 #include "serial-tools.h"
8 #include "uart.h"
9 #include "debug.h"
10
11 #include "sha1.h"
12
13 #include <stdint.h>
14 #include <string.h>
15
16
17 /*****************************************************************************
18  *  additional validation-functions                                                                                      *
19  *****************************************************************************/
20
21 /*****************************************************************************
22  *  self tests                                                                                                                           *
23  *****************************************************************************/
24
25 void sha1_ctx_dump(sha1_ctx_t *s){
26         uint8_t i;
27         uart_putstr("\r\n==== sha1_ctx_dump ====");
28         for(i=0;i<5;++i){
29                 uart_putstr("\r\na["); uart_hexdump(&i, 1); uart_putstr("]: ");
30                 uart_hexdump(&(s->h[i]), 4);
31         }
32         uart_putstr("\r\nlength"); uart_hexdump(&i, 8);
33
34
35 void testrun_sha1(void){
36         sha1_hash_t hash;
37         sha1(&hash,"abc",3*8);
38         uart_putstr("\r\nsha1(\"abc\") = \r\n\t");
39         uart_hexdump(hash,SHA1_HASH_BITS/8);
40         
41         sha1(&hash,"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",448);
42         uart_putstr("\r\nsha1(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") = \r\n\t");
43         uart_hexdump(hash,SHA1_HASH_BITS/8);
44         
45         uart_putstr("\r\nsha1(1,000,000 * 'a') = \r\n\t");
46         {
47                 uint8_t block[SHA1_BLOCK_BITS/8];
48                 uint16_t i;
49                 sha1_ctx_t s;
50                 memset(block,'a',SHA1_BLOCK_BITS/8);
51                 sha1_init(&s);
52                 for(i=0;i<15625; ++i){ /* (1000000/(SHA1_BLOCK_BITS/8)) */
53                         sha1_nextBlock(&s, block);
54                 }
55                 sha1_lastBlock(&s,block,0);
56                 sha1_ctx2hash(&hash, &s);
57         }
58         uart_hexdump(hash,SHA1_HASH_BITS/8);
59         
60
61         uart_putstr("\r\nx");
62 }
63
64
65
66 /*****************************************************************************
67  *  main                                                                                                                                         *
68  *****************************************************************************/
69
70 int main (void){
71         char str[20];
72
73         DEBUG_INIT();
74         uart_putstr("\r\n");
75
76         uart_putstr("\r\n\r\nCrypto-VS (SHA-1)\r\nloaded and running\r\n");
77
78 restart:
79         while(1){ 
80                 if (!getnextwordn(str,20))  {DEBUG_S("DBG: W1\r\n"); goto error;}
81                 if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
82                         testrun_sha1();
83                 goto restart;           
84                 continue;
85         error:
86                 uart_putstr("ERROR\r\n");
87         }
88         
89         
90 }
91