| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378 | 
							- /*
 
-  *  Benchmark demonstration program
 
-  *
 
-  *  Copyright (C) 2006-2010, Brainspark B.V.
 
-  *
 
-  *  This file is part of PolarSSL (http://www.polarssl.org)
 
-  *  Lead Maintainer: Paul Bakker <polarssl_maintainer at polarssl.org>
 
-  *
 
-  *  All rights reserved.
 
-  *
 
-  *  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>
 
- #ifdef PRINTF_STDLIB
 
- #include <stdio.h>
 
- #endif
 
- #ifdef PRINTF_CUSTOM
 
- #include "tinystdio.h"
 
- #endif
 
- #include "polarssl/config.h"
 
- #include "polarssl/md4.h"
 
- #include "polarssl/md5.h"
 
- #include "polarssl/sha1.h"
 
- #include "polarssl/sha2.h"
 
- #include "polarssl/sha4.h"
 
- #include "polarssl/arc4.h"
 
- #include "polarssl/des.h"
 
- #include "polarssl/aes.h"
 
- #include "polarssl/camellia.h"
 
- #include "polarssl/rsa.h"
 
- #include "polarssl/timing.h"
 
- #define BUFSIZE 1024
 
- static int myrand( void *rng_state )
 
- {
 
-     if( rng_state != NULL )
 
-         rng_state  = NULL;
 
-     return( rand() );
 
- }
 
- unsigned char buf[BUFSIZE];
 
- #if !defined(POLARSSL_TIMING_C)
 
- int main( void )
 
- {
 
-     printf("POLARSSL_TIMING_C not defined.\n");
 
-     return( 0 );
 
- }
 
- #else
 
- int main( void )
 
- {
 
-     int keysize;
 
-     unsigned long i, j, tsc;
 
-     unsigned char tmp[64];
 
- #if defined(POLARSSL_ARC4_C)
 
-     arc4_context arc4;
 
- #endif
 
- #if defined(POLARSSL_DES_C)
 
-     des3_context des3;
 
-     des_context des;
 
- #endif
 
- #if defined(POLARSSL_AES_C)
 
-     aes_context aes;
 
- #endif
 
- #if defined(POLARSSL_CAMELLIA_C)
 
-     camellia_context camellia;
 
- #endif
 
- #if defined(POLARSSL_RSA_C) && defined(POLARSSL_BIGNUM_C) &&    \
 
-     defined(POLARSSL_GENPRIME)
 
-     rsa_context rsa;
 
- #endif
 
-     memset( buf, 0xAA, sizeof( buf ) );
 
-     printf( "\n" );
 
- #if defined(POLARSSL_MD4_C)
 
-     printf( "  MD4       :  " );
 
-     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
 
- #if defined(POLARSSL_MD5_C)
 
-     printf( "  MD5       :  " );
 
-     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
 
- #if defined(POLARSSL_SHA1_C)
 
-     printf( "  SHA-1     :  " );
 
-     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
 
- #if defined(POLARSSL_SHA2_C)
 
-     printf( "  SHA-256   :  " );
 
-     fflush( stdout );
 
-     set_alarm( 1 );
 
-     for( i = 1; ! alarmed; i++ )
 
-         sha2( buf, BUFSIZE, tmp, 0 );
 
-     tsc = hardclock();
 
-     for( j = 0; j < 1024; j++ )
 
-         sha2( buf, BUFSIZE, tmp, 0 );
 
-     printf( "%9lu Kb/s,  %9lu cycles/byte\n", i * BUFSIZE / 1024,
 
-                     ( hardclock() - tsc ) / ( j * BUFSIZE ) );
 
- #endif
 
- #if defined(POLARSSL_SHA4_C)
 
-     printf( "  SHA-512   :  " );
 
-     fflush( stdout );
 
-     set_alarm( 1 );
 
-     for( i = 1; ! alarmed; i++ )
 
-         sha4( buf, BUFSIZE, tmp, 0 );
 
-     tsc = hardclock();
 
-     for( j = 0; j < 1024; j++ )
 
-         sha4( buf, BUFSIZE, tmp, 0 );
 
-     printf( "%9lu Kb/s,  %9lu cycles/byte\n", i * BUFSIZE / 1024,
 
-                     ( hardclock() - tsc ) / ( j * BUFSIZE ) );
 
- #endif
 
- #if defined(POLARSSL_ARC4_C)
 
-     printf( "  ARC4      :  " );
 
-     fflush( stdout );
 
-     arc4_setup( &arc4, tmp, 32 );
 
-     set_alarm( 1 );
 
-     for( i = 1; ! alarmed; i++ )
 
-         arc4_crypt( &arc4, BUFSIZE, buf, buf );
 
-     tsc = hardclock();
 
-     for( j = 0; j < 1024; j++ )
 
-         arc4_crypt( &arc4, BUFSIZE, buf, buf );
 
-     printf( "%9lu Kb/s,  %9lu cycles/byte\n", i * BUFSIZE / 1024,
 
-                     ( hardclock() - tsc ) / ( j * BUFSIZE ) );
 
- #endif
 
- #if defined(POLARSSL_DES_C)
 
-     printf( "  3DES      :  " );
 
-     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 ) );
 
-     printf( "  DES       :  " );
 
-     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
 
- #if defined(POLARSSL_AES_C)
 
-     for( keysize = 128; keysize <= 256; keysize += 64 )
 
-     {
 
-         printf( "  AES-%d   :  ", keysize );
 
-         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 ) );
 
-     }
 
- #endif
 
- #if defined(POLARSSL_CAMELLIA_C)
 
-     for( keysize = 128; keysize <= 256; keysize += 64 )
 
-     {
 
-         printf( "  CAMELLIA-%d   :  ", keysize );
 
-         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
 
- #if defined(POLARSSL_RSA_C) && defined(POLARSSL_BIGNUM_C) &&    \
 
-     defined(POLARSSL_GENPRIME)
 
-     rsa_init( &rsa, RSA_PKCS_V15, 0 );
 
-     rsa_gen_key( &rsa, myrand, NULL, 1024, 65537 );
 
-     printf( "  RSA-1024  :  " );
 
-     fflush( stdout );
 
-     set_alarm( 3 );
 
-     for( i = 1; ! alarmed; i++ )
 
-     {
 
-         buf[0] = 0;
 
-         rsa_public( &rsa, buf, buf );
 
-     }
 
-     printf( "%9lu  public/s\n", i / 3 );
 
-     printf( "  RSA-1024  :  " );
 
-     fflush( stdout );
 
-     set_alarm( 3 );
 
-     for( i = 1; ! alarmed; i++ )
 
-     {
 
-         buf[0] = 0;
 
-         rsa_private( &rsa, buf, buf );
 
-     }
 
-     printf( "%9lu private/s\n", i / 3 );
 
-     rsa_free( &rsa );
 
-     rsa_init( &rsa, RSA_PKCS_V15, 0 );
 
-     rsa_gen_key( &rsa, myrand, NULL, 2048, 65537 );
 
-     printf( "  RSA-2048  :  " );
 
-     fflush( stdout );
 
-     set_alarm( 3 );
 
-     for( i = 1; ! alarmed; i++ )
 
-     {
 
-         buf[0] = 0;
 
-         rsa_public( &rsa, buf, buf );
 
-     }
 
-     printf( "%9lu  public/s\n", i / 3 );
 
-     printf( "  RSA-2048  :  " );
 
-     fflush( stdout );
 
-     set_alarm( 3 );
 
-     for( i = 1; ! alarmed; i++ )
 
-     {
 
-         buf[0] = 0;
 
-         rsa_private( &rsa, buf, buf );
 
-     }
 
-     printf( "%9lu private/s\n", i / 3 );
 
-     rsa_free( &rsa );
 
-     rsa_init( &rsa, RSA_PKCS_V15, 0 );
 
-     rsa_gen_key( &rsa, myrand, NULL, 4096, 65537 );
 
-     printf( "  RSA-4096  :  " );
 
-     fflush( stdout );
 
-     set_alarm( 3 );
 
-     for( i = 1; ! alarmed; i++ )
 
-     {
 
-         buf[0] = 0;
 
-         rsa_public( &rsa, buf, buf );
 
-     }
 
-     printf( "%9lu  public/s\n", i / 3 );
 
-     printf( "  RSA-4096  :  " );
 
-     fflush( stdout );
 
-     set_alarm( 3 );
 
-     for( i = 1; ! alarmed; i++ )
 
-     {
 
-         buf[0] = 0;
 
-         rsa_private( &rsa, buf, buf );
 
-     }
 
-     printf( "%9lu private/s\n", i / 3 );
 
-     rsa_free( &rsa );
 
- #endif
 
-     printf( "\n" );
 
- #ifdef WIN32
 
-     printf( "  Press Enter to exit this program.\n" );
 
-     fflush( stdout ); getchar();
 
- #endif
 
-     return( 0 );
 
- }
 
- #endif /* POLARSSL_TIMING_C */
 
 
  |