首页 > 其他分享 >实验二-密码引擎-3-sdf接口

实验二-密码引擎-3-sdf接口

时间:2024-04-15 22:46:36浏览次数:28  
标签:rv tv MAX 接口 sdf 引擎 free SGD loop

`/*************************************************************************
	> File Name: test.c
	> Author: 
	> Mail: 
	> Created Time: 2018年04月26日 星期四 16时01分52秒
 ************************************************************************/

#include<stdio.h>
#include <string.h>
#include"sdf.h"
#include<pthread.h>
#include<sys/time.h>
#include<sys/types.h>
#include <stdlib.h>
#define ROOTKEY   "\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0A\x0B\x0C\x0D\x0E\x0F\x10"
#define DEVSN "hs_0000000000001"
#define MAX (4000)
//#define MAX (1536)
#define LOOP (1000)

SGD_UCHAR pubKey[64] = {
	0X00,0X53,0X61,0X6c,0X74,0X65,0X64,0X5f,0X5f,0X90,0X31,0X05,0Xf0,0Xe1,0X91,0X23,0X8b,
	0X20,0Xc6,0X57,0X6b,0X0d,0X18,0X0e,0X6c,0X1b,0X57,0Xeb,0X73,0Xd3,0X75,0X50,0X64,0Xde,
	0X40,0X48,0X24,0X5b,0X1b,0Xd4,0X80,0Xa6,0X3f,0X34,0X67,0Xd0,0Xc7,0X03,0Xa3,0X99,0Xc6
};

SGD_UCHAR priKey[32] = {
	0x32,0x30,0x32,0x31,0x31,0x33,0x30,0x37,0x6c,0x77,0x6a,0x0a,0x32,0x30,0x32,0x31,
	0x31,0x33,0x32,0x39,0x73,0x79,0x6a,0x0a
};

SGD_UCHAR pubKeyEnc[64] = {
	0x19, 0x0e, 0x9e, 0x10, 0x5a, 0x12, 0xd5, 0x9b, 
	0xd5, 0x59, 0x5d, 0x7d, 0x06, 0xbe, 0xe0, 0x1b, 
	0x15, 0x44, 0xcc, 0x16, 0x1a, 0x34, 0xcc, 0x36, 
	0xe0, 0xbd, 0xa6, 0x83, 0x03, 0x97, 0xb5, 0x2e, 
	0x7f, 0xb5, 0x1a, 0xf6, 0x0e, 0xf9, 0xb7, 0x00, 
	0x88, 0x21, 0xdd, 0xda, 0xca, 0x2a, 0x18, 0xe9, 
	0x57, 0x49, 0xce, 0x49, 0xdc, 0x5f, 0xb9, 0x4d, 
	0xb8, 0xc8, 0x5c, 0xde, 0x96, 0xfb, 0x2b, 0x39,
};

SGD_UCHAR priKeyEnc[32] = {
	0x3a, 0x7e, 0xff, 0x53, 0x3d, 0x23, 0xd1, 0x3a,
	0xde, 0x97, 0x4b, 0xc3, 0x65, 0x3c, 0xd1, 0x43,
	0x20, 0x31, 0x98, 0xe4, 0x48, 0x7f, 0x5b, 0xc0, 
	0x01, 0xd7, 0xe9, 0x5e, 0x20, 0xfc, 0xa1, 0xc5
};

SGD_UCHAR eccXYD[96] = {
	0x19, 0x0e, 0x9e, 0x10, 0x5a, 0x12, 0xd5, 0x9b, 
	0xd5, 0x59, 0x5d, 0x7d, 0x06, 0xbe, 0xe0, 0x1b, 
	0x15, 0x44, 0xcc, 0x16, 0x1a, 0x34, 0xcc, 0x36, 
	0xe0, 0xbd, 0xa6, 0x83, 0x03, 0x97, 0xb5, 0x2e, 
	0x7f, 0xb5, 0x1a, 0xf6, 0x0e, 0xf9, 0xb7, 0x00, 
	0x88, 0x21, 0xdd, 0xda, 0xca, 0x2a, 0x18, 0xe9, 
	0x57, 0x49, 0xce, 0x49, 0xdc, 0x5f, 0xb9, 0x4d, 
	0xb8, 0xc8, 0x5c, 0xde, 0x96, 0xfb, 0x2b, 0x39,
	0x3a, 0x7e, 0xff, 0x53, 0x3d, 0x23, 0xd1, 0x3a,
	0xde, 0x97, 0x4b, 0xc3, 0x65, 0x3c, 0xd1, 0x43,
	0x20, 0x31, 0x98, 0xe4, 0x48, 0x7f, 0x5b, 0xc0, 
	0x01, 0xd7, 0xe9, 0x5e, 0x20, 0xfc, 0xa1, 0xc5,
};

SGD_UCHAR eccXYDHash[32] = {
	0x4d,0x98,0x98,0x32,0x72,0xe7,0x25,0x35,0x10,0xca,0xa3,0x87,0x0d,0xee,0xc8,0x90,
	0xe0,0x50,0x4d,0xd1,0xda,0x14,0xef,0x57,0x25,0x94,0x75,0x4b,0x7d,0x94,0x51,0x57,

};

SGD_UINT8 sm3HashData[32];

void myprintf(SGD_UCHAR *pucData, SGD_UINT32 uiDataLen)
{
	int i = 0;
	for(i = 0; i < uiDataLen; i++)
	{
		if(i != 0 && i % 4 == 0)
			printf(" ");
		if(i != 0 && i % 32 == 0)
			printf("\n");
		printf("%02x", pucData[i]);
	}
	printf("\n");
}

SGD_RV EccBackUpKeyPair(SGD_HANDLE phSessionHandle)
{
	SGD_RV rv = SDR_OK;
	SGD_UCHAR eccKeyPair[2048] = {0};
	SGD_UINT32 eccKeyPairLen = 2048;
	rv = SDF_ECCBackUp(phSessionHandle,1,eccKeyPair,&eccKeyPairLen);
	if(SDR_OK != rv)
	{
		printf("Ecc Back Up failed --- \n");
	}
	return rv ;
}


SGD_RV ImportKeyPair(SGD_HANDLE phSessionHandle)
{
	SGD_RV rv = SDR_OK;
	SGD_UCHAR eccKeyPairEnc[96] = {0};
	SGD_UINT32 eccKeyPairLen = 96;
	memcpy(eccKeyPairEnc, pubKeyEnc, 64);
	memcpy(eccKeyPairEnc + 64, priKeyEnc, 32);
	rv = SDF_ImportECCKeyPair(phSessionHandle,1,(const SGD_UCHAR *)eccKeyPairEnc);
	if(SDR_OK != rv)
	{
		return rv;
	}
	return rv;
}

SGD_RV SM1_ENC_DEC_ECB(SGD_HANDLE phSessionHandle,SGD_HANDLE phKeyHandle)
{

	SGD_RV rv = SDR_OK;
	int loop = LOOP, i = 0;
	SGD_UCHAR pucIV[16] ={0};
	memset(pucIV, 1, 16);
	SGD_UCHAR *pucData = (SGD_UCHAR*)malloc(loop * MAX);
	SGD_UINT32 uiDataLength = loop * MAX;
	SGD_UCHAR *pucEncData = (SGD_UCHAR*)malloc(loop * MAX);
	SGD_UINT32 puiEncDataLength = loop * MAX;
    SGD_UCHAR pucKey[16];
	memset(pucKey,2,16);

	for(i = 0; i < loop * MAX; i++)
	{
		pucData[i] = i % 256;
	}

	unsigned long long L1,L2,L3, L4;
	struct timeval tv;
	gettimeofday(&tv, NULL);
	L1 = tv.tv_sec*1000*1000 + tv.tv_usec;
	
	for(i = 0;i < loop; i++)
	{
		rv = SDF_Encrypt( phSessionHandle,pucKey, SGD_SM1_ECB,pucIV, &pucData[i * MAX], MAX, &pucEncData[i * MAX], &puiEncDataLength);
		if(SDR_OK != rv)
		{
			free(pucData);
			free(pucEncData);
			return rv;
		}
	}
	gettimeofday(&tv, NULL);
	L2 = tv.tv_sec*1000*1000 + tv.tv_usec;
	printf("SGD_SM1_ECB Encrypt datasize: %d Bytes used time: %lld us\n",loop * MAX, L2 - L1);
	printf("SGD_SM1_ECB Encrypt average speed: %d bps\n", (int)((long long)MAX*loop*8*1000000/(L2 - L1)));

	SGD_UCHAR *pucTmpData = (SGD_UCHAR*)malloc(loop * MAX);
	memset(pucIV,1,16);
	gettimeofday(&tv, NULL);
	L3 = tv.tv_sec*1000*1000 + tv.tv_usec;
	for(i = 0; i < loop; i++)
	{
		rv = SDF_Decrypt(phSessionHandle,pucKey, SGD_SM1_ECB, pucIV, &pucEncData[i * MAX], MAX, &pucTmpData[i * MAX], &puiEncDataLength);
		if(SDR_OK != rv)
		{
			free(pucData);
			free(pucEncData);
			free(pucTmpData);
			return rv;
		}
	
	}
	gettimeofday(&tv, NULL);
	L4 = tv.tv_sec*1000*1000 + tv.tv_usec;
	
	printf("SGD_SM1_ECB Decrypt datasize: %d Bytes used time: %lld us\n",loop * MAX, L4 - L3);
	printf("SGD_SM1_ECB Decrypt average speed: %d bps\n", (int)((long long)MAX*loop*8*1000000/(L4 - L3)));

	if(memcmp(pucData,pucTmpData,loop * MAX))
	{
		free(pucData);
		free(pucEncData);
		free(pucTmpData);
		printf("memcmp    diff\n");
		return -1;
	}
	
	free(pucData);
	free(pucEncData);
	free(pucTmpData);
	return SDR_OK;
}
SGD_RV SM1_ENC_DEC_CBC(SGD_HANDLE phSessionHandle,SGD_HANDLE phKeyHandle)
{

	SGD_RV rv = SDR_OK;
	int loop = LOOP, i = 0;
	SGD_UCHAR pucIV[16] ={0};
	memset(pucIV, 1, 16);
	SGD_UCHAR *pucData = (SGD_UCHAR*)malloc(loop * MAX);
	SGD_UINT32 uiDataLength = loop * MAX;
	SGD_UCHAR *pucEncData = (SGD_UCHAR*)malloc(loop * MAX);
	SGD_UINT32 puiEncDataLength = loop * MAX;
    SGD_UCHAR pucKey[16];
	memset(pucKey,2,16);

	for(i = 0; i < loop * MAX; i++)
	{
		pucData[i] = i % 256;
	}

	unsigned long long L1,L2,L3, L4;
	struct timeval tv;
	gettimeofday(&tv, NULL);
	L1 = tv.tv_sec*1000*1000 + tv.tv_usec;
	
	for(i = 0;i < loop; i++)
	{
		rv = SDF_Encrypt( phSessionHandle,pucKey, SGD_SM1_CBC,pucIV, &pucData[i * MAX], MAX, &pucEncData[i * MAX], &puiEncDataLength);
		if(SDR_OK != rv)
		{
			free(pucData);
			free(pucEncData);
			return rv;
		}
	}
	gettimeofday(&tv, NULL);
	L2 = tv.tv_sec*1000*1000 + tv.tv_usec;
	printf("SGD_SM1_CBC Encrypt datasize: %d Bytes used time: %lld us\n",loop * MAX, L2 - L1);
	printf("SGD_SM1_CBC Encrypt average speed: %d bps\n", (int)((long long)MAX*loop*8*1000000/(L2 - L1)));

	SGD_UCHAR *pucTmpData = (SGD_UCHAR*)malloc(loop * MAX);
	memset(pucIV,1,16);
	gettimeofday(&tv, NULL);
	L3 = tv.tv_sec*1000*1000 + tv.tv_usec;
	for(i = 0; i < loop; i++)
	{
		rv = SDF_Decrypt(phSessionHandle,pucKey, SGD_SM1_CBC, pucIV, &pucEncData[i * MAX], MAX, &pucTmpData[i * MAX], &puiEncDataLength);
		if(SDR_OK != rv)
		{
			free(pucData);
			free(pucEncData);
			free(pucTmpData);
			return rv;
		}
	
	}
	gettimeofday(&tv, NULL);
	L4 = tv.tv_sec*1000*1000 + tv.tv_usec;
	
	printf("SGD_SM1_CBC Decrypt datasize: %d Bytes used time: %lld us\n",loop * MAX, L4 - L3);
	printf("SGD_SM1_CBC Decrypt average speed: %d bps\n", (int)((long long)MAX*loop*8*1000000/(L4 - L3)));

	if(memcmp(pucData,pucTmpData,loop * MAX))
	{
		free(pucData);
		free(pucEncData);
		free(pucTmpData);
		printf("memcmp    diff\n");
		return -1;
	}
	
	free(pucData);
	free(pucEncData);
	free(pucTmpData);
	return SDR_OK;
}

SGD_RV SM1_ENC_DEC_OFB(SGD_HANDLE phSessionHandle,SGD_HANDLE phKeyHandle)
{

	SGD_RV rv = SDR_OK;
	int loop = LOOP, i = 0;
	SGD_UCHAR pucIV[16] ={0};
	memset(pucIV, 1, 16);
	SGD_UCHAR *pucData = (SGD_UCHAR*)malloc(loop * MAX);
	SGD_UINT32 uiDataLength = loop * MAX;
	SGD_UCHAR *pucEncData = (SGD_UCHAR*)malloc(loop * MAX);
	SGD_UINT32 puiEncDataLength = loop * MAX;
    SGD_UCHAR pucKey[16];
	memset(pucKey,2,16);

	for(i = 0; i < loop * MAX; i++)
	{
		pucData[i] = i % 256;
	}

	unsigned long long L1,L2,L3, L4;
	struct timeval tv;
	gettimeofday(&tv, NULL);
	L1 = tv.tv_sec*1000*1000 + tv.tv_usec;
	
	for(i = 0;i < loop; i++)
	{
		rv = SDF_Encrypt( phSessionHandle,pucKey, SGD_SM1_OFB,pucIV, &pucData[i * MAX], MAX, &pucEncData[i * MAX], &puiEncDataLength);
		if(SDR_OK != rv)
		{
			free(pucData);
			free(pucEncData);
			return rv;
		}
	}
	gettimeofday(&tv, NULL);
	L2 = tv.tv_sec*1000*1000 + tv.tv_usec;
	printf("SGD_SM1_OFB Encrypt datasize: %d Bytes used time: %lld us\n",loop * MAX, L2 - L1);
	printf("SGD_SM1_OFB Encrypt average speed: %d bps\n", (int)((long long)MAX*loop*8*1000000/(L2 - L1)));

	SGD_UCHAR *pucTmpData = (SGD_UCHAR*)malloc(loop * MAX);
	memset(pucIV,1,16);
	gettimeofday(&tv, NULL);
	L3 = tv.tv_sec*1000*1000 + tv.tv_usec;
	for(i = 0; i < loop; i++)
	{
		rv = SDF_Decrypt(phSessionHandle,pucKey, SGD_SM1_OFB, pucIV, &pucEncData[i * MAX], MAX, &pucTmpData[i * MAX], &puiEncDataLength);
		if(SDR_OK != rv)
		{
			free(pucData);
			free(pucEncData);
			free(pucTmpData);
			return rv;
		}
	
	}
	gettimeofday(&tv, NULL);
	L4 = tv.tv_sec*1000*1000 + tv.tv_usec;
	
	printf("SGD_SM1_OFB Decrypt datasize: %d Bytes used time: %lld us\n",loop * MAX, L4 - L3);
	printf("SGD_SM1_OFB Decrypt average speed: %d bps\n", (int)((long long)MAX*loop*8*1000000/(L4 - L3)));

	if(memcmp(pucData,pucTmpData,loop * MAX))
	{
		free(pucData);
		free(pucEncData);
		free(pucTmpData);
		printf("memcmp    diff\n");
		return -1;
	}
	
	free(pucData);
	free(pucEncData);
	free(pucTmpData);
	return SDR_OK;
}
SGD_RV SM4_ENC_DEC_ECB(SGD_HANDLE phSessionHandle,SGD_HANDLE phKeyHandle)
{

	SGD_RV rv = SDR_OK;
	int loop = LOOP, i = 0;
	SGD_UCHAR pucIV[16] ={0};
	memset(pucIV, 1, 16);
	SGD_UCHAR *pucData = (SGD_UCHAR*)malloc(loop * MAX);
	SGD_UINT32 uiDataLength = loop * MAX;
	SGD_UCHAR *pucEncData = (SGD_UCHAR*)malloc(loop * MAX);
	SGD_UINT32 puiEncDataLength = loop * MAX;
    SGD_UCHAR pucKey[16];
	memset(pucKey,2,16);
	int count = loop;

	for(i = 0; i < loop * MAX; i++)
	{
		pucData[i] = i % 256;
	}
	
	unsigned long long L1,L2,L3, L4;
	struct timeval tv;
	gettimeofday(&tv, NULL);
	L1 = tv.tv_sec*1000*1000 + tv.tv_usec;
	
	for(i = 0;i < loop; i++)
	{
		rv = SDF_Encrypt( phSessionHandle,pucKey, SGD_SM4_ECB,pucIV, &pucData[i * MAX], MAX, &pucEncData[i * MAX], &puiEncDataLength);
		if(SDR_OK != rv)
		{
			free(pucData);
			free(pucEncData);
			return rv;
		}
	}
	gettimeofday(&tv, NULL);
	L2 = tv.tv_sec*1000*1000 + tv.tv_usec;
	printf("SGD_SM4_ECB Encrypt datasize: %d Bytes used time: %lld us\n",loop * MAX, L2 - L1);
	printf("SGD_SM4_ECB Encrypt average speed: %d bps\n", (int)((long long)MAX*loop*8*1000000/(L2 - L1)));

	SGD_UCHAR *pucTmpData = (SGD_UCHAR*)malloc(loop * MAX);
	memset(pucIV,1,16);
	gettimeofday(&tv, NULL);
	L3 = tv.tv_sec*1000*1000 + tv.tv_usec;
	for(i = 0; i < loop; i++)
	{
		rv = SDF_Decrypt(phSessionHandle,pucKey, SGD_SM4_ECB, pucIV, &pucEncData[i * MAX], MAX, &pucTmpData[i * MAX], &puiEncDataLength);
		if(SDR_OK != rv)
		{
			free(pucData);
			free(pucEncData);
			free(pucTmpData);
			return rv;
		}
	
	}
	gettimeofday(&tv, NULL);
	L4 = tv.tv_sec*1000*1000 + tv.tv_usec;
	
	printf("SGD_SM4_ECB Decrypt datasize: %d Bytes used time: %lld us\n",loop * MAX, L4 - L3);
	printf("SGD_SM4_ECB Decrypt average speed: %d bps\n", (int)((long long)MAX*loop*8*1000000/(L4 - L3)));

	if(memcmp(pucData,pucTmpData,loop * MAX))
	{
		free(pucData);
		free(pucEncData);
		free(pucTmpData);
		printf("memcmp    diff\n");
		return -1;
	}
	free(pucData);
	free(pucEncData);
	free(pucTmpData);
	return SDR_OK;
}
SGD_RV SM4_ENC_DEC_CBC(SGD_HANDLE phSessionHandle,SGD_HANDLE phKeyHandle)
{

	SGD_RV rv = SDR_OK;
	int loop = LOOP, i = 0;
	SGD_UCHAR pucIV[16] ={0};
	memset(pucIV, 1, 16);
	SGD_UCHAR *pucData = (SGD_UCHAR*)malloc(loop * MAX);
	SGD_UINT32 uiDataLength = loop * MAX;
	SGD_UCHAR *pucEncData = (SGD_UCHAR*)malloc(loop * MAX);
	SGD_UINT32 puiEncDataLength = loop * MAX;
    SGD_UCHAR pucKey[16];
	memset(pucKey,2,16);
	int count = loop;

	for(i = 0; i < loop * MAX; i++)
	{
		pucData[i] = i % 256;
	}
	
	unsigned long long L1,L2,L3, L4;
	struct timeval tv;
	gettimeofday(&tv, NULL);
	L1 = tv.tv_sec*1000*1000 + tv.tv_usec;
	
	for(i = 0;i < loop; i++)
	{
		rv = SDF_Encrypt( phSessionHandle,pucKey, SGD_SM4_CBC,pucIV, &pucData[i * MAX], MAX, &pucEncData[i * MAX], &puiEncDataLength);
		if(SDR_OK != rv)
		{
			free(pucData);
			free(pucEncData);
			return rv;
		}
	}
	gettimeofday(&tv, NULL);
	L2 = tv.tv_sec*1000*1000 + tv.tv_usec;
	printf("SGD_SM4_CBC Encrypt datasize: %d Bytes used time: %lld us\n",loop * MAX, L2 - L1);
	printf("SGD_SM4_CBC Encrypt average speed: %d bps\n", (int)((long long)MAX*loop*8*1000000/(L2 - L1)));

	SGD_UCHAR *pucTmpData = (SGD_UCHAR*)malloc(loop * MAX);
	memset(pucIV,1,16);
	gettimeofday(&tv, NULL);
	L3 = tv.tv_sec*1000*1000 + tv.tv_usec;
	for(i = 0; i < loop; i++)
	{
		rv = SDF_Decrypt(phSessionHandle,pucKey, SGD_SM4_CBC, pucIV, &pucEncData[i * MAX], MAX, &pucTmpData[i * MAX], &puiEncDataLength);
		if(SDR_OK != rv)
		{
			free(pucData);
			free(pucEncData);
			free(pucTmpData);
			return rv;
		}
	
	}
	gettimeofday(&tv, NULL);
	L4 = tv.tv_sec*1000*1000 + tv.tv_usec;
	
	printf("SGD_SM4_CBC Decrypt datasize: %d Bytes used time: %lld us\n",loop * MAX, L4 - L3);
	printf("SGD_SM4_CBC Decrypt average speed: %d bps\n", (int)((long long)MAX*loop*8*1000000/(L4 - L3)));

	if(memcmp(pucData,pucTmpData,loop * MAX))
	{
		free(pucData);
		free(pucEncData);
		free(pucTmpData);
		printf("memcmp    diff\n");
		return -1;
	}
	free(pucData);
	free(pucEncData);
	free(pucTmpData);
	return SDR_OK;
}
SGD_RV SM4_ENC_DEC_OFB(SGD_HANDLE phSessionHandle,SGD_HANDLE phKeyHandle)
{

	SGD_RV rv = SDR_OK;
	int loop = LOOP, i = 0;
	SGD_UCHAR pucIV[16] ={0};
	memset(pucIV, 1, 16);
	SGD_UCHAR *pucData = (SGD_UCHAR*)malloc(loop * MAX);
	SGD_UINT32 uiDataLength = loop * MAX;
	SGD_UCHAR *pucEncData = (SGD_UCHAR*)malloc(loop * MAX);
	SGD_UINT32 puiEncDataLength = loop * MAX;
    SGD_UCHAR pucKey[16];
	memset(pucKey,2,16);
	int count = loop;

	for(i = 0; i < loop * MAX; i++)
	{
		pucData[i] = i % 256;
	}
	
	unsigned long long L1,L2,L3, L4;
	struct timeval tv;
	gettimeofday(&tv, NULL);
	L1 = tv.tv_sec*1000*1000 + tv.tv_usec;
	
	for(i = 0;i < loop; i++)
	{
		rv = SDF_Encrypt( phSessionHandle,pucKey, SGD_SM4_OFB,pucIV, &pucData[i * MAX], MAX, &pucEncData[i * MAX], &puiEncDataLength);
		if(SDR_OK != rv)
		{
			free(pucData);
			free(pucEncData);
			return rv;
		}
	}
	gettimeofday(&tv, NULL);
	L2 = tv.tv_sec*1000*1000 + tv.tv_usec;
	printf("SGD_SM4_OFB Encrypt datasize: %d Bytes used time: %lld us\n",loop * MAX, L2 - L1);
	printf("SGD_SM4_OFB Encrypt average speed: %d bps\n", (int)((long long)MAX*loop*8*1000000/(L2 - L1)));

	SGD_UCHAR *pucTmpData = (SGD_UCHAR*)malloc(loop * MAX);
	memset(pucIV,1,16);
	gettimeofday(&tv, NULL);
	L3 = tv.tv_sec*1000*1000 + tv.tv_usec;
	for(i = 0; i < loop; i++)
	{
		rv = SDF_Decrypt(phSessionHandle,pucKey, SGD_SM4_OFB, pucIV, &pucEncData[i * MAX], MAX, &pucTmpData[i * MAX], &puiEncDataLength);
		if(SDR_OK != rv)
		{
			free(pucData);
			free(pucEncData);
			free(pucTmpData);
			return rv;
		}
	
	}
	gettimeofday(&tv, NULL);
	L4 = tv.tv_sec*1000*1000 + tv.tv_usec;
	
	printf("SGD_SM4_OFB Decrypt datasize: %d Bytes used time: %lld us\n",loop * MAX, L4 - L3);
	printf("SGD_SM4_OFB Decrypt average speed: %d bps\n", (int)((long long)MAX*loop*8*1000000/(L4 - L3)));

	if(memcmp(pucData,pucTmpData,loop * MAX))
	{
		free(pucData);
		free(pucEncData);
		free(pucTmpData);
		printf("memcmp    diff\n");
		return -1;
	}
	free(pucData);
	free(pucEncData);
	free(pucTmpData);
	return SDR_OK;
}
SGD_RV SM1_ENC_DEC_IPSEC(SGD_HANDLE phSessionHandle,SGD_HANDLE phKeyHandle)
{
	SGD_RV rv = SDR_OK;	
	int loop = LOOP, i = 0;
	SGD_UCHAR pucIV[16] ={0};
	memset(pucIV, 1, 16);
	SGD_UCHAR HMACKey[32] ={0};
	memset(HMACKey, 3, 32);
	SGD_UINT32 HMACKeyLen = 32;
	SGD_UCHAR *pucData = (SGD_UCHAR*)malloc(loop * MAX);
	SGD_UINT32 uiDataLength = loop * MAX;
	SGD_UCHAR *pucEncData = (SGD_UCHAR*)malloc(loop * MAX);
	SGD_UINT32 puiEncDataLength = loop * MAX;
	SGD_UCHAR *pucMacData = (SGD_UCHAR*)malloc(loop * 32);
	SGD_UINT32 puiMacDataLength = loop * 32;
	
    SGD_UCHAR pucKey[16];
	memset(pucKey,2,16);
	SGD_UCHAR sendTmpbuf[5000] = {0};
	SGD_UINT32 sendTmpbufLen = 5000;
	SGD_UCHAR recvTmpbuf[5000] = {0};
	SGD_UINT32 recvTmpbufLen = 5000;
	
	int count = loop;
	
	memset(sendTmpbuf, 4, 24);

	for(i = 0; i < loop * MAX; i++)
	{
		pucData[i] = i % 256;
	}
	
	unsigned long long L1,L2,L3, L4;
	struct timeval tv;
	gettimeofday(&tv, NULL);
	L1 = tv.tv_sec*1000*1000 + tv.tv_usec;
	
	for(i = 0; i < loop; i++)
	{
		memcpy(sendTmpbuf + 24, pucData + i * MAX, MAX);
		rv = SDF_Encrypt_IPSEC( phSessionHandle,pucKey, SGD_IPSEC_SM1, pucIV, HMACKey, HMACKeyLen, sendTmpbuf, 24 + MAX, recvTmpbuf, &recvTmpbufLen);
		
		if(SDR_OK != rv)
		{
			free(pucData);
			free(pucEncData);
			free(pucMacData);
			return rv;
		}
		memcpy(pucEncData + i * MAX, recvTmpbuf + 24, MAX);
		memcpy(pucMacData + i * 32, recvTmpbuf + 24 + MAX, 32);
	}
	gettimeofday(&tv, NULL);
	L2 = tv.tv_sec*1000*1000 + tv.tv_usec;
	printf("SGD_IPSEC_SM1 Encrypt datasize: %d Bytes used time: %lld us\n",count * (MAX + 24), L2 - L1);
	printf("SGD_IPSEC_SM1 Encrypt average speed: %d bps\n", (int)((long long)(MAX + 24)*count*8*1000000/(L2 - L1)));

	SGD_UCHAR *pucTmpData = (SGD_UCHAR*)malloc(loop * MAX);
	SGD_UCHAR *pucTmpMacData = (SGD_UCHAR*)malloc(loop * 32);
	
	memset(pucIV,1,16);

	loop = count;
	gettimeofday(&tv, NULL);
	L3 = tv.tv_sec*1000*1000 + tv.tv_usec;
	for(i = 0; i < loop; i++)
	{
		memcpy(sendTmpbuf + 24, pucEncData + i * MAX, MAX);
		rv = SDF_Decrypt_IPSEC(phSessionHandle,pucKey, SGD_IPSEC_SM1, pucIV, HMACKey, HMACKeyLen, sendTmpbuf, 24 + MAX, recvTmpbuf, &recvTmpbufLen);
		if(SDR_OK != rv)
		{
			free(pucData);
			free(pucEncData);
			free(pucMacData);
			free(pucTmpData);
			free(pucTmpMacData);
			return rv;
		}
		memcpy(pucTmpData + i * MAX, recvTmpbuf + 24, MAX);
		memcpy(pucTmpMacData + i * 32, recvTmpbuf + 24 + MAX, 32);
	}
	gettimeofday(&tv, NULL);
	L4 = tv.tv_sec*1000*1000 + tv.tv_usec;
	
	printf("SGD_IPSEC_SM1 Decrypt datasize: %d Bytes used time: %lld us\n",count * (MAX + 24), L4 - L3);
	printf("SGD_IPSEC_SM1 Decrypt average speed: %d bps\n", (int)((long long)(MAX + 24) * count * 8 * 1000000/(L4 - L3)));

	if(memcmp(pucData,pucTmpData,count * MAX))
	{
		free(pucData);
		free(pucEncData);
		free(pucMacData);
		free(pucTmpData);
		free(pucTmpMacData);
		printf("pucData pucTmpData  memcmp diff\n");
		return -1;
	}
	if(memcmp(pucMacData,pucTmpMacData,count * 32))
	{
		free(pucData);
		free(pucEncData);
		free(pucMacData);
		free(pucTmpData);
		free(pucTmpMacData);
		printf("pucMacData pucTmpMacData memcmp diff\n");
		return -1;
	}
	
	free(pucData);
	free(pucEncData);
	free(pucMacData);
	free(pucTmpData);
	free(pucTmpMacData);
	return SDR_OK;
}
SGD_RV SM4_ENC_DEC_IPSEC(SGD_HANDLE phSessionHandle,SGD_HANDLE phKeyHandle)
{
	SGD_RV rv = SDR_OK;	
	int loop = LOOP, i = 0;
	SGD_UCHAR pucIV[16] ={0};
	memset(pucIV, 1, 16);
	SGD_UCHAR HMACKey[32] ={0};
	memset(HMACKey, 3, 32);
	SGD_UINT32 HMACKeyLen = 32;
	SGD_UCHAR *pucData = (SGD_UCHAR*)malloc(loop * MAX);
	SGD_UINT32 uiDataLength = loop * MAX;
	SGD_UCHAR *pucEncData = (SGD_UCHAR*)malloc(loop * MAX);
	SGD_UINT32 puiEncDataLength = loop * MAX;
	SGD_UCHAR *pucMacData = (SGD_UCHAR*)malloc(loop * 32);
	SGD_UINT32 puiMacDataLength = loop * 32;
	
    SGD_UCHAR pucKey[16];
	memset(pucKey,2,16);
	SGD_UCHAR sendTmpbuf[5000] = {0};
	SGD_UINT32 sendTmpbufLen = 5000;
	SGD_UCHAR recvTmpbuf[5000] = {0};
	SGD_UINT32 recvTmpbufLen = 5000;
	
	int count = loop;
	
	memset(sendTmpbuf, 4, 24);

	for(i = 0; i < loop * MAX; i++)
	{
		pucData[i] = i / 256;
	}
	
	unsigned long long L1,L2,L3, L4;
	struct timeval tv;
	gettimeofday(&tv, NULL);
	L1 = tv.tv_sec*1000*1000 + tv.tv_usec;
	
	for(i = 0; i < loop; i++)
	{
		memcpy(sendTmpbuf + 24, pucData + i * MAX, MAX);
		rv = SDF_Encrypt_IPSEC( phSessionHandle,pucKey, SGD_IPSEC_SM4, pucIV, HMACKey, HMACKeyLen, sendTmpbuf, 24 + MAX, recvTmpbuf, &recvTmpbufLen);
		if(SDR_OK != rv)
		{
			free(pucData);
			free(pucEncData);
			free(pucMacData);
			return rv;
		}
		memcpy(pucEncData + i * MAX, recvTmpbuf + 24, MAX);
		memcpy(pucMacData + i * 32, recvTmpbuf + 24 + MAX, 32);
	}
	
	gettimeofday(&tv, NULL);
	L2 = tv.tv_sec*1000*1000 + tv.tv_usec;
	printf("SGD_IPSEC_SM4 Encrypt datasize: %d Bytes used time: %lld us\n",count * (MAX + 24), L2 - L1);
	printf("SGD_IPSEC_SM4 Encrypt average speed: %d bps\n", (int)((long long)(MAX + 24)*count*8*1000000/(L2 - L1)));
	
	SGD_UCHAR *pucTmpData = (SGD_UCHAR*)malloc(loop * MAX);
	SGD_UCHAR *pucTmpMacData = (SGD_UCHAR*)malloc(loop * 32);
	
	memset(pucIV,1,16);

	loop = count;
	gettimeofday(&tv, NULL);
	L3 = tv.tv_sec*1000*1000 + tv.tv_usec;
	for(i = 0; i < loop; i++)
	{
		memcpy(sendTmpbuf + 24, pucEncData + i * MAX, MAX);
		rv = SDF_Decrypt_IPSEC(phSessionHandle,pucKey, SGD_IPSEC_SM4, pucIV, HMACKey, HMACKeyLen, sendTmpbuf, 24 + MAX, recvTmpbuf, &recvTmpbufLen);
		if(SDR_OK != rv)
		{
			free(pucData);
			free(pucEncData);
			free(pucMacData);
			free(pucTmpData);
			free(pucTmpMacData);
			return rv;
		}
		memcpy(pucTmpData + i * MAX, recvTmpbuf + 24, MAX);
		memcpy(pucTmpMacData + i * 32, recvTmpbuf + 24 + MAX, 32);
	}
	gettimeofday(&tv, NULL);
	L4 = tv.tv_sec*1000*1000 + tv.tv_usec;
	
	printf("SGD_IPSEC_SM4 Decrypt datasize: %d Bytes used time: %lld us\n",count * (MAX + 24), L4 - L3);
	printf("SGD_IPSEC_SM4 Decrypt average speed: %d bps\n", (int)((long long)(MAX + 24) * count * 8 * 1000000/(L4 - L3)));

	if(memcmp(pucData,pucTmpData,count * MAX))
	{
		free(pucData);
		free(pucEncData);
		free(pucMacData);
		free(pucTmpData);
		free(pucTmpMacData);
		printf("pucData pucTmpData  memcmp diff\n");
		return -1;
	}
	if(memcmp(pucMacData,pucTmpMacData,count * 32))
	{
		free(pucData);
		free(pucEncData);
		free(pucMacData);
		free(pucTmpData);
		free(pucTmpMacData);
		printf("pucMacData pucTmpMacData memcmp diff\n");
		return -1;
	}
	
	free(pucData);
	free(pucEncData);
	free(pucMacData);
	free(pucTmpData);
	free(pucTmpMacData);
	return SDR_OK;
}

SGD_RV SGD_SM3Hash(SGD_HANDLE phSessionHandle)
{
	SGD_RV rv = SDR_OK;
	ECCrefPublicKey phPubKey;
	memcpy(phPubKey.x,pubKey,32);
	memcpy(phPubKey.y,pubKey+32,32);

	SGD_UCHAR  pucID[16] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08};
	SGD_UINT32 uiIDLen = 16;

	SGD_UINT8 pucData[16] ={0};
	memset(pucData,0x05,16);
	SGD_UINT32 uiPucDateLen = 16;

	//rv = SDF_HashInit(phSessionHandle,SGD_SM3,&phPubKey,pucID,uiIDLen);
	rv = SDF_HashInit(phSessionHandle,SGD_SM3,NULL,NULL,0);
	if(SDR_OK != rv)
	{
		return rv;
	}

	rv = SDF_HashUpdate(phSessionHandle,pucData,uiPucDateLen);
	if(SDR_OK != rv)
	{
		return rv;
	}
	uiPucDateLen =32;

	rv = SDF_HashFinal(phSessionHandle,sm3HashData,&uiPucDateLen);
	if(SDR_OK != rv)
	{
		return rv;
	}

	return SDR_OK;

}
SGD_RV SM2EncDec(SGD_HANDLE phSessionHandle)
{
	SGD_RV rv = SDR_OK;

	SGD_UCHAR pucData[32] ={0};
	SGD_UINT32 uiDataLen = sizeof(pucData);
	memset(pucData,0x05,sizeof(pucData));
	ECCCipher Cipher;


	rv =SDF_InternalEncrypt_ECC(phSessionHandle, 1, SGD_SM2_3, pucData, uiDataLen, &Cipher);
	if(SDR_OK != rv)
	{
		printf("SDF_InternalEncrypt_ECC failed rv = %08x\n", rv);
		return rv;
	}

	SGD_UCHAR pucDecData[1025] ={0};
	SGD_UINT32 uiDecDataLen = sizeof(pucDecData);

	rv = SDF_InternalDecrypt_ECC(phSessionHandle,1,SGD_SM2_3,&Cipher,pucDecData,&uiDecDataLen);
	if(SDR_OK != rv)
	{
		printf("SDF_InternalDecrypt_ECC failed rv = %08x\n", rv);
		return rv;
	}
	if(memcmp(pucData,pucDecData,uiDecDataLen))
	{
		printf("memcpy diff \n");
		return -1;
	}
	return SDR_OK;
}

SGD_RV SM2SignVer(SGD_HANDLE phSessionHandle)
{
	SGD_RV rv = SDR_OK;
#define COUNT 100
	ECCSignature Signature ;
	int i = 0;
	
	unsigned long long L1,L2,L3,L4;
	struct timeval tv;
	gettimeofday(&tv, NULL);
	L1 = tv.tv_sec*1000*1000 + tv.tv_usec;
	
	for(i = 0; i < COUNT; i++)
	{
		rv = SDF_InternalSign_ECC(phSessionHandle,1,sm3HashData,32,&Signature);
		if(SDR_OK != rv)
		{
			printf("SDF_InternalSign_ECC failed rv = 0x%08x\n", rv);
			return rv;
		}
	}

	gettimeofday(&tv, NULL);
	L2 = tv.tv_sec*1000*1000 + tv.tv_usec;
	printf("SM2-Sign Times: %d 次;	Spent time: %lld us\n",COUNT, L2 - L1);
	printf("SM2-Sign average speed: %d us/次\n", (int)((L2 - L1)/(long long)COUNT));

	gettimeofday(&tv, NULL);
	L3 = tv.tv_sec*1000*1000 + tv.tv_usec;
	
	for(i = 0; i < COUNT; i++)
	{
		rv = SDF_InternalVerify_ECC(phSessionHandle,1,sm3HashData,32,&Signature);
		if(SDR_OK != rv)
		{
			printf("SDF_InternalVerify_ECC failed rv = 0x%08x\n", rv);
			return rv;
		}
	}
	gettimeofday(&tv, NULL);
	L4 = tv.tv_sec*1000*1000 + tv.tv_usec;
	printf("SM2-Verify Times: %d 次;	Spent time: %lld us\n",COUNT, L4 - L3);
	printf("SM2-Verify average speed: %d us/次\n", (int)((L4 - L3)/(long long)COUNT));
	
	return SDR_OK;
}

SGD_RV ExportKeyPair(SGD_HANDLE phSessionHandle)
{
	SGD_RV rv = SDR_OK;
	SGD_UCHAR pucPubKey[64];
	rv = SDF_ExportECCPubKey(phSessionHandle,1,pucPubKey);
	if(SDR_OK != rv)
	{
		return rv;
	}


	if(memcmp(pucPubKey,pubKey,64))
	{
		printf("pubKey diff \n");
		return -1;
	}

	SGD_UCHAR pucPriKey[32];
	rv = SDF_ExportECCPriKey(phSessionHandle,1,pucPriKey);
	if(SDR_OK != rv)
	{
		return rv;
	}
	
	SGD_UCHAR pucIV[16] ={0};
	memset(pucIV, 0, 16);
	SGD_UCHAR pucEncData[100] = {0};
	SGD_UINT32 puiEncDataLength = 100;
	
	rv = SDF_Encrypt(phSessionHandle,(SGD_UINT8 *)ROOTKEY, SGD_SM1_CBC,pucIV, priKey, 32, pucEncData, &puiEncDataLength);
	if(SDR_OK != rv)
	{
		return rv;
	}

	if(memcmp(pucPriKey,pucEncData,32))
	{
		printf("priKey diff \n");
		return -1;
	}

	return SDR_OK;

}

SGD_RV SM1_CBC(SGD_HANDLE phSessionHandle,SGD_HANDLE phKeyHandle)
{

	SGD_RV rv = SDR_OK;
	SGD_UCHAR pucIV[16] ={0};
	memset(pucIV, 0, 16);
	SGD_UCHAR pucData[64] = {
	0x8B, 0x7F, 0xB9, 0x6C, 0x09, 0x53, 0x27, 0x19, 0xE4, 0xEB, 0x79, 0x16, 0xC6, 0x2E, 0x20, 0xEA, 
	0x33, 0xCC, 0x98, 0x96, 0x43, 0xFA, 0x45, 0x09, 0x0C, 0x98, 0x4E, 0xA5, 0xDF, 0x76, 0xA1, 0xD4, 
	0xC1, 0xF8, 0x9C, 0x46, 0x67, 0x61, 0xCE, 0x07, 0x83, 0x26, 0xAF, 0x1C, 0xA0, 0x81, 0xC5, 0x89, 
	0x4E, 0x0C, 0xD5, 0x29, 0x88, 0x40, 0x96, 0x45, 0x50, 0xD9, 0x14, 0x17, 0xB7, 0x5C, 0xC5, 0x5E
};
	SGD_UINT32 uiDataLength = sizeof(pucData);
	SGD_UCHAR pucEncData[64] = { 0 };
	SGD_UINT32 puiEncDataLength = sizeof(pucEncData);
    SGD_UCHAR pucKey[16] = {0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0A,0x0B,0x0C,0x0D,0x0E,0x0F,0x10};

	rv = SDF_Encrypt( phSessionHandle,pucKey, SGD_SM1_CBC,pucIV, pucData, uiDataLength, pucEncData, &puiEncDataLength);
	if(SDR_OK != rv)
	{
		return rv;
	}
	printf("pucEncData:\n");
	myprintf(pucEncData, puiEncDataLength);
	
	SGD_UCHAR pucTmpData[64] = { 0 };
	memset(pucIV,0,16);
	rv = SDF_Decrypt(phSessionHandle,pucKey, SGD_SM1_CBC, pucIV, pucEncData, puiEncDataLength, pucTmpData, &puiEncDataLength);
	if(SDR_OK != rv)
	{
		return rv;
	}
	
	if(memcmp(pucData,pucTmpData,64))
	{
		printf("memcmp    diff\n");
		return -1;
	}
	
	return SDR_OK;
}

int main(int argc, char *argv[])
{
	SGD_HANDLE phDeviceHandle;
	SGD_HANDLE phSessionHandle;
	SGD_HANDLE phKeyHandle;
	SGD_UCHAR pOutRand[16] = { 0 };
	SGD_UINT32 ulRandLen = 16;
	SGD_UCHAR SN[17] = { 0 };
	SGD_UCHAR CosVer[10] = { 0 };
	int loop = 1;
	if (argc > 1)
	{
		loop = atol(argv[1]);
	}

	SGD_RV rv = SDF_OpenDevice(&phDeviceHandle);
	if(rv != SDR_OK)
	{
		printf("open devces fail\n");
		return 0;
	}
	printf("open device success!\n");
	
	rv = SDF_OpenSession(phDeviceHandle, &phSessionHandle);
	if(rv != SDR_OK)
	{
		SDF_CloseDevice(phDeviceHandle);
		printf("open session fail\n");
		return 0;
	}
	printf("open session success!\n");
	
	rv = SDF_GenerateRandom(phSessionHandle, pOutRand, ulRandLen);
	if(rv != SDR_OK)
	{
		SDF_CloseDevice(phDeviceHandle);
		printf("SDF_GenerateRandom fail\n");
		return 0;
	}
	printf("pOutRand:\n");
	myprintf(pOutRand, ulRandLen);
	printf("SDF_GenerateRandom success!\n");
	//return 0;
#if 1 
	rv = SDF_ImportRootKeyAndDeviceSN(phSessionHandle,(SGD_UINT8 *)ROOTKEY,(SGD_UINT8 *)DEVSN,16);
	if(rv != SDR_OK)
	{
	 	printf("SDF_ImportRootKeyAndDeviceSN fail, RootKey can only import once\n");
//	 	goto err;
	}
	else
	{
		printf("SDF_ImportRootKeyAndDeviceSN success\n");
	}
#endif

#if 1 
	DEVICEINFO devInfo;
	rv =  SDF_GetDeviceInfo(phSessionHandle,&devInfo);
	if(rv != SDR_OK)
	{
		printf("SDF_GetDeviceInfo fail\n");
		goto err;
	}
	memcpy(SN, devInfo.DeviceSerial, 16);
	printf("SN:%s\n",SN);
	memcpy(CosVer, &(devInfo.DeviceVersion), 4);//int类型复制到char数组中,假如版本为4.2.05, 此时打印CosVer实际为4205
	
	//修改一下形式, 4205改为4.2.05
	CosVer[5] = CosVer[3];
	CosVer[4] = CosVer[2];
	CosVer[3] = '.';
	CosVer[2] = CosVer[1];
	CosVer[1] = '.';
	printf("CosVer: %s\n", CosVer);
#endif

	rv = ImportKeyPair(phSessionHandle);
	if(rv != SDR_OK)
	{
		printf("ImportKeyPair fail\n");
		goto err;
	}
	printf("ImportKeyPair success\n");


	rv = EccBackUpKeyPair(phSessionHandle);
	if(rv != SDR_OK)
	{
		printf("EccBackUpKeyPair fail\n");
		goto err;
	}
	printf("EccBackUpKeyPair success\n");

	rv =ExportKeyPair(phSessionHandle);
	if(rv != SDR_OK)
	{
		printf("ExportKeyPair fail\n");
		goto err;
	}
	printf("ExportKeyPair success\n");
	
	rv =SGD_SM3Hash(phSessionHandle);
	if(rv != SDR_OK)
	{
		printf("SGD_SM3Hash fail\n");
		goto err;
	} 
	printf("SGD_SM3Hash success\n");
	rv = SM2EncDec(phSessionHandle);
	if(rv != SDR_OK)
	{
		printf("SM2EncDec fail\n");
		goto err;
	}
	printf("SM2EncDec success\n");
	
	rv = SM2SignVer(phSessionHandle);
	if(rv != SDR_OK)
	{
		printf("SM2SignVer fail\n");
		goto err;
	}
	printf("SM2SignVer success\n");
	
	rv =SM1_ENC_DEC_ECB(phSessionHandle,phKeyHandle);
	if(rv != SDR_OK)
	{
		printf("SM1_ENC_DEC_ECB fail\n");
		goto err;
	}
	printf("SM1_ENC_DEC_ECB success. \n");
	
	rv =SM1_ENC_DEC_CBC(phSessionHandle,phKeyHandle);
	if(rv != SDR_OK)
	{
		printf("SM1_ENC_DEC_CBC fail\n");
		goto err;
	}
	printf("SM1_ENC_DEC_CBC success. \n");
		
	rv =SM1_ENC_DEC_OFB(phSessionHandle,phKeyHandle);
	if(rv != SDR_OK)
	{
		printf("SM1_ENC_DEC_OFB fail\n");
		goto err;
	}
	printf("SM1_ENC_DEC_OFB success. \n");
	
	rv =SM4_ENC_DEC_ECB(phSessionHandle,phKeyHandle);
	if(rv != SDR_OK)
	{
		printf("SM4_ENC_DEC_ECB fail\n");
		goto err;
	}
	printf("SM4_ENC_DEC_ECB success. \n");
	
	rv =SM4_ENC_DEC_CBC(phSessionHandle,phKeyHandle);
	if(rv != SDR_OK)
	{
		printf("SM4_ENC_DEC_CBC fail\n");
		goto err;
	}
	printf("SM4_ENC_DEC_CBC success. \n");
	
	rv =SM4_ENC_DEC_OFB(phSessionHandle,phKeyHandle);
	if(rv != SDR_OK)
	{
		printf("SM4_ENC_DEC_OFB fail\n");
		goto err;
	}
	printf("SM4_ENC_DEC_OFB success. \n");

	rv =SM1_ENC_DEC_IPSEC(phSessionHandle,phKeyHandle);
	if(rv != SDR_OK)
	{
		printf("SM1_ENC_DEC_IPSEC fail\n");
		goto err;
	}
	printf("SM1_ENC_DEC_IPSEC success. \n");

	rv =SM4_ENC_DEC_IPSEC(phSessionHandle,phKeyHandle);
	if(rv != SDR_OK)
	{
		printf("SM4_ENC_DEC_IPSEC fail\n");
		goto err;
	}
	printf("SM4_ENC_DEC_IPSEC success.\n");


err:

	SDF_CloseSession(phSessionHandle);

    SDF_CloseDevice(phDeviceHandle);

	return 0;
}
`

标签:rv,tv,MAX,接口,sdf,引擎,free,SGD,loop
From: https://www.cnblogs.com/shi-yu-jie/p/18137063

相关文章

  • 实验二-密码引擎-3-sdf接口
    两人一组完成下面任务0分析代码接口和智能钥匙的接口的异同代码接口和智能钥匙的接口是两种不同类型的接口,它们有一些异同点:类型:代码接口:通常指软件编程中的接口,用于不同软件组件之间的通信和交互。智能钥匙接口:指用于与智能钥匙通信和控制的物理接口,比如RFID接口、蓝牙接......
  • 实验二-密码引擎-3-sdf接口
    一、任务详情两人一组完成下面任务0分析代码接口和智能钥匙的接口的异同1.编译运行附件中代码,提交运行结果截图2.修改test.c完成包含小组内成员的学号姓名的文件的sm3hash运算,sm4加密解密,提交代码和运行结果截图。3.完成完成包含小组内成员的学号姓名的文件的签名验签名,......
  • 20211314实验二-密码引擎-3-sdf接口
    任务详情两人一组完成下面任务分析代码接口和智能钥匙的接口的异同编译运行附件中代码,提交运行结果截图修改test.c完成包含小组内成员的学号姓名的文件的sm3hash运算,sm4加密解密,提交代码和运行结果截图。完成完成包含小组内成员的学号姓名的文件的签名验签名,提交代码和运行......
  • java中接口多个实现类,如何指定实现类,根据子类类型选择实现方法
    问题背景在Java代码中,经常会遇到一个接口有多个实现的情况。而这些实现类的参数又是不同的子类,这时候我们该如何选择正确的实现方法呢?解决方案我们可以通过判断参数的子类类型来选择正确的实现方法。具体实现可以使用Java中的instanceof关键字,它可以判断一个对象是否是某个类的......
  • 如何让表单流程引擎提质增效?
    随着社会的进步和科技的发展,低代码技术平台在诸多行业中成为利用价值高的平台。对于解决信息孤岛、部门协作不给力、办公效率不高等缺点,低代码技术平台都可以为其架设出一道优质的桥梁,共同朝着高效率的流程化办公方向前进。表单流辰引擎是提质增效的理想软件平台,优势特点多、可视......
  • 视频汇聚/安防监控平台EasyCVR调试pprof接口信息泄露如何处理?
    EasyCVR视频融合平台基于云边端架构,可支持海量视频汇聚管理,能提供视频监控直播、云端录像、云存储、录像检索与回看、智能告警、平台级联、智能分析等视频服务。平台兼容性强,支持多协议、多类型设备接入,包括:国标GB/T28181协议、RTMP、RTSP/Onvif协议、海康Ehome、海康SDK、大华SD......
  • Linux 64位内核(arm64)驱动兼容32位应用程序(armhf)的ioctl接口
    最近,公司来了一次硬件升级,开发平台从全志T3(armhf)升级到全志T527(arm64),平台迁移后,想直接使用原来动态库和应用程序从而减少开发量,用户态大部分接口都运行正常,唯独ioctl接口无法调用成功。如果要成功移植要做到以下几点:1.驱动要同时实现unlocked_ioctl和compat_ioctl。str......
  • thymeleaf模版引擎
    简介Thymeleaf是一个java流行的模版引擎Thymeleaf是一款现代化的服务器端Java模板引擎,适用于Web和独立应用场景。它具备处理HTML、XML、JavaScript、CSS以及纯文本的能力,其核心目标是为开发者提供一种优雅且自然的模板设计方式,使得开发者能够更加便捷地构建、创建和维护结构化且......
  • ABP -Vnext框架一步一步入门落地教程——使用ABP -Vnext创建一个WEBAPI接口(二)
    人生需要指引,而复制是成功最快的方式,兄弟们让我们发车吧————代码大牛ljy开发主题:何谓开发应用服务端在官方开发教程这一段的内容叫做开发应用服务端,作为现在前后端分离的开发模式来说,一个应用就分为前端页面框架和后端API,页面框架调用WEBAPI实现业务就完事了。所以咱们今天......
  • 利用Sqlmap API接口联动Google Hacking批量SQL注入检测
    目录前言slghack自动化搜集URLSqlmapAPI脚本slghack_sqli前言挖掘SQL注入漏洞的一种方式就是通过GoogleHacking搜索那些可能存在SQL的URL,然后手工的探测注入点。但是现在的SQL注入漏洞的网站是比较少的了,所以这样一个一个手工测效率有一点低。sqlmap比较好的一点是可批量扫描......