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
24 #include "main-test-common.h"
26 #include "mqq160-sign.h"
27 #include "mqq160-sign_P.h"
28 #include "mqq160-sign_testkey.h"
29 #include "performance_test.h"
30 #include "stack_measuring.h"
32 char* algo_name = "MQQ160-sign";
35 /*****************************************************************************
36 * additional validation-functions *
37 *****************************************************************************/
38 const uint8_t test_hash[20] PROGMEM =
40 (uint8_t)0x64, (uint8_t)0xFE, (uint8_t)0x2A, (uint8_t)0x85,
41 (uint8_t)0xBB, (uint8_t)0x8C, (uint8_t)0x54, (uint8_t)0x5C,
42 (uint8_t)0x65, (uint8_t)0x74, (uint8_t)0xA0, (uint8_t)0xF3,
43 (uint8_t)0xD0, (uint8_t)0xAF, (uint8_t)0x96, (uint8_t)0xB9,
44 (uint8_t)0x0F, (uint8_t)0x17, (uint8_t)0xF3, (uint8_t)0xAD
47 void performance_mqq(void){
49 uint8_t signature[20];
51 char str[3*sizeof(long)+2];
54 stack_measuring_ctx_t smctx;
55 memcpy_P(hash, test_hash, 20);
57 uint8_t key_buffer[MQQ160SIGN_KEY_SIZE];
58 mqq160_sign_key_t key;
59 mqq_load_pgm_key(key_buffer, &key, &testkey_P);
61 cli_putstr_P(PSTR("\r\n=== Performance of MQQ160-SIGN ==="));
65 mqq160_sign_P(signature, hash, &testkey_P);
69 cli_putstr_P(PSTR("\r\n cycles for mqq160_sign_P: "));
79 mqq160_sign(signature, hash, &key);
83 cli_putstr_P(PSTR("\r\n cycles for mqq160_sign: "));
90 stack_measure_init(&smctx, 0xAA);
91 mqq160_sign_P(signature, hash, &testkey_P);
92 s1 = stack_measure_final(&smctx);
93 stack_measure_init(&smctx, 0x55);
94 mqq160_sign_P(signature, hash, &testkey_P);
95 s2 = stack_measure_final(&smctx);
97 ltoa((long)s1, str, 10);
98 cli_putstr_P(PSTR("\r\n stack for mqq160_sign_P: "));
104 stack_measure_init(&smctx, 0xAA);
105 mqq160_sign(signature, hash, &key);
106 s1 = stack_measure_final(&smctx);
107 stack_measure_init(&smctx, 0x55);
108 mqq160_sign_P(signature, hash, &testkey_P);
109 s2 = stack_measure_final(&smctx);
111 ltoa((long)s1, str, 10);
112 cli_putstr_P(PSTR("\r\n stack for mqq160_sign: "));
113 tmp = 12-strlen(str);
119 cli_putstr_P(PSTR("\r\n=== End of performance figures ==="));
122 void testrun_mqq_mem(void){
124 uint8_t signature[20];
125 memcpy_P(hash, test_hash, 20);
127 uint8_t key_buffer[MQQ160SIGN_KEY_SIZE];
128 mqq160_sign_key_t key;
129 mqq_load_pgm_key(key_buffer, &key, &testkey_P);
130 mqq160_sign(signature, hash, &key);
131 cli_putstr_P(PSTR("\r\ntest signature (RAM): "));
132 cli_hexdump(signature, 20);
135 void testrun_mqq_flash(void){
137 uint8_t signature[20];
138 memcpy_P(hash, test_hash, 20);
140 mqq160_sign_P(signature, hash, &testkey_P);
141 cli_putstr_P(PSTR("\r\ntest signature (FLASH): "));
142 cli_hexdump(signature, 20);
145 void testrun_mqq(void){
147 uint8_t signature[20];
148 memcpy_P(hash, test_hash, 20);
150 uint8_t key_buffer[MQQ160SIGN_KEY_SIZE];
151 mqq160_sign_key_t key;
152 mqq_load_pgm_key(key_buffer, &key, &testkey_P);
153 mqq160_sign(signature, hash, &key);
154 cli_putstr_P(PSTR("\r\ntest signature (RAM): "));
155 cli_hexdump(signature, 20);
157 mqq160_sign_P(signature, hash, &testkey_P);
158 cli_putstr_P(PSTR("\r\ntest signature (FLASH): "));
159 cli_hexdump(signature, 20);
162 /*****************************************************************************
164 *****************************************************************************/
166 const char test_str[] PROGMEM = "test";
167 const char test_flash_str[] PROGMEM = "flash";
168 const char test_mem_str[] PROGMEM = "mem";
169 const char performance_str[] PROGMEM = "performance";
170 const char echo_str[] PROGMEM = "echo";
172 const cmdlist_entry_t cmdlist[] PROGMEM = {
173 { test_str, NULL, testrun_mqq },
174 { test_flash_str, NULL, testrun_mqq_flash },
175 { test_mem_str, NULL, testrun_mqq_mem },
176 { performance_str, NULL, performance_mqq },
177 { echo_str, (void*)1, (void_fpt)echo_ctrl },
185 welcome_msg(algo_name);
186 cmd_interface(cmdlist);