📄 testpkha.c
字号:
/**************************************************************************** * testPKHA.c - Public key known-answer test for SEC2 device 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: * 1.1.0 Dec 05,2004 sec - prep for linux-compatible driver release * 1.2 02-Feb-2005 sec - type fixes, buffer frees fixed */#include "sec2drvTest.h"#include "Sec2.h" /* driver interfaces for this security core */#define TESTPKHA_ADD#define TESTPKHA_SUBTRACT#define TESTPKHA_MULT#define TESTPKHA_F2MMULT#define TESTPKHA_RRMODP#define TESTPKHA_EXPO#define TESTPKHA_ECC_MULTKint pkhaTestStatus; /* overall test status */static const unsigned char add_p0data[] = { 0x00, 0x00, 0x00, 0x00, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65};static const unsigned char add_p1data[] = { 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22};static const unsigned char add_p3data[] = { 0x00, 0x00, 0x00, 0x00, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99};static const unsigned char add_exp_p4[] = { 0x00, 0x00, 0x00, 0x00, 0x67, 0x87, 0x67, 0x87, 0x67, 0x87, 0x67, 0x87, 0x67, 0x87, 0x67, 0x87, 0x67, 0x87, 0x67, 0x87, 0x67, 0x87, 0x67, 0x87, 0x67, 0x87, 0x67, 0x87, 0x67, 0x87, 0x67, 0x87};int pkha_add(int fd){ int status, tstat, i; MOD_2OP_REQ addReq; unsigned char p4data[32]; memset(p4data, 0, 32); memset(&addReq, 0, sizeof(addReq)); /* ADD test */ addReq.opId = DPD_MM_LDCTX_ADD_ULCTX; addReq.bDataBytes = 32; addReq.aDataBytes = 32; addReq.modBytes = 32; addReq.outBytes = 32; addReq.bData = (unsigned char *)add_p0data; addReq.aData = (unsigned char *)add_p1data; addReq.modData = (unsigned char *)add_p3data; addReq.outData = p4data; status = putKmem(fd, add_p0data, &addReq.bData, addReq.bDataBytes); if (status) return status; status = putKmem(fd, add_p1data, &addReq.aData, addReq.aDataBytes); if (status) { freeKmem(fd, &addReq.bData); return status; } status = putKmem(fd, add_p3data, &addReq.modData, addReq.modBytes); if (status) { freeKmem(fd, &addReq.bData); freeKmem(fd, &addReq.aData); return status; } status = putKmem(fd, NULL, &addReq.outData, addReq.outBytes); if (status) { freeKmem(fd, &addReq.bData); freeKmem(fd, &addReq.aData); freeKmem(fd, &addReq.modData); return status; } armCompletion(&addReq); status = ioctl(fd, IOCTL_PROC_REQ, (int)&addReq); if (status = waitCompletion("testPKHA(): modular add test", status, &addReq)) { freeKmem(fd, &addReq.bData); freeKmem(fd, &addReq.aData); freeKmem(fd, &addReq.modData); freeKmem(fd, &addReq.outData); return status; } getKmem(fd, p4data, &addReq.outData, addReq.outBytes); freeKmem(fd, &addReq.bData); freeKmem(fd, &addReq.aData); freeKmem(fd, &addReq.modData); freeKmem(fd, &addReq.outData); if (memcmp((unsigned char *)p4data, (unsigned char *)add_exp_p4, 32) != 0) { dumpm(p4data, 32); tstat = -1; } else { printf("Results from ADD as expected\n"); tstat = 0; } return(tstat);}static const unsigned char sub_p1data[] = { 0x00, 0x00, 0x00, 0x00, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65, 0x45, 0x65};static const unsigned char sub_p0data[] = { 0x00, 0x00, 0x00, 0x00, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22, 0x22};static const unsigned char sub_p3data[] = { 0x00, 0x00, 0x00, 0x00, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99, 0x99}; static const unsigned char sub_exp_p4[] = { 0x00, 0x00, 0x00, 0x00, 0x23, 0x43, 0x23, 0x43, 0x23, 0x43, 0x23, 0x43, 0x23, 0x43, 0x23, 0x43, 0x23, 0x43, 0x23, 0x43, 0x23, 0x43, 0x23, 0x43, 0x23, 0x43, 0x23, 0x43, 0x23, 0x43, 0x23, 0x43};int pkha_subtract(int fd){ int device, status, tstat, i; MOD_2OP_REQ subReq; unsigned char p4data[256]; memset (p4data, 0, 256); memset (&subReq, 0, sizeof(subReq)); /* SUBTRACT test */ subReq.opId = DPD_MM_LDCTX_SUB_ULCTX; subReq.bDataBytes = 28; subReq.aDataBytes = 28; subReq.modBytes = 28; subReq.outBytes = 28; subReq.bData = (unsigned char *)sub_p0data; subReq.aData = (unsigned char *)sub_p1data; subReq.modData = (unsigned char *)sub_p3data; subReq.outData = p4data; status = putKmem(fd, sub_p0data, &subReq.bData, subReq.bDataBytes); if (status) return status; status = putKmem(fd, sub_p1data, &subReq.aData, subReq.aDataBytes); if (status) { freeKmem(fd, &subReq.bData); return status; } status = putKmem(fd, sub_p3data, &subReq.modData, subReq.modBytes); if (status) { freeKmem(fd, &subReq.bData); freeKmem(fd, &subReq.aData); return status; } status = putKmem(fd, NULL, &subReq.outData, subReq.outBytes); if (status) { freeKmem(fd, &subReq.bData); freeKmem(fd, &subReq.aData); freeKmem(fd, &subReq.modData); return status; } armCompletion(&subReq); status = ioctl(fd, IOCTL_PROC_REQ, (int)&subReq); if (status = waitCompletion("testPKHA(): modular subtraction test", status, &subReq)) { freeKmem(fd, &subReq.bData); freeKmem(fd, &subReq.aData); freeKmem(fd, &subReq.modData); freeKmem(fd, &subReq.outData); return status; } getKmem(fd, p4data, &subReq.outData, subReq.outBytes); freeKmem(fd, &subReq.bData); freeKmem(fd, &subReq.aData); freeKmem(fd, &subReq.modData); freeKmem(fd, &subReq.outData); if (memcmp((unsigned char *)p4data, (unsigned char *)sub_exp_p4, 28) != 0) { dumpm(p4data, 28); tstat = -1; } else { printf ("Results from SUBTRACT as expected\n"); tstat = 0; } return(tstat);}#define MUL2_DATASIZE (128)static const unsigned char mul2_p0data[] ={ 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23, 0x5f, 0xed, 0x51, 0x23};static const unsigned char mul2_p1data[] ={ 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef};static const unsigned char mul2_p3data[] = { 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5, 0xa5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xef, 0x02, 0x35, 0x24, 0xef, 0x02, 0x35, 0x24, 0xef, 0x02, 0x35, 0x24, 0xef, 0x02, 0x35, 0x24, 0xef, 0x02, 0x35, 0x24, 0xef, 0x02, 0x35, 0x24, 0xef, 0x02, 0x35, 0x24, 0xef, 0x02, 0x35, 0x24, 0xef, 0x02, 0x35, 0x24, 0xef, 0x02, 0x35, 0x24, 0xef, 0x02, 0x35, 0x24, 0xef, 0x02, 0x35, 0x24, 0xef, 0x02, 0x35, 0x24, 0xef};int pkha_mul2(int fd){ int status, i, tstat; MOD_2OP_REQ mult2Req; unsigned char p4data[MUL2_DATASIZE]; memset(p4data, 0, MUL2_DATASIZE); memset(&mult2Req, 0, sizeof(mult2Req)); /* MULT2 test */ mult2Req.opId = DPD_MM_LDCTX_MUL2_ULCTX; mult2Req.bDataBytes = MUL2_DATASIZE; mult2Req.aDataBytes = MUL2_DATASIZE; mult2Req.modBytes = MUL2_DATASIZE; mult2Req.outBytes = MUL2_DATASIZE; mult2Req.bData = (unsigned char *)mul2_p0data; mult2Req.aData = (unsigned char *)mul2_p1data; mult2Req.modData = (unsigned char *)mul2_p3data; mult2Req.outData = p4data; status = putKmem(fd, mul2_p0data, &mult2Req.bData, mult2Req.bDataBytes); if (status) return status; status = putKmem(fd, mul2_p1data, &mult2Req.aData, mult2Req.aDataBytes);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -