2 HMAC-MD5 Wrapper Implementation over OpenSSL.
4 Copyright (c) 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
15 #include "InternalCryptLib.h"
16 #include <openssl/hmac.h>
19 Retrieves the size, in bytes, of the context buffer required for HMAC-MD5 operations.
21 @return The size, in bytes, of the context buffer required for HMAC-MD5 operations.
26 HmacMd5GetContextSize (
31 // Retrieves the OpenSSL HMAC-MD5 Context Size
33 return (UINTN
)(sizeof (HMAC_CTX
));
37 Initializes user-supplied memory pointed by HmacMd5Context as HMAC-MD5 context for
40 If HmacMd5Context is NULL, then ASSERT().
42 @param[out] HmacMd5Context Pointer to HMAC-MD5 context being initialized.
43 @param[in] Key Pointer to the user-supplied key.
44 @param[in] KeySize Key size in bytes.
46 @retval TRUE HMAC-MD5 context initialization succeeded.
47 @retval FALSE HMAC-MD5 context initialization failed.
53 OUT VOID
*HmacMd5Context
,
59 // ASSERT if HmacMd5Context is NULL.
61 ASSERT (HmacMd5Context
!= NULL
);
64 // OpenSSL HMAC-MD5 Context Initialization
66 HMAC_CTX_init (HmacMd5Context
);
67 HMAC_Init_ex (HmacMd5Context
, Key
, (UINT32
) KeySize
, EVP_md5(), NULL
);
73 Makes a copy of an existing HMAC-MD5 context.
75 If HmacMd5Context is NULL, then ASSERT().
76 If NewHmacMd5Context is NULL, then ASSERT().
78 @param[in] HmacMd5Context Pointer to HMAC-MD5 context being copied.
79 @param[out] NewHmacMd5Context Pointer to new HMAC-MD5 context.
81 @retval TRUE HMAC-MD5 context copy succeeded.
82 @retval FALSE HMAC-MD5 context copy failed.
88 IN CONST VOID
*HmacMd5Context
,
89 OUT VOID
*NewHmacMd5Context
93 // ASSERT if HmacMd5Context or NewHmacMd5Context is NULL.
95 ASSERT (HmacMd5Context
!= NULL
);
96 ASSERT (NewHmacMd5Context
!= NULL
);
98 CopyMem (NewHmacMd5Context
, HmacMd5Context
, sizeof (HMAC_CTX
));
104 Digests the input data and updates HMAC-MD5 context.
106 This function performs HMAC-MD5 digest on a data buffer of the specified size.
107 It can be called multiple times to compute the digest of long or discontinuous data streams.
108 HMAC-MD5 context should be already correctly intialized by HmacMd5Init(), and should not be
109 finalized by HmacMd5Final(). Behavior with invalid context is undefined.
111 If HmacMd5Context is NULL, then ASSERT().
113 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
114 @param[in] Data Pointer to the buffer containing the data to be digested.
115 @param[in] DataSize Size of Data buffer in bytes.
117 @retval TRUE HMAC-MD5 data digest succeeded.
118 @retval FALSE HMAC-MD5 data digest failed.
124 IN OUT VOID
*HmacMd5Context
,
130 // ASSERT if HmacMd5Context is NULL
132 ASSERT (HmacMd5Context
!= NULL
);
135 // ASSERT if invalid parameters, in case that only DataLength was checked in OpenSSL
138 ASSERT (DataSize
== 0);
142 // OpenSSL HMAC-MD5 digest update
144 HMAC_Update (HmacMd5Context
, Data
, DataSize
);
150 Completes computation of the HMAC-MD5 digest value.
152 This function completes HMAC-MD5 digest computation and retrieves the digest value into
153 the specified memory. After this function has been called, the HMAC-MD5 context cannot
155 HMAC-MD5 context should be already correctly intialized by HmacMd5Init(), and should not be
156 finalized by HmacMd5Final(). Behavior with invalid HMAC-MD5 context is undefined.
158 If HmacMd5Context is NULL, then ASSERT().
159 If HmacValue is NULL, then ASSERT().
161 @param[in, out] HmacMd5Context Pointer to the HMAC-MD5 context.
162 @param[out] HmacValue Pointer to a buffer that receives the HMAC-MD5 digest
165 @retval TRUE HMAC-MD5 digest computation succeeded.
166 @retval FALSE HMAC-MD5 digest computation failed.
172 IN OUT VOID
*HmacMd5Context
,
179 // ASSERT if HmacMd5Context is NULL or HmacValue is NULL
181 ASSERT (HmacMd5Context
!= NULL
);
182 ASSERT (HmacValue
!= NULL
);
185 // OpenSSL HMAC-MD5 digest finalization
187 HMAC_Final (HmacMd5Context
, HmacValue
, &Length
);
188 HMAC_CTX_cleanup (HmacMd5Context
);