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];
143 if(hf.type!=HFDESC_TYPE_HASHFUNCTION)
145 cli_putstr_P(PSTR("\r\n\r\n === "));
146 cli_putstr_P(hf.name);
147 cli_putstr_P(PSTR(" stack-usage === "));
150 stack_measure_init(&smctx, PATTERN_A);
152 t1 = stack_measure_final(&smctx);
153 stack_measure_init(&smctx, PATTERN_B);
155 t2 = stack_measure_final(&smctx);
159 cli_putstr_P(PSTR("\r\n init (bytes): "));
160 printvalue((unsigned long)t1);
163 stack_measure_init(&smctx, PATTERN_A);
164 hf.nextBlock(&ctx, data);
165 t1 = stack_measure_final(&smctx);
166 stack_measure_init(&smctx, PATTERN_B);
167 hf.nextBlock(&ctx, data);
168 t2 = stack_measure_final(&smctx);
172 cli_putstr_P(PSTR("\r\n nextBlock (bytes): "));
173 printvalue((unsigned long)t1);
176 stack_measure_init(&smctx, PATTERN_A);
177 hf.lastBlock(&ctx, data, 0);
178 t1 = stack_measure_final(&smctx);
179 stack_measure_init(&smctx, PATTERN_B);
180 hf.lastBlock(&ctx, data, 0);
181 t2 = stack_measure_final(&smctx);
185 cli_putstr_P(PSTR("\r\n lastBlock (bytes): "));
186 printvalue((unsigned long)t1);
189 stack_measure_init(&smctx, PATTERN_A);
190 hf.ctx2hash(digest, &ctx);
191 t1 = stack_measure_final(&smctx);
192 stack_measure_init(&smctx, PATTERN_B);
193 hf.ctx2hash(digest, &ctx);
194 t2 = stack_measure_final(&smctx);
198 cli_putstr_P(PSTR("\r\n ctx2hash (bytes): "));
199 printvalue((unsigned long)t1);
206 void hfal_performance_multiple(const hfdesc_t** hd_list){
209 hd = (void*)pgm_read_word(hd_list);
211 cli_putstr_P(PSTR("\r\n\r\n End of performance figures\r\n"));
214 hfal_performance(hd);
216 hd_list = (void*)((uint8_t*)hd_list + 2);