在SM2 ECC算法中,有针对签名加密的数据结构,下面对这些结构进行分析算法
#define ECCref_MAX_BITS 512
#define ECCref_MAX_LEN ((ECCref_MAX_BITS+7) / 8)数据结构
#define ECC_OFFSET 32加密
公钥数据结构定义
typedef struct ECCrefPublicKey_st
{
unsigned int bits; //密钥位长,数据长度为4字节
unsigned char x[ECCref_MAX_LEN]; //公钥X坐标, 32字节
unsigned char y[ECCref_MAX_LEN]; //公钥Y坐标, 32字节
} ECCrefPublicKey;spa
私钥数据结构定义blog
typedef struct ECCrefPrivateKey_st
{
unsigned int bits; //密钥位长,数据长度为4字节
unsigned char K[ECCref_MAX_LEN]; // 私钥,32字节
} ECCrefPrivateKey;ip
memcpy(pucPublicKey->x+ECC_OFFSET, sm2key.x,32);
memcpy(pucPublicKey->y+ECC_OFFSET, sm2key.y,32);
memcpy(pucPrivateKey->K+ECC_OFFSET ,sm2key.d ,32);ci
用私钥k能够产生对应的公钥x y,私钥k由随机数产生hash
ECC加密数据结构定义it
#define ECCCipher_MAX_C_LEN 4096
typedef struct ECCCipher_st
{
unsigned char x[ECCref_MAX_LEN];
unsigned char y[ECCref_MAX_LEN];
unsigned char M[32];
unsigned int L;
unsigned char C[ECCCipher_MAX_C_LEN];
} ECCCipher;table
起始地址:X+32 |
起始地址Y+32 |
加密的数据C |
SM3 hash值M |
长度为32 长度为32 长度为L 长度为32
因此加密的结果为96+L