⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sec2_test.c

📁 freescale ppc sec2加解密单元驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
#include <stdio.h>
#include "ros_ex.h"
#include "mux_ex.h"
#include "sec2driver.h"
#include "sec2.h"
#include "sec2_algo.h"

#if DRIVER_IPSEC_DBG /*消除pc_lint告警增加宏控制*/
#include "protocol/security/common/include/algo_msg.h"
#endif

#if DRIVER_IPSEC_DBG
#include "protocol/security/common/include/algo_msg.h"
extern STATUS    cacheDmaFree (void * pBuf);
extern void *    cacheDmaMalloc (size_t bytes);

int ipsecswitch = 1;

#define ALGO_IKE_RNG                 1  /* 生成随机数 */

#define ALGO_IKE_HASH_MD5            2  /* MD5散列 */
#define ALGO_IKE_HASH_SHA            3  /* SHA-1散列 */
#define ALGO_IKE_HASH_TIGER          4  /* TIGER32散列 */

#define ALGO_IKE_HMAC_MD5            5  /* HMAC-MD5 */
#define ALGO_IKE_HMAC_SHA            6  /* HMAC-SHA-1 */
#define ALGO_IKE_HMAC_TIGER          7  /* HMAC-TIGER32 */

#define ALGO_IKE_CBC_ENCRYPT_DES     8  /* CBC DES加密 */
#define ALGO_IKE_CBC_DECRYPT_DES     9  /* CBC DES解密 */
#define ALGO_IKE_CBC_ENCRYPT_3DES   10  /* CBC 3DES加密 */
#define ALGO_IKE_CBC_DECRYPT_3DES   11  /* CBC 3DES解密 */
#define ALGO_IKE_CBC_ENCRYPT_AES    12  /* CBC AES加密 */
#define ALGO_IKE_CBC_DECRYPT_AES    13  /* CBC AES解密 */
#define ALGO_IKE_CBC_ENCRYPT_SSF    14  /* CBC SSF-33加密 */
#define ALGO_IKE_CBC_DECRYPT_SSF    15  /* CBC SSF-33解密 */

#define ALGO_IKE_DH                 16  /* DH交换计算(计算公共值和共享秘密) */

#define ALGO_IKE_RSA                17  /* RSA计算(RSA解密不考虑使用孙子定理) */

#define ALGO_IKE_DSS_SIG            18  /* DSS签名 */
#define ALGO_IKE_DSS_VERIFY         19  /* DSS签名验证 */

#define MAX_IKE_ALGO_NUM            19

#define DRV_IPSEC_DBG(STRING)  printf (STRING)
typedef struct algo_msg_ike_cbc_hmac
{
    algo_msg_ike_cbc_t *cbc_msg;
    algo_msg_ike_hmac_t *hmac_msg;
}algo_msg_ike_cbc_hmac_t;

extern void crypto_free_algo_reqmsg(void *msg_data);
extern void time_minus(struct timespec *r,struct timespec *t1, struct timespec *t2);

#if DRIVER_IPSEC_DBG
extern unsigned char drv_ipsec_out_lndec[512];
extern unsigned char drv_ipsec_out_lndec_hmac[32];
extern unsigned char drv_ipsec_out_internalSec2[512];
extern unsigned char drv_ipsec_out_internalSec2_hmac[32];
#endif
UINT32 drv_ipsec_success_num = 0;      
UINT32 drv_ipsec_error_num   = 0;

extern DES_LOADCTX_CRYPT_REQ *cryptReq ; /* 描述符 请求结构 */
extern AESA_CRYPT_REQ *aesReq;
extern IPSEC_CBC_REQ    *ipsecReq;	
extern CCMP_REQ  *ccmpreq ;
void sec2_test_des_callback(void *ctx)
{
    algo_msg_ike_cbc_t *cbc_msg = NULL;
    algo_msg_crypt_t *cbc = NULL;
    /*UINT32 i = 0;*/

    if (ctx == NULL)
    {
        printf("test_des_callback: null ctx!\n");
        return;
    }

    cbc_msg = (algo_msg_ike_cbc_t *)ctx;
    cbc = &(cbc_msg->msgCrypt);
#if 0
    printf("MPC190 CBC DES RESULT:\n");
    for (i = 0; i < cbc->outLen; i++)
    {
        printf("%02x ",*(cbc->outData + i));
        if ((i + 1) % 20 == 0)
        {
            printf("\n");
        }
    }
    printf("\n");

    memset(cbc->outData, 0, cbc->outLen);
    /*crypto_cbc_des(cbc , 1);*/
    printf("\nisws output:\n");
    for (i = 0; i < cbc->outLen; i++)
    {
        printf("%02x ", *(cbc->outData + i));
        if ((i + 1) % 20 == 0)
        {
            printf("\n");
        }
    }
    printf("\n");
#endif
    free(cbc->inData);
    free(cbc->key);
    free(cbc->iv);
    free(cbc->outData);

    return;
}

void sec2_test_des_err_callback(void *ctx)
{
    algo_msg_ike_cbc_t *cbc_msg = NULL;
    algo_msg_crypt_t *cbc = NULL;

    if (ctx == NULL)
    {
        printf("test_des_err_callback: null ctx!\n");
        return;
    }

    cbc_msg = (algo_msg_ike_cbc_t *)ctx;
    cbc = &(cbc_msg->msgCrypt);

    free(cbc->key);
    free(cbc->iv);
    free(cbc->outData);

    return;
}

void sec2_test_des_de_callback(void *ctx)
{
    algo_msg_ike_cbc_t *cbc_msg = NULL;
    algo_msg_crypt_t *cbc = NULL;
    /*UINT32 i = 0;*/

    if (ctx == NULL)
    {
        printf("test_des_callback: null ctx!\n");
        return;
    }

    cbc_msg = (algo_msg_ike_cbc_t *)ctx;
    cbc = &(cbc_msg->msgCrypt);

    free(cbc->key);
    free(cbc->iv);
    free(cbc->outData);

    return;
}

void sec2_test_des_de_err_callback(void *ctx)
{
    algo_msg_ike_cbc_t *cbc_msg = NULL;
    algo_msg_crypt_t *cbc = NULL;

    if (ctx == NULL)
    {
        printf("test_des_err_callback: null ctx!\n");
        return;
    }

    cbc_msg = (algo_msg_ike_cbc_t *)ctx;
    cbc = &(cbc_msg->msgCrypt);

    free(cbc->key);
    free(cbc->iv);
    free(cbc->outData);

    return;
}

void sec2_test_Aes_callback(void *ctx)
{
    algo_msg_ike_cbc_t *cbc_msg = NULL;
    algo_msg_crypt_t *cbc = NULL;

    if (ctx == NULL)
    {
        printf("test_des_callback: null ctx!\n");
        return;
    }

    cbc_msg = (algo_msg_ike_cbc_t *)ctx;
    cbc = &(cbc_msg->msgCrypt);
#if 0
    printf("MPC190 CBC DES RESULT:\n");
    for (i = 0; i < cbc->outLen; i++)
    {
        printf("%02x ",*(cbc->outData + i));
        if ((i + 1) % 20 == 0)
        {
            printf("\n");
        }
    }
    printf("\n");

    memset(cbc->outData, 0, cbc->outLen);
    /*crypto_cbc_des(cbc , 1);*/
    printf("\nisws output:\n");
    for (i = 0; i < cbc->outLen; i++)
    {
        printf("%02x ", *(cbc->outData + i));
        if ((i + 1) % 20 == 0)
        {
            printf("\n");
        }
    }
    printf("\n");
#endif
    free(cbc->inData);
    free(cbc->key);
    free(cbc->iv);
    free(cbc->outData);

    return;
}

void sec2_test_Aes_err_callback(void *ctx)
{
    algo_msg_ike_cbc_t *cbc_msg = NULL;
    algo_msg_crypt_t *cbc = NULL;

    if (ctx == NULL)
    {
        printf("test_des_err_callback: null ctx!\n");
        return;
    }

    cbc_msg = (algo_msg_ike_cbc_t *)ctx;
    cbc = &(cbc_msg->msgCrypt);

    free(cbc->inData);
    free(cbc->key);
    free(cbc->iv);
    free(cbc->outData);

    return;
}

void sec2_test_Aes_de_callback(void *ctx)
{
    algo_msg_ike_cbc_t *cbc_msg = NULL;
    algo_msg_crypt_t *cbc = NULL;

    if (ctx == NULL)
    {
        printf("test_des_callback: null ctx!\n");
        return;
    }

    cbc_msg = (algo_msg_ike_cbc_t *)ctx;
    cbc = &(cbc_msg->msgCrypt);
#if 0
    printf("MPC190 CBC DES RESULT:\n");
    for (i = 0; i < cbc->outLen; i++)
    {
        printf("%02x ",*(cbc->outData + i));
        if ((i + 1) % 20 == 0)
        {
            printf("\n");
        }
    }
    printf("\n");

    memset(cbc->outData, 0, cbc->outLen);
    /*crypto_cbc_des(cbc , 1);*/
    printf("\nisws output:\n");
    for (i = 0; i < cbc->outLen; i++)
    {
        printf("%02x ", *(cbc->outData + i));
        if ((i + 1) % 20 == 0)
        {
            printf("\n");
        }
    }
    printf("\n");
#endif
    free(cbc->key);
    free(cbc->iv);
    free(cbc->outData);

    return;
}

void sec2_test_Aes_de_err_callback(void *ctx)
{
    algo_msg_ike_cbc_t *cbc_msg = NULL;
    algo_msg_crypt_t *cbc = NULL;

    if (ctx == NULL)
    {
        printf("test_des_err_callback: null ctx!\n");
        return;
    }

    cbc_msg = (algo_msg_ike_cbc_t *)ctx;
    cbc = &(cbc_msg->msgCrypt);

    free(cbc->key);
    free(cbc->iv);
    free(cbc->outData);

    return;
}

/*********************************************************************************/
void sec2_test_rng_callback(void *ctx)
{
    algo_msg_ike_rng_t *rng_msg = NULL;
    algo_msg_rng_t *rng = NULL;
    /*UINT32 i = 0;*/

    printf("\n\nMPC190 RNG CALLBACK\n");

    if (ctx == NULL)
    {
        printf("test_rng_callback: null ctx!\n");
        return;
    }

    rng_msg = (algo_msg_ike_rng_t *)ctx;
    rng = &(rng_msg->msgRng);
#if 0
    printf("\n\nMPC190 RNG RESULT:\n");
    for (i = 0; i < rng->dataLen; i++)
    {
        printf("%02x ",*((rng->outData)+ i));
        if ((i + 1) % 20 == 0)
        {
            printf("\n");
        }
    }
    printf("\n");
#endif
    free(rng->outData);
    return;
}

void sec2_test_rng_err_callback(void *ctx)
{
    algo_msg_ike_rng_t *rng_msg = NULL;
    algo_msg_rng_t *rng = NULL;

    printf("\n\nMPC190 RNG ERR CALLBACK\n");

    if (ctx == NULL)
    {
        printf("test_rng_err_callback: null ctx!\n");
        return;
    }

    rng_msg = (algo_msg_ike_rng_t *)ctx;
    rng = &(rng_msg->msgRng);

    free(rng->outData);
    return;
}

/************************************************************************************/
/*测试hash md5散列矩阵*/
void sec2_test_md5_callback(void *ctx)
{
    algo_msg_ike_hash_t *hash_msg = NULL;
    algo_msg_hash_t *hash = NULL;
    UINT32 i = 0;

    if (ctx == NULL)
    {
        printf("test_md5_callback: null ctx!\n");
        return;
    }

    hash_msg = (algo_msg_ike_hash_t *)ctx;
    hash = &(hash_msg->msgHash);
#if 0
    printf("MPC190 HASH MD5 RESULT:\n");
    for (i = 0; i < hash->outLen; i++)
    {
        printf("%02x ",*(hash->outData + i));
        if ((i + 1) % 20 == 0)
        {
            printf("\n");
        }
    }
    printf("\n");
#endif

    memset(hash->outData, 0, hash->outLen);
    /*crypto_hash_md5(hash);*/
    printf("isws output:\n");
    for (i = 0; i < hash->outLen; i++)
    {
        printf("%02x ", *(hash->outData + i));
    }
    printf("\n");

    free(hash->inData);
    free(hash->outData);

    return;
}

void sec2_test_md5_err_callback(void *ctx)
{
    algo_msg_ike_hash_t *hash_msg = NULL;
    algo_msg_hash_t *hash = NULL;

    if (ctx == NULL)
    {
        printf("test_md5_err_callback: null ctx!\n");
        return;
    }

    hash_msg = (algo_msg_ike_hash_t *)ctx;
    hash = &(hash_msg->msgHash);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -