-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
177 lines (167 loc) · 13.4 KB
/
test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
const test = require('brittle')
const argon2 = require('./')
// const input = Buffer.from('359320f8edc5c8b9148c90cab741f69f1958f1806a997d6949d953ddc26f64bfb1a35e7483f7614dff97a9f9d5528a4a305b77494846ca5099af62b2c2320fc20000000000000000', 'hex')
const string = 'e125cee61c8cb7778d9e5ad0a6f5d978ce9f84de213a8556d9ffe202020ab4a6ed9074a4eb3416f9b168f137510f3a30b70b96cbfa219ff99f6c6eaffb15c06b60e00cc2890277f0fd3c622115772f7048adaebed86e'
const input = Buffer.from(string, 'hex')
const nonce = Buffer.from('f1192dd5dc2368b9cd421338b22433455ee0a3699f9379a08b9650ea2c126f0d', 'hex')
const key = Buffer.alloc(0)
const ad = Buffer.alloc(0)
const tests = [
{
string: 'e125cee61c8cb7778d9e5ad0a6f5d978ce9f84de213a8556d9ffe202020ab4a6ed9074a4eb3416f9b168f137510f3a30b70b96cbfa219ff99f6c6eaffb15c06b60e00cc2890277f0fd3c622115772f7048adaebed86e',
nonce: 'f1192dd5dc2368b9cd421338b22433455ee0a3699f9379a08b9650ea2c126f0d',
outlen: 256,
passes: 4,
memory: 766,
type: argon2.ARGON2I,
exp: '50f3f7f14151ee8e9cf83a822247fd1c05c26964ada82bb15ac10601e0f94fac23813b3970eddddee3484aa04ae5642041129cedca5b2358fa07e54e64bb2c45d6e5f677621fc071eeed6c3b63b0a244f312dc7c1cfc4dc89bb7b903cde1aba8cac27c381a36c2f849539505a21eeaa4708405092e5b4e801abc80fb1a3bf5e7eba716a86aabc90689fa3a3756d89bbe20b4d637347893bfe1a119ab955b8a2749e8589d5aca25ae2be752b00c1b4b4a97c5897f1a51416d58b70af7fe9ea6f4022613acf1ef1e281b920fa61fb71a996851b5f495d30455afbb32e42cb872f7e05d39415e4afb03f921e0db8eb8cd843668869f55a9c5b0aea7fb592f61c0ed'
},
{
string: '92263cbf6ac376499f68a4289d3bb59e5a22335eba63a32e6410249155b956b6a3b48d4a44906b18b897127300b375b8f834f1ceffc70880a885f47c33876717e392be57f7da3ae58da4fd1f43daa7e44bb82d3717af4319349c24cd31e46d295856b0441b6b289992a11ced1cc3bf3011604590244a3eb737ff221129215e4e4347f4915d41292b5173d196eb9add693be5319fdadc242906178bb6c0286c9b6ca6012746711f58c8c392016b2fdfc09c64f0f6b6ab7b',
nonce: '3b840e20e9555e9fb031c4ba1f1747ce25cc1d0ff664be676b9b4a90641ff194',
outlen: 249,
passes: 3,
memory: 7994791 >> 10,
type: argon2.ARGON2I,
exp: 'e9aa073b0b872f15c083d1d7ce52c09f493b827ca78f13a06c1721b45b1e17b24c04e19fe869333135360197a7eb55994fee3e8d9680aedfdf7674f3ad7b84d59d7eab03579ffc10c7093093bc48ec84252aa1b30f40f5e838f1443e15e2772a39f4e774eb052097e8881e94f15457b779fa2af2bbc9a993687657c7704ac8a37c25c1df4289eb4c70da45f2fd46bc0f78259767d3dd478a7c369cf866758bc36d9bd8e2e3c9fb0cf7fd6073ebf630c1f67fa7d303c07da40b36749d157ea37965fef810f2ea05ae6fc7d96a8f3470d73e15b22b42e8d6986dbfe5303256b2b3560372c4452ffb2a04fb7c6691489f70cb46831be0679117f7'
},
{
string: '027b6d8e8c8c474e9b69c7d9ed4f9971e8e1ce2f6ba95048414c3970f0f09b70e3b6c5ae05872b3d8678705b7d381829c351a5a9c88c233569b35d6b0b809df44b6451a9c273f1150e2ef8a0b5437eb701e373474cd44b97ef0248ebce2ca0400e1b53f3d86221eca3f18eb45b702b9172440f774a82cbf1f6f525df30a6e293c873cce69bb078ed1f0d31e7f9b8062409f37f19f8550aae',
nonce: 'eb2a3056a09ad2d7d7f975bcd707598f24cd32518cde3069f2e403b34bfee8a5',
outlen: 64,
passes: 4,
memory: 1397645 >> 10,
type: argon2.ARGON2I,
exp: 'adb256ab1a27d2e857ca82c3fc8d8844d4d5233999756aa61ea56dad3332d84121c21ffd6ee1bf1b6ebf8df60fc17209f487a8c3b230257ac46defc25f4d3574'
},
{
string: '4a857e2ee8aa9b6056f2424e84d24a72473378906ee04a46cb05311502d5250b82ad86b83c8f20a23dbb74f6da60b0b6ecffd67134d45946ac8ebfb3064294bc097d43ced68642bfb8bbbdd0f50b30118f5e',
nonce: '39d82eef32010b8b79cc5ba88ed539fbaba741100f2edbeca7cc171ffeabf258',
outlen: 190,
passes: 3,
memory: 1432947 >> 10,
type: argon2.ARGON2I,
exp: 'c121209f0ba70aed93d49200e5dc82cce013cef25ea31e160bf8db3cf448a59d1a56f6c19259e18ea020553cb75781761d112b2d949a297584c65e60df95ad89c4109825a3171dc6f20b1fd6b0cdfd194861bc2b414295bee5c6c52619e544abce7d520659c3d51de2c60e89948d830695ab38dcb75dd7ab06a4770dd4bc7c8f335519e04b038416b1a7dbd25c026786a8105c5ffe7a0931364f0376ae5772be39b51d91d3281464e0f3a128e7155a68e87cf79626ffca0b2a3022fc8420'
},
{
string: 'c7b09aec680e7b42fedd7fc792e78b2f6c1bea8f4a884320b648f81e8cf515e8ba9dcfb11d43c4aae114c1734aa69ca82d44998365db9c93744fa28b63fd16000e8261cbbe083e7e2da1e5f696bde0834fe53146d7e0e35e7de9920d041f5a5621aabe02da3e2b09b405b77937efef3197bd5772e41fdb73fb5294478e45208063b5f58e089dbeb6d6342a909c1307b3fff5fe2cf4da56bdae50848f',
nonce: '039c056d933b475032777edbaffac50f143f64c123329ed9cf59e3b65d3f43b6',
outlen: 178,
passes: 3,
memory: 4886999 >> 10,
type: argon2.ARGON2I,
exp: '91c337ce8918a5805a59b00bd1819d3eb4356807cbd2a80b271c4b482dce03f5b02ae4eb831ff668cbb327b93c300b41da4852e5547bea8342d518dd9311aaeb5f90eccf66d548f9275631f0b1fd4b299cec5d2e86a59e55dc7b3afab6204447b21d1ef1da824abaf31a25a0d6135c4fe81d34a06816c8a6eab19141f5687108500f3719a862af8c5fee36e130c69921e11ce83dfc72c5ec3b862c1bccc5fd63ad57f432fbcca6f9e18d5a59015950cdf053'
},
// {
// string: "b540beb016a5366524d4605156493f9874514a5aa58818cd0c6dfffaa9e90205f17b",
// nonce: "44071f6d181561670bda728d43fb79b443bb805afdebaf98622b5165e01b15fb",
// outlen: 231,
// passes: 2,
// memory: 1631659 >> 10,
// type: argon2.ARGON2I,
// exp: ""
// },
{
string: 'a14975c26c088755a8b715ff2528d647cd343987fcf4aa25e7194a8417fb2b4b3f7268da9f3182b4cfb22d138b2749d673a47ecc7525dd15a0a3c66046971784bb63d7eae24cc84f2631712075a10e10a96b0e0ee67c43e01c423cb9c44e5371017e9c496956b632158da3fe12addecb88912e6759bc37f9af2f45af72c5cae3b179ffb676a697de6ebe45cd4c16d4a9d642d29ddc0186a0a48cb6cd62bfc3dd229d313b301560971e740e2cf1f99a9a090a5b283f35475057e96d7064e2e0fc81984591068d55a3b4169f22cccb0745a2689407ea1901a0a766eb99',
nonce: '3d968b2752b8838431165059319f3ff8910b7b8ecb54ea01d3f54769e9d98daf',
outlen: 167,
passes: 3,
memory: 1784128 >> 10,
type: argon2.ARGON2I,
exp: 'e942951dfbc2d508294b10f9e97b47d0cd04e668a043cb95679cc1139df7c27cd54367688725be9d069f5704c12223e7e4ca181fbd0bed18bb4634795e545a6c04a7306933a41a794baedbb628d41bc285e0b9084055ae136f6b63624c874f5a1e1d8be7b0b7227a171d2d7ed578d88bfdcf18323198962d0dcad4126fd3f21adeb1e11d66252ea0c58c91696e91031bfdcc2a9dc0e028d17b9705ba2d7bcdcd1e3ba75b4b1fea'
}
]
const tests_id = [
{
string: 'a347ae92bce9f80f6f595a4480fc9c2fe7e7d7148d371e9487d75f5c23008ffae065577a928febd9b1973a5a95073acdbeb6a030cfc0d79caa2dc5cd011cef02c08da232d76d52dfbca38ca8dcbd665b17d1665f7cf5fe59772ec909733b24de97d6f58d220b20c60d7c07ec1fd93c52c31020300c6c1facd77937a597c7a6',
nonce: '5541fbc995d5c197ba290346d2c559dedf405cf97e5f95482143202f9e74f5c2',
outlen: 155,
passes: 5,
type: argon2.ARGON2ID,
memory: 7256678 >> 10,
exp: '18acec5d6507739f203d1f5d9f1d862f7c2cdac4f19d2bdff64487e60d969e3ced615337b9eec6ac4461c6ca07f0939741e57c24d0005c7ea171a0ee1e7348249d135b38f222e4dad7b9a033ed83f5ca27277393e316582033c74affe2566a2bea47f91f0fd9fe49ece7e1f79f3ad6e9b23e0277c8ecc4b313225748dd2a80f5679534a0700e246a79a49b3f74eb89ec6205fe1eeb941c73b1fcf1'
},
{
string: 'e125cee61c8cb7778d9e5ad0a6f5d978ce9f84de213a8556d9ffe202020ab4a6ed9074a4eb3416f9b168f137510f3a30b70b96cbfa219ff99f6c6eaffb15c06b60e00cc2890277f0fd3c622115772f7048adaebed86e',
nonce: 'f1192dd5dc2368b9cd421338b22433455ee0a3699f9379a08b9650ea2c126f0d',
outlen: 250,
passes: 4,
type: argon2.ARGON2ID,
memory: 7849083 >> 10,
exp: '26bab5f101560e48c711da4f05e81f5a3802b7a93d5155b9cab153069cc42b8e9f910bfead747652a0708d70e4de0bada37218bd203a1201c36b42f9a269b675b1f30cfc36f35a3030e9c7f57dfba0d341a974c1886f708c3e8297efbfe411bb9d51375264bd7c70d57a8a56fc9de2c1c97c08776803ec2cd0140bba8e61dc0f4ad3d3d1a89b4b710af81bfe35a0eea193e18a6da0f5ec05542c9eefc4584458e1da715611ba09617384748bd43b9bf1f3a6df4ecd091d0875e08d6e2fd8a5c7ce08904b5160cd38167b76ec76ef2d310049055a564da23d4ebd2b87e421cc33c401e12d5cd8d936c9baf75ebdfb557d342d2858fc781da31860'
},
{
string: '92263cbf6ac376499f68a4289d3bb59e5a22335eba63a32e6410249155b956b6a3b48d4a44906b18b897127300b375b8f834f1ceffc70880a885f47c33876717e392be57f7da3ae58da4fd1f43daa7e44bb82d3717af4319349c24cd31e46d295856b0441b6b289992a11ced1cc3bf3011604590244a3eb737ff221129215e4e4347f4915d41292b5173d196eb9add693be5319fdadc242906178bb6c0286c9b6ca6012746711f58c8c392016b2fdfc09c64f0f6b6ab7b',
nonce: '3b840e20e9555e9fb031c4ba1f1747ce25cc1d0ff664be676b9b4a90641ff194',
outlen: 249,
passes: 3,
type: argon2.ARGON2ID,
memory: 7994791 >> 10,
exp: '6eb45e668582d63788ca8f6e930ca60b045a795fca987344f9a7a135aa3b5132b50a34a3864c26581f1f56dd0bcbfafbfa92cd9bff6b24a734cfe88f854aef4bda0a7983120f44936e8ff31d29728ac08ccce6f3f916b3c63962755c23a1fa9bb4e8823fc867bfd18f28980d94bc5874423ab7f96cc0ab78d8fa21fbd00cd3a1d96a73fa439ccc3fc4eab1590677b06cc78b0f674dfb680f23022fb902022dd8620803229c6ddf79a8156ccfce48bbd76c05ab670634f206e5b2e896230baa74a856964dbd8511acb71d75a1506766a125d8ce037f1db72086ebc3bccaefbd8cd9380167c2530386544ebfbeadbe237784d102bb92a10fd242'
},
// {
// string: "027b6d8e8c8c474e9b69c7d9ed4f9971e8e1ce2f6ba95048414c3970f0f09b70e3b6c5ae05872b3d8678705b7d381829c351a5a9c88c233569b35d6b0b809df44b6451a9c273f1150e2ef8a0b5437eb701e373474cd44b97ef0248ebce2ca0400e1b53f3d86221eca3f18eb45b702b9172440f774a82cbf1f6f525df30a6e293c873cce69bb078ed1f0d31e7f9b8062409f37f19f8550aae",
// nonce: "eb2a3056a09ad2d7d7f975bcd707598f24cd32518cde3069f2e403b34bfee8a5",
// outlen: 5,
// passes: 4,
// type: argon2.ARGON2ID,
// memory: 1397645 >> 10
// },
{
string: '4a857e2ee8aa9b6056f2424e84d24a72473378906ee04a46cb05311502d5250b82ad86b83c8f20a23dbb74f6da60b0b6ecffd67134d45946ac8ebfb3064294bc097d43ced68642bfb8bbbdd0f50b30118f5e',
nonce: '39d82eef32010b8b79cc5ba88ed539fbaba741100f2edbeca7cc171ffeabf258',
outlen: 190,
passes: 3,
type: argon2.ARGON2ID,
memory: 1432947 >> 10,
exp: '08d8cd330c57e1b4643241d05bb468ba4ee4e932cd0858816be9ef15360b27bbd06a87130ee92222be267a29b81f5ae8fe8613324cfc4832dc49387fd0602f1c57b4d0f3855db94fb7e12eb05f9a484aed4a4307abf586cd3d55c809bc081541e00b682772fb2066504ff935b8ebc551a2083882f874bc0fae68e56848ae34c91097c3bf0cca8e75c0797eef3efde3f75e005815018db3cf7c109a812264c4de69dcb22322dbbcfa447f5b00ecd1b04a7be1569c8e556adb7bba48adf81d'
},
{
string: 'c7b09aec680e7b42fedd7fc792e78b2f6c1bea8f4a884320b648f81e8cf515e8ba9dcfb11d43c4aae114c1734aa69ca82d44998365db9c93744fa28b63fd16000e8261cbbe083e7e2da1e5f696bde0834fe53146d7e0e35e7de9920d041f5a5621aabe02da3e2b09b405b77937efef3197bd5772e41fdb73fb5294478e45208063b5f58e089dbeb6d6342a909c1307b3fff5fe2cf4da56bdae50848f',
nonce: '039c056d933b475032777edbaffac50f143f64c123329ed9cf59e3b65d3f43b6',
outlen: 178,
passes: 3,
type: argon2.ARGON2ID,
memory: 4886999 >> 10,
exp: 'd6e9d6cabd42fb9ba7162fe9b8e41d59d3c7034756cb460c9affe393308bd0225ce0371f2e6c3ca32aca2002bf2d3909c6b6e7dfc4a00e850ff4f570f8f749d4bb6f0091e554be67a9095ae1eefaa1a933316cbec3c2fd4a14a5b6941bda9b7eabd821d79abde2475a53af1a8571c7ee46460be415882e0b393f48c12f740a6a72cba9773000602e13b40d3dfa6ac1d4ec43a838b7e3e165fecad4b2498389e60a3ff9f0f8f4b9fca1126e64f49501e38690'
},
{
string: 'b540beb016a5366524d4605156493f9874514a5aa58818cd0c6dfffaa9e90205f17b',
nonce: '44071f6d181561670bda728d43fb79b443bb805afdebaf98622b5165e01b15fb',
outlen: 231,
passes: 1,
type: argon2.ARGON2ID,
memory: 1631659 >> 10,
exp: '7fb72409b0987f8190c3729710e98c3f80c5a8727d425fdcde7f3644d467fe973f5b5fee683bd3fce812cb9ae5e9921a2d06c2f1905e4e839692f2b934b682f11a2fe2b90482ea5dd234863516dba6f52dc0702d324ec77d860c2e181f84472bd7104fedce071ffa93c5309494ad51623d214447a7b2b1462dc7d5d55a1f6fd5b54ce024118d86f0c6489d16545aaa87b6689dad9f2fb47fda9894f8e12b87d978b483ccd4cc5fd9595cdc7a818452f915ce2f7df95ec12b1c72e3788d473441d884f9748eb14703c21b45d82fd667b85f5b2d98c13303b3fe76285531a826b6fc0fe8e3dddecf'
},
{
string: 'a14975c26c088755a8b715ff2528d647cd343987fcf4aa25e7194a8417fb2b4b3f7268da9f3182b4cfb22d138b2749d673a47ecc7525dd15a0a3c66046971784bb63d7eae24cc84f2631712075a10e10a96b0e0ee67c43e01c423cb9c44e5371017e9c496956b632158da3fe12addecb88912e6759bc37f9af2f45af72c5cae3b179ffb676a697de6ebe45cd4c16d4a9d642d29ddc0186a0a48cb6cd62bfc3dd229d313b301560971e740e2cf1f99a9a090a5b283f35475057e96d7064e2e0fc81984591068d55a3b4169f22cccb0745a2689407ea1901a0a766eb99',
nonce: '3d968b2752b8838431165059319f3ff8910b7b8ecb54ea01d3f54769e9d98daf',
outlen: 167,
passes: 3,
type: argon2.ARGON2ID,
memory: 1784128 >> 10,
exp: '4e702bc5f891df884c6ddaa243aa846ce3c087fe930fef0f36b3c2be34164ccc295db509254743f18f947159c813bcd5dd8d94a3aec93bbe57605d1fad1aef1112687c3d4ef1cb329d21f1632f626818d766915d886e8d819e4b0b9c9307f4b6afc081e13b0cf31db382ff1bf05a16aac7af696336d75e99f82163e0f371e1d25c4add808e215697ad3f779a51a462f8bf52610af21fc69dba6b072606f2dabca7d4ae1d91d919'
}
]
test('argon2i', t => {
for (const test of tests) {
const input = Buffer.from(test.string, 'hex')
const nonce = Buffer.from(test.nonce.slice(0, 32), 'hex')
const buf = argon2(input, nonce, key, ad, 'binary', test)
const exp = Buffer.from(test.exp, 'hex')
t.alike(buf, new Uint8Array(exp))
}
})
test('argon2id', t => {
for (const test of tests_id) {
const input = Buffer.from(test.string, 'hex')
const nonce = Buffer.from(test.nonce.slice(0, 32), 'hex')
const buf = argon2(input, nonce, key, ad, 'binary', test)
const exp = Buffer.from(test.exp, 'hex')
t.alike(buf, new Uint8Array(Buffer.from(test.exp, 'hex')))
}
})
// const buf = Buffer.from(argon2(input, nonce.subarray(0, 16), key, ad, { outlen: 256, passes: 4, memory: 766 }))
// console.log(buf.toString('hex'))
// d3bf532267a4c4c10475c37f5d68cb8730311bc5c9c20f9b8d441e0386e9d02b9a761f78c349f9ae7465750f6c8136d8d51aa781adb5f21e673bcf3dbe28aa3419eea9638a9eed36d5225ae6dbc374251b83320304435d1aedf1b66f01b72a0b1d11c5af166129aa002180f4b0f57877eda373e35d39fe2cb7b12fa086405941