226 lines
7.2 KiB
C
226 lines
7.2 KiB
C
/*
|
|
******************************************************************************
|
|
* SOURCE FILE
|
|
*
|
|
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipike_payload_key_exchange.c,v $ $Revision: 1.16 $
|
|
* $Source: /home/interpeak/CVSRoot/ipike/src/ipike_payload_key_exchange.c,v $
|
|
* $Author: edahlber $ $Date: 2010-04-23 15:31:41 $
|
|
* $State: Exp $ $Locker: $
|
|
*
|
|
* INTERPEAK_COPYRIGHT_STRING
|
|
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
|
|
******************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 1 DESCRIPTION
|
|
****************************************************************************
|
|
*/
|
|
|
|
/* Key exchange payload (RFC 2408, chapter 3.7) */
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 2 CONFIGURATION
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 3 INCLUDE FILES
|
|
****************************************************************************
|
|
*/
|
|
|
|
#include "ipike_h.h"
|
|
#include "ipike_config.h"
|
|
#include "ipike_attributes.h"
|
|
#include "ipike_payload_key_exchange.h"
|
|
#include "ipike_util.h"
|
|
#include "ipike_sadb.h"
|
|
|
|
#include <ipcom_clib.h>
|
|
#include <ipcom_syslog.h>
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 4 EXTERN PROTOTYPES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 5 DEFINES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 6 TYPES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 7 LOCAL PROTOTYPES
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_key_exchange_data
|
|
*===========================================================================
|
|
* Description: Returns a pointer to the key exchange data in the payload.
|
|
* Parameters: ke - a key exchange payload.
|
|
* Returns: A pointer to the key exchange data.
|
|
*
|
|
*/
|
|
IP_STATIC Ip_u8 *
|
|
ipike_key_exchange_data(Ipike_ke_payload* ke);
|
|
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_key_exchange_data_length
|
|
*===========================================================================
|
|
* Description: Returns the length of the key exchange data.
|
|
* Parameters: ke - key exchange payload.
|
|
* Returns: The length of the key exchange data (in bytes).
|
|
*
|
|
*
|
|
*/
|
|
IP_STATIC Ip_u16
|
|
ipike_key_exchange_data_length(Ipike_ke_payload* ke);
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 8 DATA
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 9 LOCAL FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_key_exchange_data
|
|
*===========================================================================
|
|
*/
|
|
IP_STATIC Ip_u8 *
|
|
ipike_key_exchange_data(Ipike_ke_payload* ke)
|
|
{
|
|
return (Ip_u8 *) ke + IPIKE_KE_HEADER_LENGTH;
|
|
}
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_key_exchange_data_length
|
|
*===========================================================================
|
|
*/
|
|
IP_STATIC Ip_u16
|
|
ipike_key_exchange_data_length(Ipike_ke_payload* ke)
|
|
{
|
|
return IPIKE_PAYLOAD_DATA_LENGTH(ke->header.length, IPIKE_KE_HEADER_LENGTH);
|
|
}
|
|
|
|
/*
|
|
****************************************************************************
|
|
* 10 PUBLIC FUNCTIONS
|
|
****************************************************************************
|
|
*/
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_key_exchange_new
|
|
*===========================================================================
|
|
*/
|
|
IP_GLOBAL Ipike_ke_payload *
|
|
ipike_key_exchange_new(const Ip_u8* ke_data, Ip_u16 ke_len)
|
|
{
|
|
Ipike_ke_payload* ret;
|
|
|
|
if (IP_NULL == (ret = ipcom_calloc(1, IPIKE_KE_HEADER_LENGTH + ke_len)))
|
|
{
|
|
IPCOM_LOG0(CRIT, "ipike_key_exchange_new: out of memory");
|
|
return IP_NULL;
|
|
}
|
|
ret->header.length = ip_htons(IPIKE_KE_HEADER_LENGTH + ke_len);
|
|
ret->header.next_payload = IPIKE_PAYLOAD_KEY_EXCHANGE;
|
|
ipcom_memcpy(ipike_key_exchange_data(ret), ke_data, ke_len);
|
|
return ret;
|
|
}
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_key_exchange_create
|
|
*===========================================================================
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_key_exchange_create(Ipike_value* g_x, Ipike_ke_payload** ke)
|
|
{
|
|
if (IP_NULL == (*ke = ipike_key_exchange_new(g_x->value, (Ip_u16) g_x->len)))
|
|
{
|
|
IP_PANIC();
|
|
return IPIKE_OUT_OF_MEMORY;
|
|
}
|
|
return IPIKE_SUCCESS;
|
|
}
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_key_exchange_check_payload
|
|
*===========================================================================
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_key_exchange_check_payload(Ipike_ke_payload* ke)
|
|
{
|
|
(void) ke;
|
|
/* Nothing to check for this payload */
|
|
return IPIKE_SUCCESS;
|
|
}
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_key_exchange_extract
|
|
*===========================================================================
|
|
*/
|
|
IP_GLOBAL Ipike_error
|
|
ipike_key_exchange_extract(
|
|
Ipike_ke_payload* payload,
|
|
Ipike_value* ke)
|
|
{
|
|
ke->len = ipike_key_exchange_data_length(payload);
|
|
|
|
ipcom_free(ke->value);
|
|
if (IP_NULL == (ke->value = ipcom_malloc(ke->len)))
|
|
{
|
|
IP_PANIC();
|
|
return IPIKE_OUT_OF_MEMORY;
|
|
}
|
|
ipcom_memcpy(ke->value, ipike_key_exchange_data(payload), ke->len);
|
|
|
|
return IPIKE_SUCCESS;
|
|
}
|
|
|
|
/*
|
|
*===========================================================================
|
|
* ipike_key_exchange_print_payload
|
|
*===========================================================================
|
|
*/
|
|
IP_GLOBAL void
|
|
ipike_key_exchange_print_payload(Ipike_ke_payload* ke)
|
|
{
|
|
(void)ipike_print_memory(IPCOM_LOG_DEBUG2, " data:\n",
|
|
ipike_key_exchange_data(ke),
|
|
ipike_key_exchange_data_length(ke));
|
|
}
|
|
|
|
/*
|
|
****************************************************************************
|
|
* END OF FILE
|
|
****************************************************************************
|
|
*/
|