hpke 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +375 -0
- package/README.md +5 -2
- package/package.json +35 -10
- package/pkg/node/.gitignore +1 -0
- package/pkg/node/LICENSE +375 -0
- package/pkg/node/README.md +83 -0
- package/{hpke_dispatch.d.ts → pkg/node/hpke_dispatch.d.ts} +42 -42
- package/{hpke_dispatch.js → pkg/node/hpke_dispatch.js} +122 -113
- package/pkg/node/hpke_dispatch_bg.wasm +0 -0
- package/pkg/node/hpke_dispatch_bg.wasm.d.ts +32 -0
- package/pkg/node/index.js +32 -0
- package/pkg/node/index.js.map +7 -0
- package/pkg/node/index.spec.js +59 -0
- package/pkg/node/index.spec.js.map +7 -0
- package/pkg/node/index.spec.mjs +4625 -0
- package/pkg/node/index.spec.mjs.map +7 -0
- package/pkg/node/index.spec.ts +82 -0
- package/pkg/node/module.mjs +582 -0
- package/pkg/node/module.mjs.map +7 -0
- package/pkg/node/package.json +21 -0
- package/pkg/node/tests.js +57 -0
- package/pkg/web/.gitignore +1 -0
- package/pkg/web/LICENSE +375 -0
- package/pkg/web/README.md +83 -0
- package/pkg/web/hpke_dispatch.d.ts +297 -0
- package/pkg/web/hpke_dispatch.js +852 -0
- package/pkg/web/hpke_dispatch_bg.wasm +0 -0
- package/pkg/web/hpke_dispatch_bg.wasm.d.ts +32 -0
- package/pkg/web/index.mjs +2 -0
- package/pkg/web/index.mjs.map +7 -0
- package/pkg/web/index.ts +5 -0
- package/pkg/web/package.json +22 -0
- package/hpke_dispatch_bg.wasm +0 -0
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { assert } from "chai";
|
|
2
|
+
import { Keypair, Aead, Kdf, Kem, Config } from ".";
|
|
3
|
+
import { TextEncoder, TextDecoder } from "util";
|
|
4
|
+
|
|
5
|
+
describe("HPKE", () => {
|
|
6
|
+
describe("Config", () => {
|
|
7
|
+
it("throws when the algorithms specified are invalid", () => {
|
|
8
|
+
const [aead, kdf, kem] = [100, 100, 100];
|
|
9
|
+
|
|
10
|
+
assert(!(aead in Aead));
|
|
11
|
+
assert(!(kdf in Kdf));
|
|
12
|
+
assert(!(kem in Kem));
|
|
13
|
+
|
|
14
|
+
assert.throws(() => Config.try_from_ids(aead, kdf, kem));
|
|
15
|
+
});
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe("Keypair", () => {
|
|
19
|
+
it("generates a (65, 32)-byte keypair for Kem.DhP256HkdfSha256", () => {
|
|
20
|
+
const keypair = new Keypair(Kem.DhP256HkdfSha256);
|
|
21
|
+
assert.equal(keypair.public_key.length, 65);
|
|
22
|
+
assert.equal(keypair.private_key.length, 32);
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("generates a (32, 32)-byte keypair for Kem.X25519HkdfSha256", () => {
|
|
26
|
+
const keypair = new Keypair(Kem.X25519HkdfSha256);
|
|
27
|
+
assert.equal(keypair.public_key.length, 32);
|
|
28
|
+
assert.equal(keypair.private_key.length, 32);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("throws when provided an invalid Kem", () => {
|
|
32
|
+
assert.throws(() => new Keypair(1000));
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
describe("Round trips", () => {
|
|
37
|
+
const decoder = new TextDecoder();
|
|
38
|
+
const encoder = new TextEncoder();
|
|
39
|
+
|
|
40
|
+
const startMessage = "plaintext message text";
|
|
41
|
+
const plaintext = encoder.encode(startMessage);
|
|
42
|
+
const info = encoder.encode("app info");
|
|
43
|
+
const aad = encoder.encode("associated data");
|
|
44
|
+
|
|
45
|
+
for (const aead of [
|
|
46
|
+
Aead.AesGcm128,
|
|
47
|
+
Aead.AesGcm256,
|
|
48
|
+
Aead.ChaCha20Poly1305,
|
|
49
|
+
]) {
|
|
50
|
+
for (const kdf of [Kdf.Sha256, Kdf.Sha384, Kdf.Sha512]) {
|
|
51
|
+
for (const kem of [Kem.DhP256HkdfSha256, Kem.X25519HkdfSha256]) {
|
|
52
|
+
it(`succeeds for ${Aead[aead]}, ${Kdf[kdf]}, ${Kem[kem]}`, () => {
|
|
53
|
+
const config = Config.try_from_ids(aead, kdf, kem);
|
|
54
|
+
|
|
55
|
+
assert.equal(config.aead, aead);
|
|
56
|
+
assert.equal(config.kem, kem);
|
|
57
|
+
assert.equal(config.kdf, kdf);
|
|
58
|
+
|
|
59
|
+
const keypair = new Keypair(config.kem);
|
|
60
|
+
|
|
61
|
+
const keyAndCiphertext = config.base_mode_seal(
|
|
62
|
+
keypair.public_key,
|
|
63
|
+
info,
|
|
64
|
+
plaintext,
|
|
65
|
+
aad
|
|
66
|
+
);
|
|
67
|
+
|
|
68
|
+
const roundTrip = config.base_mode_open(
|
|
69
|
+
keypair.private_key,
|
|
70
|
+
keyAndCiphertext.encapped_key,
|
|
71
|
+
info,
|
|
72
|
+
keyAndCiphertext.ciphertext,
|
|
73
|
+
aad
|
|
74
|
+
);
|
|
75
|
+
|
|
76
|
+
assert.equal(startMessage, decoder.decode(roundTrip));
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|