]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/Network/IScsiDxe/Md5.c
sync comments, fix function header, rename variable name to follow coding style.
[mirror_edk2.git] / MdeModulePkg / Universal / Network / IScsiDxe / Md5.c
index 44aceaeafa3cd23df7c8d7cf7733375b0675bcd7..ee69a9849690ed5dcebd418a8b7dfbff493ed715 100644 (file)
@@ -1,6 +1,7 @@
-/*++\r
+/** @file\r
+  Implementation of MD5 algorithm\r
 \r
-Copyright (c) 2004 - 2007, Intel Corporation\r
+Copyright (c) 2004 - 2008, Intel Corporation\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
@@ -17,25 +18,25 @@ Abstract:
 \r
   Implementation of MD5 algorithm\r
 \r
---*/\r
+**/\r
 \r
 #include "Md5.h"\r
 \r
-STATIC CONST UINT32  MD5_K[][2] = {\r
+CONST UINT32  MD5_K[][2] = {\r
   { 0, 1 },\r
   { 1, 5 },\r
   { 5, 3 },\r
   { 0, 7 }\r
 };\r
 \r
-STATIC 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
-STATIC 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
@@ -54,7 +55,7 @@ STATIC CONST UINT32  MD5_T[] = {
   0xF7537E82, 0xBD3AF235, 0x2AD7D2BB, 0xEB86D391\r
 };\r
 \r
-STATIC CONST UINT8 Md5HashPadding[] =\r
+CONST UINT8 Md5HashPadding[] =\r
 {\r
   0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
   0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,\r
@@ -115,33 +116,25 @@ UINT32
   IN UINT32  C\r
   );\r
 \r
-STATIC CONST MD5_TRANSFORM_FUNC MD5_F[] = {\r
+CONST MD5_TRANSFORM_FUNC MD5_F[] = {\r
   TF1,\r
   TF2,\r
   TF3,\r
   TF4\r
 };\r
 \r
-STATIC\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
+\r
+**/\r
 VOID\r
 MD5Transform (\r
   IN MD5_CTX  *Md5Ctx\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
-  Md5Ctx  - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
-  GC_TODO: add return values\r
-\r
---*/\r
 {\r
   UINT32  i;\r
   UINT32  j;\r
@@ -155,7 +148,7 @@ Returns:
   //\r
   // Copy MD5 states to S\r
   //\r
-  NetCopyMem (S, Md5Ctx->States, MD5_HASHSIZE);\r
+  CopyMem (S, Md5Ctx->States, MD5_HASHSIZE);\r
 \r
   t = 0;\r
   for (i = 0; i < 4; i++) {\r
@@ -177,35 +170,34 @@ Returns:
   }\r
 }\r
 \r
-STATIC\r
+/**\r
+  Copy data segment into the M field of MD5_CTX structure for later transform.\r
+  If the length of data segment is larger than 64 bytes, then does the transform\r
+  immediately and the generated Md5 code is stored in the States field of MD5_CTX\r
+  data struct for later accumulation. \r
+  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
+                      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
+**/\r
 VOID\r
 MD5UpdateBlock (\r
   IN MD5_CTX      *Md5Ctx,\r
   IN CONST UINT8  *Data,\r
   IN       UINTN  DataLen\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
-  Md5Ctx  - GC_TODO: add argument description\r
-  Data    - GC_TODO: add argument description\r
-  DataLen - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
-  GC_TODO: add return values\r
-\r
---*/\r
 {\r
   UINTN Limit;\r
 \r
   for (Limit = 64 - Md5Ctx->Count; DataLen >= 64 - Md5Ctx->Count; Limit = 64) {\r
-    NetCopyMem (Md5Ctx->M + Md5Ctx->Count, (VOID *)Data, Limit);\r
+    CopyMem (Md5Ctx->M + Md5Ctx->Count, (VOID *)Data, Limit);\r
     MD5Transform (Md5Ctx);\r
     \r
     Md5Ctx->Count = 0;\r
@@ -213,31 +205,24 @@ Returns:
     DataLen      -= Limit;\r
   }\r
 \r
-  NetCopyMem (Md5Ctx->M + Md5Ctx->Count, (VOID *)Data, DataLen);\r
+  CopyMem (Md5Ctx->M + Md5Ctx->Count, (VOID *)Data, DataLen);\r
   Md5Ctx->Count += DataLen;\r
 }\r
 \r
+/**\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
+\r
+**/\r
 EFI_STATUS\r
 MD5Init (\r
   IN MD5_CTX  *Md5Ctx\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
-  Md5Ctx  - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS - GC_TODO: Add description for return value\r
-\r
---*/\r
 {\r
-  NetZeroMem (Md5Ctx, sizeof (*Md5Ctx));\r
+  ZeroMem (Md5Ctx, sizeof (*Md5Ctx));\r
 \r
   //\r
   // Set magic initialization constants.\r
@@ -250,29 +235,25 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\r
+  the external interface of Md5 algorithm\r
+\r
+  @param  Md5Ctx[in]  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 EFI_SUCCESS the transform is ok.\r
+\r
+**/\r
 EFI_STATUS\r
 MD5Update (\r
   IN  MD5_CTX  *Md5Ctx,\r
   IN  VOID     *Data,\r
   IN  UINTN    DataLen\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
-  Md5Ctx  - GC_TODO: add argument description\r
-  Data    - GC_TODO: add argument description\r
-  DataLen - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS - GC_TODO: Add description for return value\r
-\r
---*/\r
 {\r
   if (EFI_ERROR (Md5Ctx->Status)) {\r
     return Md5Ctx->Status;\r
@@ -283,27 +264,23 @@ Returns:
   return EFI_SUCCESS;\r
 }\r
 \r
+/**\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
+                       segment and the final result.\r
+\r
+  @param  HashVal[out] the final 128-bits output.\r
+\r
+  @retval EFI_SUCCESS  the transform is ok.\r
+\r
+**/\r
 EFI_STATUS\r
 MD5Final (\r
   IN  MD5_CTX  *Md5Ctx,\r
   OUT UINT8    *HashVal\r
   )\r
-/*++\r
-\r
-Routine Description:\r
-\r
-  GC_TODO: Add function description\r
-\r
-Arguments:\r
-\r
-  Md5Ctx  - GC_TODO: add argument description\r
-  HashVal - GC_TODO: add argument description\r
-\r
-Returns:\r
-\r
-  EFI_SUCCESS - GC_TODO: Add description for return value\r
-\r
---*/\r
 {\r
   UINTN PadLength;\r
 \r
@@ -311,8 +288,8 @@ Returns:
     //\r
     // Store Hashed value & Zeroize sensitive context information.\r
     //\r
-    NetCopyMem (HashVal, (UINT8 *) Md5Ctx->States, MD5_HASHSIZE);\r
-    NetZeroMem ((UINT8 *)Md5Ctx, sizeof (*Md5Ctx));\r
+    CopyMem (HashVal, (UINT8 *) Md5Ctx->States, MD5_HASHSIZE);\r
+    ZeroMem ((UINT8 *)Md5Ctx, sizeof (*Md5Ctx));\r
     \r
     return EFI_SUCCESS;\r
   }\r
@@ -327,7 +304,7 @@ Returns:
   Md5Ctx->Length = LShiftU64 (Md5Ctx->Length, 3);\r
   MD5UpdateBlock (Md5Ctx, (CONST UINT8 *) &Md5Ctx->Length, 8);\r
 \r
-  NetZeroMem (Md5Ctx->M, sizeof (Md5Ctx->M));\r
+  ZeroMem (Md5Ctx->M, sizeof (Md5Ctx->M));\r
   Md5Ctx->Length  = 0;\r
   Md5Ctx->Status  = EFI_ALREADY_STARTED;\r
   return MD5Final (Md5Ctx, HashVal);\r