]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-norx-test.c
optimizing norx32
[avr-crypto-lib.git] / test_src / main-norx-test.c
1 /* main-norx-test.c */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2006-2014 Daniel Otte (daniel.otte@rub.de)
5
6     This program is free software: you can redistribute it and/or modify
7     it under the terms of the GNU General Public License as published by
8     the Free Software Foundation, either version 3 of the License, or
9     (at your option) any later version.
10
11     This program is distributed in the hope that it will be useful,
12     but WITHOUT ANY WARRANTY; without even the implied warranty of
13     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14     GNU General Public License for more details.
15
16     You should have received a copy of the GNU General Public License
17     along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 */
19
20
21 /* main-arcfour-test.c */
22 /*
23     This file is part of the AVR-Crypto-Lib.
24     Copyright (C) 2008  Daniel Otte (daniel.otte@rub.de)
25
26     This program is free software: you can redistribute it and/or modify
27     it under the terms of the GNU General Public License as published by
28     the Free Software Foundation, either version 3 of the License, or
29     (at your option) any later version.
30
31     This program is distributed in the hope that it will be useful,
32     but WITHOUT ANY WARRANTY; without even the implied warranty of
33     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
34     GNU General Public License for more details.
35
36     You should have received a copy of the GNU General Public License
37     along with this program.  If not, see <http://www.gnu.org/licenses/>.
38 */
39 /*
40  * arcfour (RC4 compatible) test-suit
41  *
42 */
43
44
45 #include "main-test-common.h"
46
47 #include <norx32.h>
48 #include "performance_test.h"
49
50 char *algo_name = "norx";
51
52 /*****************************************************************************
53  *  additional validation-functions                                          *
54  *****************************************************************************/
55
56 #define DUMP(x) do { printf("%s", "\n\n" #x ":"); \
57                     cli_hexdump_block((x), sizeof(x), 4, 16); } while (0)
58
59 #if 0
60 void g32(uint32_t *(a[4]));
61 void f32(norx32_ctx_t *ctx);
62
63
64 void g32_dump(uint32_t a, uint32_t b, uint32_t c, uint32_t d)
65 {
66     uint32_t *(x[4]) = {&a, &b, &c, &d};
67     printf("\n (a,b,c,d) = (%08lX, %08lX, %08lX, %08lX)", *(x[0]), *(x[1]), *(x[2]), *(x[3]));
68     g32(x);
69     printf("\nG(a,b,c,d) = (%08lX, %08lX, %08lX, %08lX)\n", *(x[0]), *(x[1]), *(x[2]), *(x[3]));
70 }
71
72 void testrun_g32(void)
73 {
74     uint32_t x;
75     x = 1;
76     g32_dump(0, 0, 0, 0);
77     g32_dump(x, 0, 0, 0);
78     g32_dump(0, x, 0, 0);
79     g32_dump(0, 0, x, 0);
80     g32_dump(0, 0, 0, x);
81     x = 0x80000000l;
82     g32_dump(x, 0, 0, 0);
83     g32_dump(0, x, 0, 0);
84     g32_dump(0, 0, x, 0);
85     g32_dump(0, 0, 0, x);
86     x = 0xffffffffl;
87     g32_dump(x, x, x, x);
88
89     g32_dump(0x01234567l, 0x89abcdefl, 0xfedcba98l, 0x76543210l);
90 }
91
92 void testrun_f32(void)
93 {
94     norx32_ctx_t ctx;
95     memset(ctx.s, 0, sizeof(ctx.s));
96     ctx.s[0] = 1;
97     ctx.r = 8;
98     f32(&ctx);
99 }
100 #endif
101
102 void testrun_norx32(void)
103 {
104     const uint8_t key[] = {
105         0x33, 0x22, 0x11, 0x00,
106         0x77, 0x66, 0x55, 0x44,
107         0xBB, 0xAA, 0x99, 0x88,
108         0xFF, 0xEE, 0xDD, 0xCC,
109     };
110     const uint8_t nonce[] = {
111         0xFF, 0xFF, 0xFF, 0xFF,
112         0xFF, 0xFF, 0xFF, 0xFF
113     };
114     const uint8_t header[] = {
115         0x02, 0x00, 0x00, 0x10,
116         0x04, 0x00, 0x00, 0x30,
117     };
118     const uint8_t payload[] = {
119             0x07, 0x00, 0x00, 0x80,
120             0x05, 0x00, 0x00, 0x60,
121             0x03, 0x00, 0x00, 0x40,
122             0x01, 0x00, 0x00, 0x20,
123     };
124 //    const uint8_t trailer[0];
125     uint8_t crypt[16];
126     uint8_t tag[16];
127     norx32_default_simple(
128             crypt,
129             tag,
130             key,
131             nonce,
132             header,
133             sizeof(header),
134             payload,
135             sizeof(payload),
136             NULL,
137             0 );
138     DUMP(key);
139     DUMP(nonce);
140     DUMP(header);
141     DUMP(payload);
142 //    DUMP(trailer);
143     DUMP(crypt);
144     DUMP(tag);
145 /*
146     cli_hexdump_block(crypt, sizeof(payload), 4, 16);
147     cli_hexdump_block(tag, sizeof(tag), 4, 16);
148 */
149 }
150
151
152 /*****************************************************************************
153  *  main                                                                     *
154  *****************************************************************************/
155
156 const char nessie_str[]      PROGMEM = "nessie";
157 const char test_str[]        PROGMEM = "test";
158 const char ftest_str[]       PROGMEM = "ftest";
159 const char gtest_str[]       PROGMEM = "gtest";
160 const char performance_str[] PROGMEM = "performance";
161 const char echo_str[]        PROGMEM = "echo";
162
163 const cmdlist_entry_t cmdlist[] PROGMEM = {
164 //    { nessie_str,      NULL, NULL },
165     { test_str,        NULL, testrun_norx32},
166 //    { ftest_str,       NULL, testrun_f32},
167 //    { gtest_str,       NULL, testrun_g32},
168 //    { performance_str, NULL, testrun_performance_arcfour},
169     { echo_str,    (void*)1, (void_fpt)echo_ctrl},
170     { NULL,            NULL, NULL}
171 };
172
173 int main(void) {
174     main_setup();
175
176     for(;;){
177         welcome_msg(algo_name);
178         cmd_interface(cmdlist);
179     }
180
181 }
182
183