]> git.saurik.com Git - apple/security.git/blob - SecurityTests/cspxutils/aesVect/enDecryptRef.c
Security-57031.1.35.tar.gz
[apple/security.git] / SecurityTests / cspxutils / aesVect / enDecryptRef.c
1 #include "enDecrypt.h"
2 #include "rijndaelApi.h" /* reference */
3
4 /*
5 * encrypt/decrypt using reference AES.
6 */
7 CSSM_RETURN encryptDecryptRef(
8 CSSM_BOOL forEncrypt,
9 uint32 keySizeInBits,
10 uint32 blockSizeInBits,
11 const uint8 *key, // raw key bytes
12 const uint8 *inText,
13 uint32 inTextLen,
14 uint8 *outText)
15 {
16 keyInstance aesKey;
17 cipherInstance aesCipher;
18 int artn;
19
20 artn = _makeKey(&aesKey,
21 forEncrypt ? DIR_ENCRYPT : DIR_DECRYPT,
22 keySizeInBits,
23 blockSizeInBits,
24 (BYTE *)key);
25 if(artn <= 0) {
26 printf("***AES makeKey returned %d\n", artn);
27 return CSSM_ERRCODE_INTERNAL_ERROR;
28 }
29 artn = _cipherInit(&aesCipher,
30 MODE_ECB,
31 blockSizeInBits,
32 NULL);
33 if(artn <= 0) {
34 printf("***AES cipherInit returned %d\n", artn);
35 return CSSM_ERRCODE_INTERNAL_ERROR;
36 }
37 if(forEncrypt) {
38 artn = _blockEncrypt(&aesCipher,
39 &aesKey,
40 (BYTE *)inText,
41 inTextLen * 8,
42 (BYTE *)outText);
43 }
44 else {
45 artn = _blockDecrypt(&aesCipher,
46 &aesKey,
47 (BYTE *)inText,
48 inTextLen * 8,
49 (BYTE *)outText);
50 }
51 if(artn <= 0) {
52 printf("***AES Reference encrypt/decrypt returned %d\n", artn);
53 return CSSM_ERRCODE_INTERNAL_ERROR;
54 }
55 return CSSM_OK;
56 }