]> git.saurik.com Git - apple/security.git/blob - SecurityTests/clxutils/threadTest/cspRand.cpp
Security-57336.1.9.tar.gz
[apple/security.git] / SecurityTests / clxutils / threadTest / cspRand.cpp
1 /* cspRand.cpp */
2
3 #include "testParams.h"
4 #include <utilLib/common.h>
5 #include <stdlib.h>
6 #include <stdio.h>
7 #include <security_utilities/threading.h>
8
9 #define INNER_LOOPS 100
10 #define MAX_SIZE 256
11
12 int cspRandInit(TestParams *testParams)
13 {
14 return 0;
15 }
16
17 int cspRand(TestParams *testParams)
18 {
19 unsigned loopNum;
20 unsigned iLoop;
21 unsigned char randData[MAX_SIZE];
22
23 for(loopNum=0; loopNum<testParams->numLoops; loopNum++) {
24
25 if(!testParams->quiet) {
26 printChar(testParams->progressChar);
27 }
28
29 /* pick a rand size for this outer loop using the global devRand */
30 unsigned char randSize;
31 CSSM_DATA cdata;
32 cdata.Data = &randSize;
33 cdata.Length = 1;
34 threadGetRandData(testParams, &cdata, 1);
35 if(randSize == 0) {
36 randSize = 1;
37 }
38 for(iLoop=0; iLoop<INNER_LOOPS; iLoop++) {
39 CSSM_CC_HANDLE rngHand;
40 CSSM_RETURN crtn;
41
42 crtn = CSSM_CSP_CreateRandomGenContext(testParams->cspHand,
43 CSSM_ALGID_APPLE_YARROW,
44 NULL, /* seed */
45 randSize,
46 &rngHand);
47 if(crtn) {
48 printError("CSSM_CSP_CreateRandomGenContext", crtn);
49 return 1;
50 }
51 cdata.Data = randData;
52 cdata.Length = randSize;
53 crtn = CSSM_GenerateRandom(rngHand, &cdata);
54 if(crtn) {
55 printError("CSSM_GenerateRandom", crtn);
56 return 1;
57 }
58 CSSM_DeleteContext(rngHand);
59 }
60 }
61 return 0;
62 }
63