Software /
code /
prosody
Annotate
spec/util_hashes_spec.lua @ 9970:4a43feb9ab15
Backed out changeset 61bc5c52c941
luaL_buffinitsize is only available in Lua 5.2+
author | Kim Alvefur <zash@zash.se> |
---|---|
date | Sun, 21 Apr 2019 00:59:36 +0200 |
parent | 9969:61bc5c52c941 |
child | 10747:63a89b876407 |
rev | line source |
---|---|
9964
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
1 -- Test vectors from RFC 6070 |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
2 local hashes = require "util.hashes"; |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
3 local hex = require "util.hex"; |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
4 |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
5 -- Also see spec for util.hmac where HMAC test cases reside |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
6 |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
7 describe("PBKDF2-SHA1", function () |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
8 it("test vector 1", function () |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
9 local P = "password" |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
10 local S = "salt" |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
11 local c = 1 |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
12 local DK = "0c60c80f961f0e71f3a9b524af6012062fe037a6"; |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
13 assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c))); |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
14 end); |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
15 it("test vector 2", function () |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
16 local P = "password" |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
17 local S = "salt" |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
18 local c = 2 |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
19 local DK = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957"; |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
20 assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c))); |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
21 end); |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
22 it("test vector 3", function () |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
23 local P = "password" |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
24 local S = "salt" |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
25 local c = 4096 |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
26 local DK = "4b007901b765489abead49d926f721d065a429c1"; |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
27 assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c))); |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
28 end); |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
29 it("test vector 4 #SLOW", function () |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
30 local P = "password" |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
31 local S = "salt" |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
32 local c = 16777216 |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
33 local DK = "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984"; |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
34 assert.equal(DK, hex.to(hashes.scram_Hi_sha1(P, S, c))); |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
35 end); |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
36 end); |
f299d4917dd8
util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff
changeset
|
37 |