1 /** 2 Based on Protocol/Hash2.h, original notice: 3 4 EFI_HASH2_SERVICE_BINDING_PROTOCOL as defined in UEFI 2.5. 5 EFI_HASH2_PROTOCOL as defined in UEFI 2.5. 6 The EFI Hash2 Service Binding Protocol is used to locate hashing services support 7 provided by a driver and to create and destroy instances of the EFI Hash2 Protocol 8 so that a multiple drivers can use the underlying hashing services. 9 EFI_HASH2_PROTOCOL describes hashing functions for which the algorithm-required 10 message padding and finalization are performed by the supporting driver. 11 12 Copyright (c) 2015, Intel Corporation. All rights reserved. 13 This program and the accompanying materials are licensed and made available under 14 the terms and conditions of the BSD License that accompanies this distribution. 15 The full text of the license may be found at 16 http://opensource.org/licenses/bsd-license.php. 17 18 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, 19 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. 20 21 **/ 22 module uefi.protocols.hash2; 23 import uefi.base; 24 import uefi.base_type; 25 import uefi.protocols.hash; 26 27 public: 28 extern (C): 29 enum EFI_GUID EFI_HASH2_SERVICE_BINDING_PROTOCOL_GUID = EFI_GUID(0xda836f8d, 30 0x217f, 0x4ca0, [0x99, 0xc2, 0x1c, 0xa4, 0xe1, 0x60, 0x77, 0xea]); 31 enum EFI_GUID EFI_HASH2_PROTOCOL_GUID = EFI_GUID(0x55b1d734, 0xc5e1, 0x49db, 32 [0x96, 0x47, 0xb1, 0x6a, 0xfb, 0xe, 0x30, 0x5b]); 33 34 alias EFI_HASH2_PROTOCOL = _EFI_HASH2_PROTOCOL; 35 alias EFI_MD5_HASH2 = UINT8[16]; 36 alias EFI_SHA1_HASH2 = UINT8[20]; 37 alias EFI_SHA224_HASH2 = UINT8[28]; 38 alias EFI_SHA256_HASH2 = UINT8[32]; 39 alias EFI_SHA384_HASH2 = UINT8[48]; 40 alias EFI_SHA512_HASH2 = UINT8[64]; 41 union EFI_HASH2_OUTPUT 42 { 43 EFI_MD5_HASH2 Md5Hash; 44 EFI_SHA1_HASH2 Sha1Hash; 45 EFI_SHA224_HASH2 Sha224Hash; 46 EFI_SHA256_HASH2 Sha256Hash; 47 EFI_SHA384_HASH2 Sha384Hash; 48 EFI_SHA512_HASH2 Sha512Hash; 49 } 50 /** 51 Returns the size of the hash which results from a specific algorithm. 52 53 @param[in] This Points to this instance of EFI_HASH2_PROTOCOL. 54 @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use. 55 @param[out] HashSize Holds the returned size of the algorithm's hash. 56 57 @retval EFI_SUCCESS Hash size returned successfully. 58 @retval EFI_INVALID_PARAMETER This or HashSize is NULL. 59 @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this driver 60 or HashAlgorithm is null. 61 62 **/ 63 alias EFI_HASH2_GET_HASH_SIZE = EFI_STATUS function(const EFI_HASH2_PROTOCOL* This, 64 const EFI_GUID* HashAlgorithm, UINTN* HashSize) @nogc nothrow; 65 /** 66 Creates a hash for the specified message text. The hash is not extendable. 67 The output is final with any algorithm-required padding added by the function. 68 69 @param[in] This Points to this instance of EFI_HASH2_PROTOCOL. 70 @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use. 71 @param[in] Message Points to the start of the message. 72 @param[in] MessageSize The size of Message, in bytes. 73 @param[in,out] Hash On input, points to a caller-allocated buffer of the size 74 returned by GetHashSize() for the specified HashAlgorithm. 75 On output, the buffer holds the resulting hash computed from the message. 76 77 @retval EFI_SUCCESS Hash returned successfully. 78 @retval EFI_INVALID_PARAMETER This or Hash is NULL. 79 @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this driver 80 or HashAlgorithm is Null. 81 @retval EFI_OUT_OF_RESOURCES Some resource required by the function is not available 82 or MessageSize is greater than platform maximum. 83 84 **/ 85 alias EFI_HASH2_HASH = EFI_STATUS function(const EFI_HASH2_PROTOCOL* This, 86 const EFI_GUID* HashAlgorithm, const UINT8* Message, UINTN MessageSize, EFI_HASH2_OUTPUT* Hash) @nogc nothrow; 87 /** 88 This function must be called to initialize a digest calculation to be subsequently performed using the 89 EFI_HASH2_PROTOCOL functions HashUpdate() and HashFinal(). 90 91 @param[in] This Points to this instance of EFI_HASH2_PROTOCOL. 92 @param[in] HashAlgorithm Points to the EFI_GUID which identifies the algorithm to use. 93 94 @retval EFI_SUCCESS Initialized successfully. 95 @retval EFI_INVALID_PARAMETER This is NULL. 96 @retval EFI_UNSUPPORTED The algorithm specified by HashAlgorithm is not supported by this driver 97 or HashAlgorithm is Null. 98 @retval EFI_OUT_OF_RESOURCES Process failed due to lack of required resource. 99 @retval EFI_ALREADY_STARTED This function is called when the operation in progress is still in processing Hash(), 100 or HashInit() is already called before and not terminated by HashFinal() yet on the same instance. 101 102 **/ 103 alias EFI_HASH2_HASH_INIT = EFI_STATUS function(const EFI_HASH2_PROTOCOL* This, 104 const EFI_GUID* HashAlgorithm) @nogc nothrow; 105 /** 106 Updates the hash of a computation in progress by adding a message text. 107 108 @param[in] This Points to this instance of EFI_HASH2_PROTOCOL. 109 @param[in] Message Points to the start of the message. 110 @param[in] MessageSize The size of Message, in bytes. 111 112 @retval EFI_SUCCESS Digest in progress updated successfully. 113 @retval EFI_INVALID_PARAMETER This or Hash is NULL. 114 @retval EFI_OUT_OF_RESOURCES Some resource required by the function is not available 115 or MessageSize is greater than platform maximum. 116 @retval EFI_NOT_READY This call was not preceded by a valid call to HashInit(), 117 or the operation in progress was terminated by a call to Hash() or HashFinal() on the same instance. 118 119 **/ 120 alias EFI_HASH2_HASH_UPDATE = EFI_STATUS function(const EFI_HASH2_PROTOCOL* This, 121 const UINT8* Message, UINTN MessageSize) @nogc nothrow; 122 /** 123 Finalizes a hash operation in progress and returns calculation result. 124 The output is final with any necessary padding added by the function. 125 The hash may not be further updated or extended after HashFinal(). 126 127 @param[in] This Points to this instance of EFI_HASH2_PROTOCOL. 128 @param[in,out] Hash On input, points to a caller-allocated buffer of the size 129 returned by GetHashSize() for the specified HashAlgorithm specified in preceding HashInit(). 130 On output, the buffer holds the resulting hash computed from the message. 131 132 @retval EFI_SUCCESS Hash returned successfully. 133 @retval EFI_INVALID_PARAMETER This or Hash is NULL. 134 @retval EFI_NOT_READY This call was not preceded by a valid call to HashInit() and at least one call to HashUpdate(), 135 or the operation in progress was canceled by a call to Hash() on the same instance. 136 137 **/ 138 alias EFI_HASH2_HASH_FINAL = EFI_STATUS function(const EFI_HASH2_PROTOCOL* This, 139 EFI_HASH2_OUTPUT* Hash) @nogc nothrow; 140 /// This protocol describes hashing functions for which the algorithm-required message padding and 141 /// finalization are performed by the supporting driver. 142 struct _EFI_HASH2_PROTOCOL 143 { 144 EFI_HASH2_GET_HASH_SIZE GetHashSize; 145 EFI_HASH2_HASH Hash; 146 EFI_HASH2_HASH_INIT HashInit; 147 EFI_HASH2_HASH_UPDATE HashUpdate; 148 EFI_HASH2_HASH_FINAL HashFinal; 149 150 }