]> git.cryptolib.org Git - avr-crypto-lib.git/blob - main-seed-test.c
383c8fde6e4afa264f175bd78df7d588623b0c17
[avr-crypto-lib.git] / main-seed-test.c
1 /**
2  * \file        main-seed-test.c
3  * \author      Daniel Otte 
4  * \date        2007-06-01
5  * \brief       test suit for SEED
6  * \par License 
7  * GPL
8  * 
9  */
10 #include "config.h"
11 #include "serial-tools.h"
12 #include "uart.h"
13 #include "debug.h"
14
15 #include "seed.h"
16
17 #include <stdint.h>
18 #include <string.h>
19 #include <util/delay.h>
20
21 /*****************************************************************************
22  *  additional validation-functions                                                                                      *
23  *****************************************************************************/
24
25 /*****************************************************************************
26  *  self tests                                                                                                                           *
27  *****************************************************************************/
28
29 void testencrypt(uint8_t* block, uint8_t* key){
30         seed_ctx_t ctx;
31         uart_putstr("\r\n==testy-encrypt==\r\n key: ");
32         uart_hexdump(key,16);
33         seed_init(&ctx, key);
34         uart_putstr("\r\n plain: ");
35         uart_hexdump(block,16);
36         _delay_ms(50);
37         seed_encrypt(&ctx, block);
38         uart_putstr("\r\n crypt: ");
39         uart_hexdump(block,16);
40 //      uart_putstr("\r\n post-state: ");
41 //      uart_hexdump(ctx.k,16);
42 }
43
44 void testdecrypt(uint8_t* block, uint8_t* key){
45         seed_ctx_t ctx;
46         uart_putstr("\r\n==testy-decrypt==\r\n key: ");
47         uart_hexdump(key,16);
48         seed_init(&ctx, key);
49         uart_putstr("\r\n crypt: ");
50         uart_hexdump(block,16);
51         _delay_ms(50);
52         seed_decrypt(&ctx, block);
53         uart_putstr("\r\n plain: ");
54         uart_hexdump(block,16);
55 //      uart_putstr("\r\n post-state: ");
56 //      uart_hexdump(ctx.k,16);
57 }
58
59 void testrun_seed(void){
60         uint8_t keys[4][16]=
61                 { {     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
62                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
63                   {     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
64                         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
65                   { 0x47, 0x06, 0x48, 0x08, 0x51, 0xE6, 0x1B, 0xE8,
66                         0x5D, 0x74, 0xBF, 0xB3, 0xFD, 0x95, 0x61, 0x85 },
67                   { 0x28, 0xDB, 0xC3, 0xBC, 0x49, 0xFF, 0xD8, 0x7D,
68                         0xCF, 0xA5, 0x09, 0xB1, 0x1D, 0x42, 0x2B, 0xE7,}
69                 };
70         uint8_t datas[4][16]=
71                 { {     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
72                         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
73                   {     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
74                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
75                   { 0x83, 0xA2, 0xF8, 0xA2, 0x88, 0x64, 0x1F, 0xB9, 
76                         0xA4, 0xE9, 0xA5, 0xCC, 0x2F, 0x13, 0x1C, 0x7D },
77                   { 0xB4, 0x1E, 0x6B, 0xE2, 0xEB, 0xA8, 0x4A, 0x14, 
78                         0x8E, 0x2E, 0xED, 0x84, 0x59, 0x3C, 0x5E, 0xC7 }
79                 };
80         uint8_t i=0;
81         for(i=0; i<4; ++i){
82                 testencrypt(datas[i],keys[i]);
83                 testdecrypt(datas[i],keys[i]);  
84         }
85 //      testdecrypt(data,key);  
86 }
87
88
89
90 /*****************************************************************************
91  *  main                                                                                                                                         *
92  *****************************************************************************/
93
94 int main (void){
95         char str[20];
96
97         DEBUG_INIT();
98         uart_putstr("\r\n");
99
100         uart_putstr("\r\n\r\nCrypto-VS (seed)\r\nloaded and running\r\n");
101
102 restart:
103         while(1){ 
104                 if (!getnextwordn(str,20))  {DEBUG_S("DBG: W1\r\n"); goto error;}
105                 if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
106                         testrun_seed();
107                 goto restart;           
108                 continue;
109         error:
110                 uart_putstr("ERROR\r\n");
111         }
112         
113         
114 }
115