]> git.saurik.com Git - apple/security.git/blobdiff - SecurityTests/cspxutils/aesVect/enDecryptTest.c
Security-57031.1.35.tar.gz
[apple/security.git] / SecurityTests / cspxutils / aesVect / enDecryptTest.c
diff --git a/SecurityTests/cspxutils/aesVect/enDecryptTest.c b/SecurityTests/cspxutils/aesVect/enDecryptTest.c
new file mode 100644 (file)
index 0000000..ccbcd90
--- /dev/null
@@ -0,0 +1,42 @@
+#include "enDecrypt.h"
+#include "std_defs.h"  
+#include <strings.h>
+#include <stdio.h>
+
+/* 
+ * encrypt/decrypt using Gladman version of AES.
+ */
+
+CSSM_RETURN encryptDecryptTest(
+       CSSM_BOOL                       forEncrypt,
+       uint32                          keySizeInBits,
+       uint32                          blockSizeInBits,        
+       const uint8                     *key,                           // raw key bytes
+       const uint8                     *inText,
+       uint32                          inTextLen,
+       uint8                           *outText)
+{
+       u4byte                  aesKey[8];
+       uint8                   *inPtr = (uint8 *)inText;
+       uint8                   *outPtr = outText;
+       uint32                  blockSizeInBytes = blockSizeInBits / 8;
+       uint32                  blocks = inTextLen / blockSizeInBytes;
+       
+       if(blockSizeInBits != 128) {
+               printf("***This AES implementation supports only 128 bit blocks.\n");
+               return CSSM_ERRCODE_INTERNAL_ERROR;
+       }
+       memmove(aesKey, key, keySizeInBits / 8);
+       set_key(aesKey, keySizeInBits);
+       for( ; blocks > 0; blocks--) {
+               if(forEncrypt) {
+                       rEncrypt((u4byte *)inPtr, (u4byte *)outPtr);
+               }
+               else {
+                       rDecrypt((u4byte *)inPtr, (u4byte *)outPtr);
+               }
+               inPtr += blockSizeInBytes;
+               outPtr += blockSizeInBytes;
+       }
+       return CSSM_OK;
+}