2 The interfaces of IKE/Child session operations and payload related operations
3 used by IKE Exchange Process.
5 Copyright (c) 2010 - 2018, Intel Corporation. All rights reserved.<BR>
7 This program and the accompanying materials
8 are licensed and made available under the terms and conditions of the BSD License
9 which accompanies this distribution. The full text of the license may be found at
10 http://opensource.org/licenses/bsd-license.php.
12 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
13 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #ifndef _IKE_V2_UTILITY_H_
18 #define _IKE_V2_UTILITY_H_
21 #include "IkeCommon.h"
22 #include "IpSecCryptIo.h"
24 #include <Library/PcdLib.h>
26 #define IKEV2_SUPPORT_ENCRYPT_ALGORITHM_NUM 2
27 #define IKEV2_SUPPORT_PRF_ALGORITHM_NUM 1
28 #define IKEV2_SUPPORT_DH_ALGORITHM_NUM 2
29 #define IKEV2_SUPPORT_AUTH_ALGORITHM_NUM 1
32 Allocate buffer for IKEV2_SA_SESSION and initialize it.
34 @param[in] Private Pointer to IPSEC_PRIVATE_DATA.
35 @param[in] UdpService Pointer to IKE_UDP_SERVICE related to this IKE SA Session.
37 @return Pointer to IKEV2_SA_SESSION.
42 IN IPSEC_PRIVATE_DATA
*Private
,
43 IN IKE_UDP_SERVICE
*UdpService
47 Register Establish IKEv2 SA into Private->Ikev2EstablishedList.
49 @param[in] IkeSaSession Pointer to IKEV2_SA_SESSION to be registered.
50 @param[in] Private Pointer to IPSEC_PRAVATE_DATA.
55 IN IKEV2_SA_SESSION
*IkeSaSession
,
56 IN IPSEC_PRIVATE_DATA
*Private
60 Find a IKEV2_SA_SESSION by the remote peer IP.
62 @param[in] SaSessionList SaSession List to be searched.
63 @param[in] RemotePeerIp Pointer to specified IP address.
65 @return Pointer to IKEV2_SA_SESSION if find one or NULL.
69 Ikev2SaSessionLookup (
70 IN LIST_ENTRY
*SaSessionList
,
71 IN EFI_IP_ADDRESS
*RemotePeerIp
75 Insert a IKE_SA_SESSION into IkeSaSession list. The IkeSaSession list is either
76 Private->Ikev2SaSession list or Private->Ikev2EstablishedList list.
78 @param[in] SaSessionList Pointer to list to be inserted into.
79 @param[in] IkeSaSession Pointer to IKEV2_SA_SESSION to be inserted.
80 @param[in] RemotePeerIp Pointer to EFI_IP_ADDRESSS to indicate the
81 unique IKEV2_SA_SESSION.
85 Ikev2SaSessionInsert (
86 IN LIST_ENTRY
*SaSessionList
,
87 IN IKEV2_SA_SESSION
*IkeSaSession
,
88 IN EFI_IP_ADDRESS
*RemotePeerIp
92 Remove the SA Session by Remote Peer IP.
94 @param[in] SaSessionList Pointer to list to be searched.
95 @param[in] RemotePeerIp Pointer to EFI_IP_ADDRESS to use for SA Session search.
97 @retval Pointer to IKEV2_SA_SESSION with the specified remote IP address.
101 Ikev2SaSessionRemove (
102 IN LIST_ENTRY
*SaSessionList
,
103 IN EFI_IP_ADDRESS
*RemotePeerIp
108 After IKE/Child SA is estiblished, close the time event and free sent packet.
110 @param[in] SessionCommon Pointer to a Session Common.
114 Ikev2SessionCommonRefresh (
115 IN IKEV2_SESSION_COMMON
*SessionCommon
119 Free specified IKEV2 SA Session.
121 @param[in] IkeSaSession Pointer to IKEV2_SA_SESSION to be freed.
126 IN IKEV2_SA_SESSION
*IkeSaSession
130 Free specified Seession Common. The session common would belong to a IKE SA or
133 @param[in] SessionCommon Pointer to a Session Common.
137 Ikev2SaSessionCommonFree (
138 IN IKEV2_SESSION_COMMON
*SessionCommon
142 Increase the MessageID in IkeSaSession.
144 @param[in] IkeSaSession Pointer to a specified IKEV2_SA_SESSION.
148 Ikev2SaSessionIncreaseMessageId (
149 IN IKEV2_SA_SESSION
*IkeSaSession
153 Allocate Momery for IKEV2 Child SA Session.
155 @param[in] UdpService Pointer to IKE_UDP_SERVICE.
156 @param[in] IkeSaSession Pointer to IKEV2_SA_SESSION related to this Child SA
159 @retval Pointer of a new created IKEV2 Child SA Session.
162 IKEV2_CHILD_SA_SESSION
*
163 Ikev2ChildSaSessionAlloc (
164 IN IKE_UDP_SERVICE
*UdpService
,
165 IN IKEV2_SA_SESSION
*IkeSaSession
169 Register a established IKEv2 Child SA into IkeSaSession->ChildSaEstablishSessionList.
170 If the there is IKEV2_CHILD_SA_SESSION with same remote peer IP, remove the old one
171 then register the new one.
173 @param[in] ChildSaSession Pointer to IKEV2_CHILD_SA_SESSION to be registered.
174 @param[in] Private Pointer to IPSEC_PRAVATE_DATA.
178 Ikev2ChildSaSessionReg (
179 IN IKEV2_CHILD_SA_SESSION
*ChildSaSession
,
180 IN IPSEC_PRIVATE_DATA
*Private
184 This function find the Child SA by the specified Spi.
186 This functin find a ChildSA session by searching the ChildSaSessionlist of
187 the input IKEV2_SA_SESSION by specified MessageID.
189 @param[in] SaSessionList Pointer to List to be searched.
190 @param[in] Spi Specified SPI.
192 @return Pointer to IKEV2_CHILD_SA_SESSION.
195 IKEV2_CHILD_SA_SESSION
*
196 Ikev2ChildSaSessionLookupBySpi (
197 IN LIST_ENTRY
*SaSessionList
,
203 Insert a Child SA Session into the specified ChildSa list..
205 @param[in] SaSessionList Pointer to list to be inserted in.
206 @param[in] ChildSaSession Pointer to IKEV2_CHILD_SA_SESSION to be inserted.
210 Ikev2ChildSaSessionInsert (
211 IN LIST_ENTRY
*SaSessionList
,
212 IN IKEV2_CHILD_SA_SESSION
*ChildSaSession
216 Remove the IKEV2_CHILD_SA_SESSION from IkeSaSessionList.
218 @param[in] SaSessionList The SA Session List to be iterated.
219 @param[in] Spi Spi used to identify the IKEV2_CHILD_SA_SESSION.
220 @param[in] ListType The type of the List to indicate whether it is a
223 @return The point to IKEV2_CHILD_SA_SESSION.
226 IKEV2_CHILD_SA_SESSION
*
227 Ikev2ChildSaSessionRemove (
228 IN LIST_ENTRY
*SaSessionList
,
235 Free the memory located for the specified IKEV2_CHILD_SA_SESSION.
237 @param[in] ChildSaSession Pointer to IKEV2_CHILD_SA_SESSION.
241 Ikev2ChildSaSessionFree (
242 IN IKEV2_CHILD_SA_SESSION
*ChildSaSession
246 Free the specified DhBuffer.
248 @param[in] DhBuffer Pointer to IKEV2_DH_BUFFER to be freed.
253 IN IKEV2_DH_BUFFER
*DhBuffer
257 Delete the specified established Child SA.
259 This function delete the Child SA directly and dont send the Information Packet to
262 @param[in] IkeSaSession Pointer to a IKE SA Session used to be searched for.
263 @param[in] Spi SPI used to find the Child SA.
265 @retval EFI_NOT_FOUND Pointer of IKE SA Session is NULL.
266 @retval EFI_NOT_FOUND There is no specified Child SA related with the input
267 SPI under this IKE SA Session.
268 @retval EFI_SUCCESS Delete the Child SA successfully.
272 Ikev2ChildSaSilentDelete (
273 IN IKEV2_SA_SESSION
*IkeSaSession
,
278 This function is to parse a request IKE packet and return its request type.
279 The request type is one of IKE CHILD SA creation, IKE SA rekeying and
280 IKE CHILD SA rekeying.
282 @param[in] IkePacket IKE packet to be prased.
284 return the type of the IKE packet.
287 IKEV2_CREATE_CHILD_REQUEST_TYPE
288 Ikev2ChildExchangeRequestType(
289 IN IKE_PACKET
*IkePacket
294 Associate a SPD selector to the Child SA Session.
296 This function is called when the Child SA is not the first child SA of its
297 IKE SA. It associate a SPD to this Child SA.
299 @param[in, out] ChildSaSession Pointer to the Child SA Session to be associated to
302 @retval EFI_SUCCESS Associate one SPD selector to this Child SA Session successfully.
303 @retval EFI_NOT_FOUND Can't find the related SPD selector.
307 Ikev2ChildSaAssociateSpdEntry (
308 IN OUT IKEV2_CHILD_SA_SESSION
*ChildSaSession
312 Validate the IKE header of received IKE packet.
314 @param[in] IkeSaSession Pointer to IKEV2_SA_SESSION related to this IKE packet.
315 @param[in] IkeHdr Pointer to IKE header of received IKE packet.
317 @retval TRUE If the IKE header is valid.
318 @retval FALSE If the IKE header is invalid.
322 Ikev2ValidateHeader (
323 IN IKEV2_SA_SESSION
*IkeSaSession
,
324 IN IKE_HEADER
*IkeHdr
328 Create and intialize IKEV2_SA_DATA for speicifed IKEV2_SESSION_COMMON.
330 This function will be only called by the initiator. The responder's IKEV2_SA_DATA
331 will be generated during parsed the initiator packet.
333 @param[in] SessionCommon Pointer to IKEV2_SESSION_COMMON related to.
335 @retval a Pointer to a new IKEV2_SA_DATA or NULL.
339 Ikev2InitializeSaData (
340 IN IKEV2_SESSION_COMMON
*SessionCommon
344 Store the SA into SAD.
346 @param[in] ChildSaSession Pointer to IKEV2_CHILD_SA_SESSION.
351 IN IKEV2_CHILD_SA_SESSION
*ChildSaSession
355 Routine process before the payload decoding.
357 @param[in] SessionCommon Pointer to ChildSa SessionCommon.
358 @param[in] PayloadBuf Pointer to the payload.
359 @param[in] PayloadSize Size of PayloadBuf in byte.
360 @param[in] PayloadType Type of Payload.
364 Ikev2ChildSaBeforeDecodePayload (
365 IN UINT8
*SessionCommon
,
366 IN UINT8
*PayloadBuf
,
367 IN UINTN PayloadSize
,
372 Routine Process after the encode payload.
374 @param[in] SessionCommon Pointer to ChildSa SessionCommon.
375 @param[in] PayloadBuf Pointer to the payload.
376 @param[in] PayloadSize Size of PayloadBuf in byte.
377 @param[in] PayloadType Type of Payload.
381 Ikev2ChildSaAfterEncodePayload (
382 IN UINT8
*SessionCommon
,
383 IN UINT8
*PayloadBuf
,
384 IN UINTN PayloadSize
,
389 Generate Ikev2 SA payload according to SessionSaData
391 @param[in] SessionSaData The data used in SA payload.
392 @param[in] NextPayload The payload type presented in NextPayload field of
394 @param[in] Type The SA type. It MUST be neither (1) for IKE_SA or
395 (2) for CHILD_SA or (3) for INFO.
397 @retval a Pointer to SA IKE payload.
401 Ikev2GenerateSaPayload (
402 IN IKEV2_SA_DATA
*SessionSaData
,
403 IN UINT8 NextPayload
,
404 IN IKE_SESSION_TYPE Type
408 Generate a ID payload.
410 @param[in] CommonSession Pointer to IKEV2_SESSION_COMMON related to ID payload.
411 @param[in] NextPayload The payload type presented in the NextPayload field
412 of ID Payload header.
414 @retval Pointer to ID IKE payload.
418 Ikev2GenerateIdPayload (
419 IN IKEV2_SESSION_COMMON
*CommonSession
,
424 Generate a ID payload.
426 @param[in] CommonSession Pointer to IKEV2_SESSION_COMMON related to ID payload.
427 @param[in] NextPayload The payload type presented in the NextPayload field
428 of ID Payload header.
429 @param[in] InCert Pointer to the Certificate which distinguished name
430 will be added into the Id payload.
431 @param[in] CertSize Size of the Certificate.
433 @retval Pointer to ID IKE payload.
437 Ikev2GenerateCertIdPayload (
438 IN IKEV2_SESSION_COMMON
*CommonSession
,
439 IN UINT8 NextPayload
,
445 Generate a Nonce payload contenting the input parameter NonceBuf.
447 @param[in] NonceBuf The nonce buffer content the whole Nonce payload block
448 except the payload header.
449 @param[in] NonceSize The buffer size of the NonceBuf
450 @param[in] NextPayload The payload type presented in the NextPayload field
451 of Nonce Payload header.
453 @retval Pointer to Nonce IKE paload.
457 Ikev2GenerateNoncePayload (
464 Generate the Notify payload.
466 Since the structure of Notify payload which defined in RFC 4306 is simple, so
467 there is no internal data structure for Notify payload. This function generate
468 Notify payload defined in RFC 4306, but all the fields in this payload are still
469 in host order and need call Ikev2EncodePayload() to convert those fields from
470 the host order to network order beforing sending it.
472 @param[in] ProtocolId The protocol type ID. For IKE_SA it MUST be one (1).
473 For IPsec SAs it MUST be neither (2) for AH or (3)
475 @param[in] NextPayload The next paylaod type in NextPayload field of
477 @param[in] SpiSize Size of the SPI in SPI size field of the Notify Payload.
478 @param[in] MessageType The message type in NotifyMessageType field of the
480 @param[in] SpiBuf Pointer to buffer contains the SPI value.
481 @param[in] NotifyData Pointer to buffer contains the notification data.
482 @param[in] NotifyDataSize The size of NotifyData in bytes.
485 @retval Pointer to IKE Notify Payload.
489 Ikev2GenerateNotifyPayload (
491 IN UINT8 NextPayload
,
493 IN UINT16 MessageType
,
495 IN UINT8
*NotifyData
,
496 IN UINTN NotifyDataSize
500 Generate the Delete payload.
502 Since the structure of Delete payload which defined in RFC 4306 is simple,
503 there is no internal data structure for Delete payload. This function generate
504 Delete payload defined in RFC 4306, but all the fields in this payload are still
505 in host order and need call Ikev2EncodePayload() to convert those fields from
506 the host order to network order beforing sending it.
508 @param[in] IkeSaSession Pointer to IKE SA Session to be used of Delete payload generation.
509 @param[in] NextPayload The next paylaod type in NextPayload field of
511 @param[in] SpiSize Size of the SPI in SPI size field of the Delete Payload.
512 @param[in] SpiNum Number of SPI in NumofSPIs field of the Delete Payload.
513 @param[in] SpiBuf Pointer to buffer contains the SPI value.
515 @retval Pointer to IKE Delete Payload.
519 Ikev2GenerateDeletePayload (
520 IN IKEV2_SA_SESSION
*IkeSaSession
,
521 IN UINT8 NextPayload
,
528 Generate the Configuration payload.
530 This function generates a configuration payload defined in RFC 4306, but all the
531 fields in this payload are still in host order and need call Ikev2EncodePayload()
532 to convert those fields from the host order to network order beforing sending it.
534 @param[in] IkeSaSession Pointer to IKE SA Session to be used for Delete payload
536 @param[in] NextPayload The next paylaod type in NextPayload field of
538 @param[in] CfgType The attribute type in the Configuration attribute.
540 @retval Pointer to IKE CP Payload.
544 Ikev2GenerateCpPayload (
545 IN IKEV2_SA_SESSION
*IkeSaSession
,
546 IN UINT8 NextPayload
,
551 Generate a Authentication Payload.
553 This function is used for both Authentication generation and verification. When the
554 IsVerify is TRUE, it create a Auth Data for verification. This function choose the
555 related IKE_SA_INIT Message for Auth data creation according to the IKE Session's type
556 and the value of IsVerify parameter.
558 @param[in] IkeSaSession Pointer to IKEV2_SA_SESSION related to.
559 @param[in] IdPayload Pointer to the ID payload to be used for Authentication
561 @param[in] NextPayload The type filled into the Authentication Payload next
563 @param[in] IsVerify If it is TURE, the Authentication payload is used for
566 @return pointer to IKE Authentication payload for pre-shard key method.
570 Ikev2PskGenerateAuthPayload (
571 IN IKEV2_SA_SESSION
*IkeSaSession
,
572 IN IKE_PAYLOAD
*IdPayload
,
573 IN UINT8 NextPayload
,
578 Generate a Authentication Payload for Certificate Auth method.
580 This function has two functions. One is creating a local Authentication
581 Payload for sending and other is creating the remote Authentication data
582 for verification when the IsVerify is TURE.
584 @param[in] IkeSaSession Pointer to IKEV2_SA_SESSION related to.
585 @param[in] IdPayload Pointer to the ID payload to be used for Authentication
587 @param[in] NextPayload The type filled into the Authentication Payload
589 @param[in] IsVerify If it is TURE, the Authentication payload is used
591 @param[in] UefiPrivateKey Pointer to the UEFI private key. Ignore it when
592 verify the authenticate payload.
593 @param[in] UefiPrivateKeyLen The size of UefiPrivateKey in bytes. Ignore it
594 when verify the authenticate payload.
595 @param[in] UefiKeyPwd Pointer to the password of UEFI private key.
596 Ignore it when verify the authenticate payload.
597 @param[in] UefiKeyPwdLen The size of UefiKeyPwd in bytes.Ignore it when
598 verify the authenticate payload.
600 @return pointer to IKE Authentication payload for certification method.
604 Ikev2CertGenerateAuthPayload (
605 IN IKEV2_SA_SESSION
*IkeSaSession
,
606 IN IKE_PAYLOAD
*IdPayload
,
607 IN UINT8 NextPayload
,
609 IN UINT8
*UefiPrivateKey
,
610 IN UINTN UefiPrivateKeyLen
,
611 IN UINT8
*UefiKeyPwd
,
612 IN UINTN UefiKeyPwdLen
618 This function generates TSi or TSr payload according to type of next payload.
619 If the next payload is Responder TS, gereate TSi Payload. Otherwise, generate
622 @param[in] ChildSa Pointer to IKEV2_CHILD_SA_SESSION related to this TS payload.
623 @param[in] NextPayload The payload type presented in the NextPayload field
624 of ID Payload header.
625 @param[in] IsTunnel It indicates that if the Ts Payload is after the CP payload.
626 If yes, it means the Tsi and Tsr payload should be with
627 Max port range and address range and protocol is marked
630 @retval Pointer to Ts IKE payload.
634 Ikev2GenerateTsPayload (
635 IN IKEV2_CHILD_SA_SESSION
*ChildSa
,
636 IN UINT8 NextPayload
,
641 Parser the Notify Cookie payload.
643 This function parses the Notify Cookie payload.If the Notify ProtocolId is not
644 IPSEC_PROTO_ISAKMP or if the SpiSize is not zero or if the MessageType is not
645 the COOKIE, return EFI_INVALID_PARAMETER.
647 @param[in] IkeNCookie Pointer to the IKE_PAYLOAD which contians the
648 Notify Cookie payload.
650 @param[in, out] IkeSaSession Pointer to the relevant IKE SA Session.
652 @retval EFI_SUCCESS The Notify Cookie Payload is valid.
653 @retval EFI_INVALID_PARAMETER The Notify Cookie Payload is invalid.
654 @retval EFI_OUT_OF_RESOURCE The required resource can't be allocated.
658 Ikev2ParserNotifyCookiePayload (
659 IN IKE_PAYLOAD
*IkeNCookie
,
660 IN OUT IKEV2_SA_SESSION
*IkeSaSession
664 Generate the Certificate payload or Certificate Request Payload.
666 Since the Certificate Payload structure is same with Certificate Request Payload,
667 the only difference is that one contains the Certificate Data, other contains
668 the acceptable certificateion CA. This function generate Certificate payload
669 or Certificate Request Payload defined in RFC 4306, but all the fields
670 in the payload are still in host order and need call Ikev2EncodePayload()
671 to convert those fields from the host order to network order beforing sending it.
673 @param[in] IkeSaSession Pointer to IKE SA Session to be used of Delete payload
675 @param[in] NextPayload The next paylaod type in NextPayload field of
677 @param[in] Certificate Pointer of buffer contains the certification data.
678 @param[in] CertificateLen The length of Certificate in byte.
679 @param[in] EncodeType Specified the Certificate Encodeing which is defined
681 @param[in] IsRequest To indicate create Certificate Payload or Certificate
682 Request Payload. If it is TURE, create Certificate
683 Request Payload. Otherwise, create Certificate Payload.
685 @retval a Pointer to IKE Payload whose payload buffer containing the Certificate
686 payload or Certificated Request payload.
690 Ikev2GenerateCertificatePayload (
691 IN IKEV2_SA_SESSION
*IkeSaSession
,
692 IN UINT8 NextPayload
,
693 IN UINT8
*Certificate
,
694 IN UINTN CertificateLen
,
700 General interface of payload encoding.
702 This function encode the internal data structure into payload which
703 is defined in RFC 4306. The IkePayload->PayloadBuf used to store both the input
704 payload and converted payload. Only the SA payload use the interal structure
705 to store the attribute. Other payload use structure which is same with the RFC
706 defined, for this kind payloads just do host order to network order change of
709 @param[in] SessionCommon Pointer to IKE Session Common used to encode the payload.
710 @param[in, out] IkePayload Pointer to IKE payload to be encode as input, and
711 store the encoded result as output.
713 @retval EFI_INVALID_PARAMETER Meet error when encode the SA payload.
714 @retval EFI_SUCCESS Encode successfully.
719 IN UINT8
*SessionCommon
,
720 IN OUT IKE_PAYLOAD
*IkePayload
724 The general interface of decode Payload.
726 This function convert the received Payload into internal structure.
728 @param[in] SessionCommon Pointer to IKE Session Common to use for decoding.
729 @param[in, out] IkePayload Pointer to IKE payload to be decode as input, and
730 store the decoded result as output.
732 @retval EFI_INVALID_PARAMETER Meet error when decode the SA payload.
733 @retval EFI_SUCCESS Decode successfully.
738 IN UINT8
*SessionCommon
,
739 IN OUT IKE_PAYLOAD
*IkePayload
745 This function decrpt the Encrypted IKE packet and put the result into IkePacket->PayloadBuf.
747 @param[in] SessionCommon Pointer to IKEV2_SESSION_COMMON containing
748 some parameter used during decrypting.
749 @param[in, out] IkePacket Point to IKE_PACKET to be decrypted as input,
750 and the decrypted reslult as output.
751 @param[in, out] IkeType The type of IKE. IKE_SA_TYPE, IKE_INFO_TYPE and
752 IKE_CHILD_TYPE are supportted.
754 @retval EFI_INVALID_PARAMETER If the IKE packet length is zero or the
755 IKE packet length is not Algorithm Block Size
757 @retval EFI_SUCCESS Decrypt IKE packet successfully.
762 IN IKEV2_SESSION_COMMON
*SessionCommon
,
763 IN OUT IKE_PACKET
*IkePacket
,
770 This function encrypt IKE packet before sending it. The Encrypted IKE packet
771 is put in to IKEV2 Encrypted Payload.
773 @param[in] SessionCommon Pointer to IKEV2_SESSION_COMMON related to the IKE packet.
774 @param[in, out] IkePacket Pointer to IKE packet to be encrypted.
776 @retval EFI_SUCCESS Operation is successful.
777 @retval Others OPeration is failed.
782 IN IKEV2_SESSION_COMMON
*SessionCommon
,
783 IN OUT IKE_PACKET
*IkePacket
787 Encode the IKE packet.
789 This function put all Payloads into one payload then encrypt it if needed.
791 @param[in] SessionCommon Pointer to IKEV2_SESSION_COMMON containing
792 some parameter used during IKE packet encoding.
793 @param[in, out] IkePacket Pointer to IKE_PACKET to be encoded as input,
794 and the encoded reslult as output.
795 @param[in] IkeType The type of IKE. IKE_SA_TYPE, IKE_INFO_TYPE and
796 IKE_CHILD_TYPE are supportted.
798 @retval EFI_SUCCESS Encode IKE packet successfully.
799 @retval Otherwise Encode IKE packet failed.
804 IN IKEV2_SESSION_COMMON
*SessionCommon
,
805 IN OUT IKE_PACKET
*IkePacket
,
810 Decode the IKE packet.
812 This function first decrypts the IKE packet if needed , then separats the whole
813 IKE packet from the IkePacket->PayloadBuf into IkePacket payload list.
815 @param[in] SessionCommon Pointer to IKEV1_SESSION_COMMON containing
816 some parameter used by IKE packet decoding.
817 @param[in, out] IkePacket The IKE Packet to be decoded on input, and
818 the decoded result on return.
819 @param[in] IkeType The type of IKE. IKE_SA_TYPE, IKE_INFO_TYPE and
820 IKE_CHILD_TYPE are supportted.
822 @retval EFI_SUCCESS The IKE packet is decoded successfull.
823 @retval Otherwise The IKE packet decoding is failed.
828 IN IKEV2_SESSION_COMMON
*SessionCommon
,
829 IN OUT IKE_PACKET
*IkePacket
,
835 Send out IKEV2 packet.
837 @param[in] IkeUdpService Pointer to IKE_UDP_SERVICE used to send the IKE packet.
838 @param[in] SessionCommon Pointer to IKEV1_SESSION_COMMON related to the IKE packet.
839 @param[in] IkePacket Pointer to IKE_PACKET to be sent out.
840 @param[in] IkeType The type of IKE to point what's kind of the IKE
841 packet is to be sent out. IKE_SA_TYPE, IKE_INFO_TYPE
842 and IKE_CHILD_TYPE are supportted.
844 @retval EFI_SUCCESS The operation complete successfully.
845 @retval Otherwise The operation is failed.
850 IN IKE_UDP_SERVICE
*IkeUdpService
,
851 IN UINT8
*SessionCommon
,
852 IN IKE_PACKET
*IkePacket
,
857 Callback function for the IKE life time is over.
859 This function will mark the related IKE SA Session as deleting and trigger a
860 Information negotiation.
862 @param[in] Event The time out event.
863 @param[in] Context Pointer to data passed by caller.
868 Ikev2LifetimeNotify (
874 This function will be called if the TimeOut Event is signaled.
876 @param[in] Event The signaled Event.
877 @param[in] Context The data passed by caller.
888 Generate a Key Exchange payload according to the DH group type and save the
889 public Key into IkeSaSession IkeKey field.
891 @param[in, out] IkeSaSession Pointer of the IKE_SA_SESSION.
892 @param[in] NextPayload The payload type presented in the NextPayload field of Key
893 Exchange Payload header.
895 @retval Pointer to Key IKE payload.
899 Ikev2GenerateKePayload (
900 IN OUT IKEV2_SA_SESSION
*IkeSaSession
,
905 Check if the SPD is related to the input Child SA Session.
907 This function is the subfunction of Ikev1AssociateSpdEntry(). It is the call
908 back function of IpSecVisitConfigData().
911 @param[in] Type Type of the input Config Selector.
912 @param[in] Selector Pointer to the Configure Selector to be checked.
913 @param[in] Data Pointer to the Configure Selector's Data passed
915 @param[in] SelectorSize The buffer size of Selector.
916 @param[in] DataSize The buffer size of the Data.
917 @param[in] Context The data passed from the caller. It is a Child
918 SA Session in this context.
920 @retval EFI_SUCCESS The SPD Selector is not related to the Child SA Session.
921 @retval EFI_ABORTED The SPD Selector is related to the Child SA session and
922 set the ChildSaSession->Spd to point to this SPD Selector.
927 IN EFI_IPSEC_CONFIG_DATA_TYPE Type
,
928 IN EFI_IPSEC_CONFIG_SELECTOR
*Selector
,
930 IN UINTN SelectorSize
,
936 Check if the Algorithm ID is supported.
938 @param[in] AlgorithmId The specified Algorithm ID.
939 @param[in] Type The type used to indicate the Algorithm is for Encrypt or
942 @retval TRUE If the Algorithm ID is supported.
943 @retval FALSE If the Algorithm ID is not supported.
948 IN UINT16 AlgorithmId
,
953 Generate a ChildSa Session and insert it into related IkeSaSession.
955 @param[in] IkeSaSession Pointer to related IKEV2_SA_SESSION.
956 @param[in] UdpService Pointer to related IKE_UDP_SERVICE.
958 @return pointer of IKEV2_CHILD_SA_SESSION.
961 IKEV2_CHILD_SA_SESSION
*
962 Ikev2ChildSaSessionCreate (
963 IN IKEV2_SA_SESSION
*IkeSaSession
,
964 IN IKE_UDP_SERVICE
*UdpService
968 Parse the received Initial Exchange Packet.
970 This function parse the SA Payload and Key Payload to find out the cryptographic
971 suite for the further IKE negotiation and fill it into the IKE SA Session's
972 CommonSession->SaParams.
974 @param[in, out] IkeSaSession Pointer to related IKEV2_SA_SESSION.
975 @param[in] SaPayload The received packet.
976 @param[in] Type The received packet IKE header flag.
978 @retval TRUE If the SA proposal in Packet is acceptable.
979 @retval FALSE If the SA proposal in Packet is not acceptable.
983 Ikev2SaParseSaPayload (
984 IN OUT IKEV2_SA_SESSION
*IkeSaSession
,
985 IN IKE_PAYLOAD
*SaPayload
,
990 Parse the received Authentication Exchange Packet.
992 This function parse the SA Payload and Key Payload to find out the cryptographic
993 suite for the ESP and fill it into the Child SA Session's CommonSession->SaParams.
995 @param[in, out] ChildSaSession Pointer to IKEV2_CHILD_SA_SESSION related to
996 this Authentication Exchange.
997 @param[in] SaPayload The received packet.
998 @param[in] Type The IKE header's flag of received packet .
1000 @retval TRUE If the SA proposal in Packet is acceptable.
1001 @retval FALSE If the SA proposal in Packet is not acceptable.
1005 Ikev2ChildSaParseSaPayload (
1006 IN OUT IKEV2_CHILD_SA_SESSION
*ChildSaSession
,
1007 IN IKE_PAYLOAD
*SaPayload
,
1012 Generate Key buffer from fragments.
1014 If the digest length of specified HashAlgId is larger than or equal with the
1015 required output key length, derive the key directly. Otherwise, Key Material
1016 needs to be PRF-based concatenation according to 2.13 of RFC 4306:
1017 prf+ (K,S) = T1 | T2 | T3 | T4 | ..., T1 = prf (K, S | 0x01),
1018 T2 = prf (K, T1 | S | 0x02), T3 = prf (K, T2 | S | 0x03),T4 = prf (K, T3 | S | 0x04)
1019 then derive the key from this key material.
1021 @param[in] HashAlgId The Hash Algorithm ID used to generate key.
1022 @param[in] HashKey Pointer to a key buffer which contains hash key.
1023 @param[in] HashKeyLength The length of HashKey in bytes.
1024 @param[in, out] OutputKey Pointer to buffer which is used to receive the
1026 @param[in] OutputKeyLength The length of OutPutKey buffer.
1027 @param[in] Fragments Pointer to the data to be used to generate key.
1028 @param[in] NumFragments The numbers of the Fragement.
1030 @retval EFI_SUCCESS The operation complete successfully.
1031 @retval EFI_INVALID_PARAMETER If NumFragments is zero.
1032 @retval EFI_OUT_OF_RESOURCES If the required resource can't be allocated.
1033 @retval Others The operation is failed.
1037 Ikev2SaGenerateKey (
1040 IN UINTN HashKeyLength
,
1041 IN OUT UINT8
*OutputKey
,
1042 IN UINTN OutputKeyLength
,
1043 IN PRF_DATA_FRAGMENT
*Fragments
,
1044 IN UINTN NumFragments
1048 Copy ChildSaSession->Spd->Selector to ChildSaSession->SpdSelector.
1050 ChildSaSession->SpdSelector stores the real Spdselector for its SA. Sometime,
1051 the SpdSelector in ChildSaSession is more accurated or the scope is smaller
1052 than the one in ChildSaSession->Spd, especially for the tunnel mode.
1054 @param[in, out] ChildSaSession Pointer to IKEV2_CHILD_SA_SESSION related to.
1056 @retval EFI_SUCCESS The operation complete successfully.
1057 @retval EFI_OUT_OF_RESOURCES If the required resource can't be allocated.
1061 Ikev2ChildSaSessionSpdSelectorCreate (
1062 IN OUT IKEV2_CHILD_SA_SESSION
*ChildSaSession
1065 extern IKE_ALG_GUID_INFO mIPsecEncrAlgInfo
[];