Path: blob/main/sys/contrib/edk2/Include/Protocol/Hash2.h
96339 views
/** @file1EFI_HASH2_SERVICE_BINDING_PROTOCOL as defined in UEFI 2.5.2EFI_HASH2_PROTOCOL as defined in UEFI 2.5.3The EFI Hash2 Service Binding Protocol is used to locate hashing services support4provided by a driver and to create and destroy instances of the EFI Hash2 Protocol5so that a multiple drivers can use the underlying hashing services.6EFI_HASH2_PROTOCOL describes hashing functions for which the algorithm-required7message padding and finalization are performed by the supporting driver.89Copyright (c) 2015, Intel Corporation. All rights reserved.<BR>10SPDX-License-Identifier: BSD-2-Clause-Patent1112**/1314#ifndef __EFI_HASH2_PROTOCOL_H__15#define __EFI_HASH2_PROTOCOL_H__1617#define EFI_HASH2_SERVICE_BINDING_PROTOCOL_GUID \18{ \190xda836f8d, 0x217f, 0x4ca0, { 0x99, 0xc2, 0x1c, 0xa4, 0xe1, 0x60, 0x77, 0xea } \20}2122#define EFI_HASH2_PROTOCOL_GUID \23{ \240x55b1d734, 0xc5e1, 0x49db, { 0x96, 0x47, 0xb1, 0x6a, 0xfb, 0xe, 0x30, 0x5b } \25}2627#include <Protocol/Hash.h>2829//30// NOTE:31// Algorithms EFI_HASH_ALGORITHM_SHA1_NOPAD and32// EFI_HASH_ALGORITHM_SHA256_NOPAD_GUID are not compatible with33// EFI_HASH2_PROTOCOL and will return EFI_UNSUPPORTED if used with any34// EFI_HASH2_PROTOCOL function.35//3637//38// Note: SHA-1 and MD5 are included for backwards compatibility.39// New driver implementations are encouraged to consider stronger algorithms.40//4142typedef struct _EFI_HASH2_PROTOCOL EFI_HASH2_PROTOCOL;4344typedef UINT8 EFI_MD5_HASH2[16];45typedef UINT8 EFI_SHA1_HASH2[20];46typedef UINT8 EFI_SHA224_HASH2[28];47typedef UINT8 EFI_SHA256_HASH2[32];48typedef UINT8 EFI_SHA384_HASH2[48];49typedef UINT8 EFI_SHA512_HASH2[64];5051typedef union {52EFI_MD5_HASH2 Md5Hash;53EFI_SHA1_HASH2 Sha1Hash;54EFI_SHA224_HASH2 Sha224Hash;55EFI_SHA256_HASH2 Sha256Hash;56EFI_SHA384_HASH2 Sha384Hash;57EFI_SHA512_HASH2 Sha512Hash;58} EFI_HASH2_OUTPUT;5960/**61Returns the size of the hash which results from a specific algorithm.6263@param[in] This Points to this instance of EFI_HASH2_PROTOCOL.64@param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use.65@param[out] HashSize Holds the returned size of the algorithm's hash.6667@retval EFI_SUCCESS Hash size returned successfully.68@retval EFI_INVALID_PARAMETER This or HashSize is NULL.69@retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this driver70or HashAlgorithm is null.7172**/73typedef74EFI_STATUS75(EFIAPI *EFI_HASH2_GET_HASH_SIZE)(76IN CONST EFI_HASH2_PROTOCOL *This,77IN CONST EFI_GUID *HashAlgorithm,78OUT UINTN *HashSize79);8081/**82Creates a hash for the specified message text. The hash is not extendable.83The output is final with any algorithm-required padding added by the function.8485@param[in] This Points to this instance of EFI_HASH2_PROTOCOL.86@param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use.87@param[in] Message Points to the start of the message.88@param[in] MessageSize The size of Message, in bytes.89@param[in,out] Hash On input, points to a caller-allocated buffer of the size90returned by GetHashSize() for the specified HashAlgorithm.91On output, the buffer holds the resulting hash computed from the message.9293@retval EFI_SUCCESS Hash returned successfully.94@retval EFI_INVALID_PARAMETER This or Hash is NULL.95@retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this driver96or HashAlgorithm is Null.97@retval EFI_OUT_OF_RESOURCES Some resource required by the function is not available98or MessageSize is greater than platform maximum.99100**/101typedef102EFI_STATUS103(EFIAPI *EFI_HASH2_HASH)(104IN CONST EFI_HASH2_PROTOCOL *This,105IN CONST EFI_GUID *HashAlgorithm,106IN CONST UINT8 *Message,107IN UINTN MessageSize,108IN OUT EFI_HASH2_OUTPUT *Hash109);110111/**112This function must be called to initialize a digest calculation to be subsequently performed using the113EFI_HASH2_PROTOCOL functions HashUpdate() and HashFinal().114115@param[in] This Points to this instance of EFI_HASH2_PROTOCOL.116@param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use.117118@retval EFI_SUCCESS Initialized successfully.119@retval EFI_INVALID_PARAMETER This is NULL.120@retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this driver121or HashAlgorithm is Null.122@retval EFI_OUT_OF_RESOURCES Process failed due to lack of required resource.123@retval EFI_ALREADY_STARTED This function is called when the operation in progress is still in processing Hash(),124or HashInit() is already called before and not terminated by HashFinal() yet on the same instance.125126**/127typedef128EFI_STATUS129(EFIAPI *EFI_HASH2_HASH_INIT)(130IN CONST EFI_HASH2_PROTOCOL *This,131IN CONST EFI_GUID *HashAlgorithm132);133134/**135Updates the hash of a computation in progress by adding a message text.136137@param[in] This Points to this instance of EFI_HASH2_PROTOCOL.138@param[in] Message Points to the start of the message.139@param[in] MessageSize The size of Message, in bytes.140141@retval EFI_SUCCESS Digest in progress updated successfully.142@retval EFI_INVALID_PARAMETER This or Hash is NULL.143@retval EFI_OUT_OF_RESOURCES Some resource required by the function is not available144or MessageSize is greater than platform maximum.145@retval EFI_NOT_READY This call was not preceded by a valid call to HashInit(),146or the operation in progress was terminated by a call to Hash() or HashFinal() on the same instance.147148**/149typedef150EFI_STATUS151(EFIAPI *EFI_HASH2_HASH_UPDATE)(152IN CONST EFI_HASH2_PROTOCOL *This,153IN CONST UINT8 *Message,154IN UINTN MessageSize155);156157/**158Finalizes a hash operation in progress and returns calculation result.159The output is final with any necessary padding added by the function.160The hash may not be further updated or extended after HashFinal().161162@param[in] This Points to this instance of EFI_HASH2_PROTOCOL.163@param[in,out] Hash On input, points to a caller-allocated buffer of the size164returned by GetHashSize() for the specified HashAlgorithm specified in preceding HashInit().165On output, the buffer holds the resulting hash computed from the message.166167@retval EFI_SUCCESS Hash returned successfully.168@retval EFI_INVALID_PARAMETER This or Hash is NULL.169@retval EFI_NOT_READY This call was not preceded by a valid call to HashInit() and at least one call to HashUpdate(),170or the operation in progress was canceled by a call to Hash() on the same instance.171172**/173typedef174EFI_STATUS175(EFIAPI *EFI_HASH2_HASH_FINAL)(176IN CONST EFI_HASH2_PROTOCOL *This,177IN OUT EFI_HASH2_OUTPUT *Hash178);179180///181/// This protocol describes hashing functions for which the algorithm-required message padding and182/// finalization are performed by the supporting driver.183///184struct _EFI_HASH2_PROTOCOL {185EFI_HASH2_GET_HASH_SIZE GetHashSize;186EFI_HASH2_HASH Hash;187EFI_HASH2_HASH_INIT HashInit;188EFI_HASH2_HASH_UPDATE HashUpdate;189EFI_HASH2_HASH_FINAL HashFinal;190};191192extern EFI_GUID gEfiHash2ServiceBindingProtocolGuid;193extern EFI_GUID gEfiHash2ProtocolGuid;194195#endif196197198