X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=CryptoPkg%2FLibrary%2FBaseCryptLib%2FHmac%2FCryptHmacMd5.c;fp=CryptoPkg%2FLibrary%2FBaseCryptLib%2FHmac%2FCryptHmacMd5.c;h=ff7b8e5466c79a978eb988191a1a54055485531b;hp=61750616c8638eb02550c78632a291b2ae99a1ee;hb=4c270243995a4cba33955f6dfaa8ee93748ff843;hpb=ec7ad9e10371a7fb500d8244402bb25d93c1a6db diff --git a/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacMd5.c b/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacMd5.c index 61750616c8..ff7b8e5466 100644 --- a/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacMd5.c +++ b/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacMd5.c @@ -1,7 +1,7 @@ /** @file HMAC-MD5 Wrapper Implementation over OpenSSL. -Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.
+Copyright (c) 2010 - 2017, Intel Corporation. All rights reserved.
This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at @@ -15,8 +15,13 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "InternalCryptLib.h" #include +#define HMAC_MD5_CTX_SIZE sizeof(void *) * 4 + sizeof(unsigned int) + \ + sizeof(unsigned char) * HMAC_MAX_MD_CBLOCK + /** Retrieves the size, in bytes, of the context buffer required for HMAC-MD5 operations. + (NOTE: This API is deprecated. + Use HmacMd5New() / HmacMd5Free() for HMAC-MD5 Context operations.) @return The size, in bytes, of the context buffer required for HMAC-MD5 operations. @@ -29,8 +34,49 @@ HmacMd5GetContextSize ( { // // Retrieves the OpenSSL HMAC-MD5 Context Size + // NOTE: HMAC_CTX object was made opaque in openssl-1.1.x, here we just use the + // fixed size as a workaround to make this API work for compatibility. + // We should retire HmacMd5GetContextSize() in future, and use HmacMd5New() + // and HmacMd5Free() for context allocation and release. // - return (UINTN) (sizeof (HMAC_CTX)); + return (UINTN) HMAC_MD5_CTX_SIZE; +} + +/** + Allocates and initializes one HMAC_CTX context for subsequent HMAC-MD5 use. + + @return Pointer to the HMAC_CTX context that has been initialized. + If the allocations fails, HmacMd5New() returns NULL. + +**/ +VOID * +EFIAPI +HmacMd5New ( + VOID + ) +{ + // + // Allocates & Initializes HMAC_CTX Context by OpenSSL HMAC_CTX_new() + // + return (VOID *) HMAC_CTX_new (); +} + +/** + Release the specified HMAC_CTX context. + + @param[in] HmacMd5Ctx Pointer to the HMAC_CTX context to be released. + +**/ +VOID +EFIAPI +HmacMd5Free ( + IN VOID *HmacMd5Ctx + ) +{ + // + // Free OpenSSL HMAC_CTX Context + // + HMAC_CTX_free ((HMAC_CTX *)HmacMd5Ctx); } /** @@ -65,8 +111,13 @@ HmacMd5Init ( // // OpenSSL HMAC-MD5 Context Initialization // - HMAC_CTX_init (HmacMd5Context); - HMAC_Init_ex (HmacMd5Context, Key, (UINT32) KeySize, EVP_md5(), NULL); + memset(HmacMd5Context, 0, HMAC_MD5_CTX_SIZE); + if (HMAC_CTX_reset ((HMAC_CTX *)HmacMd5Context) != 1) { + return FALSE; + } + if (HMAC_Init_ex ((HMAC_CTX *)HmacMd5Context, Key, (UINT32) KeySize, EVP_md5(), NULL) != 1) { + return FALSE; + } return TRUE; } @@ -97,8 +148,10 @@ HmacMd5Duplicate ( if (HmacMd5Context == NULL || NewHmacMd5Context == NULL) { return FALSE; } - - CopyMem (NewHmacMd5Context, HmacMd5Context, sizeof (HMAC_CTX)); + + if (HMAC_CTX_copy ((HMAC_CTX *)NewHmacMd5Context, (HMAC_CTX *)HmacMd5Context) != 1) { + return FALSE; + } return TRUE; } @@ -146,7 +199,9 @@ HmacMd5Update ( // // OpenSSL HMAC-MD5 digest update // - HMAC_Update (HmacMd5Context, Data, DataSize); + if (HMAC_Update ((HMAC_CTX *)HmacMd5Context, Data, DataSize) != 1) { + return FALSE; + } return TRUE; } @@ -190,8 +245,12 @@ HmacMd5Final ( // // OpenSSL HMAC-MD5 digest finalization // - HMAC_Final (HmacMd5Context, HmacValue, &Length); - HMAC_CTX_cleanup (HmacMd5Context); + if (HMAC_Final ((HMAC_CTX *)HmacMd5Context, HmacValue, &Length) != 1) { + return FALSE; + } + if (HMAC_CTX_reset ((HMAC_CTX *)HmacMd5Context) != 1) { + return FALSE; + } return TRUE; }