jntass / TASSL

此仓库已停止维护,请移步https://github.com/jntass/TASSL-1.1.1
http://www.tass.com.cn
Other
291 stars 106 forks source link

sm2解密直接段错误!! #36

Open ygm521 opened 6 years ago

ygm521 commented 6 years ago

秘钥文件内容:

Private-Key: (256 bit) priv: 51:5f:ff:18:27:b5:be:41:5e:70:bc:d9:00:fc:a3: d6:af:4a:b8:da:3c:5e:88:4d:d3:7b:64:2a:77:1a: 2a:ea pub: 04:43:81:e4:75:71:ba:3e:73:3b:c3:a8:bd:69:7c: 6a:08:9d:a7:e5:50:46:63:c1:d1:6e:39:ea:ee:d8: bb:39:b8:0d:0a:58:2d:e8:79:2e:73:32:2c:7e:a1: ea:47:4b:8a:08:5b:2f:6b:5a:61:c7:2d:93:bc:21: 51:28:fd:94:23 ASN1 OID: sm2p256v1

私钥16进制:

 515fff1827b5be415e70bcd900fca3d6af4ab8da3c5e884dd37b642a771a2aea

sm2加密后的数据16进制字串:

a631eaf7cfb45f6c8c1adbcb353f32fff624f629a942282e1167d4c4310ca3586eaa72a25482fd6c8f72593a437e5bb1b86c600fbf2caef88a283ab2c92896c5355c0795839f5565dfb63c3ab137a94d5333f57352df5a4e61c45515df99d92fd789fb0b9c4c19f03a3150b28062f6edec2d6f4981e96e3680203912ec40c504da0c6fe033202878c62da2513d0c0a8fe8d0ab1e2c598fdad05723550d247fe6a2f1f7adeb3ca4977c5f4a30a67b861681933ce65352387cf65ece12ffd9f1a8

解密操作:

[root@localhost crypto]# ./sm2enc_der d 515fff1827b5be415e70bcd900fca3d6af4ab8da3c5e884dd37b642a771a2aea a631eaf7cfb45f6c8c1adbcb353f32fff624f629a942282e1167d4c4310ca3586eaa72a25482fd6c8f72593a437e5bb1b86c600fbf2caef88a283ab2c92896c5355c0795839f5565dfb63c3ab137a94d5333f57352df5a4e61c45515df99d92fd789fb0b9c4c19f03a3150b28062f6edec2d6f4981e96e3680203912ec40c504da0c6fe033202878c62da2513d0c0a8fe8d0ab1e2c598fdad05723550d247fe6a2f1f7adeb3ca4977c5f4a30a67b861681933ce65352387cf65ece12ffd9f1a8

段错误:

0 0x0000000000413820 in sm2_decrypt ()

Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.132.el6.x86_64 (gdb) bt

0 0x0000000000413820 in sm2_decrypt ()

1 0x0000000000401ed7 in main (argc=4, argv=0x7fffedcf49b8) at sm2enc_der.c:220

(gdb) up

1 0x0000000000401ed7 in main (argc=4, argv=0x7fffedcf49b8) at sm2enc_der.c:220

220 retval = sm2_decrypt(NULL, &outlen, (const SM2ENC )sm2enc, NULL/EVP_sm3()*/, sm2key);

下面是加密和我的结果不一样呢?

[root@localhost crypto]# ./sm2enc_der e 044381e47571ba3e733bc3a8bd697c6a089da7e5504663c1d16e39eaeed8bb39b80d0a582de8792e73322c7ea1ea474b8a085b2f6b5a61c72d93bc215128fd9423 bfbb44b49173ee09e1a2f3c79d064dceabab2079f1de4a37009d3f630720562c2ebe9e21ba1b8970909a9088994a60ddfa422a7849c2a2b9acd918f17cf5ac5607a4f80ba3b2307273e23971a548476ddb7c514cf44b15d662d591a805e8c503

tuwulin365 commented 2 years ago

sm2加密是有随机数参与的,每次都不一样。 密文开头的04是标志位,有时可能需要去掉或者手动加上。 密文还有C1C2C3顺序问题。