]> git.cryptolib.org Git - arm-crypto-lib.git/blob - bcal/bcal-performance.c
adding install_headers.sh script
[arm-crypto-lib.git] / bcal / bcal-performance.c
1 /* bcal-performance.c */
2 /*
3     This file is part of the ARM-Crypto-Lib.
4     Copyright (C) 2006-2010  Daniel Otte (daniel.otte@rub.de)
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 /*
21  * \file    bcal-performance.c
22  * \author  Daniel Otte
23  * \email   daniel.otte@rub.de
24  * \date    2010-02-16
25  * \license GPLv3 or later
26  *
27  */
28
29 #include "bcal-performance.h"
30 #include "keysize_descriptor.h"
31 #include "blockcipher_descriptor.h"
32 #include "performance_test.h"
33 #include "cli.h"
34 #include <stdint.h>
35 #include <stdlib.h>
36 #include <string.h>
37
38
39 static
40 void printvalue(unsigned long v){
41         char str[20];
42         int i;
43         ultoa(v, str, 10);
44         for(i=0; i<10-strlen(str); ++i){
45                 cli_putc(' ');
46         }
47         cli_putstr(str);
48 }
49
50 void bcal_performance(const bcdesc_t* bcd){
51         bcdesc_t bc;
52         memcpy(&bc, bcd, sizeof(bcdesc_t));
53         uint8_t ctx[bc.ctxsize_B];
54         uint8_t data[(bc.blocksize_b+7)/8];
55         uint16_t keysize = get_keysize(bc.valid_keysize_desc);
56         uint8_t key[(keysize+7)/8];
57         uint64_t t;
58         uint8_t i;
59
60         if(bc.type!=BCDESC_TYPE_BLOCKCIPHER)
61                 return;
62         calibrateTimer();
63         print_overhead();
64         cli_putstr("\r\n\r\n === ");
65         cli_putstr(bc.name);
66         cli_putstr(" performance === "
67                    "\r\n    type:             blockcipher"
68                    "\r\n    keysize (bits):     ");
69         printvalue(keysize);
70
71         cli_putstr("\r\n    ctxsize (bytes):    ");
72         printvalue(bc.ctxsize_B);
73
74         cli_putstr("\r\n    blocksize (bits):   ");
75         printvalue(bc.blocksize_b);
76
77         t=0;
78         if(bc.init.init1){
79                 if((bc.flags&BC_INIT_TYPE)==BC_INIT_TYPE_1){
80                         for(i=0; i<32; ++i){
81                                 startTimer(0);
82                                 START_TIMER;
83                                 (bc.init.init1)(key, &ctx);
84                                 STOP_TIMER;
85                                 t += stopTimer();
86                                 if(i!=31 && bc.free){
87                                         bc.free(&ctx);
88                                 }
89                         }
90                 } else {
91                         for(i=0; i<32; ++i){
92                                 startTimer(0);
93                                 START_TIMER;
94                                 (bc.init.init2)(key, keysize, &ctx);
95                                 STOP_TIMER;
96                                 t += stopTimer();
97                                 if(i!=31 && bc.free){
98                                         bc.free(&ctx);
99                                 }
100                         }
101                 }
102                 t>>=5;
103                 cli_putstr("\r\n    init (cycles):      ");
104                 printvalue(t);
105         }
106
107         t=0;
108         for(i=0; i<32; ++i){
109                 startTimer(0);
110                 START_TIMER;
111                 bc.enc.enc1(data, &ctx);
112                 STOP_TIMER;
113                 t += stopTimer();
114         }
115         t>>=5;
116         cli_putstr("\r\n    encrypt (cycles):   ");
117         printvalue(t);
118
119         t=0;
120         for(i=0; i<32; ++i){
121                 startTimer(0);
122                 START_TIMER;
123                 bc.dec.dec1(data, &ctx);
124                 STOP_TIMER;
125                 t += stopTimer();
126         }
127         t>>=5;
128         cli_putstr("\r\n    decrypt (cycles):   ");
129         printvalue(t);
130
131         if(bc.free){
132                 bc.free(&ctx);
133         }
134
135 }
136
137
138 void bcal_performance_multiple(const bcdesc_t* const * bcd_list){
139         const bcdesc_t* bcd;
140         for(;;){
141                 bcd = *bcd_list;
142                 if(!bcd){
143                         cli_putstr("\r\n\r\n End of performance figures\r\n");
144                         return;
145                 }
146                 bcal_performance(bcd++);
147                 bcd_list++;
148         }
149 }