2005-04-17 07:37:13 -04:00
# include <tomcrypt_test.h>
2003-07-10 22:09:41 -04:00
2005-04-17 07:37:13 -04:00
prng_state yarrow_prng ;
2003-12-24 13:59:57 -05:00
2014-08-28 07:18:30 -04:00
void print_hex ( const char * what , const unsigned char * p , const unsigned long l )
{
unsigned long x ;
fprintf ( stderr , " %s contents: \n " , what ) ;
for ( x = 0 ; x < l ; ) {
fprintf ( stderr , " %02x " , p [ x ] ) ;
if ( ! ( + + x % 16 ) ) {
fprintf ( stderr , " \n " ) ;
}
}
fprintf ( stderr , " \n " ) ;
}
2005-04-17 07:37:13 -04:00
struct list results [ 100 ] ;
2003-12-24 13:59:57 -05:00
int no_results ;
int sorter ( const void * a , const void * b )
{
const struct list * A , * B ;
A = a ;
B = b ;
if ( A - > avg < B - > avg ) return - 1 ;
if ( A - > avg > B - > avg ) return 1 ;
return 0 ;
}
void tally_results ( int type )
{
int x ;
2006-06-17 21:37:50 -04:00
/* qsort the results */
2003-12-24 13:59:57 -05:00
qsort ( results , no_results , sizeof ( struct list ) , & sorter ) ;
2005-06-08 20:08:13 -04:00
fprintf ( stderr , " \n " ) ;
2003-12-24 13:59:57 -05:00
if ( type = = 0 ) {
for ( x = 0 ; x < no_results ; x + + ) {
2005-06-08 20:08:13 -04:00
fprintf ( stderr , " %-20s: Schedule at %6lu \n " , cipher_descriptor [ results [ x ] . id ] . name , ( unsigned long ) results [ x ] . spd1 ) ;
2014-05-01 12:01:13 -04:00
}
2003-12-24 13:59:57 -05:00
} else if ( type = = 1 ) {
for ( x = 0 ; x < no_results ; x + + ) {
printf
2005-04-17 07:37:13 -04:00
( " %-20s[%3d]: Encrypt at %5lu, Decrypt at %5lu \n " , cipher_descriptor [ results [ x ] . id ] . name , cipher_descriptor [ results [ x ] . id ] . ID , results [ x ] . spd1 , results [ x ] . spd2 ) ;
2003-12-24 13:59:57 -05:00
}
} else {
for ( x = 0 ; x < no_results ; x + + ) {
printf
( " %-20s: Process at %5lu \n " , hash_descriptor [ results [ x ] . id ] . name , results [ x ] . spd1 / 1000 ) ;
}
}
}
2003-07-10 22:09:41 -04:00
/* RDTSC from Scott Duplichan */
2005-04-17 07:37:13 -04:00
ulong64 rdtsc ( void )
2003-07-10 22:09:41 -04:00
{
2005-06-08 20:08:13 -04:00
# if defined __GNUC__ && !defined(LTC_NO_ASM)
2014-07-12 10:46:36 -04:00
# if defined(__i386__) || defined(__x86_64__)
2014-05-01 12:01:13 -04:00
/* version from http://www.mcs.anl.gov/~kazutomo/rdtsc.html
* the old code always got a warning issued by gcc , clang did not complain . . .
*/
unsigned hi , lo ;
__asm__ __volatile__ ( " rdtsc " : " =a " ( lo ) , " =d " ( hi ) ) ;
return ( ( ulong64 ) lo ) | ( ( ( ulong64 ) hi ) < < 32 ) ;
2005-11-18 00:15:37 -05:00
# elif defined(LTC_PPC32) || defined(TFM_PPC32)
unsigned long a , b ;
__asm__ __volatile__ ( " mftbu %1 \n mftb %0 \n " : " =r " ( a ) , " =r " ( b ) ) ;
return ( ( ( ulong64 ) b ) < < 32ULL ) | ( ( ulong64 ) a ) ;
2005-04-19 07:30:30 -04:00
# elif defined(__ia64__) /* gcc-IA64 version */
2003-07-10 22:09:41 -04:00
unsigned long result ;
__asm__ __volatile__ ( " mov %0=ar.itc " : " =r " ( result ) : : " memory " ) ;
while ( __builtin_expect ( ( int ) result = = - 1 , 0 ) )
__asm__ __volatile__ ( " mov %0=ar.itc " : " =r " ( result ) : : " memory " ) ;
return result ;
2005-08-01 12:36:47 -04:00
# elif defined(__sparc__)
# if defined(__arch64__)
ulong64 a ;
asm volatile ( " rd %%tick,%0 " : " =r " ( a ) ) ;
return a ;
# else
register unsigned long x , y ;
__asm__ __volatile__ ( " rd %%tick, %0; clruw %0, %1; srlx %0, 32, %0 " : " =r " ( x ) , " =r " ( y ) : " 0 " ( x ) , " 1 " ( y ) ) ;
2014-05-01 12:01:13 -04:00
return ( ( unsigned long long ) x < < 32 ) | y ;
2005-08-01 12:36:47 -04:00
# endif
2014-05-01 12:01:13 -04:00
# else
2005-04-19 07:30:30 -04:00
return XCLOCK ( ) ;
2003-07-10 22:09:41 -04:00
# endif
2006-06-17 21:37:50 -04:00
/* Microsoft and Intel Windows compilers */
2005-06-08 20:08:13 -04:00
# elif defined _M_IX86 && !defined(LTC_NO_ASM)
2003-07-10 22:09:41 -04:00
__asm rdtsc
2005-06-08 20:08:13 -04:00
# elif defined _M_AMD64 && !defined(LTC_NO_ASM)
2003-07-10 22:09:41 -04:00
return __rdtsc ( ) ;
2005-06-08 20:08:13 -04:00
# elif defined _M_IA64 && !defined(LTC_NO_ASM)
2003-07-10 22:09:41 -04:00
# if defined __INTEL_COMPILER
# include <ia64intrin.h>
# endif
return __getReg ( 3116 ) ;
# else
2005-04-19 07:30:30 -04:00
return XCLOCK ( ) ;
2003-07-10 22:09:41 -04:00
# endif
}
2005-04-17 07:37:13 -04:00
static ulong64 timer , skew = 0 ;
2003-07-10 22:09:41 -04:00
void t_start ( void )
{
timer = rdtsc ( ) ;
}
ulong64 t_read ( void )
{
return rdtsc ( ) - timer ;
}
void init_timer ( void )
{
2014-05-01 12:01:13 -04:00
ulong64 c1 , c2 , t1 , t2 ;
2003-07-10 22:09:41 -04:00
unsigned long y1 ;
2003-09-25 21:16:18 -04:00
2003-07-10 22:09:41 -04:00
c1 = c2 = ( ulong64 ) - 1 ;
for ( y1 = 0 ; y1 < TIMES * 100 ; y1 + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
2005-04-17 07:37:13 -04:00
t2 = ( t_read ( ) - t1 ) > > 1 ;
2003-09-25 21:16:18 -04:00
2005-04-17 07:37:13 -04:00
c1 = ( t1 > c1 ) ? t1 : c1 ;
c2 = ( t2 > c2 ) ? t2 : c2 ;
2003-07-10 22:09:41 -04:00
}
skew = c2 - c1 ;
2005-06-08 20:08:13 -04:00
fprintf ( stderr , " Clock Skew: %lu \n " , ( unsigned long ) skew ) ;
2003-09-25 21:16:18 -04:00
}
2003-07-10 22:09:41 -04:00
2014-05-07 11:36:09 -04:00
/*
* unregister ciphers , hashes & prngs
*/
static void _unregister_all ( void )
{
# ifdef LTC_RIJNDAEL
unregister_cipher ( & aes_desc ) ;
# endif
# ifdef LTC_BLOWFISH
unregister_cipher ( & blowfish_desc ) ;
# endif
# ifdef LTC_XTEA
unregister_cipher ( & xtea_desc ) ;
# endif
# ifdef LTC_RC5
unregister_cipher ( & rc5_desc ) ;
# endif
# ifdef LTC_RC6
unregister_cipher ( & rc6_desc ) ;
# endif
# ifdef LTC_SAFERP
unregister_cipher ( & saferp_desc ) ;
# endif
# ifdef LTC_TWOFISH
unregister_cipher ( & twofish_desc ) ;
# endif
# ifdef LTC_SAFER
unregister_cipher ( & safer_k64_desc ) ;
unregister_cipher ( & safer_sk64_desc ) ;
unregister_cipher ( & safer_k128_desc ) ;
unregister_cipher ( & safer_sk128_desc ) ;
# endif
# ifdef LTC_RC2
unregister_cipher ( & rc2_desc ) ;
# endif
# ifdef LTC_DES
unregister_cipher ( & des_desc ) ;
unregister_cipher ( & des3_desc ) ;
# endif
# ifdef LTC_CAST5
unregister_cipher ( & cast5_desc ) ;
# endif
# ifdef LTC_NOEKEON
unregister_cipher ( & noekeon_desc ) ;
# endif
# ifdef LTC_SKIPJACK
unregister_cipher ( & skipjack_desc ) ;
# endif
# ifdef LTC_KHAZAD
unregister_cipher ( & khazad_desc ) ;
# endif
# ifdef LTC_ANUBIS
unregister_cipher ( & anubis_desc ) ;
# endif
# ifdef LTC_KSEED
unregister_cipher ( & kseed_desc ) ;
# endif
# ifdef LTC_KASUMI
unregister_cipher ( & kasumi_desc ) ;
# endif
# ifdef LTC_MULTI2
unregister_cipher ( & multi2_desc ) ;
# endif
# ifdef LTC_CAMELLIA
unregister_cipher ( & camellia_desc ) ;
# endif
# ifdef LTC_TIGER
unregister_hash ( & tiger_desc ) ;
# endif
# ifdef LTC_MD2
unregister_hash ( & md2_desc ) ;
# endif
# ifdef LTC_MD4
unregister_hash ( & md4_desc ) ;
# endif
# ifdef LTC_MD5
unregister_hash ( & md5_desc ) ;
# endif
# ifdef LTC_SHA1
unregister_hash ( & sha1_desc ) ;
# endif
# ifdef LTC_SHA224
unregister_hash ( & sha224_desc ) ;
# endif
# ifdef LTC_SHA256
unregister_hash ( & sha256_desc ) ;
# endif
# ifdef LTC_SHA384
unregister_hash ( & sha384_desc ) ;
# endif
# ifdef LTC_SHA512
unregister_hash ( & sha512_desc ) ;
# endif
2014-08-27 08:38:56 -04:00
# ifdef LTC_SHA512_224
unregister_hash ( & sha512_224_desc ) ;
# endif
# ifdef LTC_SHA512_256
unregister_hash ( & sha512_256_desc ) ;
# endif
2014-05-07 11:36:09 -04:00
# ifdef LTC_RIPEMD128
unregister_hash ( & rmd128_desc ) ;
# endif
# ifdef LTC_RIPEMD160
unregister_hash ( & rmd160_desc ) ;
# endif
# ifdef LTC_RIPEMD256
unregister_hash ( & rmd256_desc ) ;
# endif
# ifdef LTC_RIPEMD320
unregister_hash ( & rmd320_desc ) ;
# endif
# ifdef LTC_WHIRLPOOL
unregister_hash ( & whirlpool_desc ) ;
# endif
# ifdef LTC_CHC_HASH
unregister_hash ( & chc_desc ) ;
# endif
unregister_prng ( & yarrow_desc ) ;
# ifdef LTC_FORTUNA
unregister_prng ( & fortuna_desc ) ;
# endif
# ifdef LTC_RC4
unregister_prng ( & rc4_desc ) ;
# endif
# ifdef LTC_SOBER128
unregister_prng ( & sober128_desc ) ;
# endif
} /* _cleanup() */
2003-07-10 22:09:41 -04:00
void reg_algs ( void )
{
2004-10-29 23:00:26 -04:00
int err ;
2014-05-07 11:36:09 -04:00
atexit ( _unregister_all ) ;
2007-07-20 13:48:02 -04:00
# ifdef LTC_RIJNDAEL
2003-07-10 22:09:41 -04:00
register_cipher ( & aes_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_BLOWFISH
2003-07-10 22:09:41 -04:00
register_cipher ( & blowfish_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_XTEA
2003-07-10 22:09:41 -04:00
register_cipher ( & xtea_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_RC5
2003-07-10 22:09:41 -04:00
register_cipher ( & rc5_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_RC6
2003-07-10 22:09:41 -04:00
register_cipher ( & rc6_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_SAFERP
2003-07-10 22:09:41 -04:00
register_cipher ( & saferp_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_TWOFISH
2003-07-10 22:09:41 -04:00
register_cipher ( & twofish_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_SAFER
2003-07-10 22:09:41 -04:00
register_cipher ( & safer_k64_desc ) ;
register_cipher ( & safer_sk64_desc ) ;
register_cipher ( & safer_k128_desc ) ;
register_cipher ( & safer_sk128_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_RC2
2003-07-10 22:09:41 -04:00
register_cipher ( & rc2_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_DES
2003-07-10 22:09:41 -04:00
register_cipher ( & des_desc ) ;
register_cipher ( & des3_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_CAST5
2003-07-10 22:09:41 -04:00
register_cipher ( & cast5_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_NOEKEON
2003-07-10 22:09:41 -04:00
register_cipher ( & noekeon_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_SKIPJACK
2003-12-24 13:59:57 -05:00
register_cipher ( & skipjack_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_KHAZAD
2004-12-30 18:55:53 -05:00
register_cipher ( & khazad_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_ANUBIS
2004-12-30 18:55:53 -05:00
register_cipher ( & anubis_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_KSEED
2006-11-17 09:21:24 -05:00
register_cipher ( & kseed_desc ) ;
# endif
# ifdef LTC_KASUMI
register_cipher ( & kasumi_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_MULTI2
register_cipher ( & multi2_desc ) ;
# endif
2009-10-01 05:42:27 -04:00
# ifdef LTC_CAMELLIA
register_cipher ( & camellia_desc ) ;
# endif
2003-07-10 22:09:41 -04:00
2007-07-20 13:48:02 -04:00
# ifdef LTC_TIGER
2003-07-10 22:09:41 -04:00
register_hash ( & tiger_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_MD2
2003-07-10 22:09:41 -04:00
register_hash ( & md2_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_MD4
2003-07-10 22:09:41 -04:00
register_hash ( & md4_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_MD5
2003-07-10 22:09:41 -04:00
register_hash ( & md5_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_SHA1
2003-07-10 22:09:41 -04:00
register_hash ( & sha1_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_SHA224
2003-12-24 13:59:57 -05:00
register_hash ( & sha224_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_SHA256
2003-07-10 22:09:41 -04:00
register_hash ( & sha256_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_SHA384
2003-07-10 22:09:41 -04:00
register_hash ( & sha384_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_SHA512
2003-07-10 22:09:41 -04:00
register_hash ( & sha512_desc ) ;
# endif
2014-08-27 08:38:56 -04:00
# ifdef LTC_SHA512_224
register_hash ( & sha512_224_desc ) ;
# endif
# ifdef LTC_SHA512_256
register_hash ( & sha512_256_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_RIPEMD128
2003-09-07 21:06:11 -04:00
register_hash ( & rmd128_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_RIPEMD160
2003-09-25 21:16:18 -04:00
register_hash ( & rmd160_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_RIPEMD256
2006-11-17 09:21:24 -05:00
register_hash ( & rmd256_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_RIPEMD320
2006-11-17 09:21:24 -05:00
register_hash ( & rmd320_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_WHIRLPOOL
2004-02-20 15:03:32 -05:00
register_hash ( & whirlpool_desc ) ;
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_CHC_HASH
2004-10-29 23:00:26 -04:00
register_hash ( & chc_desc ) ;
if ( ( err = chc_register ( register_cipher ( & aes_desc ) ) ) ! = CRYPT_OK ) {
2005-06-08 20:08:13 -04:00
fprintf ( stderr , " chc_register error: %s \n " , error_to_string ( err ) ) ;
2004-10-29 23:00:26 -04:00
exit ( EXIT_FAILURE ) ;
}
# endif
2003-07-10 22:09:41 -04:00
2014-05-01 12:01:13 -04:00
# ifndef LTC_YARROW
2004-08-06 12:42:41 -04:00
# error This demo requires Yarrow.
# endif
2003-12-24 13:59:57 -05:00
register_prng ( & yarrow_desc ) ;
2007-07-20 13:48:02 -04:00
# ifdef LTC_FORTUNA
2004-07-23 11:40:22 -04:00
register_prng ( & fortuna_desc ) ;
2004-08-06 12:42:41 -04:00
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_RC4
2004-07-23 11:40:22 -04:00
register_prng ( & rc4_desc ) ;
2004-08-06 12:42:41 -04:00
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_SOBER128
2004-08-06 12:42:41 -04:00
register_prng ( & sober128_desc ) ;
# endif
2004-07-23 11:40:22 -04:00
2006-01-26 13:11:56 -05:00
if ( ( err = rng_make_prng ( 128 , find_prng ( " yarrow " ) , & yarrow_prng , NULL ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " rng_make_prng failed: %s \n " , error_to_string ( err ) ) ;
exit ( EXIT_FAILURE ) ;
}
2014-05-01 12:01:13 -04:00
2014-05-07 11:36:09 -04:00
if ( strcmp ( " CRYPT_OK " , error_to_string ( err ) ) ) {
exit ( EXIT_FAILURE ) ;
}
2003-07-10 22:09:41 -04:00
}
int time_keysched ( void )
{
2004-08-06 12:42:41 -04:00
unsigned long x , y1 ;
2003-07-10 22:09:41 -04:00
ulong64 t1 , c1 ;
symmetric_key skey ;
int kl ;
int ( * func ) ( const unsigned char * , int , int , symmetric_key * ) ;
unsigned char key [ MAXBLOCKSIZE ] ;
2005-06-08 20:08:13 -04:00
fprintf ( stderr , " \n \n Key Schedule Time Trials for the Symmetric Ciphers: \n (Times are cycles per key) \n " ) ;
2014-05-01 12:01:13 -04:00
no_results = 0 ;
2003-12-24 13:59:57 -05:00
for ( x = 0 ; cipher_descriptor [ x ] . name ! = NULL ; x + + ) {
2003-07-10 22:09:41 -04:00
# define DO1(k) func(k, kl, 0, &skey);
func = cipher_descriptor [ x ] . setup ;
kl = cipher_descriptor [ x ] . min_key_length ;
c1 = ( ulong64 ) - 1 ;
for ( y1 = 0 ; y1 < KTIMES ; y1 + + ) {
2005-04-17 07:37:13 -04:00
yarrow_read ( key , kl , & yarrow_prng ) ;
2003-07-10 22:09:41 -04:00
t_start ( ) ;
DO1 ( key ) ;
t1 = t_read ( ) ;
c1 = ( t1 > c1 ) ? c1 : t1 ;
}
t1 = c1 - skew ;
2003-12-24 13:59:57 -05:00
results [ no_results ] . spd1 = results [ no_results ] . avg = t1 ;
results [ no_results + + ] . id = x ;
2005-06-08 20:08:13 -04:00
fprintf ( stderr , " . " ) ; fflush ( stdout ) ;
2003-07-10 22:09:41 -04:00
# undef DO1
}
2003-12-24 13:59:57 -05:00
tally_results ( 0 ) ;
2003-09-25 21:16:18 -04:00
2003-07-10 22:09:41 -04:00
return 0 ;
}
int time_cipher ( void )
{
unsigned long x , y1 ;
ulong64 t1 , t2 , c1 , c2 , a1 , a2 ;
2005-04-17 07:37:13 -04:00
symmetric_ECB ecb ;
unsigned char key [ MAXBLOCKSIZE ] , pt [ 4096 ] ;
2004-08-06 12:42:41 -04:00
int err ;
2003-07-10 22:09:41 -04:00
2005-06-08 20:08:13 -04:00
fprintf ( stderr , " \n \n ECB Time Trials for the Symmetric Ciphers: \n " ) ;
2003-12-24 13:59:57 -05:00
no_results = 0 ;
2003-07-10 22:09:41 -04:00
for ( x = 0 ; cipher_descriptor [ x ] . name ! = NULL ; x + + ) {
2005-04-17 07:37:13 -04:00
ecb_start ( x , key , cipher_descriptor [ x ] . min_key_length , 0 , & ecb ) ;
2003-07-10 22:09:41 -04:00
2004-08-06 12:42:41 -04:00
/* sanity check on cipher */
if ( ( err = cipher_descriptor [ x ] . test ( ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n \n ERROR: Cipher %s failed self-test %s \n " , cipher_descriptor [ x ] . name , error_to_string ( err ) ) ;
exit ( EXIT_FAILURE ) ;
}
2005-04-17 07:37:13 -04:00
# define DO1 ecb_encrypt(pt, pt, sizeof(pt), &ecb);
2003-07-10 22:09:41 -04:00
# define DO2 DO1 DO1
c1 = c2 = ( ulong64 ) - 1 ;
2005-04-17 07:37:13 -04:00
for ( y1 = 0 ; y1 < 100 ; y1 + + ) {
2003-07-10 22:09:41 -04:00
t_start ( ) ;
DO1 ;
t1 = t_read ( ) ;
DO2 ;
t2 = t_read ( ) ;
t2 - = t1 ;
2003-09-25 21:16:18 -04:00
2003-07-10 22:09:41 -04:00
c1 = ( t1 > c1 ? c1 : t1 ) ;
c2 = ( t2 > c2 ? c2 : t2 ) ;
}
a1 = c2 - c1 - skew ;
2003-09-25 21:16:18 -04:00
2005-04-17 07:37:13 -04:00
# undef DO1
# undef DO2
# define DO1 ecb_decrypt(pt, pt, sizeof(pt), &ecb);
# define DO2 DO1 DO1
2003-09-25 21:16:18 -04:00
2003-07-10 22:09:41 -04:00
c1 = c2 = ( ulong64 ) - 1 ;
2005-04-17 07:37:13 -04:00
for ( y1 = 0 ; y1 < 100 ; y1 + + ) {
t_start ( ) ;
DO1 ;
t1 = t_read ( ) ;
DO2 ;
t2 = t_read ( ) ;
t2 - = t1 ;
c1 = ( t1 > c1 ? c1 : t1 ) ;
c2 = ( t2 > c2 ? c2 : t2 ) ;
}
a2 = c2 - c1 - skew ;
2006-02-11 03:19:10 -05:00
ecb_done ( & ecb ) ;
2014-05-01 12:01:13 -04:00
2005-04-17 07:37:13 -04:00
results [ no_results ] . id = x ;
results [ no_results ] . spd1 = a1 / ( sizeof ( pt ) / cipher_descriptor [ x ] . block_length ) ;
results [ no_results ] . spd2 = a2 / ( sizeof ( pt ) / cipher_descriptor [ x ] . block_length ) ;
results [ no_results ] . avg = ( results [ no_results ] . spd1 + results [ no_results ] . spd2 + 1 ) / 2 ;
+ + no_results ;
2005-06-08 20:08:13 -04:00
fprintf ( stderr , " . " ) ; fflush ( stdout ) ;
2014-05-01 12:01:13 -04:00
2005-04-17 07:37:13 -04:00
# undef DO2
# undef DO1
}
tally_results ( 1 ) ;
return 0 ;
}
2014-05-01 12:01:13 -04:00
# ifdef LTC_CBC_MODE
2005-04-17 07:37:13 -04:00
int time_cipher2 ( void )
{
unsigned long x , y1 ;
ulong64 t1 , t2 , c1 , c2 , a1 , a2 ;
symmetric_CBC cbc ;
unsigned char key [ MAXBLOCKSIZE ] , pt [ 4096 ] ;
int err ;
2005-06-08 20:08:13 -04:00
fprintf ( stderr , " \n \n CBC Time Trials for the Symmetric Ciphers: \n " ) ;
2005-04-17 07:37:13 -04:00
no_results = 0 ;
for ( x = 0 ; cipher_descriptor [ x ] . name ! = NULL ; x + + ) {
cbc_start ( x , pt , key , cipher_descriptor [ x ] . min_key_length , 0 , & cbc ) ;
/* sanity check on cipher */
if ( ( err = cipher_descriptor [ x ] . test ( ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n \n ERROR: Cipher %s failed self-test %s \n " , cipher_descriptor [ x ] . name , error_to_string ( err ) ) ;
exit ( EXIT_FAILURE ) ;
}
# define DO1 cbc_encrypt(pt, pt, sizeof(pt), &cbc);
# define DO2 DO1 DO1
c1 = c2 = ( ulong64 ) - 1 ;
for ( y1 = 0 ; y1 < 100 ; y1 + + ) {
t_start ( ) ;
DO1 ;
t1 = t_read ( ) ;
DO2 ;
t2 = t_read ( ) ;
t2 - = t1 ;
c1 = ( t1 > c1 ? c1 : t1 ) ;
c2 = ( t2 > c2 ? c2 : t2 ) ;
}
a1 = c2 - c1 - skew ;
# undef DO1
# undef DO2
# define DO1 cbc_decrypt(pt, pt, sizeof(pt), &cbc);
# define DO2 DO1 DO1
c1 = c2 = ( ulong64 ) - 1 ;
for ( y1 = 0 ; y1 < 100 ; y1 + + ) {
2003-07-10 22:09:41 -04:00
t_start ( ) ;
DO1 ;
t1 = t_read ( ) ;
DO2 ;
t2 = t_read ( ) ;
t2 - = t1 ;
2003-09-25 21:16:18 -04:00
2003-07-10 22:09:41 -04:00
c1 = ( t1 > c1 ? c1 : t1 ) ;
c2 = ( t2 > c2 ? c2 : t2 ) ;
}
a2 = c2 - c1 - skew ;
2006-02-11 03:19:10 -05:00
cbc_done ( & cbc ) ;
2014-05-01 12:01:13 -04:00
2003-12-24 13:59:57 -05:00
results [ no_results ] . id = x ;
2005-04-17 07:37:13 -04:00
results [ no_results ] . spd1 = a1 / ( sizeof ( pt ) / cipher_descriptor [ x ] . block_length ) ;
results [ no_results ] . spd2 = a2 / ( sizeof ( pt ) / cipher_descriptor [ x ] . block_length ) ;
2003-12-24 13:59:57 -05:00
results [ no_results ] . avg = ( results [ no_results ] . spd1 + results [ no_results ] . spd2 + 1 ) / 2 ;
+ + no_results ;
2005-06-08 20:08:13 -04:00
fprintf ( stderr , " . " ) ; fflush ( stdout ) ;
2014-05-01 12:01:13 -04:00
2003-07-10 22:09:41 -04:00
# undef DO2
# undef DO1
}
2003-12-24 13:59:57 -05:00
tally_results ( 1 ) ;
2003-09-25 21:16:18 -04:00
2003-07-10 22:09:41 -04:00
return 0 ;
}
2005-04-17 07:37:13 -04:00
# else
2005-06-08 20:08:13 -04:00
int time_cipher2 ( void ) { fprintf ( stderr , " NO CBC \n " ) ; return 0 ; }
2005-04-17 07:37:13 -04:00
# endif
2006-08-30 19:30:00 -04:00
# ifdef LTC_CTR_MODE
2005-04-17 07:37:13 -04:00
int time_cipher3 ( void )
{
unsigned long x , y1 ;
ulong64 t1 , t2 , c1 , c2 , a1 , a2 ;
symmetric_CTR ctr ;
unsigned char key [ MAXBLOCKSIZE ] , pt [ 4096 ] ;
int err ;
2005-06-08 20:08:13 -04:00
fprintf ( stderr , " \n \n CTR Time Trials for the Symmetric Ciphers: \n " ) ;
2005-04-17 07:37:13 -04:00
no_results = 0 ;
for ( x = 0 ; cipher_descriptor [ x ] . name ! = NULL ; x + + ) {
2005-06-08 20:08:13 -04:00
ctr_start ( x , pt , key , cipher_descriptor [ x ] . min_key_length , 0 , CTR_COUNTER_LITTLE_ENDIAN , & ctr ) ;
2005-04-17 07:37:13 -04:00
/* sanity check on cipher */
if ( ( err = cipher_descriptor [ x ] . test ( ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n \n ERROR: Cipher %s failed self-test %s \n " , cipher_descriptor [ x ] . name , error_to_string ( err ) ) ;
exit ( EXIT_FAILURE ) ;
}
# define DO1 ctr_encrypt(pt, pt, sizeof(pt), &ctr);
# define DO2 DO1 DO1
c1 = c2 = ( ulong64 ) - 1 ;
for ( y1 = 0 ; y1 < 100 ; y1 + + ) {
t_start ( ) ;
DO1 ;
t1 = t_read ( ) ;
DO2 ;
t2 = t_read ( ) ;
t2 - = t1 ;
c1 = ( t1 > c1 ? c1 : t1 ) ;
c2 = ( t2 > c2 ? c2 : t2 ) ;
}
a1 = c2 - c1 - skew ;
# undef DO1
# undef DO2
# define DO1 ctr_decrypt(pt, pt, sizeof(pt), &ctr);
# define DO2 DO1 DO1
c1 = c2 = ( ulong64 ) - 1 ;
for ( y1 = 0 ; y1 < 100 ; y1 + + ) {
t_start ( ) ;
DO1 ;
t1 = t_read ( ) ;
DO2 ;
t2 = t_read ( ) ;
t2 - = t1 ;
c1 = ( t1 > c1 ? c1 : t1 ) ;
c2 = ( t2 > c2 ? c2 : t2 ) ;
}
a2 = c2 - c1 - skew ;
2006-02-11 03:19:10 -05:00
ctr_done ( & ctr ) ;
2014-05-01 12:01:13 -04:00
2005-04-17 07:37:13 -04:00
results [ no_results ] . id = x ;
results [ no_results ] . spd1 = a1 / ( sizeof ( pt ) / cipher_descriptor [ x ] . block_length ) ;
results [ no_results ] . spd2 = a2 / ( sizeof ( pt ) / cipher_descriptor [ x ] . block_length ) ;
results [ no_results ] . avg = ( results [ no_results ] . spd1 + results [ no_results ] . spd2 + 1 ) / 2 ;
+ + no_results ;
2005-06-08 20:08:13 -04:00
fprintf ( stderr , " . " ) ; fflush ( stdout ) ;
2014-05-01 12:01:13 -04:00
2005-04-17 07:37:13 -04:00
# undef DO2
# undef DO1
}
tally_results ( 1 ) ;
return 0 ;
}
# else
2005-06-08 20:08:13 -04:00
int time_cipher3 ( void ) { fprintf ( stderr , " NO CTR \n " ) ; return 0 ; }
2005-04-17 07:37:13 -04:00
# endif
2003-07-10 22:09:41 -04:00
2006-08-30 19:30:00 -04:00
# ifdef LTC_LRW_MODE
2006-02-11 03:19:10 -05:00
int time_cipher4 ( void )
{
unsigned long x , y1 ;
ulong64 t1 , t2 , c1 , c2 , a1 , a2 ;
symmetric_LRW lrw ;
unsigned char key [ MAXBLOCKSIZE ] , pt [ 4096 ] ;
int err ;
fprintf ( stderr , " \n \n LRW Time Trials for the Symmetric Ciphers: \n " ) ;
no_results = 0 ;
for ( x = 0 ; cipher_descriptor [ x ] . name ! = NULL ; x + + ) {
if ( cipher_descriptor [ x ] . block_length ! = 16 ) continue ;
lrw_start ( x , pt , key , cipher_descriptor [ x ] . min_key_length , key , 0 , & lrw ) ;
/* sanity check on cipher */
if ( ( err = cipher_descriptor [ x ] . test ( ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n \n ERROR: Cipher %s failed self-test %s \n " , cipher_descriptor [ x ] . name , error_to_string ( err ) ) ;
exit ( EXIT_FAILURE ) ;
}
# define DO1 lrw_encrypt(pt, pt, sizeof(pt), &lrw);
# define DO2 DO1 DO1
c1 = c2 = ( ulong64 ) - 1 ;
for ( y1 = 0 ; y1 < 100 ; y1 + + ) {
t_start ( ) ;
DO1 ;
t1 = t_read ( ) ;
DO2 ;
t2 = t_read ( ) ;
t2 - = t1 ;
c1 = ( t1 > c1 ? c1 : t1 ) ;
c2 = ( t2 > c2 ? c2 : t2 ) ;
}
a1 = c2 - c1 - skew ;
# undef DO1
# undef DO2
# define DO1 lrw_decrypt(pt, pt, sizeof(pt), &lrw);
# define DO2 DO1 DO1
c1 = c2 = ( ulong64 ) - 1 ;
for ( y1 = 0 ; y1 < 100 ; y1 + + ) {
t_start ( ) ;
DO1 ;
t1 = t_read ( ) ;
DO2 ;
t2 = t_read ( ) ;
t2 - = t1 ;
c1 = ( t1 > c1 ? c1 : t1 ) ;
c2 = ( t2 > c2 ? c2 : t2 ) ;
}
a2 = c2 - c1 - skew ;
lrw_done ( & lrw ) ;
2014-05-01 12:01:13 -04:00
2006-02-11 03:19:10 -05:00
results [ no_results ] . id = x ;
results [ no_results ] . spd1 = a1 / ( sizeof ( pt ) / cipher_descriptor [ x ] . block_length ) ;
results [ no_results ] . spd2 = a2 / ( sizeof ( pt ) / cipher_descriptor [ x ] . block_length ) ;
results [ no_results ] . avg = ( results [ no_results ] . spd1 + results [ no_results ] . spd2 + 1 ) / 2 ;
+ + no_results ;
fprintf ( stderr , " . " ) ; fflush ( stdout ) ;
2014-05-01 12:01:13 -04:00
2006-02-11 03:19:10 -05:00
# undef DO2
# undef DO1
}
tally_results ( 1 ) ;
return 0 ;
}
# else
int time_cipher4 ( void ) { fprintf ( stderr , " NO LRW \n " ) ; return 0 ; }
# endif
2003-07-10 22:09:41 -04:00
int time_hash ( void )
{
unsigned long x , y1 , len ;
ulong64 t1 , t2 , c1 , c2 ;
hash_state md ;
2004-08-06 12:42:41 -04:00
int ( * func ) ( hash_state * , const unsigned char * , unsigned long ) , err ;
2003-07-10 22:09:41 -04:00
unsigned char pt [ MAXBLOCKSIZE ] ;
2003-09-25 21:16:18 -04:00
2005-06-08 20:08:13 -04:00
fprintf ( stderr , " \n \n HASH Time Trials for: \n " ) ;
2003-12-24 13:59:57 -05:00
no_results = 0 ;
2003-07-10 22:09:41 -04:00
for ( x = 0 ; hash_descriptor [ x ] . name ! = NULL ; x + + ) {
2004-08-06 12:42:41 -04:00
/* sanity check on hash */
if ( ( err = hash_descriptor [ x ] . test ( ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n \n ERROR: Hash %s failed self-test %s \n " , hash_descriptor [ x ] . name , error_to_string ( err ) ) ;
exit ( EXIT_FAILURE ) ;
}
2003-07-10 22:09:41 -04:00
hash_descriptor [ x ] . init ( & md ) ;
# define DO1 func(&md,pt,len);
# define DO2 DO1 DO1
func = hash_descriptor [ x ] . process ;
len = hash_descriptor [ x ] . blocksize ;
2003-09-25 21:16:18 -04:00
2003-07-10 22:09:41 -04:00
c1 = c2 = ( ulong64 ) - 1 ;
for ( y1 = 0 ; y1 < TIMES ; y1 + + ) {
t_start ( ) ;
DO1 ;
t1 = t_read ( ) ;
DO2 ;
t2 = t_read ( ) - t1 ;
c1 = ( t1 > c1 ) ? c1 : t1 ;
c2 = ( t2 > c2 ) ? c2 : t2 ;
}
2003-09-25 21:16:18 -04:00
t1 = c2 - c1 - skew ;
2003-07-10 22:09:41 -04:00
t1 = ( ( t1 * CONST64 ( 1000 ) ) ) / ( ( ulong64 ) hash_descriptor [ x ] . blocksize ) ;
2003-12-24 13:59:57 -05:00
results [ no_results ] . id = x ;
results [ no_results ] . spd1 = results [ no_results ] . avg = t1 ;
+ + no_results ;
2005-06-08 20:08:13 -04:00
fprintf ( stderr , " . " ) ; fflush ( stdout ) ;
2003-07-10 22:09:41 -04:00
# undef DO2
# undef DO1
}
2003-12-24 13:59:57 -05:00
tally_results ( 2 ) ;
2003-09-25 21:16:18 -04:00
2003-07-10 22:09:41 -04:00
return 0 ;
}
2006-06-17 21:37:50 -04:00
/*#warning you need an mp_rand!!!*/
2014-07-12 11:31:03 -04:00
# ifndef USE_LTM
2014-07-17 04:49:05 -04:00
# undef LTC_MPI
2014-07-12 11:31:03 -04:00
# endif
2005-08-01 12:36:47 -04:00
2014-07-17 04:49:05 -04:00
# ifdef LTC_MPI
2004-07-23 11:40:22 -04:00
void time_mult ( void )
{
ulong64 t1 , t2 ;
unsigned long x , y ;
2005-08-01 12:36:47 -04:00
void * a , * b , * c ;
2004-07-23 11:40:22 -04:00
2005-06-08 20:08:13 -04:00
fprintf ( stderr , " Timing Multiplying: \n " ) ;
2004-07-23 11:40:22 -04:00
mp_init_multi ( & a , & b , & c , NULL ) ;
2014-07-12 11:31:03 -04:00
for ( x = 128 / MP_DIGIT_BIT ; x < = ( unsigned long ) 1536 / MP_DIGIT_BIT ; x + = 128 / MP_DIGIT_BIT ) {
mp_rand ( a , x ) ;
mp_rand ( b , x ) ;
2004-07-23 11:40:22 -04:00
2014-07-12 11:31:03 -04:00
# define DO1 mp_mul(a, b, c);
2004-07-23 11:40:22 -04:00
# define DO2 DO1; DO1;
t2 = - 1 ;
for ( y = 0 ; y < TIMES ; y + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
DO2 ;
t1 = ( t_read ( ) - t1 ) > > 1 ;
if ( t1 < t2 ) t2 = t1 ;
}
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " %4lu bits: %9 " PRI64 " u cycles \n " , x * MP_DIGIT_BIT , t2 ) ;
2004-07-23 11:40:22 -04:00
}
2014-07-12 11:31:03 -04:00
mp_clear_multi ( a , b , c , NULL ) ;
2004-07-23 11:40:22 -04:00
# undef DO1
# undef DO2
2014-05-01 12:01:13 -04:00
}
2004-07-23 11:40:22 -04:00
void time_sqr ( void )
{
ulong64 t1 , t2 ;
unsigned long x , y ;
2014-07-12 11:31:03 -04:00
void * a , * b ;
2004-07-23 11:40:22 -04:00
2005-06-08 20:08:13 -04:00
fprintf ( stderr , " Timing Squaring: \n " ) ;
2004-07-23 11:40:22 -04:00
mp_init_multi ( & a , & b , NULL ) ;
2014-07-12 11:31:03 -04:00
for ( x = 128 / MP_DIGIT_BIT ; x < = ( unsigned long ) 1536 / MP_DIGIT_BIT ; x + = 128 / MP_DIGIT_BIT ) {
mp_rand ( a , x ) ;
2004-07-23 11:40:22 -04:00
2014-07-12 11:31:03 -04:00
# define DO1 mp_sqr(a, b);
2004-07-23 11:40:22 -04:00
# define DO2 DO1; DO1;
t2 = - 1 ;
for ( y = 0 ; y < TIMES ; y + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
DO2 ;
t1 = ( t_read ( ) - t1 ) > > 1 ;
if ( t1 < t2 ) t2 = t1 ;
}
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " %4lu bits: %9 " PRI64 " u cycles \n " , x * MP_DIGIT_BIT , t2 ) ;
2004-07-23 11:40:22 -04:00
}
2014-07-12 11:31:03 -04:00
mp_clear_multi ( a , b , NULL ) ;
2004-07-23 11:40:22 -04:00
# undef DO1
# undef DO2
2005-04-17 07:37:13 -04:00
}
# else
2005-06-08 20:08:13 -04:00
void time_mult ( void ) { fprintf ( stderr , " NO MULT \n " ) ; }
void time_sqr ( void ) { fprintf ( stderr , " NO SQR \n " ) ; }
2005-04-17 07:37:13 -04:00
# endif
2014-05-01 12:01:13 -04:00
2004-07-23 11:40:22 -04:00
void time_prng ( void )
{
ulong64 t1 , t2 ;
unsigned char buf [ 4096 ] ;
2004-08-06 12:42:41 -04:00
prng_state tprng ;
2004-07-23 11:40:22 -04:00
unsigned long x , y ;
2004-08-06 12:42:41 -04:00
int err ;
2004-07-23 11:40:22 -04:00
2005-06-08 20:08:13 -04:00
fprintf ( stderr , " Timing PRNGs (cycles/byte output, cycles add_entropy (32 bytes) : \n " ) ;
2004-07-23 11:40:22 -04:00
for ( x = 0 ; prng_descriptor [ x ] . name ! = NULL ; x + + ) {
2004-08-06 12:42:41 -04:00
/* sanity check on prng */
if ( ( err = prng_descriptor [ x ] . test ( ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n \n ERROR: PRNG %s failed self-test %s \n " , prng_descriptor [ x ] . name , error_to_string ( err ) ) ;
exit ( EXIT_FAILURE ) ;
}
prng_descriptor [ x ] . start ( & tprng ) ;
2004-07-23 11:40:22 -04:00
zeromem ( buf , 256 ) ;
2004-08-06 12:42:41 -04:00
prng_descriptor [ x ] . add_entropy ( buf , 256 , & tprng ) ;
prng_descriptor [ x ] . ready ( & tprng ) ;
2004-07-23 11:40:22 -04:00
t2 = - 1 ;
2005-06-08 20:08:13 -04:00
# define DO1 if (prng_descriptor[x].read(buf, 4096, &tprng) != 4096) { fprintf(stderr, "\n\nERROR READ != 4096\n\n"); exit(EXIT_FAILURE); }
2004-07-23 11:40:22 -04:00
# define DO2 DO1 DO1
2004-08-06 12:42:41 -04:00
for ( y = 0 ; y < 10000 ; y + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
DO2 ;
t1 = ( t_read ( ) - t1 ) > > 1 ;
if ( t1 < t2 ) t2 = t1 ;
}
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " %20s: %5 " PRI64 " u " , prng_descriptor [ x ] . name , t2 > > 12 ) ;
2004-08-06 12:42:41 -04:00
# undef DO2
# undef DO1
2004-07-23 11:40:22 -04:00
2004-08-06 12:42:41 -04:00
# define DO1 prng_descriptor[x].start(&tprng); prng_descriptor[x].add_entropy(buf, 32, &tprng); prng_descriptor[x].ready(&tprng); prng_descriptor[x].done(&tprng);
# define DO2 DO1 DO1
2004-07-23 11:40:22 -04:00
for ( y = 0 ; y < 10000 ; y + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
DO2 ;
t1 = ( t_read ( ) - t1 ) > > 1 ;
if ( t1 < t2 ) t2 = t1 ;
}
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " %5 " PRI64 " u \n " , t2 ) ;
2004-07-23 11:40:22 -04:00
# undef DO2
# undef DO1
2004-08-06 12:42:41 -04:00
}
2004-07-23 11:40:22 -04:00
}
2005-04-17 07:37:13 -04:00
2007-07-20 13:48:02 -04:00
# ifdef LTC_MDSA
2006-11-17 09:21:24 -05:00
/* time various DSA operations */
void time_dsa ( void )
{
dsa_key key ;
ulong64 t1 , t2 ;
2006-12-16 13:10:04 -05:00
unsigned long x , y ;
int err ;
2006-11-17 09:21:24 -05:00
static const struct {
int group , modulus ;
} groups [ ] = {
2014-05-01 12:01:13 -04:00
{ 20 , 96 } ,
2006-11-17 09:21:24 -05:00
{ 20 , 128 } ,
{ 24 , 192 } ,
{ 28 , 256 } ,
{ 32 , 512 }
} ;
for ( x = 0 ; x < ( sizeof ( groups ) / sizeof ( groups [ 0 ] ) ) ; x + + ) {
t2 = 0 ;
for ( y = 0 ; y < 4 ; y + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
if ( ( err = dsa_make_key ( & yarrow_prng , find_prng ( " yarrow " ) , groups [ x ] . group , groups [ x ] . modulus , & key ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n \n dsa_make_key says %s, wait...no it should say %s...damn you! \n " , error_to_string ( err ) , error_to_string ( CRYPT_OK ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
t2 + = t1 ;
# ifdef LTC_PROFILE
t2 < < = 2 ;
break ;
# endif
if ( y < 3 ) {
dsa_free ( & key ) ;
}
}
t2 > > = 2 ;
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " DSA-(%lu, %lu) make_key took %15 " PRI64 " u cycles \n " , ( unsigned long ) groups [ x ] . group * 8 , ( unsigned long ) groups [ x ] . modulus * 8 , t2 ) ;
2006-11-17 09:21:24 -05:00
}
}
# endif
2014-05-01 12:01:13 -04:00
# ifdef LTC_MRSA
2004-08-06 12:42:41 -04:00
/* time various RSA operations */
void time_rsa ( void )
{
2006-11-17 09:21:24 -05:00
rsa_key key ;
ulong64 t1 , t2 ;
unsigned char buf [ 2 ] [ 2048 ] ;
2004-08-06 12:42:41 -04:00
unsigned long x , y , z , zzz ;
2006-11-17 09:21:24 -05:00
int err , zz , stat ;
2004-08-06 12:42:41 -04:00
2005-08-01 12:36:47 -04:00
for ( x = 1024 ; x < = 2048 ; x + = 256 ) {
2004-08-06 12:42:41 -04:00
t2 = 0 ;
2005-08-01 12:36:47 -04:00
for ( y = 0 ; y < 4 ; y + + ) {
2004-08-06 12:42:41 -04:00
t_start ( ) ;
t1 = t_read ( ) ;
2005-04-17 07:37:13 -04:00
if ( ( err = rsa_make_key ( & yarrow_prng , find_prng ( " yarrow " ) , x / 8 , 65537 , & key ) ) ! = CRYPT_OK ) {
2004-08-06 12:42:41 -04:00
fprintf ( stderr , " \n \n rsa_make_key says %s, wait...no it should say %s...damn you! \n " , error_to_string ( err ) , error_to_string ( CRYPT_OK ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
t2 + = t1 ;
2006-11-17 09:21:24 -05:00
# ifdef LTC_PROFILE
t2 < < = 2 ;
break ;
# endif
2005-08-01 12:36:47 -04:00
if ( y < 3 ) {
2004-08-06 12:42:41 -04:00
rsa_free ( & key ) ;
}
}
2005-08-01 12:36:47 -04:00
t2 > > = 2 ;
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " RSA-%lu make_key took %15 " PRI64 " u cycles \n " , x , t2 ) ;
2004-08-06 12:42:41 -04:00
t2 = 0 ;
for ( y = 0 ; y < 16 ; y + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
z = sizeof ( buf [ 1 ] ) ;
2006-06-17 21:37:50 -04:00
if ( ( err = rsa_encrypt_key ( buf [ 0 ] , 32 , buf [ 1 ] , & z , ( const unsigned char * ) " testprog " , 8 , & yarrow_prng ,
2004-08-06 12:42:41 -04:00
find_prng ( " yarrow " ) , find_hash ( " sha1 " ) ,
& key ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n \n rsa_encrypt_key says %s, wait...no it should say %s...damn you! \n " , error_to_string ( err ) , error_to_string ( CRYPT_OK ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
t2 + = t1 ;
2006-11-17 09:21:24 -05:00
# ifdef LTC_PROFILE
t2 < < = 4 ;
break ;
# endif
2004-08-06 12:42:41 -04:00
}
t2 > > = 4 ;
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " RSA-%lu encrypt_key took %15 " PRI64 " u cycles \n " , x , t2 ) ;
2004-08-06 12:42:41 -04:00
t2 = 0 ;
2005-11-18 00:15:37 -05:00
for ( y = 0 ; y < 2048 ; y + + ) {
2004-08-06 12:42:41 -04:00
t_start ( ) ;
t1 = t_read ( ) ;
zzz = sizeof ( buf [ 0 ] ) ;
2014-05-01 12:01:13 -04:00
if ( ( err = rsa_decrypt_key ( buf [ 1 ] , z , buf [ 0 ] , & zzz , ( const unsigned char * ) " testprog " , 8 , find_hash ( " sha1 " ) ,
2004-08-06 12:42:41 -04:00
& zz , & key ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n \n rsa_decrypt_key says %s, wait...no it should say %s...damn you! \n " , error_to_string ( err ) , error_to_string ( CRYPT_OK ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
t2 + = t1 ;
2006-11-17 09:21:24 -05:00
# ifdef LTC_PROFILE
t2 < < = 11 ;
break ;
# endif
2004-08-06 12:42:41 -04:00
}
2005-11-18 00:15:37 -05:00
t2 > > = 11 ;
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " RSA-%lu decrypt_key took %15 " PRI64 " u cycles \n " , x , t2 ) ;
2004-08-06 12:42:41 -04:00
2006-11-17 09:21:24 -05:00
t2 = 0 ;
for ( y = 0 ; y < 256 ; y + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
z = sizeof ( buf [ 1 ] ) ;
2014-05-01 12:01:13 -04:00
if ( ( err = rsa_sign_hash ( buf [ 0 ] , 20 , buf [ 1 ] , & z , & yarrow_prng ,
2006-11-17 09:21:24 -05:00
find_prng ( " yarrow " ) , find_hash ( " sha1 " ) , 8 , & key ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n \n rsa_sign_hash says %s, wait...no it should say %s...damn you! \n " , error_to_string ( err ) , error_to_string ( CRYPT_OK ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
t2 + = t1 ;
# ifdef LTC_PROFILE
t2 < < = 8 ;
break ;
# endif
}
t2 > > = 8 ;
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " RSA-%lu sign_hash took %15 " PRI64 " u cycles \n " , x , t2 ) ;
2004-08-06 12:42:41 -04:00
2006-11-17 09:21:24 -05:00
t2 = 0 ;
for ( y = 0 ; y < 2048 ; y + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
if ( ( err = rsa_verify_hash ( buf [ 1 ] , z , buf [ 0 ] , 20 , find_hash ( " sha1 " ) , 8 , & stat , & key ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n \n rsa_verify_hash says %s, wait...no it should say %s...damn you! \n " , error_to_string ( err ) , error_to_string ( CRYPT_OK ) ) ;
exit ( EXIT_FAILURE ) ;
}
if ( stat = = 0 ) {
fprintf ( stderr , " \n \n rsa_verify_hash for RSA-%lu failed to verify signature(%lu) \n " , x , y ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
t2 + = t1 ;
# ifdef LTC_PROFILE
t2 < < = 11 ;
break ;
# endif
}
t2 > > = 11 ;
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " RSA-%lu verify_hash took %15 " PRI64 " u cycles \n " , x , t2 ) ;
2006-11-17 09:21:24 -05:00
fprintf ( stderr , " \n \n " ) ;
2004-08-06 12:42:41 -04:00
rsa_free ( & key ) ;
}
}
2005-04-17 07:37:13 -04:00
# else
2005-06-08 20:08:13 -04:00
void time_rsa ( void ) { fprintf ( stderr , " NO RSA \n " ) ; }
2005-04-17 07:37:13 -04:00
# endif
2004-07-23 11:40:22 -04:00
2014-08-28 07:27:52 -04:00
# ifdef LTC_MKAT
2005-11-18 00:15:37 -05:00
/* time various KAT operations */
void time_katja ( void )
{
katja_key key ;
ulong64 t1 , t2 ;
unsigned char buf [ 2 ] [ 4096 ] ;
unsigned long x , y , z , zzz ;
int err , zz ;
for ( x = 1024 ; x < = 2048 ; x + = 256 ) {
t2 = 0 ;
for ( y = 0 ; y < 4 ; y + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
if ( ( err = katja_make_key ( & yarrow_prng , find_prng ( " yarrow " ) , x / 8 , & key ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n \n katja_make_key says %s, wait...no it should say %s...damn you! \n " , error_to_string ( err ) , error_to_string ( CRYPT_OK ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
t2 + = t1 ;
if ( y < 3 ) {
2006-11-17 09:21:24 -05:00
katja_free ( & key ) ;
2005-11-18 00:15:37 -05:00
}
}
t2 > > = 2 ;
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " Katja-%lu make_key took %15 " PRI64 " u cycles \n " , x , t2 ) ;
2005-11-18 00:15:37 -05:00
t2 = 0 ;
for ( y = 0 ; y < 16 ; y + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
z = sizeof ( buf [ 1 ] ) ;
if ( ( err = katja_encrypt_key ( buf [ 0 ] , 32 , buf [ 1 ] , & z , " testprog " , 8 , & yarrow_prng ,
find_prng ( " yarrow " ) , find_hash ( " sha1 " ) ,
& key ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n \n katja_encrypt_key says %s, wait...no it should say %s...damn you! \n " , error_to_string ( err ) , error_to_string ( CRYPT_OK ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
t2 + = t1 ;
}
t2 > > = 4 ;
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " Katja-%lu encrypt_key took %15 " PRI64 " u cycles \n " , x , t2 ) ;
2005-11-18 00:15:37 -05:00
t2 = 0 ;
for ( y = 0 ; y < 2048 ; y + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
zzz = sizeof ( buf [ 0 ] ) ;
2014-05-01 12:01:13 -04:00
if ( ( err = katja_decrypt_key ( buf [ 1 ] , z , buf [ 0 ] , & zzz , " testprog " , 8 , find_hash ( " sha1 " ) ,
2005-11-18 00:15:37 -05:00
& zz , & key ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n \n katja_decrypt_key says %s, wait...no it should say %s...damn you! \n " , error_to_string ( err ) , error_to_string ( CRYPT_OK ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
t2 + = t1 ;
}
t2 > > = 11 ;
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " Katja-%lu decrypt_key took %15 " PRI64 " u cycles \n " , x , t2 ) ;
2005-11-18 00:15:37 -05:00
katja_free ( & key ) ;
}
}
# else
void time_katja ( void ) { fprintf ( stderr , " NO Katja \n " ) ; }
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_MECC
2004-08-06 12:42:41 -04:00
/* time various ECC operations */
void time_ecc ( void )
{
ecc_key key ;
ulong64 t1 , t2 ;
2006-11-17 09:21:24 -05:00
unsigned char buf [ 2 ] [ 256 ] ;
unsigned long i , w , x , y , z ;
int err , stat ;
2005-11-18 00:15:37 -05:00
static unsigned long sizes [ ] = {
2006-11-17 09:21:24 -05:00
# ifdef ECC112
2014-05-01 12:01:13 -04:00
112 / 8 ,
2006-11-17 09:21:24 -05:00
# endif
# ifdef ECC128
2014-05-01 12:01:13 -04:00
128 / 8 ,
2006-11-17 09:21:24 -05:00
# endif
# ifdef ECC160
2014-05-01 12:01:13 -04:00
160 / 8 ,
2006-11-17 09:21:24 -05:00
# endif
2005-11-18 00:15:37 -05:00
# ifdef ECC192
2014-05-01 12:01:13 -04:00
192 / 8 ,
2005-11-18 00:15:37 -05:00
# endif
# ifdef ECC224
224 / 8 ,
# endif
# ifdef ECC256
2014-05-01 12:01:13 -04:00
256 / 8 ,
2005-11-18 00:15:37 -05:00
# endif
# ifdef ECC384
2014-05-01 12:01:13 -04:00
384 / 8 ,
2005-11-18 00:15:37 -05:00
# endif
# ifdef ECC521
2014-05-01 12:01:13 -04:00
521 / 8 ,
2005-11-18 00:15:37 -05:00
# endif
100000 } ;
2004-08-06 12:42:41 -04:00
for ( x = sizes [ i = 0 ] ; x < 100000 ; x = sizes [ + + i ] ) {
t2 = 0 ;
2006-06-17 21:37:50 -04:00
for ( y = 0 ; y < 256 ; y + + ) {
2004-08-06 12:42:41 -04:00
t_start ( ) ;
t1 = t_read ( ) ;
2005-04-17 07:37:13 -04:00
if ( ( err = ecc_make_key ( & yarrow_prng , find_prng ( " yarrow " ) , x , & key ) ) ! = CRYPT_OK ) {
2004-08-06 12:42:41 -04:00
fprintf ( stderr , " \n \n ecc_make_key says %s, wait...no it should say %s...damn you! \n " , error_to_string ( err ) , error_to_string ( CRYPT_OK ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
t2 + = t1 ;
2006-11-17 09:21:24 -05:00
# ifdef LTC_PROFILE
t2 < < = 8 ;
break ;
# endif
2006-06-17 21:37:50 -04:00
if ( y < 255 ) {
2004-08-06 12:42:41 -04:00
ecc_free ( & key ) ;
}
}
2006-06-17 21:37:50 -04:00
t2 > > = 8 ;
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " ECC-%lu make_key took %15 " PRI64 " u cycles \n " , x * 8 , t2 ) ;
2004-08-06 12:42:41 -04:00
t2 = 0 ;
2006-06-17 21:37:50 -04:00
for ( y = 0 ; y < 256 ; y + + ) {
2004-08-06 12:42:41 -04:00
t_start ( ) ;
t1 = t_read ( ) ;
z = sizeof ( buf [ 1 ] ) ;
2005-04-17 07:37:13 -04:00
if ( ( err = ecc_encrypt_key ( buf [ 0 ] , 20 , buf [ 1 ] , & z , & yarrow_prng , find_prng ( " yarrow " ) , find_hash ( " sha1 " ) ,
2004-08-06 12:42:41 -04:00
& key ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n \n ecc_encrypt_key says %s, wait...no it should say %s...damn you! \n " , error_to_string ( err ) , error_to_string ( CRYPT_OK ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
t2 + = t1 ;
2006-11-17 09:21:24 -05:00
# ifdef LTC_PROFILE
t2 < < = 8 ;
break ;
# endif
2004-08-06 12:42:41 -04:00
}
2006-06-17 21:37:50 -04:00
t2 > > = 8 ;
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " ECC-%lu encrypt_key took %15 " PRI64 " u cycles \n " , x * 8 , t2 ) ;
2006-11-17 09:21:24 -05:00
t2 = 0 ;
for ( y = 0 ; y < 256 ; y + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
w = 20 ;
if ( ( err = ecc_decrypt_key ( buf [ 1 ] , z , buf [ 0 ] , & w , & key ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n \n ecc_decrypt_key says %s, wait...no it should say %s...damn you! \n " , error_to_string ( err ) , error_to_string ( CRYPT_OK ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
t2 + = t1 ;
# ifdef LTC_PROFILE
t2 < < = 8 ;
break ;
# endif
}
t2 > > = 8 ;
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " ECC-%lu decrypt_key took %15 " PRI64 " u cycles \n " , x * 8 , t2 ) ;
2006-11-17 09:21:24 -05:00
t2 = 0 ;
for ( y = 0 ; y < 256 ; y + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
z = sizeof ( buf [ 1 ] ) ;
2014-05-01 12:01:13 -04:00
if ( ( err = ecc_sign_hash ( buf [ 0 ] , 20 , buf [ 1 ] , & z , & yarrow_prng ,
2006-11-17 09:21:24 -05:00
find_prng ( " yarrow " ) , & key ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n \n ecc_sign_hash says %s, wait...no it should say %s...damn you! \n " , error_to_string ( err ) , error_to_string ( CRYPT_OK ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
t2 + = t1 ;
# ifdef LTC_PROFILE
t2 < < = 8 ;
break ;
# endif
}
t2 > > = 8 ;
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " ECC-%lu sign_hash took %15 " PRI64 " u cycles \n " , x * 8 , t2 ) ;
2006-11-17 09:21:24 -05:00
t2 = 0 ;
for ( y = 0 ; y < 256 ; y + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
if ( ( err = ecc_verify_hash ( buf [ 1 ] , z , buf [ 0 ] , 20 , & stat , & key ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n \n ecc_verify_hash says %s, wait...no it should say %s...damn you! \n " , error_to_string ( err ) , error_to_string ( CRYPT_OK ) ) ;
exit ( EXIT_FAILURE ) ;
}
if ( stat = = 0 ) {
fprintf ( stderr , " \n \n ecc_verify_hash for ECC-%lu failed to verify signature(%lu) \n " , x * 8 , y ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
t2 + = t1 ;
# ifdef LTC_PROFILE
t2 < < = 8 ;
break ;
# endif
}
t2 > > = 8 ;
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " ECC-%lu verify_hash took %15 " PRI64 " u cycles \n " , x * 8 , t2 ) ;
2006-11-17 09:21:24 -05:00
fprintf ( stderr , " \n \n " ) ;
2004-08-06 12:42:41 -04:00
ecc_free ( & key ) ;
}
}
2005-04-17 07:37:13 -04:00
# else
2005-06-08 20:08:13 -04:00
void time_ecc ( void ) { fprintf ( stderr , " NO ECC \n " ) ; }
2005-04-17 07:37:13 -04:00
# endif
2004-08-06 12:42:41 -04:00
2005-04-17 07:37:13 -04:00
void time_macs_ ( unsigned long MAC_SIZE )
2004-08-06 12:42:41 -04:00
{
unsigned char * buf , key [ 16 ] , tag [ 16 ] ;
ulong64 t1 , t2 ;
unsigned long x , z ;
int err , cipher_idx , hash_idx ;
2005-06-08 20:08:13 -04:00
fprintf ( stderr , " \n MAC Timings (cycles/byte on %luKB blocks): \n " , MAC_SIZE ) ;
2004-08-06 12:42:41 -04:00
buf = XMALLOC ( MAC_SIZE * 1024 ) ;
if ( buf = = NULL ) {
fprintf ( stderr , " \n \n out of heap yo \n \n " ) ;
exit ( EXIT_FAILURE ) ;
}
cipher_idx = find_cipher ( " aes " ) ;
2006-01-26 13:11:56 -05:00
hash_idx = find_hash ( " sha1 " ) ;
2014-05-01 12:01:13 -04:00
2006-01-26 13:11:56 -05:00
if ( cipher_idx = = - 1 | | hash_idx = = - 1 ) {
2014-07-12 10:44:28 -04:00
fprintf ( stderr , " Warning the MAC tests requires AES and SHA1 to operate... so sorry \n " ) ;
2006-01-26 13:11:56 -05:00
return ;
}
2004-08-06 12:42:41 -04:00
2005-04-17 07:37:13 -04:00
yarrow_read ( buf , MAC_SIZE * 1024 , & yarrow_prng ) ;
yarrow_read ( key , 16 , & yarrow_prng ) ;
2004-08-06 12:42:41 -04:00
2006-11-17 09:21:24 -05:00
# ifdef LTC_OMAC
2004-08-06 12:42:41 -04:00
t2 = - 1 ;
for ( x = 0 ; x < 10000 ; x + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
z = 16 ;
if ( ( err = omac_memory ( cipher_idx , key , 16 , buf , MAC_SIZE * 1024 , tag , & z ) ) ! = CRYPT_OK ) {
2014-07-12 10:44:28 -04:00
fprintf ( stderr , " \n \n omac-%s error... %s \n " , cipher_descriptor [ cipher_idx ] . name , error_to_string ( err ) ) ;
2004-08-06 12:42:41 -04:00
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
if ( t1 < t2 ) t2 = t1 ;
}
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " OMAC-%s \t \t %9 " PRI64 " u \n " , cipher_descriptor [ cipher_idx ] . name , t2 / ( ulong64 ) ( MAC_SIZE * 1024 ) ) ;
2005-04-17 07:37:13 -04:00
# endif
2004-08-06 12:42:41 -04:00
2006-11-17 09:21:24 -05:00
# ifdef LTC_XCBC
t2 = - 1 ;
for ( x = 0 ; x < 10000 ; x + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
z = 16 ;
if ( ( err = xcbc_memory ( cipher_idx , key , 16 , buf , MAC_SIZE * 1024 , tag , & z ) ) ! = CRYPT_OK ) {
2014-07-12 10:44:28 -04:00
fprintf ( stderr , " \n \n xcbc-%s error... %s \n " , cipher_descriptor [ cipher_idx ] . name , error_to_string ( err ) ) ;
2006-11-17 09:21:24 -05:00
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
if ( t1 < t2 ) t2 = t1 ;
}
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " XCBC-%s \t \t %9 " PRI64 " u \n " , cipher_descriptor [ cipher_idx ] . name , t2 / ( ulong64 ) ( MAC_SIZE * 1024 ) ) ;
2006-11-17 09:21:24 -05:00
# endif
# ifdef LTC_F9_MODE
t2 = - 1 ;
for ( x = 0 ; x < 10000 ; x + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
z = 16 ;
if ( ( err = f9_memory ( cipher_idx , key , 16 , buf , MAC_SIZE * 1024 , tag , & z ) ) ! = CRYPT_OK ) {
2014-07-12 10:44:28 -04:00
fprintf ( stderr , " \n \n F9-%s error... %s \n " , cipher_descriptor [ cipher_idx ] . name , error_to_string ( err ) ) ;
2006-11-17 09:21:24 -05:00
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
if ( t1 < t2 ) t2 = t1 ;
}
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " F9-%s \t \t \t %9 " PRI64 " u \n " , cipher_descriptor [ cipher_idx ] . name , t2 / ( ulong64 ) ( MAC_SIZE * 1024 ) ) ;
2006-11-17 09:21:24 -05:00
# endif
# ifdef LTC_PMAC
2004-08-06 12:42:41 -04:00
t2 = - 1 ;
for ( x = 0 ; x < 10000 ; x + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
z = 16 ;
if ( ( err = pmac_memory ( cipher_idx , key , 16 , buf , MAC_SIZE * 1024 , tag , & z ) ) ! = CRYPT_OK ) {
2014-07-12 10:44:28 -04:00
fprintf ( stderr , " \n \n pmac-%s error... %s \n " , cipher_descriptor [ cipher_idx ] . name , error_to_string ( err ) ) ;
2004-08-06 12:42:41 -04:00
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
if ( t1 < t2 ) t2 = t1 ;
}
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " PMAC-%s \t \t %9 " PRI64 " u \n " , cipher_descriptor [ cipher_idx ] . name , t2 / ( ulong64 ) ( MAC_SIZE * 1024 ) ) ;
2005-04-17 07:37:13 -04:00
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_PELICAN
2005-04-17 07:37:13 -04:00
t2 = - 1 ;
for ( x = 0 ; x < 10000 ; x + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
z = 16 ;
if ( ( err = pelican_memory ( key , 16 , buf , MAC_SIZE * 1024 , tag ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n \n pelican error... %s \n " , error_to_string ( err ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
if ( t1 < t2 ) t2 = t1 ;
}
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " PELICAN \t \t %9 " PRI64 " u \n " , t2 / ( ulong64 ) ( MAC_SIZE * 1024 ) ) ;
2005-04-17 07:37:13 -04:00
# endif
2004-08-06 12:42:41 -04:00
2006-11-17 09:21:24 -05:00
# ifdef LTC_HMAC
2004-08-06 12:42:41 -04:00
t2 = - 1 ;
for ( x = 0 ; x < 10000 ; x + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
z = 16 ;
if ( ( err = hmac_memory ( hash_idx , key , 16 , buf , MAC_SIZE * 1024 , tag , & z ) ) ! = CRYPT_OK ) {
2014-07-12 10:44:28 -04:00
fprintf ( stderr , " \n \n hmac-%s error... %s \n " , hash_descriptor [ hash_idx ] . name , error_to_string ( err ) ) ;
2004-08-06 12:42:41 -04:00
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
if ( t1 < t2 ) t2 = t1 ;
}
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " HMAC-%s \t \t %9 " PRI64 " u \n " , hash_descriptor [ hash_idx ] . name , t2 / ( ulong64 ) ( MAC_SIZE * 1024 ) ) ;
2005-04-17 07:37:13 -04:00
# endif
2004-08-06 12:42:41 -04:00
XFREE ( buf ) ;
}
2004-07-23 11:40:22 -04:00
2005-04-17 07:37:13 -04:00
void time_macs ( void )
2003-07-10 22:09:41 -04:00
{
2005-04-17 07:37:13 -04:00
time_macs_ ( 1 ) ;
time_macs_ ( 4 ) ;
time_macs_ ( 32 ) ;
2003-09-25 21:16:18 -04:00
}
2003-07-10 22:09:41 -04:00
2005-04-17 07:37:13 -04:00
void time_encmacs_ ( unsigned long MAC_SIZE )
{
unsigned char * buf , IV [ 16 ] , key [ 16 ] , tag [ 16 ] ;
ulong64 t1 , t2 ;
unsigned long x , z ;
int err , cipher_idx ;
2005-11-18 00:15:37 -05:00
symmetric_key skey ;
2005-04-17 07:37:13 -04:00
2005-06-08 20:08:13 -04:00
fprintf ( stderr , " \n ENC+MAC Timings (zero byte AAD, 16 byte IV, cycles/byte on %luKB blocks): \n " , MAC_SIZE ) ;
2005-04-17 07:37:13 -04:00
buf = XMALLOC ( MAC_SIZE * 1024 ) ;
if ( buf = = NULL ) {
fprintf ( stderr , " \n \n out of heap yo \n \n " ) ;
exit ( EXIT_FAILURE ) ;
}
cipher_idx = find_cipher ( " aes " ) ;
yarrow_read ( buf , MAC_SIZE * 1024 , & yarrow_prng ) ;
yarrow_read ( key , 16 , & yarrow_prng ) ;
yarrow_read ( IV , 16 , & yarrow_prng ) ;
2007-07-20 13:48:02 -04:00
# ifdef LTC_EAX_MODE
2005-04-17 07:37:13 -04:00
t2 = - 1 ;
for ( x = 0 ; x < 10000 ; x + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
z = 16 ;
if ( ( err = eax_encrypt_authenticate_memory ( cipher_idx , key , 16 , IV , 16 , NULL , 0 , buf , MAC_SIZE * 1024 , buf , tag , & z ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n EAX error... %s \n " , error_to_string ( err ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
if ( t1 < t2 ) t2 = t1 ;
}
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " EAX \t \t \t %9 " PRI64 " u \n " , t2 / ( ulong64 ) ( MAC_SIZE * 1024 ) ) ;
2005-04-17 07:37:13 -04:00
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_OCB_MODE
2005-04-17 07:37:13 -04:00
t2 = - 1 ;
for ( x = 0 ; x < 10000 ; x + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
z = 16 ;
if ( ( err = ocb_encrypt_authenticate_memory ( cipher_idx , key , 16 , IV , buf , MAC_SIZE * 1024 , buf , tag , & z ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n OCB error... %s \n " , error_to_string ( err ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
if ( t1 < t2 ) t2 = t1 ;
}
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " OCB \t \t \t %9 " PRI64 " u \n " , t2 / ( ulong64 ) ( MAC_SIZE * 1024 ) ) ;
2005-04-17 07:37:13 -04:00
# endif
2012-08-04 19:21:13 -04:00
# ifdef LTC_OCB3_MODE
t2 = - 1 ;
for ( x = 0 ; x < 10000 ; x + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
z = 16 ;
2014-05-01 12:01:13 -04:00
if ( ( err = ocb3_encrypt_authenticate_memory ( cipher_idx , key , 16 , IV , 16 , ( unsigned char * ) " " , 0 , buf , MAC_SIZE * 1024 , buf , tag , & z ) ) ! = CRYPT_OK ) {
2012-08-04 19:21:13 -04:00
fprintf ( stderr , " \n OCB3 error... %s \n " , error_to_string ( err ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
if ( t1 < t2 ) t2 = t1 ;
}
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " OCB3 \t \t \t %9 " PRI64 " u \n " , t2 / ( ulong64 ) ( MAC_SIZE * 1024 ) ) ;
2012-08-04 19:21:13 -04:00
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_CCM_MODE
2005-04-17 07:37:13 -04:00
t2 = - 1 ;
for ( x = 0 ; x < 10000 ; x + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
z = 16 ;
2005-11-18 00:15:37 -05:00
if ( ( err = ccm_memory ( cipher_idx , key , 16 , NULL , IV , 16 , NULL , 0 , buf , MAC_SIZE * 1024 , buf , tag , & z , CCM_ENCRYPT ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n CCM error... %s \n " , error_to_string ( err ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
if ( t1 < t2 ) t2 = t1 ;
}
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " CCM (no-precomp) \t %9 " PRI64 " u \n " , t2 / ( ulong64 ) ( MAC_SIZE * 1024 ) ) ;
2014-05-01 12:01:13 -04:00
2005-11-18 00:15:37 -05:00
cipher_descriptor [ cipher_idx ] . setup ( key , 16 , 0 , & skey ) ;
t2 = - 1 ;
for ( x = 0 ; x < 10000 ; x + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
z = 16 ;
if ( ( err = ccm_memory ( cipher_idx , key , 16 , & skey , IV , 16 , NULL , 0 , buf , MAC_SIZE * 1024 , buf , tag , & z , CCM_ENCRYPT ) ) ! = CRYPT_OK ) {
2005-04-17 07:37:13 -04:00
fprintf ( stderr , " \n CCM error... %s \n " , error_to_string ( err ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
if ( t1 < t2 ) t2 = t1 ;
}
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " CCM (precomp) \t \t %9 " PRI64 " u \n " , t2 / ( ulong64 ) ( MAC_SIZE * 1024 ) ) ;
2014-05-01 12:01:13 -04:00
cipher_descriptor [ cipher_idx ] . done ( & skey ) ;
2005-04-17 07:37:13 -04:00
# endif
2007-07-20 13:48:02 -04:00
# ifdef LTC_GCM_MODE
2005-04-17 07:37:13 -04:00
t2 = - 1 ;
for ( x = 0 ; x < 100 ; x + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
z = 16 ;
if ( ( err = gcm_memory ( cipher_idx , key , 16 , IV , 16 , NULL , 0 , buf , MAC_SIZE * 1024 , buf , tag , & z , GCM_ENCRYPT ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n GCM error... %s \n " , error_to_string ( err ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
if ( t1 < t2 ) t2 = t1 ;
}
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " GCM (no-precomp) \t %9 " PRI64 " u \n " , t2 / ( ulong64 ) ( MAC_SIZE * 1024 ) ) ;
2005-04-17 07:37:13 -04:00
{
2006-08-30 19:30:00 -04:00
gcm_state gcm
2007-07-20 13:48:02 -04:00
# ifdef LTC_GCM_TABLES_SSE2
2006-08-30 19:30:00 -04:00
__attribute__ ( ( aligned ( 16 ) ) )
# endif
;
2005-04-17 07:37:13 -04:00
2005-06-08 20:08:13 -04:00
if ( ( err = gcm_init ( & gcm , cipher_idx , key , 16 ) ) ! = CRYPT_OK ) { fprintf ( stderr , " gcm_init: %s \n " , error_to_string ( err ) ) ; exit ( EXIT_FAILURE ) ; }
2005-04-17 07:37:13 -04:00
t2 = - 1 ;
for ( x = 0 ; x < 10000 ; x + + ) {
t_start ( ) ;
t1 = t_read ( ) ;
z = 16 ;
if ( ( err = gcm_reset ( & gcm ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n GCM error[%d]... %s \n " , __LINE__ , error_to_string ( err ) ) ;
exit ( EXIT_FAILURE ) ;
}
if ( ( err = gcm_add_iv ( & gcm , IV , 16 ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n GCM error[%d]... %s \n " , __LINE__ , error_to_string ( err ) ) ;
exit ( EXIT_FAILURE ) ;
}
if ( ( err = gcm_add_aad ( & gcm , NULL , 0 ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n GCM error[%d]... %s \n " , __LINE__ , error_to_string ( err ) ) ;
exit ( EXIT_FAILURE ) ;
}
if ( ( err = gcm_process ( & gcm , buf , MAC_SIZE * 1024 , buf , GCM_ENCRYPT ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n GCM error[%d]... %s \n " , __LINE__ , error_to_string ( err ) ) ;
exit ( EXIT_FAILURE ) ;
}
2014-05-01 12:01:13 -04:00
2005-04-17 07:37:13 -04:00
if ( ( err = gcm_done ( & gcm , tag , & z ) ) ! = CRYPT_OK ) {
fprintf ( stderr , " \n GCM error[%d]... %s \n " , __LINE__ , error_to_string ( err ) ) ;
exit ( EXIT_FAILURE ) ;
}
t1 = t_read ( ) - t1 ;
if ( t1 < t2 ) t2 = t1 ;
}
2014-08-28 07:27:52 -04:00
fprintf ( stderr , " GCM (precomp) \t \t %9 " PRI64 " u \n " , t2 / ( ulong64 ) ( MAC_SIZE * 1024 ) ) ;
2005-04-17 07:37:13 -04:00
}
# endif
2014-05-01 12:01:13 -04:00
}
2005-04-17 07:37:13 -04:00
void time_encmacs ( void )
{
time_encmacs_ ( 1 ) ;
time_encmacs_ ( 4 ) ;
time_encmacs_ ( 32 ) ;
}
2005-06-08 20:08:13 -04:00
/* $Source$ */
/* $Revision$ */
/* $Date$ */