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