blob: 98bfd4e82755a7483f1dc0d8365ef0d2f92103cd [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 ) );
Paul Bakkerd6d1f412014-04-17 16:03:48 +0200128 memset( tmp, 0xBB, sizeof( tmp ) );
Paul Bakker5121ce52009-01-03 21:22:43 +0000129
130 printf( "\n" );
131
Paul Bakker40e46942009-01-03 21:51:57 +0000132#if defined(POLARSSL_MD4_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000133 printf( HEADER_FORMAT, "MD4" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000134 fflush( stdout );
135
136 set_alarm( 1 );
137 for( i = 1; ! alarmed; i++ )
138 md4( buf, BUFSIZE, tmp );
139
140 tsc = hardclock();
141 for( j = 0; j < 1024; j++ )
142 md4( buf, BUFSIZE, tmp );
143
144 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
145 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
146#endif
147
Paul Bakker40e46942009-01-03 21:51:57 +0000148#if defined(POLARSSL_MD5_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000149 printf( HEADER_FORMAT, "MD5" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000150 fflush( stdout );
151
152 set_alarm( 1 );
153 for( i = 1; ! alarmed; i++ )
154 md5( buf, BUFSIZE, tmp );
155
156 tsc = hardclock();
157 for( j = 0; j < 1024; j++ )
158 md5( buf, BUFSIZE, tmp );
159
160 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
161 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
162#endif
163
Paul Bakker40e46942009-01-03 21:51:57 +0000164#if defined(POLARSSL_SHA1_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000165 printf( HEADER_FORMAT, "SHA-1" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000166 fflush( stdout );
167
168 set_alarm( 1 );
169 for( i = 1; ! alarmed; i++ )
170 sha1( buf, BUFSIZE, tmp );
171
172 tsc = hardclock();
173 for( j = 0; j < 1024; j++ )
174 sha1( buf, BUFSIZE, tmp );
175
176 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
177 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
178#endif
179
Paul Bakker40e46942009-01-03 21:51:57 +0000180#if defined(POLARSSL_SHA2_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000181 printf( HEADER_FORMAT, "SHA-256" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000182 fflush( stdout );
183
184 set_alarm( 1 );
185 for( i = 1; ! alarmed; i++ )
186 sha2( buf, BUFSIZE, tmp, 0 );
187
188 tsc = hardclock();
189 for( j = 0; j < 1024; j++ )
190 sha2( buf, BUFSIZE, tmp, 0 );
191
192 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
193 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
194#endif
195
Paul Bakker3a3c3c22009-02-09 22:33:30 +0000196#if defined(POLARSSL_SHA4_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000197 printf( HEADER_FORMAT, "SHA-512" );
Paul Bakker3a3c3c22009-02-09 22:33:30 +0000198 fflush( stdout );
199
200 set_alarm( 1 );
201 for( i = 1; ! alarmed; i++ )
202 sha4( buf, BUFSIZE, tmp, 0 );
203
204 tsc = hardclock();
205 for( j = 0; j < 1024; j++ )
206 sha4( buf, BUFSIZE, tmp, 0 );
207
208 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
209 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
210#endif
211
Paul Bakker40e46942009-01-03 21:51:57 +0000212#if defined(POLARSSL_ARC4_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000213 printf( HEADER_FORMAT, "ARC4" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000214 fflush( stdout );
215
216 arc4_setup( &arc4, tmp, 32 );
217
218 set_alarm( 1 );
219 for( i = 1; ! alarmed; i++ )
Paul Bakkerbaad6502010-03-21 15:42:15 +0000220 arc4_crypt( &arc4, BUFSIZE, buf, buf );
Paul Bakker5121ce52009-01-03 21:22:43 +0000221
222 tsc = hardclock();
223 for( j = 0; j < 1024; j++ )
Paul Bakkerbaad6502010-03-21 15:42:15 +0000224 arc4_crypt( &arc4, BUFSIZE, buf, buf );
Paul Bakker5121ce52009-01-03 21:22:43 +0000225
226 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
227 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
228#endif
229
Paul Bakker40e46942009-01-03 21:51:57 +0000230#if defined(POLARSSL_DES_C)
Paul Bakker02faf452011-11-29 11:23:58 +0000231 printf( HEADER_FORMAT, "3DES" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000232 fflush( stdout );
233
234 des3_set3key_enc( &des3, tmp );
235
236 set_alarm( 1 );
237 for( i = 1; ! alarmed; i++ )
238 des3_crypt_cbc( &des3, DES_ENCRYPT, BUFSIZE, tmp, buf, buf );
239
240 tsc = hardclock();
241 for( j = 0; j < 1024; j++ )
242 des3_crypt_cbc( &des3, DES_ENCRYPT, BUFSIZE, tmp, buf, buf );
243
244 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
245 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
246
Paul Bakker02faf452011-11-29 11:23:58 +0000247 printf( HEADER_FORMAT, "DES" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000248 fflush( stdout );
249
250 des_setkey_enc( &des, tmp );
251
252 set_alarm( 1 );
253 for( i = 1; ! alarmed; i++ )
254 des_crypt_cbc( &des, DES_ENCRYPT, BUFSIZE, tmp, buf, buf );
255
256 tsc = hardclock();
257 for( j = 0; j < 1024; j++ )
258 des_crypt_cbc( &des, DES_ENCRYPT, BUFSIZE, tmp, buf, buf );
259
260 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
261 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
262#endif
263
Paul Bakker40e46942009-01-03 21:51:57 +0000264#if defined(POLARSSL_AES_C)
Paul Bakker5121ce52009-01-03 21:22:43 +0000265 for( keysize = 128; keysize <= 256; keysize += 64 )
266 {
Paul Bakker89e80c92012-03-20 13:50:09 +0000267 printf( " AES-CBC-%d : ", keysize );
Paul Bakker5121ce52009-01-03 21:22:43 +0000268 fflush( stdout );
269
270 memset( buf, 0, sizeof( buf ) );
271 memset( tmp, 0, sizeof( tmp ) );
272 aes_setkey_enc( &aes, tmp, keysize );
273
274 set_alarm( 1 );
275
276 for( i = 1; ! alarmed; i++ )
277 aes_crypt_cbc( &aes, AES_ENCRYPT, BUFSIZE, tmp, buf, buf );
278
279 tsc = hardclock();
280 for( j = 0; j < 4096; j++ )
281 aes_crypt_cbc( &aes, AES_ENCRYPT, BUFSIZE, tmp, buf, buf );
282
283 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
284 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
285 }
Paul Bakker89e80c92012-03-20 13:50:09 +0000286#if defined(POLARSSL_GCM_C)
287 for( keysize = 128; keysize <= 256; keysize += 64 )
288 {
289 printf( " AES-GCM-%d : ", keysize );
290 fflush( stdout );
291
292 memset( buf, 0, sizeof( buf ) );
293 memset( tmp, 0, sizeof( tmp ) );
294 gcm_init( &gcm, tmp, keysize );
295
296 set_alarm( 1 );
297
298 for( i = 1; ! alarmed; i++ )
Paul Bakkerb78c7452012-03-20 15:05:59 +0000299 gcm_crypt_and_tag( &gcm, GCM_ENCRYPT, BUFSIZE, tmp, 12, NULL, 0, buf, buf, 16, tmp );
Paul Bakker89e80c92012-03-20 13:50:09 +0000300
301 tsc = hardclock();
302 for( j = 0; j < 4096; j++ )
Paul Bakkerb78c7452012-03-20 15:05:59 +0000303 gcm_crypt_and_tag( &gcm, GCM_ENCRYPT, BUFSIZE, tmp, 12, NULL, 0, buf, buf, 16, tmp );
Paul Bakker89e80c92012-03-20 13:50:09 +0000304
305 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
306 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
307 }
308#endif
Paul Bakker5121ce52009-01-03 21:22:43 +0000309#endif
310
Paul Bakker38119b12009-01-10 23:31:23 +0000311#if defined(POLARSSL_CAMELLIA_C)
312 for( keysize = 128; keysize <= 256; keysize += 64 )
313 {
Paul Bakker89e80c92012-03-20 13:50:09 +0000314 printf( " CAMELLIA-CBC-%d: ", keysize );
Paul Bakker38119b12009-01-10 23:31:23 +0000315 fflush( stdout );
316
317 memset( buf, 0, sizeof( buf ) );
318 memset( tmp, 0, sizeof( tmp ) );
319 camellia_setkey_enc( &camellia, tmp, keysize );
320
321 set_alarm( 1 );
322
323 for( i = 1; ! alarmed; i++ )
324 camellia_crypt_cbc( &camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf );
325
326 tsc = hardclock();
327 for( j = 0; j < 4096; j++ )
328 camellia_crypt_cbc( &camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf );
329
330 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
331 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
332 }
333#endif
334
Paul Bakker3d58fe82012-07-04 17:15:31 +0000335#if defined(POLARSSL_BLOWFISH_C)
336 for( keysize = 128; keysize <= 256; keysize += 64 )
337 {
338 printf( " BLOWFISH-CBC-%d: ", keysize );
339 fflush( stdout );
340
341 memset( buf, 0, sizeof( buf ) );
342 memset( tmp, 0, sizeof( tmp ) );
343 blowfish_setkey( &blowfish, tmp, keysize );
344
345 set_alarm( 1 );
346
347 for( i = 1; ! alarmed; i++ )
348 blowfish_crypt_cbc( &blowfish, BLOWFISH_ENCRYPT, BUFSIZE, tmp, buf, buf );
349
350 tsc = hardclock();
351 for( j = 0; j < 4096; j++ )
352 blowfish_crypt_cbc( &blowfish, BLOWFISH_ENCRYPT, BUFSIZE, tmp, buf, buf );
353
354 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
355 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
356 }
357#endif
358
Paul Bakker02faf452011-11-29 11:23:58 +0000359#if defined(POLARSSL_HAVEGE_C)
360 printf( HEADER_FORMAT, "HAVEGE" );
361 fflush( stdout );
362
363 havege_init( &hs );
364
365 set_alarm( 1 );
366 for( i = 1; ! alarmed; i++ )
367 havege_random( &hs, buf, BUFSIZE );
368
369 tsc = hardclock();
370 for( j = 1; j < 1024; j++ )
371 havege_random( &hs, buf, BUFSIZE );
372
373 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
374 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
375#endif
376
377#if defined(POLARSSL_CTR_DRBG_C)
378 printf( HEADER_FORMAT, "CTR_DRBG (NOPR)" );
379 fflush( stdout );
380
381 if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
382 exit(1);
383
384 set_alarm( 1 );
385 for( i = 1; ! alarmed; i++ )
386 if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
387 exit(1);
388
389 tsc = hardclock();
390 for( j = 1; j < 1024; j++ )
391 if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
392 exit(1);
393
394 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
395 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
396
397 printf( HEADER_FORMAT, "CTR_DRBG (PR)" );
398 fflush( stdout );
399
400 if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
401 exit(1);
402
403 ctr_drbg_set_prediction_resistance( &ctr_drbg, CTR_DRBG_PR_ON );
404
405 set_alarm( 1 );
406 for( i = 1; ! alarmed; i++ )
407 if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
408 exit(1);
409
410 tsc = hardclock();
411 for( j = 1; j < 1024; j++ )
412 if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
413 exit(1);
414
415 printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
416 ( hardclock() - tsc ) / ( j * BUFSIZE ) );
417#endif
418
Paul Bakker5690efc2011-05-26 13:16:06 +0000419#if defined(POLARSSL_RSA_C) && defined(POLARSSL_BIGNUM_C) && \
420 defined(POLARSSL_GENPRIME)
Paul Bakkera802e1a2010-08-16 11:56:45 +0000421 rsa_init( &rsa, RSA_PKCS_V15, 0 );
422 rsa_gen_key( &rsa, myrand, NULL, 1024, 65537 );
Paul Bakker5121ce52009-01-03 21:22:43 +0000423
Paul Bakker02faf452011-11-29 11:23:58 +0000424 printf( HEADER_FORMAT, "RSA-1024" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000425 fflush( stdout );
426 set_alarm( 3 );
427
428 for( i = 1; ! alarmed; i++ )
429 {
430 buf[0] = 0;
431 rsa_public( &rsa, buf, buf );
432 }
433
434 printf( "%9lu public/s\n", i / 3 );
435
Paul Bakker02faf452011-11-29 11:23:58 +0000436 printf( HEADER_FORMAT, "RSA-1024" );
Paul Bakker5121ce52009-01-03 21:22:43 +0000437 fflush( stdout );
438 set_alarm( 3 );
439
440 for( i = 1; ! alarmed; i++ )
441 {
442 buf[0] = 0;
Paul Bakker43f97992013-09-23 11:23:31 +0200443 rsa_private( &rsa, myrand, NULL, buf, buf );
Paul Bakker5121ce52009-01-03 21:22:43 +0000444 }
445
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000446 printf( "%9lu private/s\n", i / 3 );
447
448 rsa_free( &rsa );
449
Paul Bakkera802e1a2010-08-16 11:56:45 +0000450 rsa_init( &rsa, RSA_PKCS_V15, 0 );
451 rsa_gen_key( &rsa, myrand, NULL, 2048, 65537 );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000452
Paul Bakker02faf452011-11-29 11:23:58 +0000453 printf( HEADER_FORMAT, "RSA-2048" );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000454 fflush( stdout );
455 set_alarm( 3 );
456
457 for( i = 1; ! alarmed; i++ )
458 {
459 buf[0] = 0;
460 rsa_public( &rsa, buf, buf );
461 }
462
463 printf( "%9lu public/s\n", i / 3 );
464
Paul Bakker02faf452011-11-29 11:23:58 +0000465 printf( HEADER_FORMAT, "RSA-2048" );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000466 fflush( stdout );
467 set_alarm( 3 );
468
469 for( i = 1; ! alarmed; i++ )
470 {
471 buf[0] = 0;
Paul Bakker43f97992013-09-23 11:23:31 +0200472 rsa_private( &rsa, myrand, NULL, buf, buf );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000473 }
474
475 printf( "%9lu private/s\n", i / 3 );
476
477 rsa_free( &rsa );
478
Paul Bakkera802e1a2010-08-16 11:56:45 +0000479 rsa_init( &rsa, RSA_PKCS_V15, 0 );
480 rsa_gen_key( &rsa, myrand, NULL, 4096, 65537 );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000481
Paul Bakker02faf452011-11-29 11:23:58 +0000482 printf( HEADER_FORMAT, "RSA-4096" );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000483 fflush( stdout );
484 set_alarm( 3 );
485
486 for( i = 1; ! alarmed; i++ )
487 {
488 buf[0] = 0;
489 rsa_public( &rsa, buf, buf );
490 }
491
492 printf( "%9lu public/s\n", i / 3 );
493
Paul Bakker02faf452011-11-29 11:23:58 +0000494 printf( HEADER_FORMAT, "RSA-4096" );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000495 fflush( stdout );
496 set_alarm( 3 );
497
498 for( i = 1; ! alarmed; i++ )
499 {
500 buf[0] = 0;
Paul Bakker43f97992013-09-23 11:23:31 +0200501 rsa_private( &rsa, myrand, NULL, buf, buf );
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000502 }
503
504 printf( "%9lu private/s\n", i / 3 );
Paul Bakker5121ce52009-01-03 21:22:43 +0000505
506 rsa_free( &rsa );
507#endif
508
Paul Bakker1d4da2e2009-10-25 12:36:53 +0000509 printf( "\n" );
510
Paul Bakkercce9d772011-11-18 14:26:47 +0000511#if defined(_WIN32)
Paul Bakker5121ce52009-01-03 21:22:43 +0000512 printf( " Press Enter to exit this program.\n" );
513 fflush( stdout ); getchar();
514#endif
515
516 return( 0 );
517}
Paul Bakker5690efc2011-05-26 13:16:06 +0000518#endif /* POLARSSL_TIMING_C */