mirror of
https://github.com/shadps4-emu/ext-cryptopp.git
synced 2024-11-26 19:30:21 +00:00
Add additional SM3 test vectors
Cleanup SM3 whitespace
This commit is contained in:
parent
8c29b1a4d3
commit
5a577e71ac
@ -78,70 +78,70 @@ Plaintext: 5F9B108B715F047B7879E323B0D95C3B
|
||||
Ciphertext: 7B40084F82CAAA25821862F986ABD424
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.4 generated
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: F11235535318FA844A3CBE643169F59E
|
||||
Plaintext: A27EE076E48E6F389710EC7B5E8A3BE5
|
||||
Ciphertext: 94CFE3F59E8507FEC41DBE738CCD53E1
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.4 generated
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: 419A55A70C401DA6571654BC4AF1F6D7
|
||||
Plaintext: 9B6294AE9BE009C87CAEFCD842632A1D
|
||||
Ciphertext: 9868917B7329CE6F1E1FBA6E404D8F20
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.4 generated
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: EE1E457608D7704A99F76C73815CBFA8
|
||||
Plaintext: C89C30AD3B257CA7635052ED63B6D268
|
||||
Ciphertext: CE25779CA2A8EEFD7ADD059273E2A1FD
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.4 generated
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: 43D99B186BEAA4E2DE3159F77BF708FA
|
||||
Plaintext: 91CB86CA6B0FDF6671FF4AE4BF63AD6C
|
||||
Ciphertext: 3A6B1DF36C9CBFC327FF8B6C7318579C
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.4 generated
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: BBE5816E2B56084FCDEAB9B739CE899E
|
||||
Plaintext: B607BB382377F3B6D5FB740E3BF0E822
|
||||
Ciphertext: 4DCDC1708360A700130C3BD90C8F626F
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.4 generated
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: BF35FEE606E59D0E1E18BDA40180672C
|
||||
Plaintext: 6F217DAD31488A54A7F4482D1BE230BC
|
||||
Ciphertext: DE1AAEA076633B37B54AEF10B180661A
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.4 generated
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: D2B1CE2CFDB2306BE24F0364434F7734
|
||||
Plaintext: 7AB0E2CC96E55659E5078591F510B721
|
||||
Ciphertext: 052E420981D36C01A96A8302F71FB7A6
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.4 generated
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: 2DDD024A42B24A9652C8C52021024C33
|
||||
Plaintext: C9BD217786C00F420A88D6818B685A02
|
||||
Ciphertext: CE273E3523B443EB34C7B6A153FC9308
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.4 generated
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: 4A6453202EC4378492BFA3D6A685F6CD
|
||||
Plaintext: B9EDC63029F5FA1390918736590A3483
|
||||
Ciphertext: 2C7E67E24281BA3271E6FFF2D2B91B75
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.4 generated
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: 6FC86EFE73B3AF96014E490882A34825
|
||||
Plaintext: 13805831D15593BA3CF4553D4AEFDB71
|
||||
@ -230,3 +230,163 @@ IV: 4FD854D99894CFFC2C9A7C7F977E2766
|
||||
Plaintext: 62584CC7D1F9DB700C6AB2FF4B9DDF975CD4E8133AA9D7A1C5B077EFBB168A01
|
||||
Ciphertext: F2D73D32D40275E93B268B2256522E8AE54BEFD8F75B9356A40DBCE776C74CA6
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: 17F2C0B6780285E8C55CA80B16A8405E
|
||||
IV: 6568F64CC25C82A46AB2AA72A096DAB9
|
||||
Plaintext: E76C0998AB76A337D27A5D2A135D8FD85176919A6BA41E824C816B678969FBCE
|
||||
Ciphertext: 1A81371450233A524FD6AADDEB08C216594784117FF2EC7F6431E5BE5103C333
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: 14DAB62E532CF28FDAC99587970964D1
|
||||
IV: 71B9BBDA8A38161D7CB58176F4732552
|
||||
Plaintext: 79A23B2CB8D9232A6704692FAE27D70AB7D82F2989AE3A6F7B0F900D24C6BBEB
|
||||
Ciphertext: 2ABF06D2C75D73F09A011633CDCE97C114AF2006424402AF16FC75BB0943D8D6
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: 43F7D8DB753B659193086127F0B3E99E
|
||||
IV: D96AA0925B192F42262DDCA87EA5DAAC
|
||||
Plaintext: 233A2612AA0ABEF48BE82F2424A20554D50ED5739FD89685304059160249D610
|
||||
Ciphertext: C56D0A845FCCE64F3C2778643A296CA60209C1C6D1D0F45676455DCA50351A5C
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: 5258495BAA989D2FD0C41FE10A8389C4
|
||||
IV: D95DB7A120A826EDEFB97FF7B88A0FE0
|
||||
Plaintext: CE58464F58A584DB5D9D636DDCDB4EE3FD0B46715F5288AE98E2E2705A1EC91A
|
||||
Ciphertext: 83DA7D1263DAF274CD57BA4A8EB047E7C0C1BDA32096396FAB33AB6389833910
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: E03754933CD9BE7251E883A2D6E8B8A1
|
||||
IV: 696434CB293F4A5DD54E0F6227AFF878
|
||||
Plaintext: 3D9A5783E9995CB4684D27868A78C3D8E964DDC5FC172DD5997220D3F4328F8D
|
||||
Ciphertext: EA1159046E10E036D4FDF41BB195DE2F2E637B3B12B204762F5CD15D1EA4EAA4
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: FC0F1ADDDD28519198C5BFABA1213F5D
|
||||
IV: 36E76356F4BDABE32EA4E6493B8CAD5B
|
||||
Plaintext: 6FDA27301CCB4CA5E5CE709128137EC7C2C7D9A0D8D7300D7053972F9702115E
|
||||
Ciphertext: 15656DA7016540BF66109F35354622F1A91E6B93532C5EC4E71885E32C3617B6
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: ACA5A010B3125870BD782DEF8186796D
|
||||
IV: 5EA2BC81AAE4C2835E7E0AAFC1098632
|
||||
Plaintext: EFE7FE67775FFD17AF262091E73CF2D78E5F98DD9FE8D6681F328BB15BCA17C3
|
||||
Ciphertext: F356998B970837748589E5DF0979ADD16ECAE4DD592C85868B78B070AC8010EC
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: C91F04FFD8ADE4C142503A326A153658
|
||||
IV: 600F8BBCE6CF1E547CC8F32BCC6AF65C
|
||||
Plaintext: DF70A03C18D0584DB481711C46B4A36DFC584851D9F29F9C5761EF0AAC2BE260
|
||||
Ciphertext: A5CC5B7ABC9FCEA77AFB76DB886856D6059F450B35587998D02EECB3D6E90FD0
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: 313A78EC212B7D85E4DBBAA53AE5DA5D
|
||||
IV: 0F8A09F1A8157E095F0C4A4D2F7CBBDB
|
||||
Plaintext: B5A36428979C3180DFD76AD3C19EC992B9AA32AB60CE44DE285EA6C5D07F9CD9
|
||||
Ciphertext: 7A62C05B9303C28E4E30960B3CC6DF6115079EF6369DE59E5E7051A9F076C2B4
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: A44D63019D92AE9AEB9BAFECDA17EFAD
|
||||
IV: C82A1F870BCD7991FB07C693FE244DE1
|
||||
Plaintext: 3C46279234478D3BE2B86DA217C0095ACC419991EAE796F9A2A2D96708F0EEA0
|
||||
Ciphertext: AA8633949821711483E1496543F7AD8F4C27BCB71390EDF825E56C868EB77608
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: 26EA70B32E9C7E92A8AD09D2355B4813
|
||||
IV: 1EA558158DA6105D6C3529C0D9D071DF
|
||||
Plaintext: D7CD7EF080B5925988B3A8AB270B3595710BF368AD1CA7D67357B63A862E5B4F4D947ED680337198E51B7721D38B69599E14D327B8265EACD594195243B1A0A8F23A7BDB23F68E4F0E1DB03D4CE2A3F6DA45826E98519E30C942DC24F875B144244049777AC75D97BBCD70A13EC3D5BA93B39297B89A9DF9C753BA116F6E5FE1
|
||||
Ciphertext: 2D539F9328643980D87283E42D82D60ABE498F202DE91DEC7AB903583666DAEACA7B36759B237AA587E019DF6EFAA1998AB7F7711D5D88FA6DF90E090D55E0F8BA66E25D966EDAAC8C9256052C9173C797529F14A78A35A2EACFBC32341EDFA20AE35ADAE83ED19F1C81A159D6CA4AB1E0FD31042798E1FDE60C1191DCC9AA36
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: D5BF86802C110E14979C2B98D1A58D90
|
||||
IV: 67B3B48D7FB39548C74D147C81D7B06A
|
||||
Plaintext: B6F719F2B98B8554F69FA6BC3ECE960B1457B83E3CC37502A2FFBD22885E098622D6806B713D9B5C3FD335562E2379022073DB7EEC63710713B2DBF4D9CAD0227E5CD8BBA5B70933CA927A8F4BEB201C26DB5C6507223EB7510387D2D556F364F24F5F3627FE5A8FF534164F53EE1C5BA1335ABFD74466F9822C54CA689FC4AF
|
||||
Ciphertext: 5D60223B5011658EAA078A6470624841C8A53B400EC76517C83286A9A9E7E84CC10559176491425624D2B24264DC50927767560BCB65B7C4615E33E794DA4BAC7F9830F88567527B3B0ABCD8BAC410EDB1EFB71205B6FD976942FCF09468AD8FE2088096237C291095E98F62555C90E30B90CD7BFA518780B5154B18CDFAE6C5
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: 6A892BC55F7F80F114FBD0870B123F1B
|
||||
IV: BF2A2CBEB249805673774C2E8DBE01CA
|
||||
Plaintext: D9322E1D875A2008B61F145631CE5FDD64D6AC85604564147B7FFC06C3FA0C85A46A9678D5DB457265DDFD31C59CF52ED6173C94AC962F06C51A2C4A5AA3FE628155C06A0AFBF0C7305CE1756133E903833B9D1593EF55B6AA196AF1299087171A4517B11503A666E58E607D64931D445400BD4BB2FCB4BCE878D117E7B9AA1B
|
||||
Ciphertext: 6C84079A952561F8C733F2FB0ABE874DC04D70A8E1ECDE8BD026866F8790923B046AB51E711CD442FDB7C28CC773281E48F40178AA8F0BA5C43D56269664A54FF474BA78D9E763A1D806B489F62FF82C9D337735EC229935E18DA53E932469B081BFFFBC20089B8E62ED905D4FACF2054DC0F67D67116977AD4FF4AB80954C48
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: 5458876D02C39DB8458372E89CB3EF27
|
||||
IV: B09B187F7CCE25E94F534F06D8442796
|
||||
Plaintext: 751579F1BB15910733507A4CC04CF00EAEFC3577EAD165F77F2CDF037B445CA4390B56EDF0F3832889828B613A785CA924D3259AD7E664186D2C88C01615B637D0796246AEBBA584AA3746E10EEF436E73792CFEA40290260AE9BE1CABA919919F5AF3A2F7A2CE67912FD3464A564BF4D4374895F0CE6AB91851F35A1CB197B9
|
||||
Ciphertext: 7A97307CB8E9EACD703E6F9B518772AB2C7A0FA3F9FF61FBE8CE0896F10DA287E0CAE7C276EC9E6713A692908284EEA0420CAC3B35C6D43594605CA637C7520CB6B7759FBE7660167C4C08B337C4451B85890C3B354382C5721A555777474CDA0E0A82E623FEC9C0645CECD7A7FE7E5F499E71E49DB83A1540448FC1B84BC06C
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: BFD46DC9190FD1C167DFCA22E6CF201E
|
||||
IV: A661D3214BFD96AE23CC98E9A831A4FD
|
||||
Plaintext: 43EAB0941EFAA25550A3F267C7032BEF852132401C4799110D0A918285B40586A51D2F79015518F009F7430874D4030A96CC97F87FCEC7AFEA5C50FCB831B18CC628B6CBA5CF459C36103E985CEC386A401D468613330C1C765B79B5A424932EFAE70489CE7BF8DD640569D345440FEE6E17042B101D27A9B77669179B6E2321
|
||||
Ciphertext: 139BEF74260F84F7F186ECE92E48CBA371711961CFC0073DED8FFB3F67F2CD0B698F20D9E2C16CFB0AFAD13E303429BA63A7B52FA506E084FF62C53DED3E42E2E0FE1C08D086B445971AB31D019209ECF4D711EFBF0609E09998C65119CDEFA9E9AB8B7D49843C7145EFA6CFF3304B5CB81A4DFBF2464CC270484C5252060A7A
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: 7037C22E9E77FA9349E4F5D9B2BF5C31
|
||||
IV: 150DC7E4D6E23045AC3449091FA5F1FC
|
||||
Plaintext: C36788C3BB5E62B35A6AF89349EEB52040E0BFDAB576A53EFB24120A28413D092AB4739BD1652B6E48170EBDB51E7DC622C2EB35AA76692DA666D2B205A74B5E45F04B3FC90256717ED1B4115409630EE2B5D2D9D0BAF18A8782511B4717D80D24DB28EF328C5AEDBA2688A8F4AD2CA945290A2A4DB9C09A00A6512AF763FE9A
|
||||
Ciphertext: FBF0DF7DC49D0DA772082EAB62268C74FAC576CED62B0648404FCA9CC38E0C0DB41487BD3053702C514A46117CD03055F2C340DDA26ACB60AED77328B6A87E55D487CA67C23E39885DDD5E81AAACE95ED29E6071C14737885DC68D1CF771D7E75D8B7F7B37E6917B7548C3D93FA94B98BC02BB01FEE4125972B1243C8C9423F3
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: C15C1A33201001143C27C5EE4752FE40
|
||||
IV: F1DEF583CD269B9EAB03E43AEB68C892
|
||||
Plaintext: F174738D9194B561D2899567310395FA8E7138D2BD4659DDA06D89C192A0F438199F9D26671D23D1A17A612E773ABD74F8FD2EE80A9A032866CAB531E8F89A65181A7B6834126F5158CBEA91F698077C939006B1FC84DF6235E331F39CF32D412324BAF787A33E4D338F56B06BAAD8CC1279936F7E9FA5FE0FC68B65EC25C7A0
|
||||
Ciphertext: 872C38791713DDF693DA7393BA2BDC2C88FD86C7592E40B449BB172BC0B22C93A763241E0F3528136B9A765EFC011D7F97CC61E9FB1DF59D531A05F4F29B02A6F621E9A4EBB753838909EA51592190E2FEC47849C7DB63078B92045C75586EC38EA83506CFCCFF89AE0F90275C8C1CD304C1C7F85CCC6FAFC7A97A6867420BC4
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: 868C4D9F60BCCF5B773DA75BE9257683
|
||||
IV: 618B1C16A2F77C40D0376805A3FAB180
|
||||
Plaintext: E065F5957CB5161FA1A131C6097247D07649E4D930457114B10A987E9A99AC9F23D83C1459F388AE839A96B8E0E4DFBA81025664D700A31EB8BC4C16C02D24CC1B8F94124427D082106BEF7942D24984841B6DA96F3955B6846BE070218907F9350E40ACE2A7EF68536F7FC5B6A9514158E25774F01D70F2858DBD88BFB891C8
|
||||
Ciphertext: D1BF41AA65980104BAB813102FB68A18EC6343F1D1407CECE0A813EF396FF542F38E2EB976535FBCFD5A849FAF3B96834AA3F6F3C9ABD885BD4F74EA6C21901266662A6F5D9139E3B2BE767AE696897BA7F5C9A2EDD14E3A9EA478AFD5794D94600D37C08BF617600248BB1BBBF6BEF0C2EFFC6ED0F0285BBDA2A5FF8D298B62
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: B5C240C4F428FC89F7773E966A98AC07
|
||||
IV: 1343DC2468A27A1DCFBA19E4A2AB0743
|
||||
Plaintext: 8DE067EC9FF28BDBBF2B5FAF1D6A753E462E2081A680EEBCB01BEC0A06AD7D21BACD5F03EF229B65C8FFBF9F05B3C6258662EEABD145CFE502462C0712E4B1D7975ADD864041FA0A77E31969F4FFD1F855C928007DE2BC8888DCFE00E85644C21D27E784C013667DDC2023B0AB0A80742FDA3252E6C23F0892AEF0D6F97616B0
|
||||
Ciphertext: DBDA73BFB3D75B0454E0DFE3A4F74B08276E889CEEA606FB3DAB74BF2EEE392BAAC197C7C461FB9FA8AF71E71C5798904D5A4EB6C4EF5EF3F182CBAC96D81AA7F96BC503962314E7F77C5470DFD7081E45E888B8CC8B2B2034212B98C5EAD44F18D1057EC70A8129CC41844CD42A3FAAA8E10219204A976EF7609AD76F27EC7D
|
||||
Test: Encrypt
|
||||
#
|
||||
Source: Botan 2.3 generated
|
||||
Comment: SM4-128(128)
|
||||
Key: DBAF14277EC8B5282957FC44EBE64EC1
|
||||
IV: E334E464735A93F8E641D52FFE474CDA
|
||||
Plaintext: B1AB09547F859D8A257E55A4E3D392D12A63CAEF3E66F751C3EC59E7EEC7AF2CDD96438EC2A83D01AE059529FBE4992A8E35F8BE030BC09092B16081914CF1E0C9E734A5E0E6B4F14DD505E8878D4527F12DF1B1601A67D72BC8C09EB34E4CDC8EA24AB947D6F2FF974D7BEE9E81785DB414AD7EA453D6604360B342DE8B0975
|
||||
Ciphertext: 891480A5C542CB64B1FA46471FDBEACDCCD825920344A64CB792BAF07F2272918F78C51FA892B95A754D77B932E5E66852CF20EE198E71D29E40DBF2919663BC67B86EA5EA3CD5A77AD473B54D0C6EAF6325EACC41306EA0CF501D501D9DA4016594F1544DFACB3738EA84EEEC6C07FA887084E7547B381A34D4E571E470D161
|
||||
Test: Encrypt
|
||||
|
151
sm3.cpp
151
sm3.cpp
@ -25,12 +25,22 @@ inline word32 P0(word32 X)
|
||||
return X ^ rotlFixed(X, 9) ^ rotlFixed(X, 17);
|
||||
}
|
||||
|
||||
inline word32 FF1(word32 X, word32 Y, word32 Z)
|
||||
inline word32 P1(word32 X)
|
||||
{
|
||||
return X ^ rotlFixed(X, 15) ^ rotlFixed(X, 23);
|
||||
}
|
||||
|
||||
inline word32 EE(word32 W0, word32 W7, word32 W13, word32 W3, word32 W10)
|
||||
{
|
||||
return P1(W0 ^ W7 ^ rotlFixed(W13, 15)) ^ rotlFixed(W3, 7) ^ W10;
|
||||
}
|
||||
|
||||
inline word32 FF(word32 X, word32 Y, word32 Z)
|
||||
{
|
||||
return (X & Y) | ((X | Y) & Z);
|
||||
}
|
||||
|
||||
inline word32 GG1(word32 X, word32 Y, word32 Z)
|
||||
inline word32 GG(word32 X, word32 Y, word32 Z)
|
||||
{
|
||||
return ((Z ^ (X & (Y ^ Z))));
|
||||
}
|
||||
@ -43,10 +53,8 @@ inline void R1(word32 A, word32& B, word32 C, word32& D, word32 E, word32& F,
|
||||
const word32 TT1 = (A ^ B ^ C) + D + (SS1 ^ A12) + Wj;
|
||||
const word32 TT2 = (E ^ F ^ G) + H + SS1 + Wi;
|
||||
|
||||
B = rotlFixed(B, 9);
|
||||
D = TT1;
|
||||
F= rotlFixed(F, 19);
|
||||
H = P0(TT2);
|
||||
B = rotlFixed(B, 9); D = TT1;
|
||||
F= rotlFixed(F, 19); H = P0(TT2);
|
||||
}
|
||||
|
||||
inline void R2(word32 A, word32& B, word32 C, word32& D, word32 E, word32& F,
|
||||
@ -54,26 +62,15 @@ inline void R2(word32 A, word32& B, word32 C, word32& D, word32 E, word32& F,
|
||||
{
|
||||
const word32 A12 = rotlFixed(A, 12);
|
||||
const word32 SS1 = rotlFixed(A12 + E + TJ, 7);
|
||||
const word32 TT1 = FF1(A, B, C) + D + (SS1 ^ A12) + Wj;
|
||||
const word32 TT2 = GG1(E, F, G) + H + SS1 + Wi;
|
||||
const word32 TT1 = FF(A, B, C) + D + (SS1 ^ A12) + Wj;
|
||||
const word32 TT2 = GG(E, F, G) + H + SS1 + Wi;
|
||||
|
||||
B = rotlFixed(B, 9);
|
||||
D = TT1;
|
||||
F = rotlFixed(F, 19);
|
||||
H = P0(TT2);
|
||||
B = rotlFixed(B, 9); D = TT1;
|
||||
F = rotlFixed(F, 19); H = P0(TT2);
|
||||
}
|
||||
|
||||
inline word32 P1(word32 X)
|
||||
{
|
||||
return X ^ rotlFixed(X, 15) ^ rotlFixed(X, 23);
|
||||
}
|
||||
|
||||
inline word32 SM3_E(word32 W0, word32 W7, word32 W13, word32 W3, word32 W10)
|
||||
{
|
||||
return P1(W0 ^ W7 ^ rotlFixed(W13, 15)) ^ rotlFixed(W3, 7) ^ W10;
|
||||
}
|
||||
|
||||
static size_t SM3_HashMultipleBlocks_CXX(word32 *state, const word32 *data, size_t length)
|
||||
// Krzysztof Kwiatkowski did a very nice job with this function.
|
||||
size_t SM3_HashMultipleBlocks_CXX(word32 *state, const word32 *data, size_t length)
|
||||
{
|
||||
CRYPTOPP_ASSERT(data);
|
||||
|
||||
@ -90,109 +87,109 @@ static size_t SM3_HashMultipleBlocks_CXX(word32 *state, const word32 *data, size
|
||||
iblk(W00)(W01)(W02)(W03)(W04)(W05)(W06)(W07)(W08)(W09)(W10)(W11)(W12)(W13)(W14)(W15);
|
||||
|
||||
R1(A, B, C, D, E, F, G, H, 0x79CC4519, W00, W00 ^ W04);
|
||||
W00 = SM3_E(W00, W07, W13, W03, W10);
|
||||
W00 = EE(W00, W07, W13, W03, W10);
|
||||
R1(D, A, B, C, H, E, F, G, 0xF3988A32, W01, W01 ^ W05);
|
||||
W01 = SM3_E(W01, W08, W14, W04, W11);
|
||||
W01 = EE(W01, W08, W14, W04, W11);
|
||||
R1(C, D, A, B, G, H, E, F, 0xE7311465, W02, W02 ^ W06);
|
||||
W02 = SM3_E(W02, W09, W15, W05, W12);
|
||||
W02 = EE(W02, W09, W15, W05, W12);
|
||||
R1(B, C, D, A, F, G, H, E, 0xCE6228CB, W03, W03 ^ W07);
|
||||
W03 = SM3_E(W03, W10, W00, W06, W13);
|
||||
W03 = EE(W03, W10, W00, W06, W13);
|
||||
R1(A, B, C, D, E, F, G, H, 0x9CC45197, W04, W04 ^ W08);
|
||||
W04 = SM3_E(W04, W11, W01, W07, W14);
|
||||
W04 = EE(W04, W11, W01, W07, W14);
|
||||
R1(D, A, B, C, H, E, F, G, 0x3988A32F, W05, W05 ^ W09);
|
||||
W05 = SM3_E(W05, W12, W02, W08, W15);
|
||||
W05 = EE(W05, W12, W02, W08, W15);
|
||||
R1(C, D, A, B, G, H, E, F, 0x7311465E, W06, W06 ^ W10);
|
||||
W06 = SM3_E(W06, W13, W03, W09, W00);
|
||||
W06 = EE(W06, W13, W03, W09, W00);
|
||||
R1(B, C, D, A, F, G, H, E, 0xE6228CBC, W07, W07 ^ W11);
|
||||
W07 = SM3_E(W07, W14, W04, W10, W01);
|
||||
W07 = EE(W07, W14, W04, W10, W01);
|
||||
R1(A, B, C, D, E, F, G, H, 0xCC451979, W08, W08 ^ W12);
|
||||
W08 = SM3_E(W08, W15, W05, W11, W02);
|
||||
W08 = EE(W08, W15, W05, W11, W02);
|
||||
R1(D, A, B, C, H, E, F, G, 0x988A32F3, W09, W09 ^ W13);
|
||||
W09 = SM3_E(W09, W00, W06, W12, W03);
|
||||
W09 = EE(W09, W00, W06, W12, W03);
|
||||
R1(C, D, A, B, G, H, E, F, 0x311465E7, W10, W10 ^ W14);
|
||||
W10 = SM3_E(W10, W01, W07, W13, W04);
|
||||
W10 = EE(W10, W01, W07, W13, W04);
|
||||
R1(B, C, D, A, F, G, H, E, 0x6228CBCE, W11, W11 ^ W15);
|
||||
W11 = SM3_E(W11, W02, W08, W14, W05);
|
||||
W11 = EE(W11, W02, W08, W14, W05);
|
||||
R1(A, B, C, D, E, F, G, H, 0xC451979C, W12, W12 ^ W00);
|
||||
W12 = SM3_E(W12, W03, W09, W15, W06);
|
||||
W12 = EE(W12, W03, W09, W15, W06);
|
||||
R1(D, A, B, C, H, E, F, G, 0x88A32F39, W13, W13 ^ W01);
|
||||
W13 = SM3_E(W13, W04, W10, W00, W07);
|
||||
W13 = EE(W13, W04, W10, W00, W07);
|
||||
R1(C, D, A, B, G, H, E, F, 0x11465E73, W14, W14 ^ W02);
|
||||
W14 = SM3_E(W14, W05, W11, W01, W08);
|
||||
W14 = EE(W14, W05, W11, W01, W08);
|
||||
R1(B, C, D, A, F, G, H, E, 0x228CBCE6, W15, W15 ^ W03);
|
||||
W15 = SM3_E(W15, W06, W12, W02, W09);
|
||||
W15 = EE(W15, W06, W12, W02, W09);
|
||||
R2(A, B, C, D, E, F, G, H, 0x9D8A7A87, W00, W00 ^ W04);
|
||||
W00 = SM3_E(W00, W07, W13, W03, W10);
|
||||
W00 = EE(W00, W07, W13, W03, W10);
|
||||
R2(D, A, B, C, H, E, F, G, 0x3B14F50F, W01, W01 ^ W05);
|
||||
W01 = SM3_E(W01, W08, W14, W04, W11);
|
||||
W01 = EE(W01, W08, W14, W04, W11);
|
||||
R2(C, D, A, B, G, H, E, F, 0x7629EA1E, W02, W02 ^ W06);
|
||||
W02 = SM3_E(W02, W09, W15, W05, W12);
|
||||
W02 = EE(W02, W09, W15, W05, W12);
|
||||
R2(B, C, D, A, F, G, H, E, 0xEC53D43C, W03, W03 ^ W07);
|
||||
W03 = SM3_E(W03, W10, W00, W06, W13);
|
||||
W03 = EE(W03, W10, W00, W06, W13);
|
||||
R2(A, B, C, D, E, F, G, H, 0xD8A7A879, W04, W04 ^ W08);
|
||||
W04 = SM3_E(W04, W11, W01, W07, W14);
|
||||
W04 = EE(W04, W11, W01, W07, W14);
|
||||
R2(D, A, B, C, H, E, F, G, 0xB14F50F3, W05, W05 ^ W09);
|
||||
W05 = SM3_E(W05, W12, W02, W08, W15);
|
||||
W05 = EE(W05, W12, W02, W08, W15);
|
||||
R2(C, D, A, B, G, H, E, F, 0x629EA1E7, W06, W06 ^ W10);
|
||||
W06 = SM3_E(W06, W13, W03, W09, W00);
|
||||
W06 = EE(W06, W13, W03, W09, W00);
|
||||
R2(B, C, D, A, F, G, H, E, 0xC53D43CE, W07, W07 ^ W11);
|
||||
W07 = SM3_E(W07, W14, W04, W10, W01);
|
||||
W07 = EE(W07, W14, W04, W10, W01);
|
||||
R2(A, B, C, D, E, F, G, H, 0x8A7A879D, W08, W08 ^ W12);
|
||||
W08 = SM3_E(W08, W15, W05, W11, W02);
|
||||
W08 = EE(W08, W15, W05, W11, W02);
|
||||
R2(D, A, B, C, H, E, F, G, 0x14F50F3B, W09, W09 ^ W13);
|
||||
W09 = SM3_E(W09, W00, W06, W12, W03);
|
||||
W09 = EE(W09, W00, W06, W12, W03);
|
||||
R2(C, D, A, B, G, H, E, F, 0x29EA1E76, W10, W10 ^ W14);
|
||||
W10 = SM3_E(W10, W01, W07, W13, W04);
|
||||
W10 = EE(W10, W01, W07, W13, W04);
|
||||
R2(B, C, D, A, F, G, H, E, 0x53D43CEC, W11, W11 ^ W15);
|
||||
W11 = SM3_E(W11, W02, W08, W14, W05);
|
||||
W11 = EE(W11, W02, W08, W14, W05);
|
||||
R2(A, B, C, D, E, F, G, H, 0xA7A879D8, W12, W12 ^ W00);
|
||||
W12 = SM3_E(W12, W03, W09, W15, W06);
|
||||
W12 = EE(W12, W03, W09, W15, W06);
|
||||
R2(D, A, B, C, H, E, F, G, 0x4F50F3B1, W13, W13 ^ W01);
|
||||
W13 = SM3_E(W13, W04, W10, W00, W07);
|
||||
W13 = EE(W13, W04, W10, W00, W07);
|
||||
R2(C, D, A, B, G, H, E, F, 0x9EA1E762, W14, W14 ^ W02);
|
||||
W14 = SM3_E(W14, W05, W11, W01, W08);
|
||||
W14 = EE(W14, W05, W11, W01, W08);
|
||||
R2(B, C, D, A, F, G, H, E, 0x3D43CEC5, W15, W15 ^ W03);
|
||||
W15 = SM3_E(W15, W06, W12, W02, W09);
|
||||
W15 = EE(W15, W06, W12, W02, W09);
|
||||
R2(A, B, C, D, E, F, G, H, 0x7A879D8A, W00, W00 ^ W04);
|
||||
W00 = SM3_E(W00, W07, W13, W03, W10);
|
||||
W00 = EE(W00, W07, W13, W03, W10);
|
||||
R2(D, A, B, C, H, E, F, G, 0xF50F3B14, W01, W01 ^ W05);
|
||||
W01 = SM3_E(W01, W08, W14, W04, W11);
|
||||
W01 = EE(W01, W08, W14, W04, W11);
|
||||
R2(C, D, A, B, G, H, E, F, 0xEA1E7629, W02, W02 ^ W06);
|
||||
W02 = SM3_E(W02, W09, W15, W05, W12);
|
||||
W02 = EE(W02, W09, W15, W05, W12);
|
||||
R2(B, C, D, A, F, G, H, E, 0xD43CEC53, W03, W03 ^ W07);
|
||||
W03 = SM3_E(W03, W10, W00, W06, W13);
|
||||
W03 = EE(W03, W10, W00, W06, W13);
|
||||
R2(A, B, C, D, E, F, G, H, 0xA879D8A7, W04, W04 ^ W08);
|
||||
W04 = SM3_E(W04, W11, W01, W07, W14);
|
||||
W04 = EE(W04, W11, W01, W07, W14);
|
||||
R2(D, A, B, C, H, E, F, G, 0x50F3B14F, W05, W05 ^ W09);
|
||||
W05 = SM3_E(W05, W12, W02, W08, W15);
|
||||
W05 = EE(W05, W12, W02, W08, W15);
|
||||
R2(C, D, A, B, G, H, E, F, 0xA1E7629E, W06, W06 ^ W10);
|
||||
W06 = SM3_E(W06, W13, W03, W09, W00);
|
||||
W06 = EE(W06, W13, W03, W09, W00);
|
||||
R2(B, C, D, A, F, G, H, E, 0x43CEC53D, W07, W07 ^ W11);
|
||||
W07 = SM3_E(W07, W14, W04, W10, W01);
|
||||
W07 = EE(W07, W14, W04, W10, W01);
|
||||
R2(A, B, C, D, E, F, G, H, 0x879D8A7A, W08, W08 ^ W12);
|
||||
W08 = SM3_E(W08, W15, W05, W11, W02);
|
||||
W08 = EE(W08, W15, W05, W11, W02);
|
||||
R2(D, A, B, C, H, E, F, G, 0x0F3B14F5, W09, W09 ^ W13);
|
||||
W09 = SM3_E(W09, W00, W06, W12, W03);
|
||||
W09 = EE(W09, W00, W06, W12, W03);
|
||||
R2(C, D, A, B, G, H, E, F, 0x1E7629EA, W10, W10 ^ W14);
|
||||
W10 = SM3_E(W10, W01, W07, W13, W04);
|
||||
W10 = EE(W10, W01, W07, W13, W04);
|
||||
R2(B, C, D, A, F, G, H, E, 0x3CEC53D4, W11, W11 ^ W15);
|
||||
W11 = SM3_E(W11, W02, W08, W14, W05);
|
||||
W11 = EE(W11, W02, W08, W14, W05);
|
||||
R2(A, B, C, D, E, F, G, H, 0x79D8A7A8, W12, W12 ^ W00);
|
||||
W12 = SM3_E(W12, W03, W09, W15, W06);
|
||||
W12 = EE(W12, W03, W09, W15, W06);
|
||||
R2(D, A, B, C, H, E, F, G, 0xF3B14F50, W13, W13 ^ W01);
|
||||
W13 = SM3_E(W13, W04, W10, W00, W07);
|
||||
W13 = EE(W13, W04, W10, W00, W07);
|
||||
R2(C, D, A, B, G, H, E, F, 0xE7629EA1, W14, W14 ^ W02);
|
||||
W14 = SM3_E(W14, W05, W11, W01, W08);
|
||||
W14 = EE(W14, W05, W11, W01, W08);
|
||||
R2(B, C, D, A, F, G, H, E, 0xCEC53D43, W15, W15 ^ W03);
|
||||
W15 = SM3_E(W15, W06, W12, W02, W09);
|
||||
W15 = EE(W15, W06, W12, W02, W09);
|
||||
R2(A, B, C, D, E, F, G, H, 0x9D8A7A87, W00, W00 ^ W04);
|
||||
W00 = SM3_E(W00, W07, W13, W03, W10);
|
||||
W00 = EE(W00, W07, W13, W03, W10);
|
||||
R2(D, A, B, C, H, E, F, G, 0x3B14F50F, W01, W01 ^ W05);
|
||||
W01 = SM3_E(W01, W08, W14, W04, W11);
|
||||
W01 = EE(W01, W08, W14, W04, W11);
|
||||
R2(C, D, A, B, G, H, E, F, 0x7629EA1E, W02, W02 ^ W06);
|
||||
W02 = SM3_E(W02, W09, W15, W05, W12);
|
||||
W02 = EE(W02, W09, W15, W05, W12);
|
||||
R2(B, C, D, A, F, G, H, E, 0xEC53D43C, W03, W03 ^ W07);
|
||||
W03 = SM3_E(W03, W10, W00, W06, W13);
|
||||
W03 = EE(W03, W10, W00, W06, W13);
|
||||
R2(A, B, C, D, E, F, G, H, 0xD8A7A879, W04, W04 ^ W08);
|
||||
R2(D, A, B, C, H, E, F, G, 0xB14F50F3, W05, W05 ^ W09);
|
||||
R2(C, D, A, B, G, H, E, F, 0x629EA1E7, W06, W06 ^ W10);
|
||||
@ -229,8 +226,8 @@ NAMESPACE_BEGIN(CryptoPP)
|
||||
void SM3::InitState(HashWordType *state)
|
||||
{
|
||||
const word32 s[] = {
|
||||
0x7380166fU, 0x4914b2b9U, 0x172442d7U, 0xda8a0600U,
|
||||
0xa96f30bcU, 0x163138aaU, 0xe38dee4dU, 0xb0fb0e4eU
|
||||
0x7380166f, 0x4914b2b9, 0x172442d7, 0xda8a0600,
|
||||
0xa96f30bc, 0x163138aa, 0xe38dee4d, 0xb0fb0e4e
|
||||
};
|
||||
|
||||
std::memcpy(state, s, sizeof(s));
|
||||
|
Loading…
Reference in New Issue
Block a user