@sebastienrousseau/crypto-lib 0.0.2 → 0.0.8
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,51 @@
|
|
|
1
|
+
export declare const HMAC_ALGORITHMS: readonly ["sha256", "sha384", "sha512", "sha3-256", "sha3-512"];
|
|
2
|
+
export type HmacAlgorithm = (typeof HMAC_ALGORITHMS)[number];
|
|
3
|
+
export interface HmacComputeOptions {
|
|
4
|
+
algorithm: HmacAlgorithm;
|
|
5
|
+
key: string | Uint8Array;
|
|
6
|
+
data: string | Uint8Array;
|
|
7
|
+
}
|
|
8
|
+
export interface HmacComputeResult {
|
|
9
|
+
mac: string;
|
|
10
|
+
algorithm: HmacAlgorithm;
|
|
11
|
+
}
|
|
12
|
+
export interface HmacVerifyOptions {
|
|
13
|
+
algorithm: HmacAlgorithm;
|
|
14
|
+
key: string | Uint8Array;
|
|
15
|
+
data: string | Uint8Array;
|
|
16
|
+
mac: string;
|
|
17
|
+
}
|
|
18
|
+
export interface HmacVerifyResult {
|
|
19
|
+
valid: boolean;
|
|
20
|
+
algorithm: HmacAlgorithm;
|
|
21
|
+
}
|
|
22
|
+
export declare function computeHmac(options: HmacComputeOptions): HmacComputeResult;
|
|
23
|
+
export declare function verifyHmac(options: HmacVerifyOptions): HmacVerifyResult;
|
|
24
|
+
export declare const KMAC_ALGORITHMS: readonly ["kmac-128", "kmac-256"];
|
|
25
|
+
export type KmacAlgorithm = (typeof KMAC_ALGORITHMS)[number];
|
|
26
|
+
export interface KmacComputeOptions {
|
|
27
|
+
algorithm: KmacAlgorithm;
|
|
28
|
+
key: string | Uint8Array;
|
|
29
|
+
data: string | Uint8Array;
|
|
30
|
+
customization?: string | Uint8Array;
|
|
31
|
+
outputLength?: number;
|
|
32
|
+
}
|
|
33
|
+
export interface KmacComputeResult {
|
|
34
|
+
mac: string;
|
|
35
|
+
algorithm: KmacAlgorithm;
|
|
36
|
+
}
|
|
37
|
+
export interface KmacVerifyOptions {
|
|
38
|
+
algorithm: KmacAlgorithm;
|
|
39
|
+
key: string | Uint8Array;
|
|
40
|
+
data: string | Uint8Array;
|
|
41
|
+
mac: string;
|
|
42
|
+
customization?: string | Uint8Array;
|
|
43
|
+
outputLength?: number;
|
|
44
|
+
}
|
|
45
|
+
export interface KmacVerifyResult {
|
|
46
|
+
valid: boolean;
|
|
47
|
+
algorithm: KmacAlgorithm;
|
|
48
|
+
}
|
|
49
|
+
export declare function computeKmac(options: KmacComputeOptions): KmacComputeResult;
|
|
50
|
+
export declare function verifyKmac(options: KmacVerifyOptions): KmacVerifyResult;
|
|
51
|
+
//# sourceMappingURL=mac.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mac.d.ts","sourceRoot":"","sources":["../../src/modern/mac.ts"],"names":[],"mappings":"AAsBA,eAAO,MAAM,eAAe,iEAMlB,CAAC;AAGX,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO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M,GAAG,UAAU,CAAC;IAEzB,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;IAE1B,GAAG,EAAE,MAAM,CAAC;IAEZ,aAAa,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAEpC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAGD,MAAM,WAAW,gBAAgB;IAE/B,KAAK,EAAE,OAAO,CAAC;IAEf,SAAS,EAAE,aAAa,CAAC;CAC1B;AAoBD,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,iBAAiB,CA0B1E;AAKD,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,gBAAgB,CA4BvE"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.KMAC_ALGORITHMS = exports.HMAC_ALGORITHMS = void 0;
|
|
4
|
+
exports.computeHmac = computeHmac;
|
|
5
|
+
exports.verifyHmac = verifyHmac;
|
|
6
|
+
exports.computeKmac = computeKmac;
|
|
7
|
+
exports.verifyKmac = verifyKmac;
|
|
8
|
+
const hmac_js_1 = require("@noble/hashes/hmac.js");
|
|
9
|
+
const sha2_js_1 = require("@noble/hashes/sha2.js");
|
|
10
|
+
const sha3_js_1 = require("@noble/hashes/sha3.js");
|
|
11
|
+
const sha3_addons_js_1 = require("@noble/hashes/sha3-addons.js");
|
|
12
|
+
const utils_1 = require("../utils");
|
|
13
|
+
exports.HMAC_ALGORITHMS = [
|
|
14
|
+
"sha256",
|
|
15
|
+
"sha384",
|
|
16
|
+
"sha512",
|
|
17
|
+
"sha3-256",
|
|
18
|
+
"sha3-512",
|
|
19
|
+
];
|
|
20
|
+
const HEX_RE = /^[0-9a-fA-F]*$/;
|
|
21
|
+
function toBytes(input, encoding = "utf8") {
|
|
22
|
+
if (input instanceof Uint8Array)
|
|
23
|
+
return input;
|
|
24
|
+
if (encoding === "hex") {
|
|
25
|
+
if (!HEX_RE.test(input)) {
|
|
26
|
+
throw new Error("Invalid hex string");
|
|
27
|
+
}
|
|
28
|
+
return Buffer.from(input, "hex");
|
|
29
|
+
}
|
|
30
|
+
return Buffer.from(input, "utf8");
|
|
31
|
+
}
|
|
32
|
+
const hashFunctions = {
|
|
33
|
+
sha256: sha2_js_1.sha256,
|
|
34
|
+
sha384: sha2_js_1.sha384,
|
|
35
|
+
sha512: sha2_js_1.sha512,
|
|
36
|
+
"sha3-256": sha3_js_1.sha3_256,
|
|
37
|
+
"sha3-512": sha3_js_1.sha3_512,
|
|
38
|
+
};
|
|
39
|
+
function getHashFn(algorithm) {
|
|
40
|
+
const fn = hashFunctions[algorithm];
|
|
41
|
+
if (!fn) {
|
|
42
|
+
throw new Error(`Unsupported HMAC algorithm: ${algorithm}. Supported: ${exports.HMAC_ALGORITHMS.join(", ")}`);
|
|
43
|
+
}
|
|
44
|
+
return fn;
|
|
45
|
+
}
|
|
46
|
+
function computeHmac(options) {
|
|
47
|
+
const hashFn = getHashFn(options.algorithm);
|
|
48
|
+
const key = toBytes(options.key, "hex");
|
|
49
|
+
const data = toBytes(options.data, "utf8");
|
|
50
|
+
const mac = (0, hmac_js_1.hmac)(hashFn, key, data);
|
|
51
|
+
return {
|
|
52
|
+
mac: Buffer.from(mac).toString("hex"),
|
|
53
|
+
algorithm: options.algorithm,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
function verifyHmac(options) {
|
|
57
|
+
const hashFn = getHashFn(options.algorithm);
|
|
58
|
+
const key = toBytes(options.key, "hex");
|
|
59
|
+
const data = toBytes(options.data, "utf8");
|
|
60
|
+
const expectedMac = toBytes(options.mac, "hex");
|
|
61
|
+
const computedMac = (0, hmac_js_1.hmac)(hashFn, key, data);
|
|
62
|
+
const valid = (0, utils_1.timingSafeEqual)(computedMac, expectedMac);
|
|
63
|
+
return {
|
|
64
|
+
valid,
|
|
65
|
+
algorithm: options.algorithm,
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
exports.KMAC_ALGORITHMS = ["kmac-128", "kmac-256"];
|
|
69
|
+
const kmacFunctions = {
|
|
70
|
+
"kmac-128": sha3_addons_js_1.kmac128,
|
|
71
|
+
"kmac-256": sha3_addons_js_1.kmac256,
|
|
72
|
+
};
|
|
73
|
+
const kmacDefaultLength = {
|
|
74
|
+
"kmac-128": 32,
|
|
75
|
+
"kmac-256": 64,
|
|
76
|
+
};
|
|
77
|
+
function computeKmac(options) {
|
|
78
|
+
const fn = kmacFunctions[options.algorithm];
|
|
79
|
+
if (!fn) {
|
|
80
|
+
throw new Error(`Unsupported KMAC algorithm: ${options.algorithm}. Supported: ${exports.KMAC_ALGORITHMS.join(", ")}`);
|
|
81
|
+
}
|
|
82
|
+
const key = toBytes(options.key, "hex");
|
|
83
|
+
const data = toBytes(options.data, "utf8");
|
|
84
|
+
const outputLength = options.outputLength ?? kmacDefaultLength[options.algorithm];
|
|
85
|
+
const opts = {
|
|
86
|
+
dkLen: outputLength,
|
|
87
|
+
};
|
|
88
|
+
if (options.customization) {
|
|
89
|
+
opts.personalization = toBytes(options.customization, "utf8");
|
|
90
|
+
}
|
|
91
|
+
const mac = fn(key, data, opts);
|
|
92
|
+
return {
|
|
93
|
+
mac: Buffer.from(mac).toString("hex"),
|
|
94
|
+
algorithm: options.algorithm,
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function verifyKmac(options) {
|
|
98
|
+
const fn = kmacFunctions[options.algorithm];
|
|
99
|
+
if (!fn) {
|
|
100
|
+
throw new Error(`Unsupported KMAC algorithm: ${options.algorithm}. Supported: ${exports.KMAC_ALGORITHMS.join(", ")}`);
|
|
101
|
+
}
|
|
102
|
+
const key = toBytes(options.key, "hex");
|
|
103
|
+
const data = toBytes(options.data, "utf8");
|
|
104
|
+
const expectedMac = toBytes(options.mac, "hex");
|
|
105
|
+
const outputLength = options.outputLength ?? kmacDefaultLength[options.algorithm];
|
|
106
|
+
const verifyOpts = {
|
|
107
|
+
dkLen: outputLength,
|
|
108
|
+
};
|
|
109
|
+
if (options.customization) {
|
|
110
|
+
verifyOpts.personalization = toBytes(options.customization, "utf8");
|
|
111
|
+
}
|
|
112
|
+
const computedMac = fn(key, data, verifyOpts);
|
|
113
|
+
const valid = (0, utils_1.timingSafeEqual)(computedMac, expectedMac);
|
|
114
|
+
return {
|
|
115
|
+
valid,
|
|
116
|
+
algorithm: options.algorithm,
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
//# sourceMappingURL=mac.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
export type Argon2Variant = "argon2id" | "argon2i" | "argon2d";
|
|
2
|
+
export interface Argon2Params {
|
|
3
|
+
t: number;
|
|
4
|
+
m: number;
|
|
5
|
+
p: number;
|
|
6
|
+
}
|
|
7
|
+
export interface HashPasswordOptions {
|
|
8
|
+
password: string | Uint8Array;
|
|
9
|
+
salt?: string | Uint8Array;
|
|
10
|
+
timeCost?: number;
|
|
11
|
+
memoryCost?: number;
|
|
12
|
+
parallelism?: number;
|
|
13
|
+
hashLength?: number;
|
|
14
|
+
variant?: Argon2Variant;
|
|
15
|
+
}
|
|
16
|
+
export interface HashPasswordResult {
|
|
17
|
+
hash: string;
|
|
18
|
+
salt: string;
|
|
19
|
+
params: Argon2Params;
|
|
20
|
+
algorithm: Argon2Variant;
|
|
21
|
+
phc: string;
|
|
22
|
+
}
|
|
23
|
+
export interface VerifyPasswordOptions {
|
|
24
|
+
password: string | Uint8Array;
|
|
25
|
+
hash: string;
|
|
26
|
+
salt: string;
|
|
27
|
+
params: Argon2Params;
|
|
28
|
+
variant?: Argon2Variant;
|
|
29
|
+
}
|
|
30
|
+
export interface VerifyPasswordResult {
|
|
31
|
+
valid: boolean;
|
|
32
|
+
}
|
|
33
|
+
export interface VerifyPhcOptions {
|
|
34
|
+
password: string | Uint8Array;
|
|
35
|
+
phc: string;
|
|
36
|
+
}
|
|
37
|
+
export declare function hashPassword(options: HashPasswordOptions): HashPasswordResult;
|
|
38
|
+
export declare function verifyPassword(options: VerifyPasswordOptions): VerifyPasswordResult;
|
|
39
|
+
export declare function verifyPasswordPhc(options: VerifyPhcOptions): VerifyPasswordResult;
|
|
40
|
+
//# sourceMappingURL=password.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"password.d.ts","sourceRoot":"","sources":["../../src/modern/password.ts"],"names":[],"mappings":"AA2BA,MAAM,MAAM,aAAa,GAAG,UAAU,GAAG,SAAS,GAAG,SAAS,CAAC;AAG/D,MAAM,WAAW,YAAY;IAE3B,CAAC,EAAE,MAAM,CAAC;IAEV,CAAC,EAAE,MAAM,CAAC;IAEV,CAAC,EAAE,MAAM,CAAC;CACX;AAGD,MAAM,WAAW,mBAAmB;IAElC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAC;IAE9B,IAAI,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAE3B,QAAQ,CAAC,EAAE,MAAM,CAAC;IAElB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB,UAAU,CAAC,EAAE,MAAM,CAAC;IAEpB,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAGD,MAAM,WAAW,kBAAkB;IAEjC,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,EAAE,MAAM,CAAC;IAEb,MAAM,EAAE,YAAY,CAAC;IAErB,SAAS,EAAE,aAAa,CAAC;IAEzB,GAAG,EAAE,MAAM,CAAC;CACb;AAGD,MAAM,WAAW,qBAAqB;IAEpC,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAC;IAE9B,IAAI,EAAE,MAAM,CAAC;IAEb,IAAI,EAAE,MAAM,CAAC;IAEb,MAAM,EAAE,YAAY,CAAC;IAErB,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAGD,MAAM,WAAW,oBAAoB;IAEnC,KAAK,EAAE,OAAO,CAAC;CAChB;AAGD,MAAM,WAAW,gBAAgB;IAE/B,QAAQ,EAAE,MAAM,GAAG,UAAU,CAAC;IAE9B,GAAG,EAAE,MAAM,CAAC;CACb;AAuGD,wBAAgB,YAAY,CAAC,OAAO,EAAE,mBAAmB,GAAG,kBAAkB,CAuB7E;AAKD,wBAAgB,cAAc,CAC5B,OAAO,EAAE,qBAAqB,GAC7B,oBAAoB,CActB;AAWD,wBAAgB,iBAAiB,CAC/B,OAAO,EAAE,gBAAgB,GACxB,oBAAoB,CAgBtB"}
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.hashPassword = hashPassword;
|
|
4
|
+
exports.verifyPassword = verifyPassword;
|
|
5
|
+
exports.verifyPasswordPhc = verifyPasswordPhc;
|
|
6
|
+
const argon2_js_1 = require("@noble/hashes/argon2.js");
|
|
7
|
+
const utils_js_1 = require("@noble/ciphers/utils.js");
|
|
8
|
+
const utils_1 = require("../utils");
|
|
9
|
+
const cost_limits_1 = require("./cost-limits");
|
|
10
|
+
const HEX_RE = /^[0-9a-fA-F]*$/;
|
|
11
|
+
function toBytes(input, encoding = "utf8") {
|
|
12
|
+
if (input instanceof Uint8Array)
|
|
13
|
+
return input;
|
|
14
|
+
if (encoding === "hex") {
|
|
15
|
+
if (!HEX_RE.test(input)) {
|
|
16
|
+
throw new Error("Invalid hex string");
|
|
17
|
+
}
|
|
18
|
+
return Buffer.from(input, "hex");
|
|
19
|
+
}
|
|
20
|
+
return Buffer.from(input, "utf8");
|
|
21
|
+
}
|
|
22
|
+
function getArgon2Fn(variant) {
|
|
23
|
+
switch (variant) {
|
|
24
|
+
case "argon2id":
|
|
25
|
+
return argon2_js_1.argon2id;
|
|
26
|
+
case "argon2i":
|
|
27
|
+
return argon2_js_1.argon2i;
|
|
28
|
+
case "argon2d":
|
|
29
|
+
return argon2_js_1.argon2d;
|
|
30
|
+
default:
|
|
31
|
+
throw new Error(`Unsupported Argon2 variant: ${variant}. Supported: argon2id, argon2i, argon2d`);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function toPhcString(variant, params, salt, hash) {
|
|
35
|
+
let saltB64 = Buffer.from(salt).toString("base64");
|
|
36
|
+
while (saltB64.endsWith("="))
|
|
37
|
+
saltB64 = saltB64.slice(0, -1);
|
|
38
|
+
let hashB64 = Buffer.from(hash).toString("base64");
|
|
39
|
+
while (hashB64.endsWith("="))
|
|
40
|
+
hashB64 = hashB64.slice(0, -1);
|
|
41
|
+
return `$${variant}$v=19$m=${params.m},t=${params.t},p=${params.p}$${saltB64}$${hashB64}`;
|
|
42
|
+
}
|
|
43
|
+
function parsePhcString(phc) {
|
|
44
|
+
const parts = phc.split("$").filter(Boolean);
|
|
45
|
+
if (parts.length < 5) {
|
|
46
|
+
throw new Error("Invalid PHC string format");
|
|
47
|
+
}
|
|
48
|
+
const variant = parts[0];
|
|
49
|
+
if (!["argon2id", "argon2i", "argon2d"].includes(variant)) {
|
|
50
|
+
throw new Error(`Unsupported variant in PHC string: ${variant}`);
|
|
51
|
+
}
|
|
52
|
+
const paramStr = parts[2];
|
|
53
|
+
const paramParts = paramStr.split(",");
|
|
54
|
+
const paramMap = {};
|
|
55
|
+
for (const p of paramParts) {
|
|
56
|
+
const [k, v] = p.split("=");
|
|
57
|
+
paramMap[k] = parseInt(v, 10);
|
|
58
|
+
}
|
|
59
|
+
const params = {
|
|
60
|
+
m: paramMap["m"],
|
|
61
|
+
t: paramMap["t"],
|
|
62
|
+
p: paramMap["p"],
|
|
63
|
+
};
|
|
64
|
+
const salt = Buffer.from(parts[3], "base64");
|
|
65
|
+
const hash = Buffer.from(parts[4], "base64");
|
|
66
|
+
return { variant, params, salt, hash };
|
|
67
|
+
}
|
|
68
|
+
const DEFAULT_TIME_COST = 3;
|
|
69
|
+
const DEFAULT_MEMORY_COST = 65536;
|
|
70
|
+
const DEFAULT_PARALLELISM = 4;
|
|
71
|
+
const DEFAULT_HASH_LENGTH = 32;
|
|
72
|
+
const DEFAULT_SALT_LENGTH = 16;
|
|
73
|
+
function hashPassword(options) {
|
|
74
|
+
const variant = options.variant ?? "argon2id";
|
|
75
|
+
const argon2Fn = getArgon2Fn(variant);
|
|
76
|
+
const password = toBytes(options.password, "utf8");
|
|
77
|
+
const salt = options.salt
|
|
78
|
+
? toBytes(options.salt, "hex")
|
|
79
|
+
: (0, utils_js_1.randomBytes)(DEFAULT_SALT_LENGTH);
|
|
80
|
+
const t = options.timeCost ?? DEFAULT_TIME_COST;
|
|
81
|
+
const m = options.memoryCost ?? DEFAULT_MEMORY_COST;
|
|
82
|
+
const p = options.parallelism ?? DEFAULT_PARALLELISM;
|
|
83
|
+
const dkLen = options.hashLength ?? DEFAULT_HASH_LENGTH;
|
|
84
|
+
(0, cost_limits_1.checkArgon2Costs)(t, m, p);
|
|
85
|
+
const hash = argon2Fn(password, salt, { t, m, p, dkLen });
|
|
86
|
+
const params = { t, m, p };
|
|
87
|
+
return {
|
|
88
|
+
hash: Buffer.from(hash).toString("hex"),
|
|
89
|
+
salt: Buffer.from(salt).toString("hex"),
|
|
90
|
+
params,
|
|
91
|
+
algorithm: variant,
|
|
92
|
+
phc: toPhcString(variant, params, salt, hash),
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function verifyPassword(options) {
|
|
96
|
+
const variant = options.variant ?? "argon2id";
|
|
97
|
+
const argon2Fn = getArgon2Fn(variant);
|
|
98
|
+
const password = toBytes(options.password, "utf8");
|
|
99
|
+
const salt = toBytes(options.salt, "hex");
|
|
100
|
+
const expectedHash = toBytes(options.hash, "hex");
|
|
101
|
+
const { t, m, p } = options.params;
|
|
102
|
+
(0, cost_limits_1.checkArgon2Costs)(t, m, p);
|
|
103
|
+
const dkLen = expectedHash.length;
|
|
104
|
+
const computedHash = argon2Fn(password, salt, { t, m, p, dkLen });
|
|
105
|
+
const valid = (0, utils_1.timingSafeEqual)(computedHash, expectedHash);
|
|
106
|
+
return { valid };
|
|
107
|
+
}
|
|
108
|
+
function verifyPasswordPhc(options) {
|
|
109
|
+
const { variant, params, salt, hash } = parsePhcString(options.phc);
|
|
110
|
+
const argon2Fn = getArgon2Fn(variant);
|
|
111
|
+
const password = toBytes(options.password, "utf8");
|
|
112
|
+
const dkLen = hash.length;
|
|
113
|
+
(0, cost_limits_1.checkArgon2Costs)(params.t, params.m, params.p);
|
|
114
|
+
const computedHash = argon2Fn(password, salt, {
|
|
115
|
+
t: params.t,
|
|
116
|
+
m: params.m,
|
|
117
|
+
p: params.p,
|
|
118
|
+
dkLen,
|
|
119
|
+
});
|
|
120
|
+
const valid = (0, utils_1.timingSafeEqual)(computedHash, hash);
|
|
121
|
+
return { valid };
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=password.js.map
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
export type SlhDsaVariant = "sha2-128f" | "sha2-128s" | "sha2-192f" | "sha2-192s" | "sha2-256f" | "sha2-256s" | "shake-128f" | "shake-128s" | "shake-192f" | "shake-192s" | "shake-256f" | "shake-256s";
|
|
2
|
+
export interface SlhDsaKeyPairResult {
|
|
3
|
+
publicKey: string;
|
|
4
|
+
secretKey: string;
|
|
5
|
+
algorithm: string;
|
|
6
|
+
}
|
|
7
|
+
export interface SlhDsaSignResult {
|
|
8
|
+
signature: string;
|
|
9
|
+
algorithm: string;
|
|
10
|
+
}
|
|
11
|
+
export interface SlhDsaVerifyResult {
|
|
12
|
+
valid: boolean;
|
|
13
|
+
algorithm: string;
|
|
14
|
+
}
|
|
15
|
+
export declare function slhDsaKeygen(variant: SlhDsaVariant): SlhDsaKeyPairResult;
|
|
16
|
+
export declare function slhDsaSign(variant: SlhDsaVariant, secretKeyHex: string, message: string | Uint8Array): SlhDsaSignResult;
|
|
17
|
+
export declare function slhDsaVerify(variant: SlhDsaVariant, publicKeyHex: string, message: string | Uint8Array, signatureHex: string): SlhDsaVerifyResult;
|
|
18
|
+
//# sourceMappingURL=pq-hash-sign.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pq-hash-sign.d.ts","sourceRoot":"","sources":["../../src/modern/pq-hash-sign.ts"],"names":[],"mappings":"AAqCA,MAAM,MAAM,aAAa,GACrB,WAAW,GACX,WAAW,GACX,WAAW,GACX,WAAW,GACX,WAAW,GACX,WAAW,GACX,YAAY,GACZ,YAAY,GACZ,YAAY,GACZ,YAAY,GACZ,YAAY,GACZ,YAAY,CAAC;AAGjB,MAAM,WAAW,mBAAmB;IAElC,SAAS,EAAE,MAAM,CAAC;IAElB,SAAS,EAAE,MAAM,CAAC;IAElB,SAAS,EAAE,MAAM,CAAC;CACnB;AAGD,MAAM,WAAW,gBAAgB;IAE/B,SAAS,EAAE,MAAM,CAAC;IAElB,SAAS,EAAE,MAAM,CAAC;CACnB;AAGD,MAAM,WAAW,kBAAkB;IAEjC,KAAK,EAAE,OAAO,CAAC;IAEf,SAAS,EAAE,MAAM,CAAC;CACnB;AA0DD,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,GAAG,mBAAmB,CAQxE;AAKD,wBAAgB,UAAU,CACxB,OAAO,EAAE,aAAa,EACtB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,GAAG,UAAU,GAC3B,gBAAgB,CASlB;AAKD,wBAAgB,YAAY,CAC1B,OAAO,EAAE,aAAa,EACtB,YAAY,EAAE,MAAM,EACpB,OAAO,EAAE,MAAM,GAAG,UAAU,EAC5B,YAAY,EAAE,MAAM,GACnB,kBAAkB,CAUpB"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.slhDsaKeygen = slhDsaKeygen;
|
|
4
|
+
exports.slhDsaSign = slhDsaSign;
|
|
5
|
+
exports.slhDsaVerify = slhDsaVerify;
|
|
6
|
+
const slh_dsa_js_1 = require("@noble/post-quantum/slh-dsa.js");
|
|
7
|
+
const HEX_RE = /^[0-9a-fA-F]*$/;
|
|
8
|
+
function assertHex(input, label) {
|
|
9
|
+
if (!HEX_RE.test(input)) {
|
|
10
|
+
throw new Error(`Invalid hex string for ${label}`);
|
|
11
|
+
}
|
|
12
|
+
return Buffer.from(input, "hex");
|
|
13
|
+
}
|
|
14
|
+
function toBytes(input) {
|
|
15
|
+
if (input instanceof Uint8Array)
|
|
16
|
+
return input;
|
|
17
|
+
return Buffer.from(input, "utf8");
|
|
18
|
+
}
|
|
19
|
+
const SLH_DSA_VARIANTS = {
|
|
20
|
+
"sha2-128f": slh_dsa_js_1.slh_dsa_sha2_128f,
|
|
21
|
+
"sha2-128s": slh_dsa_js_1.slh_dsa_sha2_128s,
|
|
22
|
+
"sha2-192f": slh_dsa_js_1.slh_dsa_sha2_192f,
|
|
23
|
+
"sha2-192s": slh_dsa_js_1.slh_dsa_sha2_192s,
|
|
24
|
+
"sha2-256f": slh_dsa_js_1.slh_dsa_sha2_256f,
|
|
25
|
+
"sha2-256s": slh_dsa_js_1.slh_dsa_sha2_256s,
|
|
26
|
+
"shake-128f": slh_dsa_js_1.slh_dsa_shake_128f,
|
|
27
|
+
"shake-128s": slh_dsa_js_1.slh_dsa_shake_128s,
|
|
28
|
+
"shake-192f": slh_dsa_js_1.slh_dsa_shake_192f,
|
|
29
|
+
"shake-192s": slh_dsa_js_1.slh_dsa_shake_192s,
|
|
30
|
+
"shake-256f": slh_dsa_js_1.slh_dsa_shake_256f,
|
|
31
|
+
"shake-256s": slh_dsa_js_1.slh_dsa_shake_256s,
|
|
32
|
+
};
|
|
33
|
+
function getVariant(variant) {
|
|
34
|
+
const impl = SLH_DSA_VARIANTS[variant];
|
|
35
|
+
if (!impl) {
|
|
36
|
+
throw new Error(`Unsupported SLH-DSA variant: ${variant}. Supported: ${Object.keys(SLH_DSA_VARIANTS).join(", ")}`);
|
|
37
|
+
}
|
|
38
|
+
return impl;
|
|
39
|
+
}
|
|
40
|
+
function algorithmName(variant) {
|
|
41
|
+
return `slh-dsa-${variant}`;
|
|
42
|
+
}
|
|
43
|
+
function slhDsaKeygen(variant) {
|
|
44
|
+
const dsa = getVariant(variant);
|
|
45
|
+
const { publicKey, secretKey } = dsa.keygen();
|
|
46
|
+
return {
|
|
47
|
+
publicKey: Buffer.from(publicKey).toString("hex"),
|
|
48
|
+
secretKey: Buffer.from(secretKey).toString("hex"),
|
|
49
|
+
algorithm: algorithmName(variant),
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function slhDsaSign(variant, secretKeyHex, message) {
|
|
53
|
+
const dsa = getVariant(variant);
|
|
54
|
+
const secretKey = assertHex(secretKeyHex, "secretKey");
|
|
55
|
+
const msg = toBytes(message);
|
|
56
|
+
const signature = dsa.sign(msg, secretKey);
|
|
57
|
+
return {
|
|
58
|
+
signature: Buffer.from(signature).toString("hex"),
|
|
59
|
+
algorithm: algorithmName(variant),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function slhDsaVerify(variant, publicKeyHex, message, signatureHex) {
|
|
63
|
+
const dsa = getVariant(variant);
|
|
64
|
+
const publicKey = assertHex(publicKeyHex, "publicKey");
|
|
65
|
+
const msg = toBytes(message);
|
|
66
|
+
const signature = assertHex(signatureHex, "signature");
|
|
67
|
+
const valid = dsa.verify(signature, msg, publicKey);
|
|
68
|
+
return {
|
|
69
|
+
valid,
|
|
70
|
+
algorithm: algorithmName(variant),
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=pq-hash-sign.js.map
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
export type MlKemLevel = 512 | 768 | 1024;
|
|
2
|
+
export type MlKemAlgorithm = "ml-kem-512" | "ml-kem-768" | "ml-kem-1024";
|
|
3
|
+
export declare const RFC10024_X25519_MLKEM768: "X25519MLKEM768";
|
|
4
|
+
export declare const RFC10024_SECP256R1_MLKEM768: "SecP256r1MLKEM768";
|
|
5
|
+
export declare const RFC10024_CODEPOINTS: {
|
|
6
|
+
readonly SecP256r1MLKEM768: 4587;
|
|
7
|
+
readonly X25519MLKEM768: 4588;
|
|
8
|
+
};
|
|
9
|
+
export type HybridKemAlgorithm = "x25519-ml-kem-512" | "x25519-ml-kem-768" | "x25519-ml-kem-1024" | "p256-ml-kem-768" | "x448-ml-kem-1024";
|
|
10
|
+
export declare function normalizeHybridKemAlgorithm(name: HybridKemAlgorithm | string): string;
|
|
11
|
+
export interface MlKemKeyPairResult {
|
|
12
|
+
publicKey: string;
|
|
13
|
+
secretKey: string;
|
|
14
|
+
algorithm: MlKemAlgorithm;
|
|
15
|
+
}
|
|
16
|
+
export interface MlKemEncapsulateResult {
|
|
17
|
+
ciphertext: string;
|
|
18
|
+
sharedSecret: string;
|
|
19
|
+
algorithm: MlKemAlgorithm;
|
|
20
|
+
}
|
|
21
|
+
export interface MlKemDecapsulateResult {
|
|
22
|
+
sharedSecret: string;
|
|
23
|
+
algorithm: MlKemAlgorithm;
|
|
24
|
+
}
|
|
25
|
+
export interface HybridKemKeyPair {
|
|
26
|
+
x25519PrivateKey: string;
|
|
27
|
+
x25519PublicKey: string;
|
|
28
|
+
mlKemPublicKey: string;
|
|
29
|
+
mlKemSecretKey: string;
|
|
30
|
+
algorithm: HybridKemAlgorithm;
|
|
31
|
+
}
|
|
32
|
+
export interface HybridKemEncapsulateResult {
|
|
33
|
+
x25519EphemeralPublic: string;
|
|
34
|
+
mlKemCiphertext: string;
|
|
35
|
+
sharedSecret: string;
|
|
36
|
+
algorithm: HybridKemAlgorithm;
|
|
37
|
+
}
|
|
38
|
+
export interface HybridKemDecapsulateResult {
|
|
39
|
+
sharedSecret: string;
|
|
40
|
+
algorithm: HybridKemAlgorithm;
|
|
41
|
+
}
|
|
42
|
+
export declare function mlKemKeygen(level: MlKemLevel): MlKemKeyPairResult;
|
|
43
|
+
export declare function mlKemEncapsulate(level: MlKemLevel, publicKeyHex: string): MlKemEncapsulateResult;
|
|
44
|
+
export declare function mlKemDecapsulate(level: MlKemLevel, secretKeyHex: string, ciphertextHex: string): MlKemDecapsulateResult;
|
|
45
|
+
export declare function hybridKemKeygen(kemLevel?: MlKemLevel): HybridKemKeyPair;
|
|
46
|
+
export declare function hybridKemEncapsulate(kemLevel: MlKemLevel, theirX25519Public: string, theirMlKemPublic: string): HybridKemEncapsulateResult;
|
|
47
|
+
export declare function hybridKemDecapsulate(kemLevel: MlKemLevel, ourX25519Private: string, ourMlKemSecret: string, theirX25519Ephemeral: string, mlKemCiphertext: string): HybridKemDecapsulateResult;
|
|
48
|
+
export interface P256MlKemKeyPair {
|
|
49
|
+
p256PrivateKey: string;
|
|
50
|
+
p256PublicKey: string;
|
|
51
|
+
mlKemPublicKey: string;
|
|
52
|
+
mlKemSecretKey: string;
|
|
53
|
+
algorithm: "p256-ml-kem-768";
|
|
54
|
+
}
|
|
55
|
+
export interface P256MlKemEncapsulateResult {
|
|
56
|
+
p256EphemeralPublic: string;
|
|
57
|
+
mlKemCiphertext: string;
|
|
58
|
+
sharedSecret: string;
|
|
59
|
+
algorithm: "p256-ml-kem-768";
|
|
60
|
+
}
|
|
61
|
+
export interface P256MlKemDecapsulateResult {
|
|
62
|
+
sharedSecret: string;
|
|
63
|
+
algorithm: "p256-ml-kem-768";
|
|
64
|
+
}
|
|
65
|
+
export declare function p256MlKemKeygen(): P256MlKemKeyPair;
|
|
66
|
+
export declare function p256MlKemEncapsulate(theirP256Public: string, theirMlKemPublic: string): P256MlKemEncapsulateResult;
|
|
67
|
+
export declare function p256MlKemDecapsulate(ourP256Private: string, ourMlKemSecret: string, theirP256Ephemeral: string, mlKemCiphertext: string): P256MlKemDecapsulateResult;
|
|
68
|
+
export interface X448MlKemKeyPair {
|
|
69
|
+
x448PrivateKey: string;
|
|
70
|
+
x448PublicKey: string;
|
|
71
|
+
mlKemPublicKey: string;
|
|
72
|
+
mlKemSecretKey: string;
|
|
73
|
+
algorithm: "x448-ml-kem-1024";
|
|
74
|
+
}
|
|
75
|
+
export interface X448MlKemEncapsulateResult {
|
|
76
|
+
x448EphemeralPublic: string;
|
|
77
|
+
mlKemCiphertext: string;
|
|
78
|
+
sharedSecret: string;
|
|
79
|
+
algorithm: "x448-ml-kem-1024";
|
|
80
|
+
}
|
|
81
|
+
export interface X448MlKemDecapsulateResult {
|
|
82
|
+
sharedSecret: string;
|
|
83
|
+
algorithm: "x448-ml-kem-1024";
|
|
84
|
+
}
|
|
85
|
+
export declare function x448MlKemKeygen(): X448MlKemKeyPair;
|
|
86
|
+
export declare function x448MlKemEncapsulate(theirX448Public: string, theirMlKemPublic: string): X448MlKemEncapsulateResult;
|
|
87
|
+
export declare function x448MlKemDecapsulate(ourX448Private: string, ourMlKemSecret: string, theirX448Ephemeral: string, mlKemCiphertext: string): X448MlKemDecapsulateResult;
|
|
88
|
+
//# sourceMappingURL=pq-kem.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"pq-kem.d.ts","sourceRoot":"","sources":["../../src/modern/pq-kem.ts"],"names":[],"mappings":"AAmDA,MAAM,MAAM,UAAU,GAAG,GAAG,GAAG,GAAG,GAAG,IAAI,CAAC;AAG1C,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,YAAY,GAAG,aAAa,CAAC;AAMzE,eAAO,MAAM,wBAAwB,EAAG,gBAAyB,CAAC;AAMlE,eAAO,MAAM,2BAA2B,EAAG,mBAA4B,CAAC;AAGxE,eAAO,MAAM,mBAAmB;;;CAGtB,CAAC;AAGX,MAAM,MAAM,kBAAkB,GAC1B,mBAAmB,GACnB,mBAAmB,GACnB,oBAAoB,GACpB,iBAAiB,GACjB,kBAAkB,CAAC;AASvB,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,kBAAkB,GAAG,MAAM,GAChC,MAAM,CAWR;AAGD,MAAM,WAAW,kBAAkB;IAEjC,SAAS,EAAE,MAAM,CAAC;IAElB,SAAS,EAAE,MAAM,CAAC;IAElB,SAAS,EAAE,cAAc,CAAC;CAC3B;AAGD,MAAM,WAAW,sBAAsB;IAErC,UAAU,EAAE,MAAM,CAAC;IAEnB,YAAY,EAAE,MAAM,CAAC;IAErB,SAAS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