]> git.cryptolib.org Git - avr-crypto-lib.git/blob - main-shabea-test.c
fb9c87c6b08f168cebd3b3a9530b6361aeee2168
[avr-crypto-lib.git] / main-shabea-test.c
1 /**
2  * \file        main-shabea-test.c
3  * \author      Daniel Otte 
4  * \date        2007-06-07
5  * \brief       test suit for SHABEA
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 "shabea.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         uart_putstr("\r\n==testy-encrypt==\r\n key: ");
31         uart_hexdump(key,16);
32         uart_putstr("\r\n plain: ");
33         uart_hexdump(block,32);
34         _delay_ms(50);
35         shabea256(block,key,128,1,16);
36         uart_putstr("\r\n crypt: ");
37         uart_hexdump(block,32);
38 }
39
40 void testdecrypt(uint8_t* block, uint8_t* key){
41
42         uart_putstr("\r\n==testy-decrypt==\r\n key: ");
43         uart_hexdump(key,16);
44         uart_putstr("\r\n crypt: ");
45         uart_hexdump(block,32);
46         _delay_ms(50);
47         shabea256(block,key,128,0,16);
48         uart_putstr("\r\n plain: ");
49         uart_hexdump(block,32);
50 }
51
52 void testrun_shabea(void){
53         uint8_t keys[4][16]=
54                 { {     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
55                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
56                   {     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
57                         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
58                   { 0x47, 0x06, 0x48, 0x08, 0x51, 0xE6, 0x1B, 0xE8,
59                         0x5D, 0x74, 0xBF, 0xB3, 0xFD, 0x95, 0x61, 0x85 },
60                   { 0x28, 0xDB, 0xC3, 0xBC, 0x49, 0xFF, 0xD8, 0x7D,
61                         0xCF, 0xA5, 0x09, 0xB1, 0x1D, 0x42, 0x2B, 0xE7,}
62                 };
63         uint8_t datas[4][32]=
64                 { {     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
65                         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
66                         0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
67                         0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f },
68                   {     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
69                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
70                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
71                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
72                   { 0x83, 0xA2, 0xF8, 0xA2, 0x88, 0x64, 0x1F, 0xB9, 
73                         0xA4, 0xE9, 0xA5, 0xCC, 0x2F, 0x13, 0x1C, 0x7D,
74                         0x83, 0xA2, 0xF8, 0xA2, 0x88, 0x64, 0x1F, 0xB9, 
75                         0xA4, 0xE9, 0xA5, 0xCC, 0x2F, 0x13, 0x1C, 0x7D },
76                   { 0xB4, 0x1E, 0x6B, 0xE2, 0xEB, 0xA8, 0x4A, 0x14, 
77                         0x8E, 0x2E, 0xED, 0x84, 0x59, 0x3C, 0x5E, 0xC7,
78                         0xB4, 0x1E, 0x6B, 0xE2, 0xEB, 0xA8, 0x4A, 0x14, 
79                         0x8E, 0x2E, 0xED, 0x84, 0x59, 0x3C, 0x5E, 0xC7 }
80                 };
81         uint8_t i=0;
82         for(i=0; i<4; ++i){
83                 testencrypt(datas[i],keys[i]);
84                 testdecrypt(datas[i],keys[i]);  
85         }
86 //      testdecrypt(data,key);  
87 }
88
89
90
91 /*****************************************************************************
92  *  main                                                                                                                                         *
93  *****************************************************************************/
94
95 int main (void){
96         char str[20];
97
98         DEBUG_INIT();
99         uart_putstr("\r\n");
100
101         uart_putstr("\r\n\r\nCrypto-VS (shabea)\r\nloaded and running\r\n");
102
103 restart:
104         while(1){ 
105                 if (!getnextwordn(str,20))  {DEBUG_S("DBG: W1\r\n"); goto error;}
106                 if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
107                         testrun_shabea();
108                 goto restart;           
109                 continue;
110         error:
111                 uart_putstr("ERROR\r\n");
112         }
113         
114         
115 }
116