@sebastienrousseau/crypto-lib 0.0.3 → 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 +304 -314
- 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 +9 -7
- package/dist/bin/cryptolib.d.ts.map +1 -1
- package/dist/bin/cryptolib.js +25 -16
- package/dist/config/config.d.ts.map +1 -1
- 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 +29 -29
- package/dist/enums.d.ts.map +1 -1
- package/dist/enums.js +54 -54
- 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 +14 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +59 -0
- package/dist/key/key.d.ts +6 -13
- package/dist/key/key.d.ts.map +1 -1
- package/dist/key/key.js +20 -14
- 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 +4 -1
- package/dist/lib/decrypt.d.ts.map +1 -1
- package/dist/lib/decrypt.js +43 -51
- package/dist/lib/encrypt.d.ts +1 -1
- package/dist/lib/encrypt.d.ts.map +1 -1
- package/dist/lib/encrypt.js +29 -45
- package/dist/lib/generate.d.ts.map +1 -1
- package/dist/lib/generate.js +56 -63
- package/dist/lib/index.d.ts.map +1 -1
- package/dist/lib/index.js +17 -7
- 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 +6 -1
- package/dist/lib/reformat.d.ts.map +1 -1
- package/dist/lib/reformat.js +37 -61
- package/dist/lib/revoke.d.ts +2 -2
- package/dist/lib/revoke.d.ts.map +1 -1
- package/dist/lib/revoke.js +33 -50
- package/dist/lib/session.d.ts.map +1 -1
- package/dist/lib/session.js +21 -36
- package/dist/lib/sign.d.ts.map +1 -1
- package/dist/lib/sign.js +36 -43
- package/dist/lib/verify.d.ts +1 -3
- package/dist/lib/verify.d.ts.map +1 -1
- package/dist/lib/verify.js +25 -30
- 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 +24 -16
- package/dist/types/types.d.ts.map +1 -1
- 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 -142
- package/dist/COPYRIGHT +0 -15
- package/dist/Report.txt +0 -160
- package/dist/bin/cryptolib.js.map +0 -1
- package/dist/config/config.js.map +0 -1
- package/dist/data/decrypted.txt +0 -1
- package/dist/data/detached.sig +0 -1
- package/dist/data/encrypted.txt +0 -1
- package/dist/data/signed.sig +0 -1
- package/dist/enums.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/key/key.js.map +0 -1
- package/dist/key/rsa-reformat.cert +0 -1
- package/dist/key/rsa-reformat.key +0 -1
- package/dist/key/rsa-reformat.pub +0 -1
- package/dist/key/rsa-revoke.key +0 -1
- package/dist/key/rsa-revoke.pub +0 -1
- package/dist/key/rsa.cert +0 -1
- package/dist/key/rsa.key +0 -1
- package/dist/key/rsa.pub +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/index.js.map +0 -1
- package/dist/lib/reformat.js.map +0 -1
- package/dist/lib/revoke.js.map +0 -1
- package/dist/lib/session.js.map +0 -1
- package/dist/lib/sign.js.map +0 -1
- package/dist/lib/verify.js.map +0 -1
- package/dist/package.json +0 -143
- package/dist/types/types.js.map +0 -1
|
@@ -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
|
|
@@ -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,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAG7D,MAAM,WAAW,kBAAkB;IAEjC,SAAS,EAAE,aAAa,CAAC;IAEzB,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;IAEzB,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;CAC3B;AAGD,MAAM,WAAW,iBAAiB;IAEhC,GAAG,EAAE,MAAM,CAAC;IAEZ,SAAS,EAAE,aAAa,CAAC;CAC1B;AAGD,MAAM,WAAW,iBAAiB;IAEhC,SAAS,EAAE,aAAa,CAAC;IAEzB,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;IAEzB,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;IAE1B,GAAG,EAAE,MAAM,CAAC;CACb;AAGD,MAAM,WAAW,gBAAgB;IAE/B,KAAK,EAAE,OAAO,CAAC;IAEf,SAAS,EAAE,aAAa,CAAC;CAC1B;AAmDD,wBAAgB,WAAW,CAAC,OAAO,EAAE,kBAAkB,GAAG,iBAAiB,CAW1E;AAKD,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,gBAAgB,CAavE;AAKD,eAAO,MAAM,eAAe,mCAAoC,CAAC;AAGjE,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,eAAe,CAAC,CAAC,MAAM,CAAC,CAAC;AAG7D,MAAM,WAAW,kBAAkB;IAEjC,SAAS,EAAE,aAAa,CAAC;IAEzB,GAAG,EAAE,MAAM,GAAG,UAAU,CAAC;IAEzB,IAAI,EAAE,MAAM,GAAG,UAAU,CAAC;IAE1B,aAAa,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAEpC,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAGD,MAAM,WAAW,iBAAiB;IAEhC,GAAG,EAAE,MAAM,CAAC;IAEZ,SAAS,EAAE,aAAa,CAAC;CAC1B;AAGD,MAAM,WAAW,iBAAiB;IAEhC,SAAS,EAAE,aAAa,CAAC;IAEzB,GAAG,EAAE,MAAM,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
|