]> git.proxmox.com Git - mirror_edk2.git/commitdiff
update file header
authorywu21 <ywu21@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 10 Dec 2008 06:18:18 +0000 (06:18 +0000)
committerywu21 <ywu21@6f19259b-4bc3-4df7-8a09-765794883524>
Wed, 10 Dec 2008 06:18:18 +0000 (06:18 +0000)
update function header
update a lot of variable naming
add some function header and adjust function layout

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@6969 6f19259b-4bc3-4df7-8a09-765794883524

MdeModulePkg/Universal/Network/IScsiDxe/Md5.c

index ee69a9849690ed5dcebd418a8b7dfbff493ed715..202de40d1f1df17f3b1bfcf09f9f532818b4054c 100644 (file)
@@ -1,7 +1,7 @@
 /** @file\r
-  Implementation of MD5 algorithm\r
+  Implementation of MD5 algorithm.\r
 \r
-Copyright (c) 2004 - 2008, Intel Corporation\r
+Copyright (c) 2004 - 2008, Intel Corporation.<BR>\r
 All rights reserved. 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
@@ -10,33 +10,25 @@ http://opensource.org/licenses/bsd-license.php
 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
 \r
-Module Name:\r
-\r
-  Md5.c\r
-\r
-Abstract:\r
-\r
-  Implementation of MD5 algorithm\r
-\r
 **/\r
 \r
 #include "Md5.h"\r
 \r
-CONST UINT32  MD5_K[][2] = {\r
+CONST UINT32  Md5_Data[][2] = {\r
   { 0, 1 },\r
   { 1, 5 },\r
   { 5, 3 },\r
   { 0, 7 }\r
 };\r
 \r
-CONST UINT32  MD5_S[][4] = {\r
+CONST UINT32  Md5_S[][4] = {\r
   { 7, 22, 17, 12 },\r
   { 5, 20, 14, 9 },\r
   { 4, 23, 16 ,11 },\r
   { 6, 21, 15, 10 },\r
 };\r
 \r
-CONST UINT32  MD5_T[] = {\r
+CONST UINT32  Md5_T[] = {\r
   0xD76AA478, 0xE8C7B756, 0x242070DB, 0xC1BDCEEE,\r
   0xF57C0FAF, 0x4787C62A, 0xA8304613, 0xFD469501,\r
   0x698098D8, 0x8B44F7AF, 0xFFFF5BB1, 0x895CD7BE,\r
@@ -80,30 +72,87 @@ CONST UINT8 Md5HashPadding[] =
 //\r
 #define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n))))\r
 \r
-#define SA            S[j & 3]\r
-#define SB            S[(j + 1) & 3]\r
-#define SC            S[(j + 2) & 3]\r
-#define SD            S[(j + 3) & 3]\r
+#define SA            MedStates[Index2 & 3]\r
+#define SB            MedStates[(Index2 + 1) & 3]\r
+#define SC            MedStates[(Index2 + 2) & 3]\r
+#define SD            MedStates[(Index2 + 3) & 3]\r
 \r
-//\r
-// TF1, TF2, TF3, TF4 are basic MD5 transform functions\r
-//\r
-UINT32 TF1 (UINT32 A, UINT32 B, UINT32 C)\r
+/**\r
+  Tf1 is one basic MD5 transform function.\r
+  \r
+  @param[in]  A      A  32-bit quantity.\r
+  @param[in]  B      A  32-bit quantity. \r
+  @param[in]  C      A  32-bit quantity.\r
+\r
+  @return             Output was produced as a 32-bit quantity based on the\r
+                      three 32-bit input quantity.   \r
+**/\r
+UINT32 \r
+Tf1 (\r
+  UINT32 A, \r
+  UINT32 B, \r
+  UINT32 C\r
+  )\r
 {\r
   return (A & B) | (~A & C);\r
 }\r
 \r
-UINT32 TF2 (UINT32 A, UINT32 B, UINT32 C)\r
+/**\r
+  Tf2 is one basic MD5 transform function.\r
+  \r
+  @param[in]  A      A  32-bit quantity.\r
+  @param[in]  B      A  32-bit quantity. \r
+  @param[in]  C      A  32-bit quantity.\r
+\r
+  @return             Output was produced as a 32-bit quantity based on the\r
+                      three 32-bit input quantity.   \r
+**/\r
+UINT32 \r
+Tf2 (\r
+  UINT32 A, \r
+  UINT32 B, \r
+  UINT32 C\r
+  )\r
 {\r
   return (A & C) | (B & ~C);\r
 }\r
 \r
-UINT32 TF3 (UINT32 A, UINT32 B, UINT32 C)\r
+/**\r
+  Tf3 is one basic MD5 transform function.\r
+  \r
+  @param[in]  A      A  32-bit quantity.\r
+  @param[in]  B      A  32-bit quantity. \r
+  @param[in]  C      A  32-bit quantity.\r
+\r
+  @return             Output was produced as a 32-bit quantity based on the\r
+                      three 32-bit input quantity.   \r
+**/\r
+UINT32 \r
+Tf3 (\r
+  UINT32 A, \r
+  UINT32 B, \r
+  UINT32 C\r
+  )\r
 {\r
   return A ^ B ^ C;\r
 }\r
 \r
-UINT32 TF4 (UINT32 A, UINT32 B, UINT32 C)\r
+/**\r
+  Tf4 is one basic MD5 transform function.\r
+  \r
+  @param[in]  A      A  32-bit quantity.\r
+  @param[in]  B      A  32-bit quantity. \r
+  @param[in]  C      A  32-bit quantity.\r
+\r
+  @return             Output was produced as a 32-bit quantity based on the\r
+                      three 32-bit input quantity.   \r
+**/\r
+UINT32 \r
+Tf4 (\r
+  UINT32 A, \r
+  UINT32 B, \r
+  UINT32 C\r
+  )\r
 {\r
   return B ^ (A | ~C);\r
 }\r
@@ -116,57 +165,54 @@ UINT32
   IN UINT32  C\r
   );\r
 \r
-CONST MD5_TRANSFORM_FUNC MD5_F[] = {\r
-  TF1,\r
-  TF2,\r
-  TF3,\r
-  TF4\r
+CONST MD5_TRANSFORM_FUNC Md5_F[] = {\r
+  Tf1,\r
+  Tf2,\r
+  Tf3,\r
+  Tf4\r
 };\r
 \r
 /**\r
-  Perform the MD5 transform on 64 bytes data segment\r
-\r
-  @param  Md5Ctx[in]  it includes the data segment for Md5 transform\r
-\r
-  @retval NONE.\r
+  Perform the MD5 transform on 64 bytes data segment.\r
 \r
+  @param[in]  Md5Ctx  It includes the data segment for Md5 transform.\r
 **/\r
 VOID\r
 MD5Transform (\r
   IN MD5_CTX  *Md5Ctx\r
   )\r
 {\r
-  UINT32  i;\r
-  UINT32  j;\r
-  UINT32  S[MD5_HASHSIZE >> 2];\r
-  UINT32  *X;\r
-  UINT32  k;\r
-  UINT32  t;\r
+  UINT32  Index1;\r
+  UINT32  Index2;\r
+  UINT32  MedStates[MD5_HASHSIZE >> 2];\r
+  UINT32  *Data;\r
+  UINT32  IndexD;\r
+  UINT32  IndexT;\r
 \r
-  X = (UINT32 *) Md5Ctx->M;\r
+  Data = (UINT32 *) Md5Ctx->M;\r
 \r
   //\r
-  // Copy MD5 states to S\r
+  // Copy MD5 states to MedStates\r
   //\r
-  CopyMem (S, Md5Ctx->States, MD5_HASHSIZE);\r
-\r
-  t = 0;\r
-  for (i = 0; i < 4; i++) {\r
-    k = MD5_K[i][0];\r
-    for (j = 16; j > 0; j--) {\r
-      SA += (*MD5_F[i]) (SB, SC, SD) + X[k] + MD5_T[t];\r
-      SA  = ROTATE_LEFT (SA, MD5_S[i][j & 3]);\r
+  CopyMem (MedStates, Md5Ctx->States, MD5_HASHSIZE);\r
+\r
+  IndexT = 0;\r
+  for (Index1 = 0; Index1 < 4; Index1++) {\r
+    IndexD = Md5_Data[Index1][0];\r
+    for (Index2 = 16; Index2 > 0; Index2--) {\r
+      SA += (*Md5_F[Index1]) (SB, SC, SD) + Data[IndexD] + Md5_T[IndexT];\r
+      SA  = ROTATE_LEFT (SA, Md5_S[Index1][Index2 & 3]);\r
       SA += SB;\r
 \r
-      k += MD5_K[i][1];\r
-      k &= 15;\r
+      IndexD += Md5_Data[Index1][1];\r
+      IndexD &= 15;\r
 \r
-      t++;\r
+      IndexT++;\r
     }\r
   }\r
 \r
-  for (i = 0; i < 4; i++) {\r
-    Md5Ctx->States[i] += S[i];\r
+  for (Index1 = 0; Index1 < 4; Index1++) {\r
+    Md5Ctx->States[Index1] += MedStates[Index1];\r
   }\r
 }\r
 \r
@@ -178,14 +224,10 @@ MD5Transform (
   All of Md5 code generated for the sequential 64-bytes data segaments are be\r
   accumulated in MD5Final() function.\r
 \r
-  @param  Md5Ctx[in]  the data structure of storing the original data\r
+  @param[in]  Md5Ctx  The data structure of storing the original data\r
                       segment and the final result.\r
-\r
-  @param  Data[in]    the data wanted to be transformed\r
-\r
-  @param  DataLen[in] the length of data\r
-\r
-  @retval NONE.\r
+  @param[in]  Data    The data wanted to be transformed.\r
+  @param[in]  DataLen The length of data.\r
 **/\r
 VOID\r
 MD5UpdateBlock (\r
@@ -212,10 +254,9 @@ MD5UpdateBlock (
 /**\r
   Initialize four 32-bits chaining variables and use them to do the Md5 transform.\r
 \r
-  @param  Md5Ctx[in]  the data structure of Md5\r
-\r
-  @retval EFI_SUCCESS initialization is ok\r
+  @param[in]  Md5Ctx The data structure of Md5.\r
 \r
+  @retval EFI_SUCCESS Initialization is ok.\r
 **/\r
 EFI_STATUS\r
 MD5Init (\r
@@ -238,15 +279,13 @@ MD5Init (
 /**\r
   the external interface of Md5 algorithm\r
 \r
-  @param  Md5Ctx[in]  the data structure of storing the original data\r
+  @param[in]  Md5Ctx  The data structure of storing the original data\r
                       segment and the final result.\r
+  @param[in]  Data    The data wanted to be transformed.\r
+  @param[in]  DataLen The length of data.\r
 \r
-  @param  Data[in]    the data wanted to be transformed.\r
-\r
-  @param  DataLen[in] the length of data.\r
-\r
-  @retval EFI_SUCCESS the transform is ok.\r
-\r
+  @retval EFI_SUCCESS The transform is ok.\r
+  @retval Others      Some unexpected errors happened.\r
 **/\r
 EFI_STATUS\r
 MD5Update (\r
@@ -265,16 +304,15 @@ MD5Update (
 }\r
 \r
 /**\r
-  accumulate the MD5 value of every data segment and generate the finial\r
-  result according to MD5 algorithm\r
+  Accumulate the MD5 value of every data segment and generate the finial\r
+  result according to MD5 algorithm.\r
 \r
-  @param  Md5Ctx[in]   the data structure of storing the original data\r
+  @param[in]   Md5Ctx  The data structure of storing the original data\r
                        segment and the final result.\r
+  @param[out]  HashVal The final 128-bits output.\r
 \r
-  @param  HashVal[out] the final 128-bits output.\r
-\r
-  @retval EFI_SUCCESS  the transform is ok.\r
-\r
+  @retval EFI_SUCCESS  The transform is ok.\r
+  @retval Others       Some unexpected errors happened.\r
 **/\r
 EFI_STATUS\r
 MD5Final (\r