📄 testpkha.c
字号:
if (status) { freeKmem(fd, &mult2Req.bData); return status; } status = putKmem(fd, mul2_p3data, &mult2Req.modData, mult2Req.modBytes); if (status) { freeKmem(fd, &mult2Req.bData); freeKmem(fd, &mult2Req.aData); return status; } status = putKmem(fd, NULL, &mult2Req.outData, mult2Req.outBytes); if (status) { freeKmem(fd, &mult2Req.bData); freeKmem(fd, &mult2Req.aData); freeKmem(fd, &mult2Req.modData); return status; } armCompletion(&mult2Req); status = ioctl(fd, IOCTL_PROC_REQ, (int)&mult2Req); if (status = waitCompletion("testPKHA(): modular mult test", status, &mult2Req)) { freeKmem(fd, &mult2Req.bData); freeKmem(fd, &mult2Req.aData); freeKmem(fd, &mult2Req.modData); freeKmem(fd, &mult2Req.outData); return status; } getKmem(fd, p4data, &mult2Req.outData, mult2Req.outBytes); freeKmem(fd, &mult2Req.bData); freeKmem(fd, &mult2Req.aData); freeKmem(fd, &mult2Req.modData); freeKmem(fd, &mult2Req.outData); if (memcmp((unsigned char *)p4data, (unsigned char *)mul2_exp_p4, MUL2_DATASIZE) != 0) { dumpm(p4data, MUL2_DATASIZE); tstat = -1; } else { printf("pkha_mul2(): Results from MULT2 as expected\n"); tstat = 0; } return(tstat);}static const unsigned char f2mmul2_p0data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xb5, 0xdb, 0xef, 0x4d, 0x54, 0x20, 0xcc, 0x1a, 0x86, 0xc9, 0x89, 0x67 };static const unsigned char f2mmul2_p1data[] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x12, 0x34, 0x56, 0x78, 0x90, 0xab, 0xcd, 0xef, 0x01, 0xb2, 0x37, 0x3c, 0x16, 0xfb, 0x0b, 0xa9, 0x1b, 0x80, 0xa8, 0x10};static const unsigned char f2mmul2_p3data[] ={ 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x92, 0xfe, 0x77, 0xe7, 0x0c, 0x12, 0xa4, 0x23, 0x4c, 0x33};static const unsigned char f2mmul2_exp_p4[] ={ 0x00, 0x00, 0x00, 0x01, 0x6b, 0x9e, 0x7b, 0x1e, 0x6d, 0x4b, 0x7b, 0x64, 0xe4, 0x2a, 0xe5, 0xc4, 0x1d, 0x1b, 0x0e, 0xe5, 0x2f, 0xb1, 0xd1, 0xdf};int pkha_f2m_mult2(int fd){ int status, i, tstat; MOD_2OP_REQ f2m_mult2Req; unsigned char p4data[256]; memset (p4data, 0, 256); memset (&f2m_mult2Req, 0, sizeof(f2m_mult2Req)); /* F2M MULT2 test */ f2m_mult2Req.opId = DPD_POLY_LDCTX_A0_B0_MUL2_ULCTX; f2m_mult2Req.bDataBytes = 256; f2m_mult2Req.aDataBytes = 256; f2m_mult2Req.modBytes = 24; f2m_mult2Req.outBytes = 24; f2m_mult2Req.bData = (unsigned char *)f2mmul2_p0data; f2m_mult2Req.aData = (unsigned char *)f2mmul2_p1data; f2m_mult2Req.modData = (unsigned char *)f2mmul2_p3data; f2m_mult2Req.outData = p4data; status = putKmem(fd, f2mmul2_p0data, &f2m_mult2Req.bData, f2m_mult2Req.bDataBytes); if (status) return status; status = putKmem(fd, f2mmul2_p1data, &f2m_mult2Req.aData, f2m_mult2Req.aDataBytes); if (status) { freeKmem(fd, &f2m_mult2Req.bData); return status; } status = putKmem(fd, f2mmul2_p3data, &f2m_mult2Req.modData, f2m_mult2Req.modBytes); if (status) { freeKmem(fd, &f2m_mult2Req.bData); freeKmem(fd, &f2m_mult2Req.aData); return status; } status = putKmem(fd, NULL, &f2m_mult2Req.outData, f2m_mult2Req.outBytes); if (status) { freeKmem(fd, &f2m_mult2Req.bData); freeKmem(fd, &f2m_mult2Req.aData); freeKmem(fd, &f2m_mult2Req.modData); return status; } armCompletion(&f2m_mult2Req); status = ioctl(fd, IOCTL_PROC_REQ, (int)&f2m_mult2Req); if (status = waitCompletion("testPKHA(): modular mult test", status, &f2m_mult2Req)) { freeKmem(fd, &f2m_mult2Req.bData); freeKmem(fd, &f2m_mult2Req.aData); freeKmem(fd, &f2m_mult2Req.modData); freeKmem(fd, &f2m_mult2Req.outData); return status; } getKmem(fd, p4data, &f2m_mult2Req.outData, f2m_mult2Req.outBytes); freeKmem(fd, &f2m_mult2Req.bData); freeKmem(fd, &f2m_mult2Req.aData); freeKmem(fd, &f2m_mult2Req.modData); freeKmem(fd, &f2m_mult2Req.outData); if (memcmp((unsigned char *)p4data, (unsigned char *)f2mmul2_exp_p4, 24) != 0) { dumpm(p4data, 24); tstat = -1; } else { printf ("Results from F2M_MULT2 as expected\n"); tstat = 0; } return(tstat);}static const unsigned char modp_p3data[] ={ 0xf3, 0xc4, 0x4d, 0x17, 0x3c, 0x01, 0x2e, 0x0a, 0xec, 0x59, 0x15, 0xab, 0xe4, 0xc8, 0x9b, 0x89, 0xaa, 0x08, 0xac, 0x54, 0x5a, 0x0a, 0x0f, 0xb5, 0xaa, 0x08, 0xac, 0x54, 0x5a, 0x0a, 0x0f, 0xb5, 0xaa, 0x08, 0xac, 0x54, 0x5a, 0x0a, 0x0f, 0xb5 }; static const unsigned char modp_exp_p4[] ={ 0x37, 0x8e, 0x17, 0x36, 0x7d, 0x63, 0xf8, 0xec, 0xc7, 0x19, 0x9d, 0xbd, 0xa1, 0x16, 0xea, 0x99, 0xb8, 0x60, 0x69, 0x84, 0xa0, 0x35, 0x31, 0xa4, 0xd5, 0xd1, 0x0d, 0x59, 0x06, 0x45, 0x36, 0x8b, 0x18, 0x74, 0xe0, 0xa3, 0xbb, 0xe2, 0x51, 0xeb}; int pkha_rrmodp(int fd){ int status, i, tstat; unsigned long channel; MOD_RRMODP_REQ rrmodpReq; unsigned char p4data[256]; memset (p4data, 0, 256); memset(&rrmodpReq, 0, sizeof(rrmodpReq)); /* RRMODP test */ rrmodpReq.opId = DPD_MM_LDCTX_RRMODP_ULCTX; rrmodpReq.nBytes = 64; rrmodpReq.pBytes = 40; rrmodpReq.outBytes = 40; rrmodpReq.pData = (unsigned char *)modp_p3data; rrmodpReq.outData = p4data; status = putKmem(fd, modp_p3data, &rrmodpReq.pData, rrmodpReq.pBytes); if (status) return status; status = putKmem(fd, NULL, &rrmodpReq.outData, rrmodpReq.outBytes); if (status) { freeKmem(fd, &rrmodpReq.outData); return status; } armCompletion(&rrmodpReq); status = ioctl(fd, IOCTL_PROC_REQ, (int)&rrmodpReq); if (status = waitCompletion("testPKHA(): RRMODP test", status, &rrmodpReq)) { freeKmem(fd, &rrmodpReq.pData); freeKmem(fd, &rrmodpReq.outData); return status; } getKmem(fd, p4data, &rrmodpReq.outData, rrmodpReq.outBytes); freeKmem(fd, &rrmodpReq.pData); freeKmem(fd, &rrmodpReq.outData); if (memcmp((unsigned char *)p4data, (unsigned char *)modp_exp_p4, 40) != 0) { dumpm(p4data, 40); tstat = -1; } else { printf("Results from RRMODP as expected\n"); tstat = 0; } return(tstat);}/* Basis of main Public Key feature test */int testPKHA(int fd){ printf ("testPKHA(): Public Key Hardware Accelerator test started\n"); pkhaTestStatus = 0; #ifdef TESTPKHA_ADD if (pkha_add(fd)) pkhaTestStatus++;#endif#ifdef TESTPKHA_SUBTRACT if (pkha_subtract(fd)) pkhaTestStatus++;#endif#ifdef TESTPKHA_MULT if (pkha_mul2(fd)) pkhaTestStatus++;#endif#ifdef TESTPKHA_F2MMULT if (pkha_f2m_mult2(fd)) pkhaTestStatus++;#endif#ifdef TESTPKHA_EXPO if (pkha_exp_ss(fd)) pkhaTestStatus++;#endif#ifdef TESTPKHA_RRMODP if (pkha_rrmodp(fd)) pkhaTestStatus++;#endif#ifdef TESTPKHA_ECC_MULTK if (testEccFpPtMultkPtoQAff(fd)) pkhaTestStatus++; if (testEccMultkPtoQf2mAff(fd)) pkhaTestStatus++; if (testEccF2mPtMultkPtoQAff2(fd)) pkhaTestStatus++; if (testEccFpPtMultkPtoQProj(fd)) pkhaTestStatus++; if (testEccMultkPtoQf2mProj(fd)) pkhaTestStatus++;#endif if (!pkhaTestStatus) printf("testPKHA(): All Tests Passed\n"); else printf("testPKHA(): %d Tests Failed\n", pkhaTestStatus); return(pkhaTestStatus);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -