Files
m241Neelima/components/ip_net2-6.9/ipike/src/ipike_payload_hash.c
T
2026-07-30 11:19:44 +05:30

228 lines
6.8 KiB
C

/*
******************************************************************************
* SOURCE FILE
*
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipike_payload_hash.c,v $ $Revision: 1.16.16.1 $
* $Source: /home/interpeak/CVSRoot/ipike/src/ipike_payload_hash.c,v $
* $Author: edahlber $ $Date: 2011-12-06 12:00:22 $
* $State: Exp $ $Locker: $
*
* INTERPEAK_COPYRIGHT_STRING
* Design and implementation by Kenneth Jonsson <kenneth@interpeak.se>
******************************************************************************
*/
/*
****************************************************************************
* 1 DESCRIPTION
****************************************************************************
*/
/* Hash payload (RFC 2408, chapter 3.11) */
/*
****************************************************************************
* 2 CONFIGURATION
****************************************************************************
*/
/*
****************************************************************************
* 3 INCLUDE FILES
****************************************************************************
*/
#include "ipike_h.h"
#include "ipike_config.h"
#include "ipike_payload_hash.h"
#include "ipike_util.h"
#include <ipcom_clib.h>
#include <ipcom_syslog.h>
/*
****************************************************************************
* 4 EXTERN PROTOTYPES
****************************************************************************
*/
/*
****************************************************************************
* 5 DEFINES
****************************************************************************
*/
/*
****************************************************************************
* 6 TYPES
****************************************************************************
*/
/*
****************************************************************************
* 7 LOCAL PROTOTYPES
****************************************************************************
*/
/*
*===========================================================================
* ipike_hash_data
*===========================================================================
* Description: Returns a pointer to the hash data in the payload.
* Parameters: hash - a hash payload.
* Returns: A pointer to the hash data.
*
*/
IP_STATIC Ip_u8 *
ipike_hash_data(Ipike_hash_payload* hash);
/*
*===========================================================================
* ipike_hash_data_length
*===========================================================================
* Description: Returns the length of the hash data.
* Parameters: hash - hash payload.
* Returns: The length of the hash data (in bytes).
*
*
*/
IP_STATIC Ip_u16
ipike_hash_data_length(Ipike_hash_payload* hash);
/*
****************************************************************************
* 8 DATA
****************************************************************************
*/
/*
****************************************************************************
* 9 LOCAL FUNCTIONS
****************************************************************************
*/
IP_STATIC Ip_u8 *
ipike_hash_data(Ipike_hash_payload* hash)
{
return (Ip_u8 *) hash + IPIKE_HASH_HEADER_LENGTH;
}
IP_STATIC Ip_u16
ipike_hash_data_length(Ipike_hash_payload* hash)
{
return IPIKE_PAYLOAD_DATA_LENGTH(hash->header.length, IPIKE_HASH_HEADER_LENGTH);
}
/*
****************************************************************************
* 10 PUBLIC FUNCTIONS
****************************************************************************
*/
/*
*===========================================================================
* ipike_hash_new
*===========================================================================
*/
IP_GLOBAL Ipike_hash_payload *
ipike_hash_new(const Ip_u8* hash_data, Ip_u16 hash_length)
{
Ipike_hash_payload *ret;
if (IP_NULL == (ret = ipcom_calloc(1, IPIKE_HASH_HEADER_LENGTH + hash_length)))
{
IPCOM_LOG0(CRIT, "ipike_hash_new: out of memory");
return IP_NULL;
}
ret->header.length = ip_htons(IPIKE_HASH_HEADER_LENGTH + hash_length);
ret->header.next_payload = IPIKE_PAYLOAD_HASH;
ipcom_memcpy(ipike_hash_data(ret), hash_data, hash_length);
return ret;
}
/*
*===========================================================================
* ipike_hash_create
*===========================================================================
*/
IP_GLOBAL Ipike_error
ipike_hash_create(Ipike_value* hash, Ipike_hash_payload** payload)
{
*payload = ipike_hash_new(hash->value, (Ip_u16) hash->len);
if (IP_NULL == *payload)
{
IP_PANIC();
return IPIKE_OUT_OF_MEMORY;
}
return IPIKE_SUCCESS;
}
/*
*===========================================================================
* ipike_hash_check_payload
*===========================================================================
*/
IP_GLOBAL Ipike_error
ipike_hash_check_payload(Ipike_hash_payload* hash)
{
(void) hash;
return IPIKE_SUCCESS;
}
/*
*===========================================================================
* ipike_hash_extract
*===========================================================================
*/
IP_GLOBAL Ipike_error
ipike_hash_extract(Ipike_hash_payload* payload, Ipike_value* hash)
{
hash->len = ipike_hash_data_length(payload);
if ( hash->len == 0 )
return IPIKE_INVALID_HASH_VALUE;
if ( hash->value )
ipcom_free(hash->value);
if (IP_NULL == (hash->value = ipcom_malloc(hash->len)))
{
IP_PANIC();
return IPIKE_OUT_OF_MEMORY;
}
ipcom_memcpy(hash->value, ipike_hash_data(payload), hash->len);
return IPIKE_SUCCESS;
}
/*
*===========================================================================
* ipike_hash_print_payload
*===========================================================================
*/
IP_GLOBAL void
ipike_hash_print_payload(Ipike_hash_payload* hash)
{
char *hash_hex;
hash_hex = ipike_memory_to_string(ipike_hash_data(hash),
ipike_hash_data_length(hash), 4);
if (IP_NULL == hash_hex)
{
IPCOM_LOG0(CRIT, "ipike_print_hash_payload: out of memory");
return;
}
IPCOM_LOG1(DEBUG2, " hash: %s", hash_hex);
ipcom_free(hash_hex);
}
/*
****************************************************************************
* END OF FILE
****************************************************************************
*/