在能够解析隐式证书实例的基础上(SM2无证书及隐式证书公钥机制签名和加密过程详解(四)-CSDN博客),这里介绍如何通过隐式证书机制实现签名验签及加密解密。
(5)隐式证书机制签名验签过程
5.1签名过程
输入:
M - message digest('6D65737361676520646967657374'H)
ICA - '00030183082122232425262728008000000A0808080808080808080909090002002373008400C8812183DB65BF80F08E3FEA9758A9490F2C257A2D8ADEAA59DA786CBFAFEF221E78ADB4'H
IDA - '8000000A0808080808080808080909090002002373008400C8'H
dA - '43E0BBFDFFE6224ACCDB6C2905E41A27C1AB0CC141F47D516C42E400FAED8500'H
n - 'FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123'H
计算:
e = SM3(ICA||M)
= 'CF308D3912BFD34444F7EDB5379160E74D4CEF12159C9749C16A391CE3946A8B'H
随机数k = '34914C20251A59A2C311102944C600430A02285A0433144228142A1848004C14'H
(x1,y1) = ('80C8022B011044A1392310CD3B7E722E444B68D8B20E948A8517E5BD8BB92531'H, '1214F7E5C4D4121DE8845B5D81F138A25707C7600FC63A62D2F007C056FC0804'H)
r = (e+x1) mod n = '4FF88F6513D017E57E1AFE82730FD3161F94787FA5E526A8F2C62AD135784E99'H
s = (k-[r]dA)/(dA+1) mod n = 'BF6CCA55B7AB45D033577A2AF860DB5F0F0D6C9F12957F545B2BC02AEDCF903A'H
输出:(r,s)
5.2验签过程
输入:
M - message digest('6D65737361676520646967657374'H)
ICA - '00030183082122232425262728008000000A0808080808080808080909090002002373008400C8812183DB65BF80F08E3FEA9758A9490F2C257A2D8ADEAA59DA786CBFAFEF221E78ADB4'H
IDA - '8000000A0808080808080808080909090002002373008400C8'H
n - 'FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123'H
KGC证书(Ppub)
计算:
HA = SM3(ENTLA||IDA||a||b||Xg||Yg||Xpub||Ypub)
= '2138FC2CBF4B591D156757D998A245BAEAD4FFA85586342EFFDA6D5F33BE9384'H
基于ICA解压缩获得WA=(Xwa,Ywa)
Xwa = 'DB65BF80F08E3FEA9758A9490F2C257A2D8ADEAA59DA786CBFAFEF221E78ADB4'H
Ywa = '0728185A257F64B79DFA929C16C987ED956FB32D00B6CAF7678E56E66E01530F'H
= SM3(Xwa||Ywa||HA)
= 'D343E4E6679DBDBFBFED3F7E9EF2491DEDF1FC14D6372A5A2530C731846D8F21'H
PA = WA + []Ppub = (Xp,Yp)
Xp = '5E6203B3E5B8B4C6FDA394C9ED0940C4143D7AECC933C129A3B5CB1A6A950D1B'H
Yp = 'A0CFE288A04D33DD6BA589DA3AB397F75A6ED2CDFD9108AB29B29CD40A624BD5'H
e = SM3(ICA||M)
[s]G+[r+s]PA = (x1,y1)
r' = (e+x1) mod n
比较r'是否与r相同
(6)隐式证书机制加密解密过程
6.1加密过程
输入:
M - '01010101'H
ICA - '00030183082122232425262728008000000A0808080808080808080909090002002373008400C8812183DB65BF80F08E3FEA9758A9490F2C257A2D8ADEAA59DA786CBFAFEF221E78ADB4'H
IDA - '8000000A0808080808080808080909090002002373008400C8'H
n - 'FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFF7203DF6B21C6052B53BBF40939D54123'H
KGC证书(Ppub)
计算:
HA = SM3(ENTLA||IDA||a||b||Xg||Yg||Xpub||Ypub)
= '2138FC2CBF4B591D156757D998A245BAEAD4FFA85586342EFFDA6D5F33BE9384'H
基于ICA解压缩获得WA=(Xwa,Ywa)
Xwa = 'DB65BF80F08E3FEA9758A9490F2C257A2D8ADEAA59DA786CBFAFEF221E78ADB4'H
Ywa = '0728185A257F64B79DFA929C16C987ED956FB32D00B6CAF7678E56E66E01530F'H
= SM3(Xwa||Ywa||HA)
= 'D343E4E6679DBDBFBFED3F7E9EF2491DEDF1FC14D6372A5A2530C731846D8F21'H
PA = WA + []Ppub = (Xp,Yp)
Xp = '5E6203B3E5B8B4C6FDA394C9ED0940C4143D7AECC933C129A3B5CB1A6A950D1B'H
Yp = 'A0CFE288A04D33DD6BA589DA3AB397F75A6ED2CDFD9108AB29B29CD40A624BD5'H
随机数k = '0E548BCA4F4EBB616BBD2FBB670E8B0289CD1B7DA7893751A9EA5ECAF93DB649'H
c1 = [k]G = '207254CA421B003D4604B278BE0F369A763C6498324BD70FD835B75DAD8F7765F16872734F9BCF91AD7C8817A456FB6802F60919C9975852BD3E8A17DEE4683B'H
c2 = 'E8EC1894'H
c3 = 'E67067DEA229D24D2C98F6A089E01687A34D87DBD908124FD05F186C842BBCAC'H
输出:c1||c3||c2
6.2解密过程
输入:
dA-'43E0BBFDFFE6224ACCDB6C2905E41A27C1AB0CC141F47D516C42E400FAED8500'H
c1||c3||c2
按照SM2解密算法即可。