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

📄 sec2_test.c

📁 freescale ppc sec2加解密单元驱动
💻 C
📖 第 1 页 / 共 5 页
字号:
        return;
    }
    memset(arg_in , 0, (sizeof(DRV_LNDEC_ALG_REQ_PARA)));
    arg_in->crypt = cbc;
    arg_in->data  = cbc_msg ;
    
    /*下发驱动*/
    for(i=0;i<count;i++)
    {
        drv_sec2_Aes_ctr_crypt(DRV_IPSEC_AES_CTR_CRYPT, arg_in);
    }
    return;
}


void sec2_test_Aes_ctr_decrypt(int count,int len)
{
    algo_msg_ike_cbc_t *cbc_msg = NULL;                   /*第三个参数*/
    algo_msg_crypt_t *cbc = NULL;                               /*第二个参数*/
    UINT8 pt5[24] = "012345678987654321012345";
    int i;
    DRV_LNDEC_ALG_REQ_PARA* arg_in  = NULL; /*写消息结构,分配地址空间*/
    
    cbc_msg = (algo_msg_ike_cbc_t *)OsAlloc(sizeof(algo_msg_ike_cbc_t));
    if (cbc_msg == NULL)
    {
        printf("mpc190_test_des: failed to malloc hash_msg!\n");
        return;
    }
    cbc_msg->msgHdr.algoid = ALGO_IKE_CBC_ENCRYPT_3DES;           /*CBC DES*/
    cbc_msg->msgHdr.callback = sec2_test_Aes_callback;
    cbc_msg->msgHdr.ctx = cbc_msg;
    cbc_msg->msgHdr.error_callback = sec2_test_Aes_err_callback;
    cbc_msg->msgHdr.ISSC_num = 0;
    cbc_msg->msgHdr.reply_msgId = MSG_IKE_ALGO_OK;

    cbc = &(cbc_msg->msgCrypt);
    cbc->inLen = len;                                                      /*输入数据长度*/
    cbc->inData = aesReq->outData;
    if (cbc->inData == NULL)
    {
        printf("mpc190_test_des: failed to malloc inData!\n");
        OsFree(cbc_msg);
        return;
    }

    cbc->keyLen = 16;                                                        /*输入密钥长度*/
    cbc->key = malloc(cbc->keyLen);                /*分配内存空间*/
    if (cbc->key == NULL)
    {
        printf("mpc190_test_des: failed to malloc key!\n");
        free(cbc->inData);
        OsFree(cbc_msg);
        return;
    }
    memcpy(cbc->key, pt5, cbc->keyLen);                      /*输入密钥*/


    cbc->outLen = len;
    cbc->outData = malloc(cbc->outLen);         /*分配输出内存*/
    if (cbc->outData == NULL)                                          /*如果分配失败则释放*/
    {
        printf("mpc190_test_des: failed to malloc outData!\n");
        free(cbc->inData);
        free(cbc->key);
        OsFree(cbc_msg);
        return;
    }
    memset(cbc->outData,0,cbc->outLen);

    arg_in =(DRV_LNDEC_ALG_REQ_PARA*) malloc(sizeof(DRV_LNDEC_ALG_REQ_PARA));   
    /*检测是否为空*/
    if (arg_in == NULL)
    {
        printf("mpc190_test_rng: malloc param failed!\n");
        OsFree(cbc_msg);
        return;
    }
    memset(arg_in , 0, (sizeof(DRV_LNDEC_ALG_REQ_PARA)));
    arg_in->crypt = cbc;
    arg_in->data  = cbc_msg ;
    
    /*下发驱动*/
    for(i=0;i<count;i++)
    {
        drv_sec2_Aes_ctr_crypt(DRV_IPSEC_AES_CTR_CRYPT, arg_in);
    }
    return;
}

void sec2_test_hash_md5(void)
{
    algo_msg_ike_hash_t *hash_msg = NULL;
    algo_msg_hash_t *hash = NULL;
    UINT8 pt5[26*3] = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
    DRV_LNDEC_ALG_REQ_PARA* arg_in  = NULL; /*写消息结构,分配地址空间*/

    hash_msg = (algo_msg_ike_hash_t *)OsAlloc(sizeof(algo_msg_ike_hash_t));
    if (hash_msg == NULL)
    {
        printf("mpc190_test_hash_md5: failed to malloc hash_msg!\n");
        return;
    }
    hash_msg->msgHdr.algoid = ALGO_IKE_HASH_MD5;
    hash_msg->msgHdr.callback = sec2_test_md5_callback;
    hash_msg->msgHdr.ctx = hash_msg;
    hash_msg->msgHdr.error_callback = sec2_test_md5_err_callback;
    hash_msg->msgHdr.ISSC_num = 0;
    hash_msg->msgHdr.reply_msgId = MSG_IKE_ALGO_OK;

    hash = &(hash_msg->msgHash);

    hash->inDataLen = 64;
    hash->inData = malloc(hash->inDataLen);
    if (hash->inData == NULL)
    {
        printf("mpc190_test_hash_md5: failed to malloc inData!\n");
        OsFree(hash_msg);
        return;
    }
    memcpy(hash->inData, pt5, hash->inDataLen);

    hash->outLen = 16;
    hash->outData = malloc(hash->outLen);
    if (hash->outData == NULL)
    {
        printf("mpc190_test_hash_md5: failed to malloc outData!\n");
        free(hash->inData);
        OsFree(hash_msg);
        return;
    }
    memset(hash->outData,0,hash->outLen);

    arg_in =(DRV_LNDEC_ALG_REQ_PARA*) malloc(sizeof(DRV_LNDEC_ALG_REQ_PARA));   
    /*检测是否为空*/
    if (arg_in == NULL)
    {
        printf("mpc190_test_rng: malloc param failed!\n");
        OsFree(hash_msg);
        return;
    }
    memset(arg_in , 0, (sizeof(DRV_LNDEC_ALG_REQ_PARA)));
    arg_in->auth = hash;
    arg_in->data = hash_msg ;
    
    drv_sec2_hash_dig(DRV_IPSEC_HASH_MD5_DIG, arg_in);
    return;
}

void sec2_test_hash_sha()
{
    algo_msg_ike_hash_t *hash_msg = NULL;
    algo_msg_hash_t *hash = NULL;
    UINT8 pt5[26*3] = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
    DRV_LNDEC_ALG_REQ_PARA* arg_in  = NULL; /*写消息结构,分配地址空间*/

    hash_msg = (algo_msg_ike_hash_t *)OsAlloc(sizeof(algo_msg_ike_hash_t));
    if (hash_msg == NULL)
    {
        printf("mpc190_test_hash_md5: failed to malloc hash_msg!\n");
        return;
    }
    hash_msg->msgHdr.algoid = ALGO_IKE_HASH_SHA;
    hash_msg->msgHdr.callback = sec2_test_hash_sha_callback;
    hash_msg->msgHdr.ctx = hash_msg;
    hash_msg->msgHdr.error_callback = sec2_test_hash_sha_err_callback;
    hash_msg->msgHdr.ISSC_num = 0;
    hash_msg->msgHdr.reply_msgId = MSG_IKE_ALGO_OK;

    hash = &(hash_msg->msgHash);

    hash->inDataLen = 64;
    hash->inData = malloc(hash->inDataLen);
    if (hash->inData == NULL)
    {
        printf("mpc190_test_hash_md5: failed to malloc inData!\n");
        OsFree(hash_msg);
        return;
    }
    memcpy(hash->inData, pt5, hash->inDataLen);

    hash->outLen = 20;
    hash->outData = malloc(hash->outLen);
    memset( hash->outData,0,hash->outLen);
    if (hash->outData == NULL)
    {
        printf("mpc190_test_hash_md5: failed to malloc outData!\n");
        free(hash->inData);
        OsFree(hash_msg);
        return;
    }
    memset(hash->outData,0,hash->outLen);
    
    arg_in =(DRV_LNDEC_ALG_REQ_PARA*) malloc(sizeof(DRV_LNDEC_ALG_REQ_PARA));   
    /*检测是否为空*/
    if (arg_in == NULL)
    {
        printf("mpc190_test_rng: malloc param failed!\n");
        OsFree(hash_msg);
        return;
    }
    memset(arg_in , 0, (sizeof(DRV_LNDEC_ALG_REQ_PARA)));
    arg_in->auth = hash;
    arg_in->data = hash_msg;
    
    drv_sec2_hash_dig(DRV_IPSEC_HASH_SHA_DIG, arg_in);
    return;
}


void sec2_test_hash_sha256()
{
    algo_msg_ike_hash_t *hash_msg = NULL;
    algo_msg_hash_t *hash = NULL;
    UINT8 pt5[26*3] = "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyz";
    DRV_LNDEC_ALG_REQ_PARA* arg_in  = NULL; /*写消息结构,分配地址空间*/

    hash_msg = (algo_msg_ike_hash_t *)OsAlloc(sizeof(algo_msg_ike_hash_t));
    if (hash_msg == NULL)
    {
        printf("mpc190_test_hash_md5: failed to malloc hash_msg!\n");
        return;
    }
    hash_msg->msgHdr.algoid = ALGO_IKE_HASH_SHA;
    hash_msg->msgHdr.callback = sec2_test_hash_sha_callback;
    hash_msg->msgHdr.ctx = hash_msg;
    hash_msg->msgHdr.error_callback = sec2_test_hash_sha_err_callback;
    hash_msg->msgHdr.ISSC_num = 0;
    hash_msg->msgHdr.reply_msgId = MSG_IKE_ALGO_OK;

    hash = &(hash_msg->msgHash);

    hash->inDataLen = 64;
    hash->inData = malloc(hash->inDataLen);
    if (hash->inData == NULL)
    {
        printf("mpc190_test_hash_md5: failed to malloc inData!\n");
        OsFree(hash_msg);
        return;
    }
    memcpy(hash->inData, pt5, hash->inDataLen);

    hash->outLen = 32;
    hash->outData = malloc(hash->outLen);
    memset( hash->outData,0,hash->outLen);
    if (hash->outData == NULL)
    {
        printf("mpc190_test_hash_md5: failed to malloc outData!\n");
        free(hash->inData);
        OsFree(hash_msg);
        return;
    }
    memset(hash->outData,0,hash->outLen);

    arg_in =(DRV_LNDEC_ALG_REQ_PARA*) malloc(sizeof(DRV_LNDEC_ALG_REQ_PARA));   
    /*检测是否为空*/
    if (arg_in == NULL)
    {
        printf("mpc190_test_rng: malloc param failed!\n");
        OsFree(hash_msg);
        return;
    }
    memset(arg_in , 0, (sizeof(DRV_LNDEC_ALG_REQ_PARA)));
    arg_in->auth = hash;
    arg_in->data = hash_msg ;
    
    drv_sec2_hash_dig(DRV_IPSEC_HASH_SHA256_DIG, arg_in);
    return;
}

static const unsigned char md5padplaintext1[] = /* 64 */
{    'w','h','a','t',' ','d','o',' ',    'y','a',' ','w','a','n','t',' ',     'f','o','r',' ','n','o','t','h',    'i','n','g','?',0x80,0,0,0,    0,0,0,0,0,0,0,0,    0,0,0,0,0,0,0,0,    0,0,0,0,0,0,0,0,    0xe0,0x02,0,0,0,0,0,0};
void sec2_test_hmac_md5()
{
    algo_msg_ike_hmac_t *hmac_msg = NULL;
    algo_msg_hmac_t *hmac = NULL;
    DRV_LNDEC_ALG_REQ_PARA* arg_in  = NULL; /*写消息结构,分配地址空间*/

    hmac_msg = (algo_msg_ike_hmac_t *)OsAlloc(sizeof(algo_msg_ike_hmac_t));
    if (hmac_msg == NULL)
    {
        printf("mpc190_test_hmac_sha: failed to malloc hash_msg!\n");
        return;
    }
    hmac_msg->msgHdr.algoid = ALGO_IKE_HMAC_MD5;
    hmac_msg->msgHdr.callback = sec2_test_hmac_md5_callback;
    hmac_msg->msgHdr.ctx = hmac_msg;
    hmac_msg->msgHdr.error_callback = sec2_test_hmac_md5_err_callback;
    hmac_msg->msgHdr.ISSC_num = 0;
    hmac_msg->msgHdr.reply_msgId = MSG_IKE_ALGO_OK;
    /*ike_get_pid(&(hmac_msg->msgHdr.sender));*/

    hmac = &(hmac_msg->msgHmac);

    if(ipsecswitch==1)
    hmac->inLen = 28;
    hmac->inData = (UINT8*)md5padplaintext1;
    if(ipsecswitch==2)
    hmac->inLen = 64;
    hmac->inData = (UINT8*)md5padplaintext1;
    
    if (hmac->inData == NULL)
    {
        printf("mpc190_test_hmac_sha: failed to malloc inData!\n");
        OsFree(hmac_msg);
        return;
    }
    /*memset(hmac->inData, 0x39, 64);*/

    hmac->keyLen = 4;
    hmac->key = malloc(hmac->keyLen);
    if (hmac->key == NULL)
    {
        printf("mpc190_test_hmac_sha: failed to malloc key!\n");
        free(hmac->inData);
        OsFree(hmac_msg);
        return;
    }
    hmac->key="Jefe";
    /*memcpy(hmac->key, pt3, hmac->keyLen);*/

    hmac->outLen = 16;
    hmac->outData = malloc(32);
    if (hmac->outData == NULL)
    {
        printf("mpc190_test_hmac_sha: failed to malloc outData!\n");
        free(hmac->inData);
        free(hmac->key);
        OsFree(hmac_msg);
        return;
    }
    memset(hmac->outData,0,32);

    arg_in =(DRV_LNDEC_ALG_REQ_PARA*) malloc(sizeof(DRV_LNDEC_ALG_REQ_PARA));   
    /*检测是否为空*/
    if (arg_in == NULL)
    {
        printf("mpc190_test_rng: malloc param failed!\n");
        OsFree(hmac_msg);
        return;
    }
    memset(arg_in , 0, (sizeof(DRV_LNDEC_ALG_REQ_PARA)));
    arg_in->auth = hmac;
    arg_in->data = hmac_msg ;

    drv_sec2_hmac_auth(DRV_IPSEC_HMAC_MD5_AUTH, arg_in);
    return;
}

void sec2_test_hmac_sha(int count,int len)
{
    algo_msg_ike_hmac_t *hmac_msg = NULL;
    algo_msg_hmac_t *hmac = NULL;
    UINT8 pt3[20] = "01234567890123456789";
    int i;
    DRV_LNDEC_ALG_REQ_PARA* arg_in  = NULL; /*写消息结构,分配地址空间*/

    hmac_msg = (algo_msg_ike_hmac_t *)OsAlloc(sizeof(algo_msg_ike_hmac_t));
    if (hmac_msg == NULL)
    {
        printf("mpc190_test_hmac_sha: failed to malloc hash_msg!\n");
        return;
    }
    hmac_msg->msgHdr.algoid = ALGO_IKE_HMAC_SHA;
    hmac_msg->msgHdr.callback = sec2_test_hmac_sha_callback;
    hmac_msg->msgHdr.ctx = hmac_msg;
    hmac_msg->msgHdr.error_callback = sec2_test_hmac_sha_err_callback;
    hmac_msg->msgHdr.ISSC_num = 0;
    hmac_msg->msgHdr.reply_msgId = MSG_IKE_ALGO_OK;
    /*ike_get_pid(&(hmac_msg->msgHdr.sender));*/

    hmac = &(hmac_msg->msgHmac);

    hmac->inLen = len;
    hmac->inData = malloc(hmac->inLen);
    if (hmac->inData == NULL)
    {
        printf("mpc190_test_hmac_sha: failed to malloc inData!\n");
        OsFree(hmac_msg);
        return;
    }
    memset(hmac->inData, 0x39, hmac->inLen);

    hmac->keyLen = 20;
    hmac->key = malloc(64);
    if (hmac->key == NULL)
    {
        printf("mpc190_test_hmac_sha: failed to malloc key!\n");
        free(hmac->inData);
        OsFree(hmac_msg);
        return;
    }
    memset(hmac->key,0,64);
    memcpy(hmac->key, pt3, hmac->keyLen);

    hmac->outLen = 20;
    hmac->outData = malloc(32);
    if (hmac->outData == NULL)
    {
        printf("mpc190_test_hmac_sha: failed to malloc outData!\n");
        free(hmac->inData);
        free(hmac->key);
        OsFree(hmac_msg);
        return;
    }
    memset(hmac->outData,0, 32);

    arg_in =(DRV_LNDEC_ALG_REQ_PARA*) malloc(sizeof(DRV_LNDEC_ALG_REQ_PARA));   
    /*检测是否为空*/
    if (arg_in == NULL)
    {
        printf("mpc190_test_rng: malloc param failed!\n");
        OsFree(hmac_msg);
        return;
    }

⌨️ 快捷键说明

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