----------------------------------------------------------------------------- Purpose: Tests elliptic crypto perf -----------------------------------------------------------------------------
| 606 | // Purpose: Tests elliptic crypto perf |
| 607 | //----------------------------------------------------------------------------- |
| 608 | void TestEllipticPerf() |
| 609 | { |
| 610 | const int k_cubPktBig = 1024*1024*10; |
| 611 | const int k_cubPktSmall = 128; |
| 612 | |
| 613 | const int k_cIterationsECDH = 500; |
| 614 | const int k_cIterationsSignSmall = 500; |
| 615 | const int k_cIterationsSignBig = 25; |
| 616 | |
| 617 | uint64 usecStart; |
| 618 | CUtlBuffer bufData; |
| 619 | bufData.EnsureCapacity( k_cubPktBig ); |
| 620 | bufData.SeekPut( CUtlBuffer::SEEK_HEAD, k_cubPktBig ); |
| 621 | CCrypto::GenerateRandomBlock(bufData.Base(), k_cubPktBig); |
| 622 | |
| 623 | CECKeyExchangePublicKey lastPub; |
| 624 | CECKeyExchangePrivateKey lastPriv; |
| 625 | CCrypto::GenerateKeyExchangeKeyPair( &lastPub, &lastPriv ); |
| 626 | |
| 627 | usecStart = Plat_USTime(); |
| 628 | int x = 0; |
| 629 | for ( int i = 0; i < k_cIterationsECDH; ++i ) |
| 630 | { |
| 631 | SHA256Digest_t sharedsecret; |
| 632 | CECKeyExchangePublicKey pub; |
| 633 | CECKeyExchangePrivateKey priv; |
| 634 | CCrypto::GenerateKeyExchangeKeyPair( &pub, &priv ); |
| 635 | CHECK( CCrypto::PerformKeyExchange( priv, lastPub, &sharedsecret ) ); |
| 636 | x ^= sharedsecret[0] ^ sharedsecret[sizeof(sharedsecret)-1]; |
| 637 | } |
| 638 | double dMicrosecPerECDH = double( Plat_USTime() - usecStart ) / k_cIterationsECDH; |
| 639 | |
| 640 | |
| 641 | CECSigningPublicKey signPub; |
| 642 | CECSigningPrivateKey signPriv; |
| 643 | CCrypto::GenerateSigningKeyPair( &signPub, &signPriv ); |
| 644 | |
| 645 | CryptoSignature_t signature; |
| 646 | // small data sign |
| 647 | usecStart = Plat_USTime(); |
| 648 | for ( int i = 0; i < k_cIterationsSignSmall; ++i ) |
| 649 | { |
| 650 | CCrypto::GenerateSignature( (uint8*)bufData.Base(), k_cubPktSmall, signPriv, &signature ); |
| 651 | x ^= signature[0] ^ signature[sizeof( signature ) - 1]; |
| 652 | } |
| 653 | double dMicrosecPerSignSmall = double( Plat_USTime() - usecStart ) / k_cIterationsSignSmall; |
| 654 | |
| 655 | // small data verify |
| 656 | usecStart = Plat_USTime(); |
| 657 | for ( int i = 0; i < k_cIterationsSignSmall; ++i ) |
| 658 | { |
| 659 | x ^= (int)CCrypto::VerifySignature( (uint8*)bufData.Base(), k_cubPktSmall, signPub, signature ); |
| 660 | } |
| 661 | double dMicrosecPerSignCheckSmall = double( Plat_USTime() - usecStart ) / k_cIterationsSignSmall; |
| 662 | |
| 663 | // large data sign |
| 664 | usecStart = Plat_USTime(); |
| 665 | for ( int i = 0; i < k_cIterationsSignBig; ++i ) |
no test coverage detected