1#include "enDecrypt.h" 2#include "std_defs.h" 3#include <strings.h> 4#include <stdio.h> 5 6/* 7 * encrypt/decrypt using Gladman version of AES. 8 */ 9 10CSSM_RETURN encryptDecryptTest( 11 CSSM_BOOL forEncrypt, 12 uint32 keySizeInBits, 13 uint32 blockSizeInBits, 14 const uint8 *key, // raw key bytes 15 const uint8 *inText, 16 uint32 inTextLen, 17 uint8 *outText) 18{ 19 u4byte aesKey[8]; 20 uint8 *inPtr = (uint8 *)inText; 21 uint8 *outPtr = outText; 22 uint32 blockSizeInBytes = blockSizeInBits / 8; 23 uint32 blocks = inTextLen / blockSizeInBytes; 24 25 if(blockSizeInBits != 128) { 26 printf("***This AES implementation supports only 128 bit blocks.\n"); 27 return CSSM_ERRCODE_INTERNAL_ERROR; 28 } 29 memmove(aesKey, key, keySizeInBits / 8); 30 set_key(aesKey, keySizeInBits); 31 for( ; blocks > 0; blocks--) { 32 if(forEncrypt) { 33 rEncrypt((u4byte *)inPtr, (u4byte *)outPtr); 34 } 35 else { 36 rDecrypt((u4byte *)inPtr, (u4byte *)outPtr); 37 } 38 inPtr += blockSizeInBytes; 39 outPtr += blockSizeInBytes; 40 } 41 return CSSM_OK; 42} 43