请写一个单独的测试函数,而不是写在main函数当中
时间: 2024-02-18 19:00:52 浏览: 110
好的,以下是一个单独的测试函数,用于测试SKF_ECCSignData()函数的准确性和TPS性能。
```c
void testSKF_ECCSignData() {
ULONG rv, ulSize;
HAPPLICATION hApp;
HCONTAINER hContainer;
ECCPUBLICKEYBLOB eccPubKeyBlob;
ECCSIGNATUREBLOB eccSigBlob;
BYTE data[] = "hello world";
BYTE *pTmpData = NULL;
ULONG ulTmpDataLen;
// 初始化SKF库
SKF_Initialize();
// 打开应用
rv = SKF_OpenApplication("TestApp", &hApp);
if(rv != SAR_OK) {
printf("Open application failed, error code: %08x\n", rv);
goto END;
}
// 打开容器
rv = SKF_OpenContainer(hApp, "TestContainer", &hContainer);
if(rv != SAR_OK) {
printf("Open container failed, error code: %08x\n", rv);
goto CLOSE_APP;
}
// 获取公钥
ulSize = sizeof(eccPubKeyBlob);
rv = SKF_ExportPublicKey(hContainer, TRUE, &eccPubKeyBlob, &ulSize);
if(rv != SAR_OK) {
printf("Export public key failed, error code: %08x\n", rv);
goto CLOSE_CONTAINER;
}
// 签名数据
ulSize = sizeof(eccSigBlob);
rv = SKF_ECCSignData(hContainer, data, sizeof(data), &eccSigBlob, &ulSize);
if(rv != SAR_OK) {
printf("Sign data failed, error code: %08x\n", rv);
goto CLOSE_CONTAINER;
}
// 验证签名
rv = SKF_ECCVerify(hContainer, data, sizeof(data), &eccSigBlob, ulSize);
if(rv != SAR_OK) {
printf("Verify signature failed, error code: %08x\n", rv);
goto CLOSE_CONTAINER;
}
// 输出签名结果
printf("Signature:\n");
pTmpData = eccSigBlob.x;
ulTmpDataLen = ulSize / 2;
printf("R: ");
for(int i = 0; i < ulTmpDataLen; i++) {
printf("%02x", pTmpData[i]);
}
printf("\n");
pTmpData = eccSigBlob.y;
printf("S: ");
for(int i = 0; i < ulTmpDataLen; i++) {
printf("%02x", pTmpData[i]);
}
printf("\n");
CLOSE_CONTAINER:
SKF_CloseContainer(hContainer);
CLOSE_APP:
SKF_CloseApplication(hApp);
END:
SKF_Finalize();
}
```
该测试函数与上一个测试用例类似,只是将测试代码封装在了一个单独的函数中。使用该测试函数也可以对SKF_ECCSignData()函数进行准确性和TPS性能测试。
阅读全文