]> git.proxmox.com Git - mirror_edk2.git/blame - NetworkPkg/IpSecDxe/IpSecCryptIo.c
Add NetworkPkg (P.UDK2010.UP3.Network.P1)
[mirror_edk2.git] / NetworkPkg / IpSecDxe / IpSecCryptIo.c
CommitLineData
a3bcde70
HT
1/** @file\r
2 Common operation for Security.\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#include "IpSecCryptIo.h"\r
17//\r
18// Alogrithm's informations for the Encrypt/Decrpt Alogrithm.\r
19//\r
20ENCRYPT_ALGORITHM mIpsecEncryptAlgorithmList[IPSEC_ENCRYPT_ALGORITHM_LIST_SIZE] = {\r
21 {EFI_IPSEC_EALG_NULL, 0, 0, 1, NULL, NULL, NULL, NULL},\r
22 {(UINT8)-1, 0, 0, 0, NULL, NULL, NULL, NULL}\r
23};\r
24//\r
25// Alogrithm's informations for the Authentication algorithm\r
26//\r
27AUTH_ALGORITHM mIpsecAuthAlgorithmList[IPSEC_AUTH_ALGORITHM_LIST_SIZE] = {\r
28 {EFI_IPSEC_AALG_NONE, 0, 0, 0, NULL, NULL, NULL, NULL},\r
29 {EFI_IPSEC_AALG_NULL, 0, 0, 0, NULL, NULL, NULL, NULL},\r
30 {(UINT8)-1, 0, 0, 0, NULL, NULL, NULL, NULL}\r
31};\r
32\r
33\r
34/**\r
35 Get the block size of encrypt alogrithm. The block size is based on the algorithm used.\r
36\r
37 @param[in] AlgorithmId The encrypt algorithm ID.\r
38\r
39 @return The value of block size.\r
40\r
41**/\r
42UINTN\r
43IpSecGetEncryptBlockSize (\r
44 IN UINT8 AlgorithmId\r
45 )\r
46{\r
47 UINT8 Index;\r
48\r
49 for (Index = 0; Index < IPSEC_ENCRYPT_ALGORITHM_LIST_SIZE; Index++) {\r
50 if (AlgorithmId == mIpsecEncryptAlgorithmList[Index].AlgorithmId) {\r
51 //\r
52 // The BlockSize is same with IvSize.\r
53 //\r
54 return mIpsecEncryptAlgorithmList[Index].BlockSize;\r
55 }\r
56 }\r
57\r
58 return (UINTN) -1;\r
59}\r
60\r
61/**\r
62 Get the IV size of encrypt alogrithm. The IV size is based on the algorithm used.\r
63\r
64 @param[in] AlgorithmId The encrypt algorithm ID.\r
65\r
66 @return The value of IV size.\r
67\r
68**/\r
69UINTN\r
70IpSecGetEncryptIvLength (\r
71 IN UINT8 AlgorithmId\r
72 )\r
73{\r
74 UINT8 Index;\r
75\r
76 for (Index = 0; Index < IPSEC_ENCRYPT_ALGORITHM_LIST_SIZE; Index++) {\r
77 if (AlgorithmId == mIpsecEncryptAlgorithmList[Index].AlgorithmId) {\r
78 //\r
79 // The BlockSize is same with IvSize.\r
80 //\r
81 return mIpsecEncryptAlgorithmList[Index].IvLength;\r
82 }\r
83 }\r
84\r
85 return (UINTN) -1;\r
86}\r
87\r
88/**\r
89 Get the ICV size of Authenticaion alogrithm. The ICV size is based on the algorithm used.\r
90\r
91 @param[in] AuthAlgorithmId The Authentication algorithm ID.\r
92\r
93 @return The value of ICV size.\r
94\r
95**/\r
96UINTN\r
97IpSecGetIcvLength (\r
98 IN UINT8 AuthAlgorithmId\r
99 )\r
100{\r
101 UINT8 Index;\r
102 for (Index = 0; Index < IPSEC_AUTH_ALGORITHM_LIST_SIZE; Index++) {\r
103 if (AuthAlgorithmId == mIpsecAuthAlgorithmList[Index].AlgorithmId) {\r
104 return mIpsecAuthAlgorithmList[Index].IcvLength;\r
105 }\r
106 }\r
107 return (UINTN) -1;\r
108}\r
109\r
110/**\r
111 Generate a random data for IV. If the IvSize is zero, not needed to create\r
112 IV and return EFI_SUCCESS.\r
113\r
114 @param[in] IvBuffer The pointer of the IV buffer.\r
115 @param[in] IvSize The IV size.\r
116\r
117 @retval EFI_SUCCESS Create a random data for IV.\r
118\r
119**/\r
120EFI_STATUS\r
121IpSecGenerateIv (\r
122 IN UINT8 *IvBuffer,\r
123 IN UINTN IvSize\r
124 )\r
125{\r
126 if (IvSize != 0) {\r
127 //\r
128 //TODO: return CryptGenerateRandom (IvBuffer, IvSize);\r
129 //\r
130 return EFI_SUCCESS;\r
131 }\r
132 return EFI_SUCCESS;\r
133}\r