annotate spec/util_hashes_spec.lua @ 13652:a08065207ef0

net.server_epoll: Call :shutdown() on TLS sockets when supported Comment from Matthew: This fixes a potential issue where the Prosody process gets blocked on sockets waiting for them to close. Unlike non-TLS sockets, closing a TLS socket sends layer 7 data, and this can cause problems for sockets which are in the process of being cleaned up. This depends on LuaSec changes which are not yet upstream. From Martijn's original email: So first my analysis of luasec. in ssl.c the socket is put into blocking mode right before calling SSL_shutdown() inside meth_destroy(). My best guess to why this is is because meth_destroy is linked to the __close and __gc methods, which can't exactly be called multiple times and luasec does want to make sure that a tls session is shutdown as clean as possible. I can't say I disagree with this reasoning and don't want to change this behaviour. My solution to this without changing the current behaviour is to introduce a shutdown() method. I am aware that this overlaps in a conflicting way with tcp's shutdown method, but it stays close to the OpenSSL name. This method calls SSL_shutdown() in the current (non)blocking mode of the underlying socket and returns a boolean whether or not the shutdown is completed (matching SSL_shutdown()'s 0 or 1 return values), and returns the familiar ssl_ioerror() strings on error with a false for completion. This error can then be used to determine if we have wantread/wantwrite to finalize things. Once meth_shutdown() has been called once a shutdown flag will be set, which indicates to meth_destroy() that the SSL_shutdown() has been handled by the application and it shouldn't be needed to set the socket to blocking mode. I've left the SSL_shutdown() call in the LSEC_STATE_CONNECTED to prevent TOCTOU if the application reaches a timeout for the shutdown code, which might allow SSL_shutdown() to clean up anyway at the last possible moment. Another thing I've changed to luasec is the call to socket_setblocking() right before calling close(2) in socket_destroy() in usocket.c. According to the latest POSIX[0]: Note that the requirement for close() on a socket to block for up to the current linger interval is not conditional on the O_NONBLOCK setting. Which I read to mean that removing O_NONBLOCK on the socket before close doesn't impact the behaviour and only causes noise in system call tracers. I didn't touch the windows bits of this, since I don't do windows. For the prosody side of things I've made the TLS shutdown bits resemble interface:onwritable(), and put it under a combined guard of self._tls and self.conn.shutdown. The self._tls bit is there to prevent getting stuck on this condition, and self.conn.shutdown is there to prevent the code being called by instances where the patched luasec isn't deployed. The destroy() method can be called from various places and is read by me as the "we give up" error path. To accommodate for these unexpected entrypoints I've added a single call to self.conn:shutdown() to prevent the socket being put into blocking mode. I have no expectations that there is any other use here. Same as previous, the self.conn.shutdown check is there to make sure it's not called on unpatched luasec deployments and self._tls is there to make sure we don't call shutdown() on tcp sockets. I wouldn't recommend logging of the conn:shutdown() error inside close(), since a lot of clients simply close the connection before SSL_shutdown() is done.
author Martijn van Duren <martijn@openbsd.org>
date Thu, 06 Feb 2025 15:04:38 +0000
parents 8b06d7c73090
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
12841
8b06d7c73090 spec: Suppress some harmless luacheck warnings in tests
Matthew Wild <mwild1@gmail.com>
parents: 12836
diff changeset
7 --luacheck: ignore 631
8b06d7c73090 spec: Suppress some harmless luacheck warnings in tests
Matthew Wild <mwild1@gmail.com>
parents: 12836
diff changeset
8
10747
63a89b876407 util.hashes: Use generic name of PBKDF2-HMAC-SHA1 function in tests
Kim Alvefur <zash@zash.se>
parents: 9970
diff changeset
9 describe("PBKDF2-HMAC-SHA1", function ()
9964
f299d4917dd8 util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff changeset
10 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
11 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
12 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
13 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
14 local DK = "0c60c80f961f0e71f3a9b524af6012062fe037a6";
12355
a0ff5c438e9d util.hex: Deprecate to/from in favour of encode/decode, for consistency!
Matthew Wild <mwild1@gmail.com>
parents: 10748
diff changeset
15 assert.equal(DK, hex.encode(hashes.pbkdf2_hmac_sha1(P, S, c)));
9964
f299d4917dd8 util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff changeset
16 end);
f299d4917dd8 util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff changeset
17 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
18 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
19 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
20 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
21 local DK = "ea6c014dc72d6f8ccd1ed92ace1d41f0d8de8957";
12355
a0ff5c438e9d util.hex: Deprecate to/from in favour of encode/decode, for consistency!
Matthew Wild <mwild1@gmail.com>
parents: 10748
diff changeset
22 assert.equal(DK, hex.encode(hashes.pbkdf2_hmac_sha1(P, S, c)));
9964
f299d4917dd8 util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff changeset
23 end);
f299d4917dd8 util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff changeset
24 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
25 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
26 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
27 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
28 local DK = "4b007901b765489abead49d926f721d065a429c1";
12355
a0ff5c438e9d util.hex: Deprecate to/from in favour of encode/decode, for consistency!
Matthew Wild <mwild1@gmail.com>
parents: 10748
diff changeset
29 assert.equal(DK, hex.encode(hashes.pbkdf2_hmac_sha1(P, S, c)));
9964
f299d4917dd8 util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff changeset
30 end);
f299d4917dd8 util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff changeset
31 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
32 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
33 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
34 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
35 local DK = "eefe3d61cd4da4e4e9945b3d6ba2158c2634e984";
12355
a0ff5c438e9d util.hex: Deprecate to/from in favour of encode/decode, for consistency!
Matthew Wild <mwild1@gmail.com>
parents: 10748
diff changeset
36 assert.equal(DK, hex.encode(hashes.pbkdf2_hmac_sha1(P, S, c)));
9964
f299d4917dd8 util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff changeset
37 end);
f299d4917dd8 util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff changeset
38 end);
f299d4917dd8 util.hashes: Add test vectors from RFC 6070 for PBKDF2 (aka SCRAM Hi())
Kim Alvefur <zash@zash.se>
parents:
diff changeset
39
10748
93293891709b util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents: 10747
diff changeset
40 describe("PBKDF2-HMAC-SHA256", function ()
93293891709b util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents: 10747
diff changeset
41 it("test vector 1", function ()
93293891709b util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents: 10747
diff changeset
42 local P = "password";
93293891709b util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents: 10747
diff changeset
43 local S = "salt";
93293891709b util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents: 10747
diff changeset
44 local c = 1
93293891709b util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents: 10747
diff changeset
45 local DK = "120fb6cffcf8b32c43e7225256c4f837a86548c92ccc35480805987cb70be17b";
12355
a0ff5c438e9d util.hex: Deprecate to/from in favour of encode/decode, for consistency!
Matthew Wild <mwild1@gmail.com>
parents: 10748
diff changeset
46 assert.equal(DK, hex.encode(hashes.pbkdf2_hmac_sha256(P, S, c)));
10748
93293891709b util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents: 10747
diff changeset
47 end);
93293891709b util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents: 10747
diff changeset
48 it("test vector 2", function ()
93293891709b util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents: 10747
diff changeset
49 local P = "password";
93293891709b util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents: 10747
diff changeset
50 local S = "salt";
93293891709b util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents: 10747
diff changeset
51 local c = 2
93293891709b util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents: 10747
diff changeset
52 local DK = "ae4d0c95af6b46d32d0adff928f06dd02a303f8ef3c251dfd6e2d85a95474c43";
12355
a0ff5c438e9d util.hex: Deprecate to/from in favour of encode/decode, for consistency!
Matthew Wild <mwild1@gmail.com>
parents: 10748
diff changeset
53 assert.equal(DK, hex.encode(hashes.pbkdf2_hmac_sha256(P, S, c)));
10748
93293891709b util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents: 10747
diff changeset
54 end);
93293891709b util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents: 10747
diff changeset
55 end);
93293891709b util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents: 10747
diff changeset
56
93293891709b util.hashes: Fix output length of PBKDF2-HMAC-SHA256
Kim Alvefur <zash@zash.se>
parents: 10747
diff changeset
57
12564
36e769c64054 util.hashes: Add SHA3 bindings
Kim Alvefur <zash@zash.se>
parents: 12355
diff changeset
58 describe("SHA-3", function ()
36e769c64054 util.hashes: Add SHA3 bindings
Kim Alvefur <zash@zash.se>
parents: 12355
diff changeset
59 describe("256", function ()
36e769c64054 util.hashes: Add SHA3 bindings
Kim Alvefur <zash@zash.se>
parents: 12355
diff changeset
60 it("works", function ()
36e769c64054 util.hashes: Add SHA3 bindings
Kim Alvefur <zash@zash.se>
parents: 12355
diff changeset
61 local expected = "a7ffc6f8bf1ed76651c14756a061d662f580ff4de43b49fa82d80a4b80f8434a"
36e769c64054 util.hashes: Add SHA3 bindings
Kim Alvefur <zash@zash.se>
parents: 12355
diff changeset
62 assert.equal(expected, hashes.sha3_256("", true));
36e769c64054 util.hashes: Add SHA3 bindings
Kim Alvefur <zash@zash.se>
parents: 12355
diff changeset
63 end);
36e769c64054 util.hashes: Add SHA3 bindings
Kim Alvefur <zash@zash.se>
parents: 12355
diff changeset
64 end);
36e769c64054 util.hashes: Add SHA3 bindings
Kim Alvefur <zash@zash.se>
parents: 12355
diff changeset
65 describe("512", function ()
36e769c64054 util.hashes: Add SHA3 bindings
Kim Alvefur <zash@zash.se>
parents: 12355
diff changeset
66 it("works", function ()
36e769c64054 util.hashes: Add SHA3 bindings
Kim Alvefur <zash@zash.se>
parents: 12355
diff changeset
67 local expected = "a69f73cca23a9ac5c8b567dc185a756e97c982164fe25859e0d1dcc1475c80a615b2123af1f5f94c11e3e9402c3ac558f500199d95b6d3e301758586281dcd26"
36e769c64054 util.hashes: Add SHA3 bindings
Kim Alvefur <zash@zash.se>
parents: 12355
diff changeset
68 assert.equal(expected, hashes.sha3_512("", true));
36e769c64054 util.hashes: Add SHA3 bindings
Kim Alvefur <zash@zash.se>
parents: 12355
diff changeset
69 end);
36e769c64054 util.hashes: Add SHA3 bindings
Kim Alvefur <zash@zash.se>
parents: 12355
diff changeset
70 end);
36e769c64054 util.hashes: Add SHA3 bindings
Kim Alvefur <zash@zash.se>
parents: 12355
diff changeset
71 end);
36e769c64054 util.hashes: Add SHA3 bindings
Kim Alvefur <zash@zash.se>
parents: 12355
diff changeset
72
12836
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
73 describe("HKDF", function ()
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
74 describe("HMAC-SHA256", function ()
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
75 describe("RFC 5869", function ()
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
76 it("test vector A.1", function ()
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
77 local ikm = hex.decode("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
78 local salt = hex.decode("000102030405060708090a0b0c");
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
79 local info = hex.decode("f0f1f2f3f4f5f6f7f8f9");
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
80
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
81 local expected = "3cb25f25faacd57a90434f64d0362f2a2d2d0a90cf1a5a4c5db02d56ecc4c5bf34007208d5b887185865";
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
82
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
83 local ret = hashes.hkdf_hmac_sha256(42, ikm, salt, info);
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
84 assert.equal(expected, hex.encode(ret));
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
85 end);
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
86
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
87 it("test vector A.2", function ()
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
88 local ikm = hex.decode("000102030405060708090a0b0c0d0e0f101112131415161718191a1b1c1d1e1f202122232425262728292a2b2c2d2e2f303132333435363738393a3b3c3d3e3f404142434445464748494a4b4c4d4e4f");
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
89 local salt = hex.decode("606162636465666768696a6b6c6d6e6f707172737475767778797a7b7c7d7e7f808182838485868788898a8b8c8d8e8f909192939495969798999a9b9c9d9e9fa0a1a2a3a4a5a6a7a8a9aaabacadaeaf");
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
90 local info = hex.decode("b0b1b2b3b4b5b6b7b8b9babbbcbdbebfc0c1c2c3c4c5c6c7c8c9cacbcccdcecfd0d1d2d3d4d5d6d7d8d9dadbdcdddedfe0e1e2e3e4e5e6e7e8e9eaebecedeeeff0f1f2f3f4f5f6f7f8f9fafbfcfdfeff");
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
91
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
92 local expected = "b11e398dc80327a1c8e7f78c596a49344f012eda2d4efad8a050cc4c19afa97c59045a99cac7827271cb41c65e590e09da3275600c2f09b8367793a9aca3db71cc30c58179ec3e87c14c01d5c1f3434f1d87";
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
93
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
94 local ret = hashes.hkdf_hmac_sha256(82, ikm, salt, info);
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
95 assert.equal(expected, hex.encode(ret));
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
96 end);
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
97
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
98 it("test vector A.3", function ()
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
99 local ikm = hex.decode("0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b0b");
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
100 local salt = "";
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
101 local info = "";
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
102
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
103 local expected = "8da4e775a563c18f715f802a063c5a31b8a11f5c5ee1879ec3454e5f3c738d2d9d201395faa4b61a96c8";
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
104
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
105 local ret = hashes.hkdf_hmac_sha256(42, ikm, salt, info);
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
106 assert.equal(expected, hex.encode(ret));
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
107 end);
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
108 end);
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
109 end);
dbe9781fd278 util.hashes: Add HKDF-HMAC-SHA256/HKDF-HMAC-SHA384
Matthew Wild <mwild1@gmail.com>
parents: 12564
diff changeset
110 end);