]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-norx-test.c
27e95979a282d175f47dbd9721af7d4090310fce
[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 void g32(uint32_t *(a[4]));
60 void f32(norx32_ctx_t *ctx);
61
62
63 void g32_dump(uint32_t a, uint32_t b, uint32_t c, uint32_t d)
64 {
65     uint32_t *(x[4]) = {&a, &b, &c, &d};
66     printf("\n (a,b,c,d) = (%08lX, %08lX, %08lX, %08lX)", *(x[0]), *(x[1]), *(x[2]), *(x[3]));
67     g32(x);
68     printf("\nG(a,b,c,d) = (%08lX, %08lX, %08lX, %08lX)\n", *(x[0]), *(x[1]), *(x[2]), *(x[3]));
69 }
70
71 void testrun_g32(void)
72 {
73     uint32_t x;
74     x = 1;
75     g32_dump(0, 0, 0, 0);
76     g32_dump(x, 0, 0, 0);
77     g32_dump(0, x, 0, 0);
78     g32_dump(0, 0, x, 0);
79     g32_dump(0, 0, 0, x);
80     x = 0x80000000l;
81     g32_dump(x, 0, 0, 0);
82     g32_dump(0, x, 0, 0);
83     g32_dump(0, 0, x, 0);
84     g32_dump(0, 0, 0, x);
85     x = 0xffffffffl;
86     g32_dump(x, x, x, x);
87
88     g32_dump(0x01234567l, 0x89abcdefl, 0xfedcba98l, 0x76543210l);
89 }
90
91 void testrun_f32(void)
92 {
93     norx32_ctx_t ctx;
94     memset(ctx.s, 0, sizeof(ctx.s));
95     ctx.s[0] = 1;
96     ctx.r = 8;
97     f32(&ctx);
98 }
99
100 void testrun_norx32(void)
101 {
102     const uint8_t key[] = {
103         0x33, 0x22, 0x11, 0x00,
104         0x77, 0x66, 0x55, 0x44,
105         0xBB, 0xAA, 0x99, 0x88,
106         0xFF, 0xEE, 0xDD, 0xCC,
107     };
108     const uint8_t nonce[] = {
109         0xFF, 0xFF, 0xFF, 0xFF,
110         0xFF, 0xFF, 0xFF, 0xFF
111     };
112     const uint8_t header[] = {
113         0x02, 0x00, 0x00, 0x10,
114         0x04, 0x00, 0x00, 0x30,
115     };
116     const uint8_t payload[] = {
117             0x07, 0x00, 0x00, 0x80,
118             0x05, 0x00, 0x00, 0x60,
119             0x03, 0x00, 0x00, 0x40,
120             0x01, 0x00, 0x00, 0x20,
121     };
122 //    const uint8_t trailer[0];
123     uint8_t crypt[16];
124     uint8_t tag[16];
125     norx32_default_simple(
126             crypt,
127             tag,
128             key,
129             nonce,
130             header,
131             sizeof(header),
132             payload,
133             sizeof(payload),
134             NULL,
135             0 );
136     DUMP(key);
137     DUMP(nonce);
138     DUMP(header);
139     DUMP(payload);
140 //    DUMP(trailer);
141     DUMP(crypt);
142     DUMP(tag);
143 /*
144     cli_hexdump_block(crypt, sizeof(payload), 4, 16);
145     cli_hexdump_block(tag, sizeof(tag), 4, 16);
146 */
147 }
148
149
150 /*****************************************************************************
151  *  main                                                                     *
152  *****************************************************************************/
153
154 const char nessie_str[]      PROGMEM = "nessie";
155 const char test_str[]        PROGMEM = "test";
156 const char ftest_str[]       PROGMEM = "ftest";
157 const char gtest_str[]       PROGMEM = "gtest";
158 const char performance_str[] PROGMEM = "performance";
159 const char echo_str[]        PROGMEM = "echo";
160
161 const cmdlist_entry_t cmdlist[] PROGMEM = {
162 //    { nessie_str,      NULL, NULL },
163     { test_str,        NULL, testrun_norx32},
164     { ftest_str,       NULL, testrun_f32},
165     { gtest_str,       NULL, testrun_g32},
166 //    { performance_str, NULL, testrun_performance_arcfour},
167     { echo_str,    (void*)1, (void_fpt)echo_ctrl},
168     { NULL,            NULL, NULL}
169 };
170
171 int main(void) {
172     main_setup();
173
174     for(;;){
175         welcome_msg(algo_name);
176         cmd_interface(cmdlist);
177     }
178
179 }
180
181