]> git.proxmox.com Git - mirror_edk2.git/blame - CryptoPkg/Library/BaseCryptLib/Hash/CryptMd4.c
Add new interfaces to support PKCS7#7 signed data and authenticode signature. Update...
[mirror_edk2.git] / CryptoPkg / Library / BaseCryptLib / Hash / CryptMd4.c
CommitLineData
4a567c96 1/** @file\r
2 MD4 Digest Wrapper Implementation over OpenSSL.\r
3\r
4Copyright (c) 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 "InternalCryptLib.h"\r
16#include <openssl/md4.h>\r
17\r
18/**\r
19 Retrieves the size, in bytes, of the context buffer required for MD4 hash operations.\r
20\r
21 @return The size, in bytes, of the context buffer required for MD4 hash operations.\r
22\r
23**/\r
24UINTN\r
25EFIAPI\r
26Md4GetContextSize (\r
27 VOID\r
28 )\r
29{\r
30 //\r
31 // Retrieves the OpenSSL MD4 Context Size\r
32 //\r
33 return (UINTN)(sizeof (MD4_CTX));\r
34}\r
35\r
36/**\r
37 Initializes user-supplied memory pointed by Md4Context as MD4 hash context for\r
38 subsequent use.\r
39\r
40 If Md4Context is NULL, then ASSERT().\r
41\r
42 @param[out] Md4Context Pointer to MD4 context being initialized.\r
43\r
44 @retval TRUE MD4 context initialization succeeded.\r
45 @retval FALSE MD4 context initialization failed.\r
46\r
47**/\r
48BOOLEAN\r
49EFIAPI\r
50Md4Init (\r
51 OUT VOID *Md4Context\r
52 )\r
53{\r
54 //\r
55 // ASSERT if Md4Context is NULL.\r
56 //\r
57 ASSERT (Md4Context != NULL);\r
58\r
59 //\r
60 // OpenSSL MD4 Context Initialization\r
61 //\r
62 return (BOOLEAN) (MD4_Init ((MD4_CTX *)Md4Context));\r
63}\r
64\r
65/**\r
66 Makes a copy of an existing MD4 context.\r
67\r
68 If Md4Context is NULL, then ASSERT().\r
69 If NewMd4Context is NULL, then ASSERT().\r
70\r
71 @param[in] Md4Context Pointer to MD4 context being copied.\r
72 @param[out] NewMd4Context Pointer to new MD4 context.\r
73\r
74 @retval TRUE MD4 context copy succeeded.\r
75 @retval FALSE MD4 context copy failed.\r
76\r
77**/\r
78BOOLEAN\r
79EFIAPI\r
80Md4Duplicate (\r
81 IN CONST VOID *Md4Context,\r
82 OUT VOID *NewMd4Context\r
83 )\r
84{\r
85 //\r
86 // ASSERT if Md4Context or NewMd4Context is NULL.\r
87 //\r
88 ASSERT (Md4Context != NULL);\r
89 ASSERT (NewMd4Context != NULL);\r
90\r
91 CopyMem (NewMd4Context, Md4Context, sizeof (MD4_CTX));\r
92\r
93 return TRUE;\r
94}\r
95\r
96/**\r
97 Digests the input data and updates MD4 context.\r
98\r
99 This function performs MD4 digest on a data buffer of the specified size.\r
100 It can be called multiple times to compute the digest of long or discontinuous data streams.\r
101 MD4 context should be already correctly intialized by Md4Init(), and should not be finalized\r
102 by Md4Final(). Behavior with invalid context is undefined.\r
103\r
104 If Md4Context is NULL, then ASSERT().\r
105\r
106 @param[in, out] Md4Context Pointer to the MD4 context.\r
107 @param[in] Data Pointer to the buffer containing the data to be hashed.\r
108 @param[in] DataSize Size of Data buffer in bytes.\r
109\r
110 @retval TRUE MD4 data digest succeeded.\r
111 @retval FALSE MD4 data digest failed.\r
112\r
113**/\r
114BOOLEAN\r
115EFIAPI\r
116Md4Update (\r
117 IN OUT VOID *Md4Context,\r
118 IN CONST VOID *Data,\r
119 IN UINTN DataSize\r
120 )\r
121{\r
122 //\r
123 // ASSERT if Md4Context is NULL\r
124 //\r
125 ASSERT (Md4Context != NULL);\r
126\r
127 //\r
128 // ASSERT if invalid parameters, in case that only DataLength was checked in OpenSSL\r
129 //\r
130 if (Data == NULL) {\r
131 ASSERT (DataSize == 0);\r
132 }\r
133\r
134 //\r
135 // OpenSSL MD4 Hash Update\r
136 //\r
137 return (BOOLEAN) (MD4_Update ((MD4_CTX *)Md4Context, Data, DataSize));\r
138}\r
139\r
140/**\r
141 Completes computation of the MD4 digest value.\r
142\r
143 This function completes MD4 hash computation and retrieves the digest value into\r
144 the specified memory. After this function has been called, the MD4 context cannot\r
145 be used again.\r
146 MD4 context should be already correctly intialized by Md4Init(), and should not be\r
147 finalized by Md4Final(). Behavior with invalid MD4 context is undefined.\r
148\r
149 If Md4Context is NULL, then ASSERT().\r
150 If HashValue is NULL, then ASSERT().\r
151\r
152 @param[in, out] Md4Context Pointer to the MD4 context.\r
153 @param[out] HashValue Pointer to a buffer that receives the MD4 digest\r
154 value (16 bytes).\r
155\r
156 @retval TRUE MD4 digest computation succeeded.\r
157 @retval FALSE MD4 digest computation failed.\r
158\r
159**/\r
160BOOLEAN\r
161EFIAPI\r
162Md4Final (\r
163 IN OUT VOID *Md4Context,\r
164 OUT UINT8 *HashValue\r
165 )\r
166{\r
167 //\r
168 // ASSERT if Md4Context is NULL or HashValue is NULL\r
169 //\r
170 ASSERT (Md4Context != NULL);\r
171 ASSERT (HashValue != NULL);\r
172\r
173 //\r
174 // OpenSSL MD4 Hash Finalization\r
175 //\r
176 return (BOOLEAN) (MD4_Final (HashValue, (MD4_CTX *)Md4Context));\r
177}\r