2 * encrypt/decrypt using CSP implementation of AES.
5 #include <Security/cssm.h>
10 static CSSM_CSP_HANDLE cspHand
= 0;
12 CSSM_RETURN
encryptDecryptCsp(
15 uint32 blockSizeInBits
,
16 const uint8
*key
, // raw key bytes
21 CSSM_KEY_PTR symKey
; // mallocd by cspGenSymKey or a ptr
28 /* attach first time thru */
29 cspHand
= cspDlDbStartup(CSSM_TRUE
, NULL
);
31 return CSSMERR_CSSM_MODULE_NOT_LOADED
;
35 /* cook up a raw symmetric key */
36 symKey
= cspGenSymKey(cspHand
,
40 CSSM_KEYUSE_ENCRYPT
| CSSM_KEYUSE_DECRYPT
,
42 CSSM_FALSE
); // ref key
44 return CSSM_ERRCODE_INTERNAL_ERROR
;
46 memmove(symKey
->KeyData
.Data
, key
, keySizeInBits
/ 8);
48 inData
.Data
= (uint8
*)inText
;
49 inData
.Length
= inTextLen
;
50 outData
.Data
= outText
;
51 outData
.Length
= inTextLen
;
54 crtn
= cspEncrypt(cspHand
,
59 NULL
, // no second key
60 0, // effectiveKeyBits
65 CSSM_FALSE
); // mallocCtext
68 crtn
= cspDecrypt(cspHand
,
73 NULL
, // no second key
74 0, // effectiveKeyBits
79 CSSM_FALSE
); // mallocPtext
81 cspFreeKey(cspHand
, symKey
);