|
41 | 41 | #include "mbedtls/arc4.h"
|
42 | 42 | #include "mbedtls/des.h"
|
43 | 43 | #include "mbedtls/aes.h"
|
| 44 | +#include "mbedtls/cmac.h" |
44 | 45 | #include "mbedtls/blowfish.h"
|
45 | 46 | #include "mbedtls/camellia.h"
|
46 | 47 | #include "mbedtls/gcm.h"
|
|
164 | 165 |
|
165 | 166 | #define OPTIONS \
|
166 | 167 | "md4, md5, ripemd160, sha1, sha256, sha512,\r\n" \
|
167 |
| - "arc4, des3, des, aes_cbc, aes_gcm, aes_ccm, camellia, blowfish,\r\n" \ |
| 168 | + "arc4, camellia, blowfish,\r\n" \ |
| 169 | + "des3, des, aes_cmac, des3_cmac, aes_cbc, aes_gcm, aes_ccm,\r\n" \ |
168 | 170 | "havege, ctr_drbg, hmac_drbg\r\n" \
|
169 | 171 | "rsa, dhm, ecdsa, ecdh.\r\n"
|
170 | 172 |
|
@@ -311,7 +313,8 @@ unsigned char buf[BUFSIZE];
|
311 | 313 |
|
312 | 314 | typedef struct {
|
313 | 315 | char md4, md5, ripemd160, sha1, sha256, sha512,
|
314 |
| - arc4, des3, des, aes_cbc, aes_gcm, aes_ccm, camellia, blowfish, |
| 316 | + arc4, des3, des, aes_cbc, aes_gcm, aes_ccm, |
| 317 | + aes_cmac, des3_cmac, camellia, blowfish, |
315 | 318 | havege, ctr_drbg, hmac_drbg,
|
316 | 319 | rsa, dhm, ecdsa, ecdh;
|
317 | 320 | } todo_list;
|
@@ -360,6 +363,10 @@ static int benchmark( int argc, char *argv[] )
|
360 | 363 | todo.aes_gcm = 1;
|
361 | 364 | else if( strcmp( argv[i], "aes_ccm" ) == 0 )
|
362 | 365 | todo.aes_ccm = 1;
|
| 366 | + else if( strcmp( argv[i], "aes_cmac" ) == 0 ) |
| 367 | + todo.aes_cmac = 1; |
| 368 | + else if( strcmp( argv[i], "des3_cmac" ) == 0 ) |
| 369 | + todo.des3_cmac = 1; |
363 | 370 | else if( strcmp( argv[i], "camellia" ) == 0 )
|
364 | 371 | todo.camellia = 1;
|
365 | 372 | else if( strcmp( argv[i], "blowfish" ) == 0 )
|
@@ -455,6 +462,22 @@ static int benchmark( int argc, char *argv[] )
|
455 | 462 | mbedtls_des_crypt_cbc( &des, MBEDTLS_DES_ENCRYPT, BUFSIZE, tmp, buf, buf ) );
|
456 | 463 | mbedtls_des_free( &des );
|
457 | 464 | }
|
| 465 | +#if defined(MBEDTLS_CMAC_C) |
| 466 | + if( todo.des3_cmac ) |
| 467 | + { |
| 468 | + unsigned char output[8]; |
| 469 | + const mbedtls_cipher_info_t *cipher_info; |
| 470 | + |
| 471 | + memset( buf, 0, sizeof( buf ) ); |
| 472 | + memset( tmp, 0, sizeof( tmp ) ); |
| 473 | + |
| 474 | + cipher_info = mbedtls_cipher_info_from_type( MBEDTLS_CIPHER_DES_EDE3_ECB ); |
| 475 | + |
| 476 | + TIME_AND_TSC( "3DES-CMAC", |
| 477 | + mbedtls_cipher_cmac( cipher_info, tmp, 192, buf, |
| 478 | + BUFSIZE, output ) ); |
| 479 | + } |
| 480 | +#endif /* MBEDTLS_CMAC_C */ |
458 | 481 | #endif
|
459 | 482 |
|
460 | 483 | #if defined(MBEDTLS_AES_C)
|
@@ -524,6 +547,37 @@ static int benchmark( int argc, char *argv[] )
|
524 | 547 | }
|
525 | 548 | }
|
526 | 549 | #endif
|
| 550 | +#if defined(MBEDTLS_CMAC_C) |
| 551 | + if( todo.aes_cmac ) |
| 552 | + { |
| 553 | + unsigned char output[16]; |
| 554 | + const mbedtls_cipher_info_t *cipher_info; |
| 555 | + mbedtls_cipher_type_t cipher_type; |
| 556 | + int keysize; |
| 557 | + |
| 558 | + cipher_type = MBEDTLS_CIPHER_AES_128_ECB; |
| 559 | + for( keysize = 128; keysize <= 256; keysize += 64 ) |
| 560 | + { |
| 561 | + mbedtls_snprintf( title, sizeof( title ), "AES-CMAC-%d", keysize ); |
| 562 | + |
| 563 | + memset( buf, 0, sizeof( buf ) ); |
| 564 | + memset( tmp, 0, sizeof( tmp ) ); |
| 565 | + |
| 566 | + cipher_info = mbedtls_cipher_info_from_type( cipher_type ); |
| 567 | + |
| 568 | + TIME_AND_TSC( title, |
| 569 | + mbedtls_cipher_cmac( cipher_info, tmp, keysize, |
| 570 | + buf, BUFSIZE, output ) ); |
| 571 | + cipher_type = (mbedtls_cipher_type_t)( cipher_type + 1 ); |
| 572 | + } |
| 573 | + |
| 574 | + memset( buf, 0, sizeof( buf ) ); |
| 575 | + memset( tmp, 0, sizeof( tmp ) ); |
| 576 | + TIME_AND_TSC( "AES-CMAC-PRF-128", |
| 577 | + mbedtls_aes_cmac_prf_128( tmp, 16, buf, BUFSIZE, |
| 578 | + output ) ); |
| 579 | + } |
| 580 | +#endif /* MBEDTLS_CMAC_C */ |
527 | 581 | #endif
|
528 | 582 |
|
529 | 583 | #if defined(MBEDTLS_CAMELLIA_C) && defined(MBEDTLS_CIPHER_MODE_CBC)
|
|
0 commit comments