TianoCore EDK2 master
Loading...
Searching...
No Matches
CryptSha256.c
Go to the documentation of this file.
1
9#include "InternalCryptLib.h"
10#include <openssl/sha.h>
11
19EFIAPI
21 VOID
22 )
23{
24 //
25 // Retrieves OpenSSL SHA-256 Context Size
26 //
27 return (UINTN)(sizeof (SHA256_CTX));
28}
29
42BOOLEAN
43EFIAPI
45 OUT VOID *Sha256Context
46 )
47{
48 //
49 // Check input parameters.
50 //
51 if (Sha256Context == NULL) {
52 return FALSE;
53 }
54
55 //
56 // OpenSSL SHA-256 Context Initialization
57 //
58 return (BOOLEAN)(SHA256_Init ((SHA256_CTX *)Sha256Context));
59}
60
74BOOLEAN
75EFIAPI
77 IN CONST VOID *Sha256Context,
78 OUT VOID *NewSha256Context
79 )
80{
81 //
82 // Check input parameters.
83 //
84 if ((Sha256Context == NULL) || (NewSha256Context == NULL)) {
85 return FALSE;
86 }
87
88 CopyMem (NewSha256Context, Sha256Context, sizeof (SHA256_CTX));
89
90 return TRUE;
91}
92
111BOOLEAN
112EFIAPI
114 IN OUT VOID *Sha256Context,
115 IN CONST VOID *Data,
116 IN UINTN DataSize
117 )
118{
119 //
120 // Check input parameters.
121 //
122 if (Sha256Context == NULL) {
123 return FALSE;
124 }
125
126 //
127 // Check invalid parameters, in case that only DataLength was checked in OpenSSL
128 //
129 if ((Data == NULL) && (DataSize != 0)) {
130 return FALSE;
131 }
132
133 //
134 // OpenSSL SHA-256 Hash Update
135 //
136 return (BOOLEAN)(SHA256_Update ((SHA256_CTX *)Sha256Context, Data, DataSize));
137}
138
159BOOLEAN
160EFIAPI
162 IN OUT VOID *Sha256Context,
163 OUT UINT8 *HashValue
164 )
165{
166 //
167 // Check input parameters.
168 //
169 if ((Sha256Context == NULL) || (HashValue == NULL)) {
170 return FALSE;
171 }
172
173 //
174 // OpenSSL SHA-256 Hash Finalization
175 //
176 return (BOOLEAN)(SHA256_Final (HashValue, (SHA256_CTX *)Sha256Context));
177}
178
197BOOLEAN
198EFIAPI
200 IN CONST VOID *Data,
201 IN UINTN DataSize,
202 OUT UINT8 *HashValue
203 )
204{
205 SHA256_CTX Context;
206
207 //
208 // Check input parameters.
209 //
210 if (HashValue == NULL) {
211 return FALSE;
212 }
213
214 if ((Data == NULL) && (DataSize != 0)) {
215 return FALSE;
216 }
217
218 //
219 // OpenSSL SHA-256 Hash Computation.
220 //
221 if (!SHA256_Init (&Context)) {
222 return FALSE;
223 }
224
225 if (!SHA256_Update (&Context, Data, DataSize)) {
226 return FALSE;
227 }
228
229 if (!SHA256_Final (HashValue, &Context)) {
230 return FALSE;
231 }
232
233 return TRUE;
234}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
UINTN EFIAPI Sha256GetContextSize(VOID)
Definition: CryptSha256.c:20
BOOLEAN EFIAPI Sha256Init(OUT VOID *Sha256Context)
Definition: CryptSha256.c:44
BOOLEAN EFIAPI Sha256Final(IN OUT VOID *Sha256Context, OUT UINT8 *HashValue)
Definition: CryptSha256.c:161
BOOLEAN EFIAPI Sha256Duplicate(IN CONST VOID *Sha256Context, OUT VOID *NewSha256Context)
Definition: CryptSha256.c:76
BOOLEAN EFIAPI Sha256HashAll(IN CONST VOID *Data, IN UINTN DataSize, OUT UINT8 *HashValue)
Definition: CryptSha256.c:199
BOOLEAN EFIAPI Sha256Update(IN OUT VOID *Sha256Context, IN CONST VOID *Data, IN UINTN DataSize)
Definition: CryptSha256.c:113
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284