1 /* bcal-performance.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/>.
21 * \file bcal-performance.c
23 * \email daniel.otte@rub.de
25 * \license GPLv3 or later
29 #include "bcal-performance.h"
30 #include "keysize_descriptor.h"
31 #include "blockcipher_descriptor.h"
32 #include "performance_test.h"
37 #include <avr/pgmspace.h>
43 void printvalue(unsigned long v){
47 for(i=0; i<10-strlen(str); ++i){
53 void bcal_performance(const bcdesc_t* bcd){
55 memcpy_P(&bc, bcd, sizeof(bcdesc_t));
56 uint8_t ctx[bc.ctxsize_B];
57 uint8_t data[(bc.blocksize_b+7)/8];
58 uint16_t keysize = get_keysize(bc.valid_keysize_desc);
59 uint8_t key[(keysize+7)/8];
63 if(bc.type!=BCDESC_TYPE_BLOCKCIPHER)
67 cli_putstr_P(PSTR("\r\n\r\n === "));
68 cli_putstr_P(bc.name);
69 cli_putstr_P(PSTR(" performance === "
70 "\r\n type: blockcipher"
71 "\r\n keysize (bits): "));
74 cli_putstr_P(PSTR("\r\n ctxsize (bytes): "));
75 printvalue(bc.ctxsize_B);
77 cli_putstr_P(PSTR("\r\n blocksize (bits): "));
78 printvalue(bc.blocksize_b);
84 if((bc.flags&BC_INIT_TYPE)==BC_INIT_TYPE_1){
88 (bc.init.init1)(key, &ctx);
99 (bc.init.init2)(key, keysize, &ctx);
102 if(i!=31 && bc.free){
108 cli_putstr_P(PSTR("\r\n init (cycles): "));
115 bc.enc.enc1(data, &ctx);
120 cli_putstr_P(PSTR("\r\n encrypt (cycles): "));
127 bc.dec.dec1(data, &ctx);
132 cli_putstr_P(PSTR("\r\n decrypt (cycles): "));
141 void bcal_performance_multiple(const bcdesc_t** bcd_list){
144 bcd = (void*)pgm_read_word(bcd_list);
146 cli_putstr_P(PSTR("\r\n\r\n End of performance figures\r\n"));
149 bcal_performance(bcd);
150 bcd_list = (void*)((uint8_t*)bcd_list + 2);