TianoCore EDK2 master
Loading...
Searching...
No Matches
CryptSha1.c
Go to the documentation of this file.
1
9#include "InternalCryptLib.h"
10#include <openssl/sha.h>
11
12#ifndef DISABLE_SHA1_DEPRECATED_INTERFACES
13
21EFIAPI
23 VOID
24 )
25{
26 //
27 // Retrieves OpenSSL SHA Context Size
28 //
29 return (UINTN)(sizeof (SHA_CTX));
30}
31
44BOOLEAN
45EFIAPI
47 OUT VOID *Sha1Context
48 )
49{
50 //
51 // Check input parameters.
52 //
53 if (Sha1Context == NULL) {
54 return FALSE;
55 }
56
57 //
58 // OpenSSL SHA-1 Context Initialization
59 //
60 return (BOOLEAN)(SHA1_Init ((SHA_CTX *)Sha1Context));
61}
62
76BOOLEAN
77EFIAPI
79 IN CONST VOID *Sha1Context,
80 OUT VOID *NewSha1Context
81 )
82{
83 //
84 // Check input parameters.
85 //
86 if ((Sha1Context == NULL) || (NewSha1Context == NULL)) {
87 return FALSE;
88 }
89
90 CopyMem (NewSha1Context, Sha1Context, sizeof (SHA_CTX));
91
92 return TRUE;
93}
94
113BOOLEAN
114EFIAPI
116 IN OUT VOID *Sha1Context,
117 IN CONST VOID *Data,
118 IN UINTN DataSize
119 )
120{
121 //
122 // Check input parameters.
123 //
124 if (Sha1Context == NULL) {
125 return FALSE;
126 }
127
128 //
129 // Check invalid parameters, in case that only DataLength was checked in OpenSSL
130 //
131 if ((Data == NULL) && (DataSize != 0)) {
132 return FALSE;
133 }
134
135 //
136 // OpenSSL SHA-1 Hash Update
137 //
138 return (BOOLEAN)(SHA1_Update ((SHA_CTX *)Sha1Context, Data, DataSize));
139}
140
161BOOLEAN
162EFIAPI
164 IN OUT VOID *Sha1Context,
165 OUT UINT8 *HashValue
166 )
167{
168 //
169 // Check input parameters.
170 //
171 if ((Sha1Context == NULL) || (HashValue == NULL)) {
172 return FALSE;
173 }
174
175 //
176 // OpenSSL SHA-1 Hash Finalization
177 //
178 return (BOOLEAN)(SHA1_Final (HashValue, (SHA_CTX *)Sha1Context));
179}
180
199BOOLEAN
200EFIAPI
202 IN CONST VOID *Data,
203 IN UINTN DataSize,
204 OUT UINT8 *HashValue
205 )
206{
207 SHA_CTX Context;
208
209 //
210 // Check input parameters.
211 //
212 if (HashValue == NULL) {
213 return FALSE;
214 }
215
216 if ((Data == NULL) && (DataSize != 0)) {
217 return FALSE;
218 }
219
220 //
221 // OpenSSL SHA-1 Hash Computation.
222 //
223 if (!SHA1_Init (&Context)) {
224 return FALSE;
225 }
226
227 if (!SHA1_Update (&Context, Data, DataSize)) {
228 return FALSE;
229 }
230
231 if (!SHA1_Final (HashValue, &Context)) {
232 return FALSE;
233 }
234
235 return TRUE;
236}
237
238#endif
UINT64 UINTN
VOID *EFIAPI CopyMem(OUT VOID *DestinationBuffer, IN CONST VOID *SourceBuffer, IN UINTN Length)
BOOLEAN EFIAPI Sha1Final(IN OUT VOID *Sha1Context, OUT UINT8 *HashValue)
Definition: CryptSha1.c:163
BOOLEAN EFIAPI Sha1Duplicate(IN CONST VOID *Sha1Context, OUT VOID *NewSha1Context)
Definition: CryptSha1.c:78
BOOLEAN EFIAPI Sha1Init(OUT VOID *Sha1Context)
Definition: CryptSha1.c:46
BOOLEAN EFIAPI Sha1HashAll(IN CONST VOID *Data, IN UINTN DataSize, OUT UINT8 *HashValue)
Definition: CryptSha1.c:201
UINTN EFIAPI Sha1GetContextSize(VOID)
Definition: CryptSha1.c:22
BOOLEAN EFIAPI Sha1Update(IN OUT VOID *Sha1Context, IN CONST VOID *Data, IN UINTN DataSize)
Definition: CryptSha1.c:115
#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