sm3hash_tosm2() 栈溢出报错,SM2签名和验签没测。安全认证没输入数据没测

main
陈曦 2 years ago
parent 5234acf8fd
commit 0d43ec8b83

@ -1217,7 +1217,73 @@ int SpiLIb::SM2cert(int type,int index,string cert,unsigned char *out_cert)//证
close(fd);
return 0;
}
int SpiLIb::Indentify(unsigned char *to_idt,unsigned char *out_idt)//安全认证
{
int i;
int cnt;
unsigned char txbuf[512];
unsigned char rxbuf[512];
int retval;
int msglen;
int fd;
const char *devname = "/dev/spidevSE";
//const char *devname = "/dev/spidev0.0";
//const char *devname = "/dev/mtkgpioctrl";
// NrsecSpiPort spi("/dev/spidevSE");
//
// // NrsecSpiPort spi("/dev/spidev0.0")
fd = open(devname, O_RDWR);
if (fd < 0) {
perror("open");
return 1;
}
spi_master_init(devname, fd);
msglen = 5;
memset(rxbuf, 0, sizeof(rxbuf));
memset(txbuf, 0, sizeof(txbuf));
//printf("tx %1d bytes: ", msglen);
//__android_log_print(ANDROID_LOG_INFO, "SPi", "tx %1d bytes", msglen);
CMD_RESEND:
memcpy(txbuf, (const void *) Indentify_CMD, sizeof(Indentify_CMD));
SendCmdHeader(fd, txbuf, rxbuf);
RcvINS(fd,txbuf,rxbuf,txbuf[1]);
SendId(fd,txbuf,rxbuf, 0x55);
memcpy(txbuf, to_idt, 32);
SendData(fd, txbuf, rxbuf,32);
SendEnd(fd,txbuf,rxbuf);
memcpy(txbuf, (const void *) SM2decoder_CMD, sizeof(SM2decoder_CMD));
RcvINS(fd,txbuf,rxbuf,txbuf[1]);
RcvLEN(fd,txbuf,rxbuf+1, 1);
RcvData(fd, txbuf, rxbuf+2);
RcvSW(fd, txbuf, rxbuf+2+rxbuf[1], 0x90);
//__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_idt[i-2]= rxbuf[i];
}
close(fd);
return 0;
}

@ -26,6 +26,7 @@ class SpiLIb{
public:
int Spirandom();
int Version();
int Indentify(unsigned char *to_idt,unsigned char *out_idt);
int SM2keypair(int index);
int SM2OutPub(int index,unsigned char result[]);
int SM2OutPri(int index,unsigned char result[]);
@ -42,6 +43,7 @@ public:
private:
const unsigned char crc7_table[256]= {
0x00, 0x09, 0x12, 0x1b, 0x24, 0x2d, 0x36, 0x3f,

Loading…
Cancel
Save