update
This commit is contained in:
parent
3430231d1b
commit
5697dcdfb4
@ -10,8 +10,14 @@
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#define WaitTime 3
|
||||
|
||||
static pthread_mutex_t tMutex = PTHREAD_MUTEX_INITIALIZER;
|
||||
#define Lock pthread_mutex_lock(&tMutex)
|
||||
#define Unlock pthread_mutex_unlock(&tMutex)
|
||||
|
||||
static int iKeyNum = 1;
|
||||
|
||||
enum
|
||||
@ -20,7 +26,7 @@ enum
|
||||
eRand,
|
||||
eSignatureByIntPrikey,
|
||||
eSignatureByExtPrikey,
|
||||
eVerifySignature ,
|
||||
eVerifySignature,
|
||||
eSM2EncryptByExtPubKey,
|
||||
eSM2DecryptByExtPrikey,
|
||||
eSM2DecryptByIntPrikey,
|
||||
@ -107,6 +113,8 @@ int Generate_Hash(
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__Hash *Result = NULL;
|
||||
@ -162,6 +170,8 @@ int Generate_Hash(
|
||||
if(Result) awsm__hash__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -169,6 +179,8 @@ int Generate_Rand(unsigned char *ucRandom, unsigned int ulRandomLen)
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__Rand *Result = NULL;
|
||||
@ -202,6 +214,8 @@ int Generate_Rand(unsigned char *ucRandom, unsigned int ulRandomLen)
|
||||
if(Result) awsm__rand__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -211,6 +225,8 @@ int Generate_SignData_IntPrikey(
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__SignatureByIntPrikey *Result = NULL;
|
||||
@ -252,6 +268,8 @@ int Generate_SignData_IntPrikey(
|
||||
if(Result) awsm__signature_by_int_prikey__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -262,6 +280,8 @@ int Generate_SignData_ExtPrikey(
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__SignatureByExtPrikey *Result = NULL;
|
||||
@ -304,6 +324,8 @@ int Generate_SignData_ExtPrikey(
|
||||
if(Result) awsm__signature_by_ext_prikey__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -314,6 +336,8 @@ int Verify_SignData_ExtPubkey(
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__VerifySignature *Result = NULL;
|
||||
@ -352,6 +376,7 @@ int Verify_SignData_ExtPubkey(
|
||||
if(Result) awsm__verify_signature__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
@ -363,6 +388,8 @@ int SM2_3_Encrypt_ExtPubkey(
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__SM2EncryptByExtPubKey *Result = NULL;
|
||||
@ -405,6 +432,8 @@ int SM2_3_Encrypt_ExtPubkey(
|
||||
if(Result) awsm__sm2_encrypt_by_ext_pub_key__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -415,6 +444,8 @@ int SM2_3_Decrypt_ExtPrikey(
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__SM2DecryptByExtPrikey *Result = NULL;
|
||||
@ -458,6 +489,8 @@ int SM2_3_Decrypt_ExtPrikey(
|
||||
if(Result) awsm__sm2_decrypt_by_ext_prikey__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -467,6 +500,8 @@ int SM2_3_Decrypt_IntPrikey(
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__SM2DecryptByIntPrikey *Result = NULL;
|
||||
@ -508,6 +543,8 @@ int SM2_3_Decrypt_IntPrikey(
|
||||
if(Result) awsm__sm2_decrypt_by_int_prikey__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -517,6 +554,8 @@ int SM2_3_Decrypt_IntCryptPrikey(
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__SM2DecryptByIntCryptPrikey *Result = NULL;
|
||||
@ -558,6 +597,8 @@ int SM2_3_Decrypt_IntCryptPrikey(
|
||||
if(Result) awsm__sm2_decrypt_by_int_crypt_prikey__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -567,6 +608,8 @@ int SM1_Encrypt(
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__SM1Encrypt *Result = NULL;
|
||||
@ -619,6 +662,8 @@ int SM1_Encrypt(
|
||||
if(Result) awsm__sm1_encrypt__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -628,6 +673,8 @@ int SM1_Decrypt(
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__SM1Decrypt *Result = NULL;
|
||||
@ -663,7 +710,7 @@ int SM1_Decrypt(
|
||||
rv = ZMQSend(psZMQ, pcSendBuf, iSendBufLen);
|
||||
if(rv) { rv = -1; break; }
|
||||
|
||||
psZMQBuf = ZMQRecv(psZMQ, WaitTime);
|
||||
psZMQBuf = ZMQRecv(psZMQ, WaitTime);
|
||||
if(!psZMQBuf) { ReConnect(); rv = -1; break; }
|
||||
|
||||
Result = awsm__sm1_decrypt__unpack(NULL, psZMQBuf->iBufLen, psZMQBuf->pcBuf);
|
||||
@ -678,6 +725,8 @@ int SM1_Decrypt(
|
||||
if(Result) awsm__sm1_decrypt__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -687,6 +736,8 @@ int SM4_Encrypt(
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__SM4Encrypt *Result = NULL;
|
||||
@ -737,6 +788,8 @@ int SM4_Encrypt(
|
||||
if(Result) awsm__sm4_encrypt__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -746,6 +799,8 @@ int SM4_Decrypt(
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__SM4Decrypt *Result = NULL;
|
||||
@ -796,6 +851,8 @@ int SM4_Decrypt(
|
||||
if(Result) awsm__sm4_decrypt__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -803,6 +860,8 @@ int Generate_ECCKeyPair()
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__GenerateECCKeyPair *Result = NULL;
|
||||
@ -831,6 +890,8 @@ int Generate_ECCKeyPair()
|
||||
if(Result) awsm__generate_ecckey_pair__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -838,6 +899,8 @@ int Export_publickey(unsigned int KeyPairtype, unsigned char *publickey)
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__ExportPubkey *Result = NULL;
|
||||
@ -873,6 +936,8 @@ int Export_publickey(unsigned int KeyPairtype, unsigned char *publickey)
|
||||
if(Result) awsm__export_pubkey__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -880,6 +945,8 @@ int Import_ECCKeyPair(unsigned int KeyPairtype, unsigned char *Privatkey, unsign
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__ImportKeyPair *Result = NULL;
|
||||
@ -915,6 +982,8 @@ int Import_ECCKeyPair(unsigned int KeyPairtype, unsigned char *Privatkey, unsign
|
||||
if(Result) awsm__import_key_pair__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -922,6 +991,8 @@ int Import_Certificate(unsigned int CerType, char *InData, unsigned int InDataLe
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__ImportCertificate *Result = NULL;
|
||||
@ -955,6 +1026,8 @@ int Import_Certificate(unsigned int CerType, char *InData, unsigned int InDataLe
|
||||
if(Result) awsm__import_certificate__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -962,6 +1035,8 @@ int Export_Certificate(unsigned int CerType, char *OutData, unsigned int *OutDat
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__ExportCertificate *Result = NULL;
|
||||
@ -999,6 +1074,8 @@ int Export_Certificate(unsigned int CerType, char *OutData, unsigned int *OutDat
|
||||
if(Result) awsm__export_certificate__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -1006,6 +1083,8 @@ int ImportFile(char* FileName, char *InData, int InDataLen)
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__ImportFile *Result = NULL;
|
||||
@ -1040,6 +1119,8 @@ int ImportFile(char* FileName, char *InData, int InDataLen)
|
||||
if(Result) awsm__import_file__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -1047,6 +1128,8 @@ int ExportFile(char *FileName, char *OutData, int *OutDataLen)
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__ExportFile *Result = NULL;
|
||||
@ -1085,6 +1168,8 @@ int ExportFile(char *FileName, char *OutData, int *OutDataLen)
|
||||
if(Result) awsm__export_file__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -1092,6 +1177,8 @@ int Get_Hwcode(unsigned char *HwCode)
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__GetHwcode *Result = NULL;
|
||||
@ -1124,6 +1211,8 @@ int Get_Hwcode(unsigned char *HwCode)
|
||||
if(Result) awsm__get_hwcode__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
@ -1131,6 +1220,8 @@ int Get_DevInfo(unsigned char *DevInfo)
|
||||
{
|
||||
int rv = 0;
|
||||
|
||||
Lock;
|
||||
|
||||
int iSendBufLen = 0; char *pcSendBuf = NULL;
|
||||
pZMQBuf_s psZMQBuf = NULL;
|
||||
AWSM__GetDevInfo *Result = NULL;
|
||||
@ -1154,5 +1245,8 @@ int Get_DevInfo(unsigned char *DevInfo)
|
||||
if(psZMQBuf) ZMQBufDestroy(psZMQBuf);
|
||||
if(Result) awsm__get_dev_info__free_unpacked(Result, NULL);
|
||||
if(pcSendBuf) free(pcSendBuf);
|
||||
|
||||
Unlock;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user