TianoCore EDK2 master
Loading...
Searching...
No Matches
CryptSm3.c
Go to the documentation of this file.
1
9#include "InternalCryptLib.h"
10#include "internal/sm3.h"
11
19EFIAPI
21 VOID
22 )
23{
24 //
25 // Retrieves Openssl SM3 Context Size
26 //
27 return (UINTN)(sizeof (SM3_CTX));
28}
29
42BOOLEAN
43EFIAPI
45 OUT VOID *Sm3Context
46 )
47{
48 //
49 // Check input parameters.
50 //
51 if (Sm3Context == NULL) {
52 return FALSE;
53 }
54
55 //
56 // Openssl SM3 Context Initialization
57 //
58 ossl_sm3_init ((SM3_CTX *)Sm3Context);
59 return TRUE;
60}
61
77BOOLEAN
78EFIAPI
80 IN CONST VOID *Sm3Context,
81 OUT VOID *NewSm3Context
82 )
83{
84 //
85 // Check input parameters.
86 //
87 if ((Sm3Context == NULL) || (NewSm3Context == NULL)) {
88 return FALSE;
89 }
90
91 CopyMem (NewSm3Context, Sm3Context, sizeof (SM3_CTX));
92
93 return TRUE;
94}
95
114BOOLEAN
115EFIAPI
117 IN OUT VOID *Sm3Context,
118 IN CONST VOID *Data,
119 IN UINTN DataSize
120 )
121{
122 //
123 // Check input parameters.
124 //
125 if (Sm3Context == NULL) {
126 return FALSE;
127 }
128
129 //
130 // Check invalid parameters, in case that only DataLength was checked in Openssl
131 //
132 if ((Data == NULL) && (DataSize != 0)) {
133 return FALSE;
134 }
135
136 //
137 // Openssl SM3 Hash Update
138 //
139 ossl_sm3_update ((SM3_CTX *)Sm3Context, Data, DataSize);
140
141 return TRUE;
142}
143
164BOOLEAN
165EFIAPI
167 IN OUT VOID *Sm3Context,
168 OUT UINT8 *HashValue
169 )
170{
171 //
172 // Check input parameters.
173 //
174 if ((Sm3Context == NULL) || (HashValue == NULL)) {
175 return FALSE;
176 }
177
178 //
179 // Openssl SM3 Hash Finalization
180 //
181 ossl_sm3_final (HashValue, (SM3_CTX *)Sm3Context);
182
183 return TRUE;
184}
185
204BOOLEAN
205EFIAPI
207 IN CONST VOID *Data,
208 IN UINTN DataSize,
209 OUT UINT8 *HashValue
210 )
211{
212 SM3_CTX Ctx;
213
214 //
215 // Check input parameters.
216 //
217 if (HashValue == NULL) {
218 return FALSE;
219 }
220
221 if ((Data == NULL) && (DataSize != 0)) {
222 return FALSE;
223 }
224
225 //
226 // SM3 Hash Computation.
227 //
228 ossl_sm3_init (&Ctx);
229
230 ossl_sm3_update (&Ctx, Data, DataSize);
231
232 ossl_sm3_final (HashValue, &Ctx);
233
234 return TRUE;
235}
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI Sm3Duplicate(IN CONST VOID *Sm3Context, OUT VOID *NewSm3Context)
Definition: CryptSm3.c:79
UINTN EFIAPI Sm3GetContextSize(VOID)
Definition: CryptSm3.c:20
BOOLEAN EFIAPI Sm3Update(IN OUT VOID *Sm3Context, IN CONST VOID *Data, IN UINTN DataSize)
Definition: CryptSm3.c:116
BOOLEAN EFIAPI Sm3Final(IN OUT VOID *Sm3Context, OUT UINT8 *HashValue)
Definition: CryptSm3.c:166
BOOLEAN EFIAPI Sm3HashAll(IN CONST VOID *Data, IN UINTN DataSize, OUT UINT8 *HashValue)
Definition: CryptSm3.c:206
BOOLEAN EFIAPI Sm3Init(OUT VOID *Sm3Context)
Definition: CryptSm3.c:44
#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