2009-01-03 22:22:43 +01:00
|
|
|
/*
|
|
|
|
* Benchmark demonstration program
|
|
|
|
*
|
2013-06-30 14:49:12 +02:00
|
|
|
* Copyright (C) 2006-2013, Brainspark B.V.
|
2010-07-18 22:36:00 +02:00
|
|
|
*
|
|
|
|
* This file is part of PolarSSL (http://www.polarssl.org)
|
2010-07-18 12:13:04 +02:00
|
|
|
* Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
|
2010-07-18 22:36:00 +02:00
|
|
|
*
|
2009-07-28 19:23:11 +02:00
|
|
|
* All rights reserved.
|
2009-01-04 17:27:10 +01:00
|
|
|
*
|
2009-01-03 22:22:43 +01:00
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _CRT_SECURE_NO_DEPRECATE
|
|
|
|
#define _CRT_SECURE_NO_DEPRECATE 1
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2009-01-03 22:51:57 +01:00
|
|
|
#include "polarssl/config.h"
|
|
|
|
|
|
|
|
#include "polarssl/md4.h"
|
|
|
|
#include "polarssl/md5.h"
|
|
|
|
#include "polarssl/sha1.h"
|
2013-06-30 14:49:12 +02:00
|
|
|
#include "polarssl/sha256.h"
|
|
|
|
#include "polarssl/sha512.h"
|
2009-01-03 22:51:57 +01:00
|
|
|
#include "polarssl/arc4.h"
|
|
|
|
#include "polarssl/des.h"
|
|
|
|
#include "polarssl/aes.h"
|
2012-07-04 19:15:31 +02:00
|
|
|
#include "polarssl/blowfish.h"
|
2009-01-11 00:31:23 +01:00
|
|
|
#include "polarssl/camellia.h"
|
2012-03-20 14:50:09 +01:00
|
|
|
#include "polarssl/gcm.h"
|
2009-01-03 22:51:57 +01:00
|
|
|
#include "polarssl/rsa.h"
|
2012-11-08 11:31:48 +01:00
|
|
|
#include "polarssl/dhm.h"
|
2009-01-03 22:51:57 +01:00
|
|
|
#include "polarssl/timing.h"
|
2011-11-29 12:23:58 +01:00
|
|
|
#include "polarssl/havege.h"
|
|
|
|
#include "polarssl/ctr_drbg.h"
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-11-29 12:23:58 +01:00
|
|
|
#define BUFSIZE 1024
|
|
|
|
#define HEADER_FORMAT " %-15s : "
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2013-07-04 10:34:10 +02:00
|
|
|
#if defined(POLARSSL_TIMING_C)
|
2011-11-27 22:07:34 +01:00
|
|
|
static int myrand( void *rng_state, unsigned char *output, size_t len )
|
2009-01-03 22:22:43 +01:00
|
|
|
{
|
2011-11-27 22:07:34 +01:00
|
|
|
size_t use_len;
|
|
|
|
int rnd;
|
|
|
|
|
2009-01-03 22:22:43 +01:00
|
|
|
if( rng_state != NULL )
|
|
|
|
rng_state = NULL;
|
|
|
|
|
2011-11-27 22:07:34 +01:00
|
|
|
while( len > 0 )
|
|
|
|
{
|
|
|
|
use_len = len;
|
|
|
|
if( use_len > sizeof(int) )
|
|
|
|
use_len = sizeof(int);
|
|
|
|
|
|
|
|
rnd = rand();
|
|
|
|
memcpy( output, &rnd, use_len );
|
|
|
|
output += use_len;
|
|
|
|
len -= use_len;
|
|
|
|
}
|
|
|
|
|
|
|
|
return( 0 );
|
2009-01-03 22:22:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
unsigned char buf[BUFSIZE];
|
2013-07-04 10:34:10 +02:00
|
|
|
#endif
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-05-26 15:16:06 +02:00
|
|
|
#if !defined(POLARSSL_TIMING_C)
|
2011-11-18 15:26:47 +01:00
|
|
|
int main( int argc, char *argv[] )
|
2011-05-26 15:16:06 +02:00
|
|
|
{
|
2011-11-18 15:26:47 +01:00
|
|
|
((void) argc);
|
|
|
|
((void) argv);
|
|
|
|
|
2011-05-26 15:16:06 +02:00
|
|
|
printf("POLARSSL_TIMING_C not defined.\n");
|
|
|
|
return( 0 );
|
|
|
|
}
|
|
|
|
#else
|
2011-11-18 15:26:47 +01:00
|
|
|
int main( int argc, char *argv[] )
|
2009-01-03 22:22:43 +01:00
|
|
|
{
|
2013-09-07 12:27:35 +02:00
|
|
|
int ret, keysize;
|
2009-01-03 22:22:43 +01:00
|
|
|
unsigned long i, j, tsc;
|
2009-02-09 23:38:52 +01:00
|
|
|
unsigned char tmp[64];
|
2009-01-03 22:51:57 +01:00
|
|
|
#if defined(POLARSSL_ARC4_C)
|
2009-01-03 22:22:43 +01:00
|
|
|
arc4_context arc4;
|
|
|
|
#endif
|
2013-09-13 16:24:20 +02:00
|
|
|
#if defined(POLARSSL_DES_C) && defined(POLARSSL_CIPHER_MODE_CBC)
|
2009-01-03 22:22:43 +01:00
|
|
|
des3_context des3;
|
|
|
|
des_context des;
|
|
|
|
#endif
|
2009-01-03 22:51:57 +01:00
|
|
|
#if defined(POLARSSL_AES_C)
|
2013-09-13 16:24:20 +02:00
|
|
|
#if defined(POLARSSL_CIPHER_MODE_CBC)
|
2009-01-03 22:22:43 +01:00
|
|
|
aes_context aes;
|
2013-09-13 16:24:20 +02:00
|
|
|
#endif
|
2012-03-20 14:50:09 +01:00
|
|
|
#if defined(POLARSSL_GCM_C)
|
|
|
|
gcm_context gcm;
|
|
|
|
#endif
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif
|
2013-09-13 16:24:20 +02:00
|
|
|
#if defined(POLARSSL_BLOWFISH_C) && defined(POLARSSL_CIPHER_MODE_CBC)
|
2012-07-04 19:15:31 +02:00
|
|
|
blowfish_context blowfish;
|
|
|
|
#endif
|
2013-09-13 16:24:20 +02:00
|
|
|
#if defined(POLARSSL_CAMELLIA_C) && defined(POLARSSL_CIPHER_MODE_CBC)
|
2009-01-11 00:31:23 +01:00
|
|
|
camellia_context camellia;
|
|
|
|
#endif
|
2011-05-26 15:16:06 +02:00
|
|
|
#if defined(POLARSSL_RSA_C) && defined(POLARSSL_BIGNUM_C) && \
|
|
|
|
defined(POLARSSL_GENPRIME)
|
2009-01-03 22:22:43 +01:00
|
|
|
rsa_context rsa;
|
|
|
|
#endif
|
2011-11-29 12:23:58 +01:00
|
|
|
#if defined(POLARSSL_HAVEGE_C)
|
|
|
|
havege_state hs;
|
|
|
|
#endif
|
|
|
|
#if defined(POLARSSL_CTR_DRBG_C)
|
|
|
|
ctr_drbg_context ctr_drbg;
|
2012-11-08 11:31:48 +01:00
|
|
|
#endif
|
|
|
|
#if defined(POLARSSL_DHM_C) && defined(POLARSSL_BIGNUM_C)
|
|
|
|
dhm_context dhm;
|
|
|
|
size_t olen = BUFSIZE;
|
2011-11-29 12:23:58 +01:00
|
|
|
#endif
|
2011-11-18 15:26:47 +01:00
|
|
|
((void) argc);
|
|
|
|
((void) argv);
|
|
|
|
|
2009-01-03 22:22:43 +01:00
|
|
|
memset( buf, 0xAA, sizeof( buf ) );
|
|
|
|
|
|
|
|
printf( "\n" );
|
|
|
|
|
2009-01-03 22:51:57 +01:00
|
|
|
#if defined(POLARSSL_MD4_C)
|
2011-11-29 12:23:58 +01:00
|
|
|
printf( HEADER_FORMAT, "MD4" );
|
2009-01-03 22:22:43 +01:00
|
|
|
fflush( stdout );
|
|
|
|
|
|
|
|
set_alarm( 1 );
|
|
|
|
for( i = 1; ! alarmed; i++ )
|
|
|
|
md4( buf, BUFSIZE, tmp );
|
|
|
|
|
|
|
|
tsc = hardclock();
|
|
|
|
for( j = 0; j < 1024; j++ )
|
|
|
|
md4( buf, BUFSIZE, tmp );
|
|
|
|
|
|
|
|
printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
|
|
|
|
( hardclock() - tsc ) / ( j * BUFSIZE ) );
|
|
|
|
#endif
|
|
|
|
|
2009-01-03 22:51:57 +01:00
|
|
|
#if defined(POLARSSL_MD5_C)
|
2011-11-29 12:23:58 +01:00
|
|
|
printf( HEADER_FORMAT, "MD5" );
|
2009-01-03 22:22:43 +01:00
|
|
|
fflush( stdout );
|
|
|
|
|
|
|
|
set_alarm( 1 );
|
|
|
|
for( i = 1; ! alarmed; i++ )
|
|
|
|
md5( buf, BUFSIZE, tmp );
|
|
|
|
|
|
|
|
tsc = hardclock();
|
|
|
|
for( j = 0; j < 1024; j++ )
|
|
|
|
md5( buf, BUFSIZE, tmp );
|
|
|
|
|
|
|
|
printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
|
|
|
|
( hardclock() - tsc ) / ( j * BUFSIZE ) );
|
|
|
|
#endif
|
|
|
|
|
2009-01-03 22:51:57 +01:00
|
|
|
#if defined(POLARSSL_SHA1_C)
|
2011-11-29 12:23:58 +01:00
|
|
|
printf( HEADER_FORMAT, "SHA-1" );
|
2009-01-03 22:22:43 +01:00
|
|
|
fflush( stdout );
|
|
|
|
|
|
|
|
set_alarm( 1 );
|
|
|
|
for( i = 1; ! alarmed; i++ )
|
|
|
|
sha1( buf, BUFSIZE, tmp );
|
|
|
|
|
|
|
|
tsc = hardclock();
|
|
|
|
for( j = 0; j < 1024; j++ )
|
|
|
|
sha1( buf, BUFSIZE, tmp );
|
|
|
|
|
|
|
|
printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
|
|
|
|
( hardclock() - tsc ) / ( j * BUFSIZE ) );
|
|
|
|
#endif
|
|
|
|
|
2013-06-30 14:34:05 +02:00
|
|
|
#if defined(POLARSSL_SHA256_C)
|
2011-11-29 12:23:58 +01:00
|
|
|
printf( HEADER_FORMAT, "SHA-256" );
|
2009-01-03 22:22:43 +01:00
|
|
|
fflush( stdout );
|
|
|
|
|
|
|
|
set_alarm( 1 );
|
|
|
|
for( i = 1; ! alarmed; i++ )
|
2013-06-30 14:34:05 +02:00
|
|
|
sha256( buf, BUFSIZE, tmp, 0 );
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
tsc = hardclock();
|
|
|
|
for( j = 0; j < 1024; j++ )
|
2013-06-30 14:34:05 +02:00
|
|
|
sha256( buf, BUFSIZE, tmp, 0 );
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
|
|
|
|
( hardclock() - tsc ) / ( j * BUFSIZE ) );
|
|
|
|
#endif
|
|
|
|
|
2013-06-30 14:34:05 +02:00
|
|
|
#if defined(POLARSSL_SHA512_C)
|
2011-11-29 12:23:58 +01:00
|
|
|
printf( HEADER_FORMAT, "SHA-512" );
|
2009-02-09 23:33:30 +01:00
|
|
|
fflush( stdout );
|
|
|
|
|
|
|
|
set_alarm( 1 );
|
|
|
|
for( i = 1; ! alarmed; i++ )
|
2013-06-30 14:34:05 +02:00
|
|
|
sha512( buf, BUFSIZE, tmp, 0 );
|
2009-02-09 23:33:30 +01:00
|
|
|
|
|
|
|
tsc = hardclock();
|
|
|
|
for( j = 0; j < 1024; j++ )
|
2013-06-30 14:34:05 +02:00
|
|
|
sha512( buf, BUFSIZE, tmp, 0 );
|
2009-02-09 23:33:30 +01:00
|
|
|
|
|
|
|
printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
|
|
|
|
( hardclock() - tsc ) / ( j * BUFSIZE ) );
|
|
|
|
#endif
|
|
|
|
|
2009-01-03 22:51:57 +01:00
|
|
|
#if defined(POLARSSL_ARC4_C)
|
2011-11-29 12:23:58 +01:00
|
|
|
printf( HEADER_FORMAT, "ARC4" );
|
2009-01-03 22:22:43 +01:00
|
|
|
fflush( stdout );
|
|
|
|
|
|
|
|
arc4_setup( &arc4, tmp, 32 );
|
|
|
|
|
|
|
|
set_alarm( 1 );
|
|
|
|
for( i = 1; ! alarmed; i++ )
|
2010-03-21 16:42:15 +01:00
|
|
|
arc4_crypt( &arc4, BUFSIZE, buf, buf );
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
tsc = hardclock();
|
|
|
|
for( j = 0; j < 1024; j++ )
|
2010-03-21 16:42:15 +01:00
|
|
|
arc4_crypt( &arc4, BUFSIZE, buf, buf );
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
|
|
|
|
( hardclock() - tsc ) / ( j * BUFSIZE ) );
|
|
|
|
#endif
|
|
|
|
|
2013-09-13 16:24:20 +02:00
|
|
|
#if defined(POLARSSL_DES_C) && defined(POLARSSL_CIPHER_MODE_CBC)
|
2011-11-29 12:23:58 +01:00
|
|
|
printf( HEADER_FORMAT, "3DES" );
|
2009-01-03 22:22:43 +01:00
|
|
|
fflush( stdout );
|
|
|
|
|
|
|
|
des3_set3key_enc( &des3, tmp );
|
|
|
|
|
|
|
|
set_alarm( 1 );
|
|
|
|
for( i = 1; ! alarmed; i++ )
|
|
|
|
des3_crypt_cbc( &des3, DES_ENCRYPT, BUFSIZE, tmp, buf, buf );
|
|
|
|
|
|
|
|
tsc = hardclock();
|
|
|
|
for( j = 0; j < 1024; j++ )
|
|
|
|
des3_crypt_cbc( &des3, DES_ENCRYPT, BUFSIZE, tmp, buf, buf );
|
|
|
|
|
|
|
|
printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
|
|
|
|
( hardclock() - tsc ) / ( j * BUFSIZE ) );
|
|
|
|
|
2011-11-29 12:23:58 +01:00
|
|
|
printf( HEADER_FORMAT, "DES" );
|
2009-01-03 22:22:43 +01:00
|
|
|
fflush( stdout );
|
|
|
|
|
|
|
|
des_setkey_enc( &des, tmp );
|
|
|
|
|
|
|
|
set_alarm( 1 );
|
|
|
|
for( i = 1; ! alarmed; i++ )
|
|
|
|
des_crypt_cbc( &des, DES_ENCRYPT, BUFSIZE, tmp, buf, buf );
|
|
|
|
|
|
|
|
tsc = hardclock();
|
|
|
|
for( j = 0; j < 1024; j++ )
|
|
|
|
des_crypt_cbc( &des, DES_ENCRYPT, BUFSIZE, tmp, buf, buf );
|
|
|
|
|
|
|
|
printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
|
|
|
|
( hardclock() - tsc ) / ( j * BUFSIZE ) );
|
|
|
|
#endif
|
|
|
|
|
2009-01-03 22:51:57 +01:00
|
|
|
#if defined(POLARSSL_AES_C)
|
2013-09-13 16:24:20 +02:00
|
|
|
#if defined(POLARSSL_CIPHER_MODE_CBC)
|
2009-01-03 22:22:43 +01:00
|
|
|
for( keysize = 128; keysize <= 256; keysize += 64 )
|
|
|
|
{
|
2012-03-20 14:50:09 +01:00
|
|
|
printf( " AES-CBC-%d : ", keysize );
|
2009-01-03 22:22:43 +01:00
|
|
|
fflush( stdout );
|
|
|
|
|
|
|
|
memset( buf, 0, sizeof( buf ) );
|
|
|
|
memset( tmp, 0, sizeof( tmp ) );
|
|
|
|
aes_setkey_enc( &aes, tmp, keysize );
|
|
|
|
|
|
|
|
set_alarm( 1 );
|
|
|
|
|
|
|
|
for( i = 1; ! alarmed; i++ )
|
|
|
|
aes_crypt_cbc( &aes, AES_ENCRYPT, BUFSIZE, tmp, buf, buf );
|
|
|
|
|
|
|
|
tsc = hardclock();
|
|
|
|
for( j = 0; j < 4096; j++ )
|
|
|
|
aes_crypt_cbc( &aes, AES_ENCRYPT, BUFSIZE, tmp, buf, buf );
|
|
|
|
|
|
|
|
printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
|
|
|
|
( hardclock() - tsc ) / ( j * BUFSIZE ) );
|
|
|
|
}
|
2013-09-13 16:24:20 +02:00
|
|
|
#endif /* POLARSSL_CIPHER_MODE_CBC */
|
2012-03-20 14:50:09 +01:00
|
|
|
#if defined(POLARSSL_GCM_C)
|
|
|
|
for( keysize = 128; keysize <= 256; keysize += 64 )
|
|
|
|
{
|
|
|
|
printf( " AES-GCM-%d : ", keysize );
|
|
|
|
fflush( stdout );
|
|
|
|
|
|
|
|
memset( buf, 0, sizeof( buf ) );
|
|
|
|
memset( tmp, 0, sizeof( tmp ) );
|
2013-09-10 14:51:50 +02:00
|
|
|
gcm_init( &gcm, POLARSSL_CIPHER_ID_AES, tmp, keysize );
|
2012-03-20 14:50:09 +01:00
|
|
|
|
|
|
|
set_alarm( 1 );
|
|
|
|
|
|
|
|
for( i = 1; ! alarmed; i++ )
|
2012-03-20 16:05:59 +01:00
|
|
|
gcm_crypt_and_tag( &gcm, GCM_ENCRYPT, BUFSIZE, tmp, 12, NULL, 0, buf, buf, 16, tmp );
|
2012-03-20 14:50:09 +01:00
|
|
|
|
|
|
|
tsc = hardclock();
|
|
|
|
for( j = 0; j < 4096; j++ )
|
2012-03-20 16:05:59 +01:00
|
|
|
gcm_crypt_and_tag( &gcm, GCM_ENCRYPT, BUFSIZE, tmp, 12, NULL, 0, buf, buf, 16, tmp );
|
2012-03-20 14:50:09 +01:00
|
|
|
|
|
|
|
printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
|
|
|
|
( hardclock() - tsc ) / ( j * BUFSIZE ) );
|
|
|
|
}
|
|
|
|
#endif
|
2009-01-03 22:22:43 +01:00
|
|
|
#endif
|
|
|
|
|
2013-09-13 16:24:20 +02:00
|
|
|
#if defined(POLARSSL_CAMELLIA_C) && defined(POLARSSL_CIPHER_MODE_CBC)
|
2009-01-11 00:31:23 +01:00
|
|
|
for( keysize = 128; keysize <= 256; keysize += 64 )
|
|
|
|
{
|
2012-03-20 14:50:09 +01:00
|
|
|
printf( " CAMELLIA-CBC-%d: ", keysize );
|
2009-01-11 00:31:23 +01:00
|
|
|
fflush( stdout );
|
|
|
|
|
|
|
|
memset( buf, 0, sizeof( buf ) );
|
|
|
|
memset( tmp, 0, sizeof( tmp ) );
|
|
|
|
camellia_setkey_enc( &camellia, tmp, keysize );
|
|
|
|
|
|
|
|
set_alarm( 1 );
|
|
|
|
|
|
|
|
for( i = 1; ! alarmed; i++ )
|
|
|
|
camellia_crypt_cbc( &camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf );
|
|
|
|
|
|
|
|
tsc = hardclock();
|
|
|
|
for( j = 0; j < 4096; j++ )
|
|
|
|
camellia_crypt_cbc( &camellia, CAMELLIA_ENCRYPT, BUFSIZE, tmp, buf, buf );
|
|
|
|
|
|
|
|
printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
|
|
|
|
( hardclock() - tsc ) / ( j * BUFSIZE ) );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2013-09-13 16:24:20 +02:00
|
|
|
#if defined(POLARSSL_BLOWFISH_C) && defined(POLARSSL_CIPHER_MODE_CBC)
|
2012-07-04 19:15:31 +02:00
|
|
|
for( keysize = 128; keysize <= 256; keysize += 64 )
|
|
|
|
{
|
|
|
|
printf( " BLOWFISH-CBC-%d: ", keysize );
|
|
|
|
fflush( stdout );
|
|
|
|
|
|
|
|
memset( buf, 0, sizeof( buf ) );
|
|
|
|
memset( tmp, 0, sizeof( tmp ) );
|
|
|
|
blowfish_setkey( &blowfish, tmp, keysize );
|
|
|
|
|
|
|
|
set_alarm( 1 );
|
|
|
|
|
|
|
|
for( i = 1; ! alarmed; i++ )
|
|
|
|
blowfish_crypt_cbc( &blowfish, BLOWFISH_ENCRYPT, BUFSIZE, tmp, buf, buf );
|
|
|
|
|
|
|
|
tsc = hardclock();
|
|
|
|
for( j = 0; j < 4096; j++ )
|
|
|
|
blowfish_crypt_cbc( &blowfish, BLOWFISH_ENCRYPT, BUFSIZE, tmp, buf, buf );
|
|
|
|
|
|
|
|
printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
|
|
|
|
( hardclock() - tsc ) / ( j * BUFSIZE ) );
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2011-11-29 12:23:58 +01:00
|
|
|
#if defined(POLARSSL_HAVEGE_C)
|
|
|
|
printf( HEADER_FORMAT, "HAVEGE" );
|
|
|
|
fflush( stdout );
|
|
|
|
|
|
|
|
havege_init( &hs );
|
|
|
|
|
|
|
|
set_alarm( 1 );
|
|
|
|
for( i = 1; ! alarmed; i++ )
|
|
|
|
havege_random( &hs, buf, BUFSIZE );
|
|
|
|
|
|
|
|
tsc = hardclock();
|
|
|
|
for( j = 1; j < 1024; j++ )
|
|
|
|
havege_random( &hs, buf, BUFSIZE );
|
|
|
|
|
|
|
|
printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
|
|
|
|
( hardclock() - tsc ) / ( j * BUFSIZE ) );
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(POLARSSL_CTR_DRBG_C)
|
|
|
|
printf( HEADER_FORMAT, "CTR_DRBG (NOPR)" );
|
|
|
|
fflush( stdout );
|
|
|
|
|
|
|
|
if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
set_alarm( 1 );
|
|
|
|
for( i = 1; ! alarmed; i++ )
|
|
|
|
if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
tsc = hardclock();
|
|
|
|
for( j = 1; j < 1024; j++ )
|
|
|
|
if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
|
|
|
|
( hardclock() - tsc ) / ( j * BUFSIZE ) );
|
|
|
|
|
|
|
|
printf( HEADER_FORMAT, "CTR_DRBG (PR)" );
|
|
|
|
fflush( stdout );
|
|
|
|
|
|
|
|
if( ctr_drbg_init( &ctr_drbg, myrand, NULL, NULL, 0 ) != 0 )
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
ctr_drbg_set_prediction_resistance( &ctr_drbg, CTR_DRBG_PR_ON );
|
|
|
|
|
|
|
|
set_alarm( 1 );
|
|
|
|
for( i = 1; ! alarmed; i++ )
|
|
|
|
if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
tsc = hardclock();
|
|
|
|
for( j = 1; j < 1024; j++ )
|
|
|
|
if( ctr_drbg_random( &ctr_drbg, buf, BUFSIZE ) != 0 )
|
|
|
|
exit(1);
|
|
|
|
|
|
|
|
printf( "%9lu Kb/s, %9lu cycles/byte\n", i * BUFSIZE / 1024,
|
|
|
|
( hardclock() - tsc ) / ( j * BUFSIZE ) );
|
|
|
|
#endif
|
|
|
|
|
2011-05-26 15:16:06 +02:00
|
|
|
#if defined(POLARSSL_RSA_C) && defined(POLARSSL_BIGNUM_C) && \
|
|
|
|
defined(POLARSSL_GENPRIME)
|
2010-08-16 13:56:45 +02:00
|
|
|
rsa_init( &rsa, RSA_PKCS_V15, 0 );
|
|
|
|
rsa_gen_key( &rsa, myrand, NULL, 1024, 65537 );
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-11-29 12:23:58 +01:00
|
|
|
printf( HEADER_FORMAT, "RSA-1024" );
|
2009-01-03 22:22:43 +01:00
|
|
|
fflush( stdout );
|
|
|
|
set_alarm( 3 );
|
|
|
|
|
2013-09-07 12:27:35 +02:00
|
|
|
ret = 0;
|
|
|
|
for( i = 1; ! alarmed && ! ret ; i++ )
|
2009-01-03 22:22:43 +01:00
|
|
|
{
|
|
|
|
buf[0] = 0;
|
2013-09-07 12:27:35 +02:00
|
|
|
ret = rsa_public( &rsa, buf, buf );
|
2009-01-03 22:22:43 +01:00
|
|
|
}
|
|
|
|
|
2013-09-07 12:27:35 +02:00
|
|
|
if( ret != 0 )
|
|
|
|
printf( "FAILED\n" );
|
|
|
|
else
|
|
|
|
printf( "%9lu public/s\n", i / 3 );
|
2009-01-03 22:22:43 +01:00
|
|
|
|
2011-11-29 12:23:58 +01:00
|
|
|
printf( HEADER_FORMAT, "RSA-1024" );
|
2009-01-03 22:22:43 +01:00
|
|
|
fflush( stdout );
|
|
|
|
set_alarm( 3 );
|
|
|
|
|
2013-09-07 12:27:35 +02:00
|
|
|
ret = 0;
|
|
|
|
for( i = 1; ! alarmed && ! ret ; i++ )
|
2009-01-03 22:22:43 +01:00
|
|
|
{
|
|
|
|
buf[0] = 0;
|
2013-09-07 12:27:35 +02:00
|
|
|
ret = rsa_private( &rsa, myrand, NULL, buf, buf );
|
2009-01-03 22:22:43 +01:00
|
|
|
}
|
|
|
|
|
2013-09-07 12:27:35 +02:00
|
|
|
if( ret != 0 )
|
|
|
|
printf( "FAILED\n" );
|
|
|
|
else
|
|
|
|
printf( "%9lu private/s\n", i / 3 );
|
2009-10-25 13:36:53 +01:00
|
|
|
|
|
|
|
rsa_free( &rsa );
|
|
|
|
|
2010-08-16 13:56:45 +02:00
|
|
|
rsa_init( &rsa, RSA_PKCS_V15, 0 );
|
|
|
|
rsa_gen_key( &rsa, myrand, NULL, 2048, 65537 );
|
2009-10-25 13:36:53 +01:00
|
|
|
|
2011-11-29 12:23:58 +01:00
|
|
|
printf( HEADER_FORMAT, "RSA-2048" );
|
2009-10-25 13:36:53 +01:00
|
|
|
fflush( stdout );
|
|
|
|
set_alarm( 3 );
|
|
|
|
|
2013-09-07 12:27:35 +02:00
|
|
|
ret = 0;
|
|
|
|
for( i = 1; ! alarmed && ! ret ; i++ )
|
2009-10-25 13:36:53 +01:00
|
|
|
{
|
|
|
|
buf[0] = 0;
|
2013-09-07 12:27:35 +02:00
|
|
|
ret = rsa_public( &rsa, buf, buf );
|
2009-10-25 13:36:53 +01:00
|
|
|
}
|
|
|
|
|
2013-09-07 12:27:35 +02:00
|
|
|
if( ret != 0 )
|
|
|
|
printf( "FAILED\n" );
|
|
|
|
else
|
|
|
|
printf( "%9lu public/s\n", i / 3 );
|
2009-10-25 13:36:53 +01:00
|
|
|
|
2011-11-29 12:23:58 +01:00
|
|
|
printf( HEADER_FORMAT, "RSA-2048" );
|
2009-10-25 13:36:53 +01:00
|
|
|
fflush( stdout );
|
|
|
|
set_alarm( 3 );
|
|
|
|
|
2013-09-07 12:27:35 +02:00
|
|
|
ret = 0;
|
|
|
|
for( i = 1; ! alarmed && ! ret ; i++ )
|
2009-10-25 13:36:53 +01:00
|
|
|
{
|
|
|
|
buf[0] = 0;
|
2013-09-07 12:27:35 +02:00
|
|
|
ret = rsa_private( &rsa, myrand, NULL, buf, buf );
|
2009-10-25 13:36:53 +01:00
|
|
|
}
|
|
|
|
|
2013-09-07 12:27:35 +02:00
|
|
|
if( ret != 0 )
|
|
|
|
printf( "FAILED\n" );
|
|
|
|
else
|
|
|
|
printf( "%9lu private/s\n", i / 3 );
|
2009-10-25 13:36:53 +01:00
|
|
|
|
|
|
|
rsa_free( &rsa );
|
|
|
|
|
2010-08-16 13:56:45 +02:00
|
|
|
rsa_init( &rsa, RSA_PKCS_V15, 0 );
|
|
|
|
rsa_gen_key( &rsa, myrand, NULL, 4096, 65537 );
|
2009-10-25 13:36:53 +01:00
|
|
|
|
2011-11-29 12:23:58 +01:00
|
|
|
printf( HEADER_FORMAT, "RSA-4096" );
|
2009-10-25 13:36:53 +01:00
|
|
|
fflush( stdout );
|
|
|
|
set_alarm( 3 );
|
|
|
|
|
2013-09-07 12:27:35 +02:00
|
|
|
ret = 0;
|
|
|
|
for( i = 1; ! alarmed && ! ret ; i++ )
|
2009-10-25 13:36:53 +01:00
|
|
|
{
|
|
|
|
buf[0] = 0;
|
2013-09-07 12:27:35 +02:00
|
|
|
ret = rsa_public( &rsa, buf, buf );
|
2009-10-25 13:36:53 +01:00
|
|
|
}
|
|
|
|
|
2013-09-07 12:27:35 +02:00
|
|
|
if( ret != 0 )
|
|
|
|
printf( "FAILED\n" );
|
|
|
|
else
|
|
|
|
printf( "%9lu public/s\n", i / 3 );
|
2009-10-25 13:36:53 +01:00
|
|
|
|
2011-11-29 12:23:58 +01:00
|
|
|
printf( HEADER_FORMAT, "RSA-4096" );
|
2009-10-25 13:36:53 +01:00
|
|
|
fflush( stdout );
|
|
|
|
set_alarm( 3 );
|
|
|
|
|
2013-09-07 12:27:35 +02:00
|
|
|
ret = 0;
|
|
|
|
for( i = 1; ! alarmed && ! ret ; i++ )
|
2009-10-25 13:36:53 +01:00
|
|
|
{
|
|
|
|
buf[0] = 0;
|
2013-09-07 12:27:35 +02:00
|
|
|
ret = rsa_private( &rsa, myrand, NULL, buf, buf );
|
2009-10-25 13:36:53 +01:00
|
|
|
}
|
|
|
|
|
2013-09-07 12:27:35 +02:00
|
|
|
if( ret != 0 )
|
|
|
|
printf( "FAILED\n" );
|
|
|
|
else
|
|
|
|
printf( "%9lu private/s\n", i / 3 );
|
2009-01-03 22:22:43 +01:00
|
|
|
|
|
|
|
rsa_free( &rsa );
|
|
|
|
#endif
|
|
|
|
|
2012-11-08 11:31:48 +01:00
|
|
|
#if defined(POLARSSL_DHM_C) && defined(POLARSSL_BIGNUM_C)
|
|
|
|
memset( &dhm, 0, sizeof( dhm_context ) );
|
|
|
|
|
|
|
|
mpi_read_string( &dhm.P, 16, POLARSSL_DHM_RFC5114_MODP_1024_P );
|
|
|
|
mpi_read_string( &dhm.G, 16, POLARSSL_DHM_RFC5114_MODP_1024_G );
|
|
|
|
dhm.len = mpi_size( &dhm.P );
|
|
|
|
dhm_make_public( &dhm, dhm.len, buf, dhm.len, myrand, NULL );
|
|
|
|
mpi_copy( &dhm.GY, &dhm.GX );
|
|
|
|
|
|
|
|
printf( HEADER_FORMAT, "DHM-1024" );
|
|
|
|
fflush( stdout );
|
|
|
|
set_alarm( 3 );
|
|
|
|
|
2013-09-07 12:27:35 +02:00
|
|
|
ret = 0;
|
|
|
|
for( i = 1; ! alarmed && ! ret ; i++ )
|
2012-11-08 11:31:48 +01:00
|
|
|
{
|
2013-09-07 12:27:35 +02:00
|
|
|
olen = sizeof( buf );
|
|
|
|
ret |= dhm_make_public( &dhm, dhm.len, buf, dhm.len, myrand, NULL );
|
|
|
|
ret |= dhm_calc_secret( &dhm, buf, &olen, NULL, NULL );
|
2012-11-08 11:31:48 +01:00
|
|
|
}
|
|
|
|
|
2013-09-07 13:05:52 +02:00
|
|
|
if( ret != 0 )
|
|
|
|
printf( "FAILED\n" );
|
|
|
|
else
|
|
|
|
printf( "%9lu handshake/s\n", i / 3 );
|
|
|
|
|
|
|
|
printf( HEADER_FORMAT, "fixed-DHM-1024" );
|
|
|
|
fflush( stdout );
|
|
|
|
set_alarm( 3 );
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
for( i = 1; ! alarmed && ! ret ; i++ )
|
|
|
|
{
|
|
|
|
olen = sizeof( buf );
|
|
|
|
ret |= dhm_calc_secret( &dhm, buf, &olen, myrand, NULL );
|
|
|
|
}
|
|
|
|
|
2013-09-07 12:27:35 +02:00
|
|
|
if( ret != 0 )
|
|
|
|
printf( "FAILED\n" );
|
|
|
|
else
|
|
|
|
printf( "%9lu handshake/s\n", i / 3 );
|
2012-11-08 11:31:48 +01:00
|
|
|
|
|
|
|
dhm_free( &dhm );
|
|
|
|
|
|
|
|
memset( &dhm, 0, sizeof( dhm_context ) );
|
|
|
|
|
|
|
|
mpi_read_string( &dhm.P, 16, POLARSSL_DHM_RFC3526_MODP_2048_P );
|
|
|
|
mpi_read_string( &dhm.G, 16, POLARSSL_DHM_RFC3526_MODP_2048_G );
|
|
|
|
dhm.len = mpi_size( &dhm.P );
|
|
|
|
dhm_make_public( &dhm, dhm.len, buf, dhm.len, myrand, NULL );
|
|
|
|
mpi_copy( &dhm.GY, &dhm.GX );
|
|
|
|
|
|
|
|
printf( HEADER_FORMAT, "DHM-2048" );
|
|
|
|
fflush( stdout );
|
|
|
|
set_alarm( 3 );
|
|
|
|
|
2013-09-07 12:27:35 +02:00
|
|
|
ret = 0;
|
|
|
|
for( i = 1; ! alarmed && ! ret ; i++ )
|
2012-11-08 11:31:48 +01:00
|
|
|
{
|
2013-09-07 12:27:35 +02:00
|
|
|
olen = sizeof( buf );
|
|
|
|
ret |= dhm_make_public( &dhm, dhm.len, buf, dhm.len, myrand, NULL );
|
2013-09-07 13:05:52 +02:00
|
|
|
ret |= dhm_calc_secret( &dhm, buf, &olen, myrand, NULL );
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ret != 0 )
|
|
|
|
printf( "FAILED\n" );
|
|
|
|
else
|
|
|
|
printf( "%9lu handshake/s\n", i / 3 );
|
|
|
|
|
|
|
|
printf( HEADER_FORMAT, "fixed-DHM-2048" );
|
|
|
|
fflush( stdout );
|
|
|
|
set_alarm( 3 );
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
for( i = 1; ! alarmed && ! ret ; i++ )
|
|
|
|
{
|
|
|
|
olen = sizeof( buf );
|
2013-09-07 12:27:35 +02:00
|
|
|
ret |= dhm_calc_secret( &dhm, buf, &olen, NULL, NULL );
|
2012-11-08 11:31:48 +01:00
|
|
|
}
|
|
|
|
|
2013-09-07 12:27:35 +02:00
|
|
|
if( ret != 0 )
|
|
|
|
printf( "FAILED\n" );
|
|
|
|
else
|
|
|
|
printf( "%9lu handshake/s\n", i / 3 );
|
2012-11-08 11:31:48 +01:00
|
|
|
|
|
|
|
dhm_free( &dhm );
|
|
|
|
memset( &dhm, 0, sizeof( dhm_context ) );
|
|
|
|
|
|
|
|
mpi_read_string( &dhm.P, 16, POLARSSL_DHM_RFC3526_MODP_3072_P );
|
|
|
|
mpi_read_string( &dhm.G, 16, POLARSSL_DHM_RFC3526_MODP_3072_G );
|
|
|
|
dhm.len = mpi_size( &dhm.P );
|
|
|
|
dhm_make_public( &dhm, dhm.len, buf, dhm.len, myrand, NULL );
|
|
|
|
mpi_copy( &dhm.GY, &dhm.GX );
|
|
|
|
|
|
|
|
printf( HEADER_FORMAT, "DHM-3072" );
|
|
|
|
fflush( stdout );
|
|
|
|
set_alarm( 3 );
|
|
|
|
|
2013-09-07 12:27:35 +02:00
|
|
|
ret = 0;
|
|
|
|
for( i = 1; ! alarmed && ! ret ; i++ )
|
2012-11-08 11:31:48 +01:00
|
|
|
{
|
2013-09-07 12:27:35 +02:00
|
|
|
olen = sizeof( buf );
|
|
|
|
ret |= dhm_make_public( &dhm, dhm.len, buf, dhm.len, myrand, NULL );
|
|
|
|
ret |= dhm_calc_secret( &dhm, buf, &olen, NULL, NULL );
|
2012-11-08 11:31:48 +01:00
|
|
|
}
|
|
|
|
|
2013-09-07 13:05:52 +02:00
|
|
|
if( ret != 0 )
|
|
|
|
printf( "FAILED\n" );
|
|
|
|
else
|
|
|
|
printf( "%9lu handshake/s\n", i / 3 );
|
|
|
|
|
|
|
|
printf( HEADER_FORMAT, "fixed-DHM-3072" );
|
|
|
|
fflush( stdout );
|
|
|
|
set_alarm( 3 );
|
|
|
|
|
|
|
|
ret = 0;
|
|
|
|
for( i = 1; ! alarmed && ! ret ; i++ )
|
|
|
|
{
|
|
|
|
olen = sizeof( buf );
|
|
|
|
ret |= dhm_calc_secret( &dhm, buf, &olen, myrand, NULL );
|
|
|
|
}
|
|
|
|
|
2013-09-07 12:27:35 +02:00
|
|
|
if( ret != 0 )
|
|
|
|
printf( "FAILED\n" );
|
|
|
|
else
|
|
|
|
printf( "%9lu handshake/s\n", i / 3 );
|
2012-11-08 11:31:48 +01:00
|
|
|
|
|
|
|
dhm_free( &dhm );
|
|
|
|
#endif
|
|
|
|
|
2009-10-25 13:36:53 +01:00
|
|
|
printf( "\n" );
|
|
|
|
|
2011-11-18 15:26:47 +01:00
|
|
|
#if defined(_WIN32)
|
2009-01-03 22:22:43 +01:00
|
|
|
printf( " Press Enter to exit this program.\n" );
|
|
|
|
fflush( stdout ); getchar();
|
|
|
|
#endif
|
|
|
|
|
|
|
|
return( 0 );
|
|
|
|
}
|
2011-05-26 15:16:06 +02:00
|
|
|
#endif /* POLARSSL_TIMING_C */
|