]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Library/BaseCryptLib/Hash/CryptMd5.c
Fix PCD token value conflict issue.
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / Hash / CryptMd5.c
CommitLineData
97f98500
HT
1/** @file\r
2 MD5 Digest Wrapper Implementation over OpenSSL.\r
3\r
4Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r
5This program and the accompanying materials\r
6are licensed and made available under the terms and conditions of the BSD License\r
7which accompanies this distribution. The full text of the license may be found at\r
8http://opensource.org/licenses/bsd-license.php\r
9\r
10THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
11WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
12\r
13**/\r
14\r
15#include <Library/BaseLib.h>\r
16#include <Library/DebugLib.h>\r
17\r
18#include <Library/BaseCryptLib.h>\r
19#include <openssl/md5.h>\r
20\r
21\r
22/**\r
23 Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.\r
24\r
25 @return The size, in bytes, of the context buffer required for MD5 hash operations.\r
26\r
27**/\r
28UINTN\r
29EFIAPI\r
30Md5GetContextSize (\r
31 VOID\r
32 )\r
33{\r
34 //\r
35 // Retrieves the OpenSSL MD5 Context Size\r
36 //\r
37 return (UINTN)(sizeof (MD5_CTX));\r
38}\r
39\r
40\r
41/**\r
42 Initializes user-supplied memory pointed by Md5Context as MD5 hash context for\r
43 subsequent use.\r
44\r
45 If Md5Context is NULL, then ASSERT().\r
46\r
47 @param[in, out] Md5Context Pointer to MD5 Context being initialized.\r
48\r
49 @retval TRUE MD5 context initialization succeeded.\r
50 @retval FALSE MD5 context initialization failed.\r
51\r
52**/\r
53BOOLEAN\r
54EFIAPI\r
55Md5Init (\r
56 IN OUT VOID *Md5Context\r
57 )\r
58{\r
59 //\r
60 // ASSERT if Md5Context is NULL.\r
61 //\r
62 ASSERT (Md5Context != NULL);\r
63\r
64 //\r
65 // OpenSSL MD5 Context Initialization\r
66 //\r
67 return (BOOLEAN) (MD5_Init ((MD5_CTX *)Md5Context));\r
68}\r
69\r
70\r
71/**\r
72 Performs MD5 digest on a data buffer of the specified length. This function can\r
73 be called multiple times to compute the digest of long or discontinuous data streams.\r
74\r
75 If Md5Context is NULL, then ASSERT().\r
76\r
77 @param[in, out] Md5Context Pointer to the MD5 context.\r
78 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
79 @param[in] DataLength Length of Data buffer in bytes.\r
80\r
81 @retval TRUE MD5 data digest succeeded.\r
82 @retval FALSE Invalid MD5 context. After Md5Final function has been called, the\r
83 MD5 context cannot be reused.\r
84\r
85**/\r
86BOOLEAN\r
87EFIAPI\r
88Md5Update (\r
89 IN OUT VOID *Md5Context,\r
90 IN CONST VOID *Data,\r
91 IN UINTN DataLength\r
92 )\r
93{\r
94 //\r
95 // ASSERT if Md5Context is NULL\r
96 //\r
97 ASSERT (Md5Context != NULL);\r
98\r
99 //\r
100 // ASSERT if invalid parameters, in case that only DataLength was checked in OpenSSL\r
101 //\r
102 if (Data == NULL) {\r
103 ASSERT (DataLength == 0);\r
104 }\r
105\r
106 //\r
107 // OpenSSL MD5 Hash Update\r
108 //\r
109 return (BOOLEAN) (MD5_Update ((MD5_CTX *)Md5Context, Data, DataLength));\r
110}\r
111\r
112\r
113/**\r
114 Completes MD5 hash computation and retrieves the digest value into the specified\r
115 memory. After this function has been called, the MD5 context cannot be used again.\r
116\r
117 If Md5Context is NULL, then ASSERT().\r
118 If HashValue is NULL, then ASSERT().\r
119\r
120 @param[in, out] Md5Context Pointer to the MD5 context\r
121 @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r
122 value (16 bytes).\r
123\r
124 @retval TRUE MD5 digest computation succeeded.\r
125 @retval FALSE MD5 digest computation failed.\r
126\r
127**/\r
128BOOLEAN\r
129EFIAPI\r
130Md5Final (\r
131 IN OUT VOID *Md5Context,\r
132 OUT UINT8 *HashValue\r
133 )\r
134{\r
135 //\r
136 // ASSERT if Md5Context is NULL or HashValue is NULL\r
137 //\r
138 ASSERT (Md5Context != NULL);\r
139 ASSERT (HashValue != NULL);\r
140\r
141 //\r
142 // OpenSSL MD5 Hash Finalization\r
143 //\r
144 return (BOOLEAN) (MD5_Final (HashValue, (MD5_CTX *)Md5Context));\r
145}\r