2 Common operation of the IKE.
4 Copyright (c) 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 _IKE_COMMON_H_
17 #define _IKE_COMMON_H_
19 #include <Protocol/Udp4.h>
20 #include <Protocol/Udp6.h>
21 #include <Protocol/Ip4Config.h>
23 #include <Library/BaseLib.h>
24 #include <Library/BaseMemoryLib.h>
25 #include <Library/MemoryAllocationLib.h>
26 #include <Library/UefiRuntimeServicesTableLib.h>
27 #include <Library/UefiBootServicesTableLib.h>
28 #include <Library/DebugLib.h>
29 #include <Library/UdpIoLib.h>
30 #include <Library/BaseCryptLib.h>
32 #include "Ikev2/Ikev2.h"
33 #include "IpSecImpl.h"
34 #include "IkePacket.h"
35 #include "IpSecCryptIo.h"
38 #define IKE_DEFAULT_PORT 500
39 #define IKE_DEFAULT_TIMEOUT_INTERVAL 10000 // 10s
40 #define IKE_NONCE_SIZE 16
41 #define IKE_MAX_RETRY 4
42 #define IKE_SPI_BASE 0x10000
43 #define PRF_HMAC_SHA1_GUID &gEfiCryptAlgorithmSha1Guid
44 #define IKE_PAYLOAD_SIGNATURE SIGNATURE_32('I','K','E','P')
45 #define IKE_PAYLOAD_BY_PACKET(a) CR(a,IKE_PAYLOAD,ByPacket,IKE_PAYLOAD_SIGNATURE)
48 #define IKE_PACKET_APPEND_PAYLOAD(IkePacket,IkePayload) \
50 InsertTailList(&(IkePacket)->PayloadList, &(IkePayload)->ByPacket); \
53 #define IKE_PACKET_REMOVE_PAYLOAD(IkePacket,IkePayload) \
55 RemoveEntryList(&(IkePayload)->ByPacket); \
58 #define IKE_PACKET_END_PAYLOAD(IkePacket, Node) \
59 Node = GetFirstNode (&(IkePacket)->PayloadList); \
60 while (!IsNodeAtEnd (&(IkePacket)->PayloadList, Node)) { \
61 Node = GetNextNode (&(IkePacket)->PayloadList, Node); \
65 Call Crypto Lib to generate a random value with eight-octet length.
67 @return the 64 byte vaule.
76 Generate the random data for Nonce payload.
78 @param[in] NonceSize Size of the data in bytes.
80 @return Buffer which contains the random data of the spcified size.
89 Convert the IKE Header from Network order to Host order.
91 @param[in, out] Header The pointer of the IKE_HEADER.
96 IN OUT IKE_HEADER
*Header
101 Convert the IKE Header from Host order to Network order.
103 @param[in, out] Header The pointer of the IKE_HEADER.
108 IN OUT IKE_HEADER
*Header
112 Allocate a buffer of IKE_PAYLOAD and set its Signature.
114 @return A buffer of IKE_PAYLOAD.
123 Free a specified IKE_PAYLOAD buffer.
125 @param[in] IkePayload Pointer of IKE_PAYLOAD to be freed.
130 IN IKE_PAYLOAD
*IkePayload
134 Generate an unused SPI
136 @return a SPI in 4 bytes.
145 Generate a random data for IV
147 @param[in] IvBuffer The pointer of the IV buffer.
148 @param[in] IvSize The IV size.
150 @retval EFI_SUCCESS Create a random data for IV.
151 @retval otherwise Failed.
161 Get the IKE Version from the IKE_SA_SESSION.
163 @param[in] Session Pointer of the IKE_SA_SESSION.
167 IkeGetVersionFromSession (
172 Find SPD entry by a specified SPD selector.
174 @param[in] SpdSel Point to SPD Selector to be searched for.
176 @retval Point to Spd Entry if the SPD entry found.
177 @retval NULL if not found.
182 IN EFI_IPSEC_SPD_SELECTOR
*SpdSel
185 extern EFI_GUID mZeroGuid
;
186 extern MODP_GROUP OakleyModpGroup
[];
187 extern IKE_ALG_GUID_INFO mIPsecEncrAlgInfo
[];
188 extern IKE_ALG_GUID_INFO mIPsecAuthAlgInfo
[];