X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/80e2389990082500d76eb566d4946be3e786c3ef..d8f41ccd20de16f8ebe2ccc84d47bf1cb2b26bbb:/SecurityTests/clxutils/threadTest/cspRand.cpp diff --git a/SecurityTests/clxutils/threadTest/cspRand.cpp b/SecurityTests/clxutils/threadTest/cspRand.cpp new file mode 100644 index 00000000..ce896ec7 --- /dev/null +++ b/SecurityTests/clxutils/threadTest/cspRand.cpp @@ -0,0 +1,63 @@ +/* cspRand.cpp */ + +#include "testParams.h" +#include +#include +#include +#include + +#define INNER_LOOPS 100 +#define MAX_SIZE 256 + +int cspRandInit(TestParams *testParams) +{ + return 0; +} + +int cspRand(TestParams *testParams) +{ + unsigned loopNum; + unsigned iLoop; + unsigned char randData[MAX_SIZE]; + + for(loopNum=0; loopNumnumLoops; loopNum++) { + + if(!testParams->quiet) { + printChar(testParams->progressChar); + } + + /* pick a rand size for this outer loop using the global devRand */ + unsigned char randSize; + CSSM_DATA cdata; + cdata.Data = &randSize; + cdata.Length = 1; + threadGetRandData(testParams, &cdata, 1); + if(randSize == 0) { + randSize = 1; + } + for(iLoop=0; iLoopcspHand, + CSSM_ALGID_APPLE_YARROW, + NULL, /* seed */ + randSize, + &rngHand); + if(crtn) { + printError("CSSM_CSP_CreateRandomGenContext", crtn); + return 1; + } + cdata.Data = randData; + cdata.Length = randSize; + crtn = CSSM_GenerateRandom(rngHand, &cdata); + if(crtn) { + printError("CSSM_GenerateRandom", crtn); + return 1; + } + CSSM_DeleteContext(rngHand); + } + } + return 0; +} +