diff --git a/app/src/main/cpp/SpiLib.cpp b/app/src/main/cpp/SpiLib.cpp index c0f07fa..30ec2b6 100644 --- a/app/src/main/cpp/SpiLib.cpp +++ b/app/src/main/cpp/SpiLib.cpp @@ -1,23 +1,5 @@ -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include - -#include -#include - -#include #include "SpiLib.h" -using namespace std; -#define CMD_HEAD_SIZE 5 //typedef unsigned char u8; #define RE_SUC 0x01 @@ -166,8 +148,12 @@ void SpiLIb::RcvLEN(int fd, u8 *txbuf, u8 *buf, u8 len) int retval; /* receive length */ LEN: - retval = spi_transfer(fd, txbuf, buf, 1); - __android_log_print(ANDROID_LOG_INFO, "SPiLEN", "txbuf=%x,rxbuf=%hhu", *txbuf,*buf); + for(int i=0;i +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include + +using namespace std; + +#define CMD_HEAD_SIZE 5 using namespace std; typedef unsigned char u8; @@ -19,6 +38,7 @@ public: int SM2VerifySign(int index,unsigned char *hash,unsigned char *vs); int SM2encrypt(int index,unsigned char *to_encrypt ,unsigned char *out_encrypt); int SM2decoder(int index,unsigned char *to_decoder ,unsigned char *out_decoder); + int SM2cert(int type,int index,string cert,unsigned char *out_cert); @@ -85,6 +105,7 @@ private: void RcvINS(int fd, u8 *txbuf, u8 *buf, u8 ins); void RcvLEN(int fd, u8 *txbuf, u8 *buf, u8 len); void RcvData(int fd, u8 *txbuf, u8 *buf); + void RcvData(int fd, u8 *txbuf, u8 *buf, int len); void RcvSW(int fd, u8 *txbuf, u8 *buf, u8 sw); void SendEnd(int fd, u8 *txbuf, u8 *buf); void SendId(int fd, u8 *txbuf, u8 *buf, u8 id); @@ -92,8 +113,6 @@ private: - - }; diff --git a/app/src/main/cpp/native-lib.cpp b/app/src/main/cpp/native-lib.cpp index a1ebc1f..2ddafe7 100644 --- a/app/src/main/cpp/native-lib.cpp +++ b/app/src/main/cpp/native-lib.cpp @@ -71,31 +71,36 @@ Java_com_xinyingpower_testcomm_MainActivity_testSpi( jobject /* this */, jint port) { //testSpi(); SpiLIb a; - unsigned char newkey[64]={0xaf,0x0c,0xa9,0x40,0x1f,0xe6,0xee,0x0f,0x4c, + unsigned char newkey[32]={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 + 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],outsign[64]; + unsigned char outpub[32],outsign[64], *outen = new unsigned char [256]; unsigned char pucid[16]={0x01,0x01,0x01,0x01,0x01,0x01,0x01, 0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01,0x01}; + string b="C=CN,ST=jiangsu,L=nanjing,O=GDD,OU=nari,CN=test001"; //a.SM2keypair(0x00); //a.SM3Hash(newkey,16, outpub); - a.sm3hash_tosm2(newkey,16,outpub,newkey,pucid,16); - a.SM2Sign(0x00,outpub,outsign); - a.SM2VerifySign(0x00,outpub,outsign); + //a.sm3hash_tosm2(newkey,16,outpub,newkey,pucid,16); + //a.SM2Sign(0x00,outpub,outsign); + //a.SM2VerifySign(0x00,outpub,outsign); + a.SM2cert(0x00,0x00,b,outen); 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]); + __android_log_print(ANDROID_LOG_INFO, "SPi", "%02x", outen[i]); } +// a.SM2decoder(0x00,outen,outpub); +// +// for (int i = 0; i < 64; i++) { +// //sprintf(output, " %02x ", rxbuf[i]); +// __android_log_print(ANDROID_LOG_INFO, "SPi", "%02x", outpub[i]); +// } //a.SM3Hash(0x00,0x10,newkey); //testVersion();