----------------------------------------------------------------------------- Purpose: Tests symmetric crypto perf -----------------------------------------------------------------------------
| 740 | // Purpose: Tests symmetric crypto perf |
| 741 | //----------------------------------------------------------------------------- |
| 742 | void TestSymmetricAuthCryptoPerf() |
| 743 | { |
| 744 | const int k_cIterations = 10000; |
| 745 | |
| 746 | const int k_cMaxData = 800; |
| 747 | const int k_cBufs = 5; |
| 748 | const int k_cubTestBuf = k_cMaxData * k_cBufs + k_cIterations; |
| 749 | |
| 750 | const int k_cubPktBig = 1200; |
| 751 | const int k_cubPktSmall = 100; |
| 752 | |
| 753 | AES_GCM_EncryptContext ctxEnc; |
| 754 | AES_GCM_DecryptContext ctxDec; |
| 755 | |
| 756 | uint64 usecStart; |
| 757 | |
| 758 | // generate a random key |
| 759 | uint8 rgubKey[k_nSymmetricKeyLen]; |
| 760 | uint8 rgubIV[k_nSymmetricIVSize]; |
| 761 | |
| 762 | CCrypto::GenerateRandomBlock( rgubKey, V_ARRAYSIZE( rgubKey ) ); |
| 763 | CCrypto::GenerateRandomBlock( rgubIV, V_ARRAYSIZE( rgubIV ) ); |
| 764 | |
| 765 | uint8 rgubData[k_cubTestBuf]; |
| 766 | |
| 767 | // Initialize encrypt/decrypt contexts |
| 768 | ctxEnc.Init( |
| 769 | rgubKey, k_nSymmetricKeyLen, |
| 770 | V_ARRAYSIZE(rgubIV), |
| 771 | k_nSymmetricGCMTagSize ); |
| 772 | ctxDec.Init( |
| 773 | rgubKey, k_nSymmetricKeyLen, |
| 774 | V_ARRAYSIZE(rgubIV), |
| 775 | k_nSymmetricGCMTagSize ); |
| 776 | |
| 777 | // fill data buffer with arbitrary data |
| 778 | uint8 rgubEncrypted[ k_cubPktBig + 32 ]; // 16 = AES block size.. worst case for padded data |
| 779 | for ( int iubData = 0; iubData < V_ARRAYSIZE( rgubData ); iubData ++ ) |
| 780 | rgubData[iubData] = (uint8) iubData; |
| 781 | |
| 782 | // try a bunch of iterations of symmetric encrypting small packets |
| 783 | usecStart = Plat_USTime(); |
| 784 | SymmetricAuthEncryptRepeatedly( k_cIterations, ctxEnc, rgubData, k_cubPktSmall, rgubIV ); |
| 785 | int cMicroSecPerEncryptSmall = Plat_USTime() - usecStart; |
| 786 | |
| 787 | // try a bunch of iterations of symmetric encrypting big packets |
| 788 | usecStart = Plat_USTime(); |
| 789 | SymmetricAuthEncryptRepeatedly( k_cIterations, ctxEnc, rgubData, k_cubPktBig, rgubIV ); |
| 790 | int cMicroSecPerEncryptBig = Plat_USTime() - usecStart; |
| 791 | double dRateLargeEncrypt = double( k_cubPktBig ) * k_cIterations / cMicroSecPerEncryptBig; |
| 792 | |
| 793 | // try a bunch of iterations decrypting small packets |
| 794 | uint cubEncrypted = V_ARRAYSIZE( rgubEncrypted ); |
| 795 | bool bRet = ctxEnc.Encrypt( |
| 796 | rgubData, k_cubPktSmall, |
| 797 | rgubIV, |
| 798 | rgubEncrypted, &cubEncrypted, |
| 799 | nullptr, 0 ); |
no test coverage detected