发明名称 一种SM3密码杂凑算法及确定其中的变量字的方法
摘要 本发明涉及一种SM3密码杂凑算法及确定其中的变量字的方法。变量字为A-H;该方法包括:步骤a:设置n=0;确定常量Tn和消息扩展字W<sub>0</sub>-W<sub>67</sub>、W<sub>0</sub>’-W<sub>63</sub>’;进行设置A-H及P和Q的初始化值A<sub>-1</sub>、B<sub>-1</sub>、C<sub>-1</sub>、D<sub>-1</sub>、E<sub>-1</sub>、F<sub>-1</sub>、G<sub>-1</sub>、H<sub>-1</sub>、P<sub>-1</sub>=D<sub>-1</sub>+W’<sub>0</sub>,Q<sub>-1</sub>=H<sub>-1</sub>+W<sub>0</sub>;步骤b:按照迭代公式进行一次迭代运算,确定SS1、SS2、TT1、TT2、P、Q和各变量字的第n次迭代值;迭代公式包括:SS1<sub>n</sub>=S<sup>7</sup>[S<sup>12</sup>(A<sub>n-1</sub>)+E<sub>n-1</sub>+S<sup>n</sup>(T<sub>n</sub>)];<img file="DDA0000057543810000011.GIF" wi="517" he="55" /></maths>TT1<sub>n</sub>=FF<sub>n</sub>(A<sub>n-1</sub>,B<sub>n-1</sub>,C<sub>n-1</sub>)+SS2<sub>n</sub>+P<sub>n-1</sub>;TT2<sub>n</sub>=GG<sub>n</sub>(E<sub>n-1</sub>,F<sub>n-1</sub>,G<sub>n-1</sub>)+SS1<sub>n</sub>+Q<sub>n-1</sub>;D<sub>n</sub>=C<sub>n-1</sub>;C<sub>n</sub>=S<sup>9</sup>(B<sub>n-1</sub>);B<sub>n</sub>=A<sub>n-1</sub>;A<sub>n</sub>=TT1<sub>n</sub>;H<sub>n</sub>=G<sub>n-1</sub>;G<sub>n</sub>=S<sup>19</sup>(F<sub>n-1</sub>);F<sub>n</sub>=E<sub>n-1</sub>;E<sub>n</sub>=P<sub>0</sub>(TT2<sub>n</sub>);P<sub>n</sub>=C<sub>n-1</sub>+W′<sub>n+1</sub>;Q<sub>n</sub>=G<sub>n-1</sub>+W<sub>n+1</sub>;<img file="DDA0000057543810000012.GIF" wi="1361" he="92" /></maths><img file="DDA0000057543810000013.GIF" wi="1254" he="112" /></maths><img file="DDA0000057543810000014.GIF" wi="925" he="54" /></maths>步骤c:n自动加1;判断n是否超过63,是则执行输出A-H的迭代终值,否则继续迭代。本发明能减少变量字的迭代过程中关键路径的串行加法运算的数量。
申请公布号 CN102761414B 申请公布日期 2015.06.10
申请号 CN201110105198.6 申请日期 2011.04.26
申请人 航天信息股份有限公司 发明人 徐树民;王绍麟;田心;刘振;屈善新;刘建巍
分类号 H04L9/32(2006.01)I 主分类号 H04L9/32(2006.01)I
代理机构 北京科龙寰宇知识产权代理有限责任公司 11139 代理人 孙皓晨;朱世定
主权项 一种用于加密消息的SM3密码杂凑值的确定方法,其特征在于,包括以下步骤:步骤1:接收长度不超过(2<sup>64</sup>‑1)比特的消息m,并对其进行填充,得到长度为512比特的k倍的填充消息m’,其中的k为不超过(2<sup>55</sup>+1)的正整数;步骤2:从m’的最高比特位开始,以512比特为一个消息分组,将m’划分为k组,各消息分组按其在m’中的比特位由高到低的顺序依次记为B0‑B(k‑1);步骤3:设置循环变量i为0;设置压缩函数V的第0次迭代值VO为用16进制表示的7380166f 4914b2b9 172442d7 da8a0600 a96f30bc 163138aa e38dee4d b0fb0e4e;步骤4:根据Bi确定出132个32比特长度的消息扩展字W<sub>i0</sub>‑W<sub>i67</sub>、W<sub>i0</sub>’‑W<sub>i63</sub>’,其中,Bi为第i个消息分组,i为0与(k‑1)之间的正整数;步骤5:确定32比特长度的变量字A<sub>i</sub>、B<sub>i</sub>、C<sub>i</sub>、D<sub>i</sub>、E<sub>i</sub>、F<sub>i</sub>、G<sub>i</sub>、H<sub>i</sub>的第63次迭代值A<sub>i63</sub>、B<sub>i63</sub>、C<sub>i63</sub>、D<sub>i63</sub>、E<sub>i63</sub>、F<sub>i63</sub>、G<sub>i63</sub>、H<sub>i63</sub>,其方法包括:步骤51:设置迭代次数n为0;确定32比特长度的常量Tn;进行初始化过程,所述初始化过程包括:设置各变量字的初始迭代值A<sub>i(‑1)</sub>、B<sub>i(‑1)</sub>、C<sub>i(‑1)</sub>、D<sub>i(‑1)</sub>、E<sub>i(‑1)</sub>、F<sub>i(‑1)</sub>、G<sub>i(‑1)</sub>、H<sub>i(‑1)</sub>;确定中间变量字P<sub>i</sub>、Q<sub>i</sub>的初始迭代值P<sub>i(‑1)</sub>=D<sub>i(‑1)</sub>+W′<sub>i0</sub>,Q<sub>i(‑1)</sub>=H<sub>i(‑1)</sub>+W<sub>i0</sub>;步骤52:按照迭代公式进行一次迭代运算,确定中间变量字SS1<sub>i</sub>、SS2<sub>i</sub>、TT1<sub>i</sub>、TT2<sub>i</sub>、P<sub>i</sub>、Q<sub>i</sub>和各变量字的第n次迭代值SS1<sub>in</sub>、SS2<sub>in</sub>、TT1<sub>in</sub>、TT2<sub>in</sub>、P<sub>in</sub>、Q<sub>in</sub>、A<sub>in</sub>、B<sub>in</sub>、C<sub>in</sub>、D<sub>in</sub>、E<sub>in</sub>、F<sub>in</sub>、G<sub>in</sub>、H<sub>in</sub>;所述迭代公式包括:SS1<sub>in</sub>=S<sup>7</sup>[S<sup>12</sup>(A<sub>i</sub>(<sub>n‑1</sub>))+E<sub>i</sub>(<sub>n‑1</sub>)+S<sup>n</sup>(T<sub>n</sub>)];SS2<sub>in</sub>=SS1<sub>in</sub>⊕S<sup>12</sup>(A<sub>i</sub>(<sub>n‑1</sub>));TT1<sub>in</sub>=FFn<sub>(</sub>A<sub>i(n‑1)</sub>,B<sub>i(n‑1)</sub>,C<sub>i(n‑1)</sub>)+SS2<sub>in</sub>+P<sub>i(n‑1)</sub>;TT2<sub>in</sub>=GG<sub>n</sub>(E<sub>i(n‑1)</sub>,F<sub>i(n‑1)</sub>,G<sub>i(n‑1)</sub>)+SS1<sub>in</sub>+Q<sub>i(n‑1)</sub>;D<sub>in</sub>=C<sub>i(n‑1)</sub>;C<sub>in</sub>=S<sup>9</sup>(B<sub>i(n‑1)</sub>);B<sub>in</sub>=A<sub>i(n‑1)</sub>;A<sub>in</sub>=TT1<sub>in</sub>;H<sub>in</sub>=G<sub>i(n‑1)</sub>;G<sub>in</sub>=S<sup>19</sup>(F<sub>i(n‑1)</sub>);F<sub>in</sub>=E<sub>i(n‑1)</sub>;E<sub>in</sub>=P<sub>0</sub>(TT2<sub>in</sub>);P<sub>in</sub>=C<sub>i(n‑1)</sub>+W′<sub>i(n+1)</sub>;Q<sub>in</sub>=G<sub>i(n‑1)</sub>+W<sub>i(n+1)</sub>;其中,A<sub>i(n‑1)</sub>、B<sub>i(n‑1)</sub>、C<sub>i(n‑1)</sub>、E<sub>i(n‑1)</sub>、F<sub>i(n‑1)</sub>、G<sub>i(n‑1)</sub>为相应变量字的第n‑1次迭代值;P<sub>i(n‑1)</sub>、Q<sub>i(n‑1)</sub>分别为P<sub>i</sub>、Q<sub>i</sub>的第n‑1次迭代值;FF<sub>n</sub>(A<sub>i(n‑1)</sub>,B<sub>i(n‑1)</sub>,C<sub>i(n‑1)</sub>)和GG<sub>n</sub>(E<sub>i(n‑1)</sub>,F<sub>i(n‑1)</sub>,G<sub>i(n‑1)</sub>)均为布尔函数,其函数表达式分别为:<maths num="0001" id="cmaths0001"><math><![CDATA[<mrow><msub><mi>FF</mi><mi>n</mi></msub><mrow><mo>(</mo><msub><mi>A</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow><mo>,</mo><msub><mi>B</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub><mo>,</mo><msub><mi>C</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub></mrow></msub><mo>)</mo></mrow><mo>=</mo><mfenced open='{' close=''><mtable><mtr><mtd><msub><mi>A</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub><mo>&CirclePlus;</mo><msub><mi>B</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub><mo>&CirclePlus;</mo><msub><mi>C</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub><mrow><mo>(</mo><mn>0</mn><mo>&le;</mo><mi>n</mi><mo>&le;</mo><mn>15</mn><mo>)</mo></mrow></mtd></mtr><mtr><mtd><mrow><mo>(</mo><msub><mi>A</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub><mo>&cap;</mo><msub><mi>B</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub><mo>&cup;</mo><mrow><mo>(</mo><msub><mi>B</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub><mo>&cap;</mo><msub><mi>C</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub><mo>&cup;</mo><mrow><mo>(</mo><msub><mi>A</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub><mo>&cap;</mo><msub><mi>C</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub></mrow></mrow><mo>)</mo></mrow><mrow><mo>(</mo><mn>16</mn><mo>&le;</mo><mi>n</mi><mo>&le;</mo><mn>63</mn><mo>)</mo></mrow></mtd></mtr></mtable></mfenced><mo>;</mo></mrow>]]></math><img file="FDA0000656066420000021.GIF" wi="1770" he="136" /></maths><maths num="0002" id="cmaths0002"><math><![CDATA[<mrow><msub><mi>GG</mi><mi>n</mi></msub><mrow><mo>(</mo><msub><mi>E</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub><mo>,</mo><msub><mi>F</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub><mo>,</mo><msub><mi>G</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub><mo>)</mo></mrow><mo>=</mo><mfenced open='{' close=''><mtable><mtr><mtd><msub><mi>E</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub><mo>&CirclePlus;</mo><msub><mi>F</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub><mo>&CirclePlus;</mo><msub><mi>G</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub><mrow><mo>(</mo><mn>0</mn><mo>&le;</mo><mi>n</mi><mo>&le;</mo><mn>15</mn><mo>)</mo></mrow></mtd></mtr><mtr><mtd><mrow><mo>(</mo><msub><mi>E</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub><mo>&cap;</mo><msub><mi>F</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub><mo>&cup;</mo><mrow><mo>(</mo><mover><msub><mi>E</mi><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub><mo>&OverBar;</mo></mover><msub><mrow><mo>&cap;</mo><mi>G</mi></mrow><mrow><mi>i</mi><mrow><mo>(</mo><mi>n</mi><mo>-</mo><mn>1</mn><mo>)</mo></mrow></mrow></msub><mo>)</mo></mrow><mrow><mo>(</mo><mn>16</mn><mo>&le;</mo><mi>n</mi><mo>&le;</mo><mn>63</mn><mo>)</mo></mrow></mrow></mtd></mtr></mtable></mfenced><mo>;</mo></mrow>]]></math><img file="FDA0000656066420000022.GIF" wi="1520" he="147" /></maths>P<sub>0</sub>(TT2<sub>in</sub>)为置换函数,其函数表达式为:P<sub>0</sub>(TT2<sub>in</sub>)=TT2<sub>in</sub>⊕[S<sup>9</sup>(TT2<sub>in</sub>)]⊕[S<sup>17</sup>(TT2<sub>in</sub>)];上述的S<sup>7</sup>(X)、S<sup>12</sup>(X)、S<sup>n</sup>(X)、S<sup>9</sup>(X)、S<sup>17</sup>(X)、S<sup>19</sup>(X)分别为对字X进行循环左移7比特、12比特、n比特、9比特、17比特、19比特的运算;⊕、∩、∪、‑分别为异或、逻辑与、逻辑或、逻辑非运算符;步骤53:n的值增加1;判断n是否超过63,是则结束步骤5,并执行步骤6;否则,执行步骤52;步骤6:将A<sub>i</sub>、B<sub>i</sub>、C<sub>i</sub>、D<sub>i</sub>、E<sub>i</sub>、F<sub>i</sub>、G<sub>i</sub>、H<sub>i</sub>的先后顺序作为比特位由高到低的排列顺序,将A<sub>i63</sub>、B<sub>i63</sub>、C<sub>i63</sub>、D<sub>i63</sub>、E<sub>i63</sub>、F<sub>i63</sub>、G<sub>i63</sub>、H<sub>i63</sub>组合为一个256比特长度的异或变量U<sub>i</sub>;利用V的第i次迭代值Vi,根据V(i+1)=U<sub>i</sub>⊕Vi确定V的第(i+1)次迭代值V(i+1);步骤7:i的值增加1;判断i是否超过(k‑1),是则将Vk作为m的杂凑值输出,否则执行步骤4。
地址 100097 北京市海淀区杏石口路甲18号