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

354 lines
14 KiB
C

/*
******************************************************************************
* INTERPEAK INTERNAL API HEADER FILE
*
* Document no: @(#) $Name: VXWORKS_ITER40_2019102207 $ $RCSfile: ipfreescale_sec.h,v $ $Revision: 1.7.12.2 $
* $Source: /home/interpeak/CVSRoot/ipfreescale/src/ipfreescale_sec.h,v $
* $Author: svc-cmnet $ $Date: 2013-03-13 07:45:25 $
* $State: Exp $ $Locker: $
*
* INTERPEAK_COPYRIGHT_STRING
* Design and implementation by Markus Carlstedt <markus@interpeak.se>
******************************************************************************
*/
#ifndef IPFREESCALE_SEC_H
#define IPFREESCALE_SEC_H
/*
****************************************************************************
* 1 DESCRIPTION
****************************************************************************
*/
/*
****************************************************************************
* 2 CONFIGURATION
****************************************************************************
*/
#include "ipfreescale_config.h"
/*
****************************************************************************
* 3 INCLUDE FILES
****************************************************************************
*/
#ifdef IPFREESCALE_SEC4
#include "Sec4.h"
#endif
#ifdef IPFREESCALE_SEC2
#include "Sec2.h"
#endif
#include <ipcom_type.h>
#include <ipcom_cstyle.h>
#include <ipcom_os.h>
#include <ipcom_spinlock.h>
#ifdef IPIPSEC2
#include <ipcom_pkt.h>
#include <iphwcrypto.h>
#include <ipipsec.h>
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*
****************************************************************************
* 4 DEFINES
****************************************************************************
*/
#ifdef IPFREESCALE_USE_STATISTICS
#define IPFREESCALE_STATS(var) ipfreescale_sec.stats.var
#else
#define IPFREESCALE_STATS(var) IP_NOOP
#endif
#ifdef IPFREESCALE_SEC2
#define IPFREESCALE_SEC_NUM_CHANNELS 4
#endif
#ifdef IPFREESCALE_SEC4
/* One (of total four) job queues in SEC4 is used */
#define IPFREESCALE_SEC_NUM_CHANNELS 1
#endif
#ifdef IPFREESCALE_SEC4
/* The number of asynchronous contexts is set using a sysvar on SEC4 */
#else
/* The number of asynchronous contexts is the driver queue length plus
the number of SEC channels */
#ifdef IP_PORT_LKM
#define IPFREESCALE_SEC_NUM_ASYNC_CONTEXTS (128+IPFREESCALE_SEC_NUM_CHANNELS)
#else
#define IPFREESCALE_SEC_NUM_ASYNC_CONTEXTS (32+IPFREESCALE_SEC_NUM_CHANNELS)
#endif
#endif /* #ifdef IPFREESCALE_SEC4 */
/* The number of synchronous contexts is the number of tasks that are allowed
to access the SEC simultaneously */
#define IPFREESCALE_SEC_NUM_SYNC_CONTEXTS IPFREESCALE_SEC_NUM_TASKS
#if defined(IP_PORT_LAS) || defined(IP_PORT_UNIX)
#define IPFREESCALE_SEC_PUT_KMEM(fd, data, block, size) ipfreescale_sec_put_kmem(fd, data, block, size)
#define IPFREESCALE_SEC_GET_KMEM(fd, data, block, size) ipfreescale_sec_get_kmem(fd, data, block, size)
#define IPFREESCALE_SEC_FREE_KMEM(fd, block) ipfreescale_sec_free_kmem(fd, block)
#define IPFREESCALE_SEC_MALLOC_KMEM(fd, block, size) ipfreescale_sec_malloc_kmem(fd, block, size)
#define IPFREESCALE_SEC_COPYTO_KMEM(fd, data, block, size) ipfreescale_sec_copyto_kmem(fd, data, block, size)
#endif
#if defined(IP_PORT_LKM) || defined(IP_PORT_INTEGRITY) || defined(IP_PORT_VXWORKS)
#define IPFREESCALE_SEC_PUT_KMEM(fd, data, block, size) *(block) = (char *)(data)
#define IPFREESCALE_SEC_GET_KMEM(fd, data, block, size) IP_NOOP
#define IPFREESCALE_SEC_FREE_KMEM(fd, block) IP_NOOP
#define IPFREESCALE_SEC_MALLOC_KMEM(fd, block, size) IP_NOOP
#define IPFREESCALE_SEC_COPYTO_KMEM(fd, data, block, size) IP_NOOP
#endif
/*
****************************************************************************
* 5 TYPES
****************************************************************************
*/
/*
*===========================================================================
* Ipfreescale_sec_notify
*===========================================================================
* SEC context structure.
*/
typedef struct Ipfreescale_sec_notify_struct
{
union
{
RNG_REQ rng;
HASH_REQ hash;
HMAC_PAD_REQ hmac;
DES_LOADCTX_CRYPT_REQ des_cbc;
DES_CRYPT_REQ des_ecb;
AESA_CRYPT_REQ aes_cbc;
AESA_CRYPT_REQ aes_ecb;
ARC4_LOADKEY_CRYPT_UNLOADCTX_REQ rc4_key;
ARC4_LOADCTX_CRYPT_REQ rc4_ctx;
IPSEC_CBC_REQ esp_cbc;
MOD_SS_EXP_REQ mod_exp;
CCMP_REQ ccmp;
#ifdef IPFREESCALE_SEC4
CHKSUM_CRC_REQ crc;
DMA_REQ dma;
AESCCM_REQ aes_ccm;
#endif
}
req;
void *kreq;
struct Ipfreescale_sec_notify_struct *next;
Ipcom_block block;
#ifdef IPIPSEC2
Ipcom_pkt *pkt;
Iphwcrypto_esp_cbc_sa sa;
Ipipsec_param param;
Ip_u8 digest[IPHWCRYPTO_ENGINE_ESP_MAX_AUTHKEY];
#endif
void *handle; /* Application handle for asynchronous (non-IPsec) jobs */
void *sgt_in; /* Private handle to allocated HW specific scatter gather table */
void *sgt_out; /* Private handle to allocated HW specific scatter gather table */
Ip_u32 align;
}
Ipfreescale_sec_notify;
/*
*===========================================================================
* Ipfreescale_sec_notify_queue
*===========================================================================
* SEC context queue.
*/
typedef struct Ipfreescale_sec_notify_queue_struct
{
Ipfreescale_sec_notify *head;
Ipfreescale_sec_notify *tail;
Ip_u32 size;
}
Ipfreescale_sec_notify_queue;
/*
*===========================================================================
* Ipfreescale_sec_stats
*===========================================================================
* SEC statistics.
*/
typedef struct Ipfreescale_sec_stats_struct
{
/* requests */
unsigned long req_total;
unsigned long req_sync;
unsigned long req_async;
unsigned long req_fail_nomem;
unsigned long req_fail_nosyncctx;
unsigned long req_fail_noasyncctx;
unsigned long req_fail_ioctl;
unsigned long req_fail_notify;
unsigned long req_fail_timeout;
unsigned long req_fail_waitsync;
/* notifications */
unsigned long notify_sync_done;
unsigned long notify_async_done;
unsigned long notify_sync_error;
unsigned long notify_async_error;
/* operations */
unsigned long op_rng;
unsigned long op_md5;
unsigned long op_sha1;
unsigned long op_des_cbc;
unsigned long op_des_ecb;
unsigned long op_3des_cbc;
unsigned long op_3des_ecb;
unsigned long op_aes_cbc;
unsigned long op_aes_ecb;
unsigned long op_rc4;
unsigned long op_esp_in;
unsigned long op_esp_out;
unsigned long op_mod_exp;
unsigned long op_aes_ccm;
unsigned long op_crc;
unsigned long op_dma;
}
Ipfreescale_sec_stats;
/*
*===========================================================================
* Ipfreescale_sec_data
*===========================================================================
* SEC data.
*/
typedef struct Ipfreescale_sec_data_struct
{
#if defined(IPIPSEC2) || defined(IPFREESCALE_SEC4)
/* async context free queue */
Ipfreescale_sec_notify_queue async_queue;
/* async context request queue */
Ipfreescale_sec_notify_queue req_queue;
/* spinlock to protect async queue */
Ipcom_spinlock async_spl;
#endif
/* file handle */
int fd;
/* spinlock to protect sync queue */
Ipcom_spinlock sync_spl;
/* sync context free queue */
Ipfreescale_sec_notify_queue sync_queue;
#ifdef IPFREESCALE_USE_STATISTICS
/* statistics */
Ipfreescale_sec_stats stats;
#endif
#ifdef IPFREESCALE_SEC2
/* pid of signal dispatcher */
int pid;
/* threadid of signal dispatcher */
int threadid;
/* semaphore to synchronize start of signal dispatcher */
Ipcom_sem disp_sem;
#endif
/* sec core version */
int core_version;
/* power quicc device family */
int device_family;
/* call back funtion for successfull non-IPsec asynchronous jobs */
void (*async_done_cbf)(void *);
/* call back funtion for failed non-IPsec asynchronous jobs */
void (*async_error_cbf)(void *, int);
}
Ipfreescale_sec_data;
/*
****************************************************************************
* 6 FUNCTIONS
****************************************************************************
*/
IP_EXTERN IP_GLOBAL Ipfreescale_sec_data ipfreescale_sec;
IP_GLOBAL int ipfreescale_sec_inum(void);
IP_GLOBAL int ipfreescale_sec_num_channels(void);
IP_GLOBAL Ip_err ipfreescale_sec_init(void);
IP_GLOBAL Ip_err ipfreescale_sec_open(void);
IP_GLOBAL const char *ipfreescale_sec_err_string(int status);
IP_GLOBAL int ipfreescale_sec_print_stats(char *where, char *buf, int length);
IP_GLOBAL void ipfreescale_sec_clear_stats(void);
#ifdef IP_PORT_LKM
IP_GLOBAL int ipfreescale_sec_proc_info(char *buffer, char **start, int offset, int length);
#endif
IP_GLOBAL void ipfreescale_sec_notify_done(Ipfreescale_sec_notify *ctx);
IP_GLOBAL void ipfreescale_sec_notify_error(Ipfreescale_sec_notify *ctx);
IP_GLOBAL void ipfreescale_sec_arm_completion(GENERIC_REQ *rq);
IP_GLOBAL int ipfreescale_sec_engage(int fd, void *req, int len, Ip_bool async);
IP_GLOBAL int ipfreescale_sec_ioctl(int fd, unsigned long request, void *argp);
#if !defined(IP_PORT_LKM) && !defined(IP_PORT_INTEGRITY) && !defined(IP_PORT_VXWORKS)
IP_GLOBAL int ipfreescale_sec_put_kmem(int fd, IP_CONST void *data, void **block, unsigned int size);
IP_GLOBAL int ipfreescale_sec_get_kmem(int fd, void *data, void **block, unsigned int size);
IP_GLOBAL int ipfreescale_sec_free_kmem(int fd, void **block);
IP_GLOBAL int ipfreescale_sec_malloc_kmem(int fd, void **block, unsigned int size);
IP_GLOBAL void ipfreescale_sec_copyto_kmem(int fd, void *data, void *block, unsigned int size);
#endif
IP_GLOBAL int ipfreescale_sec_random_gen(Ip_u8 *data, Ip_u32 length);
IP_GLOBAL int ipfreescale_sec_md5_digest(IP_CONST Ip_u8 *data, Ip_u32 length, Ip_u8 *digest);
IP_GLOBAL int ipfreescale_sec_md5_hmac(IP_CONST Ip_u8 *data, Ip_u32 length, IP_CONST Ip_u8 *key, Ip_u32 keylength, Ip_u8 *hmac);
IP_GLOBAL int ipfreescale_sec_sha1_digest(IP_CONST Ip_u8 *data, Ip_u32 length, Ip_u8 *digest);
IP_GLOBAL int ipfreescale_sec_sha1_hmac(IP_CONST Ip_u8 *data, Ip_u32 length, IP_CONST Ip_u8 *key, Ip_u32 keylength, Ip_u8 *hmac);
IP_GLOBAL int ipfreescale_sec_des_cbc_cipher(Ip_u8 *out, IP_CONST Ip_u8 *in, Ip_u32 length, void *key, Ip_u8 *iv, int enc);
IP_GLOBAL int ipfreescale_sec_des_ecb_cipher(Ip_u8 *out, IP_CONST Ip_u8 *in, Ip_u32 length, void *key, int enc);
IP_GLOBAL int ipfreescale_sec_3des_cbc_cipher(Ip_u8 *out, IP_CONST Ip_u8 *in, Ip_u32 length, void *key, Ip_u8 *iv, int enc);
IP_GLOBAL int ipfreescale_sec_3des_ecb_cipher(Ip_u8 *out, IP_CONST Ip_u8 *in, Ip_u32 length, void *key, int enc);
IP_GLOBAL int ipfreescale_sec_aes_cbc_cipher(Ip_u8 *out, IP_CONST Ip_u8 *in, Ip_u32 length, void *key, Ip_u32 keylen, Ip_u8 *iv, int enc);
IP_GLOBAL int ipfreescale_sec_aes_ecb_cipher(Ip_u8 *out, IP_CONST Ip_u8 *in, Ip_u32 length, void *key, Ip_u32 keylen, int enc);
IP_GLOBAL int ipfreescale_sec_rc4_cipher(Ip_u8 *out, IP_CONST Ip_u8 *in, Ip_u32 length, void *key, Ip_u32 keylen, Ip_u8 *ctxi, Ip_u8 *ctxo);
IP_GLOBAL int ipfreescale_sec_mod_exp(Ip_u8 *out, IP_CONST Ip_u8 *base, IP_CONST Ip_u8 *e, IP_CONST Ip_u8 *mod, Ip_u32 modlen);
IP_GLOBAL int ipfreescale_sec_ccmp_encrypt(Ip_u8 *out, IP_CONST Ip_u8 *in, Ip_u32 length, Ip_u8 *mic, IP_CONST Ip_u8 *aad,
Ip_u32 aadlen, void *key, Ip_u32 keylen, Ip_u8 *ctxi);
IP_GLOBAL int ipfreescale_sec_aesccm(Ip_u8 *out, IP_CONST Ip_u8 *in, Ip_u32 length,
Ip_u8 *micout, Ip_u8 *micin, Ip_u32 miclen, IP_CONST Ip_u8 *aad, Ip_u32 aadlen,
void *key, Ip_u32 keylen, Ip_u8 *ctxi, int enc,
Ip_bool async, void * asynchandle, Ip_u32 options);
IP_GLOBAL int ipfreescale_sec_crc(IP_CONST Ip_u32 polynomial, IP_CONST Ip_u8 *indata, Ip_u32 length,
IP_CONST Ip_u8 *inctxdata, Ip_u32 inctxbytes, Ip_u8 *crc, Ip_u8 crcsize,
Ip_bool async, void * asynchandle, Ip_u32 crcoptions);
IP_GLOBAL int ipfreescale_sec_dma(IP_CONST Ip_u8 *indata, Ip_u32 length,
Ip_u8 *outdata, Ip_bool async, void * asynchandle, Ip_u32 options);
IP_GLOBAL Ipfreescale_sec_notify *ipfreescale_sec_create_sync_context(void);
IP_GLOBAL void ipfreescale_sec_destroy_sync_context(Ipfreescale_sec_notify *ctx);
IP_GLOBAL void ipfreescale_sec_enqueue_context_first(Ipfreescale_sec_notify_queue *queue, Ipfreescale_sec_notify *ctx);
IP_GLOBAL void ipfreescale_sec_enqueue_context_last(Ipfreescale_sec_notify_queue *queue, Ipfreescale_sec_notify *ctx);
IP_GLOBAL Ipfreescale_sec_notify *ipfreescale_sec_dequeue_context(Ipfreescale_sec_notify_queue *queue);
IP_GLOBAL Ipfreescale_sec_notify *ipfreescale_sec_create_async_context(void *handle);
#ifdef IPIPSEC2
IP_GLOBAL Ipfreescale_sec_notify *ipfreescale_sec_ipsec_create_async_context(Iphwcrypto_esp_cbc_sa *sa, Ipipsec_param *param, Ipcom_pkt *pkt);
IP_GLOBAL void ipfreescale_sec_destroy_async_context(Ipfreescale_sec_notify *ctx);
IP_GLOBAL void ipfreescale_ipsec_sec_notify_done(Ipfreescale_sec_notify *ctx);
IP_GLOBAL void ipfreescale_ipsec_sec_notify_error(Ipfreescale_sec_notify *ctx);
IP_GLOBAL int ipfreescale_ipsec_sec_esp_input(Ip_u32 opid, Ip_u8 *data, Ip_u32 length, Ip_u8 *outdata, Iphwcrypto_esp_cbc_sa *sa, Ip_u8 *digest, Ipipsec_param *param, Ipcom_pkt *pkt);
IP_GLOBAL int ipfreescale_ipsec_sec_esp_output(Ip_u32 opid, Ip_u8 *data, Ip_u32 length, Ip_u8 *outdata, Iphwcrypto_esp_cbc_sa *sa, Ip_u8 *digest, Ipipsec_param *param, Ipcom_pkt *pkt);
#endif
#ifdef __cplusplus
}
#endif
#endif
/*
****************************************************************************
* END OF FILE
****************************************************************************
*/