]> git.cryptolib.org Git - avr-crypto-lib.git/blob - test_src/main-mqq160-sign-test.c
fixing E-Mail-Address & Copyright
[avr-crypto-lib.git] / test_src / main-mqq160-sign-test.c
1 /* main-mqq160-sign-test.c */
2 /*
3     This file is part of the AVR-Crypto-Lib.
4     Copyright (C) 2006-2015 Daniel Otte (bg@nerilex.org)
5
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.
10
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.
15
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/>.
18 */
19 /*
20  * MQQ160-sign test-suit
21  *
22 */
23
24 #include "main-test-common.h"
25
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"
31
32 char *algo_name = "MQQ160-sign";
33
34
35 /*****************************************************************************
36  *  additional validation-functions                                                                                      *
37  *****************************************************************************/
38 const uint8_t test_hash[20] PROGMEM =
39 {
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
45 };
46
47 void performance_mqq(void){
48         uint8_t hash[20];
49         uint8_t signature[20];
50         long t;
51         char str[3*sizeof(long)+2];
52         uint8_t tmp;
53         uint16_t s1, s2;
54         stack_measuring_ctx_t smctx;
55         memcpy_P(hash, test_hash, 20);
56
57         uint8_t key_buffer[MQQ160SIGN_KEY_SIZE];
58         mqq160_sign_key_t key;
59         mqq_load_pgm_key(key_buffer, &key, &testkey_P);
60
61         cli_putstr_P(PSTR("\r\n=== Performance of MQQ160-SIGN ==="));
62         calibrateTimer();
63         startTimer(0);
64         START_TIMER;
65         mqq160_sign_P(signature, hash, &testkey_P);
66         STOP_TIMER;
67         t = stopTimer();
68         ltoa(t, str, 10);
69         cli_putstr_P(PSTR("\r\n cycles for mqq160_sign_P: "));
70         tmp = 12-strlen(str);
71         while(tmp--){
72                 cli_putc(' ');
73         }
74         cli_putstr(str);
75
76         calibrateTimer();
77         startTimer(0);
78         START_TIMER;
79         mqq160_sign(signature, hash, &key);
80         STOP_TIMER;
81         t = stopTimer();
82         ltoa(t, str, 10);
83         cli_putstr_P(PSTR("\r\n cycles for mqq160_sign:   "));
84         tmp = 12-strlen(str);
85         while(tmp--){
86                 cli_putc(' ');
87         }
88         cli_putstr(str);
89
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);
96         s1 = (s1>s2)?s1:s2;
97         ltoa((long)s1, str, 10);
98         cli_putstr_P(PSTR("\r\n stack for mqq160_sign_P:  "));
99         tmp = 12-strlen(str);
100         while(tmp--){
101                 cli_putc(' ');
102         }
103         cli_putstr(str);
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);
110         s1 = (s1>s2)?s1:s2;
111         ltoa((long)s1, str, 10);
112         cli_putstr_P(PSTR("\r\n stack for mqq160_sign:    "));
113         tmp = 12-strlen(str);
114         while(tmp--){
115                 cli_putc(' ');
116         }
117         cli_putstr(str);
118
119         cli_putstr_P(PSTR("\r\n=== End of performance figures ==="));
120 }
121
122 void testrun_mqq_mem(void){
123         uint8_t hash[20];
124         uint8_t signature[20];
125         memcpy_P(hash, test_hash, 20);
126
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);
133 }
134
135 void testrun_mqq_flash(void){
136         uint8_t hash[20];
137         uint8_t signature[20];
138         memcpy_P(hash, test_hash, 20);
139
140         mqq160_sign_P(signature, hash, &testkey_P);
141         cli_putstr_P(PSTR("\r\ntest signature (FLASH): "));
142         cli_hexdump(signature, 20);
143 }
144
145 void testrun_mqq(void){
146         uint8_t hash[20];
147         uint8_t signature[20];
148         memcpy_P(hash, test_hash, 20);
149
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);
156
157         mqq160_sign_P(signature, hash, &testkey_P);
158         cli_putstr_P(PSTR("\r\ntest signature (FLASH): "));
159         cli_hexdump(signature, 20);
160 }
161
162 /*****************************************************************************
163  *  main                                                                                                                                         *
164  *****************************************************************************/
165
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";
171
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           },
178         { NULL,                        NULL, NULL                          }
179 };
180
181 int main (void){
182     main_setup();
183
184     for(;;){
185         welcome_msg(algo_name);
186                 cmd_interface(cmdlist);
187         }
188 }