blob: 86de2c63cebc4a3c731d5cbddc5c92385dd23f49 [file] [log] [blame]
Paul Bakker5121ce52009-01-03 21:22:43 +00001/*
2 * Benchmark demonstration program
3 *
Paul Bakkercce9d772011-11-18 14:26:47 +00004 * Copyright (C) 2006-2011, Brainspark B.V.
Paul Bakkerb96f1542010-07-18 20:36:00 +00005 *
6 * This file is part of PolarSSL (http://www.polarssl.org)
Paul Bakker84f12b72010-07-18 10:13:04 +00007 * Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
Paul Bakkerb96f1542010-07-18 20:36:00 +00008 *
Paul Bakker77b385e2009-07-28 17:23:11 +00009 * All rights reserved.
Paul Bakkere0ccd0a2009-01-04 16:27:10 +000010 *
Paul Bakker5121ce52009-01-03 21:22:43 +000011 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License along
22 * with this program; if not, write to the Free Software Foundation, Inc.,
23 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 */
25
26#ifndef _CRT_SECURE_NO_DEPRECATE
27#define _CRT_SECURE_NO_DEPRECATE 1
28#endif
29
30#include <string.h>
31#include <stdlib.h>
32#include <stdio.h>
33
Paul Bakker40e46942009-01-03 21:51:57 +000034#include "polarssl/config.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000035
Paul Bakker40e46942009-01-03 21:51:57 +000036#include "polarssl/md4.h"
37#include "polarssl/md5.h"
38#include "polarssl/sha1.h"
39#include "polarssl/sha2.h"
Paul Bakker026c03b2009-03-28 17:53:03 +000040#include "polarssl/sha4.h"
Paul Bakker40e46942009-01-03 21:51:57 +000041#include "polarssl/arc4.h"
42#include "polarssl/des.h"
43#include "polarssl/aes.h"
Paul Bakker3d58fe82012-07-04 17:15:31 +000044#include "polarssl/blowfish.h"
Paul Bakker38119b12009-01-10 23:31:23 +000045#include "polarssl/camellia.h"
Paul Bakker89e80c92012-03-20 13:50:09 +000046#include "polarssl/gcm.h"
Paul Bakker40e46942009-01-03 21:51:57 +000047#include "polarssl/rsa.h"
48#include "polarssl/timing.h"
Paul Bakker02faf452011-11-29 11:23:58 +000049#include "polarssl/havege.h"
50#include "polarssl/ctr_drbg.h"
Paul Bakker5121ce52009-01-03 21:22:43 +000051
Paul Bakker02faf452011-11-29 11:23:58 +000052#define BUFSIZE 1024
53#define HEADER_FORMAT " %-15s : "
Paul Bakker5121ce52009-01-03 21:22:43 +000054
Paul Bakkera3d195c2011-11-27 21:07:34 +000055static int myrand( void *rng_state, unsigned char *output, size_t len )
Paul Bakker5121ce52009-01-03 21:22:43 +000056{
Paul Bakkera3d195c2011-11-27 21:07:34 +000057 size_t use_len;
58 int rnd;
59
Paul Bakker5121ce52009-01-03 21:22:43 +000060 if( rng_state != NULL )
61 rng_state = NULL;
62
Paul Bakkera3d195c2011-11-27 21:07:34 +000063 while( len > 0 )
64 {
65 use_len = len;
66 if( use_len > sizeof(int) )
67 use_len = sizeof(int);
68
69 rnd = rand();
70 memcpy( output, &rnd, use_len );
71 output += use_len;
72 len -= use_len;
73 }
74
75 return( 0 );
Paul Bakker5121ce52009-01-03 21:22:43 +000076}
77
78unsigned char buf[BUFSIZE];
79
Paul Bakker5690efc2011-05-26 13:16:06 +000080#if !defined(POLARSSL_TIMING_C)
Paul Bakkercce9d772011-11-18 14:26:47 +000081int main( int argc, char *argv[] )
Paul Bakker5690efc2011-05-26 13:16:06 +000082{
Paul Bakkercce9d772011-11-18 14:26:47 +000083 ((void) argc);
84 ((void) argv);
85
Paul Bakker5690efc2011-05-26 13:16:06 +000086 printf("POLARSSL_TIMING_C not defined.\n");
87 return( 0 );
88}
89#else
Paul Bakkercce9d772011-11-18 14:26:47 +000090int main( int argc, char *argv[] )
Paul Bakker5121ce52009-01-03 21:22:43 +000091{
92 int keysize;
93 unsigned long i, j, tsc;
Paul Bakker5a0aa772009-02-09 22:38:52 +000094 unsigned char tmp[64];
Paul Bakker40e46942009-01-03 21:51:57 +000095#if defined(POLARSSL_ARC4_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000096 arc4_context arc4;
97#endif
Paul Bakker40e46942009-01-03 21:51:57 +000098#if defined(POLARSSL_DES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +000099 des3_context des3;
100 des_context des;
101#endif
Paul Bakker40e46942009-01-03 21:51:57 +0000102#if defined(POLARSSL_AES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000103 aes_context aes;
Paul Bakker89e80c92012-03-20 13:50:09 +0000104#if defined(POLARSSL_GCM_C)
105 gcm_context gcm;
106#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000107#endif
Paul Bakker3d58fe82012-07-04 17:15:31 +0000108#if defined(POLARSSL_BLOWFISH_C)
109 blowfish_context blowfish;
110#endif
Paul Bakker38119b12009-01-10 23:31:23 +0000111#if defined(POLARSSL_CAMELLIA_C)
112 camellia_context camellia;
113#endif
Paul Bakker5690efc2011-05-26 13:16:06 +0000114#if defined(POLARSSL_RSA_C) && defined(POLARSSL_BIGNUM_C) && \
115 defined(POLARSSL_GENPRIME)
Paul Bakker5121ce52009-01-03 21:22:43 +0000116 rsa_context rsa;
117#endif
Paul Bakker02faf452011-11-29 11:23:58 +0000118#if defined(POLARSSL_HAVEGE_C)
119 havege_state hs;
120#endif
121#if defined(POLARSSL_CTR_DRBG_C)
122 ctr_drbg_context ctr_drbg;
123#endif
Paul Bakkercce9d772011-11-18 14:26:47 +0000124 ((void) argc);
125 ((void) argv);
126
Paul Bakker5121ce52009-01-03 21:22:43 +0000127 memset( buf, 0xAA, sizeof( buf ) );
128
129 printf( "\n" );
130
Paul Bakker40e46942009-01-03 21:51:57 +0000131#if defined(POLARSSL_MD4_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000132 printf( HEADER_FORMAT, "MD4" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000133 fflush( stdout );
134
135 set_alarm( 1 );
136 for( i = 1; ! alarmed; i++ )
137 md4( buf, BUFSIZE, tmp );
138
139 tsc = hardclock();
140 for( j = 0; j < 1024; j++ )
141 md4( buf, BUFSIZE, tmp );
142
143 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
144 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
145#endif
146
Paul Bakker40e46942009-01-03 21:51:57 +0000147#if defined(POLARSSL_MD5_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000148 printf( HEADER_FORMAT, "MD5" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000149 fflush( stdout );
150
151 set_alarm( 1 );
152 for( i = 1; ! alarmed; i++ )
153 md5( buf, BUFSIZE, tmp );
154
155 tsc = hardclock();
156 for( j = 0; j < 1024; j++ )
157 md5( buf, BUFSIZE, tmp );
158
159 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
160 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
161#endif
162
Paul Bakker40e46942009-01-03 21:51:57 +0000163#if defined(POLARSSL_SHA1_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000164 printf( HEADER_FORMAT, "SHA-1" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000165 fflush( stdout );
166
167 set_alarm( 1 );
168 for( i = 1; ! alarmed; i++ )
169 sha1( buf, BUFSIZE, tmp );
170
171 tsc = hardclock();
172 for( j = 0; j < 1024; j++ )
173 sha1( buf, BUFSIZE, tmp );
174
175 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
176 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
177#endif
178
Paul Bakker40e46942009-01-03 21:51:57 +0000179#if defined(POLARSSL_SHA2_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000180 printf( HEADER_FORMAT, "SHA-256" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000181 fflush( stdout );
182
183 set_alarm( 1 );
184 for( i = 1; ! alarmed; i++ )
185 sha2( buf, BUFSIZE, tmp, 0 );
186
187 tsc = hardclock();
188 for( j = 0; j < 1024; j++ )
189 sha2( buf, BUFSIZE, tmp, 0 );
190
191 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
192 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
193#endif
194
Paul Bakker3a3c3c22009-02-09 22:33:30 +0000195#if defined(POLARSSL_SHA4_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000196 printf( HEADER_FORMAT, "SHA-512" );
Paul Bakker3a3c3c22009-02-09 22:33:30 +0000197 fflush( stdout );
198
199 set_alarm( 1 );
200 for( i = 1; ! alarmed; i++ )
201 sha4( buf, BUFSIZE, tmp, 0 );
202
203 tsc = hardclock();
204 for( j = 0; j < 1024; j++ )
205 sha4( buf, BUFSIZE, tmp, 0 );
206
207 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
208 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
209#endif
210
Paul Bakker40e46942009-01-03 21:51:57 +0000211#if defined(POLARSSL_ARC4_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000212 printf( HEADER_FORMAT, "ARC4" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000213 fflush( stdout );
214
215 arc4_setup( &arc4, tmp, 32 );
216
217 set_alarm( 1 );
218 for( i = 1; ! alarmed; i++ )
Paul Bakkerbaad6502010-03-21 15:42:15 +0000219 arc4_crypt( &arc4, BUFSIZE, buf, buf );
Paul Bakker5121ce52009-01-03 21:22:43 +0000220
221 tsc = hardclock();
222 for( j = 0; j < 1024; j++ )
Paul Bakkerbaad6502010-03-21 15:42:15 +0000223 arc4_crypt( &arc4, BUFSIZE, buf, buf );
Paul Bakker5121ce52009-01-03 21:22:43 +0000224
225 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
226 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
227#endif
228
Paul Bakker40e46942009-01-03 21:51:57 +0000229#if defined(POLARSSL_DES_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000230 printf( HEADER_FORMAT, "3DES" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000231 fflush( stdout );
232
233 des3_set3key_enc( &des3, tmp );
234
235 set_alarm( 1 );
236 for( i = 1; ! alarmed; i++ )
237 des3_crypt_cbc( &des3, DES_ENCRYPT, BUFSIZE, tmp, buf, buf );
238
239 tsc = hardclock();
240 for( j = 0; j < 1024; j++ )
241 des3_crypt_cbc( &des3, DES_ENCRYPT, BUFSIZE, tmp, buf, buf );
242
243 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
244 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
245
Paul Bakker02faf452011-11-29 11:23:58 +0000246 printf( HEADER_FORMAT, "DES" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000247 fflush( stdout );
248
249 des_setkey_enc( &des, tmp );
250
251 set_alarm( 1 );
252 for( i = 1; ! alarmed; i++ )
253 des_crypt_cbc( &des, DES_ENCRYPT, BUFSIZE, tmp, buf, buf );
254
255 tsc = hardclock();
256 for( j = 0; j < 1024; j++ )
257 des_crypt_cbc( &des, DES_ENCRYPT, BUFSIZE, tmp, buf, buf );
258
259 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
260 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
261#endif
262
Paul Bakker40e46942009-01-03 21:51:57 +0000263#if defined(POLARSSL_AES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000264 for( keysize = 128; keysize <= 256; keysize += 64 )
265 {
Paul Bakker89e80c92012-03-20 13:50:09 +0000266 printf( " AES-CBC-%d : ", keysize );
Paul Bakker5121ce52009-01-03 21:22:43 +0000267 fflush( stdout );
268
269 memset( buf, 0, sizeof( buf ) );
270 memset( tmp, 0, sizeof( tmp ) );
271 aes_setkey_enc( &aes, tmp, keysize );
272
273 set_alarm( 1 );
274
275 for( i = 1; ! alarmed; i++ )
276 aes_crypt_cbc( &aes, AES_ENCRYPT, BUFSIZE, tmp, buf, buf );
277
278 tsc = hardclock();
279 for( j = 0; j < 4096; j++ )
280 aes_crypt_cbc( &aes, AES_ENCRYPT, BUFSIZE, tmp, buf, buf );
281
282 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
283 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
284 }
Paul Bakker89e80c92012-03-20 13:50:09 +0000285#if defined(POLARSSL_GCM_C)
286 for( keysize = 128; keysize <= 256; keysize += 64 )
287 {
288 printf( " AES-GCM-%d : ", keysize );
289 fflush( stdout );
290
291 memset( buf, 0, sizeof( buf ) );
292 memset( tmp, 0, sizeof( tmp ) );
293 gcm_init( &gcm, tmp, keysize );
294
295 set_alarm( 1 );
296
297 for( i = 1; ! alarmed; i++ )
Paul Bakkerb78c7452012-03-20 15:05:59 +0000298 gcm_crypt_and_tag( &gcm, GCM_ENCRYPT, BUFSIZE, tmp, 12, NULL, 0, buf, buf, 16, tmp );
Paul Bakker89e80c92012-03-20 13:50:09 +0000299
300 tsc = hardclock();
301 for( j = 0; j < 4096; j++ )
Paul Bakkerb78c7452012-03-20 15:05:59 +0000302 gcm_crypt_and_tag( &gcm, GCM_ENCRYPT, BUFSIZE, tmp, 12, NULL, 0, buf, buf, 16, tmp );
Paul Bakker89e80c92012-03-20 13:50:09 +0000303
304 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
305 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
306 }
307#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000308#endif
309
Paul Bakker38119b12009-01-10 23:31:23 +0000310#if defined(POLARSSL_CAMELLIA_C)
311 for( keysize = 128; keysize <= 256; keysize += 64 )
312 {
Paul Bakker89e80c92012-03-20 13:50:09 +0000313 printf( " CAMELLIA-CBC-%d: ", keysize );
Paul Bakker38119b12009-01-10 23:31:23 +0000314 fflush( stdout );
315
316 memset( buf, 0, sizeof( buf ) );
317 memset( tmp, 0, sizeof( tmp ) );
318 camellia_setkey_enc( &camellia, tmp, keysize );
319
320 set_alarm( 1 );
321
322 for( i = 1; ! alarmed; i++ )
323 camellia_crypt_cbc( &camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf );
324
325 tsc = hardclock();
326 for( j = 0; j < 4096; j++ )
327 camellia_crypt_cbc( &camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf );
328
329 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
330 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
331 }
332#endif
333
Paul Bakker3d58fe82012-07-04 17:15:31 +0000334#if defined(POLARSSL_BLOWFISH_C)
335 for( keysize = 128; keysize <= 256; keysize += 64 )
336 {
337 printf( " BLOWFISH-CBC-%d: ", keysize );
338 fflush( stdout );
339
340 memset( buf, 0, sizeof( buf ) );
341 memset( tmp, 0, sizeof( tmp ) );
342 blowfish_setkey( &blowfish, tmp, keysize );
343
344 set_alarm( 1 );
345
346 for( i = 1; ! alarmed; i++ )
347 blowfish_crypt_cbc( &blowfish, BLOWFISH_ENCRYPT, BUFSIZE, tmp, buf, buf );
348
349 tsc = hardclock();
350 for( j = 0; j < 4096; j++ )
351 blowfish_crypt_cbc( &blowfish, BLOWFISH_ENCRYPT, BUFSIZE, tmp, buf, buf );
352
353 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
354 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
355 }
356#endif
357
Paul Bakker02faf452011-11-29 11:23:58 +0000358#if defined(POLARSSL_HAVEGE_C)
359 printf( HEADER_FORMAT, "HAVEGE" );
360 fflush( stdout );
361
362 havege_init( &hs );
363
364 set_alarm( 1 );
365 for( i = 1; ! alarmed; i++ )
366 havege_random( &hs, buf, BUFSIZE );
367
368 tsc = hardclock();
369 for( j = 1; j < 1024; j++ )
370 havege_random( &hs, buf, BUFSIZE );
371
372 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
373 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
374#endif
375
376#if defined(POLARSSL_CTR_DRBG_C)
377 printf( HEADER_FORMAT, "CTR_DRBG (NOPR)" );
378 fflush( stdout );
379
380 if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
381 exit(1);
382
383 set_alarm( 1 );
384 for( i = 1; ! alarmed; i++ )
385 if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
386 exit(1);
387
388 tsc = hardclock();
389 for( j = 1; j < 1024; j++ )
390 if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
391 exit(1);
392
393 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
394 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
395
396 printf( HEADER_FORMAT, "CTR_DRBG (PR)" );
397 fflush( stdout );
398
399 if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
400 exit(1);
401
402 ctr_drbg_set_prediction_resistance( &ctr_drbg, CTR_DRBG_PR_ON );
403
404 set_alarm( 1 );
405 for( i = 1; ! alarmed; i++ )
406 if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
407 exit(1);
408
409 tsc = hardclock();
410 for( j = 1; j < 1024; j++ )
411 if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
412 exit(1);
413
414 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
415 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
416#endif
417
Paul Bakker5690efc2011-05-26 13:16:06 +0000418#if defined(POLARSSL_RSA_C) && defined(POLARSSL_BIGNUM_C) && \
419 defined(POLARSSL_GENPRIME)
Paul Bakkera802e1a2010-08-16 11:56:45 +0000420 rsa_init( &rsa, RSA_PKCS_V15, 0 );
421 rsa_gen_key( &rsa, myrand, NULL, 1024, 65537 );
Paul Bakker5121ce52009-01-03 21:22:43 +0000422
Paul Bakker02faf452011-11-29 11:23:58 +0000423 printf( HEADER_FORMAT, "RSA-1024" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000424 fflush( stdout );
425 set_alarm( 3 );
426
427 for( i = 1; ! alarmed; i++ )
428 {
429 buf[0] = 0;
430 rsa_public( &rsa, buf, buf );
431 }
432
433 printf( "%9lu public/s\n", i / 3 );
434
Paul Bakker02faf452011-11-29 11:23:58 +0000435 printf( HEADER_FORMAT, "RSA-1024" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000436 fflush( stdout );
437 set_alarm( 3 );
438
439 for( i = 1; ! alarmed; i++ )
440 {
441 buf[0] = 0;
442 rsa_private( &rsa, buf, buf );
443 }
444
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000445 printf( "%9lu private/s\n", i / 3 );
446
447 rsa_free( &rsa );
448
Paul Bakkera802e1a2010-08-16 11:56:45 +0000449 rsa_init( &rsa, RSA_PKCS_V15, 0 );
450 rsa_gen_key( &rsa, myrand, NULL, 2048, 65537 );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000451
Paul Bakker02faf452011-11-29 11:23:58 +0000452 printf( HEADER_FORMAT, "RSA-2048" );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000453 fflush( stdout );
454 set_alarm( 3 );
455
456 for( i = 1; ! alarmed; i++ )
457 {
458 buf[0] = 0;
459 rsa_public( &rsa, buf, buf );
460 }
461
462 printf( "%9lu public/s\n", i / 3 );
463
Paul Bakker02faf452011-11-29 11:23:58 +0000464 printf( HEADER_FORMAT, "RSA-2048" );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000465 fflush( stdout );
466 set_alarm( 3 );
467
468 for( i = 1; ! alarmed; i++ )
469 {
470 buf[0] = 0;
471 rsa_private( &rsa, buf, buf );
472 }
473
474 printf( "%9lu private/s\n", i / 3 );
475
476 rsa_free( &rsa );
477
Paul Bakkera802e1a2010-08-16 11:56:45 +0000478 rsa_init( &rsa, RSA_PKCS_V15, 0 );
479 rsa_gen_key( &rsa, myrand, NULL, 4096, 65537 );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000480
Paul Bakker02faf452011-11-29 11:23:58 +0000481 printf( HEADER_FORMAT, "RSA-4096" );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000482 fflush( stdout );
483 set_alarm( 3 );
484
485 for( i = 1; ! alarmed; i++ )
486 {
487 buf[0] = 0;
488 rsa_public( &rsa, buf, buf );
489 }
490
491 printf( "%9lu public/s\n", i / 3 );
492
Paul Bakker02faf452011-11-29 11:23:58 +0000493 printf( HEADER_FORMAT, "RSA-4096" );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000494 fflush( stdout );
495 set_alarm( 3 );
496
497 for( i = 1; ! alarmed; i++ )
498 {
499 buf[0] = 0;
500 rsa_private( &rsa, buf, buf );
501 }
502
503 printf( "%9lu private/s\n", i / 3 );
Paul Bakker5121ce52009-01-03 21:22:43 +0000504
505 rsa_free( &rsa );
506#endif
507
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000508 printf( "\n" );
509
Paul Bakkercce9d772011-11-18 14:26:47 +0000510#if defined(_WIN32)
Paul Bakker5121ce52009-01-03 21:22:43 +0000511 printf( " Press Enter to exit this program.\n" );
512 fflush( stdout ); getchar();
513#endif
514
515 return( 0 );
516}
Paul Bakker5690efc2011-05-26 13:16:06 +0000517#endif /* POLARSSL_TIMING_C */