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