]> git.cryptolib.org Git - avr-crypto-lib.git/blob - main-serpent-test.c
+Serpent
[avr-crypto-lib.git] / main-serpent-test.c
1 /*
2  * serpent 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 "serpent.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 dumpctx(serpent_ctx_t * ctx){
26         uint8_t i;
27         uart_putstr("\r\n --ctx dump--\r\n");
28         for(i=0; i<33; ++i){
29                 uart_putstr("  K["); uart_putc('0'+i/10); uart_putc('0'+i%10); uart_putstr("] = ");     
30             uart_hexdump(ctx->k[i],16);
31             uart_putstr("\r\n");
32         }
33 }
34
35 void testencrypt(uint8_t* block, uint8_t* key){
36         serpent_ctx_t ctx;
37         uart_putstr("\r\n==testy-encrypt==\r\n key: ");
38         uart_hexdump(key,32);
39         serpent_genctx(key, &ctx);      
40 //      dumpctx(&ctx);
41         uart_putstr("\r\n plain: ");
42         uart_hexdump(block,16);
43         serpent_enc(block, &ctx);
44         uart_putstr("\r\n crypt: ");
45         uart_hexdump(block,16);
46 }
47
48 void testdecrypt(uint8_t* block, uint8_t* key){
49         serpent_ctx_t ctx;
50         uart_putstr("\r\n==testy-decrypt==\r\n key: ");
51         uart_hexdump(key,32);
52         serpent_genctx(key, &ctx);
53 //      dumpctx(&ctx);
54         uart_putstr("\r\n crypt: ");
55         uart_hexdump(block,16);
56         serpent_dec(block, &ctx);
57         uart_putstr("\r\n plain: ");
58         uart_hexdump(block,16);
59 }
60
61 /**
62  Test vectors -- set 4
63 =====================
64
65 Set 4, vector#  0:
66                            key=000102030405060708090A0B0C0D0E0F
67                                101112131415161718191A1B1C1D1E1F
68                          plain=00112233445566778899AABBCCDDEEFF
69                         cipher=2868B7A2D28ECD5E4FDEFAC3C4330074
70                      decrypted=00112233445566778899AABBCCDDEEFF
71             Iterated 100 times=8BF56992354F3F1A0F4E49DCBA82CBC0
72            Iterated 1000 times=9B1D8B34845DF9BFD36AAAD0CDA1C8FE
73
74 Set 4, vector#  1:
75                            key=2BD6459F82C5B300952C49104881FF48
76                                2BD6459F82C5B300952C49104881FF48
77                          plain=EA024714AD5C4D84EA024714AD5C4D84
78                         cipher=3E507730776B93FDEA661235E1DD99F0
79                      decrypted=EA024714AD5C4D84EA024714AD5C4D84
80             Iterated 100 times=3B5462E5D87A40C4BE745E3994D5E373
81            Iterated 1000 times=99D5D067EF7C787E6A764EB47DAC59AD
82
83
84 Set 1, vector#  0:
85                            key=80000000000000000000000000000000
86                                00000000000000000000000000000000
87                          plain=00000000000000000000000000000000
88                         cipher=A223AA1288463C0E2BE38EBD825616C0
89                      decrypted=00000000000000000000000000000000
90             Iterated 100 times=739E0148971FD975B585EAFDBD659E2C
91            Iterated 1000 times=BEFD00E0D6E27E56951DC6614440D286
92  
93 */
94
95 void testrun_serpent(void){
96         
97         uint8_t key[]={ 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 
98                             0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
99                     0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
100                     0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F };
101                     
102         uint8_t data[]={ 0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
103                              0x88, 0x99, 0xAA, 0xBB, 0xCC, 0xDD, 0xEE, 0xFF};
104 /* * /
105         uint8_t key[]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
106                             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
107                         0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
108                             0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; 
109                             
110         uint8_t data[]={ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 
111                                          0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
112 */
113         testencrypt(data,key);
114         testdecrypt(data,key);  
115 }
116
117
118
119 /*****************************************************************************
120  *  main                                                                                                                                         *
121  *****************************************************************************/
122
123 int main (void){
124         char str[20];
125
126         DEBUG_INIT();
127         uart_putstr("\r\n");
128
129         uart_putstr("\r\n\r\nCrypto-VS (serpent)\r\nloaded and running\r\n");
130
131 restart:
132         while(1){ 
133                 if (!getnextwordn(str,20))  {DEBUG_S("DBG: W1\r\n"); goto error;}
134                 if (strcmp(str, "test")) {DEBUG_S("DBG: 1b\r\n"); goto error;}
135                         testrun_serpent();
136                 goto restart;           
137                 continue;
138         error:
139                 uart_putstr("ERROR\r\n");
140         }
141         
142         
143 }
144