]> git.cryptolib.org Git - avr-crypto-lib.git/blob - main-shabea-test.c
+DES/3DES
[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,16);
34         _delay_ms(50);
35         shabea128(block,key,128,1,16);
36         uart_putstr("\r\n crypt: ");
37         uart_hexdump(block,16);
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,16);
46         _delay_ms(50);
47         shabea128(block,key,128,0,16);
48         uart_putstr("\r\n plain: ");
49         uart_hexdump(block,16);
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][16]=
64                 { {     0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
65                         0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f },
66                   {     0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
67                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
68                   { 0x83, 0xA2, 0xF8, 0xA2, 0x88, 0x64, 0x1F, 0xB9, 
69                         0xA4, 0xE9, 0xA5, 0xCC, 0x2F, 0x13, 0x1C, 0x7D },
70                   { 0xB4, 0x1E, 0x6B, 0xE2, 0xEB, 0xA8, 0x4A, 0x14, 
71                         0x8E, 0x2E, 0xED, 0x84, 0x59, 0x3C, 0x5E, 0xC7 }
72                 };
73         uint8_t i=0;
74         for(i=0; i<4; ++i){
75                 testencrypt(datas[i],keys[i]);
76                 testdecrypt(datas[i],keys[i]);  
77         }
78 //      testdecrypt(data,key);  
79 }
80
81
82
83 /*****************************************************************************
84  *  main                                                                                                                                         *
85  *****************************************************************************/
86
87 int main (void){
88         char str[20];
89
90         DEBUG_INIT();
91         uart_putstr("\r\n");
92
93         uart_putstr("\r\n\r\nCrypto-VS (shabea)\r\nloaded and running\r\n");
94
95 restart:
96         while(1){ 
97                 if (!getnextwordn(str,20))  {DEBUG_S("DBG: W1\r\n"); goto error;}
98                 if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
99                         testrun_shabea();
100                 goto restart;           
101                 continue;
102         error:
103                 uart_putstr("ERROR\r\n");
104         }
105         
106         
107 }
108