sm3hash_tosm2() 栈溢出报错

main
陈曦 2 years ago
parent c99503af23
commit 5451ae869b

@ -732,12 +732,12 @@ int SpiLIb::SM2InPri(int index,const unsigned char new_key[])//导入私钥 没
return 0;
}
int SpiLIb::SM3Hash(const unsigned char *to_hash ,int len,unsigned char *out_hash)//原始哈希 跑通了,没有验证
int SpiLIb::SM3Hash(unsigned char *to_hash ,int len,unsigned char *out_hash)//原始哈希 跑通了,没有验证
{
int i;
int cnt;
unsigned char txbuf[256];
unsigned char rxbuf[256];
unsigned char txbuf[512];
unsigned char rxbuf[512];
int retval;
int msglen;
@ -799,9 +799,9 @@ int SpiLIb::SM3Hash(const unsigned char *to_hash ,int len,unsigned char *out_has
RcvData(fd, txbuf, rxbuf+2);
RcvSW(fd, txbuf, rxbuf+2+rxbuf[1], 0x90);//?
RcvSW(fd, txbuf, rxbuf+2+rxbuf[1], 0x90);
__android_log_print(ANDROID_LOG_INFO, "SPi", "rx %1d bytes:", rxbuf[1]+4);
//__android_log_print(ANDROID_LOG_INFO, "SPi", "rx %1d bytes:", rxbuf[1]+4);
for (i = 2; i < rxbuf[1]+2; i++) {
//sprintf(output, " %02x ", rxbuf[i]);
out_hash[i-2]= rxbuf[i];

@ -12,11 +12,11 @@ public:
int SM2OutPri(int index,unsigned char result[]);
int SM2InPub(int index,const unsigned char new_key[]);
int SM2InPri(int index,const unsigned char new_key[]);
int SM3Hash(const unsigned char *to_hash ,int len,unsigned char *out_hash);
int SM3Hash(unsigned char *to_hash ,int len,unsigned char *out_hash);
int sm3hash_tosm2(unsigned char *in,int inl,unsigned char *out, unsigned char *pubkey, unsigned char
*pucID, int idl);
int SM2Sign(int index,const unsigned char *to_sign,unsigned char *out_sign);
int SM2VerifySign(int index,unsigned char *hash,unsigned char *vs)
int SM2VerifySign(int index,unsigned char *hash,unsigned char *vs);

@ -9,8 +9,6 @@
#include <linux/spi/spidev.h>
#include <android/log.h>
int testSpi();
int testVersion();
class NrsecSpiPort : public SpiPort {
@ -73,22 +71,31 @@ Java_com_xinyingpower_testcomm_MainActivity_testSpi(
jobject /* this */, jint port) {
//testSpi();
SpiLIb a;
const unsigned char newkey[64]={0xaf,0x0c,0xa9,0x40,0x1f,0xe6,0xee,0x0f,0x4c,
unsigned char newkey[64]={0xaf,0x0c,0xa9,0x40,0x1f,0xe6,0xee,0x0f,0x4c,
0xfb,0xf7,0x17,0x71,0xde,0x61,0x59
// ,0x0a,0x05,0x77,
// 0xfa,0xe7,0xd1,0x8d,0x10,0x3a,0x79,0x23,0xf2,0xb3,
// 0x6d,0xea,0x8e,0xe0,0x64,0xe7,0x5d,0x49,0x84,0xe4,
// 0x5f,0xc9,0x07,0x03,0x52,0x33,0x79,0x87,0xd4,0x62,
// 0x62,0xc0,0xcc,0xf0,0xd6,0x85,0x20,0x7f,0x7a,0xe8,
// 0xc8,0xed,0x12,0xdb,0xdc
,0x0a,0x05,0x77,
0xfa,0xe7,0xd1,0x8d,0x10,0x3a,0x79,0x23,0xf2,0xb3,
0x6d,0xea,0x8e,0xe0,0x64,0xe7,0x5d,0x49,0x84,0xe4,
0x5f,0xc9,0x07,0x03,0x52,0x33,0x79,0x87,0xd4,0x62,
0x62,0xc0,0xcc,0xf0,0xd6,0x85,0x20,0x7f,0x7a,0xe8,
0xc8,0xed,0x12,0xdb,0xdc
};
unsigned char outpub[32];
unsigned char outpub[32],outsign[64];
unsigned char pucid[16]={0x01,0x01,0x01,0x01,0x01,0x01,0x01,
0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01};
//a.SM2keypair(0x00);
a.SM3Hash(newkey,16, outpub);
//a.SM3Hash(newkey,16, outpub);
a.sm3hash_tosm2(newkey,16,outpub,newkey,pucid,16);
a.SM2Sign(0x00,outpub,outsign);
a.SM2VerifySign(0x00,outpub,outsign);
for (int i = 0; i < 32; i++) {
//sprintf(output, " %02x ", rxbuf[i]);
__android_log_print(ANDROID_LOG_INFO, "SPi", "%02x", outpub[i]);
}
for (int i = 0; i < 64; i++) {
//sprintf(output, " %02x ", rxbuf[i]);
__android_log_print(ANDROID_LOG_INFO, "SPi", "%02x", outsign[i]);
}
//a.SM3Hash(0x00,0x10,newkey);
//testVersion();

Loading…
Cancel
Save