]> git.cryptolib.org Git - arm-crypto-lib.git/blob - test_src/main-mickey128-test.c
adding mickey128
[arm-crypto-lib.git] / test_src / main-mickey128-test.c
1 /*
2  * Mickey128 test-suit
3  * 
4 */
5 #include "main-test-common.h"
6
7 #include "performance_test.h"
8 #include "mickey128.h"
9 #include "scal_mickey128.h"
10 #include "scal-basic.h"
11 #include "scal-nessie.h"
12
13 char* algo_name = "Mickey128";
14
15 /*****************************************************************************
16  *  additional validation-functions                                                                                      *
17  *****************************************************************************/
18
19 void testrun_nessie_mickey128(void){
20         scal_nessie_set_estream(1);
21         scal_nessie_run(&mickey128_desc);
22 }
23
24 void testrun_ref_mickey128(void){
25         uint8_t key[4][16] ={
26                                   { 0x12, 0x34, 0x56, 0x78, 
27                                 0x9a, 0xbc, 0xde, 0xf0, 
28                                 0x01, 0x23, 0x45, 0x67, 
29                                 0x89, 0xab, 0xcd, 0xef},
30                               { 0xf1, 0x1a, 0x56, 0x27, 
31                                 0xce, 0x43, 0xb6, 0x1f, 
32                                 0x89, 0x12, 0x29, 0x94, 
33                                 0x86, 0x09, 0x44, 0x86},
34                               { 0x3b, 0x80, 0xfc, 0x8c, 
35                                 0x47, 0x5f, 0xc2, 0x70, 
36                                 0xfa, 0x26, 0xb4, 0x70, 
37                                 0x64, 0xb3, 0x2d, 0x33},
38                                                   { 0x82, 0xac, 0xb3, 0x8c,
39                                                     0x5d, 0x7a, 0x3c, 0x78,
40                                                         0xd9, 0x8f, 0x15, 0x3c,
41                                                         0xa3, 0xf9, 0xde, 0x7c} };
42         uint8_t iv_1[] = {0x21, 0x43, 0x65, 0x87};
43         uint8_t iv_2[] = {0x9c, 0x53, 0x2f, 0x8a, 
44                           0xc3, 0xea, 0x4b, 0x2e, 
45                           0xa0, 0xf5, 0x96, 0x40, 
46                           0x30, 0x83, 0x77, 0xcc};
47         uint8_t data[16];
48         uint8_t i;
49         mickey128_ctx_t ctx;
50         cli_putstr("\r\n-=Reference test=-\r\n");
51         
52         cli_putstr("Test 1:\r\n key:    ");
53         cli_hexdump(key[0], 16);
54         cli_putstr("\r\n iv:     ");
55         cli_hexdump(iv_1, 4);
56         mickey128_init(&(key[0][0]), 128, iv_1, 4*8, &ctx);
57         for(i=0; i<16; ++i){
58                 data[i] = mickey128_getbyte(&ctx);
59         }
60         cli_putstr("\r\n stream: ");
61         cli_hexdump(data, 16);
62         
63         cli_putstr("\r\n\r\nTest 2:\r\n key:    ");
64         cli_hexdump(key[1], 16);
65         cli_putstr("\r\n iv:     ");
66         cli_hexdump(iv_2, 16);
67         mickey128_init(key[1], 128, iv_2, 16*8, &ctx);
68         for(i=0; i<16; ++i){
69                 data[i] = mickey128_getbyte(&ctx);
70         }
71         cli_putstr("\r\n stream: ");
72         cli_hexdump(data, 16);
73         
74         cli_putstr("\r\n\r\nTest 3:\r\n key:    ");
75         cli_hexdump(key[2], 16);
76         cli_putstr("\r\n iv:     ");
77         mickey128_init(key[2], 128, NULL, 0, &ctx);
78         for(i=0; i<16; ++i){
79                 data[i] = mickey128_getbyte(&ctx);
80         }
81         cli_putstr("\r\n stream: ");
82         cli_hexdump(data, 16);
83
84         cli_putstr("\r\n\r\nIteration test:\r\n key:    ");
85         cli_hexdump(key[3], 16);
86         mickey128_init(key[3], 128, NULL, 0, &ctx);
87         uint16_t j;
88         for(j=0; j<1000; ++j){
89                 for(i=0; i<16; ++i)
90                         key[0][i] = mickey128_getbyte(&ctx);
91                 for(i=0; i<4; ++i)
92                         iv_1[i] = mickey128_getbyte(&ctx);
93                 mickey128_init(key[0], 128, iv_1, 32, &ctx);
94         }
95                 for(i=0; i<16; ++i){
96                 data[i] = mickey128_getbyte(&ctx);
97         }
98         cli_putstr("\r\n stream: ");
99         cli_hexdump(data, 16);
100         cli_putstr("\r\n");
101
102 }
103
104
105
106 /*****************************************************************************
107  *  main                                                                                                                                         *
108  *****************************************************************************/
109
110 const char nessie_str[] = "nessie";
111 const char test_str[] = "test";
112 const char performance_str[] = "performance";
113 const char echo_str[] = "echo";
114
115 cmdlist_entry_t cmdlist[] = {
116         { nessie_str,      NULL, testrun_nessie_mickey128},
117         { test_str,        NULL, testrun_ref_mickey128},
118         { echo_str,    (void*)1, (void_fpt)echo_ctrl},
119         { NULL,            NULL, NULL}
120 };
121
122 int main (void){
123         main_setup();
124         
125         for(;;){
126                 welcome_msg(algo_name);
127                 cmd_interface(cmdlist);
128         }
129 }