Skip to content

Commit b1567b2

Browse files
mxu9mergify[bot]
authored andcommitted
CryptoPkg: Add SecCryptLib
RFC: https://bugzilla.tianocore.org/show_bug.cgi?id=3853 This is the Cryptographic library instance for SEC. The motivation of this library is to support SHA384 in SEC phase for Td guest. So only Hash/CryptSha512.c is included which supports SHA384 and SHA512. Other cryptographics are added with the null version, such as CryptMd5Null.c. Cc: Jiewen Yao <[email protected]> Cc: Jian J Wang <[email protected]> Cc: Xiaoyu Lu <[email protected]> Cc: Guomin Jiang <[email protected]> Cc: Gerd Hoffmann <[email protected]> Reviewed-by: Jiewen Yao <[email protected]> Signed-off-by: Min Xu <[email protected]>
1 parent 72c5afd commit b1567b2

File tree

8 files changed

+1023
-0
lines changed

8 files changed

+1023
-0
lines changed

Diff for: CryptoPkg/CryptoPkg.dsc

+4
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@
109109
[LibraryClasses.ARM]
110110
ArmSoftFloatLib|ArmPkg/Library/ArmSoftFloatLib/ArmSoftFloatLib.inf
111111

112+
[LibraryClasses.common.SEC]
113+
BaseCryptLib|CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf
114+
112115
[LibraryClasses.common.PEIM]
113116
PcdLib|MdePkg/Library/PeiPcdLib/PeiPcdLib.inf
114117
ReportStatusCodeLib|MdeModulePkg/Library/PeiReportStatusCodeLib/PeiReportStatusCodeLib.inf
@@ -236,6 +239,7 @@
236239
!if $(CRYPTO_SERVICES) == PACKAGE
237240
[Components]
238241
CryptoPkg/Library/BaseCryptLib/BaseCryptLib.inf
242+
CryptoPkg/Library/BaseCryptLib/SecCryptLib.inf
239243
CryptoPkg/Library/BaseCryptLib/PeiCryptLib.inf
240244
CryptoPkg/Library/BaseCryptLib/SmmCryptLib.inf
241245
CryptoPkg/Library/BaseCryptLib/RuntimeCryptLib.inf

Diff for: CryptoPkg/Library/BaseCryptLib/Hash/CryptMd5Null.c

+163
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,163 @@
1+
/** @file
2+
3+
MD5 Digest Wrapper Null Implementation.
4+
5+
Copyright (c) Microsoft Corporation. All rights reserved.
6+
SPDX-License-Identifier: BSD-2-Clause-Patent
7+
8+
**/
9+
10+
#include "InternalCryptLib.h"
11+
12+
/**
13+
Retrieves the size, in bytes, of the context buffer required for MD5 hash operations.
14+
15+
@return The size, in bytes, of the context buffer required for MD5 hash operations.
16+
17+
**/
18+
UINTN
19+
EFIAPI
20+
Md5GetContextSize (
21+
VOID
22+
)
23+
{
24+
ASSERT (FALSE);
25+
return 0;
26+
}
27+
28+
/**
29+
Initializes user-supplied memory pointed by Md5Context as MD5 hash context for
30+
subsequent use.
31+
32+
If Md5Context is NULL, then return FALSE.
33+
34+
@param[out] Md5Context Pointer to MD5 context being initialized.
35+
36+
@retval TRUE MD5 context initialization succeeded.
37+
@retval FALSE MD5 context initialization failed.
38+
39+
**/
40+
BOOLEAN
41+
EFIAPI
42+
Md5Init (
43+
OUT VOID *Md5Context
44+
)
45+
{
46+
ASSERT (FALSE);
47+
return FALSE;
48+
}
49+
50+
/**
51+
Makes a copy of an existing MD5 context.
52+
53+
If Md5Context is NULL, then return FALSE.
54+
If NewMd5Context is NULL, then return FALSE.
55+
56+
@param[in] Md5Context Pointer to MD5 context being copied.
57+
@param[out] NewMd5Context Pointer to new MD5 context.
58+
59+
@retval TRUE MD5 context copy succeeded.
60+
@retval FALSE MD5 context copy failed.
61+
62+
**/
63+
BOOLEAN
64+
EFIAPI
65+
Md5Duplicate (
66+
IN CONST VOID *Md5Context,
67+
OUT VOID *NewMd5Context
68+
)
69+
{
70+
ASSERT (FALSE);
71+
return FALSE;
72+
}
73+
74+
/**
75+
Digests the input data and updates MD5 context.
76+
77+
This function performs MD5 digest on a data buffer of the specified size.
78+
It can be called multiple times to compute the digest of long or discontinuous data streams.
79+
MD5 context should be already correctly intialized by Md5Init(), and should not be finalized
80+
by Md5Final(). Behavior with invalid context is undefined.
81+
82+
If Md5Context is NULL, then return FALSE.
83+
84+
@param[in, out] Md5Context Pointer to the MD5 context.
85+
@param[in] Data Pointer to the buffer containing the data to be hashed.
86+
@param[in] DataSize Size of Data buffer in bytes.
87+
88+
@retval TRUE MD5 data digest succeeded.
89+
@retval FALSE MD5 data digest failed.
90+
91+
**/
92+
BOOLEAN
93+
EFIAPI
94+
Md5Update (
95+
IN OUT VOID *Md5Context,
96+
IN CONST VOID *Data,
97+
IN UINTN DataSize
98+
)
99+
{
100+
ASSERT (FALSE);
101+
return FALSE;
102+
}
103+
104+
/**
105+
Completes computation of the MD5 digest value.
106+
107+
This function completes MD5 hash computation and retrieves the digest value into
108+
the specified memory. After this function has been called, the MD5 context cannot
109+
be used again.
110+
MD5 context should be already correctly intialized by Md5Init(), and should not be
111+
finalized by Md5Final(). Behavior with invalid MD5 context is undefined.
112+
113+
If Md5Context is NULL, then return FALSE.
114+
If HashValue is NULL, then return FALSE.
115+
116+
@param[in, out] Md5Context Pointer to the MD5 context.
117+
@param[out] HashValue Pointer to a buffer that receives the MD5 digest
118+
value (16 bytes).
119+
120+
@retval TRUE MD5 digest computation succeeded.
121+
@retval FALSE MD5 digest computation failed.
122+
123+
**/
124+
BOOLEAN
125+
EFIAPI
126+
Md5Final (
127+
IN OUT VOID *Md5Context,
128+
OUT UINT8 *HashValue
129+
)
130+
{
131+
ASSERT (FALSE);
132+
return FALSE;
133+
}
134+
135+
/**
136+
Computes the MD5 message digest of a input data buffer.
137+
138+
This function performs the MD5 message digest of a given data buffer, and places
139+
the digest value into the specified memory.
140+
141+
If this interface is not supported, then return FALSE.
142+
143+
@param[in] Data Pointer to the buffer containing the data to be hashed.
144+
@param[in] DataSize Size of Data buffer in bytes.
145+
@param[out] HashValue Pointer to a buffer that receives the MD5 digest
146+
value (16 bytes).
147+
148+
@retval TRUE MD5 digest computation succeeded.
149+
@retval FALSE MD5 digest computation failed.
150+
@retval FALSE This interface is not supported.
151+
152+
**/
153+
BOOLEAN
154+
EFIAPI
155+
Md5HashAll (
156+
IN CONST VOID *Data,
157+
IN UINTN DataSize,
158+
OUT UINT8 *HashValue
159+
)
160+
{
161+
ASSERT (FALSE);
162+
return FALSE;
163+
}

Diff for: CryptoPkg/Library/BaseCryptLib/Hash/CryptSha1Null.c

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
/** @file
2+
SHA-1 Digest Wrapper Null Implementation.
3+
4+
Copyright (c) 2009 - 2016, Intel Corporation. All rights reserved.<BR>
5+
SPDX-License-Identifier: BSD-2-Clause-Patent
6+
7+
**/
8+
9+
#include "InternalCryptLib.h"
10+
11+
/**
12+
Retrieves the size, in bytes, of the context buffer required for SHA-1 hash operations.
13+
14+
@return The size, in bytes, of the context buffer required for SHA-1 hash operations.
15+
16+
**/
17+
UINTN
18+
EFIAPI
19+
Sha1GetContextSize (
20+
VOID
21+
)
22+
{
23+
//
24+
// Retrieves SHA Context Size
25+
//
26+
ASSERT (FALSE);
27+
return 0;
28+
}
29+
30+
/**
31+
Initializes user-supplied memory pointed by Sha1Context as SHA-1 hash context for
32+
subsequent use.
33+
34+
If Sha1Context is NULL, then return FALSE.
35+
36+
@param[out] Sha1Context Pointer to SHA-1 context being initialized.
37+
38+
@retval TRUE SHA-1 context initialization succeeded.
39+
@retval FALSE SHA-1 context initialization failed.
40+
41+
**/
42+
BOOLEAN
43+
EFIAPI
44+
Sha1Init (
45+
OUT VOID *Sha1Context
46+
)
47+
{
48+
ASSERT (FALSE);
49+
return FALSE;
50+
}
51+
52+
/**
53+
Makes a copy of an existing SHA-1 context.
54+
55+
If Sha1Context is NULL, then return FALSE.
56+
If NewSha1Context is NULL, then return FALSE.
57+
58+
@param[in] Sha1Context Pointer to SHA-1 context being copied.
59+
@param[out] NewSha1Context Pointer to new SHA-1 context.
60+
61+
@retval TRUE SHA-1 context copy succeeded.
62+
@retval FALSE SHA-1 context copy failed.
63+
64+
**/
65+
BOOLEAN
66+
EFIAPI
67+
Sha1Duplicate (
68+
IN CONST VOID *Sha1Context,
69+
OUT VOID *NewSha1Context
70+
)
71+
{
72+
ASSERT (FALSE);
73+
74+
return FALSE;
75+
}
76+
77+
/**
78+
Digests the input data and updates SHA-1 context.
79+
80+
This function performs SHA-1 digest on a data buffer of the specified size.
81+
It can be called multiple times to compute the digest of long or discontinuous data streams.
82+
SHA-1 context should be already correctly initialized by Sha1Init(), and should not be finalized
83+
by Sha1Final(). Behavior with invalid context is undefined.
84+
85+
If Sha1Context is NULL, then return FALSE.
86+
87+
@param[in, out] Sha1Context Pointer to the SHA-1 context.
88+
@param[in] Data Pointer to the buffer containing the data to be hashed.
89+
@param[in] DataSize Size of Data buffer in bytes.
90+
91+
@retval TRUE SHA-1 data digest succeeded.
92+
@retval FALSE SHA-1 data digest failed.
93+
94+
**/
95+
BOOLEAN
96+
EFIAPI
97+
Sha1Update (
98+
IN OUT VOID *Sha1Context,
99+
IN CONST VOID *Data,
100+
IN UINTN DataSize
101+
)
102+
{
103+
ASSERT (FALSE);
104+
return FALSE;
105+
}
106+
107+
/**
108+
Completes computation of the SHA-1 digest value.
109+
110+
This function completes SHA-1 hash computation and retrieves the digest value into
111+
the specified memory. After this function has been called, the SHA-1 context cannot
112+
be used again.
113+
SHA-1 context should be already correctly initialized by Sha1Init(), and should not be
114+
finalized by Sha1Final(). Behavior with invalid SHA-1 context is undefined.
115+
116+
If Sha1Context is NULL, then return FALSE.
117+
If HashValue is NULL, then return FALSE.
118+
119+
@param[in, out] Sha1Context Pointer to the SHA-1 context.
120+
@param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
121+
value (20 bytes).
122+
123+
@retval TRUE SHA-1 digest computation succeeded.
124+
@retval FALSE SHA-1 digest computation failed.
125+
126+
**/
127+
BOOLEAN
128+
EFIAPI
129+
Sha1Final (
130+
IN OUT VOID *Sha1Context,
131+
OUT UINT8 *HashValue
132+
)
133+
{
134+
ASSERT (FALSE);
135+
return FALSE;
136+
}
137+
138+
/**
139+
Computes the SHA-1 message digest of a input data buffer.
140+
141+
This function performs the SHA-1 message digest of a given data buffer, and places
142+
the digest value into the specified memory.
143+
144+
If this interface is not supported, then return FALSE.
145+
146+
@param[in] Data Pointer to the buffer containing the data to be hashed.
147+
@param[in] DataSize Size of Data buffer in bytes.
148+
@param[out] HashValue Pointer to a buffer that receives the SHA-1 digest
149+
value (20 bytes).
150+
151+
@retval TRUE SHA-1 digest computation succeeded.
152+
@retval FALSE SHA-1 digest computation failed.
153+
@retval FALSE This interface is not supported.
154+
155+
**/
156+
BOOLEAN
157+
EFIAPI
158+
Sha1HashAll (
159+
IN CONST VOID *Data,
160+
IN UINTN DataSize,
161+
OUT UINT8 *HashValue
162+
)
163+
{
164+
ASSERT (FALSE);
165+
return FALSE;
166+
}

0 commit comments

Comments
 (0)