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, IkeChildSaEntry *childSa, uint8_t *p, size_t *written, uint8_t **nextPayload)
 Format Security Association payload. More...
 
error_t ikeFormatSaProposal (IkeSaEntry *sa, const uint8_t *spi, uint8_t *p, size_t *written)
 Format Proposal substructure (IKE protocol) More...
 
error_t ikeFormatChildSaProposal (IkeChildSaEntry *childSa, IpsecProtocol protocolId, const uint8_t *spi, uint8_t *p, size_t *written)
 Format Proposal substructure (AH or ESP protocol) More...
 
error_t ikeFormatKePayload (IkeSaEntry *sa, 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 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 ikeFormatTs (const IkeTsParams *tsParams, 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-2024 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.4.4

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 827 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 668 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 575 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 729 of file ike_payload_format.c.

◆ ikeFormatChildSaProposal()

error_t ikeFormatChildSaProposal ( IkeChildSaEntry childSa,
IpsecProtocol  protocolId,
const uint8_t *  spi,
uint8_t *  p,
size_t *  written 
)

Format Proposal substructure (AH or ESP protocol)

Parameters
[in]childSaPointer to the Child SA
[in]protocolIdProtocol identifier (AH or ESP)
[in]spiSecurity parameter index
[out]pBuffer where to format the Proposal substructure
[out]writtenLength of the resulting Proposal substructure
Returns
Error code

Definition at line 256 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 1177 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 472 of file ike_payload_format.c.

◆ ikeFormatKePayload()

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

Format Key Exchange 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 417 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 880 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 968 of file ike_payload_format.c.

◆ ikeFormatSaPayload()

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

Format Security Association 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 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 136 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 1108 of file ike_payload_format.c.

◆ ikeFormatTs()

error_t ikeFormatTs ( const IkeTsParams tsParams,
uint8_t *  p,
size_t *  written 
)

Format Traffic Selector substructure.

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

Definition at line 1407 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 1240 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 1324 of file ike_payload_format.c.