Software /
code /
prosody
Comparison
spec/util_hashes_spec.lua @ 12355:a0ff5c438e9d
util.hex: Deprecate to/from in favour of encode/decode, for consistency!
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 04 Mar 2022 15:22:45 +0000 |
parent | 10748:93293891709b |
child | 12564:36e769c64054 |
comparison
equal
deleted
inserted
replaced
12354:3ce3633527af | 12355:a0ff5c438e9d |
---|---|
8 it("test vector 1", function () | 8 it("test vector 1", function () |
9 local P = "password" | 9 local P = "password" |
10 local S = "salt" | 10 local S = "salt" |
11 local c = 1 | 11 local c = 1 |
12 local DK = "0c60c80f961f0e71f3a9b524af6012062fe037a6"; | 12 local DK = "0c60c80f961f0e71f3a9b524af6012062fe037a6"; |
13 assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha1(P, S, c))); | 13 assert.equal(DK, hex.encode(hashes.pbkdf2_hmac_sha1(P, S, c))); |
14 end); | 14 end); |
15 it("test vector 2", function () | 15 it("test vector 2", function () |
16 local P = "password" | 16 local P = "password" |
17 local S = "salt" | 17 local S = "salt" |
18 local c = 2 | 18 local c = 2 |
19 local DK = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957"; | 19 local DK = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957"; |
20 assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha1(P, S, c))); | 20 assert.equal(DK, hex.encode(hashes.pbkdf2_hmac_sha1(P, S, c))); |
21 end); | 21 end); |
22 it("test vector 3", function () | 22 it("test vector 3", function () |
23 local P = "password" | 23 local P = "password" |
24 local S = "salt" | 24 local S = "salt" |
25 local c = 4096 | 25 local c = 4096 |
26 local DK = "4b007901b765489abead49d926f721d065a429c1"; | 26 local DK = "4b007901b765489abead49d926f721d065a429c1"; |
27 assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha1(P, S, c))); | 27 assert.equal(DK, hex.encode(hashes.pbkdf2_hmac_sha1(P, S, c))); |
28 end); | 28 end); |
29 it("test vector 4 #SLOW", function () | 29 it("test vector 4 #SLOW", function () |
30 local P = "password" | 30 local P = "password" |
31 local S = "salt" | 31 local S = "salt" |
32 local c = 16777216 | 32 local c = 16777216 |
33 local DK = "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984"; | 33 local DK = "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984"; |
34 assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha1(P, S, c))); | 34 assert.equal(DK, hex.encode(hashes.pbkdf2_hmac_sha1(P, S, c))); |
35 end); | 35 end); |
36 end); | 36 end); |
37 | 37 |
38 describe("PBKDF2-HMAC-SHA256", function () | 38 describe("PBKDF2-HMAC-SHA256", function () |
39 it("test vector 1", function () | 39 it("test vector 1", function () |
40 local P = "password"; | 40 local P = "password"; |
41 local S = "salt"; | 41 local S = "salt"; |
42 local c = 1 | 42 local c = 1 |
43 local DK = "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b"; | 43 local DK = "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b"; |
44 assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha256(P, S, c))); | 44 assert.equal(DK, hex.encode(hashes.pbkdf2_hmac_sha256(P, S, c))); |
45 end); | 45 end); |
46 it("test vector 2", function () | 46 it("test vector 2", function () |
47 local P = "password"; | 47 local P = "password"; |
48 local S = "salt"; | 48 local S = "salt"; |
49 local c = 2 | 49 local c = 2 |
50 local DK = "ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43"; | 50 local DK = "ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43"; |
51 assert.equal(DK, hex.to(hashes.pbkdf2_hmac_sha256(P, S, c))); | 51 assert.equal(DK, hex.encode(hashes.pbkdf2_hmac_sha256(P, S, c))); |
52 end); | 52 end); |
53 end); | 53 end); |
54 | 54 |
55 | 55 |