1:HL["/_next/static/css/275839517c59c532.css",{"as":"style"}] 2:HL["/_next/static/css/bdb880d990e879b6.css",{"as":"style"}] 0:[[["",{"children":["post",{"children":[["slug","sm3-implementing","d"],{"children":["__PAGE__?{\"slug\":\"sm3-implementing\"}",{}]}]}]},"$undefined","$undefined",true],"$L3",[[["$","link","0",{"rel":"stylesheet","href":"/_next/static/css/275839517c59c532.css","precedence":"next"}],["$","link","1",{"rel":"stylesheet","href":"/_next/static/css/bdb880d990e879b6.css","precedence":"next"}]],["$L4",null]]]] 5:HL["/_next/static/css/95c7fb627fba8423.css",{"as":"style"}] 6:HL["/_next/static/css/477df780fc5cb593.css",{"as":"style"}] 7:HL["/_next/static/css/c40a92e7f996f910.css",{"as":"style"}] 3:["$L8",null] 4:[["$","meta","0",{"charSet":"utf-8"}],["$","title","1",{"children":"SM3 哈希密码算法实现"}],["$","meta","2",{"name":"description","content":"SM3 哈希密码算法实现"}],["$","link","3",{"rel":"manifest","href":"/manifest.json"}],["$","meta","4",{"name":"generator","content":"Hexo.js & Next.js"}],["$","meta","5",{"name":"viewport","content":"width=device-width, initial-scale=1"}],["$","meta","6",{"property":"og:title","content":"SM3 哈希密码算法实现"}],["$","meta","7",{"property":"og:description","content":"SM3 哈希密码算法实现"}],["$","meta","8",{"name":"twitter:card","content":"summary"}],["$","meta","9",{"name":"twitter:title","content":"SM3 哈希密码算法实现"}],["$","meta","10",{"name":"twitter:description","content":"SM3 哈希密码算法实现"}]] 9:I{"id":"7477","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","859:static/chunks/859-ea023633456a13f8.js","355:static/chunks/app/tags/[slug]/page-257dc97429efd72a.js"],"name":"","async":false} a:I{"id":"92","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","92:static/chunks/92-371a458fbe090447.js","284:static/chunks/284-b1d21b691d3eabee.js","605:static/chunks/app/post/[slug]/page-0339b76e369b6af8.js"],"name":"","async":false} b:I{"id":"2449","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","92:static/chunks/92-371a458fbe090447.js","185:static/chunks/app/layout-4eab34e1c4d9af8d.js"],"name":"","async":false} c:I{"id":"3211","chunks":["272:static/chunks/webpack-7471fa70de6bdb29.js","253:static/chunks/bce60fc1-2413e66000a5dd8f.js","769:static/chunks/769-2bf088c0a421e73d.js"],"name":"","async":false} d:I{"id":"5767","chunks":["272:static/chunks/webpack-7471fa70de6bdb29.js","253:static/chunks/bce60fc1-2413e66000a5dd8f.js","769:static/chunks/769-2bf088c0a421e73d.js"],"name":"","async":false} f:I{"id":"6424","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","92:static/chunks/92-371a458fbe090447.js","185:static/chunks/app/layout-4eab34e1c4d9af8d.js"],"name":"GaLite","async":false} 10:I{"id":"9869","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","92:static/chunks/92-371a458fbe090447.js","185:static/chunks/app/layout-4eab34e1c4d9af8d.js"],"name":"SpeedInsights","async":false} 11:I{"id":"7148","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","92:static/chunks/92-371a458fbe090447.js","185:static/chunks/app/layout-4eab34e1c4d9af8d.js"],"name":"Analytics","async":false} 8:["$","html",null,{"lang":"zh-CN","children":[["$","link",null,{"rel":"icon","href":"/images/icons/icon-72x72.png","type":"image/x-icon"}],["$","link",null,{"rel":"preconnect","href":"https://vip2.loli.io"}],["$","link",null,{"rel":"dns-prefetch","href":"https://vip2.loli.io"}],["$","link",null,{"rel":"alternate","type":"application/atom+xml","href":"/atom.xml"}],["$","body",null,{"children":["$","div",null,{"className":"kbCXHY jdraHW eqrBPF kEFtPS bNzOWQ juexza kXMrYr ","children":[["$","header",null,{"className":"doNOqr WhAZY cRUUAa cwMEsi dpJmjl bsTuZj iRietU JCsMI fONtwf eEsPgn gWUoqV kazZiE fsKTUV dkPCxO gdGTeM ","children":[["$","div",null,{"className":"doNOqr WhAZY hrtgtE iYRJzs iJGxaV jlwzhw ","children":[["$","$L9",null,{"className":"icyDkI gSBWlu foGVKH IVbXa kooHYa JxWnH cVJMrm hyoqRt jlijat kUpitc gdtkYW iDPWLw kayxZK hCkclF cneMsd gYPNzh ","href":"/","children":[["$","div",null,{"className":"eSltVp cpOcAb caItCN cyerGB dSxtaa lbEyiT kUPESX Pmecg ldtSOY ","children":["$","$La",null,{"src":"https://vip2.loli.io/2023/03/09/2tAMcy694lE3IZX.jpg","blurDataURL":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAIAAAACDbGyAAAACXBIWXMAAAsTAAALEwEAmpwYAAAAW0lEQVR4nAFQAK//AAAAAA0MCD08JoiyXkqWNQBPSDHtwYf/86ehuWNAeS4Aep9O+bt9/9aWxbtzETMSAClqHld9MqambcuqdgMOAwBCaS1Mdzd/hFE4PCMEEAS4ex049PWXOAAAAABJRU5ErkJggg==","alt":"avatar","width":200,"height":200,"layout":"responsive","className":"jWjrEQ eKtERL BRobm iovjFN ","placeholder":"blur","priority":true}]}],["$","h1",null,{"className":"evYdWj cpOcAb XEVlt huiurs ","children":"fengkx's Blog"}]]}],["$","h2",null,{"id":"name","className":"hrtgtE fcXWHl ","children":"fengkx"}],["$","h3",null,{"id":"title","className":"hrtgtE fcXWHl ","children":"Student & Coder"}],["$","div",null,{"className":"fONtwf fcXWHl foGVKH IVbXa dPVLzs fkrGAA cvCecb jJGIjV ","children":[["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","children":["$undefined",[["$","path","0",{"d":"M21 10c0 7-9 13-9 13s-9-6-9-13a9 9 0 0 1 18 0z","children":"$undefined"}],["$","circle","1",{"cx":"12","cy":"10","r":"3","children":"$undefined"}]]],"className":"$undefined","style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}],["$","span",null,{"className":"gUpJEt ","children":"Guangzhou, China"}]]}],["$","nav",null,{"className":"hrtgtE jlwzhw gSBWlu IVbXa kKRHCo jzaqKj ehqwGF ","children":[["$","div",null,{"className":"kooHYa ","children":["$","$L9",null,{"className":"gSBWlu foGVKH fPWmiY JxWnH cVJMrm OqOoD jJbtJp ihIJmy bgUfpT AsNjI kwISoH gdPTUr eLDTYY dmKgnC dPFrWx bmQfsF krqYva kXurrt ","href":"/","children":[["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","className":"jJhMtm fcXWHl gdPTUr dCiVRS TTRIX ","children":["$undefined",[["$","path","0",{"d":"M3 9l9-7 9 7v11a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z","children":"$undefined"}],["$","polyline","1",{"points":"9 22 9 12 15 12 15 22","children":"$undefined"}]]],"style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}],["$","span",null,{"className":"","children":"首页"}]]}]}],["$","div",null,{"className":"kooHYa ","children":["$","$L9",null,{"className":"gSBWlu foGVKH fPWmiY JxWnH cVJMrm OqOoD jJbtJp ihIJmy bgUfpT AsNjI kwISoH gdPTUr eLDTYY dmKgnC dPFrWx bmQfsF krqYva kXurrt ","href":"/archives","children":[["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","className":"jJhMtm fcXWHl gdPTUr dCiVRS TTRIX ","children":["$undefined",[["$","polyline","0",{"points":"21 8 21 21 3 21 3 8","children":"$undefined"}],["$","rect","1",{"x":"1","y":"3","width":"22","height":"5","children":"$undefined"}],["$","line","2",{"x1":"10","y1":"12","x2":"14","y2":"12","children":"$undefined"}]]],"style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}],["$","span",null,{"className":"","children":"归档"}]]}]}],["$","div",null,{"className":"kooHYa ","children":["$","$L9",null,{"className":"gSBWlu foGVKH fPWmiY JxWnH cVJMrm OqOoD jJbtJp ihIJmy bgUfpT AsNjI kwISoH gdPTUr eLDTYY dmKgnC dPFrWx bmQfsF krqYva kXurrt ","href":"/tags","children":[["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","className":"jJhMtm fcXWHl gdPTUr dCiVRS TTRIX ","children":["$undefined",[["$","path","0",{"d":"M20.59 13.41l-7.17 7.17a2 2 0 0 1-2.83 0L2 12V2h10l8.59 8.59a2 2 0 0 1 0 2.82z","children":"$undefined"}],["$","line","1",{"x1":"7","y1":"7","x2":"7.01","y2":"7","children":"$undefined"}]]],"style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}],["$","span",null,{"className":"","children":"标签"}]]}]}],["$","div",null,{"className":"kooHYa ","children":["$","$L9",null,{"className":"gSBWlu foGVKH fPWmiY JxWnH cVJMrm OqOoD jJbtJp ihIJmy bgUfpT AsNjI kwISoH gdPTUr eLDTYY dmKgnC dPFrWx bmQfsF krqYva kXurrt ","href":"/links","children":[["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","className":"jJhMtm fcXWHl gdPTUr dCiVRS TTRIX ","children":["$undefined",[["$","path","0",{"d":"M17 21v-2a4 4 0 0 0-4-4H5a4 4 0 0 0-4 4v2","children":"$undefined"}],["$","circle","1",{"cx":"9","cy":"7","r":"4","children":"$undefined"}],["$","path","2",{"d":"M23 21v-2a4 4 0 0 0-3-3.87","children":"$undefined"}],["$","path","3",{"d":"M16 3.13a4 4 0 0 1 0 7.75","children":"$undefined"}]]],"style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}],["$","span",null,{"className":"","children":"友链"}]]}]}],["$","div",null,{"className":"kooHYa ","children":["$","$L9",null,{"className":"gSBWlu foGVKH fPWmiY JxWnH cVJMrm OqOoD jJbtJp ihIJmy bgUfpT AsNjI kwISoH gdPTUr eLDTYY dmKgnC dPFrWx bmQfsF krqYva kXurrt ","href":"/about","children":[["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","className":"jJhMtm fcXWHl gdPTUr dCiVRS TTRIX ","children":["$undefined",[["$","path","0",{"d":"M18 8h1a4 4 0 0 1 0 8h-1","children":"$undefined"}],["$","path","1",{"d":"M2 8h16v9a4 4 0 0 1-4 4H6a4 4 0 0 1-4-4V8z","children":"$undefined"}],["$","line","2",{"x1":"6","y1":"1","x2":"6","y2":"4","children":"$undefined"}],["$","line","3",{"x1":"10","y1":"1","x2":"10","y2":"4","children":"$undefined"}],["$","line","4",{"x1":"14","y1":"1","x2":"14","y2":"4","children":"$undefined"}]]],"style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}],["$","span",null,{"className":"","children":"关于"}]]}]}],["$","div",null,{"className":"kooHYa ","children":["$","$L9",null,{"className":"gSBWlu foGVKH fPWmiY JxWnH cVJMrm OqOoD jJbtJp ihIJmy bgUfpT AsNjI kwISoH gdPTUr eLDTYY dmKgnC dPFrWx bmQfsF krqYva kXurrt ","href":"/search","children":[["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","className":"cpOcAb gdPTUr dCiVRS TTRIX ","children":["$undefined",[["$","circle","0",{"cx":"11","cy":"11","r":"8","children":"$undefined"}],["$","line","1",{"x1":"21","y1":"21","x2":"16.65","y2":"16.65","children":"$undefined"}]]],"style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}],["$","span",null,{"className":"jJhMtm fcXWHl ","children":"搜索"}]]}]}],["$","div",null,{"className":"kooHYa evYdWj ","children":["$","$L9",null,{"className":"gSBWlu foGVKH fPWmiY JxWnH cVJMrm OqOoD jJbtJp ihIJmy bgUfpT AsNjI kwISoH gdPTUr eLDTYY dmKgnC dPFrWx bmQfsF krqYva kXurrt ","href":"/atom.xml","prefetch":false,"children":[["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","className":"cpOcAb gdPTUr dCiVRS TTRIX ","children":["$undefined",[["$","path","0",{"d":"M4 11a9 9 0 0 1 9 9","children":"$undefined"}],["$","path","1",{"d":"M4 4a16 16 0 0 1 16 16","children":"$undefined"}],["$","circle","2",{"cx":"5","cy":"19","r":"1","children":"$undefined"}]]],"style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}],["$","span",null,{"className":"jJhMtm fcXWHl ","children":"RSS"}]]}]}]]}]]}],["$","div",null,{"className":"doNOqr hrtgtE fcXWHl iigETV bMSzLf XEVlt jmezSN izetJs kdrTtD bLIxaN ","children":[["$","div",null,{"className":"iLYBKc gSBWlu zEGrF evYWGf hDdCaA ","children":[["$","$L9",null,{"title":"fengkx's GitHub","href":"https://github.com/fengkx","prefetch":false,"children":["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","children":["$undefined",[["$","path","0",{"d":"M9 19c-5 1.5-5-2.5-7-3m14 6v-3.87a3.37 3.37 0 0 0-.94-2.61c3.14-.35 6.44-1.54 6.44-7A5.44 5.44 0 0 0 20 4.77 5.07 5.07 0 0 0 19.91 1S18.73.65 16 2.48a13.38 13.38 0 0 0-7 0C6.27.65 5.09 1 5.09 1A5.07 5.07 0 0 0 5 4.77a5.44 5.44 0 0 0-1.5 3.78c0 5.42 3.3 6.61 6.44 7A3.37 3.37 0 0 0 9 18.13V22","children":"$undefined"}]]],"className":"$undefined","style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}]}],["$","$L9",null,{"title":"fengkx's Telegram","href":"https://t.me/fengkx","prefetch":false,"children":["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","children":["$undefined",[["$","line","0",{"x1":"22","y1":"2","x2":"11","y2":"13","children":"$undefined"}],["$","polygon","1",{"points":"22 2 15 22 11 13 2 9 22 2","children":"$undefined"}]]],"className":"$undefined","style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}]}],["$","$L9",null,{"href":"https://mstdn.social/@fengkx","rel":"me","prefetch":false,"children":["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","children":["$undefined",[["$","path","0",{"stroke":"none","d":"M0 0h24v24H0z","fill":"none","children":"$undefined"}],["$","path","1",{"d":"M18.648 15.254c-1.816 1.763 -6.648 1.626 -6.648 1.626a18.262 18.262 0 0 1 -3.288 -.256c1.127 1.985 4.12 2.81 8.982 2.475c-1.945 2.013 -13.598 5.257 -13.668 -7.636l-.026 -1.154c0 -3.036 .023 -4.115 1.352 -5.633c1.671 -1.91 6.648 -1.666 6.648 -1.666s4.977 -.243 6.648 1.667c1.329 1.518 1.352 2.597 1.352 5.633s-.456 4.074 -1.352 4.944z","children":"$undefined"}],["$","path","2",{"d":"M12 11.204v-2.926c0 -1.258 -.895 -2.278 -2 -2.278s-2 1.02 -2 2.278v4.722m4 -4.722c0 -1.258 .895 -2.278 2 -2.278s2 1.02 2 2.278v4.722","children":"$undefined"}]]],"className":"$undefined","style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}]}],["$","$L9",null,{"title":"RSS feed","href":"/atom.xml","prefetch":false,"children":["$","svg",null,{"stroke":"currentColor","fill":"none","strokeWidth":"2","viewBox":"0 0 24 24","strokeLinecap":"round","strokeLinejoin":"round","children":["$undefined",[["$","path","0",{"d":"M4 11a9 9 0 0 1 9 9","children":"$undefined"}],["$","path","1",{"d":"M4 4a16 16 0 0 1 16 16","children":"$undefined"}],["$","circle","2",{"cx":"5","cy":"19","r":"1","children":"$undefined"}]]],"className":"$undefined","style":{"color":"$undefined"},"height":"1em","width":"1em","xmlns":"http://www.w3.org/2000/svg"}]}]]}],["$","div",null,{"className":"hrtgtE fcXWHl cyerGB kKRHCo ","children":["Build with ",["$","$L9",null,{"title":"Hexo official site","rel":"noopener noreferrer external nofollow","href":"https://hexo.io","children":"Hexo"}]," ","and"," ",["$","$L9",null,{"title":"Next.js official site","href":"https://nextjs.org","rel":"noopener noreferrer external nofollow","children":"Next.js"}]]}]]}]]}],["$","$Lb",null,{"children":["$","$Lc",null,{"parallelRouterKey":"children","segmentPath":["children"],"error":"$undefined","errorStyles":"$undefined","loading":"$undefined","loadingStyles":"$undefined","hasLoading":false,"template":["$","$Ld",null,{}],"templateStyles":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined","childProp":{"current":["$","$Lc",null,{"parallelRouterKey":"children","segmentPath":["children","post","children"],"error":"$undefined","errorStyles":"$undefined","loading":"$undefined","loadingStyles":"$undefined","hasLoading":false,"template":["$","$Ld",null,{}],"templateStyles":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined","childProp":{"current":["$","$Lc",null,{"parallelRouterKey":"children","segmentPath":["children","post","children",["slug","sm3-implementing","d"],"children"],"error":"$undefined","errorStyles":"$undefined","loading":"$undefined","loadingStyles":"$undefined","hasLoading":false,"template":["$","$Ld",null,{}],"templateStyles":"$undefined","notFound":"$undefined","notFoundStyles":"$undefined","childProp":{"current":["$Le",null],"segment":"__PAGE__?{\"slug\":\"sm3-implementing\"}"},"styles":[["$","link","0",{"rel":"stylesheet","href":"/_next/static/css/275839517c59c532.css","precedence":"next"}],["$","link","1",{"rel":"stylesheet","href":"/_next/static/css/95c7fb627fba8423.css","precedence":"next"}],["$","link","2",{"rel":"stylesheet","href":"/_next/static/css/477df780fc5cb593.css","precedence":"next"}],["$","link","3",{"rel":"stylesheet","href":"/_next/static/css/c40a92e7f996f910.css","precedence":"next"}]]}],"segment":["slug","sm3-implementing","d"]},"styles":[]}],"segment":"post"},"styles":[]}]}],["$","$Lf",null,{"uaId":"UA-103237573-1"}],["$","$L10",null,{}],["$","$L11",null,{}]]}]}]]}] 13:I{"id":"5307","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","92:static/chunks/92-371a458fbe090447.js","284:static/chunks/284-b1d21b691d3eabee.js","605:static/chunks/app/post/[slug]/page-0339b76e369b6af8.js"],"name":"TocTitle","async":false} e:[["$","link",null,{"rel":"stylesheet","href":"https://cdn.jsdelivr.net/npm/katex@0.16.9/dist/katex.min.css"}],["$","main",null,{"className":"prose eUUCKp kTeytq jmezSN cjScYX eqrBPF jdraHW cRUUAa DOWJl hgvoZN iZwowi jGHqUK kwISoH AsNjI","children":[["$","h1",null,{"className":"EKhXX ","children":"SM3 哈希密码算法实现"}],"$L12"]}],["$","aside",null,{"className":"cwMEsi dpJmjl gWUoqV kazZiE fsKTUV dkPCxO fcXWHl hrtgtE icKiSN eeREmo fZMRmg hRjOno ","children":["$","div",null,{"className":"doNOqr gepZXl AsideContainer_asideContainer___FNWl","children":["$","div",null,{"className":"bKqOie lkcNSa doNOqr dNtEOi ","children":[["$","div",null,{"className":"hlBtvm ckBWJI XEVlt ","children":"文章目录"}],["$","div",null,{"className":"$undefined","children":["$","ol",null,{"className":"jOeduE ","children":[["$","li",null,{"children":[["$","$L13",null,{"id":"SM3-Hash","text":"SM3 Hash"}],false]}],["$","li",null,{"children":[["$","$L13",null,{"id":"Hash-通用结构","text":"Hash 通用结构"}],false]}],["$","li",null,{"children":[["$","$L13",null,{"id":"SM3-实现","text":"SM3 实现"}],false]}],["$","li",null,{"children":[["$","$L13",null,{"id":"具体步骤","text":"具体步骤"}],["$","ol",null,{"className":"jOeduE iDuqPI ","children":[["$","li",null,{"children":[["$","$L13",null,{"id":"padding","text":"padding"}],false]}]]}]]}],["$","li",null,{"children":[["$","$L13",null,{"id":"拓展消息","text":"拓展消息"}],false]}],["$","li",null,{"children":[["$","$L13",null,{"id":"CF-压缩函数","text":"CF 压缩函数"}],false]}],["$","li",null,{"children":[["$","$L13",null,{"id":"注意的点","text":"注意的点"}],["$","ol",null,{"className":"jOeduE iDuqPI ","children":[["$","li",null,{"children":[["$","$L13",null,{"id":"大小端判断和转换","text":"大小端判断和转换"}],false]}]]}]]}],["$","li",null,{"children":[["$","$L13",null,{"id":"循环移位","text":"循环移位"}],false]}],["$","li",null,{"children":[["$","$L13",null,{"id":"用移位代替除法","text":"用移位代替除法"}],false]}],["$","li",null,{"children":[["$","$L13",null,{"id":"体会","text":"体会"}],false]}],["$","li",null,{"children":[["$","$L13",null,{"id":"参考文章","text":"参考文章"}],false]}]]}]}]]}]}]}]] 14:I{"id":"4998","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","92:static/chunks/92-371a458fbe090447.js","284:static/chunks/284-b1d21b691d3eabee.js","605:static/chunks/app/post/[slug]/page-0339b76e369b6af8.js"],"name":"ArticleContentClient","async":false} 16:I{"id":"7974","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","92:static/chunks/92-371a458fbe090447.js","284:static/chunks/284-b1d21b691d3eabee.js","605:static/chunks/app/post/[slug]/page-0339b76e369b6af8.js"],"name":"H1","async":false} 1a:I{"id":"7974","chunks":["194:static/chunks/194-26e3c21be498c0ce.js","92:static/chunks/92-371a458fbe090447.js","284:static/chunks/284-b1d21b691d3eabee.js","605:static/chunks/app/post/[slug]/page-0339b76e369b6af8.js"],"name":"H2","async":false} 12:["$","$L14",null,{"permalink":"https://www.fengkx.top/post/sm3-implementing/","dateString":"2019-11-06","comments":true,"aplayer":false,"showCopyright":true,"children":[["$","p","5441",{"children":["这学期欧气爆棚,有幸在第一轮选到了密码学研学项目的非正式课程。第一个要学习的算法是","$L15"]}],"\n",["$","$L16","5442",{"id":"SM3-Hash","children":["SM3 Hash"]}],"\n",["$","p","5444",{"children":["SM3 是一个","$L17","而不是加密。哈希是将一个任意长的输入映射到一个固定长的输出的函数。在 SM3 中输出为 256bit 长度。它的特点就是具有单向性,并且同样的输入总是映射到同样的输出。单向性从输入能轻松求出输出。但是却很难从输出反推输入。这样的性质让 Hash 有了它的应用。比如说网站后台的密码存储通常不会存储明文而是存储密码的哈希值。在需要验证密码的时候只需要计算并比对哈希值。而比特币的工作量证明也是通过不断尝试 nonce 反推哈希来实现的。"]}],"\n",["$","$L16","5445",{"id":"Hash-通用结构","children":["Hash 通用结构"]}],"\n",["$","p","5447",{"children":["哈希算法总是有","$L18"]}],"\n",["$","ol","5604",{"children":["\n",["$","li","5448",{"children":["将输入 padding 直到恰好可以分组"]}],"\n",["$","li","5503",{"children":["将输入分成 n 组 ",["$","span","5502",{"className":"katex","children":[["$","span","5463",{"className":"katex-mathml","children":[["$","math","5462",{"xmlns":"http://www.w3.org/1998/Math/MathML","children":[["$","semantics","5461",{"children":[["$","mrow","5459",{"children":[["$","msub","5451",{"children":[["$","mi","5449",{"children":["B"]}],["$","mn","5450",{"children":["0"]}]]}],["$","mo","5452",{"children":["…"]}],["$","msub","5458",{"children":[["$","mi","5453",{"children":["B"]}],["$","mrow","5457",{"children":[["$","mi","5454",{"children":["n"]}],["$","mo","5455",{"children":["−"]}],["$","mn","5456",{"children":["1"]}]]}]]}]]}],["$","annotation","5460",{"encoding":"application/x-tex","children":["B_{0} \\ldots B_{n-1}"]}]]}]]}]]}],["$","span","5501",{"className":"katex-html","aria-hidden":"true","children":[["$","span","5500",{"className":"base","children":[["$","span","5464",{"className":"strut","style":{"height":"0.891661em","verticalAlign":"-0.208331em"},"children":[]}],["$","span","5479",{"className":"mord","children":[["$","span","5465",{"className":"mord mathnormal","style":{"marginRight":"0.05017em"},"children":["B"]}],["$","span","5478",{"className":"msupsub","children":[["$","span","5477",{"className":"vlist-t vlist-t2","children":[["$","span","5473",{"className":"vlist-r","children":[["$","span","5471",{"className":"vlist","style":{"height":"0.30110799999999993em"},"children":[["$","span","5470",{"style":{"top":"-2.5500000000000003em","marginLeft":"-0.05017em","marginRight":"0.05em"},"children":[["$","span","5466",{"className":"pstrut","style":{"height":"2.7em"},"children":[]}],["$","span","5469",{"className":"sizing reset-size6 size3 mtight","children":[["$","span","5468",{"className":"mord mtight","children":[["$","span","5467",{"className":"mord mtight","children":["0"]}]]}]]}]]}]]}],["$","span","5472",{"className":"vlist-s","children":["​"]}]]}],["$","span","5476",{"className":"vlist-r","children":[["$","span","5475",{"className":"vlist","style":{"height":"0.15em"},"children":[["$","span","5474",{"children":[]}]]}]]}]]}]]}]]}],["$","span","5480",{"className":"mspace","style":{"marginRight":"0.16666666666666666em"},"children":[]}],["$","span","5481",{"className":"minner","children":["…"]}],["$","span","5482",{"className":"mspace","style":{"marginRight":"0.16666666666666666em"},"children":[]}],["$","span","5499",{"className":"mord","children":[["$","span","5483",{"className":"mord mathnormal","style":{"marginRight":"0.05017em"},"children":["B"]}],["$","span","5498",{"className":"msupsub","children":[["$","span","5497",{"className":"vlist-t vlist-t2","children":[["$","span","5493",{"className":"vlist-r","children":[["$","span","5491",{"className":"vlist","style":{"height":"0.301108em"},"children":[["$","span","5490",{"style":{"top":"-2.5500000000000003em","marginLeft":"-0.05017em","marginRight":"0.05em"},"children":[["$","span","5484",{"className":"pstrut","style":{"height":"2.7em"},"children":[]}],["$","span","5489",{"className":"sizing reset-size6 size3 mtight","children":[["$","span","5488",{"className":"mord mtight","children":[["$","span","5485",{"className":"mord mathnormal mtight","children":["n"]}],["$","span","5486",{"className":"mbin mtight","children":["−"]}],["$","span","5487",{"className":"mord mtight","children":["1"]}]]}]]}]]}]]}],["$","span","5492",{"className":"vlist-s","children":["​"]}]]}],["$","span","5496",{"className":"vlist-r","children":[["$","span","5495",{"className":"vlist","style":{"height":"0.208331em"},"children":[["$","span","5494",{"children":[]}]]}]]}]]}]]}]]}]]}]]}]]}]]}],"\n",["$","li","5504",{"children":["对初始 iv 置数"]}],"\n",["$","li","5602",{"children":["迭代压缩函数 ",["$","span","5601",{"className":"katex","children":[["$","span","5533",{"className":"katex-mathml","children":[["$","math","5532",{"xmlns":"http://www.w3.org/1998/Math/MathML","children":[["$","semantics","5531",{"children":[["$","mrow","5529",{"children":[["$","mi","5505",{"children":["I"]}],["$","msub","5508",{"children":[["$","mi","5506",{"children":["V"]}],["$","mi","5507",{"children":["n"]}]]}],["$","mo","5509",{"children":["="]}],["$","mi","5510",{"children":["C"]}],["$","mi","5511",{"children":["F"]}],["$","mrow","5528",{"children":[["$","mo","5512",{"fence":"true","children":["("]}],["$","mi","5513",{"children":["I"]}],["$","msub","5519",{"children":[["$","mi","5514",{"children":["V"]}],["$","mrow","5518",{"children":[["$","mi","5515",{"children":["n"]}],["$","mo","5516",{"children":["−"]}],["$","mn","5517",{"children":["1"]}]]}]]}],["$","mo","5520",{"separator":"true","children":[","]}],["$","msub","5526",{"children":[["$","mi","5521",{"children":["B"]}],["$","mrow","5525",{"children":[["$","mi","5522",{"children":["n"]}],["$","mo","5523",{"children":["−"]}],["$","mn","5524",{"children":["1"]}]]}]]}],["$","mo","5527",{"fence":"true","children":[")"]}]]}]]}],["$","annotation","5530",{"encoding":"application/x-tex","children":["IV_{n}=CF \\left( IV_{n-1},B_{n-1} \\right)"]}]]}]]}]]}],["$","span","5600",{"className":"katex-html","aria-hidden":"true","children":[["$","span","5554",{"className":"base","children":[["$","span","5534",{"className":"strut","style":{"height":"0.83333em","verticalAlign":"-0.15em"},"children":[]}],["$","span","5535",{"className":"mord mathnormal","style":{"marginRight":"0.07847em"},"children":["I"]}],["$","span","5550",{"className":"mord","children":[["$","span","5536",{"className":"mord mathnormal","style":{"marginRight":"0.22222em"},"children":["V"]}],["$","span","5549",{"className":"msupsub","children":[["$","span","5548",{"className":"vlist-t vlist-t2","children":[["$","span","5544",{"className":"vlist-r","children":[["$","span","5542",{"className":"vlist","style":{"height":"0.151392em"},"children":[["$","span","5541",{"style":{"top":"-2.5500000000000003em","marginLeft":"-0.22222em","marginRight":"0.05em"},"children":[["$","span","5537",{"className":"pstrut","style":{"height":"2.7em"},"children":[]}],["$","span","5540",{"className":"sizing reset-size6 size3 mtight","children":[["$","span","5539",{"className":"mord mtight","children":[["$","span","5538",{"className":"mord mathnormal mtight","children":["n"]}]]}]]}]]}]]}],["$","span","5543",{"className":"vlist-s","children":["​"]}]]}],["$","span","5547",{"className":"vlist-r","children":[["$","span","5546",{"className":"vlist","style":{"height":"0.15em"},"children":[["$","span","5545",{"children":[]}]]}]]}]]}]]}]]}],["$","span","5551",{"className":"mspace","style":{"marginRight":"0.2777777777777778em"},"children":[]}],["$","span","5552",{"className":"mrel","children":["="]}],["$","span","5553",{"className":"mspace","style":{"marginRight":"0.2777777777777778em"},"children":[]}]]}],["$","span","5599",{"className":"base","children":[["$","span","5555",{"className":"strut","style":{"height":"1em","verticalAlign":"-0.25em"},"children":[]}],["$","span","5556",{"className":"mord mathnormal","style":{"marginRight":"0.07153em"},"children":["C"]}],["$","span","5557",{"className":"mord mathnormal","style":{"marginRight":"0.13889em"},"children":["F"]}],["$","span","5558",{"className":"mspace","style":{"marginRight":"0.16666666666666666em"},"children":[]}],["$","span","5598",{"className":"minner","children":[["$","span","5559",{"className":"mopen delimcenter","style":{"top":"0em"},"children":["("]}],["$","span","5560",{"className":"mord mathnormal","style":{"marginRight":"0.07847em"},"children":["I"]}],["$","span","5577",{"className":"mord","children":[["$","span","5561",{"className":"mord mathnormal","style":{"marginRight":"0.22222em"},"children":["V"]}],["$","span","5576",{"className":"msupsub","children":[["$","span","5575",{"className":"vlist-t vlist-t2","children":[["$","span","5571",{"className":"vlist-r","children":[["$","span","5569",{"className":"vlist","style":{"height":"0.301108em"},"children":[["$","span","5568",{"style":{"top":"-2.5500000000000003em","marginLeft":"-0.22222em","marginRight":"0.05em"},"children":[["$","span","5562",{"className":"pstrut","style":{"height":"2.7em"},"children":[]}],["$","span","5567",{"className":"sizing reset-size6 size3 mtight","children":[["$","span","5566",{"className":"mord mtight","children":[["$","span","5563",{"className":"mord mathnormal mtight","children":["n"]}],["$","span","5564",{"className":"mbin mtight","children":["−"]}],["$","span","5565",{"className":"mord mtight","children":["1"]}]]}]]}]]}]]}],["$","span","5570",{"className":"vlist-s","children":["​"]}]]}],["$","span","5574",{"className":"vlist-r","children":[["$","span","5573",{"className":"vlist","style":{"height":"0.208331em"},"children":[["$","span","5572",{"children":[]}]]}]]}]]}]]}]]}],["$","span","5578",{"className":"mpunct","children":[","]}],["$","span","5579",{"className":"mspace","style":{"marginRight":"0.16666666666666666em"},"children":[]}],["$","span","5596",{"className":"mord","children":[["$","span","5580",{"className":"mord mathnormal","style":{"marginRight":"0.05017em"},"children":["B"]}],["$","span","5595",{"className":"msupsub","children":[["$","span","5594",{"className":"vlist-t vlist-t2","children":[["$","span","5590",{"className":"vlist-r","children":[["$","span","5588",{"className":"vlist","style":{"height":"0.301108em"},"children":[["$","span","5587",{"style":{"top":"-2.5500000000000003em","marginLeft":"-0.05017em","marginRight":"0.05em"},"children":[["$","span","5581",{"className":"pstrut","style":{"height":"2.7em"},"children":[]}],["$","span","5586",{"className":"sizing reset-size6 size3 mtight","children":[["$","span","5585",{"className":"mord mtight","children":[["$","span","5582",{"className":"mord mathnormal mtight","children":["n"]}],["$","span","5583",{"className":"mbin mtight","children":["−"]}],["$","span","5584",{"className":"mord mtight","children":["1"]}]]}]]}]]}]]}],["$","span","5589",{"className":"vlist-s","children":["​"]}]]}],["$","span","5593",{"className":"vlist-r","children":[["$","span","5592",{"className":"vlist","style":{"height":"0.208331em"},"children":[["$","span","5591",{"children":[]}]]}]]}]]}]]}]]}],["$","span","5597",{"className":"mclose delimcenter","style":{"top":"0em"},"children":[")"]}]]}]]}]]}]]}]]}],"\n",["$","li","5603",{"children":["最后一个 IV 就是 Hash 值"]}],"\n"]}],"\n",["$","$L16","5605",{"id":"SM3-实现","children":["SM3 实现"]}],"\n",["$","p","5607",{"children":["按照文档和网上查到的资料,我也实现了一个 SM3。","$L19","。头文件如下。里面的几个函数分别对应其中的几个步骤。"]}],"\n",["$","pre","5730",{"className":"shiki github-light","style":{"backgroundColor":"#fff","color":"#24292e"},"tabindex":"0","children":[["$","code","5729",{"className":"language-c","children":[["$","span","5610",{"className":"line","children":[["$","span","5608",{"style":{"color":"#D73A49"},"children":["#ifndef"]}],["$","span","5609",{"style":{"color":"#6F42C1"},"children":[" _sm3_H_"]}]]}],"\n",["$","span","5613",{"className":"line","children":[["$","span","5611",{"style":{"color":"#D73A49"},"children":["#define"]}],["$","span","5612",{"style":{"color":"#6F42C1"},"children":[" _sm3_H_"]}]]}],"\n",["$","span","5614",{"className":"line","children":[]}],"\n",["$","span","5617",{"className":"line","children":[["$","span","5615",{"style":{"color":"#D73A49"},"children":["#include"]}],["$","span","5616",{"style":{"color":"#032F62"},"children":[" "]}]]}],"\n",["$","span","5618",{"className":"line","children":[]}],"\n",["$","span","5623",{"className":"line","children":[["$","span","5619",{"style":{"color":"#D73A49"},"children":["typedef"]}],["$","span","5620",{"style":{"color":"#D73A49"},"children":[" unsigned"]}],["$","span","5621",{"style":{"color":"#D73A49"},"children":[" char"]}],["$","span","5622",{"style":{"color":"#24292E"},"children":[" byte;"]}]]}],"\n",["$","span","5628",{"className":"line","children":[["$","span","5624",{"style":{"color":"#D73A49"},"children":["typedef"]}],["$","span","5625",{"style":{"color":"#D73A49"},"children":[" unsigned"]}],["$","span","5626",{"style":{"color":"#D73A49"},"children":[" int"]}],["$","span","5627",{"style":{"color":"#24292E"},"children":[" word;"]}]]}],"\n",["$","span","5629",{"className":"line","children":[]}],"\n",["$","span","5631",{"className":"line","children":[["$","span","5630",{"style":{"color":"#6A737D"},"children":["// padding"]}]]}],"\n",["$","span","5648",{"className":"line","children":[["$","span","5632",{"style":{"color":"#24292E"},"children":["byte "]}],["$","span","5633",{"style":{"color":"#D73A49"},"children":["*"]}],["$","span","5634",{"style":{"color":"#6F42C1"},"children":["padding"]}],["$","span","5635",{"style":{"color":"#24292E"},"children":["("]}],["$","span","5636",{"style":{"color":"#D73A49"},"children":["const"]}],["$","span","5637",{"style":{"color":"#24292E"},"children":[" byte "]}],["$","span","5638",{"style":{"color":"#D73A49"},"children":["*"]}],["$","span","5639",{"style":{"color":"#E36209"},"children":["src"]}],["$","span","5640",{"style":{"color":"#24292E"},"children":[", "]}],["$","span","5641",{"style":{"color":"#D73A49"},"children":["size_t"]}],["$","span","5642",{"style":{"color":"#E36209"},"children":[" src_len"]}],["$","span","5643",{"style":{"color":"#24292E"},"children":[", "]}],["$","span","5644",{"style":{"color":"#D73A49"},"children":["size_t"]}],["$","span","5645",{"style":{"color":"#D73A49"},"children":[" *"]}],["$","span","5646",{"style":{"color":"#E36209"},"children":["out_len"]}],["$","span","5647",{"style":{"color":"#24292E"},"children":[");"]}]]}],"\n",["$","span","5649",{"className":"line","children":[]}],"\n",["$","span","5651",{"className":"line","children":[["$","span","5650",{"style":{"color":"#6A737D"},"children":["// 生成拓展 Block CF 需要用到"]}]]}],"\n",["$","span","5664",{"className":"line","children":[["$","span","5652",{"style":{"color":"#24292E"},"children":["word "]}],["$","span","5653",{"style":{"color":"#D73A49"},"children":["*"]}],["$","span","5654",{"style":{"color":"#6F42C1"},"children":["expand_blk"]}],["$","span","5655",{"style":{"color":"#24292E"},"children":["("]}],["$","span","5656",{"style":{"color":"#D73A49"},"children":["const"]}],["$","span","5657",{"style":{"color":"#D73A49"},"children":[" char"]}],["$","span","5658",{"style":{"color":"#D73A49"},"children":[" *"]}],["$","span","5659",{"style":{"color":"#E36209"},"children":["block"]}],["$","span","5660",{"style":{"color":"#24292E"},"children":[", word "]}],["$","span","5661",{"style":{"color":"#D73A49"},"children":["**"]}],["$","span","5662",{"style":{"color":"#E36209"},"children":["W_p"]}],["$","span","5663",{"style":{"color":"#24292E"},"children":[");"]}]]}],"\n",["$","span","5665",{"className":"line","children":[]}],"\n",["$","span","5676",{"className":"line","children":[["$","span","5666",{"style":{"color":"#D73A49"},"children":["void"]}],["$","span","5667",{"style":{"color":"#6F42C1"},"children":[" reverse_by_byte"]}],["$","span","5668",{"style":{"color":"#24292E"},"children":["(byte "]}],["$","span","5669",{"style":{"color":"#D73A49"},"children":["*"]}],["$","span","5670",{"style":{"color":"#D73A49"},"children":[" const"]}],["$","span","5671",{"style":{"color":"#E36209"},"children":[" le"]}],["$","span","5672",{"style":{"color":"#24292E"},"children":[", "]}],["$","span","5673",{"style":{"color":"#D73A49"},"children":["size_t"]}],["$","span","5674",{"style":{"color":"#E36209"},"children":[" len"]}],["$","span","5675",{"style":{"color":"#24292E"},"children":[");"]}]]}],"\n",["$","span","5677",{"className":"line","children":[]}],"\n",["$","span","5679",{"className":"line","children":[["$","span","5678",{"style":{"color":"#6A737D"},"children":["// 初始化 IV"]}]]}],"\n",["$","span","5687",{"className":"line","children":[["$","span","5680",{"style":{"color":"#D73A49"},"children":["void"]}],["$","span","5681",{"style":{"color":"#6F42C1"},"children":[" iv_init"]}],["$","span","5682",{"style":{"color":"#24292E"},"children":["(word "]}],["$","span","5683",{"style":{"color":"#D73A49"},"children":["*"]}],["$","span","5684",{"style":{"color":"#D73A49"},"children":[" const"]}],["$","span","5685",{"style":{"color":"#E36209"},"children":[" ivs"]}],["$","span","5686",{"style":{"color":"#24292E"},"children":[");"]}]]}],"\n",["$","span","5688",{"className":"line","children":[]}],"\n",["$","span","5690",{"className":"line","children":[["$","span","5689",{"style":{"color":"#6A737D"},"children":["// CF"]}]]}],"\n",["$","span","5713",{"className":"line","children":[["$","span","5691",{"style":{"color":"#D73A49"},"children":["void"]}],["$","span","5692",{"style":{"color":"#6F42C1"},"children":[" CF"]}],["$","span","5693",{"style":{"color":"#24292E"},"children":["(word "]}],["$","span","5694",{"style":{"color":"#D73A49"},"children":["*"]}],["$","span","5695",{"style":{"color":"#D73A49"},"children":[" const"]}],["$","span","5696",{"style":{"color":"#E36209"},"children":[" iv"]}],["$","span","5697",{"style":{"color":"#24292E"},"children":[", byte"]}],["$","span","5698",{"style":{"color":"#D73A49"},"children":["*"]}],["$","span","5699",{"style":{"color":"#E36209"},"children":[" blk"]}],["$","span","5700",{"style":{"color":"#24292E"},"children":[", "]}],["$","span","5701",{"style":{"color":"#D73A49"},"children":["const"]}],["$","span","5702",{"style":{"color":"#24292E"},"children":[" word "]}],["$","span","5703",{"style":{"color":"#D73A49"},"children":["*"]}],["$","span","5704",{"style":{"color":"#D73A49"},"children":[" const"]}],["$","span","5705",{"style":{"color":"#E36209"},"children":[" W"]}],["$","span","5706",{"style":{"color":"#24292E"},"children":[", "]}],["$","span","5707",{"style":{"color":"#D73A49"},"children":["const"]}],["$","span","5708",{"style":{"color":"#24292E"},"children":[" word "]}],["$","span","5709",{"style":{"color":"#D73A49"},"children":["*"]}],["$","span","5710",{"style":{"color":"#D73A49"},"children":[" const"]}],["$","span","5711",{"style":{"color":"#E36209"},"children":[" W_p"]}],["$","span","5712",{"style":{"color":"#24292E"},"children":[");"]}]]}],"\n",["$","span","5714",{"className":"line","children":[]}],"\n",["$","span","5725",{"className":"line","children":[["$","span","5715",{"style":{"color":"#24292E"},"children":["byte "]}],["$","span","5716",{"style":{"color":"#D73A49"},"children":["*"]}],["$","span","5717",{"style":{"color":"#6F42C1"},"children":["sm3"]}],["$","span","5718",{"style":{"color":"#24292E"},"children":["("]}],["$","span","5719",{"style":{"color":"#D73A49"},"children":["const"]}],["$","span","5720",{"style":{"color":"#D73A49"},"children":[" char"]}],["$","span","5721",{"style":{"color":"#D73A49"},"children":[" *"]}],["$","span","5722",{"style":{"color":"#D73A49"},"children":[" const"]}],["$","span","5723",{"style":{"color":"#E36209"},"children":[" s"]}],["$","span","5724",{"style":{"color":"#24292E"},"children":[");"]}]]}],"\n",["$","span","5726",{"className":"line","children":[]}],"\n",["$","span","5728",{"className":"line","children":[["$","span","5727",{"style":{"color":"#D73A49"},"children":["#endif"]}]]}]]}]]}],"\n",["$","p","5732",{"children":["下面从依次分析这几个步骤",["$","br","5731",{}],"\n操作的层次或者说对象各有不同,主要分为 byte 和 word(根据文档中的定义是 4byte)"]}],"\n",["$","$L16","5733",{"id":"具体步骤","children":["具体步骤"]}],"\n",["$","$L1a","5734",{"id":"padding","children":["padding"]}],"\n",["$","p","5735",{"children":["padding 的操作对象是 byte,在这一层次上可以忽略大小端。因为对象是一个 byte"]}],"\n",["$","p","5736",{"children":["Padding 的规则在文档中写的很清楚。"]}],"\n",["$","blockquote","5738",{"children":["\n",["$","p","5737",{"children":["假设消息 m 的长度为 l 比特。首先将比特 “1” 添加到消息的末尾,再添加 k 个 “0”,k 是满 足 l + 1 + k ≡ 448mod512 的最小的非负整数。然后再添加一个 64 位比特串,该比特串是长度 l 的二进 制表示。填充后的消息 m′ 的比特长度为 512 的倍数。"]}],"\n"]}],"\n",["$","p","5740",{"children":["实现上我们首先需要算出最终输出的长度来分配内存。关键需要计算出填充的 0 的个数 k。k 可以通过",["$","code","5739",{"children":["(448 - ((l % 512) + 1) + 512) % 512"]}],"算出。加上 512 再模 512 可以避免得到负数的情况。然后只需要分配合适大小的内存置零并将 m 复制过去。这样我们填充 0 的部分和明文部分就算做好了。"]}],"\n",["$","p","5741",{"children":["然后还有两个步骤,明文后面的一位需要置 1,然后最后的 64 位需要置为明文长度的二进制表示。"]}],"\n",["$","p","5743",{"children":["明文后一 byte 可以通过 m [l] 得到,然后只需要对这一位跟 0x80 做位或运算就好了。",["$","br","5742",{}],"\n而最后的 64 位长度表示则有大小端的差别在小端机器上需要先转换为大端表示。"]}],"\n",["$","$L1a","5744",{"id":"拓展消息","children":["拓展消息"]}],"\n",["$","p","5745",{"children":["拓展消息这里就是按照文档套公式。在实现上由于操作对象变成了 word 需要注意的是大小端问题。因为牵涉到字的位移操作所以大小端尤为重要。在我这个实现中 padding 产生的 bytes 是按照大端排列的。所以需要先转成小端再计算。"]}],"\n",["$","$L1a","5746",{"id":"CF-压缩函数","children":["CF 压缩函数"]}],"\n",["$","p","5747",{"children":["CF 也是照着文档套公式实现。因为 + 是模 2^32 加法,所以我们应该选择 unsigned int 来作为 word 的具体数字类型。之后就没有什么特别需要注意了。"]}],"\n",["$","$L16","5748",{"id":"注意的点","children":["注意的点"]}],"\n",["$","$L1a","5749",{"id":"大小端判断和转换","children":["大小端判断和转换"]}],"\n",["$","p","5751",{"children":["大小端的判断参考了","$L1b","。通过在内存中分配一个 int 变量,通过强转它的指针为 char 判断低地址 byte 的值判断机器是大端还是小端。"]}],"\n",["$","p","5752",{"children":["例如"]}],"\n",["$","pre","5763",{"className":"shiki github-light","style":{"backgroundColor":"#fff","color":"#24292e"},"tabindex":"0","children":[["$","code","5762",{"className":"language-c","children":[["$","span","5761",{"className":"line","children":[["$","span","5753",{"style":{"color":"#D73A49"},"children":["static"]}],["$","span","5754",{"style":{"color":"#D73A49"},"children":[" const"]}],["$","span","5755",{"style":{"color":"#D73A49"},"children":[" int"]}],["$","span","5756",{"style":{"color":"#24292E"},"children":[" endianTest "]}],["$","span","5757",{"style":{"color":"#D73A49"},"children":["="]}],["$","span","5758",{"style":{"color":"#D73A49"},"children":[" 0x"]}],["$","span","5759",{"style":{"color":"#005CC5"},"children":["12345678"]}],["$","span","5760",{"style":{"color":"#24292E"},"children":[";"]}]]}]]}]]}],"\n",["$","p","5765",{"children":["大端中表示为 0x12 0x34 0x56 0x78",["$","br","5764",{}],"\n小端中表示为 0x78 0x56 0x34 0x12"]}],"\n",["$","p","5766",{"children":["转换也是通过强转指针为 char,参考以下代码"]}],"\n",["$","pre","5822",{"className":"shiki github-light","style":{"backgroundColor":"#fff","color":"#24292e"},"tabindex":"0","children":[["$","code","5821",{"className":"language-c","children":[["$","span","5777",{"className":"line","children":[["$","span","5767",{"style":{"color":"#D73A49"},"children":["void"]}],["$","span","5768",{"style":{"color":"#6F42C1"},"children":[" reverse_by_byte"]}],["$","span","5769",{"style":{"color":"#24292E"},"children":["(byte "]}],["$","span","5770",{"style":{"color":"#D73A49"},"children":["*"]}],["$","span","5771",{"style":{"color":"#D73A49"},"children":[" const"]}],["$","span","5772",{"style":{"color":"#E36209"},"children":[" le"]}],["$","span","5773",{"style":{"color":"#24292E"},"children":[", "]}],["$","span","5774",{"style":{"color":"#D73A49"},"children":["size_t"]}],["$","span","5775",{"style":{"color":"#E36209"},"children":[" len"]}],["$","span","5776",{"style":{"color":"#24292E"},"children":[") {"]}]]}],"\n",["$","span","5792",{"className":"line","children":[["$","span","5778",{"style":{"color":"#D73A49"},"children":["\tfor"]}],["$","span","5779",{"style":{"color":"#24292E"},"children":[" ("]}],["$","span","5780",{"style":{"color":"#D73A49"},"children":["size_t"]}],["$","span","5781",{"style":{"color":"#24292E"},"children":[" i"]}],["$","span","5782",{"style":{"color":"#D73A49"},"children":["="]}],["$","span","5783",{"style":{"color":"#005CC5"},"children":["0"]}],["$","span","5784",{"style":{"color":"#24292E"},"children":[";i"]}],["$","span","5785",{"style":{"color":"#D73A49"},"children":["<"]}],["$","span","5786",{"style":{"color":"#24292E"},"children":["len"]}],["$","span","5787",{"style":{"color":"#D73A49"},"children":[">>"]}],["$","span","5788",{"style":{"color":"#005CC5"},"children":["1"]}],["$","span","5789",{"style":{"color":"#24292E"},"children":[";i"]}],["$","span","5790",{"style":{"color":"#D73A49"},"children":["++"]}],["$","span","5791",{"style":{"color":"#24292E"},"children":[") {"]}]]}],"\n",["$","span","5797",{"className":"line","children":[["$","span","5793",{"style":{"color":"#24292E"},"children":["\t\tbyte tmp "]}],["$","span","5794",{"style":{"color":"#D73A49"},"children":["="]}],["$","span","5795",{"style":{"color":"#E36209"},"children":[" le"]}],["$","span","5796",{"style":{"color":"#24292E"},"children":["[i];"]}]]}],"\n",["$","span","5807",{"className":"line","children":[["$","span","5798",{"style":{"color":"#E36209"},"children":["\t\tle"]}],["$","span","5799",{"style":{"color":"#24292E"},"children":["[i] "]}],["$","span","5800",{"style":{"color":"#D73A49"},"children":["="]}],["$","span","5801",{"style":{"color":"#E36209"},"children":[" le"]}],["$","span","5802",{"style":{"color":"#24292E"},"children":["[len"]}],["$","span","5803",{"style":{"color":"#D73A49"},"children":["-"]}],["$","span","5804",{"style":{"color":"#005CC5"},"children":["1"]}],["$","span","5805",{"style":{"color":"#D73A49"},"children":["-"]}],["$","span","5806",{"style":{"color":"#24292E"},"children":["i];"]}]]}],"\n",["$","span","5816",{"className":"line","children":[["$","span","5808",{"style":{"color":"#E36209"},"children":["\t\tle"]}],["$","span","5809",{"style":{"color":"#24292E"},"children":["[len"]}],["$","span","5810",{"style":{"color":"#D73A49"},"children":["-"]}],["$","span","5811",{"style":{"color":"#005CC5"},"children":["1"]}],["$","span","5812",{"style":{"color":"#D73A49"},"children":["-"]}],["$","span","5813",{"style":{"color":"#24292E"},"children":["i]"]}],["$","span","5814",{"style":{"color":"#D73A49"},"children":["="]}],["$","span","5815",{"style":{"color":"#24292E"},"children":["tmp;"]}]]}],"\n",["$","span","5818",{"className":"line","children":[["$","span","5817",{"style":{"color":"#24292E"},"children":["\t}"]}]]}],"\n",["$","span","5820",{"className":"line","children":[["$","span","5819",{"style":{"color":"#24292E"},"children":["}"]}]]}]]}]]}],"\n",["$","$L1a","5823",{"id":"循环移位","children":["循环移位"]}],"\n",["$","pre","5842",{"className":"shiki github-light","style":{"backgroundColor":"#fff","color":"#24292e"},"tabindex":"0","children":[["$","code","5841",{"className":"language-c","children":[["$","span","5840",{"className":"line","children":[["$","span","5824",{"style":{"color":"#D73A49"},"children":["#define"]}],["$","span","5825",{"style":{"color":"#6F42C1"},"children":[" ls_w"]}],["$","span","5826",{"style":{"color":"#24292E"},"children":["("]}],["$","span","5827",{"style":{"color":"#E36209"},"children":["a"]}],["$","span","5828",{"style":{"color":"#24292E"},"children":[", "]}],["$","span","5829",{"style":{"color":"#E36209"},"children":["n"]}],["$","span","5830",{"style":{"color":"#24292E"},"children":[") (a "]}],["$","span","5831",{"style":{"color":"#D73A49"},"children":[">>"]}],["$","span","5832",{"style":{"color":"#24292E"},"children":[" ("]}],["$","span","5833",{"style":{"color":"#005CC5"},"children":["32"]}],["$","span","5834",{"style":{"color":"#D73A49"},"children":[" -"]}],["$","span","5835",{"style":{"color":"#24292E"},"children":[" n) "]}],["$","span","5836",{"style":{"color":"#D73A49"},"children":["|"]}],["$","span","5837",{"style":{"color":"#24292E"},"children":[" a "]}],["$","span","5838",{"style":{"color":"#D73A49"},"children":["<<"]}],["$","span","5839",{"style":{"color":"#24292E"},"children":[" n)"]}]]}]]}]]}],"\n",["$","p","5843",{"children":["先保留剩下的位再和要移过去的位或"]}],"\n",["$","$L1a","5844",{"id":"用移位代替除法","children":["用移位代替除法"]}],"\n",["$","p","5847",{"children":["为了效率我们可以使用右移代替除法。乘法","$L1c","。但是除法因为",["$","code","5846",{"children":["DIV"]}],"指令会将余数放到寄存器里面所以不能优化掉,可以用右移代替。"]}],"\n",["$","$L16","5848",{"id":"体会","children":["体会"]}],"\n",["$","p","5850",{"children":["算法的实现方面其实不多考虑效率单纯实现的话不难。比较需要注意的就是大小端的问题。C 语言可以直接操作内存所以还是比较舒服的。",["$","br","5849",{}],"\n至于算法的原理,为什么要那样设计就不知道了。这也应该是正式上课的时候应该注意的问题。"]}],"\n",["$","$L16","5851",{"id":"参考文章","children":["参考文章"]}],"\n",["$","ul","5860",{"children":["\n",["$","li","5853",{"children":["$L1d"]}],"\n",["$","li","5855",{"children":["$L1e"]}],"\n",["$","li","5857",{"children":["$L1f"]}],"\n",["$","li","5859",{"children":["$L20"]}],"\n"]}],"\n"]}] 15:["$","a",null,{"href":"http://www.sca.gov.cn/sca/xwdt/2010-12/17/content_1002389.shtml","children":["SM3"],"target":"_blank","rel":"noopener noreferrer external nofollow"}] 17:["$","a",null,{"href":"https://en.wikipedia.org/wiki/Cryptographic_hash_function","children":["哈希算法"],"target":"_blank","rel":"noopener noreferrer external nofollow"}] 18:["$","a",null,{"href":"https://wenku.baidu.com/view/0831e189680203d8ce2f24d3.html","children":["通用的结构"],"target":"_blank","rel":"noopener noreferrer external nofollow"}] 19:["$","a",null,{"href":"https://github.com/fengkx/sm3","children":["代码放在了 GitHub"],"target":"_blank","rel":"noopener noreferrer external nofollow"}] 1b:["$","a",null,{"href":"https://blog.csdn.net/a344288106/article/details/80094878","children":["大佬的博文"],"target":"_blank","rel":"noopener noreferrer external nofollow"}] 1c:["$","a",null,{"href":"https://github.com/0xffff-one/0xffff-lib/pull/2#discussion_r311075793","children":["一般都能被编译器优化掉"],"target":"_blank","rel":"noopener noreferrer external nofollow"}] 1d:["$","a",null,{"href":"https://github.com/fengkx/sm3/blob/master/SM3%E5%AF%86%E7%A0%81%E6%9D%82%E5%87%91%E7%AE%97%E6%B3%95.pdf","children":["SM3 文档"],"target":"_blank","rel":"noopener noreferrer external nofollow"}] 1e:["$","a",null,{"href":"https://blog.csdn.net/a344288106/article/details/80094878","children":["SM3 密码杂凑算法实现及说明 by 梁默鱼"],"target":"_blank","rel":"noopener noreferrer external nofollow"}] 1f:["$","a",null,{"href":"https://stackoverflow.com/questions/19068705/undefined-reference-when-calling-inline-function","children":["undefined reference when calling inline function"],"target":"_blank","rel":"noopener noreferrer external nofollow"}] 20:["$","a",null,{"href":"https://stackoverflow.com/questions/30552039/calculating-k-for-padding-of-sha-256-message","children":["Calculating k for padding of SHA-256 message"],"target":"_blank","rel":"noopener noreferrer external nofollow"}]