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

📄 morepkhatest.c

📁 freescale ppc sec2加解密单元驱动
💻 C
📖 第 1 页 / 共 3 页
字号:
/**************************************************************************** * morepkhaTest.c - Elliptic curve known-answer testsrt for SEC2 driver **************************************************************************** * Copyright (c) 2004-2005 Freescale Semiconductor * All Rights Reserved. Proprietary and Confidential. * * NOTICE: The information contained in this file is proprietary * to Freescale Semiconductor, and is being made available to * Freescale's customers under strict license agreements. * Use or disclosure of this information is permissible only * under the terms of the existing license agreement. ***************************************************************************//* Revision History: *  01a,  May 02,2003 dgs  *        Jun 14,2004 sec - convert for compounded ECC operations for SEC2  *  1.1.0 Dec 05,2004 sec - prep for Linux-compatible driver release *  1.2   02-Feb-2005 sec - convert test data to const types */#include "sec2drvTest.h"#include "Sec2.h"/* New MULTK P to Q F2M Affine test *//* This one builds the field from raw data *//* input a0 = 19 bytes */static const unsigned char pqf2mAff_a0[] = {    0x04, 0x2d, 0x9c, 0x6c, 0xf4, 0x20, 0xd2, 0x8f,    0x5d, 0xf5, 0xef, 0x21, 0xa3, 0x29, 0xf3, 0xc2,    0x0a, 0xb0, 0xa5};/* input a1 = 19 bytes */static const unsigned char pqf2mAff_a1[] ={    0x04, 0xed, 0x25, 0x64, 0x5c, 0x5e, 0x0a, 0xa3,    0x54, 0xb8, 0x19, 0x3e, 0xab, 0xcd, 0x09, 0x75,    0x00, 0x2d, 0x31};/* input a2 = 19 bytes */static const unsigned char pqf2mAff_a2[] ={    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x01};  /* input a3 = 19 bytes */static const unsigned char pqf2mAff_a3[] ={    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00};  /* input b1 = 19 bytes */static const unsigned char pqf2mAff_b0[] ={    0x03, 0x06, 0x2e, 0x4f, 0x2d, 0xb1, 0x7b, 0xfc,    0x75, 0x1f, 0xa4, 0xab, 0xb5, 0x22, 0xf3, 0xe7,    0xb7, 0x97, 0xb2};  /* input b2 = 19 bytes */static const unsigned char pqf2mAff_b1[] ={    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,     0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,    0x00, 0x00, 0x00};/* expected output from array build operation - 384 bytes */static const unsigned char pqf2mAff_exp_build[] ={    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x2d, 0x9c,    0x6c, 0xf4, 0x20, 0xd2, 0x8f, 0x5d, 0xf5, 0xef,    0x21, 0xa3, 0x29, 0xf3, 0xc2, 0x0a, 0xb0, 0xa5,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0xed, 0x25,    0x64, 0x5c, 0x5e, 0x0a, 0xa3, 0x54, 0xb8, 0x19,    0x3e, 0xab, 0xcd, 0x09, 0x75, 0x00, 0x2d, 0x31,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x06, 0x2e,    0x4f, 0x2d, 0xb1, 0x7b, 0xfc, 0x75, 0x1f, 0xa4,    0xab, 0xb5, 0x22, 0xf3, 0xe7, 0xb7, 0x97, 0xb2,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x00,    0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00};static const unsigned char pqf2mAff_n[] = {    0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08,    0x00, 0x00, 0x01};  static const unsigned char pqf2mAff_e[] ={    0x03};static const unsigned char pqf2mAff_exp_b1[] = {    0x09, 0xa5, 0x55, 0x55, 0x9b, 0xf2, 0x2e, 0xf0,    0xa1, 0xbf, 0x61, 0xa9, 0xe8, 0x5d, 0x47, 0xda,    0x95, 0x25, 0xfb};  static const unsigned char pqf2mAff_exp_b2[] = {    0x00, 0x33, 0x9d, 0xc8, 0x47, 0xed, 0xd9, 0xe2,    0x99, 0x11, 0x14, 0x27, 0x73, 0xff, 0xff, 0xdb,    0xcb, 0xb0, 0xe4};int testEccMultkPtoQf2mAff(int fd){    int              stat, tstat;    ECC_SPKBUILD_REQ ecc_buildReq;    ECC_POINT_REQ    eccPtRq;    unsigned char    buildOut[384], b1out[19], b2out[19];    tstat  = 0;    memset(buildOut, 0, 384);    memset(&ecc_buildReq, 0, sizeof(ecc_buildReq));    memset(&eccPtRq, 0, sizeof(ECC_POINT_REQ));      printf("ECC F2M Point Multiply Affine Test\n");        ecc_buildReq.opId            = DPD_EC_SPKBUILD;    ecc_buildReq.a0Data          = (unsigned char *)pqf2mAff_a0;    ecc_buildReq.a0DataBytes     = 19;    ecc_buildReq.a1Data          = (unsigned char *)pqf2mAff_a1;    ecc_buildReq.a1DataBytes     = 19;    ecc_buildReq.a2Data          = (unsigned char *)pqf2mAff_a2;    ecc_buildReq.a2DataBytes     = 19;    ecc_buildReq.a3Data          = (unsigned char *)pqf2mAff_a3;    ecc_buildReq.a3DataBytes     = 19;    ecc_buildReq.b0Data          = (unsigned char *)pqf2mAff_b0;    ecc_buildReq.b0DataBytes     = 19;    ecc_buildReq.b1Data          = (unsigned char *)pqf2mAff_b1;    ecc_buildReq.b1DataBytes     = 19;    ecc_buildReq.buildData       = buildOut;    ecc_buildReq.buildDataBytes  = 384;      stat = putKmem(fd, pqf2mAff_a0, &ecc_buildReq.a0Data, ecc_buildReq.a0DataBytes);    if (stat)        return -1;    stat = putKmem(fd, pqf2mAff_a1, &ecc_buildReq.a1Data, ecc_buildReq.a1DataBytes);    if (stat)    {        freeKmem(fd, &ecc_buildReq.a0Data);        return -1;    }    stat = putKmem(fd, pqf2mAff_a2, &ecc_buildReq.a2Data, ecc_buildReq.a2DataBytes);    if (stat)    {        freeKmem(fd, &ecc_buildReq.a0Data);        freeKmem(fd, &ecc_buildReq.a1Data);        return -1;    }    stat = putKmem(fd, pqf2mAff_a3, &ecc_buildReq.a3Data, ecc_buildReq.a3DataBytes);    if (stat)    {        freeKmem(fd, &ecc_buildReq.a0Data);        freeKmem(fd, &ecc_buildReq.a1Data);        freeKmem(fd, &ecc_buildReq.a2Data);        return -1;    }    stat = putKmem(fd, pqf2mAff_b0, &ecc_buildReq.b0Data, ecc_buildReq.b0DataBytes);    if (stat)    {        freeKmem(fd, &ecc_buildReq.a0Data);        freeKmem(fd, &ecc_buildReq.a1Data);        freeKmem(fd, &ecc_buildReq.a2Data);        freeKmem(fd, &ecc_buildReq.a3Data);        return -1;    }    stat = putKmem(fd, pqf2mAff_b1, &ecc_buildReq.b1Data, ecc_buildReq.b1DataBytes);    if (stat)    {        freeKmem(fd, &ecc_buildReq.a0Data);        freeKmem(fd, &ecc_buildReq.a1Data);        freeKmem(fd, &ecc_buildReq.a2Data);        freeKmem(fd, &ecc_buildReq.a3Data);        freeKmem(fd, &ecc_buildReq.b0Data);        return -1;    }    stat = putKmem(fd, NULL, &ecc_buildReq.buildData, ecc_buildReq.buildDataBytes);    if (stat)    {        freeKmem(fd, &ecc_buildReq.a0Data);        freeKmem(fd, &ecc_buildReq.a1Data);        freeKmem(fd, &ecc_buildReq.a2Data);        freeKmem(fd, &ecc_buildReq.a3Data);        freeKmem(fd, &ecc_buildReq.b0Data);        freeKmem(fd, &ecc_buildReq.b1Data);        return -1;    }    armCompletion(&ecc_buildReq);    stat = ioctl(fd, IOCTL_PROC_REQ, (int)&ecc_buildReq);    if (stat = waitCompletion("testPKHA(): elliptic curve set build test", stat, &ecc_buildReq))    {        freeKmem(fd, &ecc_buildReq.a0Data);        freeKmem(fd, &ecc_buildReq.a1Data);        freeKmem(fd, &ecc_buildReq.a2Data);        freeKmem(fd, &ecc_buildReq.a3Data);        freeKmem(fd, &ecc_buildReq.b0Data);        freeKmem(fd, &ecc_buildReq.b1Data);        freeKmem(fd, &ecc_buildReq.buildData);    }        getKmem(fd, buildOut, &ecc_buildReq.buildData, ecc_buildReq.buildDataBytes);    freeKmem(fd, &ecc_buildReq.a0Data);    freeKmem(fd, &ecc_buildReq.a1Data);    freeKmem(fd, &ecc_buildReq.a2Data);    freeKmem(fd, &ecc_buildReq.a3Data);    freeKmem(fd, &ecc_buildReq.b0Data);    freeKmem(fd, &ecc_buildReq.b1Data);    freeKmem(fd, &ecc_buildReq.buildData);    if (memcmp(buildOut, pqf2mAff_exp_build, 384) != 0)    {        printf("ECC Point Multiply Affine Test SPKbuild output data miscompare\n");        dumpm(buildOut, 384);        tstat = -1;    }    /* Now that the build is done, go do the multiply */    eccPtRq.opId            = DPD_EC_F2M_AFF_LDCTX_kP_ULCTX;    eccPtRq.nDataBytes      = 19;    eccPtRq.nData           = (unsigned char *)pqf2mAff_n;    eccPtRq.eDataBytes      = 1;    eccPtRq.eData           = (unsigned char *)pqf2mAff_e;    eccPtRq.buildDataBytes  = 384;    eccPtRq.buildData       = buildOut;    eccPtRq.b1DataBytes     = 19;    eccPtRq.b1Data          = b1out;    eccPtRq.b2DataBytes     = 19;    eccPtRq.b2Data          = b2out;    stat = putKmem(fd, pqf2mAff_n, &eccPtRq.nData, eccPtRq.nDataBytes);    if (stat)        return -1;    stat = putKmem(fd, pqf2mAff_e, &eccPtRq.eData, eccPtRq.eDataBytes);    if (stat)    {        freeKmem(fd, &eccPtRq.nData);        return -1;    }    stat = putKmem(fd, buildOut, &eccPtRq.buildData, eccPtRq.buildDataBytes);    if (stat)    {        freeKmem(fd, &eccPtRq.nData);        freeKmem(fd, &eccPtRq.eData);        return -1;    }    stat = putKmem(fd, NULL, &eccPtRq.b1Data, eccPtRq.b1DataBytes);    if (stat)    {        freeKmem(fd, &eccPtRq.nData);        freeKmem(fd, &eccPtRq.eData);        freeKmem(fd, &eccPtRq.buildData);        return -1;    }    stat = putKmem(fd, NULL, &eccPtRq.b2Data, eccPtRq.b2DataBytes);    if (stat)    {        freeKmem(fd, &eccPtRq.nData);        freeKmem(fd, &eccPtRq.eData);        freeKmem(fd, &eccPtRq.buildData);        freeKmem(fd, &eccPtRq.b1Data);        return -1;    }    armCompletion(&eccPtRq);    stat = ioctl(fd, IOCTL_PROC_REQ, (int)&eccPtRq);    if (stat = waitCompletion("testPKHA(): ECC P->Q F2M Affine test", stat, &eccPtRq))    {        freeKmem(fd, &eccPtRq.nData);        freeKmem(fd, &eccPtRq.eData);        freeKmem(fd, &eccPtRq.buildData);        freeKmem(fd, &eccPtRq.b1Data);        freeKmem(fd, &eccPtRq.b2Data);    }        getKmem(fd, b1out, &eccPtRq.b1Data, eccPtRq.b1DataBytes);    getKmem(fd, b2out, &eccPtRq.b2Data, eccPtRq.b1DataBytes);    freeKmem(fd, &eccPtRq.nData);    freeKmem(fd, &eccPtRq.eData);    freeKmem(fd, &eccPtRq.buildData);    freeKmem(fd, &eccPtRq.b1Data);    freeKmem(fd, &eccPtRq.b2Data);  if (memcmp(b1out, pqf2mAff_exp_b1, 19) != 0)  {    printf("ECC Point Multiply Affine Test output B1 data miscompare\n");    dumpm(b1out, 19);    tstat = -1;  }  if (memcmp(b2out, pqf2mAff_exp_b2, 19) != 0)  {    printf("ECC Point Multiply Affine Test output B2 data miscompare\n");    dumpm(b2out, 19);    tstat = -1;  }  if (!tstat)    printf("ECC Point Multiply Affine Test test passed\n");          return(tstat);}static const unsigned char ptpqAff_MODULUS[] =  /* 20 bytes */{    0xed, 0xbe, 0x63, 0xac,    0x07, 0xf2, 0x60, 0x10,    0xfb, 0x91, 0xc1, 0x5f,    0x9e, 0x5d, 0x75, 0xca,    0x39, 0x3d, 0x73, 0x6b};  static const unsigned char ptpqAff_e[] =  /* 20 bytes */{    0x02, 0x72, 0x27, 0x96,    0x6b, 0x6b, 0x9f, 0x53,    0x84, 0x1f, 0x7b, 0x03,    0x2b, 0x2f, 0xa9, 0x30,    0x35, 0x28, 0xb2, 0xf2};    static const unsigned char ptpqAff_builddata[] = /* 384 bytes */{    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0xe1, 0x34, 0x60, 0x37,    0x7d, 0x80, 0xa4, 0x91, 0xae, 0x4a, 0x06, 0x9f,    0xcf, 0x1c, 0xcf, 0xf3, 0x7a, 0xe0, 0x72, 0x33,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0xea, 0x0a, 0xd5, 0xd3,    0xde, 0x97, 0x7a, 0x76, 0xdd, 0xc1, 0x7b, 0xb6,    0xea, 0xb0, 0xc8, 0x2b, 0x7f, 0x10, 0x8e, 0xf4,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,    0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,

⌨️ 快捷键说明

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