1 /* main-salsa20-test.c */
3 This file is part of the AVR-Crypto-Lib.
4 Copyright (C) 2006-2011 Daniel Otte (daniel.otte@rub.de)
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.
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.
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/>.
28 #include "performance_test.h"
30 #include "scal_salsa20.h"
31 #include "scal-basic.h"
32 #include "scal-nessie.h"
38 char* algo_name = "Salsa20";
40 /*****************************************************************************
41 * additional validation-functions *
42 *****************************************************************************/
44 void nessie_first(void){
50 cli_putstr_P(PSTR("\r\n testing with key: "));
52 salsa20_init(key, 128, NULL, &ctx);
53 cli_putstr_P(PSTR("\r\n internal state: "));
54 cli_hexdump_block(ctx.a, 64, 4, 16);
56 cli_putstr_P(PSTR("\r\n internal state: "));
57 cli_hexdump_block(ctx.a, 64, 4, 16);
58 cli_putstr_P(PSTR("\r\n data: "));
59 cli_hexdump_block(ctx.buffer, 64, 4, 16);
64 cli_putstr_P(PSTR("\r\n testing with key: "));
66 cli_hexdump_block(ctx.a, 64, 4, 16);
67 salsa20_init(key, 128, NULL, &ctx);
68 cli_putstr_P(PSTR("\r\n internal state: "));
69 cli_hexdump_block(ctx.a, 64, 4, 16);
71 cli_putstr_P(PSTR("\r\n internal state: "));
72 cli_hexdump_block(ctx.a, 64, 4, 16);
73 cli_putstr_P(PSTR("\r\n data: "));
74 cli_hexdump_block(ctx.buffer, 64, 4, 16);
79 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
80 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
81 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
82 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
84 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
85 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
86 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
87 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
92 211,159, 13,115, 76, 55, 82,183, 3,117,222, 37,191,187,234,136,
93 49,237,179, 48, 1,106,178,219,175,199,166, 48, 86, 16,179,207,
94 31,240, 32, 63, 15, 83, 93,161,116,147, 48,113,238, 55,204, 36,
95 79,201,235, 79, 3, 81,156, 47,203, 26,244,243, 88,118,104, 54)
97 109, 42,178,168,156,240,248,238,168,196,190,203, 26,110,170,154,
98 29, 29,150, 26,150, 30,235,249,190,163,251, 48, 69,144, 51, 57,
99 118, 40,152,157,180, 57, 27, 94,107, 42,236, 35, 27,111,114,114,
100 219,236,232,135,111,155,110, 18, 24,232, 95,158,179, 19, 48,202
104 88,118,104, 54, 79,201,235, 79, 3, 81,156, 47,203, 26,244,243,
105 191,187,234,136,211,159, 13,115, 76, 55, 82,183, 3,117,222, 37,
106 86, 16,179,207, 49,237,179, 48, 1,106,178,219,175,199,166, 48,
107 238, 55,204, 36, 31,240, 32, 63, 15, 83, 93,161,116,147, 48,113)
109 179, 19, 48,202,219,236,232,135,111,155,110, 18, 24,232, 95,158,
110 26,110,170,154,109, 42,178,168,156,240,248,238,168,196,190,203,
111 69,144, 51, 57, 29, 29,150, 26,150, 30,235,249,190,163,251, 48,
112 27,111,114,114,118, 40,152,157,180, 57, 27, 94,107, 42,236, 35
116 6,124, 83,146, 38,191, 9, 50, 4,161, 47,222,122,182,223,185,
117 75, 27, 0,216, 16,122, 7, 89,162,104,101,147,213, 21, 54, 95,
118 225,253,139,176,105,132, 23,116, 76, 41,176,207,221, 34,157,108,
119 94, 94, 99, 52, 90,117, 91,220,146,190,239,143,196,176,130,186)
121 8, 18, 38,199,119, 76,215, 67,173,127,144,162,103,212,176,217,
122 192, 19,233, 33,159,197,154,160,128,243,219, 65,171,136,135,225,
123 123, 11, 68, 86,237, 82, 20,155,133,189, 9, 83,167,116,194, 78,
124 122,127,195,185,185,204,188, 90,245, 9,183,248,226, 85,245,104
128 const uint8_t Salsa20_spectest0_in[] PROGMEM = {
129 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
130 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
131 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
132 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
134 const uint8_t Salsa20_spectest0_ref[] PROGMEM = {
135 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
136 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
137 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
138 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
141 const uint8_t Salsa20_spectest1_in[] PROGMEM = {
142 211,159, 13,115, 76, 55, 82,183, 3,117,222, 37,191,187,234,136,
143 49,237,179, 48, 1,106,178,219,175,199,166, 48, 86, 16,179,207,
144 31,240, 32, 63, 15, 83, 93,161,116,147, 48,113,238, 55,204, 36,
145 79,201,235, 79, 3, 81,156, 47,203, 26,244,243, 88,118,104, 54 };
147 const uint8_t Salsa20_spectest1_ref[] PROGMEM = {
148 109, 42,178,168,156,240,248,238,168,196,190,203, 26,110,170,154,
149 29, 29,150, 26,150, 30,235,249,190,163,251, 48, 69,144, 51, 57,
150 118, 40,152,157,180, 57, 27, 94,107, 42,236, 35, 27,111,114,114,
151 219,236,232,135,111,155,110, 18, 24,232, 95,158,179, 19, 48,202 };
153 const uint8_t Salsa20_spectest2_in[] PROGMEM = {
154 88,118,104, 54, 79,201,235, 79, 3, 81,156, 47,203, 26,244,243,
155 191,187,234,136,211,159, 13,115, 76, 55, 82,183, 3,117,222, 37,
156 86, 16,179,207, 49,237,179, 48, 1,106,178,219,175,199,166, 48,
157 238, 55,204, 36, 31,240, 32, 63, 15, 83, 93,161,116,147, 48,113 };
159 const uint8_t Salsa20_spectest2_ref[] PROGMEM = {
160 179, 19, 48,202,219,236,232,135,111,155,110, 18, 24,232, 95,158,
161 26,110,170,154,109, 42,178,168,156,240,248,238,168,196,190,203,
162 69,144, 51, 57, 29, 29,150, 26,150, 30,235,249,190,163,251, 48,
163 27,111,114,114,118, 40,152,157,180, 57, 27, 94,107, 42,236, 35 };
165 const uint8_t Salsa20_spectest3_in[] PROGMEM = {
166 6,124, 83,146, 38,191, 9, 50, 4,161, 47,222,122,182,223,185,
167 75, 27, 0,216, 16,122, 7, 89,162,104,101,147,213, 21, 54, 95,
168 225,253,139,176,105,132, 23,116, 76, 41,176,207,221, 34,157,108,
169 94, 94, 99, 52, 90,117, 91,220,146,190,239,143,196,176,130,186 };
171 const uint8_t Salsa20_spectest3_ref[] PROGMEM = {
172 8, 18, 38,199,119, 76,215, 67,173,127,144,162,103,212,176,217,
173 192, 19,233, 33,159,197,154,160,128,243,219, 65,171,136,135,225,
174 123, 11, 68, 86,237, 82, 20,155,133,189, 9, 83,167,116,194, 78,
175 122,127,195,185,185,204,188, 90,245, 9,183,248,226, 85,245,104 };
178 void spec_test(void){
181 cli_putstr_P(PSTR("\r\ntesting with vectors from sepcification"));
182 cli_putstr_P(PSTR("\r\ntest 0: "));
183 memcpy_P(buffer, Salsa20_spectest0_in, 64);
184 salsa20_hash((uint32_t*)buffer);
185 if(memcmp_P(buffer, Salsa20_spectest0_ref, 64)){
186 cli_putstr_P(PSTR(" [fail]"));
188 cli_putstr_P(PSTR(" [ok]"));
191 cli_putstr_P(PSTR("\r\ntest 1: "));
192 memcpy_P(buffer, Salsa20_spectest1_in, 64);
193 salsa20_hash((uint32_t*)buffer);
194 if(memcmp_P(buffer, Salsa20_spectest1_ref, 64)){
195 cli_putstr_P(PSTR(" [fail]"));
197 cli_putstr_P(PSTR(" [ok]"));
200 cli_putstr_P(PSTR("\r\ntest 2: "));
201 memcpy_P(buffer, Salsa20_spectest2_in, 64);
202 salsa20_hash((uint32_t*)buffer);
203 if(memcmp_P(buffer, Salsa20_spectest2_ref, 64)){
204 cli_putstr_P(PSTR(" [fail]"));
206 cli_putstr_P(PSTR(" [ok]"));
212 cli_putstr_P(PSTR("\r\ntest 3: "));
213 memcpy_P(buffer, Salsa20_spectest3_in, 64);
215 if((count&0xFFFF)==0){
217 if((count&0x20FFFF)==0){
218 cli_putc('\r'); cli_putc('\n');
221 salsa20_hash((uint32_t*)buffer);
222 }while(++count<1000000);
223 if(memcmp_P(buffer, Salsa20_spectest0_ref, 64)){
224 cli_putstr_P(PSTR(" [fail]"));
226 cli_putstr_P(PSTR(" [ok]"));
230 void testrun_nessie_salsa20(void){
231 scal_nessie_set_estream(1);
232 scal_nessie_run(&salsa20_desc);
235 void testrun_performance_salsa20(void){
247 salsa20_init(key, 128, NULL, &ctx);
249 cli_putstr_P(PSTR("\r\n\tctx-gen time: "));
250 ultoa((unsigned long)t, str, 10);
256 cli_putstr_P(PSTR("\r\n\tencrypt time: "));
257 ultoa((unsigned long)t, str, 10);
260 cli_putstr_P(PSTR("\r\n"));
264 /*****************************************************************************
266 *****************************************************************************/
268 const char nessie_str[] PROGMEM = "nessie";
269 const char test_str[] PROGMEM = "test";
270 const char performance_str[] PROGMEM = "performance";
271 const char echo_str[] PROGMEM = "echo";
273 const cmdlist_entry_t cmdlist[] PROGMEM = {
274 { nessie_str, NULL, testrun_nessie_salsa20 },
275 { performance_str, NULL, testrun_performance_salsa20},
276 { test_str, NULL, spec_test},
277 { echo_str, (void*)1, (void_fpt)echo_ctrl},
284 cli_rx = (cli_rx_fpt)uart0_getc;
285 cli_tx = (cli_tx_fpt)uart0_putc;
287 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
288 cli_putstr(algo_name);
289 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
290 cmd_interface(cmdlist);