blob: f37b15a549c54f71b23d522ce8d38ded94f50ff0 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * Benchmark demonstration program
3 *
Paul Bakker530927b2015-02-13 14:24:10 +01004 * Copyright (C) 2006-2015, ARM Limited, All Rights Reserved
Paul Bakkerb96f1542010-07-18 20:36:00 +00005 *
Manuel Pégourié-Gonnarde12abf92015-01-28 17:13:45 +00006 * This file is part of mbed TLS (https://polarssl.org)
Paul Bakkere0ccd0a2009-01-04 16:27:10 +00007 *
Paul Bakker5121ce52009-01-03 21:22:43 +00008 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23#ifndef _CRT_SECURE_NO_DEPRECATE
24#define _CRT_SECURE_NO_DEPRECATE 1
25#endif
26
27#include <string.h>
28#include <stdlib.h>
29#include <stdio.h>
30
Paul Bakker40e46942009-01-03 21:51:57 +000031#include "polarssl/config.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000032
Paul Bakker40e46942009-01-03 21:51:57 +000033#include "polarssl/md4.h"
34#include "polarssl/md5.h"
35#include "polarssl/sha1.h"
36#include "polarssl/sha2.h"
Paul Bakker026c03b2009-03-28 17:53:03 +000037#include "polarssl/sha4.h"
Paul Bakker40e46942009-01-03 21:51:57 +000038#include "polarssl/arc4.h"
39#include "polarssl/des.h"
40#include "polarssl/aes.h"
Paul Bakker3d58fe82012-07-04 17:15:31 +000041#include "polarssl/blowfish.h"
Paul Bakker38119b12009-01-10 23:31:23 +000042#include "polarssl/camellia.h"
Paul Bakker89e80c92012-03-20 13:50:09 +000043#include "polarssl/gcm.h"
Paul Bakker40e46942009-01-03 21:51:57 +000044#include "polarssl/rsa.h"
45#include "polarssl/timing.h"
Paul Bakker02faf452011-11-29 11:23:58 +000046#include "polarssl/havege.h"
47#include "polarssl/ctr_drbg.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000048
Paul Bakker02faf452011-11-29 11:23:58 +000049#define BUFSIZE 1024
50#define HEADER_FORMAT " %-15s : "
Paul Bakker5121ce52009-01-03 21:22:43 +000051
Paul Bakkera3d195c2011-11-27 21:07:34 +000052static int myrand( void *rng_state, unsigned char *output, size_t len )
Paul Bakker5121ce52009-01-03 21:22:43 +000053{
Paul Bakkera3d195c2011-11-27 21:07:34 +000054 size_t use_len;
55 int rnd;
56
Paul Bakker5121ce52009-01-03 21:22:43 +000057 if( rng_state != NULL )
58 rng_state = NULL;
59
Paul Bakkera3d195c2011-11-27 21:07:34 +000060 while( len > 0 )
61 {
62 use_len = len;
63 if( use_len > sizeof(int) )
64 use_len = sizeof(int);
65
66 rnd = rand();
67 memcpy( output, &rnd, use_len );
68 output += use_len;
69 len -= use_len;
70 }
71
72 return( 0 );
Paul Bakker5121ce52009-01-03 21:22:43 +000073}
74
75unsigned char buf[BUFSIZE];
76
Paul Bakker5690efc2011-05-26 13:16:06 +000077#if !defined(POLARSSL_TIMING_C)
Paul Bakkercce9d772011-11-18 14:26:47 +000078int main( int argc, char *argv[] )
Paul Bakker5690efc2011-05-26 13:16:06 +000079{
Paul Bakkercce9d772011-11-18 14:26:47 +000080 ((void) argc);
81 ((void) argv);
82
Paul Bakker5690efc2011-05-26 13:16:06 +000083 printf("POLARSSL_TIMING_C not defined.\n");
84 return( 0 );
85}
86#else
Paul Bakkercce9d772011-11-18 14:26:47 +000087int main( int argc, char *argv[] )
Paul Bakker5121ce52009-01-03 21:22:43 +000088{
89 int keysize;
90 unsigned long i, j, tsc;
Paul Bakker5a0aa772009-02-09 22:38:52 +000091 unsigned char tmp[64];
Paul Bakker40e46942009-01-03 21:51:57 +000092#if defined(POLARSSL_ARC4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000093 arc4_context arc4;
94#endif
Paul Bakker40e46942009-01-03 21:51:57 +000095#if defined(POLARSSL_DES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000096 des3_context des3;
97 des_context des;
98#endif
Paul Bakker40e46942009-01-03 21:51:57 +000099#if defined(POLARSSL_AES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000100 aes_context aes;
Paul Bakker89e80c92012-03-20 13:50:09 +0000101#if defined(POLARSSL_GCM_C)
102 gcm_context gcm;
103#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000104#endif
Paul Bakker3d58fe82012-07-04 17:15:31 +0000105#if defined(POLARSSL_BLOWFISH_C)
106 blowfish_context blowfish;
107#endif
Paul Bakker38119b12009-01-10 23:31:23 +0000108#if defined(POLARSSL_CAMELLIA_C)
109 camellia_context camellia;
110#endif
Paul Bakker5690efc2011-05-26 13:16:06 +0000111#if defined(POLARSSL_RSA_C) && defined(POLARSSL_BIGNUM_C) && \
112 defined(POLARSSL_GENPRIME)
Paul Bakker5121ce52009-01-03 21:22:43 +0000113 rsa_context rsa;
114#endif
Paul Bakker02faf452011-11-29 11:23:58 +0000115#if defined(POLARSSL_HAVEGE_C)
116 havege_state hs;
117#endif
118#if defined(POLARSSL_CTR_DRBG_C)
119 ctr_drbg_context ctr_drbg;
120#endif
Paul Bakkercce9d772011-11-18 14:26:47 +0000121 ((void) argc);
122 ((void) argv);
123
Paul Bakker5121ce52009-01-03 21:22:43 +0000124 memset( buf, 0xAA, sizeof( buf ) );
Paul Bakkerd6d1f412014-04-17 16:03:48 +0200125 memset( tmp, 0xBB, sizeof( tmp ) );
Paul Bakker5121ce52009-01-03 21:22:43 +0000126
127 printf( "\n" );
128
Paul Bakker40e46942009-01-03 21:51:57 +0000129#if defined(POLARSSL_MD4_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000130 printf( HEADER_FORMAT, "MD4" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000131 fflush( stdout );
132
133 set_alarm( 1 );
134 for( i = 1; ! alarmed; i++ )
135 md4( buf, BUFSIZE, tmp );
136
137 tsc = hardclock();
138 for( j = 0; j < 1024; j++ )
139 md4( buf, BUFSIZE, tmp );
140
141 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
142 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
143#endif
144
Paul Bakker40e46942009-01-03 21:51:57 +0000145#if defined(POLARSSL_MD5_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000146 printf( HEADER_FORMAT, "MD5" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000147 fflush( stdout );
148
149 set_alarm( 1 );
150 for( i = 1; ! alarmed; i++ )
151 md5( buf, BUFSIZE, tmp );
152
153 tsc = hardclock();
154 for( j = 0; j < 1024; j++ )
155 md5( buf, BUFSIZE, tmp );
156
157 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
158 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
159#endif
160
Paul Bakker40e46942009-01-03 21:51:57 +0000161#if defined(POLARSSL_SHA1_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000162 printf( HEADER_FORMAT, "SHA-1" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000163 fflush( stdout );
164
165 set_alarm( 1 );
166 for( i = 1; ! alarmed; i++ )
167 sha1( buf, BUFSIZE, tmp );
168
169 tsc = hardclock();
170 for( j = 0; j < 1024; j++ )
171 sha1( buf, BUFSIZE, tmp );
172
173 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
174 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
175#endif
176
Paul Bakker40e46942009-01-03 21:51:57 +0000177#if defined(POLARSSL_SHA2_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000178 printf( HEADER_FORMAT, "SHA-256" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000179 fflush( stdout );
180
181 set_alarm( 1 );
182 for( i = 1; ! alarmed; i++ )
183 sha2( buf, BUFSIZE, tmp, 0 );
184
185 tsc = hardclock();
186 for( j = 0; j < 1024; j++ )
187 sha2( buf, BUFSIZE, tmp, 0 );
188
189 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
190 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
191#endif
192
Paul Bakker3a3c3c22009-02-09 22:33:30 +0000193#if defined(POLARSSL_SHA4_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000194 printf( HEADER_FORMAT, "SHA-512" );
Paul Bakker3a3c3c22009-02-09 22:33:30 +0000195 fflush( stdout );
196
197 set_alarm( 1 );
198 for( i = 1; ! alarmed; i++ )
199 sha4( buf, BUFSIZE, tmp, 0 );
200
201 tsc = hardclock();
202 for( j = 0; j < 1024; j++ )
203 sha4( buf, BUFSIZE, tmp, 0 );
204
205 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
206 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
207#endif
208
Paul Bakker40e46942009-01-03 21:51:57 +0000209#if defined(POLARSSL_ARC4_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000210 printf( HEADER_FORMAT, "ARC4" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000211 fflush( stdout );
212
213 arc4_setup( &arc4, tmp, 32 );
214
215 set_alarm( 1 );
216 for( i = 1; ! alarmed; i++ )
Paul Bakkerbaad6502010-03-21 15:42:15 +0000217 arc4_crypt( &arc4, BUFSIZE, buf, buf );
Paul Bakker5121ce52009-01-03 21:22:43 +0000218
219 tsc = hardclock();
220 for( j = 0; j < 1024; j++ )
Paul Bakkerbaad6502010-03-21 15:42:15 +0000221 arc4_crypt( &arc4, BUFSIZE, buf, buf );
Paul Bakker5121ce52009-01-03 21:22:43 +0000222
223 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
224 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
225#endif
226
Paul Bakker40e46942009-01-03 21:51:57 +0000227#if defined(POLARSSL_DES_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000228 printf( HEADER_FORMAT, "3DES" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000229 fflush( stdout );
230
231 des3_set3key_enc( &des3, tmp );
232
233 set_alarm( 1 );
234 for( i = 1; ! alarmed; i++ )
235 des3_crypt_cbc( &des3, DES_ENCRYPT, BUFSIZE, tmp, buf, buf );
236
237 tsc = hardclock();
238 for( j = 0; j < 1024; j++ )
239 des3_crypt_cbc( &des3, DES_ENCRYPT, BUFSIZE, tmp, buf, buf );
240
241 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
242 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
243
Paul Bakker02faf452011-11-29 11:23:58 +0000244 printf( HEADER_FORMAT, "DES" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000245 fflush( stdout );
246
247 des_setkey_enc( &des, tmp );
248
249 set_alarm( 1 );
250 for( i = 1; ! alarmed; i++ )
251 des_crypt_cbc( &des, DES_ENCRYPT, BUFSIZE, tmp, buf, buf );
252
253 tsc = hardclock();
254 for( j = 0; j < 1024; j++ )
255 des_crypt_cbc( &des, DES_ENCRYPT, BUFSIZE, tmp, buf, buf );
256
257 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
258 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
259#endif
260
Paul Bakker40e46942009-01-03 21:51:57 +0000261#if defined(POLARSSL_AES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000262 for( keysize = 128; keysize <= 256; keysize += 64 )
263 {
Paul Bakker89e80c92012-03-20 13:50:09 +0000264 printf( " AES-CBC-%d : ", keysize );
Paul Bakker5121ce52009-01-03 21:22:43 +0000265 fflush( stdout );
266
267 memset( buf, 0, sizeof( buf ) );
268 memset( tmp, 0, sizeof( tmp ) );
269 aes_setkey_enc( &aes, tmp, keysize );
270
271 set_alarm( 1 );
272
273 for( i = 1; ! alarmed; i++ )
274 aes_crypt_cbc( &aes, AES_ENCRYPT, BUFSIZE, tmp, buf, buf );
275
276 tsc = hardclock();
277 for( j = 0; j < 4096; j++ )
278 aes_crypt_cbc( &aes, AES_ENCRYPT, BUFSIZE, tmp, buf, buf );
279
280 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
281 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
282 }
Paul Bakker89e80c92012-03-20 13:50:09 +0000283#if defined(POLARSSL_GCM_C)
284 for( keysize = 128; keysize <= 256; keysize += 64 )
285 {
286 printf( " AES-GCM-%d : ", keysize );
287 fflush( stdout );
288
289 memset( buf, 0, sizeof( buf ) );
290 memset( tmp, 0, sizeof( tmp ) );
291 gcm_init( &gcm, tmp, keysize );
292
293 set_alarm( 1 );
294
295 for( i = 1; ! alarmed; i++ )
Paul Bakkerb78c7452012-03-20 15:05:59 +0000296 gcm_crypt_and_tag( &gcm, GCM_ENCRYPT, BUFSIZE, tmp, 12, NULL, 0, buf, buf, 16, tmp );
Paul Bakker89e80c92012-03-20 13:50:09 +0000297
298 tsc = hardclock();
299 for( j = 0; j < 4096; j++ )
Paul Bakkerb78c7452012-03-20 15:05:59 +0000300 gcm_crypt_and_tag( &gcm, GCM_ENCRYPT, BUFSIZE, tmp, 12, NULL, 0, buf, buf, 16, tmp );
Paul Bakker89e80c92012-03-20 13:50:09 +0000301
302 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
303 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
304 }
305#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000306#endif
307
Paul Bakker38119b12009-01-10 23:31:23 +0000308#if defined(POLARSSL_CAMELLIA_C)
309 for( keysize = 128; keysize <= 256; keysize += 64 )
310 {
Paul Bakker89e80c92012-03-20 13:50:09 +0000311 printf( " CAMELLIA-CBC-%d: ", keysize );
Paul Bakker38119b12009-01-10 23:31:23 +0000312 fflush( stdout );
313
314 memset( buf, 0, sizeof( buf ) );
315 memset( tmp, 0, sizeof( tmp ) );
316 camellia_setkey_enc( &camellia, tmp, keysize );
317
318 set_alarm( 1 );
319
320 for( i = 1; ! alarmed; i++ )
321 camellia_crypt_cbc( &camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf );
322
323 tsc = hardclock();
324 for( j = 0; j < 4096; j++ )
325 camellia_crypt_cbc( &camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf );
326
327 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
328 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
329 }
330#endif
331
Paul Bakker3d58fe82012-07-04 17:15:31 +0000332#if defined(POLARSSL_BLOWFISH_C)
333 for( keysize = 128; keysize <= 256; keysize += 64 )
334 {
335 printf( " BLOWFISH-CBC-%d: ", keysize );
336 fflush( stdout );
337
338 memset( buf, 0, sizeof( buf ) );
339 memset( tmp, 0, sizeof( tmp ) );
340 blowfish_setkey( &blowfish, tmp, keysize );
341
342 set_alarm( 1 );
343
344 for( i = 1; ! alarmed; i++ )
345 blowfish_crypt_cbc( &blowfish, BLOWFISH_ENCRYPT, BUFSIZE, tmp, buf, buf );
346
347 tsc = hardclock();
348 for( j = 0; j < 4096; j++ )
349 blowfish_crypt_cbc( &blowfish, BLOWFISH_ENCRYPT, BUFSIZE, tmp, buf, buf );
350
351 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
352 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
353 }
354#endif
355
Paul Bakker02faf452011-11-29 11:23:58 +0000356#if defined(POLARSSL_HAVEGE_C)
357 printf( HEADER_FORMAT, "HAVEGE" );
358 fflush( stdout );
359
360 havege_init( &hs );
361
362 set_alarm( 1 );
363 for( i = 1; ! alarmed; i++ )
364 havege_random( &hs, buf, BUFSIZE );
365
366 tsc = hardclock();
367 for( j = 1; j < 1024; j++ )
368 havege_random( &hs, buf, BUFSIZE );
369
370 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
371 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
372#endif
373
374#if defined(POLARSSL_CTR_DRBG_C)
375 printf( HEADER_FORMAT, "CTR_DRBG (NOPR)" );
376 fflush( stdout );
377
378 if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
379 exit(1);
380
381 set_alarm( 1 );
382 for( i = 1; ! alarmed; i++ )
383 if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
384 exit(1);
385
386 tsc = hardclock();
387 for( j = 1; j < 1024; j++ )
388 if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
389 exit(1);
390
391 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
392 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
393
394 printf( HEADER_FORMAT, "CTR_DRBG (PR)" );
395 fflush( stdout );
396
397 if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
398 exit(1);
399
400 ctr_drbg_set_prediction_resistance( &ctr_drbg, CTR_DRBG_PR_ON );
401
402 set_alarm( 1 );
403 for( i = 1; ! alarmed; i++ )
404 if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
405 exit(1);
406
407 tsc = hardclock();
408 for( j = 1; j < 1024; j++ )
409 if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
410 exit(1);
411
412 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
413 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
414#endif
415
Paul Bakker5690efc2011-05-26 13:16:06 +0000416#if defined(POLARSSL_RSA_C) && defined(POLARSSL_BIGNUM_C) && \
417 defined(POLARSSL_GENPRIME)
Paul Bakkera802e1a2010-08-16 11:56:45 +0000418 rsa_init( &rsa, RSA_PKCS_V15, 0 );
419 rsa_gen_key( &rsa, myrand, NULL, 1024, 65537 );
Paul Bakker5121ce52009-01-03 21:22:43 +0000420
Paul Bakker02faf452011-11-29 11:23:58 +0000421 printf( HEADER_FORMAT, "RSA-1024" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000422 fflush( stdout );
423 set_alarm( 3 );
424
425 for( i = 1; ! alarmed; i++ )
426 {
427 buf[0] = 0;
428 rsa_public( &rsa, buf, buf );
429 }
430
431 printf( "%9lu public/s\n", i / 3 );
432
Paul Bakker02faf452011-11-29 11:23:58 +0000433 printf( HEADER_FORMAT, "RSA-1024" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000434 fflush( stdout );
435 set_alarm( 3 );
436
437 for( i = 1; ! alarmed; i++ )
438 {
439 buf[0] = 0;
Paul Bakker43f97992013-09-23 11:23:31 +0200440 rsa_private( &rsa, myrand, NULL, buf, buf );
Paul Bakker5121ce52009-01-03 21:22:43 +0000441 }
442
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000443 printf( "%9lu private/s\n", i / 3 );
444
445 rsa_free( &rsa );
446
Paul Bakkera802e1a2010-08-16 11:56:45 +0000447 rsa_init( &rsa, RSA_PKCS_V15, 0 );
448 rsa_gen_key( &rsa, myrand, NULL, 2048, 65537 );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000449
Paul Bakker02faf452011-11-29 11:23:58 +0000450 printf( HEADER_FORMAT, "RSA-2048" );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000451 fflush( stdout );
452 set_alarm( 3 );
453
454 for( i = 1; ! alarmed; i++ )
455 {
456 buf[0] = 0;
457 rsa_public( &rsa, buf, buf );
458 }
459
460 printf( "%9lu public/s\n", i / 3 );
461
Paul Bakker02faf452011-11-29 11:23:58 +0000462 printf( HEADER_FORMAT, "RSA-2048" );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000463 fflush( stdout );
464 set_alarm( 3 );
465
466 for( i = 1; ! alarmed; i++ )
467 {
468 buf[0] = 0;
Paul Bakker43f97992013-09-23 11:23:31 +0200469 rsa_private( &rsa, myrand, NULL, buf, buf );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000470 }
471
472 printf( "%9lu private/s\n", i / 3 );
473
474 rsa_free( &rsa );
475
Paul Bakkera802e1a2010-08-16 11:56:45 +0000476 rsa_init( &rsa, RSA_PKCS_V15, 0 );
477 rsa_gen_key( &rsa, myrand, NULL, 4096, 65537 );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000478
Paul Bakker02faf452011-11-29 11:23:58 +0000479 printf( HEADER_FORMAT, "RSA-4096" );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000480 fflush( stdout );
481 set_alarm( 3 );
482
483 for( i = 1; ! alarmed; i++ )
484 {
485 buf[0] = 0;
486 rsa_public( &rsa, buf, buf );
487 }
488
489 printf( "%9lu public/s\n", i / 3 );
490
Paul Bakker02faf452011-11-29 11:23:58 +0000491 printf( HEADER_FORMAT, "RSA-4096" );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000492 fflush( stdout );
493 set_alarm( 3 );
494
495 for( i = 1; ! alarmed; i++ )
496 {
497 buf[0] = 0;
Paul Bakker43f97992013-09-23 11:23:31 +0200498 rsa_private( &rsa, myrand, NULL, buf, buf );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000499 }
500
501 printf( "%9lu private/s\n", i / 3 );
Paul Bakker5121ce52009-01-03 21:22:43 +0000502
503 rsa_free( &rsa );
504#endif
505
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000506 printf( "\n" );
507
Paul Bakkercce9d772011-11-18 14:26:47 +0000508#if defined(_WIN32)
Paul Bakker5121ce52009-01-03 21:22:43 +0000509 printf( " Press Enter to exit this program.\n" );
510 fflush( stdout ); getchar();
511#endif
512
513 return( 0 );
514}
Paul Bakker5690efc2011-05-26 13:16:06 +0000515#endif /* POLARSSL_TIMING_C */