]>
Commit | Line | Data |
---|---|---|
97f98500 HT |
1 | /** @file\r |
2 | MD5 Digest Wrapper Implementation over OpenSSL.\r | |
3 | \r | |
4 | Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
a8c44645 | 15 | #include "InternalCryptLib.h"\r |
97f98500 HT |
16 | #include <openssl/md5.h>\r |
17 | \r | |
18 | \r | |
19 | /**\r | |
20 | Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.\r | |
21 | \r | |
22 | @return The size, in bytes, of the context buffer required for MD5 hash operations.\r | |
23 | \r | |
24 | **/\r | |
25 | UINTN\r | |
26 | EFIAPI\r | |
27 | Md5GetContextSize (\r | |
28 | VOID\r | |
29 | )\r | |
30 | {\r | |
31 | //\r | |
32 | // Retrieves the OpenSSL MD5 Context Size\r | |
33 | //\r | |
34 | return (UINTN)(sizeof (MD5_CTX));\r | |
35 | }\r | |
36 | \r | |
37 | \r | |
38 | /**\r | |
39 | Initializes user-supplied memory pointed by Md5Context as MD5 hash context for\r | |
40 | subsequent use.\r | |
41 | \r | |
42 | If Md5Context is NULL, then ASSERT().\r | |
43 | \r | |
a8c44645 | 44 | @param[out] Md5Context Pointer to MD5 context being initialized.\r |
97f98500 HT |
45 | \r |
46 | @retval TRUE MD5 context initialization succeeded.\r | |
47 | @retval FALSE MD5 context initialization failed.\r | |
48 | \r | |
49 | **/\r | |
50 | BOOLEAN\r | |
51 | EFIAPI\r | |
52 | Md5Init (\r | |
a8c44645 | 53 | OUT VOID *Md5Context\r |
97f98500 HT |
54 | )\r |
55 | {\r | |
56 | //\r | |
57 | // ASSERT if Md5Context is NULL.\r | |
58 | //\r | |
59 | ASSERT (Md5Context != NULL);\r | |
60 | \r | |
61 | //\r | |
62 | // OpenSSL MD5 Context Initialization\r | |
63 | //\r | |
64 | return (BOOLEAN) (MD5_Init ((MD5_CTX *)Md5Context));\r | |
65 | }\r | |
66 | \r | |
a8c44645 | 67 | /**\r |
68 | Makes a copy of an existing MD5 context.\r | |
69 | \r | |
70 | If Md5Context is NULL, then ASSERT().\r | |
71 | If NewMd5Context is NULL, then ASSERT().\r | |
72 | \r | |
73 | @param[in] Md5Context Pointer to MD5 context being copied.\r | |
74 | @param[out] NewMd5Context Pointer to new MD5 context.\r | |
75 | \r | |
76 | @retval TRUE MD5 context copy succeeded.\r | |
77 | @retval FALSE MD5 context copy failed.\r | |
78 | \r | |
79 | **/\r | |
80 | BOOLEAN\r | |
81 | EFIAPI\r | |
82 | Md5Duplicate (\r | |
83 | IN CONST VOID *Md5Context,\r | |
84 | OUT VOID *NewMd5Context\r | |
85 | )\r | |
86 | {\r | |
4a567c96 | 87 | //\r |
88 | // ASSERT if Md5Context or NewMd5Context is NULL.\r | |
89 | //\r | |
90 | ASSERT (Md5Context != NULL);\r | |
91 | ASSERT (NewMd5Context != NULL);\r | |
92 | \r | |
a8c44645 | 93 | CopyMem (NewMd5Context, Md5Context, sizeof (MD5_CTX));\r |
94 | \r | |
95 | return TRUE;\r | |
96 | }\r | |
97f98500 HT |
97 | \r |
98 | /**\r | |
a8c44645 | 99 | Digests the input data and updates MD5 context.\r |
100 | \r | |
101 | This function performs MD5 digest on a data buffer of the specified size.\r | |
102 | It can be called multiple times to compute the digest of long or discontinuous data streams.\r | |
103 | MD5 context should be already correctly intialized by Md5Init(), and should not be finalized\r | |
104 | by Md5Final(). Behavior with invalid context is undefined.\r | |
97f98500 HT |
105 | \r |
106 | If Md5Context is NULL, then ASSERT().\r | |
107 | \r | |
108 | @param[in, out] Md5Context Pointer to the MD5 context.\r | |
109 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
a8c44645 | 110 | @param[in] DataSize Size of Data buffer in bytes.\r |
97f98500 HT |
111 | \r |
112 | @retval TRUE MD5 data digest succeeded.\r | |
a8c44645 | 113 | @retval FALSE MD5 data digest failed.\r |
97f98500 HT |
114 | \r |
115 | **/\r | |
116 | BOOLEAN\r | |
117 | EFIAPI\r | |
118 | Md5Update (\r | |
119 | IN OUT VOID *Md5Context,\r | |
120 | IN CONST VOID *Data,\r | |
a8c44645 | 121 | IN UINTN DataSize\r |
97f98500 HT |
122 | )\r |
123 | {\r | |
124 | //\r | |
125 | // ASSERT if Md5Context is NULL\r | |
126 | //\r | |
127 | ASSERT (Md5Context != NULL);\r | |
128 | \r | |
129 | //\r | |
130 | // ASSERT if invalid parameters, in case that only DataLength was checked in OpenSSL\r | |
131 | //\r | |
132 | if (Data == NULL) {\r | |
a8c44645 | 133 | ASSERT (DataSize == 0);\r |
97f98500 HT |
134 | }\r |
135 | \r | |
136 | //\r | |
137 | // OpenSSL MD5 Hash Update\r | |
138 | //\r | |
a8c44645 | 139 | return (BOOLEAN) (MD5_Update ((MD5_CTX *)Md5Context, Data, DataSize));\r |
97f98500 HT |
140 | }\r |
141 | \r | |
97f98500 | 142 | /**\r |
a8c44645 | 143 | Completes computation of the MD5 digest value.\r |
144 | \r | |
145 | This function completes MD5 hash computation and retrieves the digest value into\r | |
146 | the specified memory. After this function has been called, the MD5 context cannot\r | |
147 | be used again.\r | |
148 | MD5 context should be already correctly intialized by Md5Init(), and should not be\r | |
149 | finalized by Md5Final(). Behavior with invalid MD5 context is undefined.\r | |
97f98500 HT |
150 | \r |
151 | If Md5Context is NULL, then ASSERT().\r | |
152 | If HashValue is NULL, then ASSERT().\r | |
153 | \r | |
a8c44645 | 154 | @param[in, out] Md5Context Pointer to the MD5 context.\r |
97f98500 HT |
155 | @param[out] HashValue Pointer to a buffer that receives the MD5 digest\r |
156 | value (16 bytes).\r | |
157 | \r | |
158 | @retval TRUE MD5 digest computation succeeded.\r | |
159 | @retval FALSE MD5 digest computation failed.\r | |
160 | \r | |
161 | **/\r | |
162 | BOOLEAN\r | |
163 | EFIAPI\r | |
164 | Md5Final (\r | |
165 | IN OUT VOID *Md5Context,\r | |
166 | OUT UINT8 *HashValue\r | |
167 | )\r | |
168 | {\r | |
169 | //\r | |
170 | // ASSERT if Md5Context is NULL or HashValue is NULL\r | |
171 | //\r | |
172 | ASSERT (Md5Context != NULL);\r | |
173 | ASSERT (HashValue != NULL);\r | |
174 | \r | |
175 | //\r | |
176 | // OpenSSL MD5 Hash Finalization\r | |
177 | //\r | |
178 | return (BOOLEAN) (MD5_Final (HashValue, (MD5_CTX *)Md5Context));\r | |
179 | }\r |