* Fix security issue #266.

* Add more tests.

* Fix PeerID tests should not use RSA-512 keys.

* Fix crypto tests to use vectors with 2048+ bits.

* Disable 4096bit RSA key generation for CI debug runs.
This commit is contained in:
Eugene Kabanov 2020-07-15 11:24:04 +03:00 committed by GitHub
parent d7bab37119
commit 9eb5828a42
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 398 additions and 240 deletions

View File

@ -23,11 +23,13 @@ import stew/results
export results
const
DefaultPublicExponent* = 3'u32
DefaultPublicExponent* = 65537'u32
## Default value for RSA public exponent.
MinKeySize* = 512
## https://golang.org/src/crypto/rsa/rsa.go#226
MinKeySize* = 2048
## Minimal allowed RSA key size in bits.
DefaultKeySize* = 2048
## https://github.com/libp2p/go-libp2p-core/blob/master/crypto/rsa_common.go#L13
DefaultKeySize* = 3072
## Default RSA key size in bits.
RsaOidSha1* = [
@ -78,7 +80,8 @@ type
RsaError* = enum
RsaGenError,
RsaKeyIncorrectError,
RsaSignatureError
RsaSignatureError,
RsaLowSecurityError
RsaResult*[T] = Result[T, RsaError]
@ -118,9 +121,12 @@ proc random*[T: RsaKP](t: typedesc[T], rng: var BrHmacDrbgContext,
## algorithm.
##
## ``bits`` number of bits in RSA key, must be in
## range [512, 4096] (default = 2048).
## range [2048, 4096] (default = 3072).
##
## ``pubexp`` is RSA public exponent, which must be prime (default = 3).
if bits < MinKeySize:
return err(RsaLowSecurityError)
let
sko = 0
pko = brRsaPrivateKeyBufferSize(bits)

View File

@ -17,37 +17,6 @@ when defined(nimHasUsed): {.used.}
const
PrivateKeys = [
"""080012BE023082013A020100024100AD8A7D5B0EB7C852C1464E4567651F412C
692534E1600FDC5BDA9EDBFA9927AF0FFA7C52599BE62999E085C345D21C8D43
627CCC0E16D695C770E26D220AE709020301000102403B58BCFDC2CEBEC6EE29
A8E2BB352DB71004F5205C62898A062F815C211AF722AADD1087C68E24015417
E36632EEA2D2B1A20FF3D283A4C3881C724B3919FCF1022100D4BD1D7D15B328
4EFBBB5B2C6A11CFB7BCD9000C1010D69C808F370DFA751D47022100D0D4CB1B
BAB9F8C11376744F0D96D6E4BC2B12F4DF768AC9EEA79DAB24C8C12F02210089
A3FA0A4E19E64083FA8A58C81FD2070CF651637C9988612584839855ADA44D02
20137DD91B5479693B743A992E8BC1297B9E08933361EC2996217D699D00C8F0
2702201A8D0497E8962E0AF5B15CA03085070F735B39876C54BA8908EDC87C42
D9DADC""",
"""080012E0043082025C02010002818100B91DCD5578C2FA3EA7D1DF62F59DEEDA
834ECE568844554163E1803CDF4C2988BE182B8F957D3405BC745A33DA1E714A
BA13C316683767735ED72AE8B35648FD6E33A49D696FADB6499C63A09204F0BF
77B44D3917DC746FB7B52040725746A3140E96E8682A02A4767C280DEFBE58C6
ACB6DD1EE63F3F589F4C7941B27957F70203010001028180364CDFA66ABE06D9
CA306DEE814DCA7A9E79C75CEAABE0B645AE2807B3188C36684C7EBAA7870A73
844C3D0968B9F5518E33ADCE2CD3D3ACABED41D0F08A26EE705E4277AF0D5816
491C626F6D2D5396A741B83D0730401B061A8C2DE19E18B07CE8798F387D4C79
78C92DA6F4080A45F93D0ADE50CF7E139DB7288EBA72D341024100DE9B394C60
6C396B65756CE4A2E3D77F66C3AFBDA0C09C3CD87EB60A35018BDA7D82FF119F
F6EBAAEC868E8ED1AD215C9EBF4073F26A1B187CDAFC862540B1C3024100D4E2
D92E126D92B6795EBD7991A2D8A35147FAB73CFA4BBE74644CE8D1AEDE10A2FF
33CEDF0B4961A89B1121C58D233309589BFBDE72D374ECB6A6859B0CC9BD0241
008B0ABB9C6831D11FB2CCC8CA7AB003BF9109B3B0A7430793BDCA4F9C4A857F
BC665F3740E400D02CFFF5FFFF571A63D73D54CA4661E942A965FB4675E7B8E4
0F02404A175D90DC57085DBBA60E79B6072030CF04272D08EAEFDBAC349053E3
4E61F916518D9D6D21477BD6AB896DE08C7B78B2C3051EC6CFDDEA6ECC2EEE87
050F5D02407BC18B68F253353D7DB89AA85A7CEC4069DAEB894828F83931ADC4
9A3255DFD0C9AAF9D09EBFAE831588A360EB0EEB89E45C9D136DCEEC8EAEBD3E
65FBA9EE01""",
"""080012A809308204A40201000282010100C8B014EC01E135D635F7E246BA7D42
3E2B36F45B052F0B644DA6B1B6DD964696F279BB9BB5F5C41EE3204F74EF70C2
28C8CDD97E4F19094274EB01C292EC25055CB3CECD1A41E8919A0C111602B1B8
@ -86,6 +55,62 @@ const
8C0E4AEA1453952818FF9AD2FACCED7CE3A037D8545C151F57D35DED691CA53F
8A5336590F7B080805A46701B01C9F9919E3890CA1A0373D909373638B57FD0C
87627491C41F1BF1E9643DE7B4""",
"""080012E80D308206E40201000282018100F50BABF75636386F1C606950F495F5
3149B648408E5D61B7EB0C9F96681CC685F35358A3B91C2AD848C819902FFCD2
D3B1E46F806DC464109CEE43BDA4BDD01EE8A3F035B654C965255B5834A34C6F
3543E66A0D61545B42F2BF819E76B602F6F6ADECB6EC81FBCFB0EBC9CAEFC7AA
D95DB7E91B52C4CF3BA5B25CCADB117FFE2488A906FFD56318A39B3054E3D221
D95334A385A6AF9A00D51D119D953E2ADCDFF57708DA27602A2BF4C4B9D62059
35A22313086C8531017EF749B407B76A25280DD079CB7A0FACE87BA6EDA0C945
39E8CBC91D7E709E3BD32F266D4949B829A01303513AC3BF9777A8A6657AE1F2
CDF18FF026C23321B2BFFAAD68250D054F7B24B98A18AF270EF7A5FF918BCABA
3BDF1F44C0345CFD4B4CDDA9D51486D281F9560D69C0C30718118AD76C6BAB4A
E585A188A16A1148131D558555B36E8348065C7441D6D823906E13EF6F287310
9F3AF729637379CF07028FBFC34411DCDC765C38BBFC632556B29415EDC70DF8
352EFEF1BED37656565ECB8598EF9D7B8502030100010282018100B34C5C02B9
392927DBBA8BB4E99203FB9174E7FF1C6C25811E62792EE37512A9967648A85B
5CC9D8C1C0703BF970E38E745EB25B6575CAC6011DB1C14496827EEB38711DCC
10D3DFC76AC3EA9805E865300E9B50B903B15716299C1D27BD5C03FA511EA066
03620E00E5361CE03FD7B9FE81FFF5B7253C80E767CFCFBA655EA2C5769D3EFA
D8D70E833F9D28B01DE418917235A82863DAAA7B452ECB801521E5C5956508BC
1F0D952DDE864777EEE9777DF06E0FBEDFE210B72717EDBBABAFE49B872FB653
5C35D539775E7B06241E7AE2C6C6B16E7A62334B60D4E034C514DD4EDB306AC1
151981114A555E69EB2C3CD5E71FB825151381506E7A574FB3448990CB3E11A8
832269C005E9C26601580492B1CC9A7C0FCB5008F1019781A6E06EAC47F270B5
333B9BA54F5BDBF73DC36B650AE320A269F2E723DD811A9B557EE001EC7EA037
3B88DD277FFA31C82FAC1C80657BCF175E81BD13C55A6F14F8D3FC8F2BBBC57D
CEFC0A697A57B27CBD82CF5F2C41DB0E9308A3D7C8374B970D786D0281C100F5
D4DE76DC843D98DCF3D49787421D00E7CED08325863FA72793B0CBC339A29D0C
1762BBD382EEE3CFD77F99343E8A9D1AB561E10286819A892E0C638C8F95904C
2BA43BD83270817401158DB986F4DB41AAAFF769799319BBC958299AEA1809CA
A76A13FDE12D35830946DDCA39C1F828EE997F5F6E11365BC0A8417D2BB72CE8
A9D31838D6EE6988E2BE8ACB7C50A64EBA9E78CB2519F9A0466411D250EB1F80
122071CD6D104D4845F5669A8DE63DECE598549827492306C898655BA6F49702
81C100FF2E7B01C2318C22AFE6D3B210542FC2BCC35EF128209C672AACCD997C
56FB7263795ECA9EEB4C8E34E5A1D0D56209159311FB929D4839AAB873E5E194
6F5768C1798BB5CBA763D3BAE0F54456CFD812CFFA407731C5870E06CCBC9BF0
43D8A3DBD050AE0EC1116AD702531398FE76C9323C0B20277671859F15EB09E7
FC84F4CC0122AED4C0C3ED9579DF2D0D0B0E625B4E2A04C893F3DCD7D00B2B57
C6D7F7825C6C26EB4D9A74BA6D78046B6218B8420816ED46683CDD27E3AB3BE2
0748430281C100E6851183662F7F4F6BCA1DCD65E1822F0A306E68BC7452161D
CFA996B95FBF7403159ED94072E42EAE04873B93B91DE44A5A52095C83E2DE95
CA9F856E166A8AA052C033F9FCFA70F9E5D65F4ADD1998CCD011283138F6CEC7
BFFBB32FF85A483C4796FA5E349C5F349C2B5EE9361604EDE527FD3FF087A570
8E8D78B3B69D93382D9FAC7408601288710F7A396C3E7865152C6B5B1B546B37
772A7967BDC76D877BF7FE9F42A969BEDF134A7E9D978CF42B2C180F81AF5C70
0D0492EF49F4CB0281C0139CD1ED6FAC7935CD49336A1321354E854D8AC5842D
0578546A559EFF547C1CED924D7BCB3D10743992909E495830948CEA2BE8B7D7
EE3EB5D08A918CE405D6D24FF231F5C616C11632E606EB992BE53E40E0A58898
C2E98C123E48C9ED9CFFF30C0EB76200EAC2C865B056E8425E84D62C913A566E
1F0983119F2FF2B990CA73C77E8FEB60296EE0372EB4FAB4A7D55D6923879C96
EA7E45C402A7C1265240FEAEF5CD03F6C1F148C6D31B9BD93D4724241507058B
4B6A3FFF9A908EADBA9B0281C07259AACD3FD4D7A3B62814F9F3ADD57972CF52
AD319505589E3E838F6A97D45F9965BD9B7A534C007A1B5BEA17D79971F4BCAE
ECCAF0283CEFBB81DCED9AB547221520E3D574746A7390303AD0C64F77657575
9D0D220B3269B739D2AD84501EAF84F819669AA926BA9F058C40BA1FCE327C38
1957F275AD7C6A832086438063A88F8502EC112D06726B9BF550B6E0720B8FDC
3DE36D24F6E1A123779CE59D2340A36E025D47E4B1F8B49BBEF1E0FEEB70AE42
8B86865554F05081A22BF3F399""",
"""080012AD12308209290201000282020100E35735127777C52E66252B014E9650
01F3A515317B90DDAC8671F4F820AE67308DE2AA4162E99522CD6DA7EB9D7DB6
06489FEB77341A8FA058FAC832EE6EE5E978D512FF79461FC419A23B27C39C81
@ -170,16 +195,6 @@ const
]
PublicKeys = [
"""0800125E305C300D06092A864886F70D0101010500034B003048024100AD8A7D
5B0EB7C852C1464E4567651F412C692534E1600FDC5BDA9EDBFA9927AF0FFA7C
52599BE62999E085C345D21C8D43627CCC0E16D695C770E26D220AE709020301
0001""",
"""080012A20130819F300D06092A864886F70D010101050003818D003081890281
8100B91DCD5578C2FA3EA7D1DF62F59DEEDA834ECE568844554163E1803CDF4C
2988BE182B8F957D3405BC745A33DA1E714ABA13C316683767735ED72AE8B356
48FD6E33A49D696FADB6499C63A09204F0BF77B44D3917DC746FB7B520407257
46A3140E96E8682A02A4767C280DEFBE58C6ACB6DD1EE63F3F589F4C7941B279
57F70203010001""",
"""080012A60230820122300D06092A864886F70D01010105000382010F00308201
0A0282010100C8B014EC01E135D635F7E246BA7D423E2B36F45B052F0B644DA6
B1B6DD964696F279BB9BB5F5C41EE3204F74EF70C228C8CDD97E4F19094274EB
@ -190,6 +205,20 @@ const
4E2745A05E4D31F364C2C50C0F5C9A6889378051BF05669EA905C2370548D6EF
2CF66A4A5DC23F10B7614BC43CF0BFCC8711B6FF9F645FC2E5713ED1CB597539
2B8C865202690203010001""",
"""080012A603308201A2300D06092A864886F70D01010105000382018F00308201
8A0282018100F50BABF75636386F1C606950F495F53149B648408E5D61B7EB0C
9F96681CC685F35358A3B91C2AD848C819902FFCD2D3B1E46F806DC464109CEE
43BDA4BDD01EE8A3F035B654C965255B5834A34C6F3543E66A0D61545B42F2BF
819E76B602F6F6ADECB6EC81FBCFB0EBC9CAEFC7AAD95DB7E91B52C4CF3BA5B2
5CCADB117FFE2488A906FFD56318A39B3054E3D221D95334A385A6AF9A00D51D
119D953E2ADCDFF57708DA27602A2BF4C4B9D6205935A22313086C8531017EF7
49B407B76A25280DD079CB7A0FACE87BA6EDA0C94539E8CBC91D7E709E3BD32F
266D4949B829A01303513AC3BF9777A8A6657AE1F2CDF18FF026C23321B2BFFA
AD68250D054F7B24B98A18AF270EF7A5FF918BCABA3BDF1F44C0345CFD4B4CDD
A9D51486D281F9560D69C0C30718118AD76C6BAB4AE585A188A16A1148131D55
8555B36E8348065C7441D6D823906E13EF6F2873109F3AF729637379CF07028F
BFC34411DCDC765C38BBFC632556B29415EDC70DF8352EFEF1BED37656565ECB
8598EF9D7B850203010001""",
"""080012A60430820222300D06092A864886F70D01010105000382020F00308202
0A0282020100E35735127777C52E66252B014E965001F3A515317B90DDAC8671
F4F820AE67308DE2AA4162E99522CD6DA7EB9D7DB606489FEB77341A8FA058FA
@ -396,10 +425,10 @@ suite "Key interface test suite":
sig2.verify(bmsg, pubkey) == true
recsig2.verify(bmsg, recpub2) == true
for i in 0..<5:
var seckey = PrivateKey.random(RSA, rng[], 512).get()
for i in 0 ..< 2:
var seckey = PrivateKey.random(RSA, rng[], 2048).get()
var pubkey = seckey.getKey().get()
var pair = KeyPair.random(RSA, rng[], 512).get()
var pair = KeyPair.random(RSA, rng[], 2048).get()
var sig1 = pair.seckey.sign(bmsg).get()
var sig2 = seckey.sign(bmsg).get()
var sersig1 = sig1.getBytes()

View File

@ -20,40 +20,121 @@ const
# https://github.com/libp2p/go-libp2p-crypto/blob/master/key.go
# https://github.com/libp2p/go-libp2p-peer/blob/master/peer.go
PrivateKeys = [
# RSA512 keys
"""080012BE023082013A020100024100CCE59D6260E7D511DB3DD2C8A3CD5B0F1
D16C8A6FD6A331A211305B677EADF48A7B06F0A74088E96458F23B453EC03A6
63985D32105017A26F7EEE8CF43FAB110203010001024056D5609396B9E9447
E037F56E4845CF8D4BD19201BF96BDAC0F58CD03D95DE35EBB015A88FD8B8CF
731F5604C3895E05A1268D218E64E0C077422AAB3762E801022100F5C1FAAC2
59F7A765C2F7B5639EF537CFAB102989924552C0EB3608936623DC1022100D5
6FAFBD6ED32E7C02D310CC5355EA4B85704D1F73AECCCAB28BDD3BBEC461510
220056286B796EB73A77C459E12399AC0DD9030A8B9E741208CA295D39BAE11
6101022016D390070170427B6ECDE5F104449EFF1EB148FE412003B4F5ED716
6AF5B4F51022100B9F2F54717615B6B34C08571098BAE081B5DDA58A35440BC
BD0222EB250682BB""",
"""080012BD0230820139020100024100A0C957A3EC20A90D511F732ECC650E4EA
EC501EC8349E8891BAF786E6AB424B5665AC229BCB241217FFC51FB7A443C85
688CE0D12A4C9C267B511488B537D2BB0203010001024068AD8CA448F79E77F
007A4AAA4216AA6293C539B52824CA4EEE45768B3896297BABA5CFDAE4D1345
3BF3B7CEC8DF4623693B7CA7F046982A6B0CFEC722338D19022100CEC09F191
08A63E059DE14B057D08D81D6F8583D9CDCB89300A8D11DED084C4D022100C7
15CDBEDAF98D9F0A73DF4880A511B70E17835DA94C32D765B57E88AC827F270
220040684127CDBF4EDDD52119D0D58A628AD02D0D50244D9E322D4269E2A8B
4AD102201316D81F90C794F8C6FBCD511A64B98A1FE3C948D5CEE4A11AB3886
A7A8018C9022075677C2486F633F74E5718681D0C75477B62F0CD14A5C2226A
11DEC5CFA96299""",
"""080012C0023082013C020100024100D6E4788FBF4FCD607D6F61E01E910CE58
14B8BBA5A0F878EDF1C5ACC46A7C3FDECDEEE990D67C3DE5AE4A0301A1621BA
1903938D08451F475393E2C863A8FE230203010001024100980168DE95BF475
197A8F01CEEC23FD3205065F85DB85A754F90E91152715D8AB693A37504D700
703C09F3B171BB5441CD6B5BF462FADDAAB896F2E4047D8681022100DFEE0F7
3DC6C9DC269E44A722007D937238299EEB7D07CE7B527AD9EE40A30E1022100
F5AB120334B11F27C475385B2769448A53D40B47AA48D40AF623C7E4CB525B8
3022100B340507451754CCFAC8E471D9610524BB60C3C867FF3CF987745DCD0
7D00BF61022100DBCAC400CE41B18818C26F3B4E9565D7048CEFD29C4D3038E
662B8D2BFFDDD1502206BC3E38AA82EBA2B99D2FF56AB19B2CE118B9A8A2AD1
AEAF45F3ED4FE957619F""",
# RSA2048 keys
"""080012A709308204A30201000282010100C277609AE7F5A06157D57A6EAACFA2
1CC01049AF18B9DE167B8B3B933487E9403E915FF3E7896932F4DD66A8B24061
CC88F8650ED50E3C28026A83A018D994912491580B8FD70313EAB2D03AB582EA
3B3DEB60133743CA0F15D9F844C1333D64DADD961CFF9E780A6D7F2245A838A0
FF991955E2958D9B6781D6FD15E3C350D702377EB01823E64927A7CF7098801C
ACF60F5DDEDB64FBA27143F54878668657945D878981839EDE691393388F75E0
F5948FE2EC86CAF2FD8882A57566E004A647721F47F2A82FBFBCD9F481D8DC74
0ED8A2FD9164367958FC55C4ABEC99D4ADCD8D841C616285D3076DE688045359
3E3E2B9811100A4B8E2C7E6DC5D5B3C93702030100010282010100913BB8B158
0550A7028313B1ECEDAEC3CC091E0E9FE7C85E801C06FD346140A953511D193A
559C748AFD82FB004D26FD2B5A5F9709355D66000FEE87B5A761D6583A184862
3F9133E1B773DE34CB3605D283A43815B11209DC26F2CCDE81571BA87D8EEBCF
58598C682467C3201452E1314503A87A4ACCC22BED150CB112A09EF5E9168FAD
E3AB135DD41B455B2754251E557D6AEC20B7EC9B38B512F1A93F40CD31D59071
67555D17A72A00E4BED5857D3CF9965016018F4DD0567A4C9440D8AB1C7A82CA
E3C2A34EF8CCDB81E3D070ACE7681CBDF5A438E15F6F2821D51F654467CBD509
576D5EBA6F3FF7B15F38FA92AF7F9CA92C0A41E10F038647920A4102818100E0
17CB68FAD59E92C5CA8F65C3C95900789D092755343A667ACA8C5BAC626EE30F
789155F0E07D7D00B8132C502CF8D02CF7D7699C174193BCC5B821F3792AF060
E838DB757929686AFF95BF9966A7B11951E16FEC07B09C16C2C27A3B1690D02E
4D24E89C0BEE63A786CA70AA9DD7BF78E59CF364A194A858949ABA32CB296102
818100DE27B098887C0916D1F6CF7782A6B5F7C8A699665B49A5557317582329
A61E411E36BEB2050390531E43466356D957825ECF49F889F2F4C1FCFD2B8855
ACBB2663DF7F362F6FCCCE883B850F215A3E37D752E20549B429A0A90149B761
A8D566013893D0B7A5E14D78F2237205ADB099D43A01CF573FB61E6DD9431407
D501970281800BC7946CB74AC56427BB87202D5387372C1FED1C413156A48E6D
D944F461D43C6152D028F959839F2F8B7D8E85C4676BE20141348EFCF5F88322
CD94134D5A417A869A7E86C550B4E972F7F733641F0A832F37AF7F73C407E076
6A6CAC707A3A4744CCDCE15F0B2FF7DD7104CD2330F522B0C7385020E2449B2B
6C9ABF12C8E10281803ED36EA7D4816F789AAC7803CE5923410DE7BF9E28D6ED
00FB6970AD910BBFA69ECAD0A73BAFC4531D4DDD4C1EB59C7FEC1C2749388A13
1A0157FFC5B0A506D0569250419CACBB78F52210013567760D08C211D5790090
7D350E7E307457F0F1C60AA012F8BCDAB8B42996489ABE82211ED9C0C5486166
39B8CB26A3358BD1C5028180412A1CE4CE9DDCDFFBB2AC90DD466C21D75F13F1
415967EADFBD9E87AF3DB520B4D87B1B619DCB26F32B500D439A0A4E7FF44A2B
6EAFE424672F5A249BEB74D72A4A04A2EE2B5546571A68C79BC290677039E9C4
84B192DA4B7C7F72C21695403D421238539216861160351B99FC0BBD0F9D1A76
6A900436BAD373F31AAFBEB7""",
"""080012A709308204A302010002820101009C338EFF095FB3F9989288D3B0D1EF
4A425E887A109DD9E212311EACB8AA6737B53F352FC4B948E9B5BE9943C98516
E71A85DD7D4A49325133294CE82D4E262FCA647444907BE36727DE527892DDC0
BEA272F767EC596429E1DD4545D7910DF82ABA72C71EBD8D4E34C6C0424BD6BD
66265DAD0D85A8BF912CFECCEB9B63B6C09A6AD026D70FAD445BAEE39ACF6DF1
AAF81CFF3D6207053DEE94569C24274B9307CEF9770385C1FE65D8B502526903
D834678F17BABEA1F9850B58C54B72D5E52E13B5C3E796BC3B989CD9FD616598
4BEA473B3157A1A61C072ECECFB12E09EAB2EDE57A7B5F1BE9D49C8B5242F7DA
90BBC967BE92C761134E69D2F9AB0451CD02030100010282010030F794CF6CDF
DCAAD562B294326D4DA7A8F0BBB610797BB17C647BAA47E5DB9FC22903826B18
6EBC1D6697E3814C40A6C850C8E39B23212C056EE0163505B7C0E9A0DE361459
522BA77AF1BDACC4E9C49966931AB82439DB4B5C337836A0D9913FCBDD6980C0
8988C7D0BABACDCD8EE874048FD89A5B115AF0911C2A8C37113608804DCB3D04
CA34EA7E184A3011C42525D8B2B00B12D45CCD533E32D7014E5119CF51954591
0B41E6845019104B5D63907616DB0CF0EEB82C449DAB0D1073D118660972D337
7786A662CE219F5012F4DCB0F0E2257F3558EDF372321F740458B13DF762D8C0
D51AF28024198EE6E134CE2C9CCEB3940FFF04D8A5A38980D42102818100C170
DF5FB4F412E18FAEA20C7C8C768B59933B72B12986877763706CFB8DD0062781
DBD2102CD419DDFF20C39FA3B19AF9A10D7A38F9C1D426666521E4BAC7B7847E
9838BF9CF28E4B1D12B7FD54166FCA81095E5557486F98641C7BAB6A6EA55C9B
CE2F4ED6B56BA259F93D4D95B32505CA3D38F7680310D03C05D36F6F9E490281
8100CEB798EFF7EDC87E46A2FAD6E061DBBB0051366E5FD6234B857B8B0F5501
BC3708D7A23DB9F029FA4A17DFA9D0E1E271E3AB3065732A6525C4C2A881831C
2D35E56749AAF26AC51A3EDD6989C7E161B3421AEE565CBFBB9C779BEE4182BA
6CF8AF844FADF56C9A54C85EB949447A16D3CD0188A81E191BA824E4376286EF
E7650281810080A59158B41E5264424B30A83F38A729FBB38828B99BD5454868
107FDA3830EDB6DE8D13C2001E3AE9C1DFC759E6E29A1F843553608AF19626C7
9860971E84EE0EA6A693AF1330D8E3297DA6714AB7F536E6E415218A7FB8FFCF
2C862EB504CAE2B117C9AC93EC699DBA5AA0A375788399BB2B46347BAEF64296
78856A2A004902818009089CF65FAF5483B0328F23B4CA91FFAA13E27D10531B
57C18D949626F0DC78CB3A212CF1633D7262AA886BB3652BB02E72DCBA923DD8
0DBE7B8341A5A92590A565CE225A55B0276577E794CDD75B9DA9D5E37482B91E
49C8305849249D6105BD25DB158F141FEA74972F21B48C6153003280F657DA61
0B0811B119ED2BAEC102818077F48BB3C3D417DC4A3D1F871FCD21A6434F1F55
B73DF98524011427524695562A63DAE828427D22897EF60CC5E6A8591E8305AC
202749D7459EBB85E4D65BC9CC44E251F92BDFEA5279C2F06647A2A29C62E90E
37C7A3A72EC0FD20D9073D397EA1D6723473368B28ADA577FA8C2E840EB769FE
CC8B5863789948D6A1550344""",
"""080012A809308204A40201000282010100EF0EBAC68BA931EC25491A9E062F11
485E4BE8CE5A3C7ACB9B058DB956517B76AC2227AD24CFE3CCB75DD4B3C1059E
5FF472FD07715E2DACC97D809AC8CA3C37FBFB6352B956C0F6B9B28CB9ED291C
85FD2814D954DECFB366CC59F3B1C74D477CE9CC2177C9A70041C5C7848627FE
4599FA1AFEFB7E2064E917C56123C717E8670E35ADBE7E0BF981A7104CCE17B3
3758D75F09B42FAEEB6A5ED2B458B798DA2F7C5BF020EF83F4F947C583CE5797
D3E6CCF815040A13CCBA898EB3EDFB57C77A1C6A6D58122BA87BF7C8E581E0A4
F6E96DD783025C9B7C1DDF8F0ABE286B2CEADB884FE1B3081F9648448D5A9319
9A355C7FCFEDF72925A6224BA1E64749290203010001028201003E0ECFD3BCEB
B646FC42E70300CDF5299939117D88154D374FCDF84595AFDF62263B539B7203
F9B9EA1C149C794E3117EDC870011F9FF83173B8FDCAB0B7373CBD503C2F7C67
95FE36A4B03D8FE06D44273CE174ADC08DA09FDE0AB7E57DBC85035B5A1F920E
2A2939E9D2EA873D18980EE9CB5A48052CF9A53D03833D1B710BE64B2D7FEE62
66BF2C2A002C9589D8B9D7710244078FE2F10D18F45962B86F4FF834B3A5C8D0
080C9F36CE556E7BB5D9AF79D91263A179457575C84009C5A219D23A99586762
16319E1D5D85723771625FF80BC7D6A6665515F70EED682BD8209057DF1F6326
A1734D73370F54A388F08C7379F07929DF1CCEA3D813772F126502818100F939
9034445E74434F6E7794874866D793AC180E9C2DB1F37327CC9C085789279F23
AF5BB5323379565AADF865FC2376D8DCEB0C79580525B7FD3CDBE8C8F6CDC295
D852FF40462B0D7AA05B4265ECDA4C4A2C13364A772AD57524D17F8B38A65784
03DF83C2702CD98D1A03778181A738FD05FF2D80D3082D99D6253DBB8F970281
8100F58E689B42904F62BAE4AC2EA87D8EAD61B93CF19622B939FE22F95C1DBA
8A53BA5555F9A321A6E7A83B3D4F4BDEDB95068A9BD42E7CD61B075FEB5FD26E
9D79502CA3A9C080EB0C00126B0D5064EBEFFE437036533133259895EB18CD14
095D7968A63382F0DED2727AD8A495E0C5774E59B1199BFF568A914E616C9957
053F02818100C73F911D68478775C4CC5147EABC249457187007462F7624673D
3B64C77A8C49A3FE18951E10EB7C2760C9D35C5DAF50B5E230FCC10A70DB0DF4
A4B23FB263366F49F32FAFA80831254E9363427B5057DA44366689B21101AAB4
43E245B0DD72876720DD926E61D6497B787FAB0C5BC6805631742841E4F595D7
76904181713302818100DC6E154B62CA86E8FB1AB1D244A049872D158B36D76E
9E5607E3BF7348A09EF2206FE078F34F0F341F99E6249BD817C7C49282E64B40
F736563D6DDE9BD97E755B5A6724C851322E9895F011889CC00BB57536731DE5
29A3D340A9459F3B20590FD6B873BF5498C1D3D0A14FC5D77B8BE902ACEF6F51
1C8FD176CA1021EAB32302818011C9B0591DF6F20172B6DBE725C14CAEB91A6B
8C112CC765A5CDAC993ADFA031465BEB01C55212D8D30402B2C479D072642C48
7998D80899881202CDAFA7C3CCD2B87493C4F8A5E40E84A8E63D93B95F370C0C
15A353C1BF0E625DB36257A2A499AE5611ACED18EBF0AA669D45AA1DC0583268
C41737A8ECEC1978543EDE3D96""",
# Ed25519 keys
"""08011240B6F99B4E4422C516F1BD135B4D2B02AE62C48388CE31AFBA16496D2
42FABE09BF3848ADABAA9F1E1230A3B94EDD3247C2395397EAFB59790B86595
@ -84,9 +165,9 @@ const
]
PeerIDs = [
"Qmdxy8GAu1pvi35xBAie9sMpMN4G9p6GK6WCNbSCDCDgyp",
"QmczLMwRH4cNaLZx1t7PTe5b7k6xKkd3RCJZSxmG3azXJK",
"QmS9Sg4ZA5Fd1hHjNNkqfuMUXX9QnEXxgvT5hfSRuKHp8p",
"QmeuZJbXrszW2jdT7GdduSjQskPU3S7vvGWKtKgDfkDvWs",
"QmeasUkAi1BhVUmopWzYJ5G1PGys9T5MZ2sPn87XTyaUAM",
"Qmc3PxhMhQja8N4t7mRDyGm2vHkvcxe5Kabp2iAig1DXHb",
"12D3KooWSCxTfVvMBJbpF75PQmnFdxdBfC1ZxAGYbFc3U9MjALXz",
"12D3KooWMdZbdEudjgnCvQLoSoiqhQ4ET2gaA1d4JpC1CBkUnfzn",
"12D3KooWDFCm93uCnm8tVdk3DYxNeMFxMGBaywVSt8a8ULtdLoeX",

View File

@ -13,9 +13,7 @@ import ../libp2p/crypto/[crypto, rsa]
when defined(nimHasUsed): {.used.}
const
TestsCount = 20 # number of random tests
PrivateKeys = [
NotAllowedPrivateKeys = [
"""3082013902010002410093405660EDBF5DADAF93DD91E1B38F1EF086A3A0C6EA
38011E58E08D27B163A9506AB837F4AF5CA23338AB3BFBC0AC7A0FAF6B9EE3B1
27BD66083C7B272C1D370203010001024017EE5DDB74E823F6655197B1ECC77C
@ -46,6 +44,21 @@ const
00C2200411163DFAD0D56501AB1076A2CD7CC2FDB066CEAACD8212EC1F292C22
F1840B8C1E23D941436F2EB38873FB76DC649D4DB85FF026D1D5DF405481A2F7
F5""",
]
NotAllowedPublicKeys = [
"""305C300D06092A864886F70D0101010500034B00304802410093405660EDBF5D
ADAF93DD91E1B38F1EF086A3A0C6EA38011E58E08D27B163A9506AB837F4AF5C
A23338AB3BFBC0AC7A0FAF6B9EE3B127BD66083C7B272C1D370203010001""",
"""30819F300D06092A864886F70D010101050003818D0030818902818100BDB0E9
A7AF9865E318C8890A883D185F6D9F88868A5F586244CA6A07F298349EE52E38
EA322D7E453AD2AA8B5019C25C50AEAAA59AFA57173F2B3B44501EF45BCC6C1F
75BEBAC5C11D7861A8A9DAED68964DEFA6ABD0D9FE232E6BA9E97572B6F68C57
030CCBAE19E972D16338201B7C11E00364FE7D613CB3367BB6CF2C3BE5020301
0001""",
]
PrivateKeys = [
"""308204A40201000282010100B7362C6653ED53C35C3AE663DA496C9B834FF34D
72DA98FA6DBF4AABA39FCA0901F58A1B1D205076D20010151DBCA8FC2693E14D
3502320D61E796E9C102C4EBB8F50B90616DE7FB8EA0A4BFC89BE542CC86DB7F
@ -84,6 +97,62 @@ const
8A97B09FF1DC131E7136B557002205E2ADE5DB114499F15AA1E3C6C7E6FE6381
04B6A67697C60C4113F613130403C554688C7046D6AC5F5364A658917E23D40F
1FDDD3DE4C9F51A9""",
"""308206E402010002820181009E4E6CCBE33B69A9FB6A3CAEADDC47E26AE15E1F
F8C56B3126C4C66E549F86F0002A1CC3D0169F034825A3683AA0A579D844B415
698F6F2AA5907246D911CFCD69A5151A78BA5AD803A8FAF0184DAD4BF471469D
B91BE951FD12EE5C8047B536984873A4F79BC054BF0E0A4730A1B20C3CF92440
B1ECC5FA608213AD823C10D9994B3F532FE5FDEF25D6DAE7CDAF1EE7238E70F1
59BA05684261A49050B8E3F37141D13A328A4418168629A5CE8845FBDB70EAF8
988617D5200F1D3695E07CF72978B220AF30E9832BBCFC02273716D2851D43A0
154E16DED7B4975C1881411B63ACEEC3EA7E438DB441128BEB77BC7D452C931D
C8C03E8A882F85BF6E211EB79DC649A2CEF2F1A197EA69C022C6929AA79D9BAB
6BF56DC21F7E3A70192F2523F8393AC95ADD0C07889F31C4BB2F936C35D2C25F
9BDB1DCF131FCC87038C5F53898616956CC92FF904ED9DE01202630100E99D76
31556C3A335B4E44D74C2145F7769E071576CBBFB120850D85C524F0E613705E
0EF3F8D2386F4EBF47520FB50203010001028201800C32CADB63251EDD444C49
64C46CE6F5217B403F8271E3F2A3A4220E3A631888C1DA7CE0F1D5EC66DA565C
2319F16B0EDA8560C30DA149D5A5705DFDEB981DC51C50E63166002623E31450
51D3ED985EF3F50E95F4BF9BD8FF8147F0C4C9C1C2F535100434384237C58915
6DAAE7AACA9AA03014F420E498887B3D7CEF3E25A63ED3B78B7773677FD81098
49A865C821D371946E64959AF90FB46A73DC6482DC2D6BFEED571BA4679EC4B3
CCDCFF4F353B11966995872FAAF28F7796CF31BF2F457270466CF15971A2F0F1
89EA7F9B68EA76290F06FF4FCE9D3A4526D9CB111B5B606CD6AB143B48D5444E
1CA10F24AE42C243C9CDE87CFEF846D229D76707EB3ADA819C073FD4D601CB2D
4FF7E58F61363B76826394327D1460A334C5C09BA5CEB51ED865ECC5D0BE75E7
19939A4C029F0AA49B5E958EC8303FF431D251CA7B4EA13158C3C61758675390
A97D2BFE31CC592E249E78B55D434D837DD0F471C5782244C8ACCC2FDFEFDAB7
0FA53B8DC8C60933B94284853199C7EB6F9B7070F90281C100C9707D75B3C445
93C6295D6FF65FB41F38C74A8B358A3D6AF188B99971ABCA0B3374FFC15DC154
3DB4B4B502331E5FB075987C68FC42844855D45303DD3B78FA0581631149E31B
7739E13C7CE2D2727AC75ECECAFAD3C2DF63A147134A9476F8DFAF72C74DB184
875434F94BD8C617B60B4CDE3C5EBEA372CFAB5FBBC56ADFAC2A5C25CDB157C8
56579AEB36338791AEFCC46B62481F3EABC753AD1ACDCAF2C1856B0E5F061941
4C1B5B133E25B70CD92AE6CDEC776A8D064BECBF11DBE3794F0281C100C92F26
EFDCEB269267FB024A9C3BC33187CB80FAEA989E3F3A2CF657226D7FA8D9F32E
D3EA93730F7D1BA7CE807F3155E9CF931A812579CDF194C3608B12E66967B7F3
50E4AD150878F1CD4B18BDB7C250F3D69E078F0F4B6BFC32DC3369D7B7318896
5A6BCE2A73EC4BEDACF6165DC191C57A642AB69DF5B5B5B1F35D9488035FBF2E
A0BE3D0868A66E2C93E06EAEF6080CBC94D7CEABC895751618AD6ECB43C4146F
C5FD7A4CE761BA24F0EB4C7F159C74A18201174661037294F9364D9DBB0281C1
009C2D2DE822AF0A6EAED5854EF80A6D4143A927BF548C505FE8D1E36BF73884
963897FE6E71FD210E125B84772720E6798E42E23A17528EF2F23083085CEEEE
35922D259CD2D754851487EF78B7F707B0EF802EFE2A8821EF46745501BCF1EC
67BA2D71E4D9F4C6D6914FDCF49425C95E67D679FAFE4DF9B55B12F84F419941
BF5EBC40C7003719E8EF54FA05F4DFA7F0AEA2AECAED35E446146D68A97E6259
E1F649F143751C01873B325A71F595BD4D6638B9F11B08AE3BF283A403F9A29C
7B0281C077FAB2D1E1822B62ACB839499D9AD671B77659D94A06F278EA8CDDEC
610FC44E428C90A4B9046E5E125267E4F324E79B40F115DD7C9F88E094EE0F06
886A2117434FA4BFDD608B669E1A36404EE4F5ADE0F14A50BC5948D9C5F085B4
64C4FE6CB611AAF909C9CDEF8C404BE2167088416459CCFFE7A938D2CC272B94
E37E2D0F360EA21422DFEB1FDE015E7C6220201F81F576919D9217486C39838F
FBFE53227AD16547423FA99563E6CB19127A705FC70A97371CC770A57294E6DB
28D368F90281C1009D7403C764BBF9CC1A23F600E542B3069F1FC6C8B44D1C21
BF2260E65EE86E4116E2CDB721257BB2D27BA8648DC47A3F583D2234263B24EE
49B5549C8732D14493F72BB4A1290D70A181086A2ADFCA250FDAE11245353032
5A6E065A8C96E59E11BCADB3C4810AC2B1899AB986F62282B430EB317B771E6D
B7D2FC2F3F1A8C73CEE0095C67D102263143A518B6622EC47A39B52E276A82D1
CFBFCF6011D9ED12206458512E807B310D9643FAB61DE3F517441116D7270E9E
B626451B5007DBCC""",
"""30820928020100028202010099EBDD4A8DBFD112966F0242CD0D0DFEE9A48572
D49ED4F1E8BD52A08924691A6CE53A47140EC84D046DB142E0607733204FD461
D8CB58BDBF05E51FFB77854660ED814861429AE54BD682A06F0B3C51FBD7A27D
@ -161,15 +230,6 @@ const
]
PublicKeys = [
"""305C300D06092A864886F70D0101010500034B00304802410093405660EDBF5D
ADAF93DD91E1B38F1EF086A3A0C6EA38011E58E08D27B163A9506AB837F4AF5C
A23338AB3BFBC0AC7A0FAF6B9EE3B127BD66083C7B272C1D370203010001""",
"""30819F300D06092A864886F70D010101050003818D0030818902818100BDB0E9
A7AF9865E318C8890A883D185F6D9F88868A5F586244CA6A07F298349EE52E38
EA322D7E453AD2AA8B5019C25C50AEAAA59AFA57173F2B3B44501EF45BCC6C1F
75BEBAC5C11D7861A8A9DAED68964DEFA6ABD0D9FE232E6BA9E97572B6F68C57
030CCBAE19E972D16338201B7C11E00364FE7D613CB3367BB6CF2C3BE5020301
0001""",
"""30820122300D06092A864886F70D01010105000382010F003082010A02820101
00B7362C6653ED53C35C3AE663DA496C9B834FF34D72DA98FA6DBF4AABA39FCA
0901F58A1B1D205076D20010151DBCA8FC2693E14D3502320D61E796E9C102C4
@ -180,6 +240,20 @@ const
7847CA4806722BC74ED9954F409D42CAA3BE028E251FA0218414F2ED4469ED78
C601C71EF7C68D06BBA24DCDFDC8DCCB1F93A72896756B9CCA840E4188D8D02F
890203010001""",
"""308201A2300D06092A864886F70D01010105000382018F003082018A02820181
009E4E6CCBE33B69A9FB6A3CAEADDC47E26AE15E1FF8C56B3126C4C66E549F86
F0002A1CC3D0169F034825A3683AA0A579D844B415698F6F2AA5907246D911CF
CD69A5151A78BA5AD803A8FAF0184DAD4BF471469DB91BE951FD12EE5C8047B5
36984873A4F79BC054BF0E0A4730A1B20C3CF92440B1ECC5FA608213AD823C10
D9994B3F532FE5FDEF25D6DAE7CDAF1EE7238E70F159BA05684261A49050B8E3
F37141D13A328A4418168629A5CE8845FBDB70EAF8988617D5200F1D3695E07C
F72978B220AF30E9832BBCFC02273716D2851D43A0154E16DED7B4975C188141
1B63ACEEC3EA7E438DB441128BEB77BC7D452C931DC8C03E8A882F85BF6E211E
B79DC649A2CEF2F1A197EA69C022C6929AA79D9BAB6BF56DC21F7E3A70192F25
23F8393AC95ADD0C07889F31C4BB2F936C35D2C25F9BDB1DCF131FCC87038C5F
53898616956CC92FF904ED9DE01202630100E99D7631556C3A335B4E44D74C21
45F7769E071576CBBFB120850D85C524F0E613705E0EF3F8D2386F4EBF47520F
B50203010001""",
"""30820222300D06092A864886F70D01010105000382020F003082020A02820201
0099EBDD4A8DBFD112966F0242CD0D0DFEE9A48572D49ED4F1E8BD52A0892469
1A6CE53A47140EC84D046DB142E0607733204FD461D8CB58BDBF05E51FFB7785
@ -201,22 +275,10 @@ const
]
Messages = [
"sample", "test", "sample", "test", "sample", "test", "sample", "test"
"sample", "test", "sample", "test", "sample", "test"
]
Signatures = [
"""2E597258C445FC802E502E23E9ECC711F22A2264F661C2A738032A62408FA74B
C170A8C32F5283355898B2A547BB8C63E0A5CC80CBB326EE52C46094B9D1C517""",
"""8CA474B07CFB229D530E9A1955D30058D3589DFCF44B442DA9F3D5362F1D36CD
03184CFAA1F9153E034FCB2DA2226BD99BCD51612F909016707B22585A43DA96""",
"""7B5311FED58881F5684343E030011A376563A7264C72553C66A5B2EA5D203127
8701B248C8D5008415AB7AB302F53A2C44064C84720C5F96A179B0DBC3AF7447
3E5A040513B0F8212509EE168E7AB90C0E59E157182471202D189F5C0AA2C30B
F172994581ECEC82F0D59DA7E35611B7E6938E8642F9F13DEC8E257FC5F1D70F""",
"""8C8D7F3E30F8E8D9171F38BFFE2D80A8CF1F9CFC40BED7E530B650149BD395EF
FE1FFF5683B7E75215453E7ECFB5EF40BBF35B194FB85B718C80B3190C2851B1
36C84EBB8A8E45D55AB610B7E78B38F0D6A4E7032959CA1EF94E3B1C26702366
F1524A9FFBA5243DF07876B7B77C4262C064841FEDCF82D1D7A1A0A411ED6E8D""",
"""30768DB2A850D5F3F9044D2C7545C3E3D30B03B6F8159D305F19B1CF939C1336
DDA83B406D86ECE5170CE922671FCB178FC03DEF87DBA73C002DC7D302FD122F
1A23BB9F39F21DEBFE42E69A06A0871691B02AEE59772B485ABBF92B99B8E3C8
@ -233,6 +295,30 @@ const
7CAEBE2EACA1067E9B76DB8A74AF8416A3C1E0711F92A520AFE4A258ACDB6128
47B06DF8B6705618D284C4272EDC1C11D1EDDF4D8174DE4F4706034421B0CB82
70771C40A2020E022886C44F7811AB06A3838B055F8D652104E653A1312B7506""",
"""89D01B4043322ED57F20D6756EAE5295A86AA3503FA66A6AC35E2AABAD78F199
EC5E85DBD6D43DE03C662CEFA003413434EC890DD58DF8ED6C3167DA9B4DBFD5
703ADED2544C72E6300A76F0126720F7843A0B0C82CBE220619B3925F94BE8D1
E6B9455EC9DFE6A133868E6E6893C8868B9DAD5D6F1A49056BD2784B6677A76D
B0B90152C398890305FC3A37BAAB5253CBC358FD33BC86FBFAC88E136C3EF393
8C922575C20878FEF8AB0CBD8570654275F9B96801410E13A8BF9F3ED8AAA72F
5C7A9500A80761EB4462FBD3A0011C660C54301460B63E79F0693352E62DDD7C
2EFF6522A39EA366A1CE0386EAE546EB373AD8BFE8371DF6D76241FB67215DE0
3D0A0EC109B2CD7D74BDCBBBD1700F6BA04CD737FB11A2BFDEA5CDC5AA162C73
26DBFE23D7EEBBCFD2462381BFEFDDC6929E0338CA552181022834F8C869D37B
4EC5FD00A6AA7D8FDBB77AF226E2CB1D5A01056B3050409F9EE6C04188106E21
E6EAE8991FB4355BA1037E6792F80F35A99598E493F910439DB7AC6BB211BE3B""",
"""16A0A6913C5FFB44105C25B5C217249BC8A72D9AF0D7C669B66CB3520D131497
A60EAD1EAE629C3102812FBC17FE681489F4B88705BD9E3DF6587897FF86AE4F
4C23753BFDB59FCB6723910B087C2BEBA379AB418CE54C2FD98DBD8A64798F48
9989DE0C3980B2DA1EFF03A98945947DFFAE0053FD7E62C9C1525F5608693FF7
A359CCA7970143878ED13E510D83B872FDE3E74E869B650728C93146A926D81F
B56A938E8F76F5D617A814926E54A43819815286B3A929A61A64C1D4D6236FFE
3A3D6E5D1D77787A80B1EF30FE06F02DABC908C635E9D16CE15D3DD5F3DDEBEE
F30C2CD930A0835B75889EFCE46868A5CB6D484ABB1178E3867DEDAA81921414
AA34200E2066C50AC5A9E926E4EB2ABFAD7B1D068E88D7A4EC748420DAE63926
CF47E8A911B99FA9C9A4016A378B5AEB8B9AA2C92C1836994A9069D10985B394
7AC24DD27432DE0B4D3D62D9D2EC24CC1F1D9F44B6BFF74085CE3D8E2B23BD3F
9BD704817EE7DC8E2B07D32A02790C8B40F8286802FA0C0707B1CD98F19DE9AF""",
"""984A8ACD327392DF3C16D504AC152BB7484255A9A8E06EE54F4CE61D017B6908
11FA8D1845E72073E775A07FE5C8C028B1FC6E9B8349993D69A058DFA233E9FF
69B2F65D12A80051C823AD81BAA143C958D484E1ED5749F67B21E2D69D7EC6E9
@ -273,43 +359,7 @@ type
RsaPrivateKey = rsa.RsaPrivateKey
RsaPublicKey = rsa.RsaPublicKey
suite "RSA 512/1024/2048/4096 test suite":
test "[rsa512] Private key serialize/deserialize test":
for i in 0..<TestsCount:
var rkey1, rkey2: RsaPrivateKey
var skey2 = newSeq[byte](4096)
var key = RsaPrivateKey.random(rng[], 512).expect("random key")
var skey1 = key.getBytes().expect("bytes")
check key.toBytes(skey2).expect("bytes") > 0
check:
rkey1.init(skey1).isOk()
rkey2.init(skey2).isOk()
var rkey3 = RsaPrivateKey.init(skey1).expect("key initialization")
var rkey4 = RsaPrivateKey.init(skey2).expect("key initialization")
check:
rkey1 == key
rkey2 == key
rkey3 == key
rkey4 == key
test "[rsa1024] Private key serialize/deserialize test":
for i in 0..<TestsCount:
var rkey1, rkey2: RsaPrivateKey
var skey2 = newSeq[byte](4096)
var key = RsaPrivateKey.random(rng[], 1024).expect("random failed")
var skey1 = key.getBytes().expect("bytes")
check key.toBytes(skey2).expect("bytes") > 0
check:
rkey1.init(skey1).isOk()
rkey2.init(skey2).isOk()
var rkey3 = RsaPrivateKey.init(skey1).expect("key initialization")
var rkey4 = RsaPrivateKey.init(skey2).expect("key initialization")
check:
rkey1 == key
rkey2 == key
rkey3 == key
rkey4 == key
suite "RSA 2048/3072/4096 test suite":
test "[rsa2048] Private key serialize/deserialize test":
var rkey1, rkey2: RsaPrivateKey
var skey2 = newSeq[byte](4096)
@ -327,6 +377,23 @@ suite "RSA 512/1024/2048/4096 test suite":
rkey3 == key
rkey4 == key
test "[rsa3072] Private key serialize/deserialize test":
var rkey1, rkey2: RsaPrivateKey
var skey2 = newSeq[byte](4096)
var key = RsaPrivateKey.random(rng[], 3072).expect("random failed")
var skey1 = key.getBytes().expect("bytes")
check key.toBytes(skey2).expect("bytes") > 0
check:
rkey1.init(skey1).isOk()
rkey2.init(skey2).isOk()
var rkey3 = RsaPrivateKey.init(skey1).expect("key initialization")
var rkey4 = RsaPrivateKey.init(skey2).expect("key initialization")
check:
rkey1 == key
rkey2 == key
rkey3 == key
rkey4 == key
test "[rsa4096] Private key serialize/deserialize test":
# This test is too slow to run in debug mode.
when defined(release):
@ -345,42 +412,8 @@ suite "RSA 512/1024/2048/4096 test suite":
rkey2 == key
rkey3 == key
rkey4 == key
test "[rsa512] Public key serialize/deserialize test":
for i in 0..<TestsCount:
var rkey1, rkey2: RsaPublicKey
var skey2 = newSeq[byte](4096)
var pair = RsaKeyPair.random(rng[], 512).expect("random failed")
var skey1 = pair.pubkey().getBytes().expect("bytes")
check:
pair.pubkey.toBytes(skey2).expect("bytes") > 0
rkey1.init(skey1).isOk()
rkey2.init(skey2).isOk()
var rkey3 = RsaPublicKey.init(skey1).expect("key initialization")
var rkey4 = RsaPublicKey.init(skey2).expect("key initialization")
check:
rkey1 == pair.pubkey
rkey2 == pair.pubkey
rkey3 == pair.pubkey
rkey4 == pair.pubkey
test "[rsa1024] Public key serialize/deserialize test":
for i in 0..<TestsCount:
var rkey1, rkey2: RsaPublicKey
var skey2 = newSeq[byte](4096)
var pair = RsaKeyPair.random(rng[], 1024).expect("random failed")
var skey1 = pair.pubkey.getBytes().expect("bytes")
check:
pair.pubkey.toBytes(skey2).expect("bytes") > 0
rkey1.init(skey1).isOk()
rkey2.init(skey2).isOk()
var rkey3 = RsaPublicKey.init(skey1).expect("key initialization")
var rkey4 = RsaPublicKey.init(skey2).expect("key initialization")
check:
rkey1 == pair.pubkey
rkey2 == pair.pubkey
rkey3 == pair.pubkey
rkey4 == pair.pubkey
else:
skip()
test "[rsa2048] Public key serialize/deserialize test":
var rkey1, rkey2: RsaPublicKey
@ -399,6 +432,23 @@ suite "RSA 512/1024/2048/4096 test suite":
rkey3 == pair.pubkey
rkey4 == pair.pubkey
test "[rsa3072] Public key serialize/deserialize test":
var rkey1, rkey2: RsaPublicKey
var skey2 = newSeq[byte](4096)
var pair = RsaKeyPair.random(rng[], 3072).expect("random failed")
var skey1 = pair.pubkey.getBytes().expect("bytes")
check:
pair.pubkey.toBytes(skey2).expect("bytes") > 0
rkey1.init(skey1).isOk()
rkey2.init(skey2).isOk()
var rkey3 = RsaPublicKey.init(skey1).expect("key initialization")
var rkey4 = RsaPublicKey.init(skey2).expect("key initialization")
check:
rkey1 == pair.pubkey
rkey2 == pair.pubkey
rkey3 == pair.pubkey
rkey4 == pair.pubkey
test "[rsa4096] Public key serialize/deserialize test":
when defined(release):
var rkey1, rkey2: RsaPublicKey
@ -416,38 +466,8 @@ suite "RSA 512/1024/2048/4096 test suite":
rkey2 == pair.pubkey
rkey3 == pair.pubkey
rkey4 == pair.pubkey
test "[rsa512] Generate/Sign/Serialize/Deserialize/Verify test":
var message = "message to sign"
for i in 0..<TestsCount:
var kp = RsaKeyPair.random(rng[], 512).expect("RsaKeyPair.random failed")
var sig = kp.seckey.sign(message).expect("signature")
var sersk = kp.seckey.getBytes().expect("bytes")
var serpk = kp.pubkey.getBytes().expect("bytes")
var sersig = sig.getBytes().expect("bytes")
discard RsaPrivateKey.init(sersk).expect("RsaPrivateKey.key initialization")
var pubkey = RsaPublicKey.init(serpk).expect("RsaPublicKey.key initialization")
var csig = RsaSignature.init(sersig).expect("RsaSignature.key initialization")
check csig.verify(message, pubkey) == true
let error = csig.buffer.high
csig.buffer[error] = not(csig.buffer[error])
check csig.verify(message, pubkey) == false
test "[rsa1024] Generate/Sign/Serialize/Deserialize/Verify test":
var message = "message to sign"
for i in 0..<TestsCount:
var kp = RsaKeyPair.random(rng[], 1024).expect("RsaPrivateKey.random failed")
var sig = kp.seckey.sign(message).expect("signature")
var sersk = kp.seckey.getBytes().expect("bytes")
var serpk = kp.pubkey.getBytes().expect("bytes")
var sersig = sig.getBytes().expect("bytes")
discard RsaPrivateKey.init(sersk).expect("key initialization")
var pubkey = RsaPublicKey.init(serpk).expect("key initialization")
var csig = RsaSignature.init(sersig).expect("key initialization")
check csig.verify(message, pubkey) == true
let error = csig.buffer.high
csig.buffer[error] = not(csig.buffer[error])
check csig.verify(message, pubkey) == false
else:
skip()
test "[rsa2048] Generate/Sign/Serialize/Deserialize/Verify test":
var message = "message to sign"
@ -464,10 +484,25 @@ suite "RSA 512/1024/2048/4096 test suite":
csig.buffer[error] = not(csig.buffer[error])
check csig.verify(message, pubkey) == false
test "[rsa3072] Generate/Sign/Serialize/Deserialize/Verify test":
var message = "message to sign"
var kp = RsaKeyPair.random(rng[], 3072).expect("RsaPrivateKey.random failed")
var sig = kp.seckey.sign(message).expect("signature")
var sersk = kp.seckey.getBytes().expect("bytes")
var serpk = kp.pubkey.getBytes().expect("bytes")
var sersig = sig.getBytes().expect("bytes")
discard RsaPrivateKey.init(sersk).expect("key initialization")
var pubkey = RsaPublicKey.init(serpk).expect("key initialization")
var csig = RsaSignature.init(sersig).expect("key initialization")
check csig.verify(message, pubkey) == true
let error = csig.buffer.high
csig.buffer[error] = not(csig.buffer[error])
check csig.verify(message, pubkey) == false
test "[rsa4096] Generate/Sign/Serialize/Deserialize/Verify test":
when defined(release):
var message = "message to sign"
var kp = RsaKeyPair.random(rng[], 2048).expect("RsaPrivateKey.random failed")
var kp = RsaKeyPair.random(rng[], 4096).expect("RsaPrivateKey.random failed")
var sig = kp.seckey.sign(message).expect("signature")
var sersk = kp.seckey.getBytes().expect("bytes")
var serpk = kp.pubkey.getBytes().expect("bytes")
@ -479,8 +514,10 @@ suite "RSA 512/1024/2048/4096 test suite":
let error = csig.buffer.high
csig.buffer[error] = not(csig.buffer[error])
check csig.verify(message, pubkey) == false
else:
skip()
test "[rsa512] Test vectors":
test "[rsa2048] Test vectors":
var prvser = fromHex(stripSpaces(PrivateKeys[0]))
var pubser = fromHex(stripSpaces(PublicKeys[0]))
var seckey = RsaPrivateKey.init(prvser).expect("key initialization")
@ -503,7 +540,7 @@ suite "RSA 512/1024/2048/4096 test suite":
csig.verify(Messages[i], pubkey) == true
csig.verify(Messages[(i + 1) mod 2], pubkey) == false
test "[rsa1024] Test vectors":
test "[rsa3072] Test vectors":
var prvser = fromHex(stripSpaces(PrivateKeys[1]))
var pubser = fromHex(stripSpaces(PublicKeys[1]))
var seckey = RsaPrivateKey.init(prvser).expect("key initialization")
@ -526,7 +563,7 @@ suite "RSA 512/1024/2048/4096 test suite":
csig.verify(Messages[2 + i], pubkey) == true
csig.verify(Messages[2 + (i + 1) mod 2], pubkey) == false
test "[rsa2048] Test vectors":
test "[rsa4096] Test vectors":
var prvser = fromHex(stripSpaces(PrivateKeys[2]))
var pubser = fromHex(stripSpaces(PublicKeys[2]))
var seckey = RsaPrivateKey.init(prvser).expect("key initialization")
@ -549,25 +586,30 @@ suite "RSA 512/1024/2048/4096 test suite":
csig.verify(Messages[4 + i], pubkey) == true
csig.verify(Messages[4 + (i + 1) mod 2], pubkey) == false
test "[rsa4096] Test vectors":
var prvser = fromHex(stripSpaces(PrivateKeys[3]))
var pubser = fromHex(stripSpaces(PublicKeys[3]))
var seckey = RsaPrivateKey.init(prvser).expect("key initialization")
var pubkey = RsaPublicKey.init(pubser).expect("key initialization")
test "[rsa512] not allowed test":
var key1 = RsaPrivateKey.random(rng[], 512)
let prvser = fromHex(stripSpaces(NotAllowedPrivateKeys[0]))
let pubser = fromHex(stripSpaces(NotAllowedPublicKeys[0]))
var key2 = RsaPrivateKey.init(prvser)
var key3 = RsaPublicKey.init(pubser)
check:
seckey.getBytes().expect("bytes") == prvser
var cpubkey = seckey.getKey()
check:
pubkey == cpubkey
pubkey.getBytes().expect("bytes") == cpubkey.getBytes().expect("bytes")
pubkey.getBytes().expect("bytes") == pubser
key1.isErr() == true
key2.isErr() == true
key3.isErr() == true
key1.error == RsaLowSecurityError
key2.error == RsaKeyIncorrectError
key3.error == RsaKeyIncorrectError
for i in 0..1:
var sigser = fromHex(stripSpaces(Signatures[6 + i]))
var sig = RsaSignature.init(sigser).expect("key initialization")
var csig = seckey.sign(Messages[6 + i]).expect("signature")
check:
sig == csig
sig.getBytes().expect("bytes") == csig.getBytes().expect("bytes")
csig.verify(Messages[6 + i], pubkey) == true
csig.verify(Messages[6 + (i + 1) mod 2], pubkey) == false
test "[rsa1024] not allowed test":
var key1 = RsaPrivateKey.random(rng[], 1024)
let prvser = fromHex(stripSpaces(NotAllowedPrivateKeys[1]))
let pubser = fromHex(stripSpaces(NotAllowedPublicKeys[1]))
var key2 = RsaPrivateKey.init(prvser)
var key3 = RsaPublicKey.init(pubser)
check:
key1.isErr() == true
key2.isErr() == true
key3.isErr() == true
key1.error == RsaLowSecurityError
key2.error == RsaKeyIncorrectError
key3.error == RsaKeyIncorrectError