]>
Commit | Line | Data |
---|---|---|
1 | /** @file\r | |
2 | Header file of Runtime Cryptographic Driver.\r | |
3 | \r | |
4 | Copyright (c) 2010 - 2012, Intel Corporation. All rights reserved.<BR>\r | |
5 | This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | #ifndef _CRYPT_RUNTIME_H_\r | |
16 | #define _CRYPT_RUNTIME_H_\r | |
17 | \r | |
18 | #include <Uefi.h>\r | |
19 | \r | |
20 | #include <Protocol/RuntimeCrypt.h>\r | |
21 | \r | |
22 | #include <Library/DebugLib.h>\r | |
23 | #include <Library/UefiDriverEntryPoint.h>\r | |
24 | #include <Library/UefiBootServicesTableLib.h>\r | |
25 | #include <Library/BaseCryptLib.h>\r | |
26 | \r | |
27 | /**\r | |
28 | Retrieves the size, in bytes, of the context buffer required for SHA-256 operations.\r | |
29 | \r | |
30 | @return The size, in bytes, of the context buffer required for SHA-256 operations.\r | |
31 | \r | |
32 | **/\r | |
33 | UINTN\r | |
34 | EFIAPI\r | |
35 | RuntimeCryptSha256GetContextSize (\r | |
36 | VOID\r | |
37 | );\r | |
38 | \r | |
39 | \r | |
40 | /**\r | |
41 | Initializes user-supplied memory pointed by Sha256Context as SHA-256 hash context for\r | |
42 | subsequent use.\r | |
43 | \r | |
44 | If Sha256Context is NULL, then return FALSE.\r | |
45 | \r | |
46 | @param[in, out] Sha256Context Pointer to SHA-256 Context being initialized.\r | |
47 | \r | |
48 | @retval TRUE SHA-256 context initialization succeeded.\r | |
49 | @retval FALSE SHA-256 context initialization failed.\r | |
50 | \r | |
51 | **/\r | |
52 | BOOLEAN\r | |
53 | EFIAPI\r | |
54 | RuntimeCryptSha256Init (\r | |
55 | IN OUT VOID *Sha256Context\r | |
56 | );\r | |
57 | \r | |
58 | \r | |
59 | /**\r | |
60 | Performs SHA-256 digest on a data buffer of the specified length. This function can\r | |
61 | be called multiple times to compute the digest of long or discontinuous data streams.\r | |
62 | \r | |
63 | If Sha256Context is NULL, then return FALSE.\r | |
64 | \r | |
65 | @param[in, out] Sha256Context Pointer to the SHA-256 context.\r | |
66 | @param[in] Data Pointer to the buffer containing the data to be hashed.\r | |
67 | @param[in] DataLength Length of Data buffer in bytes.\r | |
68 | \r | |
69 | @retval TRUE SHA-256 data digest succeeded.\r | |
70 | @retval FALSE Invalid SHA-256 context. After Sha256Final function has been called, the\r | |
71 | SHA-256 context cannot be reused.\r | |
72 | \r | |
73 | **/\r | |
74 | BOOLEAN\r | |
75 | EFIAPI\r | |
76 | RuntimeCryptSha256Update (\r | |
77 | IN OUT VOID *Sha256Context,\r | |
78 | IN CONST VOID *Data,\r | |
79 | IN UINTN DataLength\r | |
80 | );\r | |
81 | \r | |
82 | \r | |
83 | /**\r | |
84 | Completes SHA-256 hash computation and retrieves the digest value into the specified\r | |
85 | memory. After this function has been called, the SHA-256 context cannot be used again.\r | |
86 | \r | |
87 | If Sha256Context is NULL, then return FALSE.\r | |
88 | If HashValue is NULL, then return FALSE.\r | |
89 | \r | |
90 | @param[in, out] Sha256Context Pointer to SHA-256 context\r | |
91 | @param[out] HashValue Pointer to a buffer that receives the SHA-256 digest\r | |
92 | value (32 bytes).\r | |
93 | \r | |
94 | @retval TRUE SHA-256 digest computation succeeded.\r | |
95 | @retval FALSE SHA-256 digest computation failed.\r | |
96 | \r | |
97 | **/\r | |
98 | BOOLEAN\r | |
99 | EFIAPI\r | |
100 | RuntimeCryptSha256Final (\r | |
101 | IN OUT VOID *Sha256Context,\r | |
102 | OUT UINT8 *HashValue\r | |
103 | );\r | |
104 | \r | |
105 | /**\r | |
106 | Allocates and Initializes one RSA Context for subsequent use.\r | |
107 | \r | |
108 | @return Pointer to the RSA Context that has been initialized.\r | |
109 | If the allocations fails, RsaNew() returns NULL.\r | |
110 | \r | |
111 | **/\r | |
112 | VOID *\r | |
113 | EFIAPI\r | |
114 | RuntimeCryptRsaNew (\r | |
115 | VOID\r | |
116 | );\r | |
117 | \r | |
118 | \r | |
119 | /**\r | |
120 | Release the specified RSA Context.\r | |
121 | \r | |
122 | @param[in] RsaContext Pointer to the RSA context to be released.\r | |
123 | \r | |
124 | **/\r | |
125 | VOID\r | |
126 | EFIAPI\r | |
127 | RuntimeCryptRsaFree (\r | |
128 | IN VOID *RsaContext\r | |
129 | );\r | |
130 | \r | |
131 | /**\r | |
132 | Sets the tag-designated RSA key component into the established RSA context from\r | |
133 | the user-specified nonnegative integer (octet string format represented in RSA\r | |
134 | PKCS#1).\r | |
135 | \r | |
136 | If RsaContext is NULL, then return FALSE.\r | |
137 | \r | |
138 | @param[in, out] RsaContext Pointer to RSA context being set.\r | |
139 | @param[in] KeyTag Tag of RSA key component being set.\r | |
140 | @param[in] BigNumber Pointer to octet integer buffer.\r | |
141 | @param[in] BnLength Length of big number buffer in bytes.\r | |
142 | \r | |
143 | @return TRUE RSA key component was set successfully.\r | |
144 | @return FALSE Invalid RSA key component tag.\r | |
145 | \r | |
146 | **/\r | |
147 | BOOLEAN\r | |
148 | EFIAPI\r | |
149 | RuntimeCryptRsaSetKey (\r | |
150 | IN OUT VOID *RsaContext,\r | |
151 | IN RSA_KEY_TAG KeyTag,\r | |
152 | IN CONST UINT8 *BigNumber,\r | |
153 | IN UINTN BnLength\r | |
154 | );\r | |
155 | \r | |
156 | \r | |
157 | /**\r | |
158 | Verifies the RSA-SSA signature with EMSA-PKCS1-v1_5 encoding scheme defined in\r | |
159 | RSA PKCS#1.\r | |
160 | \r | |
161 | If RsaContext is NULL, then return FALSE.\r | |
162 | If MessageHash is NULL, then return FALSE.\r | |
163 | If Signature is NULL, then return FALSE.\r | |
164 | If HashLength is not equal to the size of MD5, SHA-1 or SHA-256 digest, return FALSE.\r | |
165 | \r | |
166 | @param[in] RsaContext Pointer to RSA context for signature verification.\r | |
167 | @param[in] MessageHash Pointer to octet message hash to be checked.\r | |
168 | @param[in] HashLength Length of the message hash in bytes.\r | |
169 | @param[in] Signature Pointer to RSA PKCS1-v1_5 signature to be verified.\r | |
170 | @param[in] SigLength Length of signature in bytes.\r | |
171 | \r | |
172 | @return TRUE Valid signature encoded in PKCS1-v1_5.\r | |
173 | @return FALSE Invalid signature or invalid RSA context.\r | |
174 | \r | |
175 | **/\r | |
176 | BOOLEAN\r | |
177 | EFIAPI\r | |
178 | RuntimeCryptRsaPkcs1Verify (\r | |
179 | IN VOID *RsaContext,\r | |
180 | IN CONST UINT8 *MessageHash,\r | |
181 | IN UINTN HashLength,\r | |
182 | IN CONST UINT8 *Signature,\r | |
183 | IN UINTN SigLength\r | |
184 | );\r | |
185 | \r | |
186 | #endif\r |