int pkha_add(int fd) { int status, tstat; 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, (void *)add_p0data, (void **)&addReq.bData, addReq.bDataBytes); if (status) return status; status = putKmem(fd, (void *)add_p1data, (void **)&addReq.aData, addReq.aDataBytes); if (status) { freeKmem(fd, (void **)&addReq.bData); return status; } status = putKmem(fd, (void *)add_p3data, (void **)&addReq.modData, addReq.modBytes); if (status) { freeKmem(fd, (void **)&addReq.bData); freeKmem(fd, (void **)&addReq.aData); return status; } status = putKmem(fd, NULL, (void **)&addReq.outData, addReq.outBytes); if (status) { freeKmem(fd, (void **)&addReq.bData); freeKmem(fd, (void **)&addReq.aData); freeKmem(fd, (void **)&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, (void **)&addReq.bData); freeKmem(fd, (void **)&addReq.aData); freeKmem(fd, (void **)&addReq.modData); freeKmem(fd, (void **)&addReq.outData); return status; } getKmem(fd, p4data, (void **)&addReq.outData, addReq.outBytes); freeKmem(fd, (void **)&addReq.bData); freeKmem(fd, (void **)&addReq.aData); freeKmem(fd, (void **)&addReq.modData); freeKmem(fd, (void **)&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); }
int pkha_rrmodp(int fd) { int status, tstat; 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, (void *)modp_p3data, (void **)&rrmodpReq.pData, rrmodpReq.pBytes); if (status) return status; status = putKmem(fd, NULL, (void **)&rrmodpReq.outData, rrmodpReq.outBytes); if (status) { freeKmem(fd, (void **)&rrmodpReq.outData); return status; } armCompletion(&rrmodpReq); status = ioctl(fd, IOCTL_PROC_REQ, (int)&rrmodpReq); if ((status = waitCompletion("testPKHA(): RRMODP test", status, &rrmodpReq))) { freeKmem(fd, (void **)&rrmodpReq.pData); freeKmem(fd, (void **)&rrmodpReq.outData); return status; } getKmem(fd, p4data, (void **)&rrmodpReq.outData, rrmodpReq.outBytes); freeKmem(fd, (void **)&rrmodpReq.pData); freeKmem(fd, (void **)&rrmodpReq.outData); if (memcmp((unsigned char *)p4data, (unsigned char *)modp_exp_p4, 40) != 0) { printf("RRMODP result miscompare\n"); printf("actual result:\n"); dumpm(p4data, 40); printf("expected result:\n"); dumpm((unsigned char *)modp_exp_p4, 40); tstat = -1; } else { printf("Results from RRMODP as expected\n"); tstat = 0; } return(tstat); }
int pkha_f2m_mult2(int fd) { int status, 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, (void *)f2mmul2_p0data, (void **)&f2m_mult2Req.bData, f2m_mult2Req.bDataBytes); if (status) return status; status = putKmem(fd, (void *)f2mmul2_p1data, (void **)&f2m_mult2Req.aData, f2m_mult2Req.aDataBytes); if (status) { freeKmem(fd, (void **)&f2m_mult2Req.bData); return status; } status = putKmem(fd, (void *)f2mmul2_p3data, (void **)&f2m_mult2Req.modData, f2m_mult2Req.modBytes); if (status) { freeKmem(fd, (void **)&f2m_mult2Req.bData); freeKmem(fd, (void **)&f2m_mult2Req.aData); return status; } status = putKmem(fd, NULL, (void **)&f2m_mult2Req.outData, f2m_mult2Req.outBytes); if (status) { freeKmem(fd, (void **)&f2m_mult2Req.bData); freeKmem(fd, (void **)&f2m_mult2Req.aData); freeKmem(fd, (void **)&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, (void **)&f2m_mult2Req.bData); freeKmem(fd, (void **)&f2m_mult2Req.aData); freeKmem(fd, (void **)&f2m_mult2Req.modData); freeKmem(fd, (void **)&f2m_mult2Req.outData); return status; } getKmem(fd, p4data, (void **)&f2m_mult2Req.outData, f2m_mult2Req.outBytes); freeKmem(fd, (void **)&f2m_mult2Req.bData); freeKmem(fd, (void **)&f2m_mult2Req.aData); freeKmem(fd, (void **)&f2m_mult2Req.modData); freeKmem(fd, (void **)&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); }
int pkha_mul2(int fd) { int status, 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, (void *)mul2_p0data, (void **)&mult2Req.bData, mult2Req.bDataBytes); if (status) return status; status = putKmem(fd, (void *)mul2_p1data, (void **)&mult2Req.aData, mult2Req.aDataBytes); if (status) { freeKmem(fd, (void **)&mult2Req.bData); return status; } status = putKmem(fd, (void *)mul2_p3data, (void **)&mult2Req.modData, mult2Req.modBytes); if (status) { freeKmem(fd, (void **)&mult2Req.bData); freeKmem(fd, (void **)&mult2Req.aData); return status; } status = putKmem(fd, NULL, (void **)&mult2Req.outData, mult2Req.outBytes); if (status) { freeKmem(fd, (void **)&mult2Req.bData); freeKmem(fd, (void **)&mult2Req.aData); freeKmem(fd, (void **)&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, (void **)&mult2Req.bData); freeKmem(fd, (void **)&mult2Req.aData); freeKmem(fd, (void **)&mult2Req.modData); freeKmem(fd, (void **)&mult2Req.outData); return status; } getKmem(fd, p4data, (void **)&mult2Req.outData, mult2Req.outBytes); freeKmem(fd, (void **)&mult2Req.bData); freeKmem(fd, (void **)&mult2Req.aData); freeKmem(fd, (void **)&mult2Req.modData); freeKmem(fd, (void **)&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); }
int pkha_subtract(int fd) { int status, tstat; 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, (void *)sub_p0data, (void **)&subReq.bData, subReq.bDataBytes); if (status) return status; status = putKmem(fd, (void *)sub_p1data, (void **)&subReq.aData, subReq.aDataBytes); if (status) { freeKmem(fd, (void **)&subReq.bData); return status; } status = putKmem(fd, (void *)sub_p3data, (void **)&subReq.modData, subReq.modBytes); if (status) { freeKmem(fd, (void **)&subReq.bData); freeKmem(fd, (void **)&subReq.aData); return status; } status = putKmem(fd, NULL, (void **)&subReq.outData, subReq.outBytes); if (status) { freeKmem(fd, (void **)&subReq.bData); freeKmem(fd, (void **)&subReq.aData); freeKmem(fd, (void **)&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, (void **)&subReq.bData); freeKmem(fd, (void **)&subReq.aData); freeKmem(fd, (void **)&subReq.modData); freeKmem(fd, (void **)&subReq.outData); return status; } getKmem(fd, p4data, (void **)&subReq.outData, subReq.outBytes); freeKmem(fd, (void **)&subReq.bData); freeKmem(fd, (void **)&subReq.aData); freeKmem(fd, (void **)&subReq.modData); freeKmem(fd, (void **)&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); }
int testTLS(int fd) { TLS_BLOCK_OUTBOUND_REQ tlsRq; int status, fail; printf("*** Test TLS Block Outbound ***\n"); /* clear request block */ memset(&tlsRq, 0, sizeof(tlsRq)); memset(packetOut, 0, 256); /* set up request */ tlsRq.opId = DPD_TLS_BLOCK_OUTBOUND_SDES_SHA1; tlsRq.hashKeyBytes = 20; tlsRq.hashKeyData = (unsigned char *)authKey; tlsRq.ivBytes = 8; tlsRq.ivData = in_iv; tlsRq.cipherKeyBytes = 8; tlsRq.cipherKeyData = (unsigned char *)EncKey; tlsRq.ivOutBytes = 8; tlsRq.ivOutData = outivdata; tlsRq.outBytes = 256; tlsRq.outData = packetOut; tlsRq.hashOnlyBytes = 13; tlsRq.mainDataBytes = 235; tlsRq.MACbytes = 20; tlsRq.cipherOnlyBytes = 1; tlsRq.hashOnlyData = packetIn; status = putKmem(fd, (void *)authKey, (void **)&tlsRq.hashKeyData, tlsRq.hashKeyBytes); if (status) return status; status = putKmem(fd, (void *)in_iv, (void **)&tlsRq.ivData, tlsRq.ivBytes); if (status) { freeKmem(fd, (void **)&tlsRq.hashKeyData); return status; } status = putKmem(fd, (void *)EncKey, (void **)&tlsRq.cipherKeyData, tlsRq.cipherKeyBytes); if (status) { freeKmem(fd, (void **)&tlsRq.hashKeyData); freeKmem(fd, (void **)&tlsRq.ivData); return status; } status = putKmem(fd, NULL, (void **)&tlsRq.ivOutData, tlsRq.ivOutBytes); if (status) { freeKmem(fd, (void **)&tlsRq.hashKeyData); freeKmem(fd, (void **)&tlsRq.ivData); freeKmem(fd, (void **)&tlsRq.cipherKeyData); return status; } status = putKmem(fd, NULL, (void **)&tlsRq.outData, tlsRq.outBytes); if (status) { freeKmem(fd, (void **)&tlsRq.hashKeyData); freeKmem(fd, (void **)&tlsRq.ivData); freeKmem(fd, (void **)&tlsRq.cipherKeyData); freeKmem(fd, (void **)&tlsRq.ivOutData); return status; } status = putKmem(fd, (void *)packetIn, (void **)&tlsRq.hashOnlyData, 284); if (status) { freeKmem(fd, (void **)&tlsRq.hashKeyData); freeKmem(fd, (void **)&tlsRq.ivData); freeKmem(fd, (void **)&tlsRq.cipherKeyData); freeKmem(fd, (void **)&tlsRq.ivOutData); freeKmem(fd, (void **)&tlsRq.outData); return status; } tlsRq.cipherOnlyData = &tlsRq.hashOnlyData[268]; armCompletion(&tlsRq); status = ioctl(fd, IOCTL_PROC_REQ, (int)&tlsRq); if ((status = waitCompletion("testTLS(): outbound block test", status, &tlsRq))) { freeKmem(fd, (void **)&tlsRq.hashKeyData); freeKmem(fd, (void **)&tlsRq.ivData); freeKmem(fd, (void **)&tlsRq.cipherKeyData); freeKmem(fd, (void **)&tlsRq.ivOutData); freeKmem(fd, (void **)&tlsRq.outData); freeKmem(fd, (void **)&tlsRq.hashOnlyData); return status; } getKmem(fd, outivdata, (void **)&tlsRq.ivOutData, tlsRq.ivOutBytes); getKmem(fd, packetOut, (void **)&tlsRq.outData, tlsRq.outBytes); freeKmem(fd, (void **)&tlsRq.hashKeyData); freeKmem(fd, (void **)&tlsRq.ivData); freeKmem(fd, (void **)&tlsRq.cipherKeyData); freeKmem(fd, (void **)&tlsRq.ivOutData); freeKmem(fd, (void **)&tlsRq.outData); freeKmem(fd, (void **)&tlsRq.hashOnlyData); /* run results comparisons */ fail = 0; if ((memcmp(outivdata, exp_iv_out, 8)) != 0) { printf("cipher context out miscompare\n"); printf("expected result:\n"); dumpm((unsigned char *)exp_iv_out, 8); printf("actual result:\n"); dumpm(outivdata, 8); fail++; } if ((memcmp(packetOut, exp_cipher_out, 256)) != 0) { printf("packet out miscompare\n"); printf("expected result:\n"); dumpm((unsigned char *)exp_cipher_out, 256); printf("actual result:\n"); dumpm(packetOut, 256); fail++; } printf("*** Test TLS Block Outbound - "); if (fail) { printf("failed ***\n"); return(-1); } else { printf("passed ***\n"); return(0); } return 0; }