]> git.proxmox.com Git - mirror_edk2.git/blobdiff - CryptoPkg/Library/BaseCryptLib/Cipher/CryptTdes.c
1. Remove conducting ASSERT in BaseCryptLib.
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / Cipher / CryptTdes.c
index 5535ab368650d5f2c517c404c639949323028a11..8213718b42642f89ec75451d5daa0278533561e5 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
   TDES 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
@@ -44,9 +44,9 @@ TdesGetContextSize (
   KeyLength = 128, Keying option 2: K1 != K2 and K3 = K1 (Less Security)\r
   KeyLength = 192  Keying option 3: K1 != K2 != K3 (Strongest)\r
 \r
-  If TdesContext is NULL, then ASSERT().\r
-  If Key is NULL, then ASSERT().\r
-  If KeyLength is not valid, then ASSERT().\r
+  If TdesContext 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]  TdesContext  Pointer to TDES context being initialized.\r
   @param[in]   Key          Pointer to the user-supplied TDES key.\r
@@ -66,9 +66,12 @@ TdesInit (
 {\r
   DES_key_schedule  *KeySchedule;\r
 \r
-  ASSERT (TdesContext != NULL);\r
-  ASSERT (Key != NULL);\r
-  ASSERT ((KeyLength == 64) || (KeyLength == 128) || (KeyLength == 192));\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (TdesContext == NULL || Key == NULL || (KeyLength != 64 && KeyLength != 128 && KeyLength != 192)) {\r
+    return FALSE;\r
+  }\r
 \r
   KeySchedule = (DES_key_schedule *) TdesContext;\r
 \r
@@ -117,10 +120,10 @@ TdesInit (
   TdesContext should be already correctly initialized by TdesInit(). Behavior with\r
   invalid TDES context is undefined.\r
 \r
-  If TdesContext is NULL, then ASSERT().\r
-  If Input is NULL, then ASSERT().\r
-  If InputSize is not multiple of block size (8 bytes), then ASSERT().\r
-  If Output is NULL, then ASSERT().\r
+  If TdesContext is NULL, then return FALSE.\r
+  If Input is NULL, then return FALSE.\r
+  If InputSize is not multiple of block size (8 bytes), then return FALSE.\r
+  If Output is NULL, then return FALSE.\r
 \r
   @param[in]   TdesContext  Pointer to the TDES context.\r
   @param[in]   Input        Pointer to the buffer containing the data to be encrypted.\r
@@ -142,10 +145,12 @@ TdesEcbEncrypt (
 {\r
   DES_key_schedule  *KeySchedule;\r
 \r
-  ASSERT (TdesContext != NULL);\r
-  ASSERT (Input != NULL);\r
-  ASSERT ((InputSize % TDES_BLOCK_SIZE) == 0);\r
-  ASSERT (Output != NULL);\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (TdesContext == NULL || Input == NULL || (InputSize % TDES_BLOCK_SIZE) != 0 || Output == NULL) {\r
+    return FALSE;\r
+  }\r
 \r
   KeySchedule = (DES_key_schedule *) TdesContext;\r
 \r
@@ -176,10 +181,10 @@ TdesEcbEncrypt (
   TdesContext should be already correctly initialized by TdesInit(). Behavior with\r
   invalid TDES context is undefined.\r
 \r
-  If TdesContext is NULL, then ASSERT().\r
-  If Input is NULL, then ASSERT().\r
-  If InputSize is not multiple of block size (8 bytes), then ASSERT().\r
-  If Output is NULL, then ASSERT().\r
+  If TdesContext is NULL, then return FALSE.\r
+  If Input is NULL, then return FALSE.\r
+  If InputSize is not multiple of block size (8 bytes), then return FALSE.\r
+  If Output is NULL, then return FALSE.\r
 \r
   @param[in]   TdesContext  Pointer to the TDES context.\r
   @param[in]   Input        Pointer to the buffer containing the data to be decrypted.\r
@@ -201,10 +206,12 @@ TdesEcbDecrypt (
 {\r
   DES_key_schedule  *KeySchedule;\r
 \r
-  ASSERT (TdesContext != NULL);\r
-  ASSERT (Input != NULL);\r
-  ASSERT ((InputSize % TDES_BLOCK_SIZE) == 0);\r
-  ASSERT (Output != NULL);\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (TdesContext == NULL || Input == NULL || (InputSize % TDES_BLOCK_SIZE) != 0 || Output == NULL) {\r
+    return FALSE;\r
+  }\r
 \r
   KeySchedule = (DES_key_schedule *) TdesContext;\r
 \r
@@ -236,11 +243,11 @@ TdesEcbDecrypt (
   TdesContext should be already correctly initialized by TdesInit(). Behavior with\r
   invalid TDES context is undefined.\r
 \r
-  If TdesContext is NULL, then ASSERT().\r
-  If Input is NULL, then ASSERT().\r
-  If InputSize is not multiple of block size (8 bytes), then ASSERT().\r
-  If Ivec is NULL, then ASSERT().\r
-  If Output is NULL, then ASSERT().\r
+  If TdesContext is NULL, then return FALSE.\r
+  If Input is NULL, then return FALSE.\r
+  If InputSize is not multiple of block size (8 bytes), then return FALSE.\r
+  If Ivec is NULL, then return FALSE.\r
+  If Output is NULL, then return FALSE.\r
 \r
   @param[in]   TdesContext  Pointer to the TDES context.\r
   @param[in]   Input        Pointer to the buffer containing the data to be encrypted.\r
@@ -265,11 +272,12 @@ TdesCbcEncrypt (
   DES_key_schedule  *KeySchedule;\r
   UINT8             IvecBuffer[TDES_BLOCK_SIZE];\r
 \r
-  ASSERT (TdesContext != NULL);\r
-  ASSERT (Input != NULL);\r
-  ASSERT ((InputSize % TDES_BLOCK_SIZE) == 0);\r
-  ASSERT (Ivec != NULL);\r
-  ASSERT (Output != NULL);\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (TdesContext == NULL || Input == NULL || (InputSize % TDES_BLOCK_SIZE) != 0 || Ivec == NULL || Output == NULL) {\r
+    return FALSE;\r
+  }\r
 \r
   KeySchedule = (DES_key_schedule *) TdesContext;\r
   CopyMem (IvecBuffer, Ivec, TDES_BLOCK_SIZE);\r
@@ -299,11 +307,11 @@ TdesCbcEncrypt (
   TdesContext should be already correctly initialized by TdesInit(). Behavior with\r
   invalid TDES context is undefined.\r
 \r
-  If TdesContext is NULL, then ASSERT().\r
-  If Input is NULL, then ASSERT().\r
-  If InputSize is not multiple of block size (8 bytes), then ASSERT().\r
-  If Ivec is NULL, then ASSERT().\r
-  If Output is NULL, then ASSERT().\r
+  If TdesContext is NULL, then return FALSE.\r
+  If Input is NULL, then return FALSE.\r
+  If InputSize is not multiple of block size (8 bytes), then return FALSE.\r
+  If Ivec is NULL, then return FALSE.\r
+  If Output is NULL, then return FALSE.\r
 \r
   @param[in]   TdesContext  Pointer to the TDES context.\r
   @param[in]   Input        Pointer to the buffer containing the data to be encrypted.\r
@@ -328,11 +336,12 @@ TdesCbcDecrypt (
   DES_key_schedule  *KeySchedule;\r
   UINT8             IvecBuffer[TDES_BLOCK_SIZE];\r
 \r
-  ASSERT (TdesContext != NULL);\r
-  ASSERT (Input != NULL);\r
-  ASSERT ((InputSize % TDES_BLOCK_SIZE) == 0);\r
-  ASSERT (Ivec != NULL);\r
-  ASSERT (Output != NULL);\r
+  //\r
+  // Check input parameters.\r
+  //\r
+  if (TdesContext == NULL || Input == NULL || (InputSize % TDES_BLOCK_SIZE) != 0 || Ivec == NULL || Output == NULL) {\r
+    return FALSE;\r
+  }\r
 \r
   KeySchedule = (DES_key_schedule *) TdesContext;\r
   CopyMem (IvecBuffer, Ivec, TDES_BLOCK_SIZE);\r