1*3c5ca68bSWarner Losh /** @file 2*3c5ca68bSWarner Losh EFI_HASH2_SERVICE_BINDING_PROTOCOL as defined in UEFI 2.5. 3*3c5ca68bSWarner Losh EFI_HASH2_PROTOCOL as defined in UEFI 2.5. 4*3c5ca68bSWarner Losh The EFI Hash2 Service Binding Protocol is used to locate hashing services support 5*3c5ca68bSWarner Losh provided by a driver and to create and destroy instances of the EFI Hash2 Protocol 6*3c5ca68bSWarner Losh so that a multiple drivers can use the underlying hashing services. 7*3c5ca68bSWarner Losh EFI_HASH2_PROTOCOL describes hashing functions for which the algorithm-required 8*3c5ca68bSWarner Losh message padding and finalization are performed by the supporting driver. 9*3c5ca68bSWarner Losh 10*3c5ca68bSWarner Losh Copyright (c) 2015, Intel Corporation. All rights reserved.<BR> 11*3c5ca68bSWarner Losh SPDX-License-Identifier: BSD-2-Clause-Patent 12*3c5ca68bSWarner Losh 13*3c5ca68bSWarner Losh **/ 14*3c5ca68bSWarner Losh 15*3c5ca68bSWarner Losh #ifndef __EFI_HASH2_PROTOCOL_H__ 16*3c5ca68bSWarner Losh #define __EFI_HASH2_PROTOCOL_H__ 17*3c5ca68bSWarner Losh 18*3c5ca68bSWarner Losh #define EFI_HASH2_SERVICE_BINDING_PROTOCOL_GUID \ 19*3c5ca68bSWarner Losh { \ 20*3c5ca68bSWarner Losh 0xda836f8d, 0x217f, 0x4ca0, { 0x99, 0xc2, 0x1c, 0xa4, 0xe1, 0x60, 0x77, 0xea } \ 21*3c5ca68bSWarner Losh } 22*3c5ca68bSWarner Losh 23*3c5ca68bSWarner Losh #define EFI_HASH2_PROTOCOL_GUID \ 24*3c5ca68bSWarner Losh { \ 25*3c5ca68bSWarner Losh 0x55b1d734, 0xc5e1, 0x49db, { 0x96, 0x47, 0xb1, 0x6a, 0xfb, 0xe, 0x30, 0x5b } \ 26*3c5ca68bSWarner Losh } 27*3c5ca68bSWarner Losh 28*3c5ca68bSWarner Losh #include <Protocol/Hash.h> 29*3c5ca68bSWarner Losh 30*3c5ca68bSWarner Losh // 31*3c5ca68bSWarner Losh // NOTE: 32*3c5ca68bSWarner Losh // Algorithms EFI_HASH_ALGORITHM_SHA1_NOPAD and 33*3c5ca68bSWarner Losh // EFI_HASH_ALGORITHM_SHA256_NOPAD_GUID are not compatible with 34*3c5ca68bSWarner Losh // EFI_HASH2_PROTOCOL and will return EFI_UNSUPPORTED if used with any 35*3c5ca68bSWarner Losh // EFI_HASH2_PROTOCOL function. 36*3c5ca68bSWarner Losh // 37*3c5ca68bSWarner Losh 38*3c5ca68bSWarner Losh // 39*3c5ca68bSWarner Losh // Note: SHA-1 and MD5 are included for backwards compatibility. 40*3c5ca68bSWarner Losh // New driver implementations are encouraged to consider stronger algorithms. 41*3c5ca68bSWarner Losh // 42*3c5ca68bSWarner Losh 43*3c5ca68bSWarner Losh typedef struct _EFI_HASH2_PROTOCOL EFI_HASH2_PROTOCOL; 44*3c5ca68bSWarner Losh 45*3c5ca68bSWarner Losh typedef UINT8 EFI_MD5_HASH2[16]; 46*3c5ca68bSWarner Losh typedef UINT8 EFI_SHA1_HASH2[20]; 47*3c5ca68bSWarner Losh typedef UINT8 EFI_SHA224_HASH2[28]; 48*3c5ca68bSWarner Losh typedef UINT8 EFI_SHA256_HASH2[32]; 49*3c5ca68bSWarner Losh typedef UINT8 EFI_SHA384_HASH2[48]; 50*3c5ca68bSWarner Losh typedef UINT8 EFI_SHA512_HASH2[64]; 51*3c5ca68bSWarner Losh 52*3c5ca68bSWarner Losh typedef union { 53*3c5ca68bSWarner Losh EFI_MD5_HASH2 Md5Hash; 54*3c5ca68bSWarner Losh EFI_SHA1_HASH2 Sha1Hash; 55*3c5ca68bSWarner Losh EFI_SHA224_HASH2 Sha224Hash; 56*3c5ca68bSWarner Losh EFI_SHA256_HASH2 Sha256Hash; 57*3c5ca68bSWarner Losh EFI_SHA384_HASH2 Sha384Hash; 58*3c5ca68bSWarner Losh EFI_SHA512_HASH2 Sha512Hash; 59*3c5ca68bSWarner Losh } EFI_HASH2_OUTPUT; 60*3c5ca68bSWarner Losh 61*3c5ca68bSWarner Losh /** 62*3c5ca68bSWarner Losh Returns the size of the hash which results from a specific algorithm. 63*3c5ca68bSWarner Losh 64*3c5ca68bSWarner Losh @param[in] This Points to this instance of EFI_HASH2_PROTOCOL. 65*3c5ca68bSWarner Losh @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use. 66*3c5ca68bSWarner Losh @param[out] HashSize Holds the returned size of the algorithm's hash. 67*3c5ca68bSWarner Losh 68*3c5ca68bSWarner Losh @retval EFI_SUCCESS Hash size returned successfully. 69*3c5ca68bSWarner Losh @retval EFI_INVALID_PARAMETER This or HashSize is NULL. 70*3c5ca68bSWarner Losh @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this driver 71*3c5ca68bSWarner Losh or HashAlgorithm is null. 72*3c5ca68bSWarner Losh 73*3c5ca68bSWarner Losh **/ 74*3c5ca68bSWarner Losh typedef 75*3c5ca68bSWarner Losh EFI_STATUS 76*3c5ca68bSWarner Losh (EFIAPI *EFI_HASH2_GET_HASH_SIZE)( 77*3c5ca68bSWarner Losh IN CONST EFI_HASH2_PROTOCOL *This, 78*3c5ca68bSWarner Losh IN CONST EFI_GUID *HashAlgorithm, 79*3c5ca68bSWarner Losh OUT UINTN *HashSize 80*3c5ca68bSWarner Losh ); 81*3c5ca68bSWarner Losh 82*3c5ca68bSWarner Losh /** 83*3c5ca68bSWarner Losh Creates a hash for the specified message text. The hash is not extendable. 84*3c5ca68bSWarner Losh The output is final with any algorithm-required padding added by the function. 85*3c5ca68bSWarner Losh 86*3c5ca68bSWarner Losh @param[in] This Points to this instance of EFI_HASH2_PROTOCOL. 87*3c5ca68bSWarner Losh @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use. 88*3c5ca68bSWarner Losh @param[in] Message Points to the start of the message. 89*3c5ca68bSWarner Losh @param[in] MessageSize The size of Message, in bytes. 90*3c5ca68bSWarner Losh @param[in,out] Hash On input, points to a caller-allocated buffer of the size 91*3c5ca68bSWarner Losh returned by GetHashSize() for the specified HashAlgorithm. 92*3c5ca68bSWarner Losh On output, the buffer holds the resulting hash computed from the message. 93*3c5ca68bSWarner Losh 94*3c5ca68bSWarner Losh @retval EFI_SUCCESS Hash returned successfully. 95*3c5ca68bSWarner Losh @retval EFI_INVALID_PARAMETER This or Hash is NULL. 96*3c5ca68bSWarner Losh @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this driver 97*3c5ca68bSWarner Losh or HashAlgorithm is Null. 98*3c5ca68bSWarner Losh @retval EFI_OUT_OF_RESOURCES Some resource required by the function is not available 99*3c5ca68bSWarner Losh or MessageSize is greater than platform maximum. 100*3c5ca68bSWarner Losh 101*3c5ca68bSWarner Losh **/ 102*3c5ca68bSWarner Losh typedef 103*3c5ca68bSWarner Losh EFI_STATUS 104*3c5ca68bSWarner Losh (EFIAPI *EFI_HASH2_HASH)( 105*3c5ca68bSWarner Losh IN CONST EFI_HASH2_PROTOCOL *This, 106*3c5ca68bSWarner Losh IN CONST EFI_GUID *HashAlgorithm, 107*3c5ca68bSWarner Losh IN CONST UINT8 *Message, 108*3c5ca68bSWarner Losh IN UINTN MessageSize, 109*3c5ca68bSWarner Losh IN OUT EFI_HASH2_OUTPUT *Hash 110*3c5ca68bSWarner Losh ); 111*3c5ca68bSWarner Losh 112*3c5ca68bSWarner Losh /** 113*3c5ca68bSWarner Losh This function must be called to initialize a digest calculation to be subsequently performed using the 114*3c5ca68bSWarner Losh EFI_HASH2_PROTOCOL functions HashUpdate() and HashFinal(). 115*3c5ca68bSWarner Losh 116*3c5ca68bSWarner Losh @param[in] This Points to this instance of EFI_HASH2_PROTOCOL. 117*3c5ca68bSWarner Losh @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use. 118*3c5ca68bSWarner Losh 119*3c5ca68bSWarner Losh @retval EFI_SUCCESS Initialized successfully. 120*3c5ca68bSWarner Losh @retval EFI_INVALID_PARAMETER This is NULL. 121*3c5ca68bSWarner Losh @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this driver 122*3c5ca68bSWarner Losh or HashAlgorithm is Null. 123*3c5ca68bSWarner Losh @retval EFI_OUT_OF_RESOURCES Process failed due to lack of required resource. 124*3c5ca68bSWarner Losh @retval EFI_ALREADY_STARTED This function is called when the operation in progress is still in processing Hash(), 125*3c5ca68bSWarner Losh or HashInit() is already called before and not terminated by HashFinal() yet on the same instance. 126*3c5ca68bSWarner Losh 127*3c5ca68bSWarner Losh **/ 128*3c5ca68bSWarner Losh typedef 129*3c5ca68bSWarner Losh EFI_STATUS 130*3c5ca68bSWarner Losh (EFIAPI *EFI_HASH2_HASH_INIT)( 131*3c5ca68bSWarner Losh IN CONST EFI_HASH2_PROTOCOL *This, 132*3c5ca68bSWarner Losh IN CONST EFI_GUID *HashAlgorithm 133*3c5ca68bSWarner Losh ); 134*3c5ca68bSWarner Losh 135*3c5ca68bSWarner Losh /** 136*3c5ca68bSWarner Losh Updates the hash of a computation in progress by adding a message text. 137*3c5ca68bSWarner Losh 138*3c5ca68bSWarner Losh @param[in] This Points to this instance of EFI_HASH2_PROTOCOL. 139*3c5ca68bSWarner Losh @param[in] Message Points to the start of the message. 140*3c5ca68bSWarner Losh @param[in] MessageSize The size of Message, in bytes. 141*3c5ca68bSWarner Losh 142*3c5ca68bSWarner Losh @retval EFI_SUCCESS Digest in progress updated successfully. 143*3c5ca68bSWarner Losh @retval EFI_INVALID_PARAMETER This or Hash is NULL. 144*3c5ca68bSWarner Losh @retval EFI_OUT_OF_RESOURCES Some resource required by the function is not available 145*3c5ca68bSWarner Losh or MessageSize is greater than platform maximum. 146*3c5ca68bSWarner Losh @retval EFI_NOT_READY This call was not preceded by a valid call to HashInit(), 147*3c5ca68bSWarner Losh or the operation in progress was terminated by a call to Hash() or HashFinal() on the same instance. 148*3c5ca68bSWarner Losh 149*3c5ca68bSWarner Losh **/ 150*3c5ca68bSWarner Losh typedef 151*3c5ca68bSWarner Losh EFI_STATUS 152*3c5ca68bSWarner Losh (EFIAPI *EFI_HASH2_HASH_UPDATE)( 153*3c5ca68bSWarner Losh IN CONST EFI_HASH2_PROTOCOL *This, 154*3c5ca68bSWarner Losh IN CONST UINT8 *Message, 155*3c5ca68bSWarner Losh IN UINTN MessageSize 156*3c5ca68bSWarner Losh ); 157*3c5ca68bSWarner Losh 158*3c5ca68bSWarner Losh /** 159*3c5ca68bSWarner Losh Finalizes a hash operation in progress and returns calculation result. 160*3c5ca68bSWarner Losh The output is final with any necessary padding added by the function. 161*3c5ca68bSWarner Losh The hash may not be further updated or extended after HashFinal(). 162*3c5ca68bSWarner Losh 163*3c5ca68bSWarner Losh @param[in] This Points to this instance of EFI_HASH2_PROTOCOL. 164*3c5ca68bSWarner Losh @param[in,out] Hash On input, points to a caller-allocated buffer of the size 165*3c5ca68bSWarner Losh returned by GetHashSize() for the specified HashAlgorithm specified in preceding HashInit(). 166*3c5ca68bSWarner Losh On output, the buffer holds the resulting hash computed from the message. 167*3c5ca68bSWarner Losh 168*3c5ca68bSWarner Losh @retval EFI_SUCCESS Hash returned successfully. 169*3c5ca68bSWarner Losh @retval EFI_INVALID_PARAMETER This or Hash is NULL. 170*3c5ca68bSWarner Losh @retval EFI_NOT_READY This call was not preceded by a valid call to HashInit() and at least one call to HashUpdate(), 171*3c5ca68bSWarner Losh or the operation in progress was canceled by a call to Hash() on the same instance. 172*3c5ca68bSWarner Losh 173*3c5ca68bSWarner Losh **/ 174*3c5ca68bSWarner Losh typedef 175*3c5ca68bSWarner Losh EFI_STATUS 176*3c5ca68bSWarner Losh (EFIAPI *EFI_HASH2_HASH_FINAL)( 177*3c5ca68bSWarner Losh IN CONST EFI_HASH2_PROTOCOL *This, 178*3c5ca68bSWarner Losh IN OUT EFI_HASH2_OUTPUT *Hash 179*3c5ca68bSWarner Losh ); 180*3c5ca68bSWarner Losh 181*3c5ca68bSWarner Losh /// 182*3c5ca68bSWarner Losh /// This protocol describes hashing functions for which the algorithm-required message padding and 183*3c5ca68bSWarner Losh /// finalization are performed by the supporting driver. 184*3c5ca68bSWarner Losh /// 185*3c5ca68bSWarner Losh struct _EFI_HASH2_PROTOCOL { 186*3c5ca68bSWarner Losh EFI_HASH2_GET_HASH_SIZE GetHashSize; 187*3c5ca68bSWarner Losh EFI_HASH2_HASH Hash; 188*3c5ca68bSWarner Losh EFI_HASH2_HASH_INIT HashInit; 189*3c5ca68bSWarner Losh EFI_HASH2_HASH_UPDATE HashUpdate; 190*3c5ca68bSWarner Losh EFI_HASH2_HASH_FINAL HashFinal; 191*3c5ca68bSWarner Losh }; 192*3c5ca68bSWarner Losh 193*3c5ca68bSWarner Losh extern EFI_GUID gEfiHash2ServiceBindingProtocolGuid; 194*3c5ca68bSWarner Losh extern EFI_GUID gEfiHash2ProtocolGuid; 195*3c5ca68bSWarner Losh 196*3c5ca68bSWarner Losh #endif 197