@sebastienrousseau/crypto-lib 0.0.2 → 0.0.7
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/README.md +334 -185
- package/dist/accel/index.d.ts +11 -0
- package/dist/accel/index.d.ts.map +1 -0
- package/dist/accel/index.js +31 -0
- package/dist/accel/native-pqc-bridge.d.ts +18 -0
- package/dist/accel/native-pqc-bridge.d.ts.map +1 -0
- package/dist/accel/native-pqc-bridge.js +100 -0
- package/dist/accel/wasm-bridge.d.ts +35 -0
- package/dist/accel/wasm-bridge.d.ts.map +1 -0
- package/dist/accel/wasm-bridge.js +161 -0
- package/dist/accel/webcrypto-bridge.d.ts +32 -0
- package/dist/accel/webcrypto-bridge.d.ts.map +1 -0
- package/dist/accel/webcrypto-bridge.js +179 -0
- package/dist/accel/webcrypto-modern.d.ts +40 -0
- package/dist/accel/webcrypto-modern.d.ts.map +1 -0
- package/dist/accel/webcrypto-modern.js +213 -0
- package/dist/accel/worker-pool.d.ts +23 -0
- package/dist/accel/worker-pool.d.ts.map +1 -0
- package/dist/accel/worker-pool.js +119 -0
- package/dist/bin/cryptolib.d.ts +25 -0
- package/dist/bin/cryptolib.d.ts.map +1 -0
- package/dist/bin/cryptolib.js +87 -0
- package/dist/config/config.d.ts +8 -0
- package/dist/config/config.d.ts.map +1 -0
- package/dist/config/config.js +13 -0
- package/dist/crypto.d.ts +43 -0
- package/dist/crypto.d.ts.map +1 -0
- package/dist/crypto.js +107 -0
- package/dist/enums.d.ts +81 -0
- package/dist/enums.d.ts.map +1 -0
- package/dist/enums.js +82 -0
- package/dist/errors.d.ts +14 -0
- package/dist/errors.d.ts.map +1 -0
- package/dist/errors.js +22 -0
- package/dist/high-level/index.d.ts +11 -0
- package/dist/high-level/index.d.ts.map +1 -0
- package/dist/high-level/index.js +53 -0
- package/dist/high-level/key-wrap.d.ts +16 -0
- package/dist/high-level/key-wrap.d.ts.map +1 -0
- package/dist/high-level/key-wrap.js +93 -0
- package/dist/high-level/multi-recipient.d.ts +25 -0
- package/dist/high-level/multi-recipient.d.ts.map +1 -0
- package/dist/high-level/multi-recipient.js +122 -0
- package/dist/high-level/password-encrypt.d.ts +14 -0
- package/dist/high-level/password-encrypt.d.ts.map +1 -0
- package/dist/high-level/password-encrypt.js +93 -0
- package/dist/high-level/sealedbox.d.ts +13 -0
- package/dist/high-level/sealedbox.d.ts.map +1 -0
- package/dist/high-level/sealedbox.js +119 -0
- package/dist/high-level/secretbox.d.ts +7 -0
- package/dist/high-level/secretbox.d.ts.map +1 -0
- package/dist/high-level/secretbox.js +54 -0
- package/dist/index.d.ts +16 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +61 -2
- package/dist/key/key.d.ts +10 -0
- package/dist/key/key.d.ts.map +1 -0
- package/dist/key/key.js +25 -0
- package/dist/key/keystore.d.ts +11 -0
- package/dist/key/keystore.d.ts.map +1 -0
- package/dist/key/keystore.js +87 -0
- package/dist/keys/index.d.ts +7 -0
- package/dist/keys/index.d.ts.map +1 -0
- package/dist/keys/index.js +22 -0
- package/dist/keys/keygen.d.ts +16 -0
- package/dist/keys/keygen.d.ts.map +1 -0
- package/dist/keys/keygen.js +128 -0
- package/dist/keys/keyring.d.ts +35 -0
- package/dist/keys/keyring.d.ts.map +1 -0
- package/dist/keys/keyring.js +136 -0
- package/dist/keys/serialize.d.ts +30 -0
- package/dist/keys/serialize.d.ts.map +1 -0
- package/dist/keys/serialize.js +120 -0
- package/dist/lib/decrypt.d.ts +5 -5
- package/dist/lib/decrypt.d.ts.map +1 -1
- package/dist/lib/decrypt.js +49 -39
- package/dist/lib/encrypt.d.ts +2 -5
- package/dist/lib/encrypt.d.ts.map +1 -1
- package/dist/lib/encrypt.js +34 -39
- package/dist/lib/generate.d.ts +2 -11
- package/dist/lib/generate.d.ts.map +1 -1
- package/dist/lib/generate.js +57 -29
- package/dist/lib/index.d.ts +10 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +53 -0
- package/dist/lib/key-output.d.ts +7 -0
- package/dist/lib/key-output.d.ts.map +1 -0
- package/dist/lib/key-output.js +50 -0
- package/dist/lib/reformat.d.ts +9 -0
- package/dist/lib/reformat.d.ts.map +1 -0
- package/dist/lib/reformat.js +67 -0
- package/dist/lib/revoke.d.ts +3 -3
- package/dist/lib/revoke.d.ts.map +1 -1
- package/dist/lib/revoke.js +36 -28
- package/dist/lib/session.d.ts +5 -0
- package/dist/lib/session.d.ts.map +1 -0
- package/dist/lib/session.js +55 -0
- package/dist/lib/sign.d.ts +4 -0
- package/dist/lib/sign.d.ts.map +1 -0
- package/dist/lib/sign.js +63 -0
- package/dist/lib/verify.d.ts +5 -0
- package/dist/lib/verify.d.ts.map +1 -0
- package/dist/lib/verify.js +52 -0
- package/dist/modern/aead.d.ts +17 -0
- package/dist/modern/aead.d.ts.map +1 -0
- package/dist/modern/aead.js +51 -0
- package/dist/modern/aes.d.ts +35 -0
- package/dist/modern/aes.d.ts.map +1 -0
- package/dist/modern/aes.js +82 -0
- package/dist/modern/cost-limits.d.ts +11 -0
- package/dist/modern/cost-limits.d.ts.map +1 -0
- package/dist/modern/cost-limits.js +35 -0
- package/dist/modern/curves.d.ts +86 -0
- package/dist/modern/curves.d.ts.map +1 -0
- package/dist/modern/curves.js +171 -0
- package/dist/modern/ecdh.d.ts +11 -0
- package/dist/modern/ecdh.d.ts.map +1 -0
- package/dist/modern/ecdh.js +28 -0
- package/dist/modern/fn-dsa.d.ts +19 -0
- package/dist/modern/fn-dsa.d.ts.map +1 -0
- package/dist/modern/fn-dsa.js +57 -0
- package/dist/modern/hash.d.ts +13 -0
- package/dist/modern/hash.d.ts.map +1 -0
- package/dist/modern/hash.js +45 -0
- package/dist/modern/hpke.d.ts +47 -0
- package/dist/modern/hpke.d.ts.map +1 -0
- package/dist/modern/hpke.js +207 -0
- package/dist/modern/index.d.ts +40 -0
- package/dist/modern/index.d.ts.map +1 -0
- package/dist/modern/index.js +194 -0
- package/dist/modern/kdf.d.ts +23 -0
- package/dist/modern/kdf.d.ts.map +1 -0
- package/dist/modern/kdf.js +67 -0
- package/dist/modern/mac.d.ts +51 -0
- package/dist/modern/mac.d.ts.map +1 -0
- package/dist/modern/mac.js +119 -0
- package/dist/modern/password.d.ts +40 -0
- package/dist/modern/password.d.ts.map +1 -0
- package/dist/modern/password.js +123 -0
- package/dist/modern/pq-hash-sign.d.ts +18 -0
- package/dist/modern/pq-hash-sign.d.ts.map +1 -0
- package/dist/modern/pq-hash-sign.js +73 -0
- package/dist/modern/pq-kem.d.ts +88 -0
- package/dist/modern/pq-kem.d.ts.map +1 -0
- package/dist/modern/pq-kem.js +270 -0
- package/dist/modern/pq-sign.d.ts +30 -0
- package/dist/modern/pq-sign.d.ts.map +1 -0
- package/dist/modern/pq-sign.js +94 -0
- package/dist/modern/pq.d.ts +38 -0
- package/dist/modern/pq.d.ts.map +1 -0
- package/dist/modern/pq.js +80 -0
- package/dist/modern/signing.d.ts +16 -0
- package/dist/modern/signing.d.ts.map +1 -0
- package/dist/modern/signing.js +34 -0
- package/dist/protocols/index.d.ts +7 -0
- package/dist/protocols/index.d.ts.map +1 -0
- package/dist/protocols/index.js +46 -0
- package/dist/protocols/iso20022.d.ts +51 -0
- package/dist/protocols/iso20022.d.ts.map +1 -0
- package/dist/protocols/iso20022.js +145 -0
- package/dist/protocols/opaque/ake.d.ts +51 -0
- package/dist/protocols/opaque/ake.d.ts.map +1 -0
- package/dist/protocols/opaque/ake.js +102 -0
- package/dist/protocols/opaque/client.d.ts +45 -0
- package/dist/protocols/opaque/client.d.ts.map +1 -0
- package/dist/protocols/opaque/client.js +63 -0
- package/dist/protocols/opaque/config.d.ts +14 -0
- package/dist/protocols/opaque/config.d.ts.map +1 -0
- package/dist/protocols/opaque/config.js +18 -0
- package/dist/protocols/opaque/credentials.d.ts +29 -0
- package/dist/protocols/opaque/credentials.d.ts.map +1 -0
- package/dist/protocols/opaque/credentials.js +61 -0
- package/dist/protocols/opaque/envelope.d.ts +36 -0
- package/dist/protocols/opaque/envelope.d.ts.map +1 -0
- package/dist/protocols/opaque/envelope.js +77 -0
- package/dist/protocols/opaque/ksf.d.ts +15 -0
- package/dist/protocols/opaque/ksf.d.ts.map +1 -0
- package/dist/protocols/opaque/ksf.js +27 -0
- package/dist/protocols/opaque/messages.d.ts +61 -0
- package/dist/protocols/opaque/messages.d.ts.map +1 -0
- package/dist/protocols/opaque/messages.js +94 -0
- package/dist/protocols/opaque/server.d.ts +33 -0
- package/dist/protocols/opaque/server.d.ts.map +1 -0
- package/dist/protocols/opaque/server.js +74 -0
- package/dist/protocols/opaque/suite.d.ts +58 -0
- package/dist/protocols/opaque/suite.d.ts.map +1 -0
- package/dist/protocols/opaque/suite.js +115 -0
- package/dist/protocols/pake.d.ts +14 -0
- package/dist/protocols/pake.d.ts.map +1 -0
- package/dist/protocols/pake.js +33 -0
- package/dist/protocols/pqxdh.d.ts +53 -0
- package/dist/protocols/pqxdh.d.ts.map +1 -0
- package/dist/protocols/pqxdh.js +143 -0
- package/dist/protocols/ratchet.d.ts +52 -0
- package/dist/protocols/ratchet.d.ts.map +1 -0
- package/dist/protocols/ratchet.js +187 -0
- package/dist/protocols/threshold.d.ts +23 -0
- package/dist/protocols/threshold.d.ts.map +1 -0
- package/dist/protocols/threshold.js +191 -0
- package/dist/registry.d.ts +20 -0
- package/dist/registry.d.ts.map +1 -0
- package/dist/registry.js +399 -0
- package/dist/streaming/index.d.ts +7 -0
- package/dist/streaming/index.d.ts.map +1 -0
- package/dist/streaming/index.js +15 -0
- package/dist/streaming/stream-aead.d.ts +17 -0
- package/dist/streaming/stream-aead.d.ts.map +1 -0
- package/dist/streaming/stream-aead.js +125 -0
- package/dist/streaming/stream-hash.d.ts +9 -0
- package/dist/streaming/stream-hash.d.ts.map +1 -0
- package/dist/streaming/stream-hash.js +52 -0
- package/dist/streaming/web-streams.d.ts +17 -0
- package/dist/streaming/web-streams.d.ts.map +1 -0
- package/dist/streaming/web-streams.js +114 -0
- package/dist/tokens/index.d.ts +5 -0
- package/dist/tokens/index.d.ts.map +1 -0
- package/dist/tokens/index.js +15 -0
- package/dist/tokens/key-rotation.d.ts +20 -0
- package/dist/tokens/key-rotation.d.ts.map +1 -0
- package/dist/tokens/key-rotation.js +76 -0
- package/dist/tokens/paseto.d.ts +46 -0
- package/dist/tokens/paseto.d.ts.map +1 -0
- package/dist/tokens/paseto.js +200 -0
- package/dist/types/types.d.ts +57 -0
- package/dist/types/types.d.ts.map +1 -1
- package/dist/types/types.js +1 -0
- package/dist/utils.d.ts +13 -0
- package/dist/utils.d.ts.map +1 -0
- package/dist/utils.js +56 -0
- package/package.json +77 -130
- package/dist/COPYRIGHT +0 -15
- package/dist/Report.txt +0 -72
- package/dist/bin/crypto-lib.d.ts +0 -13
- package/dist/bin/crypto-lib.d.ts.map +0 -1
- package/dist/bin/crypto-lib.js +0 -52
- package/dist/bin/crypto-lib.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/lib/decrypt.js.map +0 -1
- package/dist/lib/encrypt.js.map +0 -1
- package/dist/lib/generate.js.map +0 -1
- package/dist/lib/revoke.js.map +0 -1
- package/dist/package.json +0 -131
- package/dist/types/types.js.map +0 -1
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.HASH_ALGORITHMS = void 0;
|
|
4
|
+
exports.hash = hash;
|
|
5
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
6
|
+
const sha3_js_1 = require("@noble/hashes/sha3.js");
|
|
7
|
+
const blake2_js_1 = require("@noble/hashes/blake2.js");
|
|
8
|
+
const blake3_js_1 = require("@noble/hashes/blake3.js");
|
|
9
|
+
exports.HASH_ALGORITHMS = [
|
|
10
|
+
"sha256",
|
|
11
|
+
"sha384",
|
|
12
|
+
"sha512",
|
|
13
|
+
"sha3-256",
|
|
14
|
+
"sha3-512",
|
|
15
|
+
"blake2b",
|
|
16
|
+
"blake3",
|
|
17
|
+
];
|
|
18
|
+
function toBytes(input) {
|
|
19
|
+
if (input instanceof Uint8Array)
|
|
20
|
+
return input;
|
|
21
|
+
return Buffer.from(input, "utf8");
|
|
22
|
+
}
|
|
23
|
+
const hashFunctions = {
|
|
24
|
+
sha256: (d) => (0, sha2_js_1.sha256)(d),
|
|
25
|
+
sha384: (d) => (0, sha2_js_1.sha384)(d),
|
|
26
|
+
sha512: (d) => (0, sha2_js_1.sha512)(d),
|
|
27
|
+
"sha3-256": (d) => (0, sha3_js_1.sha3_256)(d),
|
|
28
|
+
"sha3-512": (d) => (0, sha3_js_1.sha3_512)(d),
|
|
29
|
+
blake2b: (d) => (0, blake2_js_1.blake2b)(d),
|
|
30
|
+
blake3: (d) => (0, blake3_js_1.blake3)(d),
|
|
31
|
+
};
|
|
32
|
+
function hash(options) {
|
|
33
|
+
const fn = hashFunctions[options.algorithm];
|
|
34
|
+
if (!fn) {
|
|
35
|
+
throw new Error(`Unsupported algorithm: ${options.algorithm}. Supported: ${exports.HASH_ALGORITHMS.join(", ")}`);
|
|
36
|
+
}
|
|
37
|
+
const data = toBytes(options.data);
|
|
38
|
+
const digest = fn(data);
|
|
39
|
+
return {
|
|
40
|
+
digest: Buffer.from(digest).toString("hex"),
|
|
41
|
+
algorithm: options.algorithm,
|
|
42
|
+
length: digest.length,
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=hash.js.map
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
export type HpkeKem = "x25519" | "p256";
|
|
2
|
+
export type HpkeAead = "chacha20-poly1305" | "aes-128-gcm";
|
|
3
|
+
export type HpkeMode = "base" | "psk";
|
|
4
|
+
export interface HpkeKeyPair {
|
|
5
|
+
publicKey: string;
|
|
6
|
+
privateKey: string;
|
|
7
|
+
}
|
|
8
|
+
export interface HpkeSealResult {
|
|
9
|
+
ciphertext: string;
|
|
10
|
+
encapsulatedKey: string;
|
|
11
|
+
}
|
|
12
|
+
export interface HpkeOpenResult {
|
|
13
|
+
plaintext: string;
|
|
14
|
+
}
|
|
15
|
+
export interface HpkeSuiteOptions {
|
|
16
|
+
kem?: HpkeKem;
|
|
17
|
+
aead?: HpkeAead;
|
|
18
|
+
}
|
|
19
|
+
export interface HpkePskOptions {
|
|
20
|
+
psk: string;
|
|
21
|
+
pskId: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function hpkeGenerateKeyPair(kem?: HpkeKem): HpkeKeyPair;
|
|
24
|
+
export declare function hpkeSeal(options: {
|
|
25
|
+
recipientPublicKey: string;
|
|
26
|
+
plaintext: string;
|
|
27
|
+
info?: string;
|
|
28
|
+
aad?: string;
|
|
29
|
+
suite?: HpkeSuiteOptions;
|
|
30
|
+
psk?: HpkePskOptions;
|
|
31
|
+
}): HpkeSealResult;
|
|
32
|
+
export declare function hpkeSealWithEphemeral(options: Parameters<typeof hpkeSeal>[0], ephemeralPrivateKey: Uint8Array): HpkeSealResult & {
|
|
33
|
+
sharedSecret: string;
|
|
34
|
+
key: string;
|
|
35
|
+
baseNonce: string;
|
|
36
|
+
exporterSecret: string;
|
|
37
|
+
};
|
|
38
|
+
export declare function hpkeOpen(options: {
|
|
39
|
+
recipientPrivateKey: string;
|
|
40
|
+
encapsulatedKey: string;
|
|
41
|
+
ciphertext: string;
|
|
42
|
+
info?: string;
|
|
43
|
+
aad?: string;
|
|
44
|
+
suite?: HpkeSuiteOptions;
|
|
45
|
+
psk?: HpkePskOptions;
|
|
46
|
+
}): HpkeOpenResult;
|
|
47
|
+
//# sourceMappingURL=hpke.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hpke.d.ts","sourceRoot":"","sources":["../../src/modern/hpke.ts"],"names":[],"mappings":"AA4DA,MAAM,MAAM,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAC;AAUxC,MAAM,MAAM,QAAQ,GAAG,mBAAmB,GAAG,aAAa,CAAC;AAU3D,MAAM,MAAM,QAAQ,GAAG,MAAM,GAAG,KAAK,CAAC;AAUtC,MAAM,WAAW,WAAW;IAE1B,SAAS,EAAE,MAAM,CAAC;IAElB,UAAU,EAAE,MAAM,CAAC;CACpB;AAUD,MAAM,WAAW,cAAc;IAE7B,UAAU,EAAE,MAAM,CAAC;IAEnB,eAAe,EAAE,MAAM,CAAC;CACzB;AAUD,MAAM,WAAW,cAAc;IAE7B,SAAS,EAAE,MAAM,CAAC;CACnB;AAUD,MAAM,WAAW,gBAAgB;IAE/B,GAAG,CAAC,EAAE,OAAO,CAAC;IAEd,IAAI,CAAC,EAAE,QAAQ,CAAC;CACjB;AAUD,MAAM,WAAW,cAAc;IAE7B,GAAG,EAAE,MAAM,CAAC;IAEZ,KAAK,EAAE,MAAM,CAAC;CACf;AAiWD,wBAAgB,mBAAmB,CAAC,GAAG,GAAE,OAAkB,GAAG,WAAW,CAMxE;AAuBD,wBAAgB,QAAQ,CAAC,OAAO,EAAE;IAEhC,kBAAkB,EAAE,MAAM,CAAC;IAE3B,SAAS,EAAE,MAAM,CAAC;IAElB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,KAAK,CAAC,EAAE,gBAAgB,CAAC;IAEzB,GAAG,CAAC,EAAE,cAAc,CAAC;CACtB,GAAG,cAAc,CAOjB;AAUD,wBAAgB,qBAAqB,CACnC,OAAO,EAAE,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC,CAAC,CAAC,EACvC,mBAAmB,EAAE,UAAU,GAC9B,cAAc,GAAG;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,GAAG,EAAE,MAAM,CAAC;IACZ,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,MAAM,CAAC;CACxB,CA2BA;AA0BD,wBAAgB,QAAQ,CAAC,OAAO,EAAE;IAEhC,mBAAmB,EAAE,MAAM,CAAC;IAE5B,eAAe,EAAE,MAAM,CAAC;IAExB,UAAU,EAAE,MAAM,CAAC;IAEnB,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd,GAAG,CAAC,EAAE,MAAM,CAAC;IAEb,KAAK,CAAC,EAAE,gBAAgB,CAAC;IAEzB,GAAG,CAAC,EAAE,cAAc,CAAC;CACtB,GAAG,cAAc,CAgBjB"}
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hpkeGenerateKeyPair = hpkeGenerateKeyPair;
|
|
4
|
+
exports.hpkeSeal = hpkeSeal;
|
|
5
|
+
exports.hpkeSealWithEphemeral = hpkeSealWithEphemeral;
|
|
6
|
+
exports.hpkeOpen = hpkeOpen;
|
|
7
|
+
const ed25519_js_1 = require("@noble/curves/ed25519.js");
|
|
8
|
+
const nist_js_1 = require("@noble/curves/nist.js");
|
|
9
|
+
const hkdf_js_1 = require("@noble/hashes/hkdf.js");
|
|
10
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
11
|
+
const chacha_js_1 = require("@noble/ciphers/chacha.js");
|
|
12
|
+
const aes_js_1 = require("@noble/ciphers/aes.js");
|
|
13
|
+
const KEM_X25519 = 0x0020;
|
|
14
|
+
const KEM_P256 = 0x0010;
|
|
15
|
+
const KDF_HKDF_SHA256 = 0x0001;
|
|
16
|
+
const AEAD_AES_128_GCM = 0x0001;
|
|
17
|
+
const AEAD_CHACHA20_POLY1305 = 0x0003;
|
|
18
|
+
const MODE_BASE = 0x00;
|
|
19
|
+
const MODE_PSK = 0x01;
|
|
20
|
+
const HEX_RE = /^[0-9a-fA-F]*$/;
|
|
21
|
+
function hexToBytes(hex) {
|
|
22
|
+
if (!HEX_RE.test(hex) || hex.length % 2 !== 0) {
|
|
23
|
+
throw new Error("Invalid hex string");
|
|
24
|
+
}
|
|
25
|
+
return Buffer.from(hex, "hex");
|
|
26
|
+
}
|
|
27
|
+
function bytesToHex(bytes) {
|
|
28
|
+
return Buffer.from(bytes).toString("hex");
|
|
29
|
+
}
|
|
30
|
+
function i2osp2(n) {
|
|
31
|
+
return new Uint8Array([(n >> 8) & 0xff, n & 0xff]);
|
|
32
|
+
}
|
|
33
|
+
function concat(...arrays) {
|
|
34
|
+
const len = arrays.reduce((s, a) => s + a.length, 0);
|
|
35
|
+
const result = new Uint8Array(len);
|
|
36
|
+
let offset = 0;
|
|
37
|
+
for (const a of arrays) {
|
|
38
|
+
result.set(a, offset);
|
|
39
|
+
offset += a.length;
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
}
|
|
43
|
+
function suiteParams(kem, aead) {
|
|
44
|
+
const kemId = kem === "x25519" ? KEM_X25519 : KEM_P256;
|
|
45
|
+
const aeadId = aead === "chacha20-poly1305" ? AEAD_CHACHA20_POLY1305 : AEAD_AES_128_GCM;
|
|
46
|
+
const nk = aead === "chacha20-poly1305" ? 32 : 16;
|
|
47
|
+
const nn = 12;
|
|
48
|
+
const nSecret = 32;
|
|
49
|
+
let nEnc;
|
|
50
|
+
let nSk;
|
|
51
|
+
if (kem === "x25519") {
|
|
52
|
+
nEnc = 32;
|
|
53
|
+
nSk = 32;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
nEnc = 65;
|
|
57
|
+
nSk = 32;
|
|
58
|
+
}
|
|
59
|
+
return {
|
|
60
|
+
kemId,
|
|
61
|
+
kdfId: KDF_HKDF_SHA256,
|
|
62
|
+
aeadId,
|
|
63
|
+
nk,
|
|
64
|
+
nn,
|
|
65
|
+
nSecret,
|
|
66
|
+
nEnc,
|
|
67
|
+
nSk,
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
function hpkeSuiteId(params) {
|
|
71
|
+
return concat(Buffer.from("HPKE"), i2osp2(params.kemId), i2osp2(params.kdfId), i2osp2(params.aeadId));
|
|
72
|
+
}
|
|
73
|
+
function kemSuiteId(kemId) {
|
|
74
|
+
return concat(Buffer.from("KEM"), i2osp2(kemId));
|
|
75
|
+
}
|
|
76
|
+
function labeledExtract(suiteId, salt, label, ikm) {
|
|
77
|
+
const labeledIkm = concat(Buffer.from("HPKE-v1"), suiteId, Buffer.from(label), ikm);
|
|
78
|
+
return (0, hkdf_js_1.extract)(sha2_js_1.sha256, labeledIkm, salt.length > 0 ? salt : undefined);
|
|
79
|
+
}
|
|
80
|
+
function labeledExpand(suiteId, prk, label, info, length) {
|
|
81
|
+
const labeledInfo = concat(i2osp2(length), Buffer.from("HPKE-v1"), suiteId, Buffer.from(label), info);
|
|
82
|
+
return (0, hkdf_js_1.expand)(sha2_js_1.sha256, prk, labeledInfo, length);
|
|
83
|
+
}
|
|
84
|
+
function kemPublicKey(kem, sk) {
|
|
85
|
+
return kem === "x25519"
|
|
86
|
+
? ed25519_js_1.x25519.getPublicKey(sk)
|
|
87
|
+
: nist_js_1.p256.getPublicKey(sk, false);
|
|
88
|
+
}
|
|
89
|
+
function kemRandomPrivateKey(kem) {
|
|
90
|
+
return kem === "x25519"
|
|
91
|
+
? ed25519_js_1.x25519.utils.randomSecretKey()
|
|
92
|
+
: nist_js_1.p256.utils.randomSecretKey();
|
|
93
|
+
}
|
|
94
|
+
function kemDh(kem, sk, pk) {
|
|
95
|
+
if (kem === "x25519") {
|
|
96
|
+
return ed25519_js_1.x25519.getSharedSecret(sk, pk);
|
|
97
|
+
}
|
|
98
|
+
return nist_js_1.p256.getSharedSecret(sk, pk, false).subarray(1, 33);
|
|
99
|
+
}
|
|
100
|
+
function extractAndExpand(params, dh, kemContext) {
|
|
101
|
+
const kemSid = kemSuiteId(params.kemId);
|
|
102
|
+
const eaePrk = labeledExtract(kemSid, new Uint8Array(0), "eae_prk", dh);
|
|
103
|
+
return labeledExpand(kemSid, eaePrk, "shared_secret", kemContext, params.nSecret);
|
|
104
|
+
}
|
|
105
|
+
function dhkemEncap(kem, recipientPub, ephPriv, params) {
|
|
106
|
+
const enc = kemPublicKey(kem, ephPriv);
|
|
107
|
+
const dh = kemDh(kem, ephPriv, recipientPub);
|
|
108
|
+
const sharedSecret = extractAndExpand(params, dh, concat(enc, recipientPub));
|
|
109
|
+
return { sharedSecret, enc };
|
|
110
|
+
}
|
|
111
|
+
function dhkemDecap(kem, enc, recipientPriv, params) {
|
|
112
|
+
const dh = kemDh(kem, recipientPriv, enc);
|
|
113
|
+
const recipientPub = kemPublicKey(kem, recipientPriv);
|
|
114
|
+
return extractAndExpand(params, dh, concat(enc, recipientPub));
|
|
115
|
+
}
|
|
116
|
+
function keySchedule(params, sharedSecret, inputs) {
|
|
117
|
+
const suiteId = hpkeSuiteId(params);
|
|
118
|
+
const empty = new Uint8Array(0);
|
|
119
|
+
const pskIdHash = labeledExtract(suiteId, empty, "psk_id_hash", inputs.pskId);
|
|
120
|
+
const infoHash = labeledExtract(suiteId, empty, "info_hash", inputs.info);
|
|
121
|
+
const ksContext = concat(new Uint8Array([inputs.mode]), pskIdHash, infoHash);
|
|
122
|
+
const secret = labeledExtract(suiteId, sharedSecret, "secret", inputs.psk);
|
|
123
|
+
return {
|
|
124
|
+
key: labeledExpand(suiteId, secret, "key", ksContext, params.nk),
|
|
125
|
+
baseNonce: labeledExpand(suiteId, secret, "base_nonce", ksContext, params.nn),
|
|
126
|
+
exporterSecret: labeledExpand(suiteId, secret, "exp", ksContext, params.nSecret),
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
function scheduleInputs(options) {
|
|
130
|
+
const info = options.info ? hexToBytes(options.info) : new Uint8Array(0);
|
|
131
|
+
if (!options.psk) {
|
|
132
|
+
return {
|
|
133
|
+
mode: MODE_BASE,
|
|
134
|
+
info,
|
|
135
|
+
psk: new Uint8Array(0),
|
|
136
|
+
pskId: new Uint8Array(0),
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
const psk = hexToBytes(options.psk.psk);
|
|
140
|
+
const pskId = hexToBytes(options.psk.pskId);
|
|
141
|
+
if (psk.length === 0 || pskId.length === 0) {
|
|
142
|
+
throw new Error("PSK mode requires a non-empty psk and pskId");
|
|
143
|
+
}
|
|
144
|
+
return { mode: MODE_PSK, info, psk, pskId };
|
|
145
|
+
}
|
|
146
|
+
function aeadSeal(aead, key, nonce, aad, plaintext) {
|
|
147
|
+
if (aead === "chacha20-poly1305") {
|
|
148
|
+
return (0, chacha_js_1.chacha20poly1305)(key, nonce, aad).encrypt(plaintext);
|
|
149
|
+
}
|
|
150
|
+
return (0, aes_js_1.gcm)(key, nonce, aad).encrypt(plaintext);
|
|
151
|
+
}
|
|
152
|
+
function aeadOpen(aead, key, nonce, aad, ciphertext) {
|
|
153
|
+
if (aead === "chacha20-poly1305") {
|
|
154
|
+
return (0, chacha_js_1.chacha20poly1305)(key, nonce, aad).decrypt(ciphertext);
|
|
155
|
+
}
|
|
156
|
+
return (0, aes_js_1.gcm)(key, nonce, aad).decrypt(ciphertext);
|
|
157
|
+
}
|
|
158
|
+
function hpkeGenerateKeyPair(kem = "x25519") {
|
|
159
|
+
const privateKey = kemRandomPrivateKey(kem);
|
|
160
|
+
return {
|
|
161
|
+
publicKey: bytesToHex(kemPublicKey(kem, privateKey)),
|
|
162
|
+
privateKey: bytesToHex(privateKey),
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
function hpkeSeal(options) {
|
|
166
|
+
const kem = options.suite?.kem ?? "x25519";
|
|
167
|
+
const sealed = hpkeSealWithEphemeral(options, kemRandomPrivateKey(kem));
|
|
168
|
+
return {
|
|
169
|
+
ciphertext: sealed.ciphertext,
|
|
170
|
+
encapsulatedKey: sealed.encapsulatedKey,
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
function hpkeSealWithEphemeral(options, ephemeralPrivateKey) {
|
|
174
|
+
const kem = options.suite?.kem ?? "x25519";
|
|
175
|
+
const aead = options.suite?.aead ?? "chacha20-poly1305";
|
|
176
|
+
const params = suiteParams(kem, aead);
|
|
177
|
+
const recipientPub = hexToBytes(options.recipientPublicKey);
|
|
178
|
+
const plaintext = hexToBytes(options.plaintext);
|
|
179
|
+
const aad = options.aad ? hexToBytes(options.aad) : new Uint8Array(0);
|
|
180
|
+
const inputs = scheduleInputs(options);
|
|
181
|
+
const { sharedSecret, enc } = dhkemEncap(kem, recipientPub, ephemeralPrivateKey, params);
|
|
182
|
+
const ks = keySchedule(params, sharedSecret, inputs);
|
|
183
|
+
const ct = aeadSeal(aead, ks.key, ks.baseNonce, aad, plaintext);
|
|
184
|
+
return {
|
|
185
|
+
ciphertext: bytesToHex(ct),
|
|
186
|
+
encapsulatedKey: bytesToHex(enc),
|
|
187
|
+
sharedSecret: bytesToHex(sharedSecret),
|
|
188
|
+
key: bytesToHex(ks.key),
|
|
189
|
+
baseNonce: bytesToHex(ks.baseNonce),
|
|
190
|
+
exporterSecret: bytesToHex(ks.exporterSecret),
|
|
191
|
+
};
|
|
192
|
+
}
|
|
193
|
+
function hpkeOpen(options) {
|
|
194
|
+
const kem = options.suite?.kem ?? "x25519";
|
|
195
|
+
const aead = options.suite?.aead ?? "chacha20-poly1305";
|
|
196
|
+
const params = suiteParams(kem, aead);
|
|
197
|
+
const recipientPriv = hexToBytes(options.recipientPrivateKey);
|
|
198
|
+
const enc = hexToBytes(options.encapsulatedKey);
|
|
199
|
+
const ciphertext = hexToBytes(options.ciphertext);
|
|
200
|
+
const aad = options.aad ? hexToBytes(options.aad) : new Uint8Array(0);
|
|
201
|
+
const inputs = scheduleInputs(options);
|
|
202
|
+
const sharedSecret = dhkemDecap(kem, enc, recipientPriv, params);
|
|
203
|
+
const { key, baseNonce } = keySchedule(params, sharedSecret, inputs);
|
|
204
|
+
const pt = aeadOpen(aead, key, baseNonce, aad, ciphertext);
|
|
205
|
+
return { plaintext: bytesToHex(pt) };
|
|
206
|
+
}
|
|
207
|
+
//# sourceMappingURL=hpke.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export { aeadEncrypt, aeadDecrypt } from "./aead";
|
|
2
|
+
export type { AeadEncryptOptions, AeadDecryptOptions, AeadEncryptResult, } from "./aead";
|
|
3
|
+
export { aesGcmEncrypt, aesGcmDecrypt, aesGcmSivEncrypt, aesGcmSivDecrypt, } from "./aes";
|
|
4
|
+
export type { AesGcmEncryptOptions, AesGcmEncryptResult, AesGcmDecryptOptions, AesGcmAlgorithm, AesGcmSivEncryptOptions, AesGcmSivEncryptResult, AesGcmSivDecryptOptions, AesGcmSivAlgorithm, } from "./aes";
|
|
5
|
+
export { hash, HASH_ALGORITHMS } from "./hash";
|
|
6
|
+
export type { HashOptions, HashResult, HashAlgorithm } from "./hash";
|
|
7
|
+
export { kdfDerive, KDF_ALGORITHMS } from "./kdf";
|
|
8
|
+
export type { KdfDeriveOptions, KdfResult, KdfAlgorithm } from "./kdf";
|
|
9
|
+
export { generateEd25519KeyPair, ed25519Sign, ed25519Verify } from "./signing";
|
|
10
|
+
export type { Ed25519KeyPair, SignResult, VerifyResult } from "./signing";
|
|
11
|
+
export { generateX25519KeyPair, x25519Exchange } from "./ecdh";
|
|
12
|
+
export type { X25519KeyPair, KeyExchangeResult } from "./ecdh";
|
|
13
|
+
export { mlKemGenerateKeyPair, mlKemEncapsulate, mlKemDecapsulate, hybridGenerateKeyPair, hybridEncapsulate, hybridDecapsulate, } from "./pq";
|
|
14
|
+
export type { MlKemKeyPair, MlKemEncapsulateResult, MlKemDecapsulateResult, HybridKeyPair, HybridEncapsulateResult, HybridDecapsulateResult, } from "./pq";
|
|
15
|
+
export { mlKemKeygen, mlKemEncapsulate as mlKemEncap, mlKemDecapsulate as mlKemDecap, hybridKemKeygen, hybridKemEncapsulate, hybridKemDecapsulate, p256MlKemKeygen, p256MlKemEncapsulate, p256MlKemDecapsulate, x448MlKemKeygen, x448MlKemEncapsulate, x448MlKemDecapsulate, RFC10024_X25519_MLKEM768, RFC10024_SECP256R1_MLKEM768, RFC10024_CODEPOINTS, normalizeHybridKemAlgorithm, } from "./pq-kem";
|
|
16
|
+
export type { MlKemLevel, MlKemAlgorithm, MlKemKeyPairResult, MlKemEncapsulateResult as MlKemEncapResult, MlKemDecapsulateResult as MlKemDecapResult, HybridKemAlgorithm, HybridKemKeyPair, HybridKemEncapsulateResult, HybridKemDecapsulateResult, P256MlKemKeyPair, P256MlKemEncapsulateResult, P256MlKemDecapsulateResult, X448MlKemKeyPair, X448MlKemEncapsulateResult, X448MlKemDecapsulateResult, } from "./pq-kem";
|
|
17
|
+
export { mlDsaKeygen, mlDsaSign, mlDsaVerify, hybridSign, hybridVerify, } from "./pq-sign";
|
|
18
|
+
export type { MlDsaLevel, MlDsaAlgorithm, MlDsaKeyPairResult, MlDsaSignResult, MlDsaVerifyResult, HybridSignResult, HybridVerifyResult, } from "./pq-sign";
|
|
19
|
+
export { fnDsaKeygen, fnDsaSign, fnDsaVerify } from "./fn-dsa";
|
|
20
|
+
export type { FnDsaLevel, FnDsaAlgorithm, FnDsaKeyPairResult, FnDsaSignResult, FnDsaVerifyResult, } from "./fn-dsa";
|
|
21
|
+
export { slhDsaKeygen, slhDsaSign, slhDsaVerify } from "./pq-hash-sign";
|
|
22
|
+
export type { SlhDsaVariant, SlhDsaKeyPairResult, SlhDsaSignResult, SlhDsaVerifyResult, } from "./pq-hash-sign";
|
|
23
|
+
export { computeHmac, verifyHmac, HMAC_ALGORITHMS, computeKmac, verifyKmac, KMAC_ALGORITHMS, } from "./mac";
|
|
24
|
+
export type { HmacAlgorithm, HmacComputeOptions, HmacComputeResult, HmacVerifyOptions, HmacVerifyResult, KmacAlgorithm, KmacComputeOptions, KmacComputeResult, KmacVerifyOptions, KmacVerifyResult, } from "./mac";
|
|
25
|
+
export { hashPassword, verifyPassword, verifyPasswordPhc } from "./password";
|
|
26
|
+
export type { Argon2Variant, Argon2Params, HashPasswordOptions, HashPasswordResult, VerifyPasswordOptions, VerifyPasswordResult, VerifyPhcOptions, } from "./password";
|
|
27
|
+
export { generateP256KeyPair, p256Sign, p256Verify, generateP384KeyPair, p384Sign, p384Verify, generateEd448KeyPair, ed448Sign, ed448Verify, generateX448KeyPair, x448Exchange, ecdhP256, ecdhP384, generateSchnorrKeyPair, schnorrSign, schnorrVerify, } from "./curves";
|
|
28
|
+
export type { P256KeyPair, P256SignResult, P256VerifyResult, P384KeyPair, P384SignResult, P384VerifyResult, Ed448KeyPair, Ed448SignResult, Ed448VerifyResult, X448KeyPair, X448ExchangeResult, EcdhP256Result, EcdhP384Result, SchnorrKeyPair, SchnorrSignResult, SchnorrVerifyResult, } from "./curves";
|
|
29
|
+
export { hpkeGenerateKeyPair, hpkeSeal, hpkeOpen } from "./hpke";
|
|
30
|
+
export type { HpkeKem, HpkeAead, HpkeMode, HpkeKeyPair, HpkeSealResult, HpkeOpenResult, HpkeSuiteOptions, HpkePskOptions, } from "./hpke";
|
|
31
|
+
export declare const SUPPORTED_ALGORITHMS: {
|
|
32
|
+
readonly encryption: readonly ["xchacha20-poly1305", "aes-128-gcm", "aes-256-gcm", "aes-128-gcm-siv", "aes-256-gcm-siv"];
|
|
33
|
+
readonly hashing: readonly ["sha256", "sha384", "sha512", "sha3-256", "sha3-512", "blake2b", "blake3"];
|
|
34
|
+
readonly kdf: readonly ["scrypt", "hkdf-sha256", "pbkdf2-sha256", "argon2id", "argon2i", "argon2d"];
|
|
35
|
+
readonly mac: readonly ["hmac-sha256", "hmac-sha384", "hmac-sha512", "hmac-sha3-256", "hmac-sha3-512", "kmac-128", "kmac-256"];
|
|
36
|
+
readonly signing: readonly ["ed25519", "ed448", "ecdsa-p256", "ecdsa-p384", "schnorr", "ml-dsa-44", "ml-dsa-65", "ml-dsa-87", "slh-dsa-sha2-128f", "slh-dsa-sha2-128s", "slh-dsa-sha2-192f", "slh-dsa-sha2-192s", "slh-dsa-sha2-256f", "slh-dsa-sha2-256s", "slh-dsa-shake-128f", "slh-dsa-shake-128s", "slh-dsa-shake-192f", "slh-dsa-shake-192s", "slh-dsa-shake-256f", "slh-dsa-shake-256s", "ed25519-ml-dsa-44", "ed25519-ml-dsa-65", "ed25519-ml-dsa-87", "fn-dsa-512", "fn-dsa-1024"];
|
|
37
|
+
readonly keyExchange: readonly ["x25519", "x448", "ecdh-p256", "ecdh-p384", "x25519-ml-kem-512", "x25519-ml-kem-768", "x25519-ml-kem-1024", "p256-ml-kem-768", "x448-ml-kem-1024", "hpke-x25519-chacha20", "hpke-x25519-aes128gcm", "hpke-p256-aes128gcm"];
|
|
38
|
+
readonly postQuantum: readonly ["ml-kem-512", "ml-kem-768", "ml-kem-1024", "ml-dsa-44", "ml-dsa-65", "ml-dsa-87", "slh-dsa-sha2-128f", "slh-dsa-sha2-128s", "slh-dsa-sha2-192f", "slh-dsa-sha2-192s", "slh-dsa-sha2-256f", "slh-dsa-sha2-256s", "slh-dsa-shake-128f", "slh-dsa-shake-128s", "slh-dsa-shake-192f", "slh-dsa-shake-192s", "slh-dsa-shake-256f", "slh-dsa-shake-256s", "fn-dsa-512", "fn-dsa-1024"];
|
|
39
|
+
};
|
|
40
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/modern/index.ts"],"names":[],"mappings":"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"}
|
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyHmac = exports.computeHmac = exports.slhDsaVerify = exports.slhDsaSign = exports.slhDsaKeygen = exports.fnDsaVerify = exports.fnDsaSign = exports.fnDsaKeygen = exports.hybridVerify = exports.hybridSign = exports.mlDsaVerify = exports.mlDsaSign = exports.mlDsaKeygen = exports.normalizeHybridKemAlgorithm = exports.RFC10024_CODEPOINTS = exports.RFC10024_SECP256R1_MLKEM768 = exports.RFC10024_X25519_MLKEM768 = exports.x448MlKemDecapsulate = exports.x448MlKemEncapsulate = exports.x448MlKemKeygen = exports.p256MlKemDecapsulate = exports.p256MlKemEncapsulate = exports.p256MlKemKeygen = exports.hybridKemDecapsulate = exports.hybridKemEncapsulate = exports.hybridKemKeygen = exports.mlKemDecap = exports.mlKemEncap = exports.mlKemKeygen = exports.hybridDecapsulate = exports.hybridEncapsulate = exports.hybridGenerateKeyPair = exports.mlKemDecapsulate = exports.mlKemEncapsulate = exports.mlKemGenerateKeyPair = exports.x25519Exchange = exports.generateX25519KeyPair = exports.ed25519Verify = exports.ed25519Sign = exports.generateEd25519KeyPair = exports.KDF_ALGORITHMS = exports.kdfDerive = exports.HASH_ALGORITHMS = exports.hash = exports.aesGcmSivDecrypt = exports.aesGcmSivEncrypt = exports.aesGcmDecrypt = exports.aesGcmEncrypt = exports.aeadDecrypt = exports.aeadEncrypt = void 0;
|
|
4
|
+
exports.SUPPORTED_ALGORITHMS = exports.hpkeOpen = exports.hpkeSeal = exports.hpkeGenerateKeyPair = exports.schnorrVerify = exports.schnorrSign = exports.generateSchnorrKeyPair = exports.ecdhP384 = exports.ecdhP256 = exports.x448Exchange = exports.generateX448KeyPair = exports.ed448Verify = exports.ed448Sign = exports.generateEd448KeyPair = exports.p384Verify = exports.p384Sign = exports.generateP384KeyPair = exports.p256Verify = exports.p256Sign = exports.generateP256KeyPair = exports.verifyPasswordPhc = exports.verifyPassword = exports.hashPassword = exports.KMAC_ALGORITHMS = exports.verifyKmac = exports.computeKmac = exports.HMAC_ALGORITHMS = void 0;
|
|
5
|
+
var aead_1 = require("./aead");
|
|
6
|
+
Object.defineProperty(exports, "aeadEncrypt", { enumerable: true, get: function () { return aead_1.aeadEncrypt; } });
|
|
7
|
+
Object.defineProperty(exports, "aeadDecrypt", { enumerable: true, get: function () { return aead_1.aeadDecrypt; } });
|
|
8
|
+
var aes_1 = require("./aes");
|
|
9
|
+
Object.defineProperty(exports, "aesGcmEncrypt", { enumerable: true, get: function () { return aes_1.aesGcmEncrypt; } });
|
|
10
|
+
Object.defineProperty(exports, "aesGcmDecrypt", { enumerable: true, get: function () { return aes_1.aesGcmDecrypt; } });
|
|
11
|
+
Object.defineProperty(exports, "aesGcmSivEncrypt", { enumerable: true, get: function () { return aes_1.aesGcmSivEncrypt; } });
|
|
12
|
+
Object.defineProperty(exports, "aesGcmSivDecrypt", { enumerable: true, get: function () { return aes_1.aesGcmSivDecrypt; } });
|
|
13
|
+
var hash_1 = require("./hash");
|
|
14
|
+
Object.defineProperty(exports, "hash", { enumerable: true, get: function () { return hash_1.hash; } });
|
|
15
|
+
Object.defineProperty(exports, "HASH_ALGORITHMS", { enumerable: true, get: function () { return hash_1.HASH_ALGORITHMS; } });
|
|
16
|
+
var kdf_1 = require("./kdf");
|
|
17
|
+
Object.defineProperty(exports, "kdfDerive", { enumerable: true, get: function () { return kdf_1.kdfDerive; } });
|
|
18
|
+
Object.defineProperty(exports, "KDF_ALGORITHMS", { enumerable: true, get: function () { return kdf_1.KDF_ALGORITHMS; } });
|
|
19
|
+
var signing_1 = require("./signing");
|
|
20
|
+
Object.defineProperty(exports, "generateEd25519KeyPair", { enumerable: true, get: function () { return signing_1.generateEd25519KeyPair; } });
|
|
21
|
+
Object.defineProperty(exports, "ed25519Sign", { enumerable: true, get: function () { return signing_1.ed25519Sign; } });
|
|
22
|
+
Object.defineProperty(exports, "ed25519Verify", { enumerable: true, get: function () { return signing_1.ed25519Verify; } });
|
|
23
|
+
var ecdh_1 = require("./ecdh");
|
|
24
|
+
Object.defineProperty(exports, "generateX25519KeyPair", { enumerable: true, get: function () { return ecdh_1.generateX25519KeyPair; } });
|
|
25
|
+
Object.defineProperty(exports, "x25519Exchange", { enumerable: true, get: function () { return ecdh_1.x25519Exchange; } });
|
|
26
|
+
var pq_1 = require("./pq");
|
|
27
|
+
Object.defineProperty(exports, "mlKemGenerateKeyPair", { enumerable: true, get: function () { return pq_1.mlKemGenerateKeyPair; } });
|
|
28
|
+
Object.defineProperty(exports, "mlKemEncapsulate", { enumerable: true, get: function () { return pq_1.mlKemEncapsulate; } });
|
|
29
|
+
Object.defineProperty(exports, "mlKemDecapsulate", { enumerable: true, get: function () { return pq_1.mlKemDecapsulate; } });
|
|
30
|
+
Object.defineProperty(exports, "hybridGenerateKeyPair", { enumerable: true, get: function () { return pq_1.hybridGenerateKeyPair; } });
|
|
31
|
+
Object.defineProperty(exports, "hybridEncapsulate", { enumerable: true, get: function () { return pq_1.hybridEncapsulate; } });
|
|
32
|
+
Object.defineProperty(exports, "hybridDecapsulate", { enumerable: true, get: function () { return pq_1.hybridDecapsulate; } });
|
|
33
|
+
var pq_kem_1 = require("./pq-kem");
|
|
34
|
+
Object.defineProperty(exports, "mlKemKeygen", { enumerable: true, get: function () { return pq_kem_1.mlKemKeygen; } });
|
|
35
|
+
Object.defineProperty(exports, "mlKemEncap", { enumerable: true, get: function () { return pq_kem_1.mlKemEncapsulate; } });
|
|
36
|
+
Object.defineProperty(exports, "mlKemDecap", { enumerable: true, get: function () { return pq_kem_1.mlKemDecapsulate; } });
|
|
37
|
+
Object.defineProperty(exports, "hybridKemKeygen", { enumerable: true, get: function () { return pq_kem_1.hybridKemKeygen; } });
|
|
38
|
+
Object.defineProperty(exports, "hybridKemEncapsulate", { enumerable: true, get: function () { return pq_kem_1.hybridKemEncapsulate; } });
|
|
39
|
+
Object.defineProperty(exports, "hybridKemDecapsulate", { enumerable: true, get: function () { return pq_kem_1.hybridKemDecapsulate; } });
|
|
40
|
+
Object.defineProperty(exports, "p256MlKemKeygen", { enumerable: true, get: function () { return pq_kem_1.p256MlKemKeygen; } });
|
|
41
|
+
Object.defineProperty(exports, "p256MlKemEncapsulate", { enumerable: true, get: function () { return pq_kem_1.p256MlKemEncapsulate; } });
|
|
42
|
+
Object.defineProperty(exports, "p256MlKemDecapsulate", { enumerable: true, get: function () { return pq_kem_1.p256MlKemDecapsulate; } });
|
|
43
|
+
Object.defineProperty(exports, "x448MlKemKeygen", { enumerable: true, get: function () { return pq_kem_1.x448MlKemKeygen; } });
|
|
44
|
+
Object.defineProperty(exports, "x448MlKemEncapsulate", { enumerable: true, get: function () { return pq_kem_1.x448MlKemEncapsulate; } });
|
|
45
|
+
Object.defineProperty(exports, "x448MlKemDecapsulate", { enumerable: true, get: function () { return pq_kem_1.x448MlKemDecapsulate; } });
|
|
46
|
+
Object.defineProperty(exports, "RFC10024_X25519_MLKEM768", { enumerable: true, get: function () { return pq_kem_1.RFC10024_X25519_MLKEM768; } });
|
|
47
|
+
Object.defineProperty(exports, "RFC10024_SECP256R1_MLKEM768", { enumerable: true, get: function () { return pq_kem_1.RFC10024_SECP256R1_MLKEM768; } });
|
|
48
|
+
Object.defineProperty(exports, "RFC10024_CODEPOINTS", { enumerable: true, get: function () { return pq_kem_1.RFC10024_CODEPOINTS; } });
|
|
49
|
+
Object.defineProperty(exports, "normalizeHybridKemAlgorithm", { enumerable: true, get: function () { return pq_kem_1.normalizeHybridKemAlgorithm; } });
|
|
50
|
+
var pq_sign_1 = require("./pq-sign");
|
|
51
|
+
Object.defineProperty(exports, "mlDsaKeygen", { enumerable: true, get: function () { return pq_sign_1.mlDsaKeygen; } });
|
|
52
|
+
Object.defineProperty(exports, "mlDsaSign", { enumerable: true, get: function () { return pq_sign_1.mlDsaSign; } });
|
|
53
|
+
Object.defineProperty(exports, "mlDsaVerify", { enumerable: true, get: function () { return pq_sign_1.mlDsaVerify; } });
|
|
54
|
+
Object.defineProperty(exports, "hybridSign", { enumerable: true, get: function () { return pq_sign_1.hybridSign; } });
|
|
55
|
+
Object.defineProperty(exports, "hybridVerify", { enumerable: true, get: function () { return pq_sign_1.hybridVerify; } });
|
|
56
|
+
var fn_dsa_1 = require("./fn-dsa");
|
|
57
|
+
Object.defineProperty(exports, "fnDsaKeygen", { enumerable: true, get: function () { return fn_dsa_1.fnDsaKeygen; } });
|
|
58
|
+
Object.defineProperty(exports, "fnDsaSign", { enumerable: true, get: function () { return fn_dsa_1.fnDsaSign; } });
|
|
59
|
+
Object.defineProperty(exports, "fnDsaVerify", { enumerable: true, get: function () { return fn_dsa_1.fnDsaVerify; } });
|
|
60
|
+
var pq_hash_sign_1 = require("./pq-hash-sign");
|
|
61
|
+
Object.defineProperty(exports, "slhDsaKeygen", { enumerable: true, get: function () { return pq_hash_sign_1.slhDsaKeygen; } });
|
|
62
|
+
Object.defineProperty(exports, "slhDsaSign", { enumerable: true, get: function () { return pq_hash_sign_1.slhDsaSign; } });
|
|
63
|
+
Object.defineProperty(exports, "slhDsaVerify", { enumerable: true, get: function () { return pq_hash_sign_1.slhDsaVerify; } });
|
|
64
|
+
var mac_1 = require("./mac");
|
|
65
|
+
Object.defineProperty(exports, "computeHmac", { enumerable: true, get: function () { return mac_1.computeHmac; } });
|
|
66
|
+
Object.defineProperty(exports, "verifyHmac", { enumerable: true, get: function () { return mac_1.verifyHmac; } });
|
|
67
|
+
Object.defineProperty(exports, "HMAC_ALGORITHMS", { enumerable: true, get: function () { return mac_1.HMAC_ALGORITHMS; } });
|
|
68
|
+
Object.defineProperty(exports, "computeKmac", { enumerable: true, get: function () { return mac_1.computeKmac; } });
|
|
69
|
+
Object.defineProperty(exports, "verifyKmac", { enumerable: true, get: function () { return mac_1.verifyKmac; } });
|
|
70
|
+
Object.defineProperty(exports, "KMAC_ALGORITHMS", { enumerable: true, get: function () { return mac_1.KMAC_ALGORITHMS; } });
|
|
71
|
+
var password_1 = require("./password");
|
|
72
|
+
Object.defineProperty(exports, "hashPassword", { enumerable: true, get: function () { return password_1.hashPassword; } });
|
|
73
|
+
Object.defineProperty(exports, "verifyPassword", { enumerable: true, get: function () { return password_1.verifyPassword; } });
|
|
74
|
+
Object.defineProperty(exports, "verifyPasswordPhc", { enumerable: true, get: function () { return password_1.verifyPasswordPhc; } });
|
|
75
|
+
var curves_1 = require("./curves");
|
|
76
|
+
Object.defineProperty(exports, "generateP256KeyPair", { enumerable: true, get: function () { return curves_1.generateP256KeyPair; } });
|
|
77
|
+
Object.defineProperty(exports, "p256Sign", { enumerable: true, get: function () { return curves_1.p256Sign; } });
|
|
78
|
+
Object.defineProperty(exports, "p256Verify", { enumerable: true, get: function () { return curves_1.p256Verify; } });
|
|
79
|
+
Object.defineProperty(exports, "generateP384KeyPair", { enumerable: true, get: function () { return curves_1.generateP384KeyPair; } });
|
|
80
|
+
Object.defineProperty(exports, "p384Sign", { enumerable: true, get: function () { return curves_1.p384Sign; } });
|
|
81
|
+
Object.defineProperty(exports, "p384Verify", { enumerable: true, get: function () { return curves_1.p384Verify; } });
|
|
82
|
+
Object.defineProperty(exports, "generateEd448KeyPair", { enumerable: true, get: function () { return curves_1.generateEd448KeyPair; } });
|
|
83
|
+
Object.defineProperty(exports, "ed448Sign", { enumerable: true, get: function () { return curves_1.ed448Sign; } });
|
|
84
|
+
Object.defineProperty(exports, "ed448Verify", { enumerable: true, get: function () { return curves_1.ed448Verify; } });
|
|
85
|
+
Object.defineProperty(exports, "generateX448KeyPair", { enumerable: true, get: function () { return curves_1.generateX448KeyPair; } });
|
|
86
|
+
Object.defineProperty(exports, "x448Exchange", { enumerable: true, get: function () { return curves_1.x448Exchange; } });
|
|
87
|
+
Object.defineProperty(exports, "ecdhP256", { enumerable: true, get: function () { return curves_1.ecdhP256; } });
|
|
88
|
+
Object.defineProperty(exports, "ecdhP384", { enumerable: true, get: function () { return curves_1.ecdhP384; } });
|
|
89
|
+
Object.defineProperty(exports, "generateSchnorrKeyPair", { enumerable: true, get: function () { return curves_1.generateSchnorrKeyPair; } });
|
|
90
|
+
Object.defineProperty(exports, "schnorrSign", { enumerable: true, get: function () { return curves_1.schnorrSign; } });
|
|
91
|
+
Object.defineProperty(exports, "schnorrVerify", { enumerable: true, get: function () { return curves_1.schnorrVerify; } });
|
|
92
|
+
var hpke_1 = require("./hpke");
|
|
93
|
+
Object.defineProperty(exports, "hpkeGenerateKeyPair", { enumerable: true, get: function () { return hpke_1.hpkeGenerateKeyPair; } });
|
|
94
|
+
Object.defineProperty(exports, "hpkeSeal", { enumerable: true, get: function () { return hpke_1.hpkeSeal; } });
|
|
95
|
+
Object.defineProperty(exports, "hpkeOpen", { enumerable: true, get: function () { return hpke_1.hpkeOpen; } });
|
|
96
|
+
exports.SUPPORTED_ALGORITHMS = {
|
|
97
|
+
encryption: [
|
|
98
|
+
"xchacha20-poly1305",
|
|
99
|
+
"aes-128-gcm",
|
|
100
|
+
"aes-256-gcm",
|
|
101
|
+
"aes-128-gcm-siv",
|
|
102
|
+
"aes-256-gcm-siv",
|
|
103
|
+
],
|
|
104
|
+
hashing: [
|
|
105
|
+
"sha256",
|
|
106
|
+
"sha384",
|
|
107
|
+
"sha512",
|
|
108
|
+
"sha3-256",
|
|
109
|
+
"sha3-512",
|
|
110
|
+
"blake2b",
|
|
111
|
+
"blake3",
|
|
112
|
+
],
|
|
113
|
+
kdf: [
|
|
114
|
+
"scrypt",
|
|
115
|
+
"hkdf-sha256",
|
|
116
|
+
"pbkdf2-sha256",
|
|
117
|
+
"argon2id",
|
|
118
|
+
"argon2i",
|
|
119
|
+
"argon2d",
|
|
120
|
+
],
|
|
121
|
+
mac: [
|
|
122
|
+
"hmac-sha256",
|
|
123
|
+
"hmac-sha384",
|
|
124
|
+
"hmac-sha512",
|
|
125
|
+
"hmac-sha3-256",
|
|
126
|
+
"hmac-sha3-512",
|
|
127
|
+
"kmac-128",
|
|
128
|
+
"kmac-256",
|
|
129
|
+
],
|
|
130
|
+
signing: [
|
|
131
|
+
"ed25519",
|
|
132
|
+
"ed448",
|
|
133
|
+
"ecdsa-p256",
|
|
134
|
+
"ecdsa-p384",
|
|
135
|
+
"schnorr",
|
|
136
|
+
"ml-dsa-44",
|
|
137
|
+
"ml-dsa-65",
|
|
138
|
+
"ml-dsa-87",
|
|
139
|
+
"slh-dsa-sha2-128f",
|
|
140
|
+
"slh-dsa-sha2-128s",
|
|
141
|
+
"slh-dsa-sha2-192f",
|
|
142
|
+
"slh-dsa-sha2-192s",
|
|
143
|
+
"slh-dsa-sha2-256f",
|
|
144
|
+
"slh-dsa-sha2-256s",
|
|
145
|
+
"slh-dsa-shake-128f",
|
|
146
|
+
"slh-dsa-shake-128s",
|
|
147
|
+
"slh-dsa-shake-192f",
|
|
148
|
+
"slh-dsa-shake-192s",
|
|
149
|
+
"slh-dsa-shake-256f",
|
|
150
|
+
"slh-dsa-shake-256s",
|
|
151
|
+
"ed25519-ml-dsa-44",
|
|
152
|
+
"ed25519-ml-dsa-65",
|
|
153
|
+
"ed25519-ml-dsa-87",
|
|
154
|
+
"fn-dsa-512",
|
|
155
|
+
"fn-dsa-1024",
|
|
156
|
+
],
|
|
157
|
+
keyExchange: [
|
|
158
|
+
"x25519",
|
|
159
|
+
"x448",
|
|
160
|
+
"ecdh-p256",
|
|
161
|
+
"ecdh-p384",
|
|
162
|
+
"x25519-ml-kem-512",
|
|
163
|
+
"x25519-ml-kem-768",
|
|
164
|
+
"x25519-ml-kem-1024",
|
|
165
|
+
"p256-ml-kem-768",
|
|
166
|
+
"x448-ml-kem-1024",
|
|
167
|
+
"hpke-x25519-chacha20",
|
|
168
|
+
"hpke-x25519-aes128gcm",
|
|
169
|
+
"hpke-p256-aes128gcm",
|
|
170
|
+
],
|
|
171
|
+
postQuantum: [
|
|
172
|
+
"ml-kem-512",
|
|
173
|
+
"ml-kem-768",
|
|
174
|
+
"ml-kem-1024",
|
|
175
|
+
"ml-dsa-44",
|
|
176
|
+
"ml-dsa-65",
|
|
177
|
+
"ml-dsa-87",
|
|
178
|
+
"slh-dsa-sha2-128f",
|
|
179
|
+
"slh-dsa-sha2-128s",
|
|
180
|
+
"slh-dsa-sha2-192f",
|
|
181
|
+
"slh-dsa-sha2-192s",
|
|
182
|
+
"slh-dsa-sha2-256f",
|
|
183
|
+
"slh-dsa-sha2-256s",
|
|
184
|
+
"slh-dsa-shake-128f",
|
|
185
|
+
"slh-dsa-shake-128s",
|
|
186
|
+
"slh-dsa-shake-192f",
|
|
187
|
+
"slh-dsa-shake-192s",
|
|
188
|
+
"slh-dsa-shake-256f",
|
|
189
|
+
"slh-dsa-shake-256s",
|
|
190
|
+
"fn-dsa-512",
|
|
191
|
+
"fn-dsa-1024",
|
|
192
|
+
],
|
|
193
|
+
};
|
|
194
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
export declare const KDF_ALGORITHMS: readonly ["scrypt", "hkdf-sha256", "pbkdf2-sha256"];
|
|
2
|
+
export type KdfAlgorithm = (typeof KDF_ALGORITHMS)[number];
|
|
3
|
+
export interface KdfDeriveOptions {
|
|
4
|
+
algorithm: KdfAlgorithm;
|
|
5
|
+
password: string | Uint8Array;
|
|
6
|
+
salt?: string | Uint8Array;
|
|
7
|
+
keyLength?: number;
|
|
8
|
+
params?: {
|
|
9
|
+
N?: number;
|
|
10
|
+
r?: number;
|
|
11
|
+
p?: number;
|
|
12
|
+
iterations?: number;
|
|
13
|
+
info?: string | Uint8Array;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
export interface KdfResult {
|
|
17
|
+
derivedKey: string;
|
|
18
|
+
salt: string;
|
|
19
|
+
algorithm: KdfAlgorithm;
|
|
20
|
+
keyLength: number;
|
|
21
|
+
}
|
|
22
|
+
export declare function kdfDerive(options: KdfDeriveOptions): KdfResult;
|
|
23
|
+
//# sourceMappingURL=kdf.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"kdf.d.ts","sourceRoot":"","sources":["../../src/modern/kdf.ts"],"names":[],"mappings":"AAqBA,eAAO,MAAM,cAAc,qDAIjB,CAAC;AAEX,MAAM,MAAM,YAAY,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAC;AAG3D,MAAM,WAAW,gBAAgB;IAE/B,SAAS,EAAE,YAAY,CAAC;IAExB,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAC;IAE9B,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAE3B,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,MAAM,CAAC,EAAE;QAEP,CAAC,CAAC,EAAE,MAAM,CAAC;QAEX,CAAC,CAAC,EAAE,MAAM,CAAC;QAEX,CAAC,CAAC,EAAE,MAAM,CAAC;QAEX,UAAU,CAAC,EAAE,MAAM,CAAC;QAEpB,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;KAC5B,CAAC;CACH;AAGD,MAAM,WAAW,SAAS;IAExB,UAAU,EAAE,MAAM,CAAC;IAEnB,IAAI,EAAE,MAAM,CAAC;IAEb,SAAS,EAAE,YAAY,CAAC;IAExB,SAAS,EAAE,MAAM,CAAC;CACnB;AAuBD,wBAAgB,SAAS,CAAC,OAAO,EAAE,gBAAgB,GAAG,SAAS,CAyC9D"}
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KDF_ALGORITHMS = void 0;
|
|
4
|
+
exports.kdfDerive = kdfDerive;
|
|
5
|
+
const scrypt_js_1 = require("@noble/hashes/scrypt.js");
|
|
6
|
+
const hkdf_js_1 = require("@noble/hashes/hkdf.js");
|
|
7
|
+
const pbkdf2_js_1 = require("@noble/hashes/pbkdf2.js");
|
|
8
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
9
|
+
const utils_js_1 = require("@noble/ciphers/utils.js");
|
|
10
|
+
const cost_limits_1 = require("./cost-limits");
|
|
11
|
+
exports.KDF_ALGORITHMS = [
|
|
12
|
+
"scrypt",
|
|
13
|
+
"hkdf-sha256",
|
|
14
|
+
"pbkdf2-sha256",
|
|
15
|
+
];
|
|
16
|
+
const HEX_RE = /^[0-9a-fA-F]*$/;
|
|
17
|
+
function toBytes(input, encoding = "utf8") {
|
|
18
|
+
if (input instanceof Uint8Array)
|
|
19
|
+
return input;
|
|
20
|
+
if (encoding === "hex") {
|
|
21
|
+
if (!HEX_RE.test(input)) {
|
|
22
|
+
throw new Error("Invalid hex string");
|
|
23
|
+
}
|
|
24
|
+
return Buffer.from(input, "hex");
|
|
25
|
+
}
|
|
26
|
+
return Buffer.from(input, "utf8");
|
|
27
|
+
}
|
|
28
|
+
function kdfDerive(options) {
|
|
29
|
+
const password = toBytes(options.password, "utf8");
|
|
30
|
+
const salt = options.salt ? toBytes(options.salt, "hex") : (0, utils_js_1.randomBytes)(16);
|
|
31
|
+
const keyLength = options.keyLength ?? 32;
|
|
32
|
+
const params = options.params ?? {};
|
|
33
|
+
let derived;
|
|
34
|
+
switch (options.algorithm) {
|
|
35
|
+
case "scrypt": {
|
|
36
|
+
const N = params.N ?? 131072;
|
|
37
|
+
const r = params.r ?? 8;
|
|
38
|
+
const p = params.p ?? 1;
|
|
39
|
+
(0, cost_limits_1.checkScryptCosts)(N, r, p);
|
|
40
|
+
derived = (0, scrypt_js_1.scrypt)(password, salt, { N, r, p, dkLen: keyLength });
|
|
41
|
+
break;
|
|
42
|
+
}
|
|
43
|
+
case "hkdf-sha256": {
|
|
44
|
+
const info = params.info ? toBytes(params.info, "utf8") : undefined;
|
|
45
|
+
derived = (0, hkdf_js_1.hkdf)(sha2_js_1.sha256, password, salt, info, keyLength);
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
case "pbkdf2-sha256": {
|
|
49
|
+
const iterations = params.iterations ?? 600000;
|
|
50
|
+
(0, cost_limits_1.checkPbkdf2Iterations)(iterations);
|
|
51
|
+
derived = (0, pbkdf2_js_1.pbkdf2)(sha2_js_1.sha256, password, salt, {
|
|
52
|
+
c: iterations,
|
|
53
|
+
dkLen: keyLength,
|
|
54
|
+
});
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
default:
|
|
58
|
+
throw new Error(`Unsupported KDF algorithm: ${options.algorithm}`);
|
|
59
|
+
}
|
|
60
|
+
return {
|
|
61
|
+
derivedKey: Buffer.from(derived).toString("hex"),
|
|
62
|
+
salt: Buffer.from(salt).toString("hex"),
|
|
63
|
+
algorithm: options.algorithm,
|
|
64
|
+
keyLength,
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//# sourceMappingURL=kdf.js.map
|