]>
git.saurik.com Git - apple/security.git/blob - SecurityTests/cspxutils/macTest/macTest.c
11 #include <Security/cssm.h>
14 #define DATA_SIZE_DEF 100
17 #define KEY_ALG_DEF CSSM_ALGID_SHA1HMAC
18 #define MAC_ALG_DEF CSSM_ALGID_SHA1HMAC
20 static void usage(char **argv
)
22 printf("usage: %s [options]\n", argv
[0]);
24 printf(" d=dataSize (default = %d)\n", DATA_SIZE_DEF
);
25 printf(" l=loops (0=forever)\n");
26 printf(" p=pauseInterval (default=0, no pause)\n");
27 printf(" m (HMACMD5; default is HMACSHA1)\n");
28 printf(" D (CSP/DL; default = bare CSP)\n");
30 printf(" v(erbose))\n");
34 int main(int argc
, char **argv
)
38 CSSM_CSP_HANDLE cspHand
;
39 CSSM_CC_HANDLE macHand
;
43 CSSM_DATA macData
= {0, NULL
};
46 unsigned dataSize
= DATA_SIZE_DEF
;
47 unsigned pauseInterval
= 0;
48 unsigned loops
= LOOPS_DEF
;
49 CSSM_BOOL quiet
= CSSM_FALSE
;
50 CSSM_BOOL verbose
= CSSM_FALSE
;
51 CSSM_BOOL bareCsp
= CSSM_TRUE
;
52 CSSM_ALGORITHMS macAlg
= MAC_ALG_DEF
;
53 CSSM_ALGORITHMS keyAlg
= KEY_ALG_DEF
;
55 for(arg
=1; arg
<argc
; arg
++) {
57 switch(argv
[arg
][0]) {
59 dataSize
= atoi(&argv
[arg
][2]);
62 loops
= atoi(&argv
[arg
][2]);
65 pauseInterval
= atoi(&argv
[arg
][2]);
68 keyAlg
= macAlg
= CSSM_ALGID_MD5HMAC
;
83 cspHand
= cspDlDbStartup(bareCsp
, NULL
);
87 printf("Starting mactest; args: ");
88 for(i
=1; i
<argc
; i
++) {
89 printf("%s ", argv
[i
]);
92 symmKey
= cspGenSymKey(cspHand
,
96 CSSM_KEYUSE_SIGN
| CSSM_KEYUSE_VERIFY
,
100 printf("Error generating symmetric key; aborting.\n");
103 randData
.Data
= (uint8
*)CSSM_MALLOC(dataSize
);
104 randData
.Length
= dataSize
;
105 simpleGenData(&randData
, dataSize
, dataSize
);
106 for(loop
=1; ; loop
++) {
108 printf("...Loop %d\n", loop
);
110 crtn
= CSSM_CSP_CreateMacContext(cspHand
,
115 printError("CSSM_CSP_CreateMacContext (1)", crtn
);
118 crtn
= CSSM_GenerateMac(macHand
,
123 printError("CSSM_GenerateMac error", crtn
);
126 crtn
= CSSM_DeleteContext(macHand
);
128 printError("CSSM_DeleteContext", crtn
);
131 crtn
= CSSM_CSP_CreateMacContext(cspHand
,
136 printError("CSSM_CSP_CreateMacContext (2)", crtn
);
139 crtn
= CSSM_VerifyMac(macHand
,
144 printError("CSSM_VerifyMac", crtn
);
147 crtn
= CSSM_DeleteContext(macHand
);
149 printError("CSSM_DeleteContext", crtn
);
152 if(loops
&& (loop
== loops
)) {
155 if(pauseInterval
&& ((loop
% pauseInterval
) == 0)) {
158 printf("Hit CR to proceed or q to quit: ");
165 CSSM_FREE(randData
.Data
);
166 crtn
= CSSM_ModuleDetach(cspHand
);
168 printError("CSSM_CSP_Detach", crtn
);