]>
Commit | Line | Data |
---|---|---|
a3bcde70 HT |
1 | /** @file\r |
2 | Definition related to the Security operation.\r | |
3 | \r | |
4 | Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>\r | |
5 | \r | |
6 | This program and the accompanying materials\r | |
7 | are licensed and made available under the terms and conditions of the BSD License\r | |
8 | which accompanies this distribution. The full text of the license may be found at\r | |
9 | http://opensource.org/licenses/bsd-license.php.\r | |
10 | \r | |
11 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
12 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
13 | \r | |
14 | **/\r | |
15 | \r | |
16 | #ifndef _EFI_IPSEC_CRYPTIO_H_\r | |
17 | #define _EFI_IPSEC_CRYPTIO_H_\r | |
18 | \r | |
19 | #include <Protocol/IpSecConfig.h>\r | |
20 | #include <Library/DebugLib.h>\r | |
21 | \r | |
22 | #define IPSEC_ENCRYPT_ALGORITHM_LIST_SIZE 2\r | |
23 | #define IPSEC_AUTH_ALGORITHM_LIST_SIZE 3\r | |
24 | \r | |
25 | /**\r | |
26 | Prototype of Hash GetContextSize.\r | |
27 | \r | |
28 | Retrieves the size, in bytes, of the context buffer required.\r | |
29 | \r | |
30 | @return The size, in bytes, of the context buffer required.\r | |
31 | \r | |
32 | **/\r | |
33 | typedef\r | |
34 | UINTN\r | |
35 | (EFIAPI *CPL_HASH_GETCONTEXTSIZE) (\r | |
36 | VOID\r | |
37 | );\r | |
38 | \r | |
39 | /**\r | |
40 | Prototype of Hash Operation Initiating.\r | |
41 | \r | |
42 | Initialization with a new context.\r | |
43 | \r | |
44 | \r | |
45 | @param[in,out] Context Input Context.\r | |
46 | \r | |
47 | @retval TRUE Initialization Successfully.\r | |
48 | \r | |
49 | **/\r | |
50 | typedef\r | |
51 | EFI_STATUS\r | |
52 | (EFIAPI *CPL_HASH_INIT) (\r | |
53 | IN OUT VOID *Context\r | |
54 | );\r | |
55 | \r | |
56 | /**\r | |
57 | Prototype of HASH update.\r | |
58 | Hash update operation. Continue an Hash message digest operation, processing\r | |
59 | another message block, and updating the Hash context.\r | |
60 | \r | |
61 | If Context is NULL, then ASSERT().\r | |
62 | If Data is NULL, then ASSERT().\r | |
63 | \r | |
64 | @param[in,out] Context The Specified Context.\r | |
65 | @param[in,out] Data The Input Data to hash.\r | |
66 | @param[in] DataLength The length, in bytes, of Data.\r | |
67 | \r | |
68 | @retval TRUE Update data successfully.\r | |
69 | @retval FALSE The Context has been finalized.\r | |
70 | \r | |
71 | **/\r | |
72 | typedef\r | |
73 | BOOLEAN\r | |
74 | (EFIAPI *CPL_HASH_UPDATE) (\r | |
75 | IN OUT VOID *Context,\r | |
76 | IN CONST VOID *Data,\r | |
77 | IN UINTN DataLength\r | |
78 | );\r | |
79 | \r | |
80 | /**\r | |
81 | Prototype of Hash finallization.\r | |
82 | Terminate a Hash message digest operation and output the message digest.\r | |
83 | \r | |
84 | If Context is NULL, then ASSERT().\r | |
85 | If HashValue is NULL, then ASSERT().\r | |
86 | \r | |
87 | @param[in,out] Context The specified Context.\r | |
88 | @param[out] HashValue Pointer to a 16-byte message digest output buffer.\r | |
89 | \r | |
90 | @retval TRUE Finalized successfully.\r | |
91 | \r | |
92 | **/\r | |
93 | typedef\r | |
94 | BOOLEAN\r | |
95 | (EFIAPI *CPL_HASH_FINAL) (\r | |
96 | IN OUT VOID *Context,\r | |
97 | OUT UINT8 *HashValue\r | |
98 | );\r | |
99 | \r | |
100 | /**\r | |
101 | Prototype of Cipher GetContextSize.\r | |
102 | \r | |
103 | Retrieves the size, in bytes, of the context buffer required.\r | |
104 | \r | |
105 | @return The size, in bytes, of the context buffer required.\r | |
106 | \r | |
107 | **/\r | |
108 | typedef\r | |
109 | UINTN\r | |
110 | (EFIAPI *CPL_CIPHER_GETCONTEXTSIZE) (\r | |
111 | VOID\r | |
112 | );\r | |
113 | \r | |
114 | /**\r | |
115 | Prototype of Cipher initiation.\r | |
116 | Intializes the user-supplied key as the specifed context (key materials) for both\r | |
117 | encryption and decryption operations.\r | |
118 | \r | |
119 | If Context is NULL, then ASSERT().\r | |
120 | If Key is NULL, then generate random key for usage.\r | |
121 | \r | |
122 | @param[in,out] Context The specified Context.\r | |
123 | @param[in] Key User-supplied TDES key (64/128/192 bits).\r | |
124 | @param[in] KeyBits Key length in bits.\r | |
125 | \r | |
126 | @retval TRUE TDES Initialization was successful.\r | |
127 | \r | |
128 | **/\r | |
129 | typedef\r | |
130 | BOOLEAN\r | |
131 | (EFIAPI *CPL_CIPHER_INIT) (\r | |
132 | IN OUT VOID *Context,\r | |
133 | IN CONST UINT8 *Key,\r | |
134 | IN CONST UINTN KeyBits\r | |
135 | );\r | |
136 | \r | |
137 | \r | |
138 | /**\r | |
139 | Prototype of Cipher encryption.\r | |
140 | Encrypts plaintext message with the specified cipher.\r | |
141 | \r | |
142 | If Context is NULL, then ASSERT().\r | |
143 | if InData is NULL, then ASSERT().\r | |
144 | If Size of input data is not multiple of Cipher algorithm related block size,\r | |
145 | then ASSERT().\r | |
146 | \r | |
147 | @param[in] Context The specified Context.\r | |
148 | @param[in] InData The input plaintext data to be encrypted.\r | |
149 | @param[out] OutData The resultant encrypted ciphertext.\r | |
150 | @param[in] DataLength Length of input data in bytes.\r | |
151 | \r | |
152 | @retval TRUE Encryption successful.\r | |
153 | \r | |
154 | **/\r | |
155 | typedef\r | |
156 | BOOLEAN\r | |
157 | (EFIAPI *CPL_CIPHER_ENCRYPT) (\r | |
158 | IN VOID *Context,\r | |
159 | IN CONST UINT8 *InData,\r | |
160 | OUT UINT8 *OutData,\r | |
161 | IN CONST UINTN DataLength\r | |
162 | );\r | |
163 | \r | |
164 | \r | |
165 | /**\r | |
166 | Prototype of Cipher decryption.\r | |
167 | Decrypts cipher message with specified cipher.\r | |
168 | \r | |
169 | If Context is NULL, then ASSERT().\r | |
170 | if InData is NULL, then ASSERT().\r | |
171 | If Size of input data is not a multiple of a certaion block size , then ASSERT().\r | |
172 | \r | |
173 | @param[in] Context The specified Context.\r | |
174 | @param[in] InData The input ciphertext data to be decrypted.\r | |
175 | @param[out] OutData The resultant decrypted plaintext.\r | |
176 | @param[in] DataLength Length of input data in bytes.\r | |
177 | \r | |
178 | @retval TRUE Decryption successful.\r | |
179 | \r | |
180 | **/\r | |
181 | typedef\r | |
182 | BOOLEAN\r | |
183 | (EFIAPI *CPL_CIPHER_DECRYPT) (\r | |
184 | IN CONST VOID *Context,\r | |
185 | IN CONST UINT8 *InData,\r | |
186 | OUT UINT8 *OutData,\r | |
187 | IN CONST UINTN DataLength\r | |
188 | );\r | |
189 | \r | |
190 | //\r | |
191 | // The struct used to store the informatino and operation of Cipher algorithm.\r | |
192 | //\r | |
193 | typedef struct _ENCRYPT_ALGORITHM {\r | |
194 | //\r | |
195 | // The ID of the Algorithm\r | |
196 | //\r | |
197 | UINT8 AlgorithmId;\r | |
198 | //\r | |
199 | // The Key length of the Algorithm\r | |
200 | //\r | |
201 | UINTN KeyLength;\r | |
202 | //\r | |
203 | // Iv Size of the Algorithm\r | |
204 | //\r | |
205 | UINTN IvLength;\r | |
206 | //\r | |
207 | // The Block Size of the Algorithm\r | |
208 | //\r | |
209 | UINTN BlockSize;\r | |
210 | //\r | |
211 | // The Function pointer of GetContextSize.\r | |
212 | //\r | |
213 | CPL_CIPHER_GETCONTEXTSIZE CipherGetContextSize;\r | |
214 | //\r | |
215 | // The Function pointer of Cipher intitiaion.\r | |
216 | //\r | |
217 | CPL_CIPHER_INIT CipherInitiate;\r | |
218 | //\r | |
219 | // The Function pointer of Cipher Encryption.\r | |
220 | //\r | |
221 | CPL_CIPHER_ENCRYPT CipherEncrypt;\r | |
222 | //\r | |
223 | // The Function pointer of Cipher Decrption.\r | |
224 | //\r | |
225 | CPL_CIPHER_DECRYPT CipherDecrypt;\r | |
226 | } ENCRYPT_ALGORITHM;\r | |
227 | \r | |
228 | //\r | |
229 | // The struct used to store the informatino and operation of Autahentication algorithm.\r | |
230 | //\r | |
231 | typedef struct _AUTH_ALGORITHM {\r | |
232 | //\r | |
233 | // ID of the Algorithm\r | |
234 | //\r | |
235 | UINT8 AlgorithmId;\r | |
236 | //\r | |
237 | // The Key length of the Algorithm\r | |
238 | //\r | |
239 | UINTN KeyLength;\r | |
240 | //\r | |
241 | // The ICV length of the Algorithm\r | |
242 | //\r | |
243 | UINTN IcvLength;\r | |
244 | //\r | |
245 | // The block size of the Algorithm\r | |
246 | //\r | |
247 | UINTN BlockSize;\r | |
248 | //\r | |
249 | // The function pointer of GetContextSize.\r | |
250 | //\r | |
251 | CPL_HASH_GETCONTEXTSIZE HashGetContextSize;\r | |
252 | //\r | |
253 | // The function pointer of Initiatoion\r | |
254 | //\r | |
255 | CPL_HASH_INIT HashInitiate;\r | |
256 | //\r | |
257 | // The function pointer of Hash Update.\r | |
258 | //\r | |
259 | CPL_HASH_UPDATE HashUpdate;\r | |
260 | //\r | |
261 | // The fucntion pointer of Hash Final\r | |
262 | //\r | |
263 | CPL_HASH_FINAL HashFinal;\r | |
264 | } AUTH_ALGORITHM;\r | |
265 | \r | |
266 | /**\r | |
267 | Get the IV size of encrypt alogrithm. IV size is different from different algorithm.\r | |
268 | \r | |
269 | @param[in] AlgorithmId The encrypt algorithm ID.\r | |
270 | \r | |
271 | @return The value of IV size.\r | |
272 | \r | |
273 | **/\r | |
274 | UINTN\r | |
275 | IpSecGetEncryptIvLength (\r | |
276 | IN UINT8 AlgorithmId\r | |
277 | );\r | |
278 | \r | |
279 | /**\r | |
280 | Get the block size of encrypt alogrithm. Block size is different from different algorithm.\r | |
281 | \r | |
282 | @param[in] AlgorithmId The encrypt algorithm ID.\r | |
283 | \r | |
284 | @return The value of block size.\r | |
285 | \r | |
286 | **/\r | |
287 | UINTN\r | |
288 | IpSecGetEncryptBlockSize (\r | |
289 | IN UINT8 AlgorithmId\r | |
290 | );\r | |
291 | \r | |
292 | /**\r | |
293 | Get the ICV size of Authenticaion alogrithm. ICV size is different from different algorithm.\r | |
294 | \r | |
295 | @param[in] AuthAlgorithmId The Authentication algorithm ID.\r | |
296 | \r | |
297 | @return The value of ICV size.\r | |
298 | \r | |
299 | **/\r | |
300 | UINTN\r | |
301 | IpSecGetIcvLength (\r | |
302 | IN UINT8 AuthAlgorithmId\r | |
303 | );\r | |
304 | \r | |
305 | /**\r | |
306 | Generate a random data for IV. If the IvSize is zero, not needed to create\r | |
307 | IV and return EFI_SUCCESS.\r | |
308 | \r | |
309 | @param[in] IvBuffer The pointer of the IV buffer.\r | |
310 | @param[in] IvSize The IV size.\r | |
311 | \r | |
312 | @retval EFI_SUCCESS Create random data for IV.\r | |
313 | \r | |
314 | **/\r | |
315 | EFI_STATUS\r | |
316 | IpSecGenerateIv (\r | |
317 | IN UINT8 *IvBuffer,\r | |
318 | IN UINTN IvSize\r | |
319 | );\r | |
320 | \r | |
321 | #endif\r | |
322 | \r |