From c00cac79be120c1c12d135024d44cd6a59e77a1f Mon Sep 17 00:00:00 2001 From: Jaeden Amero Date: Wed, 2 May 2018 17:38:00 +0100 Subject: [PATCH] benchmark: Add AES-XTS benchmark --- programs/test/benchmark.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/programs/test/benchmark.c b/programs/test/benchmark.c index cecf3e363..0366f9c2e 100644 --- a/programs/test/benchmark.c +++ b/programs/test/benchmark.c @@ -94,7 +94,7 @@ int main( void ) #define OPTIONS \ "md4, md5, ripemd160, sha1, sha256, sha512,\n" \ "arc4, des3, des, camellia, blowfish,\n" \ - "aes_cbc, aes_gcm, aes_ccm, aes_cmac, des3_cmac,\n" \ + "aes_cbc, aes_gcm, aes_ccm, aes_cmac, aes_xts, des3_cmac,\n" \ "havege, ctr_drbg, hmac_drbg\n" \ "rsa, dhm, ecdsa, ecdh.\n" @@ -228,7 +228,7 @@ unsigned char buf[BUFSIZE]; typedef struct { char md4, md5, ripemd160, sha1, sha256, sha512, arc4, des3, des, - aes_cbc, aes_gcm, aes_ccm, aes_cmac, des3_cmac, + aes_cbc, aes_gcm, aes_ccm, aes_cmac, aes_xts, des3_cmac, camellia, blowfish, havege, ctr_drbg, hmac_drbg, rsa, dhm, ecdsa, ecdh; @@ -280,6 +280,8 @@ int main( int argc, char *argv[] ) todo.aes_ccm = 1; else if( strcmp( argv[i], "aes_cmac" ) == 0 ) todo.aes_cmac = 1; + else if( strcmp( argv[i], "aes_xts" ) == 0 ) + todo.aes_xts = 1; else if( strcmp( argv[i], "des3_cmac" ) == 0 ) todo.des3_cmac = 1; else if( strcmp( argv[i], "camellia" ) == 0 ) @@ -496,6 +498,29 @@ int main( int argc, char *argv[] ) output ) ); } #endif /* MBEDTLS_CMAC_C */ +#if defined(MBEDTLS_CIPHER_MODE_XTS) + if( todo.aes_xts ) + { + int keysize; + mbedtls_aes_xts_context ctx; + + mbedtls_aes_xts_init( &ctx ); + for( keysize = 128; keysize <= 256; keysize += 64 ) + { + mbedtls_snprintf( title, sizeof( title ), "AES-XTS-%d", keysize ); + + memset( buf, 0, sizeof( buf ) ); + memset( tmp, 0, sizeof( tmp ) ); + mbedtls_aes_xts_setkey_enc( &ctx, tmp, keysize * 2); + + TIME_AND_TSC( title, + mbedtls_aes_crypt_xts( &ctx, MBEDTLS_AES_ENCRYPT, BUFSIZE, + tmp, buf, buf ) ); + + mbedtls_aes_xts_free( &ctx ); + } + } +#endif /* MBEDTLS_CIPHER_MODE_XTS */ #endif /* MBEDTLS_AES_C */ #if defined(MBEDTLS_CAMELLIA_C) && defined(MBEDTLS_CIPHER_MODE_CBC)