Changeset 85718 in vbox for trunk/src/VBox/Devices/EFI/FirmwareNew/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha256.c
- Timestamp:
- Aug 12, 2020 4:09:12 PM (4 years ago)
- Location:
- trunk/src/VBox/Devices/EFI/FirmwareNew
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Devices/EFI/FirmwareNew
-
Property svn:mergeinfo
changed from (toggle deleted branches)
to (toggle deleted branches)/vendor/edk2/current 103735-103757,103769-103776,129194-133213 /vendor/edk2/current 103735-103757,103769-103776,129194-139864
-
Property svn:mergeinfo
changed from (toggle deleted branches)
-
trunk/src/VBox/Devices/EFI/FirmwareNew/CryptoPkg/Library/BaseCryptLib/Hmac/CryptHmacSha256.c
r80721 r85718 2 2 HMAC-SHA256 Wrapper Implementation over OpenSSL. 3 3 4 Copyright (c) 2016 - 20 17, Intel Corporation. All rights reserved.<BR>4 Copyright (c) 2016 - 2020, Intel Corporation. All rights reserved.<BR> 5 5 SPDX-License-Identifier: BSD-2-Clause-Patent 6 6 … … 10 10 #include <openssl/hmac.h> 11 11 12 //13 // NOTE: OpenSSL redefines the size of HMAC_CTX at crypto/hmac/hmac_lcl.h14 // #define HMAC_MAX_MD_CBLOCK_SIZE 14415 //16 #define HMAC_SHA256_CTX_SIZE (sizeof(void *) * 4 + sizeof(unsigned int) + \17 sizeof(unsigned char) * 144)18 19 /**20 Retrieves the size, in bytes, of the context buffer required for HMAC-SHA256 operations.21 (NOTE: This API is deprecated.22 Use HmacSha256New() / HmacSha256Free() for HMAC-SHA256 Context operations.)23 24 @return The size, in bytes, of the context buffer required for HMAC-SHA256 operations.25 26 **/27 UINTN28 EFIAPI29 HmacSha256GetContextSize (30 VOID31 )32 {33 //34 // Retrieves the OpenSSL HMAC-SHA256 Context Size35 // NOTE: HMAC_CTX object was made opaque in openssl-1.1.x, here we just use the36 // fixed size as a workaround to make this API work for compatibility.37 // We should retire HmacSha256GetContextSize() in future, and use HmacSha256New()38 // and HmacSha256Free() for context allocation and release.39 //40 return (UINTN)HMAC_SHA256_CTX_SIZE;41 }42 43 12 /** 44 13 Allocates and initializes one HMAC_CTX context for subsequent HMAC-SHA256 use. … … 79 48 80 49 /** 81 Initializes user-supplied memory pointed by HmacSha256Context as HMAC-SHA256 context for82 subsequent use.83 84 If HmacSha256Context is NULL, then return FALSE. 85 86 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context being initialized.50 Set user-supplied key for subsequent use. It must be done before any 51 calling to HmacSha256Update(). 52 53 If HmacSha256Context is NULL, then return FALSE. 54 55 @param[out] HmacSha256Context Pointer to HMAC-SHA256 context. 87 56 @param[in] Key Pointer to the user-supplied key. 88 57 @param[in] KeySize Key size in bytes. 89 58 90 @retval TRUE HMAC-SHA256 context initialization succeeded.91 @retval FALSE HMAC-SHA256 context initialization failed.92 93 **/ 94 BOOLEAN 95 EFIAPI 96 HmacSha256 Init(59 @retval TRUE The Key is set successfully. 60 @retval FALSE The Key is set unsuccessfully. 61 62 **/ 63 BOOLEAN 64 EFIAPI 65 HmacSha256SetKey ( 97 66 OUT VOID *HmacSha256Context, 98 67 IN CONST UINT8 *Key, … … 107 76 } 108 77 109 //110 // OpenSSL HMAC-SHA256 Context Initialization111 //112 memset(HmacSha256Context, 0, HMAC_SHA256_CTX_SIZE);113 if (HMAC_CTX_reset ((HMAC_CTX *)HmacSha256Context) != 1) {114 return FALSE;115 }116 78 if (HMAC_Init_ex ((HMAC_CTX *)HmacSha256Context, Key, (UINT32) KeySize, EVP_sha256(), NULL) != 1) { 117 79 return FALSE; … … 160 122 This function performs HMAC-SHA256 digest on a data buffer of the specified size. 161 123 It can be called multiple times to compute the digest of long or discontinuous data streams. 162 HMAC-SHA256 context should be already correctly initialized by HmacSha256Init(), and should not163 b e finalized by HmacSha256Final(). Behavior with invalid context is undefined.124 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized 125 by HmacSha256Final(). Behavior with invalid context is undefined. 164 126 165 127 If HmacSha256Context is NULL, then return FALSE. … … 211 173 the specified memory. After this function has been called, the HMAC-SHA256 context cannot 212 174 be used again. 213 HMAC-SHA256 context should be already correctly initialized by HmacSha256Init(), and should214 not be finalizedby HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined.175 HMAC-SHA256 context should be initialized by HmacSha256New(), and should not be finalized 176 by HmacSha256Final(). Behavior with invalid HMAC-SHA256 context is undefined. 215 177 216 178 If HmacSha256Context is NULL, then return FALSE.
Note:
See TracChangeset
for help on using the changeset viewer.