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