X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/80e2389990082500d76eb566d4946be3e786c3ef..d8f41ccd20de16f8ebe2ccc84d47bf1cb2b26bbb:/SecurityTests/cspxutils/aesVect/enDecryptRef.c diff --git a/SecurityTests/cspxutils/aesVect/enDecryptRef.c b/SecurityTests/cspxutils/aesVect/enDecryptRef.c new file mode 100644 index 00000000..5f91b127 --- /dev/null +++ b/SecurityTests/cspxutils/aesVect/enDecryptRef.c @@ -0,0 +1,56 @@ +#include "enDecrypt.h" +#include "rijndaelApi.h" /* reference */ + +/* + * encrypt/decrypt using reference AES. + */ +CSSM_RETURN encryptDecryptRef( + CSSM_BOOL forEncrypt, + uint32 keySizeInBits, + uint32 blockSizeInBits, + const uint8 *key, // raw key bytes + const uint8 *inText, + uint32 inTextLen, + uint8 *outText) +{ + keyInstance aesKey; + cipherInstance aesCipher; + int artn; + + artn = _makeKey(&aesKey, + forEncrypt ? DIR_ENCRYPT : DIR_DECRYPT, + keySizeInBits, + blockSizeInBits, + (BYTE *)key); + if(artn <= 0) { + printf("***AES makeKey returned %d\n", artn); + return CSSM_ERRCODE_INTERNAL_ERROR; + } + artn = _cipherInit(&aesCipher, + MODE_ECB, + blockSizeInBits, + NULL); + if(artn <= 0) { + printf("***AES cipherInit returned %d\n", artn); + return CSSM_ERRCODE_INTERNAL_ERROR; + } + if(forEncrypt) { + artn = _blockEncrypt(&aesCipher, + &aesKey, + (BYTE *)inText, + inTextLen * 8, + (BYTE *)outText); + } + else { + artn = _blockDecrypt(&aesCipher, + &aesKey, + (BYTE *)inText, + inTextLen * 8, + (BYTE *)outText); + } + if(artn <= 0) { + printf("***AES Reference encrypt/decrypt returned %d\n", artn); + return CSSM_ERRCODE_INTERNAL_ERROR; + } + return CSSM_OK; +}