2 Definition related to the Security operation.
4 Copyright (c) 2009 - 2010, Intel Corporation. All rights reserved.<BR>
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.
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.
16 #ifndef _EFI_IPSEC_CRYPTIO_H_
17 #define _EFI_IPSEC_CRYPTIO_H_
19 #include <Protocol/IpSecConfig.h>
20 #include <Library/DebugLib.h>
22 #define IPSEC_ENCRYPT_ALGORITHM_LIST_SIZE 2
23 #define IPSEC_AUTH_ALGORITHM_LIST_SIZE 3
26 Prototype of Hash GetContextSize.
28 Retrieves the size, in bytes, of the context buffer required.
30 @return The size, in bytes, of the context buffer required.
35 (EFIAPI
*CPL_HASH_GETCONTEXTSIZE
) (
40 Prototype of Hash Operation Initiating.
42 Initialization with a new context.
45 @param[in,out] Context Input Context.
47 @retval TRUE Initialization Successfully.
52 (EFIAPI
*CPL_HASH_INIT
) (
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.
61 If Context is NULL, then ASSERT().
62 If Data is NULL, then ASSERT().
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.
68 @retval TRUE Update data successfully.
69 @retval FALSE The Context has been finalized.
74 (EFIAPI
*CPL_HASH_UPDATE
) (
81 Prototype of Hash finallization.
82 Terminate a Hash message digest operation and output the message digest.
84 If Context is NULL, then ASSERT().
85 If HashValue is NULL, then ASSERT().
87 @param[in,out] Context The specified Context.
88 @param[out] HashValue Pointer to a 16-byte message digest output buffer.
90 @retval TRUE Finalized successfully.
95 (EFIAPI
*CPL_HASH_FINAL
) (
101 Prototype of Cipher GetContextSize.
103 Retrieves the size, in bytes, of the context buffer required.
105 @return The size, in bytes, of the context buffer required.
110 (EFIAPI
*CPL_CIPHER_GETCONTEXTSIZE
) (
115 Prototype of Cipher initiation.
116 Intializes the user-supplied key as the specifed context (key materials) for both
117 encryption and decryption operations.
119 If Context is NULL, then ASSERT().
120 If Key is NULL, then generate random key for usage.
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.
126 @retval TRUE TDES Initialization was successful.
131 (EFIAPI
*CPL_CIPHER_INIT
) (
132 IN OUT VOID
*Context
,
134 IN CONST UINTN KeyBits
139 Prototype of Cipher encryption.
140 Encrypts plaintext message with the specified cipher.
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,
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.
152 @retval TRUE Encryption successful.
157 (EFIAPI
*CPL_CIPHER_ENCRYPT
) (
159 IN CONST UINT8
*InData
,
161 IN CONST UINTN DataLength
166 Prototype of Cipher decryption.
167 Decrypts cipher message with specified cipher.
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().
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.
178 @retval TRUE Decryption successful.
183 (EFIAPI
*CPL_CIPHER_DECRYPT
) (
184 IN CONST VOID
*Context
,
185 IN CONST UINT8
*InData
,
187 IN CONST UINTN DataLength
191 // The struct used to store the informatino and operation of Cipher algorithm.
193 typedef struct _ENCRYPT_ALGORITHM
{
195 // The ID of the Algorithm
199 // The Key length of the Algorithm
203 // Iv Size of the Algorithm
207 // The Block Size of the Algorithm
211 // The Function pointer of GetContextSize.
213 CPL_CIPHER_GETCONTEXTSIZE CipherGetContextSize
;
215 // The Function pointer of Cipher intitiaion.
217 CPL_CIPHER_INIT CipherInitiate
;
219 // The Function pointer of Cipher Encryption.
221 CPL_CIPHER_ENCRYPT CipherEncrypt
;
223 // The Function pointer of Cipher Decrption.
225 CPL_CIPHER_DECRYPT CipherDecrypt
;
229 // The struct used to store the informatino and operation of Autahentication algorithm.
231 typedef struct _AUTH_ALGORITHM
{
233 // ID of the Algorithm
237 // The Key length of the Algorithm
241 // The ICV length of the Algorithm
245 // The block size of the Algorithm
249 // The function pointer of GetContextSize.
251 CPL_HASH_GETCONTEXTSIZE HashGetContextSize
;
253 // The function pointer of Initiatoion
255 CPL_HASH_INIT HashInitiate
;
257 // The function pointer of Hash Update.
259 CPL_HASH_UPDATE HashUpdate
;
261 // The fucntion pointer of Hash Final
263 CPL_HASH_FINAL HashFinal
;
267 Get the IV size of encrypt alogrithm. IV size is different from different algorithm.
269 @param[in] AlgorithmId The encrypt algorithm ID.
271 @return The value of IV size.
275 IpSecGetEncryptIvLength (
280 Get the block size of encrypt alogrithm. Block size is different from different algorithm.
282 @param[in] AlgorithmId The encrypt algorithm ID.
284 @return The value of block size.
288 IpSecGetEncryptBlockSize (
293 Get the ICV size of Authenticaion alogrithm. ICV size is different from different algorithm.
295 @param[in] AuthAlgorithmId The Authentication algorithm ID.
297 @return The value of ICV size.
302 IN UINT8 AuthAlgorithmId
306 Generate a random data for IV. If the IvSize is zero, not needed to create
307 IV and return EFI_SUCCESS.
309 @param[in] IvBuffer The pointer of the IV buffer.
310 @param[in] IvSize The IV size.
312 @retval EFI_SUCCESS Create random data for IV.