1 /* main-mqq160-sign-test.c */
3 This file is part of the AVR-Crypto-Lib.
4 Copyright (C) 2010 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/>.
20 * MQQ160-sign test-suit
29 #include "mqq160-sign.h"
30 #include "mqq160-sign_P.h"
31 #include "mqq160-sign_testkey.h"
32 #include "performance_test.h"
36 #include <avr/pgmspace.h>
37 #include "stack_measuring.h"
39 char* algo_name = "MQQ160-sign";
42 /*****************************************************************************
43 * additional validation-functions *
44 *****************************************************************************/
45 uint8_t test_hash[20] PROGMEM =
47 (uint8_t)0x64, (uint8_t)0xFE, (uint8_t)0x2A, (uint8_t)0x85,
48 (uint8_t)0xBB, (uint8_t)0x8C, (uint8_t)0x54, (uint8_t)0x5C,
49 (uint8_t)0x65, (uint8_t)0x74, (uint8_t)0xA0, (uint8_t)0xF3,
50 (uint8_t)0xD0, (uint8_t)0xAF, (uint8_t)0x96, (uint8_t)0xB9,
51 (uint8_t)0x0F, (uint8_t)0x17, (uint8_t)0xF3, (uint8_t)0xAD
54 void performance_mqq(void){
56 uint8_t signature[20];
58 char str[3*sizeof(long)+2];
61 stack_measuring_ctx_t smctx;
62 memcpy_P(hash, test_hash, 20);
64 uint8_t key_buffer[MQQ160SIGN_KEY_SIZE];
65 mqq160_sign_key_t key;
66 mqq_load_pgm_key(key_buffer, &key, &testkey_P);
68 cli_putstr_P(PSTR("\r\n=== Performance of MQQ160-SIGN ==="));
72 mqq160_sign_P(signature, hash, &testkey_P);
76 cli_putstr_P(PSTR("\r\n cycles for mqq160_sign_P: "));
86 mqq160_sign(signature, hash, &key);
90 cli_putstr_P(PSTR("\r\n cycles for mqq160_sign: "));
97 stack_measure_init(&smctx, 0xAA);
98 mqq160_sign_P(signature, hash, &testkey_P);
99 s1 = stack_measure_final(&smctx);
100 stack_measure_init(&smctx, 0x55);
101 mqq160_sign_P(signature, hash, &testkey_P);
102 s2 = stack_measure_final(&smctx);
104 ltoa((long)s1, str, 10);
105 cli_putstr_P(PSTR("\r\n stack for mqq160_sign_P: "));
106 tmp = 12-strlen(str);
111 stack_measure_init(&smctx, 0xAA);
112 mqq160_sign(signature, hash, &key);
113 s1 = stack_measure_final(&smctx);
114 stack_measure_init(&smctx, 0x55);
115 mqq160_sign_P(signature, hash, &testkey_P);
116 s2 = stack_measure_final(&smctx);
118 ltoa((long)s1, str, 10);
119 cli_putstr_P(PSTR("\r\n stack for mqq160_sign: "));
120 tmp = 12-strlen(str);
126 cli_putstr_P(PSTR("\r\n=== End of performance figures ==="));
129 void testrun_mqq_mem(void){
131 uint8_t signature[20];
132 memcpy_P(hash, test_hash, 20);
134 uint8_t key_buffer[MQQ160SIGN_KEY_SIZE];
135 mqq160_sign_key_t key;
136 mqq_load_pgm_key(key_buffer, &key, &testkey_P);
137 mqq160_sign(signature, hash, &key);
138 cli_putstr_P(PSTR("\r\ntest signature (RAM): "));
139 cli_hexdump(signature, 20);
142 void testrun_mqq_flash(void){
144 uint8_t signature[20];
145 memcpy_P(hash, test_hash, 20);
147 mqq160_sign_P(signature, hash, &testkey_P);
148 cli_putstr_P(PSTR("\r\ntest signature (FLASH): "));
149 cli_hexdump(signature, 20);
152 void testrun_mqq(void){
154 uint8_t signature[20];
155 memcpy_P(hash, test_hash, 20);
157 uint8_t key_buffer[MQQ160SIGN_KEY_SIZE];
158 mqq160_sign_key_t key;
159 mqq_load_pgm_key(key_buffer, &key, &testkey_P);
160 mqq160_sign(signature, hash, &key);
161 cli_putstr_P(PSTR("\r\ntest signature (RAM): "));
162 cli_hexdump(signature, 20);
164 mqq160_sign_P(signature, hash, &testkey_P);
165 cli_putstr_P(PSTR("\r\ntest signature (FLASH): "));
166 cli_hexdump(signature, 20);
169 /*****************************************************************************
171 *****************************************************************************/
173 const char test_str[] PROGMEM = "test";
174 const char test_flash_str[] PROGMEM = "flash";
175 const char test_mem_str[] PROGMEM = "mem";
176 const char performance_str[] PROGMEM = "performance";
177 const char echo_str[] PROGMEM = "echo";
179 cmdlist_entry_t cmdlist[] PROGMEM = {
180 { test_str, NULL, testrun_mqq },
181 { test_flash_str, NULL, testrun_mqq_flash },
182 { test_mem_str, NULL, testrun_mqq_mem },
183 { performance_str, NULL, performance_mqq },
184 { echo_str, (void*)1, (void_fpt)echo_ctrl },
191 cli_rx = (cli_rx_fpt)uart0_getc;
192 cli_tx = (cli_tx_fpt)uart0_putc;
194 cli_putstr_P(PSTR("\r\n\r\nCrypto-VS ("));
195 cli_putstr(algo_name);
196 cli_putstr_P(PSTR("; "));
197 cli_putstr(__DATE__);
198 cli_putstr_P(PSTR(" "));
199 cli_putstr(__TIME__);
200 cli_putstr_P(PSTR(")\r\nloaded and running\r\n"));
202 cmd_interface(cmdlist);