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