1 /* hfal-performance.c */
3 This file is part of the ARM-Crypto-Lib.
4 Copyright (C) 2006-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 * \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"
33 #include "string-extras.h"
39 #define PATTERN_A 0xAA
40 #define PATTERN_B 0x55
43 void printvalue(unsigned long v){
47 for(i=0; i<10-strlen(str); ++i){
53 void hfal_performance(const hfdesc_t* hd){
55 memcpy(&hf, hd, sizeof(hfdesc_t));
56 uint8_t ctx[hf.ctxsize_B];
57 uint8_t data[(hf.blocksize_b+7)/8];
58 uint8_t digest[(hf.hashsize_b+7)/8];
62 if(hf.type!=HFDESC_TYPE_HASHFUNCTION)
66 cli_putstr("\r\n\r\n === ");
68 cli_putstr(" performance === "
69 "\r\n type: hashfunction"
70 "\r\n hashsize (bits): ");
71 printvalue(hf.hashsize_b);
73 cli_putstr("\r\n ctxsize (bytes): ");
74 printvalue(hf.ctxsize_B);
76 cli_putstr("\r\n blocksize (bits): ");
77 printvalue(hf.blocksize_b);
91 cli_putstr("\r\n init (cycles): ");
98 hf.nextBlock(&ctx, data);
103 cli_putstr("\r\n nextBlock (cycles): ");
110 hf.lastBlock(&ctx, data, 0);
115 cli_putstr("\r\n lastBlock (cycles): ");
122 hf.ctx2hash(digest, &ctx);
127 cli_putstr("\r\n ctx2hash (cycles): ");
135 void hfal_stacksize(const hfdesc_t* hd){
137 stack_measuring_ctx_t smctx;
138 memcpy(&hf, hd, sizeof(hfdesc_t));
139 uint8_t ctx[hf.ctxsize_B];
140 uint8_t data[(hf.blocksize_b+7)/8];
141 uint8_t digest[(hf.hashsize_b+7)/8];
144 if(hf.type!=HFDESC_TYPE_HASHFUNCTION)
146 cli_putstr("\r\n\r\n === ");
147 cli_putstr_P(hf.name);
148 cli_putstr(" stack-usage === ");
151 stack_measure_init(&smctx, PATTERN_A);
153 t1 = stack_measure_final(&smctx);
154 stack_measure_init(&smctx, PATTERN_B);
156 t2 = stack_measure_final(&smctx);
160 cli_putstr("\r\n init (bytes): ");
161 printvalue((unsigned long)t1);
164 stack_measure_init(&smctx, PATTERN_A);
165 hf.nextBlock(&ctx, data);
166 t1 = stack_measure_final(&smctx);
167 stack_measure_init(&smctx, PATTERN_B);
168 hf.nextBlock(&ctx, data);
169 t2 = stack_measure_final(&smctx);
173 cli_putstr("\r\n nextBlock (bytes): ");
174 printvalue((unsigned long)t1);
177 stack_measure_init(&smctx, PATTERN_A);
178 hf.lastBlock(&ctx, data, 0);
179 t1 = stack_measure_final(&smctx);
180 stack_measure_init(&smctx, PATTERN_B);
181 hf.lastBlock(&ctx, data, 0);
182 t2 = stack_measure_final(&smctx);
186 cli_putstr("\r\n lastBlock (bytes): ");
187 printvalue((unsigned long)t1);
190 stack_measure_init(&smctx, PATTERN_A);
191 hf.ctx2hash(digest, &ctx);
192 t1 = stack_measure_final(&smctx);
193 stack_measure_init(&smctx, PATTERN_B);
194 hf.ctx2hash(digest, &ctx);
195 t2 = stack_measure_final(&smctx);
199 cli_putstr("\r\n ctx2hash (bytes): ");
200 printvalue((unsigned long)t1);
208 void hfal_performance_multiple(const hfdesc_t** hd_list){
213 cli_putstr("\r\n\r\n End of performance figures\r\n");
216 hfal_performance(hd);
217 // hfal_stacksize(hd);