1 /* hfal-performance.c */
3 This file is part of the AVR-Crypto-Lib.
4 Copyright (C) 2009 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 * \file hfal-performance.c
22 * \email daniel.otte@rub.de
24 * \license GPLv3 or later
28 #include "hfal-performance.h"
29 #include "hashfunction_descriptor.h"
30 #include "stack_measuring.h"
32 #include "performance_test.h"
36 #include <avr/pgmspace.h>
38 #define PATTERN_A 0xAA
39 #define PATTERN_B 0x55
42 void printvalue(unsigned long v){
46 for(i=0; i<10-strlen(str); ++i){
52 void hfal_performance(const hfdesc_t* hd){
54 memcpy_P(&hf, hd, sizeof(hfdesc_t));
55 uint8_t ctx[hf.ctxsize_B];
56 uint8_t data[(hf.blocksize_b+7)/8];
57 uint8_t digest[(hf.hashsize_b+7)/8];
61 if(hf.type!=HFDESC_TYPE_HASHFUNCTION)
65 cli_putstr_P(PSTR("\r\n\r\n === "));
66 cli_putstr_P(hf.name);
67 cli_putstr_P(PSTR(" performance === "
68 "\r\n type: hashfunction"
69 "\r\n hashsize (bits): "));
70 printvalue(hf.hashsize_b);
72 cli_putstr_P(PSTR("\r\n ctxsize (bytes): "));
73 printvalue(hf.ctxsize_B);
75 cli_putstr_P(PSTR("\r\n blocksize (bits): "));
76 printvalue(hf.blocksize_b);
90 cli_putstr_P(PSTR("\r\n init (cycles): "));
97 hf.nextBlock(&ctx, data);
102 cli_putstr_P(PSTR("\r\n nextBlock (cycles): "));
109 hf.lastBlock(&ctx, data, 0);
114 cli_putstr_P(PSTR("\r\n lastBlock (cycles): "));
121 hf.ctx2hash(digest, &ctx);
126 cli_putstr_P(PSTR("\r\n ctx2hash (cycles): "));
134 void hfal_stacksize(const hfdesc_t* hd){
136 stack_measuring_ctx_t smctx;
137 memcpy_P(&hf, hd, sizeof(hfdesc_t));
138 uint8_t ctx[hf.ctxsize_B];
139 uint8_t data[(hf.blocksize_b+7)/8];
140 uint8_t digest[(hf.hashsize_b+7)/8];
144 if(hf.type!=HFDESC_TYPE_HASHFUNCTION)
146 cli_putstr_P(PSTR("\r\n\r\n === "));
147 cli_putstr_P(hf.name);
148 cli_putstr_P(PSTR(" stack-usage === "
149 "\r\n type: hashfunction"
150 "\r\n hashsize (bits): "));
151 printvalue(hf.hashsize_b);
153 cli_putstr_P(PSTR("\r\n ctxsize (bytes): "));
154 printvalue(hf.ctxsize_B);
156 cli_putstr_P(PSTR("\r\n blocksize (bits): "));
157 printvalue(hf.blocksize_b);
160 stack_measure_init(&smctx, PATTERN_A);
162 t1 = stack_measure_final(&smctx);
163 stack_measure_init(&smctx, PATTERN_B);
165 t1 = stack_measure_final(&smctx);
169 cli_putstr_P(PSTR("\r\n init (bytes): "));
170 printvalue((unsigned long)t1);
173 stack_measure_init(&smctx, PATTERN_A);
174 hf.nextBlock(&ctx, data);
175 t1 = stack_measure_final(&smctx);
176 stack_measure_init(&smctx, PATTERN_B);
177 hf.nextBlock(&ctx, data);
178 t1 = stack_measure_final(&smctx);
182 cli_putstr_P(PSTR("\r\n nextBlock (bytes): "));
183 printvalue((unsigned long)t1);
186 stack_measure_init(&smctx, PATTERN_A);
187 hf.lastBlock(&ctx, data, 0);
188 t1 = stack_measure_final(&smctx);
189 stack_measure_init(&smctx, PATTERN_B);
190 hf.lastBlock(&ctx, data, 0);
191 t1 = stack_measure_final(&smctx);
195 cli_putstr_P(PSTR("\r\n lastBlock (bytes): "));
196 printvalue((unsigned long)t1);
199 stack_measure_init(&smctx, PATTERN_A);
200 hf.ctx2hash(digest, &ctx);
201 t1 = stack_measure_final(&smctx);
202 stack_measure_init(&smctx, PATTERN_B);
203 hf.ctx2hash(digest, &ctx);
204 t1 = stack_measure_final(&smctx);
208 cli_putstr_P(PSTR("\r\n ctx2hash (bytes): "));
209 printvalue((unsigned long)t1);
216 void hfal_performance_multiple(const hfdesc_t** hd_list){
219 hd = (void*)pgm_read_word(hd_list);
221 cli_putstr_P(PSTR("\r\n\r\n End of performance figures\r\n"));
224 hfal_performance(hd);
226 hd_list = (void*)((uint8_t*)hd_list + 2);