2 Common operation of the IKE.
4 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #ifndef _IKE_COMMON_H_
11 #define _IKE_COMMON_H_
13 #include <Protocol/Udp4.h>
14 #include <Protocol/Udp6.h>
15 #include <Protocol/Ip4Config2.h>
17 #include <Library/BaseLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/MemoryAllocationLib.h>
20 #include <Library/UefiRuntimeServicesTableLib.h>
21 #include <Library/UefiBootServicesTableLib.h>
22 #include <Library/DebugLib.h>
23 #include <Library/UdpIoLib.h>
24 #include <Library/BaseCryptLib.h>
26 #include "Ikev2/Ikev2.h"
27 #include "IpSecImpl.h"
28 #include "IkePacket.h"
29 #include "IpSecCryptIo.h"
32 #define IKE_DEFAULT_PORT 500
33 #define IKE_DEFAULT_TIMEOUT_INTERVAL 10000 // 10s
34 #define IKE_NONCE_SIZE 16
35 #define IKE_MAX_RETRY 4
36 #define IKE_SPI_BASE 0x100
37 #define IKE_PAYLOAD_SIGNATURE SIGNATURE_32('I','K','E','P')
38 #define IKE_PAYLOAD_BY_PACKET(a) CR(a,IKE_PAYLOAD,ByPacket,IKE_PAYLOAD_SIGNATURE)
41 #define IKE_PACKET_APPEND_PAYLOAD(IkePacket,IkePayload) \
43 InsertTailList(&(IkePacket)->PayloadList, &(IkePayload)->ByPacket); \
46 #define IKE_PACKET_REMOVE_PAYLOAD(IkePacket,IkePayload) \
48 RemoveEntryList(&(IkePayload)->ByPacket); \
51 #define IKE_PACKET_END_PAYLOAD(IkePacket, Node) \
52 Node = GetFirstNode (&(IkePacket)->PayloadList); \
53 while (!IsNodeAtEnd (&(IkePacket)->PayloadList, Node)) { \
54 Node = GetNextNode (&(IkePacket)->PayloadList, Node); \
58 Call Crypto Lib to generate a random value with eight-octet length.
60 @return the 64 byte vaule.
69 Generate the random data for Nonce payload.
71 @param[in] NonceSize Size of the data in bytes.
73 @return Buffer which contains the random data of the spcified size.
82 Convert the IKE Header from Network order to Host order.
84 @param[in, out] Header The pointer of the IKE_HEADER.
89 IN OUT IKE_HEADER
*Header
94 Convert the IKE Header from Host order to Network order.
96 @param[in, out] Header The pointer of the IKE_HEADER.
101 IN OUT IKE_HEADER
*Header
105 Allocate a buffer of IKE_PAYLOAD and set its Signature.
107 @return A buffer of IKE_PAYLOAD.
116 Free a specified IKE_PAYLOAD buffer.
118 @param[in] IkePayload Pointer of IKE_PAYLOAD to be freed.
123 IN IKE_PAYLOAD
*IkePayload
129 @param[in] IkeSaSession Pointer to IKEV2_SA_SESSION related to this Child SA
131 @param[in, out] SpiValue Pointer to the new generated SPI value.
133 @retval EFI_SUCCESS The operation performs successfully.
134 @retval Otherwise The operation is failed.
139 IN IKEV2_SA_SESSION
*IkeSaSession
,
140 IN OUT UINT32
*SpiValue
144 Generate a random data for IV
146 @param[in] IvBuffer The pointer of the IV buffer.
147 @param[in] IvSize The IV size.
149 @retval EFI_SUCCESS Create a random data for IV.
150 @retval otherwise Failed.
160 Get the IKE Version from the IKE_SA_SESSION.
162 @param[in] Session Pointer of the IKE_SA_SESSION.
166 IkeGetVersionFromSession (
171 Find SPD entry by a specified SPD selector.
173 @param[in] SpdSel Point to SPD Selector to be searched for.
175 @retval Point to Spd Entry if the SPD entry found.
176 @retval NULL if not found.
181 IN EFI_IPSEC_SPD_SELECTOR
*SpdSel
184 extern MODP_GROUP OakleyModpGroup
[];
185 extern IKE_ALG_GUID_INFO mIPsecEncrAlgInfo
[];
186 extern IKE_ALG_GUID_INFO mIPsecAuthAlgInfo
[];