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