This commit is contained in:
void_sora 2024-08-06 21:15:38 +08:00
parent 09c5022ff4
commit a3f9ee10c8
6 changed files with 75 additions and 73 deletions

View File

@ -2,6 +2,8 @@
"files.associations": {
"awsdf.h": "c",
"sdf.h": "c",
"sdf_dev_manage.h": "c"
"sdf_dev_manage.h": "c",
"awsmcall.h": "c",
"awsm.pb-c.h": "c"
}
}

View File

@ -50,9 +50,9 @@ int main()
CallXXX(Hash, 4)
else CallXXX(HashInit, 8)
else CallXXX(HashUpdate, 10)
else CallXXX(HashFinsh, 9)
else CallXXX(HashFinal, 9)
else CallXXX(Rand, 4)
else CallXXX(SignatureByIntPrikey, 20)
else CallXXX(SignatureByIntPrikey, 20)
else CallXXX(SignatureByExtPrikey, 20)
else CallXXX(VerifySignature, 15)
else CallXXX(SM2EncryptByExtPubKey, 21)

View File

@ -39,10 +39,10 @@ int AWSMCallInit()
if(!pfAWSKF) pfAWSKF = AWSKFFunInit();
if(!pfAWSKF) { rv = -1; break; }
if(!psAWSKF) psAWSKF = pfAWSKF->Malloc();
if(!psAWSKF) psAWSKF = pfAWSKF->Malloc();
if(!psAWSKF) { rv = -1; break; }
rv = pfAWSKF->Open(psAWSKF, "123456");
rv = pfAWSKF->Open(psAWSKF, "UserPIN");
}while(0);
return rv;
@ -134,40 +134,40 @@ pAWSMProtobuf_s CallHashUpdate(const char *pcProtoBuf, const int iProtoBufLen)
return psReturn;
}
pAWSMProtobuf_s CallHashFinsh(const char *pcProtoBuf, const int iProtoBufLen)
pAWSMProtobuf_s CallHashFinal(const char *pcProtoBuf, const int iProtoBufLen)
{
int rv = 0;
pAWSMProtobuf_s psReturn = NULL;
AWSM__HashFinsh *HashFinshIN = NULL;
AWSM__HashFinal *HashFinalIN = NULL;
do
{
unsigned char pcHashData[33] = {0}; unsigned int iHashDataLen = 32;
do
{
HashFinshIN = awsm__hash_finsh__unpack(NULL, iProtoBufLen, pcProtoBuf);
HashFinalIN = awsm__hash_Final__unpack(NULL, iProtoBufLen, pcProtoBuf);
if(
!HashFinshIN ||
!HashFinshIN->hashdata.data || HashFinshIN->hashdata.len <= 0 ||
HashFinshIN->hashdatalen <= 0
!HashFinalIN ||
!HashFinalIN->hashdata.data || HashFinalIN->hashdata.len <= 0 ||
HashFinalIN->hashdatalen <= 0
) { rv = -1; break; }
rv = pfAWSKF->GenerateHashFinal(psAWSKF, pcHashData, &iHashDataLen);
}while(0);
AWSM__HashFinsh HashFinshOUT = AWSM__HASH_FINSH__INIT;
HashFinshOUT.hashdata.data = pcHashData;
HashFinshOUT.hashdata.len = iHashDataLen;
HashFinshOUT.hashdatalen = iHashDataLen;
HashFinshOUT.returnvalue = rv;
AWSM__HashFinal HashFinalOUT = AWSM__HASH_FINAL__INIT;
HashFinalOUT.hashdata.data = pcHashData;
HashFinalOUT.hashdata.len = iHashDataLen;
HashFinalOUT.hashdatalen = iHashDataLen;
HashFinalOUT.returnvalue = rv;
ToAWProtobuf(hash_finsh, psReturn, HashFinshOUT);
ToAWProtobuf(hash_Final, psReturn, HashFinalOUT);
Unlock();
}while(0);
if(HashFinshIN) awsm__hash_finsh__free_unpacked(HashFinshIN, NULL);
if(HashFinalIN) awsm__hash_Final__free_unpacked(HashFinalIN, NULL);
return psReturn;
}

View File

@ -15,7 +15,7 @@ message HashUpdate
int32 ReturnValue = 3;
}
message HashFinsh
message HashFinal
{
bytes HashData = 1;
int32 HashDataLen = 2;

View File

@ -17,7 +17,7 @@ PROTOBUF_C__BEGIN_DECLS
typedef struct _AWSM__HashInit AWSM__HashInit;
typedef struct _AWSM__HashUpdate AWSM__HashUpdate;
typedef struct _AWSM__HashFinsh AWSM__HashFinsh;
typedef struct _AWSM__HashFinal AWSM__HashFinal;
typedef struct _AWSM__Hash AWSM__Hash;
typedef struct _AWSM__Rand AWSM__Rand;
typedef struct _AWSM__SignatureByIntPrikey AWSM__SignatureByIntPrikey;
@ -70,15 +70,15 @@ struct _AWSM__HashUpdate
, {0,NULL}, 0, 0 }
struct _AWSM__HashFinsh
struct _AWSM__HashFinal
{
ProtobufCMessage base;
ProtobufCBinaryData hashdata;
int32_t hashdatalen;
int32_t returnvalue;
};
#define AWSM__HASH_FINSH__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&awsm__hash_finsh__descriptor) \
#define AWSM__HASH_FINAL__INIT \
{ PROTOBUF_C_MESSAGE_INIT (&awsm__hash_final__descriptor) \
, {0,NULL}, 0, 0 }
@ -436,24 +436,24 @@ AWSM__HashUpdate *
void awsm__hash_update__free_unpacked
(AWSM__HashUpdate *message,
ProtobufCAllocator *allocator);
/* AWSM__HashFinsh methods */
void awsm__hash_finsh__init
(AWSM__HashFinsh *message);
size_t awsm__hash_finsh__get_packed_size
(const AWSM__HashFinsh *message);
size_t awsm__hash_finsh__pack
(const AWSM__HashFinsh *message,
/* AWSM__HashFinal methods */
void awsm__hash_final__init
(AWSM__HashFinal *message);
size_t awsm__hash_final__get_packed_size
(const AWSM__HashFinal *message);
size_t awsm__hash_final__pack
(const AWSM__HashFinal *message,
uint8_t *out);
size_t awsm__hash_finsh__pack_to_buffer
(const AWSM__HashFinsh *message,
size_t awsm__hash_final__pack_to_buffer
(const AWSM__HashFinal *message,
ProtobufCBuffer *buffer);
AWSM__HashFinsh *
awsm__hash_finsh__unpack
AWSM__HashFinal *
awsm__hash_final__unpack
(ProtobufCAllocator *allocator,
size_t len,
const uint8_t *data);
void awsm__hash_finsh__free_unpacked
(AWSM__HashFinsh *message,
void awsm__hash_final__free_unpacked
(AWSM__HashFinal *message,
ProtobufCAllocator *allocator);
/* AWSM__Hash methods */
void awsm__hash__init
@ -881,8 +881,8 @@ typedef void (*AWSM__HashInit_Closure)
typedef void (*AWSM__HashUpdate_Closure)
(const AWSM__HashUpdate *message,
void *closure_data);
typedef void (*AWSM__HashFinsh_Closure)
(const AWSM__HashFinsh *message,
typedef void (*AWSM__HashFinal_Closure)
(const AWSM__HashFinal *message,
void *closure_data);
typedef void (*AWSM__Hash_Closure)
(const AWSM__Hash *message,
@ -958,7 +958,7 @@ typedef void (*AWSM__GetDevInfo_Closure)
extern const ProtobufCMessageDescriptor awsm__hash_init__descriptor;
extern const ProtobufCMessageDescriptor awsm__hash_update__descriptor;
extern const ProtobufCMessageDescriptor awsm__hash_finsh__descriptor;
extern const ProtobufCMessageDescriptor awsm__hash_final__descriptor;
extern const ProtobufCMessageDescriptor awsm__hash__descriptor;
extern const ProtobufCMessageDescriptor awsm__rand__descriptor;
extern const ProtobufCMessageDescriptor awsm__signature_by_int_prikey__descriptor;

View File

@ -97,49 +97,49 @@ void awsm__hash_update__free_unpacked
assert(message->base.descriptor == &awsm__hash_update__descriptor);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void awsm__hash_finsh__init
(AWSM__HashFinsh *message)
void awsm__hash_final__init
(AWSM__HashFinal *message)
{
static const AWSM__HashFinsh init_value = AWSM__HASH_FINSH__INIT;
static const AWSM__HashFinal init_value = AWSM__HASH_FINAL__INIT;
*message = init_value;
}
size_t awsm__hash_finsh__get_packed_size
(const AWSM__HashFinsh *message)
size_t awsm__hash_final__get_packed_size
(const AWSM__HashFinal *message)
{
assert(message->base.descriptor == &awsm__hash_finsh__descriptor);
assert(message->base.descriptor == &awsm__hash_final__descriptor);
return protobuf_c_message_get_packed_size ((const ProtobufCMessage*)(message));
}
size_t awsm__hash_finsh__pack
(const AWSM__HashFinsh *message,
size_t awsm__hash_final__pack
(const AWSM__HashFinal *message,
uint8_t *out)
{
assert(message->base.descriptor == &awsm__hash_finsh__descriptor);
assert(message->base.descriptor == &awsm__hash_final__descriptor);
return protobuf_c_message_pack ((const ProtobufCMessage*)message, out);
}
size_t awsm__hash_finsh__pack_to_buffer
(const AWSM__HashFinsh *message,
size_t awsm__hash_final__pack_to_buffer
(const AWSM__HashFinal *message,
ProtobufCBuffer *buffer)
{
assert(message->base.descriptor == &awsm__hash_finsh__descriptor);
assert(message->base.descriptor == &awsm__hash_final__descriptor);
return protobuf_c_message_pack_to_buffer ((const ProtobufCMessage*)message, buffer);
}
AWSM__HashFinsh *
awsm__hash_finsh__unpack
AWSM__HashFinal *
awsm__hash_final__unpack
(ProtobufCAllocator *allocator,
size_t len,
const uint8_t *data)
{
return (AWSM__HashFinsh *)
protobuf_c_message_unpack (&awsm__hash_finsh__descriptor,
return (AWSM__HashFinal *)
protobuf_c_message_unpack (&awsm__hash_final__descriptor,
allocator, len, data);
}
void awsm__hash_finsh__free_unpacked
(AWSM__HashFinsh *message,
void awsm__hash_final__free_unpacked
(AWSM__HashFinal *message,
ProtobufCAllocator *allocator)
{
if(!message)
return;
assert(message->base.descriptor == &awsm__hash_finsh__descriptor);
assert(message->base.descriptor == &awsm__hash_final__descriptor);
protobuf_c_message_free_unpacked ((ProtobufCMessage*)message, allocator);
}
void awsm__hash__init
@ -1247,7 +1247,7 @@ const ProtobufCMessageDescriptor awsm__hash_update__descriptor =
(ProtobufCMessageInit) awsm__hash_update__init,
NULL,NULL,NULL /* reserved[123] */
};
static const ProtobufCFieldDescriptor awsm__hash_finsh__field_descriptors[3] =
static const ProtobufCFieldDescriptor awsm__hash_final__field_descriptors[3] =
{
{
"HashData",
@ -1255,7 +1255,7 @@ static const ProtobufCFieldDescriptor awsm__hash_finsh__field_descriptors[3] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_BYTES,
0, /* quantifier_offset */
offsetof(AWSM__HashFinsh, hashdata),
offsetof(AWSM__HashFinal, hashdata),
NULL,
NULL,
0, /* flags */
@ -1267,7 +1267,7 @@ static const ProtobufCFieldDescriptor awsm__hash_finsh__field_descriptors[3] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_INT32,
0, /* quantifier_offset */
offsetof(AWSM__HashFinsh, hashdatalen),
offsetof(AWSM__HashFinal, hashdatalen),
NULL,
NULL,
0, /* flags */
@ -1279,36 +1279,36 @@ static const ProtobufCFieldDescriptor awsm__hash_finsh__field_descriptors[3] =
PROTOBUF_C_LABEL_NONE,
PROTOBUF_C_TYPE_INT32,
0, /* quantifier_offset */
offsetof(AWSM__HashFinsh, returnvalue),
offsetof(AWSM__HashFinal, returnvalue),
NULL,
NULL,
0, /* flags */
0,NULL,NULL /* reserved1,reserved2, etc */
},
};
static const unsigned awsm__hash_finsh__field_indices_by_name[] = {
static const unsigned awsm__hash_final__field_indices_by_name[] = {
0, /* field[0] = HashData */
1, /* field[1] = HashDataLen */
2, /* field[2] = ReturnValue */
};
static const ProtobufCIntRange awsm__hash_finsh__number_ranges[1 + 1] =
static const ProtobufCIntRange awsm__hash_final__number_ranges[1 + 1] =
{
{ 1, 0 },
{ 0, 3 }
};
const ProtobufCMessageDescriptor awsm__hash_finsh__descriptor =
const ProtobufCMessageDescriptor awsm__hash_final__descriptor =
{
PROTOBUF_C__MESSAGE_DESCRIPTOR_MAGIC,
"AWSM.HashFinsh",
"HashFinsh",
"AWSM__HashFinsh",
"AWSM.HashFinal",
"HashFinal",
"AWSM__HashFinal",
"AWSM",
sizeof(AWSM__HashFinsh),
sizeof(AWSM__HashFinal),
3,
awsm__hash_finsh__field_descriptors,
awsm__hash_finsh__field_indices_by_name,
1, awsm__hash_finsh__number_ranges,
(ProtobufCMessageInit) awsm__hash_finsh__init,
awsm__hash_final__field_descriptors,
awsm__hash_final__field_indices_by_name,
1, awsm__hash_final__number_ranges,
(ProtobufCMessageInit) awsm__hash_final__init,
NULL,NULL,NULL /* reserved[123] */
};
static const ProtobufCFieldDescriptor awsm__hash__field_descriptors[6] =