TianoCore EDK2 master
Loading...
Searching...
No Matches
CryptSha256.c
Go to the documentation of this file.
1
9#include "InternalCryptLib.h"
10#include <mbedtls/sha256.h>
11
19EFIAPI
21 VOID
22 )
23{
24 return (UINTN)(sizeof (mbedtls_sha256_context));
25}
26
39BOOLEAN
40EFIAPI
42 OUT VOID *Sha256Context
43 )
44{
45 INT32 Ret;
46
47 if (Sha256Context == NULL) {
48 return FALSE;
49 }
50
51 mbedtls_sha256_init (Sha256Context);
52
53 Ret = mbedtls_sha256_starts (Sha256Context, FALSE);
54 if (Ret != 0) {
55 return FALSE;
56 }
57
58 return TRUE;
59}
60
74BOOLEAN
75EFIAPI
77 IN CONST VOID *Sha256Context,
78 OUT VOID *NewSha256Context
79 )
80{
81 if ((Sha256Context == NULL) || (NewSha256Context == NULL)) {
82 return FALSE;
83 }
84
85 mbedtls_sha256_clone (NewSha256Context, Sha256Context);
86
87 return TRUE;
88}
89
108BOOLEAN
109EFIAPI
111 IN OUT VOID *Sha256Context,
112 IN CONST VOID *Data,
113 IN UINTN DataSize
114 )
115{
116 INT32 Ret;
117
118 if (Sha256Context == NULL) {
119 return FALSE;
120 }
121
122 if ((Data == NULL) && (DataSize != 0)) {
123 return FALSE;
124 }
125
126 Ret = mbedtls_sha256_update (Sha256Context, Data, DataSize);
127 if (Ret != 0) {
128 return FALSE;
129 }
130
131 return TRUE;
132}
133
154BOOLEAN
155EFIAPI
157 IN OUT VOID *Sha256Context,
158 OUT UINT8 *HashValue
159 )
160{
161 INT32 Ret;
162
163 if ((Sha256Context == NULL) || (HashValue == NULL)) {
164 return FALSE;
165 }
166
167 Ret = mbedtls_sha256_finish (Sha256Context, HashValue);
168 mbedtls_sha256_free (Sha256Context);
169 if (Ret != 0) {
170 return FALSE;
171 }
172
173 return TRUE;
174}
175
194BOOLEAN
195EFIAPI
197 IN CONST VOID *Data,
198 IN UINTN DataSize,
199 OUT UINT8 *HashValue
200 )
201{
202 INT32 Ret;
203
204 if (HashValue == NULL) {
205 return FALSE;
206 }
207
208 if ((Data == NULL) && (DataSize != 0)) {
209 return FALSE;
210 }
211
212 Ret = mbedtls_sha256 (Data, DataSize, HashValue, FALSE);
213 if (Ret != 0) {
214 return FALSE;
215 }
216
217 return TRUE;
218}
UINT64 UINTN
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