]> git.cryptolib.org Git - avr-crypto-lib.git/blob - main-sha1-test.c
insereated GPLv3 stub
[avr-crypto-lib.git] / main-sha1-test.c
1 /* main-sha1-test.c */
2 /*
3     This file is part of the Crypto-avr-lib/microcrypt-lib.
4     Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19 /*
20  * SHA-1 test-suit
21  * 
22 */
23
24 #include "config.h"
25 #include "serial-tools.h"
26 #include "uart.h"
27 #include "debug.h"
28
29 #include "sha1.h"
30
31 #include <stdint.h>
32 #include <string.h>
33
34
35 /*****************************************************************************
36  *  additional validation-functions                                                                                      *
37  *****************************************************************************/
38
39 /*****************************************************************************
40  *  self tests                                                                                                                           *
41  *****************************************************************************/
42
43 void sha1_ctx_dump(sha1_ctx_t *s){
44         uint8_t i;
45         uart_putstr("\r\n==== sha1_ctx_dump ====");
46         for(i=0;i<5;++i){
47                 uart_putstr("\r\na["); uart_hexdump(&i, 1); uart_putstr("]: ");
48                 uart_hexdump(&(s->h[i]), 4);
49         }
50         uart_putstr("\r\nlength"); uart_hexdump(&i, 8);
51
52
53 void testrun_sha1(void){
54         sha1_hash_t hash;
55         sha1(&hash,"abc",3*8);
56         uart_putstr("\r\nsha1(\"abc\") = \r\n\t");
57         uart_hexdump(hash,SHA1_HASH_BITS/8);
58         
59         sha1(&hash,"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq",448);
60         uart_putstr("\r\nsha1(\"abcdbcdecdefdefgefghfghighijhijkijkljklmklmnlmnomnopnopq\") = \r\n\t");
61         uart_hexdump(hash,SHA1_HASH_BITS/8);
62         
63         uart_putstr("\r\nsha1(1,000,000 * 'a') = \r\n\t");
64         {
65                 uint8_t block[SHA1_BLOCK_BITS/8];
66                 uint16_t i;
67                 sha1_ctx_t s;
68                 memset(block,'a',SHA1_BLOCK_BITS/8);
69                 sha1_init(&s);
70                 for(i=0;i<15625; ++i){ /* (1000000/(SHA1_BLOCK_BITS/8)) */
71                         sha1_nextBlock(&s, block);
72                 }
73                 sha1_lastBlock(&s,block,0);
74                 sha1_ctx2hash(&hash, &s);
75         }
76         uart_hexdump(hash,SHA1_HASH_BITS/8);
77         
78
79         uart_putstr("\r\nx");
80 }
81
82
83
84 /*****************************************************************************
85  *  main                                                                                                                                         *
86  *****************************************************************************/
87
88 int main (void){
89         char str[20];
90
91         DEBUG_INIT();
92         uart_putstr("\r\n");
93
94         uart_putstr("\r\n\r\nCrypto-VS (SHA-1)\r\nloaded and running\r\n");
95
96 restart:
97         while(1){ 
98                 if (!getnextwordn(str,20))  {DEBUG_S("DBG: W1\r\n"); goto error;}
99                 if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
100                         testrun_sha1();
101                 goto restart;           
102                 continue;
103         error:
104                 uart_putstr("ERROR\r\n");
105         }
106         
107         
108 }
109