ike_payload_format.c File Reference

IKE payload formatting. More...

#include "ike/ike.h"
#include "ike/ike_algorithms.h"
#include "ike/ike_payload_format.h"
#include "ike/ike_auth.h"
#include "ike/ike_certificate.h"
#include "ike/ike_key_exchange.h"
#include "ike/ike_key_material.h"
#include "ah/ah_algorithms.h"
#include "esp/esp_algorithms.h"
#include "pkix/pem_import.h"
#include "debug.h"

Go to the source code of this file.

Macros

#define TRACE_LEVEL   IKE_TRACE_LEVEL
 

Functions

error_t ikeFormatSaPayload (IkeSaEntry *sa, const uint8_t *spi, uint8_t *p, size_t *written, uint8_t **nextPayload)
 Format Security Association payload (IKE protocol) More...
 
error_t ikeFormatSaProposal (IkeSaEntry *sa, const uint8_t *spi, uint8_t *p, size_t *written)
 Format Proposal substructure (IKE protocol) More...
 
error_t ikeFormatChildSaPayload (IkeChildSaEntry *childSa, uint8_t *p, size_t *written, uint8_t **nextPayload)
 Format Security Association payload (AH or ESP protocol) More...
 
error_t ikeFormatChildSaProposal (IkeChildSaEntry *childSa, uint8_t *p, size_t *written)
 Format Proposal substructure (AH or ESP protocol) More...
 
error_t ikeFormatKePayload (IkeKeContext *keContext, uint8_t *p, size_t *written, uint8_t **nextPayload)
 Format Key Exchange payload. More...
 
error_t ikeFormatIdPayload (IkeSaEntry *sa, uint8_t *p, size_t *written, uint8_t **nextPayload)
 Format Identification payload. More...
 
error_t ikeFormatCertPayloads (IkeSaEntry *sa, uint8_t *p, size_t *written, uint8_t **nextPayload)
 Format Certificate payloads. More...
 
error_t ikeFormatCertPayload (const char_t *certChain, size_t certChainLen, size_t *consumed, uint8_t *p, size_t *written, uint8_t **nextPayload)
 Format Certificate payload. More...
 
error_t ikeFormatCertReqPayload (IkeSaEntry *sa, uint8_t *p, size_t *written, uint8_t **nextPayload)
 Format Certificate Request payload. More...
 
error_t ikeFormatAuthPayload (IkeSaEntry *sa, const IkeIdPayload *idPayload, uint8_t *p, size_t *written, uint8_t **nextPayload)
 Format Authentication payload. More...
 
error_t ikeFormatNoncePayload (IkeSaEntry *sa, IkeChildSaEntry *childSa, uint8_t *p, size_t *written, uint8_t **nextPayload)
 Format Nonce payload. More...
 
error_t ikeFormatNotifyPayload (IkeSaEntry *sa, IkeChildSaEntry *childSa, IkeNotifyMsgType notifyMsgType, uint8_t *p, size_t *written, uint8_t **nextPayload)
 Format Notify payload. More...
 
error_t ikeFormatNatDetectSrcIpNotificationData (IkeSaEntry *sa, uint8_t *p, size_t *written)
 Format NAT_DETECTION_SOURCE_IP notification data. More...
 
error_t ikeFormatNatDetectDestIpNotificationData (IkeSaEntry *sa, uint8_t *p, size_t *written)
 Format NAT_DETECTION_DESTINATION_IP notification data. More...
 
error_t ikeFormatSignHashAlgosNotificationData (IkeSaEntry *sa, uint8_t *p, size_t *written)
 Format SIGNATURE_HASH_ALGORITHMS notification data. More...
 
error_t ikeFormatDeletePayload (IkeSaEntry *sa, IkeChildSaEntry *childSa, uint8_t *p, size_t *written, uint8_t **nextPayload)
 Format Delete payload. More...
 
error_t ikeFormatTsiPayload (IkeChildSaEntry *childSa, uint8_t *p, size_t *written, uint8_t **nextPayload)
 Format Traffic Selector payload (initiator) More...
 
error_t ikeFormatTsrPayload (IkeChildSaEntry *childSa, uint8_t *p, size_t *written, uint8_t **nextPayload)
 Format Traffic Selector payload (responder) More...
 
error_t ikeFormatTsEntry (const IkeTsEntry *tsEntry, uint8_t *p, size_t *written)
 Format Traffic Selector substructure. More...
 

Detailed Description

IKE payload formatting.

License

SPDX-License-Identifier: GPL-2.0-or-later

Copyright (C) 2022-2026 Oryx Embedded SARL. All rights reserved.

This file is part of CycloneIPSEC Open.

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

Author
Oryx Embedded SARL (www.oryx-embedded.com)
Version
2.6.6

Definition in file ike_payload_format.c.

Macro Definition Documentation

◆ TRACE_LEVEL

#define TRACE_LEVEL   IKE_TRACE_LEVEL

Definition at line 32 of file ike_payload_format.c.

Function Documentation

◆ ikeFormatAuthPayload()

error_t ikeFormatAuthPayload ( IkeSaEntry *  sa,
const IkeIdPayload *  idPayload,
uint8_t *  p,
size_t *  written,
uint8_t **  nextPayload 
)

Format Authentication payload.

Parameters
[in]saPointer to the IKE SA
[in]idPayloadPointer to the Identification payload
[out]pBuffer where to format the payload
[out]writtenLength of the resulting payload
[in,out]nextPayloadPointer to the Next Payload field
Returns
Error code

Definition at line 898 of file ike_payload_format.c.

◆ ikeFormatCertPayload()

error_t ikeFormatCertPayload ( const char_t *  certChain,
size_t  certChainLen,
size_t *  consumed,
uint8_t *  p,
size_t *  written,
uint8_t **  nextPayload 
)

Format Certificate payload.

Parameters
[in]certChainPointer to the certificate chain (PEM format)
[in]certChainLenLength of the certificate chain, in bytes
[out]consumedTotal number of characters that have been consumed
[out]pBuffer where to format the payload
[out]writtenLength of the resulting payload
[in,out]nextPayloadPointer to the Next Payload field
Returns
Error code

Definition at line 739 of file ike_payload_format.c.

◆ ikeFormatCertPayloads()

error_t ikeFormatCertPayloads ( IkeSaEntry *  sa,
uint8_t *  p,
size_t *  written,
uint8_t **  nextPayload 
)

Format Certificate payloads.

Parameters
[in]saPointer to the IKE SA
[out]pBuffer where to format the payloads
[out]writtenLength of the resulting payloads
[in,out]nextPayloadPointer to the Next Payload field
Returns
Error code

Definition at line 646 of file ike_payload_format.c.

◆ ikeFormatCertReqPayload()

error_t ikeFormatCertReqPayload ( IkeSaEntry *  sa,
uint8_t *  p,
size_t *  written,
uint8_t **  nextPayload 
)

Format Certificate Request payload.

Parameters
[in]saPointer to the IKE SA
[out]pBuffer where to format the payload
[out]writtenLength of the resulting payload
[in,out]nextPayloadPointer to the Next Payload field
Returns
Error code

Definition at line 800 of file ike_payload_format.c.

◆ ikeFormatChildSaPayload()

error_t ikeFormatChildSaPayload ( IkeChildSaEntry *  childSa,
uint8_t *  p,
size_t *  written,
uint8_t **  nextPayload 
)

Format Security Association payload (AH or ESP protocol)

Parameters
[in]childSaPointer to the Child SA
[out]pBuffer where to format the payload
[out]writtenLength of the resulting payload
[in,out]nextPayloadPointer to the Next Payload field
Returns
Error code

Definition at line 242 of file ike_payload_format.c.

◆ ikeFormatChildSaProposal()

error_t ikeFormatChildSaProposal ( IkeChildSaEntry *  childSa,
uint8_t *  p,
size_t *  written 
)

Format Proposal substructure (AH or ESP protocol)

Parameters
[in]childSaPointer to the Child SA
[out]pBuffer where to format the Proposal substructure
[out]writtenLength of the resulting Proposal substructure
Returns
Error code

Definition at line 294 of file ike_payload_format.c.

◆ ikeFormatDeletePayload()

error_t ikeFormatDeletePayload ( IkeSaEntry *  sa,
IkeChildSaEntry *  childSa,
uint8_t *  p,
size_t *  written,
uint8_t **  nextPayload 
)

Format Delete payload.

Parameters
[in]saPointer to the IKE SA
[in]childSaPointer to the Child SA
[out]pBuffer where to format the payload
[out]writtenLength of the resulting payload
[in,out]nextPayloadPointer to the Next Payload field
Returns
Error code

Definition at line 1430 of file ike_payload_format.c.

◆ ikeFormatIdPayload()

error_t ikeFormatIdPayload ( IkeSaEntry *  sa,
uint8_t *  p,
size_t *  written,
uint8_t **  nextPayload 
)

Format Identification payload.

Parameters
[in]saPointer to the IKE SA
[out]pBuffer where to format the payload
[out]writtenLength of the resulting payload
[in,out]nextPayloadPointer to the Next Payload field
Returns
Error code

Definition at line 543 of file ike_payload_format.c.

◆ ikeFormatKePayload()

error_t ikeFormatKePayload ( IkeKeContext *  keContext,
uint8_t *  p,
size_t *  written,
uint8_t **  nextPayload 
)

Format Key Exchange payload.

Parameters
[in]keContextPointer to the key exchange context
[out]pBuffer where to format the payload
[out]writtenLength of the resulting payload
[in,out]nextPayloadPointer to the Next Payload field
Returns
Error code

Definition at line 488 of file ike_payload_format.c.

◆ ikeFormatNatDetectDestIpNotificationData()

error_t ikeFormatNatDetectDestIpNotificationData ( IkeSaEntry *  sa,
uint8_t *  p,
size_t *  written 
)

Format NAT_DETECTION_DESTINATION_IP notification data.

Parameters
[in]saPointer to the IKE SA
[out]pBuffer where to format the notification data
[out]writtenLength of the notification data, in bytes
Returns
Error code

Definition at line 1291 of file ike_payload_format.c.

◆ ikeFormatNatDetectSrcIpNotificationData()

error_t ikeFormatNatDetectSrcIpNotificationData ( IkeSaEntry *  sa,
uint8_t *  p,
size_t *  written 
)

Format NAT_DETECTION_SOURCE_IP notification data.

Parameters
[in]saPointer to the IKE SA
[out]pBuffer where to format the notification data
[out]writtenLength of the notification data, in bytes
Returns
Error code

Definition at line 1209 of file ike_payload_format.c.

◆ ikeFormatNoncePayload()

error_t ikeFormatNoncePayload ( IkeSaEntry *  sa,
IkeChildSaEntry *  childSa,
uint8_t *  p,
size_t *  written,
uint8_t **  nextPayload 
)

Format Nonce payload.

Parameters
[in]saPointer to the IKE SA
[in]childSaPointer to the Child SA
[out]pBuffer where to format the payload
[out]writtenLength of the resulting payload
[in,out]nextPayloadPointer to the Next Payload field
Returns
Error code

Definition at line 951 of file ike_payload_format.c.

◆ ikeFormatNotifyPayload()

error_t ikeFormatNotifyPayload ( IkeSaEntry *  sa,
IkeChildSaEntry *  childSa,
IkeNotifyMsgType  notifyMsgType,
uint8_t *  p,
size_t *  written,
uint8_t **  nextPayload 
)

Format Notify payload.

Parameters
[in]saPointer to the IKE SA
[in]childSaPointer to the Child SA
[in]notifyMsgTypeType of notification
[out]pBuffer where to format the payload
[out]writtenLength of the resulting payload
[in,out]nextPayloadPointer to the Next Payload field
Returns
Error code

Definition at line 1039 of file ike_payload_format.c.

◆ ikeFormatSaPayload()

error_t ikeFormatSaPayload ( IkeSaEntry *  sa,
const uint8_t *  spi,
uint8_t *  p,
size_t *  written,
uint8_t **  nextPayload 
)

Format Security Association payload (IKE protocol)

Parameters
[in]saPointer to the IKE SA
[in]spiSecurity parameter index (optional parameter)
[out]pBuffer where to format the payload
[out]writtenLength of the resulting payload
[in,out]nextPayloadPointer to the Next Payload field
Returns
Error code

Definition at line 61 of file ike_payload_format.c.

◆ ikeFormatSaProposal()

error_t ikeFormatSaProposal ( IkeSaEntry *  sa,
const uint8_t *  spi,
uint8_t *  p,
size_t *  written 
)

Format Proposal substructure (IKE protocol)

Parameters
[in]saPointer to the IKE SA
[in]spiSecurity parameter index (optional parameter)
[out]pBuffer where to format the Proposal substructure
[out]writtenLength of the resulting Proposal substructure
Returns
Error code

Definition at line 114 of file ike_payload_format.c.

◆ ikeFormatSignHashAlgosNotificationData()

error_t ikeFormatSignHashAlgosNotificationData ( IkeSaEntry *  sa,
uint8_t *  p,
size_t *  written 
)

Format SIGNATURE_HASH_ALGORITHMS notification data.

Parameters
[in]saPointer to the IKE SA
[out]pBuffer where to format the notification data
[out]writtenLength of the notification data, in bytes
Returns
Error code

Definition at line 1356 of file ike_payload_format.c.

◆ ikeFormatTsEntry()

error_t ikeFormatTsEntry ( const IkeTsEntry *  tsEntry,
uint8_t *  p,
size_t *  written 
)

Format Traffic Selector substructure.

Parameters
[in]tsEntryTraffic selector entry
[out]pBuffer where to format the Traffic Selector substructure
[out]writtenLength of the resulting Traffic Selector substructure
Returns
Error code

Definition at line 1770 of file ike_payload_format.c.

◆ ikeFormatTsiPayload()

error_t ikeFormatTsiPayload ( IkeChildSaEntry *  childSa,
uint8_t *  p,
size_t *  written,
uint8_t **  nextPayload 
)

Format Traffic Selector payload (initiator)

Parameters
[in]childSaPointer to the Child SA
[out]pBuffer where to format the payload
[out]writtenLength of the resulting payload
[in,out]nextPayloadPointer to the Next Payload field
Returns
Error code

Definition at line 1493 of file ike_payload_format.c.

◆ ikeFormatTsrPayload()

error_t ikeFormatTsrPayload ( IkeChildSaEntry *  childSa,
uint8_t *  p,
size_t *  written,
uint8_t **  nextPayload 
)

Format Traffic Selector payload (responder)

Parameters
[in]childSaPointer to the Child SA
[out]pBuffer where to format the payload
[out]writtenLength of the resulting payload
[in,out]nextPayloadPointer to the Next Payload field
Returns
Error code

Definition at line 1631 of file ike_payload_format.c.