X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/b04fe171f0375ecd5d8a24747ca1dff85720a0ca..6b200bc335dc93c5516ccb52f14bd896d8c7fad7:/SecurityTests/cspxutils/perform/perform.cpp diff --git a/SecurityTests/cspxutils/perform/perform.cpp b/SecurityTests/cspxutils/perform/perform.cpp deleted file mode 100644 index a49b66ef..00000000 --- a/SecurityTests/cspxutils/perform/perform.cpp +++ /dev/null @@ -1,339 +0,0 @@ -/* - * CSP symmetric encryption performance measurement tool - * Based on Michael Brouwer's cryptoPerformance.cpp - * - */ -#include -#include -#include -#include -#include -#include -#include "common.h" -#include -#include -#include -using namespace std; - -/* - * Default values - */ -#define ALG_DEFAULT CSSM_ALGID_AES -#define ALG_STR_DEFAULT "AES" -#define CHAIN_DEFAULT CSSM_TRUE -#define KEY_SIZE_DEFAULT 128 - -#define BEGIN_FUNCTION try { - -#define END_FUNCTION } \ - catch (const CssmError &e) \ - { \ - cssmPerror(__PRETTY_FUNCTION__, e.error); \ - } \ - catch (...) \ - { \ - fprintf(stderr, "%s: failed\n", __PRETTY_FUNCTION__); \ - } \ - -static void usage(char **argv) -{ - printf("usage: %s iterations bufsize [options]\n", argv[0]); - printf(" Options:\n"); - printf(" a=algorithm (s=ASC; d=DES; 3=3DES; 2=RC2; 4=RC4; 5=RC5;\n"); - printf(" a=AES; b=Blowfish; c=CAST; n=NULL; default=AES)\n"); - printf(" k=keySizeInBits\n"); - printf(" b=blockSizeInBits\n"); - printf(" e (ECB mode; default is CBC)\n"); - printf(" i (re-set IV in each loop)\n"); - printf(" v(erbose)\n"); - printf(" h(elp)\n"); - exit(1); -} - -static void -cdsaSetupContexts(int iterations, - auto_ptr &encrypt, - auto_ptr &decrypt, - CSSM_ALGORITHMS keyAlg, - CSSM_ALGORITHMS encrAlg, - CSSM_ENCRYPT_MODE encrMode, - uint32 keySizeInBits, - uint32 blockSizeInBits) // optional -{ - BEGIN_FUNCTION - Security::CssmClient::CSP csp(gGuidAppleCSP); - //CssmData keyData((uint8 *)"1234567812345678", 16); - Security::CssmClient::GenerateKey keyGenerator(csp, keyAlg, keySizeInBits); - Security::CssmClient::Key key = keyGenerator(Security::CssmClient::KeySpec( - CSSM_KEYUSE_ENCRYPT | CSSM_KEYUSE_DECRYPT, - CSSM_KEYATTR_RETURN_DATA | CSSM_KEYATTR_EXTRACTABLE)); - for (int ix=0; ix < iterations; ++ix) - { - encrypt.reset(new Security::CssmClient::Encrypt(csp, encrAlg)); - encrypt->mode(encrMode); - encrypt->key(key); - if(blockSizeInBits) { - encrypt->add(CSSM_ATTRIBUTE_BLOCK_SIZE, blockSizeInBits / 8); - } - //encrypt->activate(); - - decrypt.reset(new Security::CssmClient::Decrypt(csp, encrAlg)); - decrypt->mode(encrMode); - decrypt->key(key); - if(blockSizeInBits) { - decrypt->add(CSSM_ATTRIBUTE_BLOCK_SIZE, blockSizeInBits / 8); - } - //decrypt->activate(); - } - END_FUNCTION -} - -static void -cdsaEncrypt(int iterations, Security::CssmClient::Encrypt &encrypt, - uint8 *inBuf, uint32 bufLen, uint8 *outBuf, bool useIv, uint32 blockSizeBytes, - CSSM_BOOL resetIv) -{ - BEGIN_FUNCTION - CssmData iv((uint8 *)"12345678123456781234567812345678", blockSizeBytes); - CssmData inData(inBuf, bufLen); - CssmData outData(outBuf, bufLen); - CssmData nullData(reinterpret_cast(NULL) + 1, 0); - if(useIv) { - encrypt.initVector(iv); - } - if(useIv && resetIv) { - for (int ix=0; ix < iterations; ++ix) - { - encrypt.initVector(iv); - encrypt.encrypt(inData, outData, nullData); - } - } - else { - for (int ix=0; ix < iterations; ++ix) - { - encrypt.encrypt(inData, outData, nullData); - } - } - END_FUNCTION -} - -static void -cdsaDecrypt(int iterations, Security::CssmClient::Decrypt &decrypt, - uint8 *inBuf, uint32 bufLen, uint8 *outBuf, bool useIv, uint32 blockSizeBytes, - CSSM_BOOL resetIv) -{ - BEGIN_FUNCTION - CssmData iv((uint8 *)"12345678123456781234567812345678", blockSizeBytes); - CssmData inData(inBuf, bufLen); - CssmData outData(outBuf, bufLen); - CssmData nullData(reinterpret_cast(NULL) + 1, 0); - if(useIv) { - decrypt.initVector(iv); - } - if(useIv && resetIv) { - for (int ix=0; ix < iterations; ++ix) - { - decrypt.initVector(iv); - decrypt.decrypt(inData, outData, nullData); - } - } - else { - for (int ix=0; ix < iterations; ++ix) - { - decrypt.decrypt(inData, outData, nullData); - } - } - END_FUNCTION -} - -int main(int argc, char **argv) -{ - int arg; - char *argp; - CSSM_ENCRYPT_MODE mode; - uint32 blockSizeBytes = 8; - - /* - * User-spec'd params - */ - CSSM_BOOL chainEnable = CHAIN_DEFAULT; - uint32 keySizeInBits = KEY_SIZE_DEFAULT; - uint32 blockSizeInBits = 0; - const char *algStr = ALG_STR_DEFAULT; - uint32 keyAlg = ALG_DEFAULT; // CSSM_ALGID_xxx of the key - uint32 encrAlg = ALG_DEFAULT; // CSSM_ALGID_xxx for encrypt - int iterations; - int bufSize; - CSSM_BOOL resetIv = CSSM_FALSE; - CSSM_BOOL verbose = false; - - if(argc < 3) { - usage(argv); - } - iterations = atoi(argv[1]); - bufSize = atoi(argv[2]); - for(arg=3; arg buffer(bufSize), plain(bufSize); - auto_ptr encrypt(NULL); - auto_ptr decrypt(NULL); - - uint8 *bp = buffer.get(); - for(int ix=0; ix