]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/BaseCryptLib/Cipher/CryptAes.c
Fix some typo and coding style issues in BaseCryptLib instances.
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / Cipher / CryptAes.c
index e32063cd9883ba02362ad0e00e19315fa7f9f821..c8dbb797fa7aeb30523dec90cad2c59c02222e4d 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   AES Wrapper Implementation over OpenSSL.\r
 \r
-Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>\r
+Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r
 This program and the accompanying materials\r
 are licensed and made available under the terms and conditions of the BSD License\r
 which accompanies this distribution.  The full text of the license may be found at\r
@@ -38,13 +38,13 @@ AesGetContextSize (
   Initializes user-supplied memory as AES context for subsequent use.\r
 \r
   This function initializes user-supplied memory pointed by AesContext as AES context.\r
-  In addtion, it sets up all AES key materials for subsequent encryption and decryption\r
+  In addition, it sets up all AES key materials for subsequent encryption and decryption\r
   operations.\r
   There are 3 options for key length, 128 bits, 192 bits, and 256 bits.\r
 \r
-  If AesContext is NULL, then ASSERT().\r
-  If Key is NULL, then ASSERT().\r
-  If KeyLength is not valid, then ASSERT().\r
+  If AesContext is NULL, then return FALSE.\r
+  If Key is NULL, then return FALSE.\r
+  If KeyLength is not valid, then return FALSE.\r
 \r
   @param[out]  AesContext  Pointer to AES context being initialized.\r
   @param[in]   Key         Pointer to the user-supplied AES key.\r
@@ -64,12 +64,12 @@ AesInit (
 {\r
   AES_KEY  *AesKey;\r
 \r
-  ASSERT (AesContext != NULL);\r
   //\r
-  // AES Key Checking\r
+  // Check input parameters.\r
   //\r
-  ASSERT (Key != NULL);\r
-  ASSERT ((KeyLength == 128) || (KeyLength == 192) || (KeyLength == 256));\r
+  if (AesContext == NULL || Key == NULL || (KeyLength != 128 && KeyLength != 192 && KeyLength != 256)) {\r
+    return FALSE;\r
+  }\r
 \r
   //\r
   // Initialize AES encryption & decryption key schedule.\r
@@ -94,10 +94,10 @@ AesInit (
   AesContext should be already correctly initialized by AesInit(). Behavior with\r
   invalid AES context is undefined.\r
 \r
-  If AesContext is NULL, then ASSERT().\r
-  If Input is NULL, then ASSERT().\r
-  If InputSize is not multiple of block size (16 bytes), then ASSERT().\r
-  If Output is NULL, then ASSERT().\r
+  If AesContext is NULL, then return FALSE.\r
+  If Input is NULL, then return FALSE.\r
+  If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
+  If Output is NULL, then return FALSE.\r
 \r
   @param[in]   AesContext  Pointer to the AES context.\r
   @param[in]   Input       Pointer to the buffer containing the data to be encrypted.\r
@@ -118,12 +118,14 @@ AesEcbEncrypt (
   )\r
 {\r
   AES_KEY  *AesKey;\r
-  \r
-  ASSERT (AesContext != NULL);\r
-  ASSERT (Input != NULL);\r
-  ASSERT ((InputSize % AES_BLOCK_SIZE) == 0);\r
-  ASSERT (Output != NULL);\r
 \r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (AesContext == NULL || Input == NULL || (InputSize % AES_BLOCK_SIZE) != 0 || Output == NULL) {\r
+    return FALSE;\r
+  }\r
+  \r
   AesKey = (AES_KEY *) AesContext;\r
 \r
   //\r
@@ -149,10 +151,10 @@ AesEcbEncrypt (
   AesContext should be already correctly initialized by AesInit(). Behavior with\r
   invalid AES context is undefined.\r
 \r
-  If AesContext is NULL, then ASSERT().\r
-  If Input is NULL, then ASSERT().\r
-  If InputSize is not multiple of block size (16 bytes), then ASSERT().\r
-  If Output is NULL, then ASSERT().\r
+  If AesContext is NULL, then return FALSE.\r
+  If Input is NULL, then return FALSE.\r
+  If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
+  If Output is NULL, then return FALSE.\r
 \r
   @param[in]   AesContext  Pointer to the AES context.\r
   @param[in]   Input       Pointer to the buffer containing the data to be decrypted.\r
@@ -173,11 +175,13 @@ AesEcbDecrypt (
   )\r
 {\r
   AES_KEY  *AesKey;\r
-  \r
-  ASSERT (AesContext != NULL);\r
-  ASSERT (Input != NULL);\r
-  ASSERT ((InputSize % AES_BLOCK_SIZE) == 0);\r
-  ASSERT (Output != NULL);\r
+\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (AesContext == NULL || Input == NULL || (InputSize % AES_BLOCK_SIZE) != 0 || Output == NULL) {\r
+    return FALSE;\r
+  }\r
 \r
   AesKey = (AES_KEY *) AesContext;\r
 \r
@@ -205,11 +209,11 @@ AesEcbDecrypt (
   AesContext should be already correctly initialized by AesInit(). Behavior with\r
   invalid AES context is undefined.\r
 \r
-  If AesContext is NULL, then ASSERT().\r
-  If Input is NULL, then ASSERT().\r
-  If InputSize is not multiple of block size (16 bytes), then ASSERT().\r
-  If Ivec is NULL, then ASSERT().\r
-  If Output is NULL, then ASSERT().\r
+  If AesContext is NULL, then return FALSE.\r
+  If Input is NULL, then return FALSE.\r
+  If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
+  If Ivec is NULL, then return FALSE.\r
+  If Output is NULL, then return FALSE.\r
 \r
   @param[in]   AesContext  Pointer to the AES context.\r
   @param[in]   Input       Pointer to the buffer containing the data to be encrypted.\r
@@ -234,11 +238,12 @@ AesCbcEncrypt (
   AES_KEY  *AesKey;\r
   UINT8    IvecBuffer[AES_BLOCK_SIZE];\r
 \r
-  ASSERT (AesContext != NULL);\r
-  ASSERT (Input != NULL);\r
-  ASSERT ((InputSize % AES_BLOCK_SIZE) == 0);\r
-  ASSERT (Ivec != NULL);\r
-  ASSERT (Output != NULL);\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (AesContext == NULL || Input == NULL || (InputSize % AES_BLOCK_SIZE) != 0 || Ivec == NULL || Output == NULL) {\r
+    return FALSE;\r
+  }\r
 \r
   AesKey = (AES_KEY *) AesContext;\r
   CopyMem (IvecBuffer, Ivec, AES_BLOCK_SIZE);\r
@@ -262,11 +267,11 @@ AesCbcEncrypt (
   AesContext should be already correctly initialized by AesInit(). Behavior with\r
   invalid AES context is undefined.\r
 \r
-  If AesContext is NULL, then ASSERT().\r
-  If Input is NULL, then ASSERT().\r
-  If InputSize is not multiple of block size (16 bytes), then ASSERT().\r
-  If Ivec is NULL, then ASSERT().\r
-  If Output is NULL, then ASSERT().\r
+  If AesContext is NULL, then return FALSE.\r
+  If Input is NULL, then return FALSE.\r
+  If InputSize is not multiple of block size (16 bytes), then return FALSE.\r
+  If Ivec is NULL, then return FALSE.\r
+  If Output is NULL, then return FALSE.\r
 \r
   @param[in]   AesContext  Pointer to the AES context.\r
   @param[in]   Input       Pointer to the buffer containing the data to be encrypted.\r
@@ -290,12 +295,13 @@ AesCbcDecrypt (
 {\r
   AES_KEY  *AesKey;\r
   UINT8    IvecBuffer[AES_BLOCK_SIZE];\r
-  \r
-  ASSERT (AesContext != NULL);\r
-  ASSERT (Input != NULL);\r
-  ASSERT ((InputSize % AES_BLOCK_SIZE) == 0);\r
-  ASSERT (Ivec != NULL);\r
-  ASSERT (Output != NULL);\r
+\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (AesContext == NULL || Input == NULL || (InputSize % AES_BLOCK_SIZE) != 0 || Ivec == NULL || Output == NULL) {\r
+    return FALSE;\r
+  }\r
 \r
   AesKey = (AES_KEY *) AesContext;\r
   CopyMem (IvecBuffer, Ivec, AES_BLOCK_SIZE);\r