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

1120 lines
44 KiB
C

/*
******************************************************************************
* INTERPEAK SOURCE FILE
*
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipfreescale_ipsec.c,v $ $Revision: 1.21.10.1 $
* $Source: /home/interpeak/CVSRoot/ipfreescale/src/ipfreescale_ipsec.c,v $
* $Author: svc-cmnet $
* $State: Exp $ $Locker: $
*
* INTERPEAK_COPYRIGHT_STRING
* Design and implementation by Markus Carlstedt <markus@interpeak.se>
******************************************************************************
*/
/*
****************************************************************************
* 1 DESCRIPTION
****************************************************************************
*/
/*
****************************************************************************
* 2 CONFIGURATION
****************************************************************************
*/
#include "ipfreescale_config.h"
#ifdef IPIPSEC2
/*
****************************************************************************
* 3 INCLUDE FILES
****************************************************************************
*/
#define IPCOM_USE_CLIB_PROTO
#include <ipcom_type.h>
#include <ipcom_cstyle.h>
#include <ipcom_clib.h>
#include <ipcom_syslog.h>
#include <ipcom_err.h>
#include <ipcom_os.h>
/* TODO: Not pretty! Nasty dependencies between files */
/* Include ipfreescale_sec4.h before iphwcrypto.h to avoid type collition for uint32_t between stdint.h and ipipsec_pfkeyv2.h */
#ifdef IPFREESCALE_SEC4
#define IPIPSEC_HAVE_UINT_TYPE
#endif
#if defined(IPFREESCALE_SEC2) || defined(IPFREESCALE_SEC4)
#include "ipfreescale_sec.h"
#endif
#include <iphwcrypto.h>
#include "ipfreescale.h"
#include "ipfreescale_h.h"
#ifdef IPFREESCALE_COLDFIRE
#include "ipfreescale_coldfire.h"
#endif
/*
****************************************************************************
* 4 DEFINES
****************************************************************************
*/
/*
****************************************************************************
* 5 TYPES
****************************************************************************
*/
/*
****************************************************************************
* 6 EXTERN PROTOTYPES
****************************************************************************
*/
/*
****************************************************************************
* 7 LOCAL PROTOTYPES
****************************************************************************
*/
/*
****************************************************************************
* 8 DATA
****************************************************************************
*/
/*
****************************************************************************
* 9 STATIC FUNCTIONS
****************************************************************************
*/
/*
****************************************************************************
* 10 GLOBAL FUNCTIONS
****************************************************************************
*/
/*
*===========================================================================
* ipfreescale_ipsec_esp_null_md5_input
*===========================================================================
* Description: IPSEC ESP input processing using NULL-MD5.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_null_md5_input(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
(void)param;
(void)pkt;
return ipfreescale_md5_hmac(data, length - sa->authlen, sa->akey, sa->akeylen, digest);
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_null_md5_output
*===========================================================================
* Description: IPSEC ESP output processing using NULL-MD5.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_null_md5_output(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
(void)param;
(void)pkt;
return ipfreescale_md5_hmac(data, length, sa->akey, sa->akeylen, digest);
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_null_sha1_input
*===========================================================================
* Description: IPSEC ESP input processing using NULL-SHA1.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_null_sha1_input(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
(void)param;
(void)pkt;
return ipfreescale_sha1_hmac(data, length - sa->authlen, sa->akey, sa->akeylen, digest);
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_null_sha1_output
*===========================================================================
* Description: IPSEC ESP output processing using NULL-SHA1.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_null_sha1_output(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
(void)param;
(void)pkt;
return ipfreescale_sha1_hmac(data, length, sa->akey, sa->akeylen, digest);
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_des_cbc_null_input
*===========================================================================
* Description: IPSEC ESP input processing using DES-CBC-NULL.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_des_cbc_null_input(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
(void)digest;
(void)param;
(void)pkt;
return ipfreescale_des_cbc_cipher(data + sa->hdrlen, data + sa->hdrlen,
length - sa->hdrlen - sa->authlen, sa->ekey,
data + sa->hdrlen - sa->ivlen, 0);
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_des_cbc_null_output
*===========================================================================
* Description: IPSEC ESP output processing using DES-CBC-NULL.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_des_cbc_null_output(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
Ip_u8 iv[IPFREESCALE_DES_IV_SIZE];
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
(void)digest;
(void)param;
(void)pkt;
ipcom_memcpy(iv, sa->iv, IPFREESCALE_DES_IV_SIZE);
return ipfreescale_des_cbc_cipher(data + sa->hdrlen, data + sa->hdrlen,
length - sa->hdrlen, sa->ekey,
iv, 1);
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_des_cbc_md5_input
*===========================================================================
* Description: IPSEC ESP input processing using DES-CBC-MD5.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_des_cbc_md5_input(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
return ipfreescale_ipsec_esp_des_cbc_md5_input_relocate(data, length, data, sa, digest, param, pkt);
}
IP_PUBLIC int
ipfreescale_ipsec_esp_des_cbc_md5_input_relocate(Ip_u8 *data,
Ip_u32 length,
Ip_u8 *outdata,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
#if defined(IPFREESCALE_SEC2) || defined (IPFREESCALE_SEC4)
return ipfreescale_ipsec_sec_esp_input(DPD_IPSEC_CBC_SDES_DECRYPT_MD5_PAD, data, length, outdata, sa, digest, param, pkt);
#endif
#ifdef IPFREESCALE_COLDFIRE
return ipfreescale_ipsec_coldfire_esp_input(IPFREESCALE_COLDFIRE_ESP_DECRYPT_DES_CBC_MD5, data, length, sa, digest, param, pkt);
#endif
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_des_cbc_md5_output
*===========================================================================
* Description: IPSEC ESP output processing using DES-CBC-MD5.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_des_cbc_md5_output(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
return ipfreescale_ipsec_esp_des_cbc_md5_output_relocate(data, length, data, sa, digest, param, pkt);
}
IP_PUBLIC int
ipfreescale_ipsec_esp_des_cbc_md5_output_relocate(Ip_u8 *data,
Ip_u32 length,
Ip_u8 *outdata,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
#if defined(IPFREESCALE_SEC2) || defined (IPFREESCALE_SEC4)
return ipfreescale_ipsec_sec_esp_output(DPD_IPSEC_CBC_SDES_ENCRYPT_MD5_PAD, data, length, outdata, sa, digest, param, pkt);
#endif
#ifdef IPFREESCALE_COLDFIRE
return ipfreescale_ipsec_coldfire_esp_output(IPFREESCALE_COLDFIRE_ESP_ENCRYPT_DES_CBC_MD5, data, length, sa, digest, param, pkt);
#endif
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_des_cbc_sha1_input
*===========================================================================
* Description: IPSEC ESP input processing using DES-CBC-SHA1.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_des_cbc_sha1_input(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
return ipfreescale_ipsec_esp_des_cbc_sha1_input_relocate(data, length, data, sa, digest, param, pkt);
}
IP_PUBLIC int
ipfreescale_ipsec_esp_des_cbc_sha1_input_relocate(Ip_u8 *data,
Ip_u32 length,
Ip_u8 *outdata,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
#if defined(IPFREESCALE_SEC2) || defined (IPFREESCALE_SEC4)
return ipfreescale_ipsec_sec_esp_input(DPD_IPSEC_CBC_SDES_DECRYPT_SHA_PAD, data, length, outdata, sa, digest, param, pkt);
#endif
#ifdef IPFREESCALE_COLDFIRE
return ipfreescale_ipsec_coldfire_esp_input(IPFREESCALE_COLDFIRE_ESP_DECRYPT_DES_CBC_SHA1, data, length, sa, digest, param, pkt);
#endif
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_des_cbc_sha1_output
*===========================================================================
* Description: IPSEC ESP output processing using DES-CBC-SHA1.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_des_cbc_sha1_output(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
return ipfreescale_ipsec_esp_des_cbc_sha1_output_relocate(data, length, data, sa, digest, param, pkt);
}
IP_PUBLIC int
ipfreescale_ipsec_esp_des_cbc_sha1_output_relocate(Ip_u8 *data,
Ip_u32 length,
Ip_u8 *outdata,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
#if defined(IPFREESCALE_SEC2) || defined (IPFREESCALE_SEC4)
return ipfreescale_ipsec_sec_esp_output(DPD_IPSEC_CBC_SDES_ENCRYPT_SHA_PAD, data, length, outdata, sa, digest, param, pkt);
#endif
#ifdef IPFREESCALE_COLDFIRE
return ipfreescale_ipsec_coldfire_esp_output(IPFREESCALE_COLDFIRE_ESP_ENCRYPT_DES_CBC_SHA1, data, length, sa, digest, param, pkt);
#endif
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_3des_cbc_null_input
*===========================================================================
* Description: IPSEC ESP input processing using 3DES-CBC-NULL.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_3des_cbc_null_input(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
(void)digest;
(void)param;
(void)pkt;
return ipfreescale_3des_cbc_cipher(data + sa->hdrlen, data + sa->hdrlen,
length - sa->hdrlen - sa->authlen, sa->ekey,
data + sa->hdrlen - sa->ivlen, 0);
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_3des_cbc_null_output
*===========================================================================
* Description: IPSEC ESP output processing using 3DES-CBC-NULL.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_3des_cbc_null_output(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
Ip_u8 iv[IPFREESCALE_DES_IV_SIZE];
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
(void)digest;
(void)param;
(void)pkt;
ipcom_memcpy(iv, sa->iv, IPFREESCALE_DES_IV_SIZE);
return ipfreescale_3des_cbc_cipher(data + sa->hdrlen, data + sa->hdrlen,
length - sa->hdrlen, sa->ekey,
iv, 1);
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_3des_cbc_md5_input
*===========================================================================
* Description: IPSEC ESP input processing using 3DES-CBC-MD5.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_3des_cbc_md5_input(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
return ipfreescale_ipsec_esp_3des_cbc_md5_input_relocate(data, length, data, sa, digest, param, pkt);
}
IP_PUBLIC int
ipfreescale_ipsec_esp_3des_cbc_md5_input_relocate(Ip_u8 *data,
Ip_u32 length,
Ip_u8 *outdata,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
#if defined(IPFREESCALE_SEC2) || defined (IPFREESCALE_SEC4)
return ipfreescale_ipsec_sec_esp_input(DPD_IPSEC_CBC_TDES_DECRYPT_MD5_PAD, data, length, outdata, sa, digest, param, pkt);
#endif
#ifdef IPFREESCALE_COLDFIRE
return ipfreescale_ipsec_coldfire_esp_input(IPFREESCALE_COLDFIRE_ESP_DECRYPT_3DES_CBC_MD5, data, length, sa, digest, param, pkt);
#endif
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_3des_cbc_md5_output
*===========================================================================
* Description: IPSEC ESP output processing using 3DES-CBC-MD5.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_3des_cbc_md5_output(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
return ipfreescale_ipsec_esp_3des_cbc_md5_output_relocate(data, length, data, sa, digest, param, pkt);
}
IP_PUBLIC int
ipfreescale_ipsec_esp_3des_cbc_md5_output_relocate(Ip_u8 *data,
Ip_u32 length,
Ip_u8 *outdata,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
#if defined(IPFREESCALE_SEC2) || defined (IPFREESCALE_SEC4)
/* Used to place crypto output at other location than input */
/* ipcom_printf("ipfreescale_ipsec_esp_3des_cbc_md5_output: data=0x%x, length=%d, outdata=0x%x, sa=0x%x, digest=0x%x, param=0x%x, pkt=0x%x\n",data, length, outdata, sa, digest, param, pkt);*/
return ipfreescale_ipsec_sec_esp_output(DPD_IPSEC_CBC_TDES_ENCRYPT_MD5_PAD, data, length, outdata, sa, digest, param, pkt);
#endif
#ifdef IPFREESCALE_COLDFIRE
return ipfreescale_ipsec_coldfire_esp_output(IPFREESCALE_COLDFIRE_ESP_ENCRYPT_3DES_CBC_MD5, data, length, sa, digest, param, pkt);
#endif
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_3des_cbc_sha1_input
*===========================================================================
* Description: IPSEC ESP input processing using 3DES-CBC-SHA1.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_3des_cbc_sha1_input(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
return ipfreescale_ipsec_esp_3des_cbc_sha1_input_relocate(data, length, data, sa, digest, param, pkt);
}
IP_PUBLIC int
ipfreescale_ipsec_esp_3des_cbc_sha1_input_relocate(Ip_u8 *data,
Ip_u32 length,
Ip_u8 *outdata,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
#if defined(IPFREESCALE_SEC2) || defined (IPFREESCALE_SEC4)
return ipfreescale_ipsec_sec_esp_input(DPD_IPSEC_CBC_TDES_DECRYPT_SHA_PAD, data, length, outdata, sa, digest, param, pkt);
#endif
#ifdef IPFREESCALE_COLDFIRE
return ipfreescale_ipsec_coldfire_esp_input(IPFREESCALE_COLDFIRE_ESP_DECRYPT_3DES_CBC_SHA1, data, length, sa, digest, param, pkt);
#endif
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_3des_cbc_sha1_output
*===========================================================================
* Description: IPSEC ESP output processing using 3DES-CBC-SHA1.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_3des_cbc_sha1_output(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
return ipfreescale_ipsec_esp_3des_cbc_sha1_output_relocate(data, length, data, sa, digest, param, pkt);
}
IP_PUBLIC int
ipfreescale_ipsec_esp_3des_cbc_sha1_output_relocate(Ip_u8 *data,
Ip_u32 length,
Ip_u8 *outdata,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
#if defined(IPFREESCALE_SEC2) || defined (IPFREESCALE_SEC4)
return ipfreescale_ipsec_sec_esp_output(DPD_IPSEC_CBC_TDES_ENCRYPT_SHA_PAD, data, length, outdata, sa, digest, param, pkt);
#endif
#ifdef IPFREESCALE_COLDFIRE
return ipfreescale_ipsec_coldfire_esp_output(IPFREESCALE_COLDFIRE_ESP_ENCRYPT_3DES_CBC_SHA1, data, length, sa, digest, param, pkt);
#endif
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_aes_cbc_null_input
*===========================================================================
* Description: IPSEC ESP input processing using AES-CBC-NULL.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_aes_cbc_null_input(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
(void)digest;
(void)param;
(void)pkt;
if (sa->ekeylen == 16)
return ipfreescale_aes128_cbc_cipher(data + sa->hdrlen, data + sa->hdrlen,
length - sa->hdrlen - sa->authlen, sa->ekey,
data + sa->hdrlen - sa->ivlen, 0);
else if (sa->ekeylen == 24)
return ipfreescale_aes192_cbc_cipher(data + sa->hdrlen, data + sa->hdrlen,
length - sa->hdrlen - sa->authlen, sa->ekey,
data + sa->hdrlen - sa->ivlen, 0);
else if (sa->ekeylen == 32)
return ipfreescale_aes256_cbc_cipher(data + sa->hdrlen, data + sa->hdrlen,
length - sa->hdrlen - sa->authlen, sa->ekey,
data + sa->hdrlen - sa->ivlen, 0);
else
return -1;
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_aes_cbc_null_output
*===========================================================================
* Description: IPSEC ESP output processing using AES-CBC-NULL.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_aes_cbc_null_output(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
Ip_u8 iv[IPFREESCALE_AES_IV_SIZE];
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
(void)digest;
(void)param;
(void)pkt;
ipcom_memcpy(iv, sa->iv, IPFREESCALE_AES_IV_SIZE);
if (sa->ekeylen == 16)
return ipfreescale_aes128_cbc_cipher(data + sa->hdrlen, data + sa->hdrlen,
length - sa->hdrlen, sa->ekey,
iv, 1);
else if (sa->ekeylen == 24)
return ipfreescale_aes192_cbc_cipher(data + sa->hdrlen, data + sa->hdrlen,
length - sa->hdrlen, sa->ekey,
iv, 1);
else if (sa->ekeylen == 32)
return ipfreescale_aes256_cbc_cipher(data + sa->hdrlen, data + sa->hdrlen,
length - sa->hdrlen, sa->ekey,
iv, 1);
else
return -1;
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_aes_cbc_md5_input
*===========================================================================
* Description: IPSEC ESP input processing using AES-CBC-MD5.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_aes_cbc_md5_input(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
return ipfreescale_ipsec_esp_aes_cbc_md5_input_relocate(data, length, data, sa, digest, param, pkt);
}
IP_PUBLIC int
ipfreescale_ipsec_esp_aes_cbc_md5_input_relocate(Ip_u8 *data,
Ip_u32 length,
Ip_u8 *outdata,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
#if defined(IPFREESCALE_SEC2) || defined (IPFREESCALE_SEC4)
return ipfreescale_ipsec_sec_esp_input(DPD_IPSEC_AES_CBC_DECRYPT_MD5_APAD, data, length, outdata, sa, digest, param, pkt);
#endif
#ifdef IPFREESCALE_COLDFIRE
return ipfreescale_ipsec_coldfire_esp_input(IPFREESCALE_COLDFIRE_ESP_DECRYPT_AES_CBC_MD5, data, length, sa, digest, param, pkt);
#endif
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_aes_cbc_md5_output
*===========================================================================
* Description: IPSEC ESP output processing using AES-CBC-MD5.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_aes_cbc_md5_output(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
return ipfreescale_ipsec_esp_aes_cbc_md5_output_relocate(data, length, data, sa, digest, param, pkt);
}
IP_PUBLIC int
ipfreescale_ipsec_esp_aes_cbc_md5_output_relocate(Ip_u8 *data,
Ip_u32 length,
Ip_u8 *outdata,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
#if defined(IPFREESCALE_SEC2) || defined (IPFREESCALE_SEC4)
return ipfreescale_ipsec_sec_esp_output(DPD_IPSEC_AES_CBC_ENCRYPT_MD5_APAD, data, length, outdata, sa, digest, param, pkt);
#endif
#ifdef IPFREESCALE_COLDFIRE
return ipfreescale_ipsec_coldfire_esp_output(IPFREESCALE_COLDFIRE_ESP_ENCRYPT_AES_CBC_MD5, data, length, sa, digest, param, pkt);
#endif
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_aes_cbc_sha1_input
*===========================================================================
* Description: IPSEC ESP input processing using AES-CBC-SHA1.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_aes_cbc_sha1_input(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
return ipfreescale_ipsec_esp_aes_cbc_sha1_input_relocate(data, length, data, sa, digest, param, pkt);
}
IP_PUBLIC int
ipfreescale_ipsec_esp_aes_cbc_sha1_input_relocate(Ip_u8 *data,
Ip_u32 length,
Ip_u8 *outdata,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
#if defined(IPFREESCALE_SEC2) || defined (IPFREESCALE_SEC4)
return ipfreescale_ipsec_sec_esp_input(DPD_IPSEC_AES_CBC_DECRYPT_SHA_APAD, data, length, outdata, sa, digest, param, pkt);
#endif
#ifdef IPFREESCALE_COLDFIRE
return ipfreescale_ipsec_coldfire_esp_input(IPFREESCALE_COLDFIRE_ESP_DECRYPT_AES_CBC_SHA1, data, length, sa, digest, param, pkt);
#endif
}
/*
*===========================================================================
* ipfreescale_ipsec_esp_aes_cbc_sha1_output
*===========================================================================
* Description: IPSEC ESP output processing using AES-CBC-SHA1.
* Parameters: data - pointer to the packet data.
* length - length of the packet.
* sa - pointer to the sa (tunnel descriptor block).
* param - pointer to ipsec parameters.
* digest - pointer the message autentication code.
* pkt - pointer to the packet structure.
* Returns: 2 = kept
* 1 = ok
* 0 = timeout
* -1 = error
*/
IP_PUBLIC int
ipfreescale_ipsec_esp_aes_cbc_sha1_output(Ip_u8 *data,
Ip_u32 length,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
return ipfreescale_ipsec_esp_aes_cbc_sha1_output_relocate(data, length, data, sa, digest, param, pkt);
}
IP_PUBLIC int
ipfreescale_ipsec_esp_aes_cbc_sha1_output_relocate(Ip_u8 *data,
Ip_u32 length,
Ip_u8 *outdata,
Iphwcrypto_esp_cbc_sa *sa,
Ip_u8 *digest,
Ipipsec_param *param,
Ipcom_pkt *pkt)
{
ip_assert(length <= IPFREESCALE_CRYPTO_BUFSIZE);
if(length > IPFREESCALE_CRYPTO_BUFSIZE)
return -1;
#if defined(IPFREESCALE_SEC2) || defined (IPFREESCALE_SEC4)
return ipfreescale_ipsec_sec_esp_output(DPD_IPSEC_AES_CBC_ENCRYPT_SHA_APAD, data, length, outdata, sa, digest, param, pkt);
#endif
#ifdef IPFREESCALE_COLDFIRE
return ipfreescale_ipsec_coldfire_esp_output(IPFREESCALE_COLDFIRE_ESP_ENCRYPT_AES_CBC_SHA1, data, length, sa, digest, param, pkt);
#endif
}
/*
****************************************************************************
* 11 PUBLIC FUNCTIONS
****************************************************************************
*/
#else
int ipfreescale_ipsec_empty_file;
#endif /* #ifdef IPIPSEC2 */
/*
****************************************************************************
* END OF FILE
****************************************************************************
*/