leviathan-crypto 2.1.0 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +86 -443
- package/README.md +198 -65
- package/dist/aes/aes-cbc.d.ts +40 -0
- package/dist/aes/aes-cbc.js +158 -0
- package/dist/aes/aes-ctr.d.ts +50 -0
- package/dist/aes/aes-ctr.js +141 -0
- package/dist/aes/aes-gcm-siv.d.ts +67 -0
- package/dist/aes/aes-gcm-siv.js +217 -0
- package/dist/aes/aes-gcm.d.ts +61 -0
- package/dist/aes/aes-gcm.js +226 -0
- package/dist/aes/cipher-suite.d.ts +21 -0
- package/dist/aes/cipher-suite.js +179 -0
- package/dist/aes/embedded.d.ts +1 -0
- package/dist/aes/embedded.js +26 -0
- package/dist/aes/generator.d.ts +14 -0
- package/dist/aes/generator.js +103 -0
- package/dist/aes/index.d.ts +58 -0
- package/dist/aes/index.js +125 -0
- package/dist/aes/ops.d.ts +60 -0
- package/dist/aes/ops.js +164 -0
- package/dist/aes/pool-worker.d.ts +1 -0
- package/dist/aes/pool-worker.js +92 -0
- package/dist/aes/types.d.ts +1 -0
- package/dist/aes/types.js +23 -0
- package/dist/aes.wasm +0 -0
- package/dist/blake3/embedded.d.ts +1 -0
- package/dist/blake3/embedded.js +26 -0
- package/dist/blake3/index.d.ts +143 -0
- package/dist/blake3/index.js +620 -0
- package/dist/blake3/types.d.ts +102 -0
- package/dist/blake3/types.js +31 -0
- package/dist/blake3/validate.d.ts +29 -0
- package/dist/blake3/validate.js +80 -0
- package/dist/blake3.wasm +0 -0
- package/dist/chacha20/cipher-suite.js +47 -25
- package/dist/chacha20/generator.d.ts +2 -2
- package/dist/chacha20/generator.js +4 -4
- package/dist/chacha20/index.d.ts +16 -15
- package/dist/chacha20/index.js +52 -46
- package/dist/chacha20/ops.d.ts +7 -7
- package/dist/chacha20/ops.js +34 -34
- package/dist/chacha20/pool-worker.js +5 -3
- package/dist/cte-wasm.d.ts +1 -0
- package/dist/cte-wasm.js +3 -0
- package/dist/curve25519.wasm +0 -0
- package/dist/ecdsa/der.d.ts +23 -0
- package/dist/ecdsa/der.js +192 -0
- package/dist/ecdsa/ecprivatekey-der.d.ts +32 -0
- package/dist/ecdsa/ecprivatekey-der.js +230 -0
- package/dist/ecdsa/embedded.d.ts +1 -0
- package/dist/ecdsa/embedded.js +25 -0
- package/dist/ecdsa/index.d.ts +124 -0
- package/dist/ecdsa/index.js +366 -0
- package/dist/ecdsa/types.d.ts +31 -0
- package/dist/ecdsa/types.js +28 -0
- package/dist/ecdsa/validate.d.ts +18 -0
- package/dist/ecdsa/validate.js +92 -0
- package/dist/ed25519/embedded.d.ts +1 -0
- package/dist/ed25519/embedded.js +31 -0
- package/dist/ed25519/index.d.ts +70 -0
- package/dist/ed25519/index.js +308 -0
- package/dist/ed25519/types.d.ts +27 -0
- package/dist/ed25519/types.js +27 -0
- package/dist/ed25519/validate.d.ts +7 -0
- package/dist/ed25519/validate.js +77 -0
- package/dist/embedded/aes-pool-worker.d.ts +1 -0
- package/dist/embedded/aes-pool-worker.js +5 -0
- package/dist/embedded/aes.d.ts +1 -0
- package/dist/embedded/aes.js +3 -0
- package/dist/embedded/blake3.d.ts +1 -0
- package/dist/embedded/blake3.js +3 -0
- package/dist/embedded/chacha20-pool-worker.d.ts +1 -1
- package/dist/embedded/chacha20-pool-worker.js +2 -2
- package/dist/embedded/chacha20.d.ts +1 -1
- package/dist/embedded/chacha20.js +2 -2
- package/dist/embedded/curve25519.d.ts +1 -0
- package/dist/embedded/curve25519.js +3 -0
- package/dist/embedded/mldsa.d.ts +1 -0
- package/dist/embedded/mldsa.js +3 -0
- package/dist/embedded/mlkem.d.ts +1 -0
- package/dist/embedded/mlkem.js +3 -0
- package/dist/embedded/p256.d.ts +1 -0
- package/dist/embedded/p256.js +3 -0
- package/dist/embedded/serpent-pool-worker.d.ts +1 -1
- package/dist/embedded/serpent-pool-worker.js +2 -2
- package/dist/embedded/serpent.d.ts +1 -1
- package/dist/embedded/serpent.js +2 -2
- package/dist/embedded/sha2.d.ts +1 -1
- package/dist/embedded/sha2.js +2 -2
- package/dist/embedded/sha3.d.ts +1 -1
- package/dist/embedded/sha3.js +2 -2
- package/dist/embedded/slhdsa.d.ts +1 -0
- package/dist/embedded/slhdsa.js +3 -0
- package/dist/errors.d.ts +92 -1
- package/dist/errors.js +111 -1
- package/dist/fortuna.d.ts +5 -5
- package/dist/fortuna.js +37 -64
- package/dist/index.d.ts +38 -9
- package/dist/index.js +63 -19
- package/dist/init.d.ts +1 -1
- package/dist/init.js +11 -25
- package/dist/keccak/embedded.js +1 -1
- package/dist/keccak/index.d.ts +2 -0
- package/dist/keccak/index.js +4 -2
- package/dist/loader.d.ts +1 -24
- package/dist/loader.js +13 -16
- package/dist/merkle/blake3-tree.d.ts +35 -0
- package/dist/merkle/blake3-tree.js +187 -0
- package/dist/merkle/checkpoint.d.ts +58 -0
- package/dist/merkle/checkpoint.js +217 -0
- package/dist/merkle/index.d.ts +19 -0
- package/dist/merkle/index.js +37 -0
- package/dist/merkle/merkle-log.d.ts +130 -0
- package/dist/merkle/merkle-log.js +207 -0
- package/dist/merkle/merkle-verifier.d.ts +126 -0
- package/dist/merkle/merkle-verifier.js +296 -0
- package/dist/merkle/proof.d.ts +70 -0
- package/dist/merkle/proof.js +300 -0
- package/dist/merkle/sha256-tree.d.ts +33 -0
- package/dist/merkle/sha256-tree.js +145 -0
- package/dist/merkle/signed-log.d.ts +156 -0
- package/dist/merkle/signed-log.js +356 -0
- package/dist/merkle/signed-note.d.ts +309 -0
- package/dist/merkle/signed-note.js +648 -0
- package/dist/merkle/sth.d.ts +31 -0
- package/dist/merkle/sth.js +31 -0
- package/dist/merkle/storage.d.ts +40 -0
- package/dist/merkle/storage.js +71 -0
- package/dist/merkle/tree.d.ts +68 -0
- package/dist/merkle/tree.js +94 -0
- package/dist/mldsa/embedded.d.ts +1 -0
- package/dist/{kyber → mldsa}/embedded.js +5 -5
- package/dist/mldsa/expand.d.ts +53 -0
- package/dist/mldsa/expand.js +188 -0
- package/dist/mldsa/format.d.ts +16 -0
- package/dist/mldsa/format.js +68 -0
- package/dist/mldsa/hashvariant.d.ts +32 -0
- package/dist/mldsa/hashvariant.js +248 -0
- package/dist/mldsa/index.d.ts +142 -0
- package/dist/mldsa/index.js +463 -0
- package/dist/mldsa/keygen.d.ts +16 -0
- package/dist/mldsa/keygen.js +232 -0
- package/dist/mldsa/params.d.ts +21 -0
- package/dist/mldsa/params.js +55 -0
- package/dist/mldsa/sha3-helpers.d.ts +30 -0
- package/dist/mldsa/sha3-helpers.js +124 -0
- package/dist/mldsa/sign.d.ts +36 -0
- package/dist/mldsa/sign.js +380 -0
- package/dist/mldsa/types.d.ts +91 -0
- package/dist/mldsa/types.js +25 -0
- package/dist/mldsa/validate.d.ts +55 -0
- package/dist/mldsa/validate.js +125 -0
- package/dist/mldsa/verify.d.ts +29 -0
- package/dist/mldsa/verify.js +269 -0
- package/dist/mldsa.wasm +0 -0
- package/dist/mlkem/embedded.d.ts +1 -0
- package/dist/mlkem/embedded.js +27 -0
- package/dist/mlkem/indcpa.d.ts +49 -0
- package/dist/{kyber → mlkem}/indcpa.js +44 -44
- package/dist/mlkem/index.d.ts +37 -0
- package/dist/{kyber → mlkem}/index.js +24 -34
- package/dist/mlkem/kem.d.ts +21 -0
- package/dist/{kyber → mlkem}/kem.js +44 -64
- package/dist/{kyber → mlkem}/params.d.ts +4 -4
- package/dist/{kyber → mlkem}/params.js +2 -2
- package/dist/mlkem/suite.d.ts +12 -0
- package/dist/{kyber → mlkem}/suite.js +17 -12
- package/dist/{kyber → mlkem}/types.d.ts +3 -3
- package/dist/{kyber → mlkem}/types.js +1 -1
- package/dist/{kyber → mlkem}/validate.d.ts +7 -7
- package/dist/{kyber → mlkem}/validate.js +7 -7
- package/dist/{kyber.wasm → mlkem.wasm} +0 -0
- package/dist/p256.wasm +0 -0
- package/dist/ratchet/index.d.ts +2 -0
- package/dist/ratchet/index.js +1 -0
- package/dist/ratchet/kdf-chain.js +3 -3
- package/dist/ratchet/ratchet-keypair.js +2 -2
- package/dist/ratchet/root-kdf.js +7 -7
- package/dist/ratchet/skipped-key-store.js +4 -4
- package/dist/ratchet/types.d.ts +1 -1
- package/dist/serpent/cipher-suite.js +20 -17
- package/dist/serpent/generator.d.ts +1 -1
- package/dist/serpent/generator.js +2 -2
- package/dist/serpent/index.d.ts +8 -7
- package/dist/serpent/index.js +18 -27
- package/dist/serpent/pool-worker.js +7 -5
- package/dist/serpent/serpent-cbc.d.ts +4 -4
- package/dist/serpent/serpent-cbc.js +11 -8
- package/dist/serpent/shared-ops.d.ts +3 -23
- package/dist/serpent/shared-ops.js +50 -85
- package/dist/serpent.wasm +0 -0
- package/dist/sha2/hkdf.js +5 -5
- package/dist/sha2/index.d.ts +21 -1
- package/dist/sha2/index.js +65 -10
- package/dist/sha2/types.d.ts +41 -2
- package/dist/sha2.wasm +0 -0
- package/dist/sha3/index.d.ts +72 -3
- package/dist/sha3/index.js +240 -14
- package/dist/sha3/kmac.d.ts +121 -0
- package/dist/sha3/kmac.js +800 -0
- package/dist/sha3.wasm +0 -0
- package/dist/shared/pkcs7.d.ts +22 -0
- package/dist/shared/pkcs7.js +84 -0
- package/dist/sign/ctx.d.ts +41 -0
- package/dist/sign/ctx.js +102 -0
- package/dist/sign/envelope.d.ts +45 -0
- package/dist/sign/envelope.js +152 -0
- package/dist/sign/hasher.d.ts +9 -0
- package/dist/sign/hasher.js +132 -0
- package/dist/sign/index.d.ts +11 -0
- package/dist/sign/index.js +34 -0
- package/dist/sign/sign-stream.d.ts +25 -0
- package/dist/sign/sign-stream.js +112 -0
- package/dist/sign/suites/ecdsa-p256.d.ts +2 -0
- package/dist/sign/suites/ecdsa-p256.js +120 -0
- package/dist/sign/suites/ed25519.d.ts +3 -0
- package/dist/sign/suites/ed25519.js +165 -0
- package/dist/sign/suites/hybrid-classical.d.ts +23 -0
- package/dist/sign/suites/hybrid-classical.js +526 -0
- package/dist/sign/suites/hybrid-pq.d.ts +4 -0
- package/dist/sign/suites/hybrid-pq.js +234 -0
- package/dist/sign/suites/mldsa.d.ts +7 -0
- package/dist/sign/suites/mldsa.js +161 -0
- package/dist/sign/suites/slhdsa.d.ts +7 -0
- package/dist/sign/suites/slhdsa.js +176 -0
- package/dist/sign/types.d.ts +106 -0
- package/dist/sign/types.js +28 -0
- package/dist/sign/verify-stream.d.ts +30 -0
- package/dist/sign/verify-stream.js +227 -0
- package/dist/slhdsa/embedded.d.ts +1 -0
- package/dist/slhdsa/embedded.js +26 -0
- package/dist/slhdsa/index.d.ts +149 -0
- package/dist/slhdsa/index.js +493 -0
- package/dist/slhdsa/params.d.ts +26 -0
- package/dist/slhdsa/params.js +70 -0
- package/dist/slhdsa/prehash.d.ts +68 -0
- package/dist/slhdsa/prehash.js +307 -0
- package/dist/slhdsa/sign.d.ts +39 -0
- package/dist/slhdsa/sign.js +116 -0
- package/dist/slhdsa/types.d.ts +129 -0
- package/dist/slhdsa/types.js +27 -0
- package/dist/slhdsa/validate.d.ts +60 -0
- package/dist/slhdsa/validate.js +127 -0
- package/dist/slhdsa/verify.d.ts +32 -0
- package/dist/slhdsa/verify.js +107 -0
- package/dist/slhdsa.wasm +0 -0
- package/dist/stream/header.js +3 -3
- package/dist/stream/index.d.ts +1 -0
- package/dist/stream/index.js +1 -0
- package/dist/stream/open-stream.js +31 -10
- package/dist/stream/seal-stream-pool.d.ts +1 -0
- package/dist/stream/seal-stream-pool.js +63 -26
- package/dist/stream/seal-stream.d.ts +1 -1
- package/dist/stream/seal-stream.js +20 -9
- package/dist/stream/seal.js +6 -6
- package/dist/stream/types.d.ts +3 -1
- package/dist/stream/types.js +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js +1 -1
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js +46 -54
- package/dist/wasm-source.d.ts +7 -7
- package/dist/wasm-source.js +1 -1
- package/dist/x25519/embedded.d.ts +1 -0
- package/dist/x25519/embedded.js +31 -0
- package/dist/x25519/index.d.ts +43 -0
- package/dist/x25519/index.js +159 -0
- package/dist/x25519/types.d.ts +25 -0
- package/dist/x25519/types.js +27 -0
- package/dist/x25519/validate.d.ts +2 -0
- package/dist/x25519/validate.js +39 -0
- package/package.json +70 -26
- package/SECURITY.md +0 -163
- package/dist/ct-wasm.d.ts +0 -1
- package/dist/ct-wasm.js +0 -3
- package/dist/docs/aead.md +0 -363
- package/dist/docs/architecture.md +0 -1011
- package/dist/docs/argon2id.md +0 -305
- package/dist/docs/chacha20.md +0 -781
- package/dist/docs/exports.md +0 -277
- package/dist/docs/fortuna.md +0 -530
- package/dist/docs/init.md +0 -301
- package/dist/docs/loader.md +0 -256
- package/dist/docs/serpent.md +0 -617
- package/dist/docs/sha2.md +0 -671
- package/dist/docs/sha3.md +0 -612
- package/dist/docs/types.md +0 -416
- package/dist/docs/utils.md +0 -457
- package/dist/embedded/kyber.d.ts +0 -1
- package/dist/embedded/kyber.js +0 -3
- package/dist/kyber/embedded.d.ts +0 -1
- package/dist/kyber/indcpa.d.ts +0 -49
- package/dist/kyber/index.d.ts +0 -38
- package/dist/kyber/kem.d.ts +0 -21
- package/dist/kyber/suite.d.ts +0 -12
- /package/dist/{ct.wasm → cte.wasm} +0 -0
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prehash algorithm identifier used by StreamableSignatureSuite. The
|
|
3
|
+
* lowercase, hyphenated form is the lib's public sign-surface; the
|
|
4
|
+
* mldsa-internal `PreHashAlgorithm` (uppercase, no hyphen on SHAKE)
|
|
5
|
+
* remains private. `prehashAlgoToMldsa` in ctx.ts is the only bridge.
|
|
6
|
+
*/
|
|
7
|
+
export type PrehashAlgorithm = 'sha-256' | 'sha-512' | 'sha3-256' | 'sha3-512' | 'shake-128' | 'shake-256';
|
|
8
|
+
/**
|
|
9
|
+
* Base SignatureSuite interface. All suite consts conform to this.
|
|
10
|
+
* Pure-mode suites conform to SignatureSuite only; suites that support
|
|
11
|
+
* streaming additionally conform to StreamableSignatureSuite.
|
|
12
|
+
*/
|
|
13
|
+
export interface SignatureSuite {
|
|
14
|
+
/**
|
|
15
|
+
* Wire format byte. Bits 0-3 = suite within category;
|
|
16
|
+
* bits 4-5 = category (0x0X pure, 0x1X prehash, 0x2X classical+PQ
|
|
17
|
+
* hybrid, 0x3X PQ-only hybrid); bits 6-7 reserved.
|
|
18
|
+
*/
|
|
19
|
+
readonly formatEnum: number;
|
|
20
|
+
/** Human label, e.g. 'mldsa65', 'mldsa65-prehash'. */
|
|
21
|
+
readonly formatName: string;
|
|
22
|
+
/**
|
|
23
|
+
* Built-in domain separator. Concatenated, length-prefixed, with
|
|
24
|
+
* user-supplied ctx before being fed to the underlying primitive's
|
|
25
|
+
* ctx parameter. Convention: `{scheme}-envelope-v3` for pure suites,
|
|
26
|
+
* `{scheme}-prehash-envelope-v3` for prehash variants. Max 32 bytes,
|
|
27
|
+
* validated at factory construction.
|
|
28
|
+
*/
|
|
29
|
+
readonly ctxDomain: string;
|
|
30
|
+
/** Public key size in bytes. */
|
|
31
|
+
readonly pkSize: number;
|
|
32
|
+
/** Secret key size in bytes. */
|
|
33
|
+
readonly skSize: number;
|
|
34
|
+
/**
|
|
35
|
+
* Upper-bound signature size in bytes. For fixed-length signature
|
|
36
|
+
* schemes equals the actual size. For variable-length schemes
|
|
37
|
+
* (e.g., composite ECDSA whose `Ecdsa-Sig-Value` DER encoding per
|
|
38
|
+
* RFC 3279 §2.2.3 varies with leading-zero stripping) is the
|
|
39
|
+
* catalog-reserved upper bound, the actual sig may be shorter.
|
|
40
|
+
* Hybrid suites precompute `sig_classical + sig_pq` for clear
|
|
41
|
+
* visibility.
|
|
42
|
+
*/
|
|
43
|
+
readonly sigMaxSize: number;
|
|
44
|
+
/** WASM modules this suite requires initialized via init(). */
|
|
45
|
+
readonly wasmModules: readonly string[];
|
|
46
|
+
/**
|
|
47
|
+
* Sign a message. Returns the raw signature bytes, not wrapped in
|
|
48
|
+
* the envelope wire format; that is Sign.sign's job.
|
|
49
|
+
*
|
|
50
|
+
* @param sk Secret key, must be exactly skSize bytes.
|
|
51
|
+
* @param msg Message to sign. Any length.
|
|
52
|
+
* @param ctx User context, up to USER_CTX_MAX (255) bytes per
|
|
53
|
+
* FIPS 204 §3.6.1. Suites that route ctx through
|
|
54
|
+
* buildEffectiveCtx have a tighter per-call ceiling
|
|
55
|
+
* equal to `253 - len(ctxDomain)`. Empty Uint8Array
|
|
56
|
+
* is legal but must be passed explicitly.
|
|
57
|
+
* @throws SigningError on contract violations (wrong-size key,
|
|
58
|
+
* ctx too long).
|
|
59
|
+
* @returns Signature bytes, length at most sigMaxSize.
|
|
60
|
+
*/
|
|
61
|
+
sign(sk: Uint8Array, msg: Uint8Array, ctx: Uint8Array): Uint8Array;
|
|
62
|
+
/**
|
|
63
|
+
* Verify a signature. Returns boolean for all signature outcomes
|
|
64
|
+
* including malformed signature encoding. Throws SigningError on
|
|
65
|
+
* contract violations (wrong-size key, ctx too long).
|
|
66
|
+
*/
|
|
67
|
+
verify(pk: Uint8Array, msg: Uint8Array, sig: Uint8Array, ctx: Uint8Array): boolean;
|
|
68
|
+
/**
|
|
69
|
+
* Generate a fresh keypair. Returns named-field object regardless
|
|
70
|
+
* of how the underlying primitive names its keys.
|
|
71
|
+
*/
|
|
72
|
+
keygen(): {
|
|
73
|
+
pk: Uint8Array;
|
|
74
|
+
sk: Uint8Array;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* SignatureSuite extension for streamable signing. Suites that support
|
|
79
|
+
* SignStream / VerifyStream must conform to this interface; pure-mode
|
|
80
|
+
* suites do not.
|
|
81
|
+
*/
|
|
82
|
+
export interface StreamableSignatureSuite extends SignatureSuite {
|
|
83
|
+
/** Prehash algorithm. Locked at suite construction. */
|
|
84
|
+
readonly prehashAlgorithm: PrehashAlgorithm;
|
|
85
|
+
/** Digest size in bytes for the locked prehash algorithm. */
|
|
86
|
+
readonly prehashSize: number;
|
|
87
|
+
/**
|
|
88
|
+
* Sign a precomputed digest. Caller is responsible for computing
|
|
89
|
+
* the digest with the prehash algorithm matching this suite, or
|
|
90
|
+
* using SignStream which does it internally.
|
|
91
|
+
*
|
|
92
|
+
* @param digest Digest bytes, must be exactly prehashSize.
|
|
93
|
+
* @throws SigningError('sig-malformed-input') on digest length
|
|
94
|
+
* mismatch; SigningError on other contract violations.
|
|
95
|
+
*/
|
|
96
|
+
signPrehashed(sk: Uint8Array, digest: Uint8Array, ctx: Uint8Array): Uint8Array;
|
|
97
|
+
/**
|
|
98
|
+
* Verify a precomputed-digest signature. Returns false on signature
|
|
99
|
+
* failure (including malformed signature encoding). Throws SigningError
|
|
100
|
+
* on contract violations: wrong-size key, ctx too long, or wrong-size
|
|
101
|
+
* digest (`sig-malformed-input`). The digest length is a caller-side
|
|
102
|
+
* contract; symmetric with `signPrehashed` which throws on the same
|
|
103
|
+
* condition.
|
|
104
|
+
*/
|
|
105
|
+
verifyPrehashed(pk: Uint8Array, digest: Uint8Array, sig: Uint8Array, ctx: Uint8Array): boolean;
|
|
106
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
// ▄▄▄▄▄▄▄▄▄▄
|
|
2
|
+
// ▄████████████████████▄▄ ▒ ▄▀▀ ▒ ▒ █ ▄▀▄ ▀█▀ █ ▒ ▄▀▄ █▀▄
|
|
3
|
+
// ▄██████████████████████ ▀████▄ ▓ ▓▀ ▓ ▓ ▓ ▓▄▓ ▓ ▓▀▓ ▓▄▓ ▓ ▓
|
|
4
|
+
// ▄█████████▀▀▀ ▀███████▄▄███████▌ ▀▄ ▀▄▄ ▀▄▀ ▒ ▒ ▒ ▒ ▒ █ ▒ ▒ ▒ █
|
|
5
|
+
// ▐████████▀ ▄▄▄▄ ▀████████▀██▀█▌
|
|
6
|
+
// ████████ ███▀▀ ████▀ █▀ █▀ Leviathan Crypto Library
|
|
7
|
+
// ███████▌ ▀██▀ ███
|
|
8
|
+
// ███████ ▀███ ▀██ ▀█▄ Repository & Mirror:
|
|
9
|
+
// ▀██████ ▄▄██ ▀▀ ██▄ github.com/xero/leviathan-crypto
|
|
10
|
+
// ▀█████▄ ▄██▄ ▄▀▄▀ unpkg.com/leviathan-crypto
|
|
11
|
+
// ▀████▄ ▄██▄
|
|
12
|
+
// ▐████ ▐███ Author: xero (https://x-e.ro)
|
|
13
|
+
// ▄▄██████████ ▐███ ▄▄ License: MIT
|
|
14
|
+
// ▄██▀▀▀▀▀▀▀▀▀▀ ▄████ ▄██▀
|
|
15
|
+
// ▄▀ ▄▄█████████▄▄ ▀▀▀▀▀ ▄███ This file is provided completely
|
|
16
|
+
// ▄██████▀▀▀▀▀▀██████▄ ▀▄▄▄▄████▀ free, "as is", and without
|
|
17
|
+
// ████▀ ▄▄▄▄▄▄▄ ▀████▄ ▀█████▀ ▄▄▄▄ warranty of any kind. The author
|
|
18
|
+
// █████▄▄█████▀▀▀▀▀▀▄ ▀███▄ ▄████ assumes absolutely no liability
|
|
19
|
+
// ▀██████▀ ▀████▄▄▄████▀ for its {ab,mis,}use.
|
|
20
|
+
// ▀█████▀▀
|
|
21
|
+
//
|
|
22
|
+
// src/ts/sign/types.ts
|
|
23
|
+
//
|
|
24
|
+
// SignatureSuite interface definitions for the v3 signature layer.
|
|
25
|
+
// Mirrors src/ts/stream/types.ts (CipherSuite) shape; signatures plug
|
|
26
|
+
// into Sign / SignStream / VerifyStream the way ciphers plug into
|
|
27
|
+
// Seal / SealStream / OpenStream.
|
|
28
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type { StreamableSignatureSuite } from './types.js';
|
|
2
|
+
export declare class VerifyStream {
|
|
3
|
+
private readonly suite;
|
|
4
|
+
private readonly pk;
|
|
5
|
+
private readonly expectedCtx;
|
|
6
|
+
private state;
|
|
7
|
+
private headerBuf;
|
|
8
|
+
private payloadChunks;
|
|
9
|
+
private payloadHasher;
|
|
10
|
+
private payloadRemaining;
|
|
11
|
+
private sigBuf;
|
|
12
|
+
constructor(suite: StreamableSignatureSuite, pk: Uint8Array, ctx: Uint8Array);
|
|
13
|
+
/**
|
|
14
|
+
* Feed bytes from the wire. Header parsing is byte-by-byte tolerant;
|
|
15
|
+
* payload bytes accumulate up to the wire-declared payload_len; the
|
|
16
|
+
* trailing sig bytes accumulate until finalize.
|
|
17
|
+
*/
|
|
18
|
+
update(chunk: Uint8Array): void;
|
|
19
|
+
/**
|
|
20
|
+
* Verify the buffered signature. Returns the payload on success.
|
|
21
|
+
* Throws and wipes the buffered payload on verification failure.
|
|
22
|
+
*/
|
|
23
|
+
finalize(): Uint8Array;
|
|
24
|
+
/** Wipe all internal state. Idempotent. */
|
|
25
|
+
dispose(): void;
|
|
26
|
+
private consumeHeaderBytes;
|
|
27
|
+
private consumePayloadBytes;
|
|
28
|
+
private consumeSigBytes;
|
|
29
|
+
private wipeBuffers;
|
|
30
|
+
}
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
// ▄▄▄▄▄▄▄▄▄▄
|
|
2
|
+
// ▄████████████████████▄▄ ▒ ▄▀▀ ▒ ▒ █ ▄▀▄ ▀█▀ █ ▒ ▄▀▄ █▀▄
|
|
3
|
+
// ▄██████████████████████ ▀████▄ ▓ ▓▀ ▓ ▓ ▓ ▓▄▓ ▓ ▓▀▓ ▓▄▓ ▓ ▓
|
|
4
|
+
// ▄█████████▀▀▀ ▀███████▄▄███████▌ ▀▄ ▀▄▄ ▀▄▀ ▒ ▒ ▒ ▒ ▒ █ ▒ ▒ ▒ █
|
|
5
|
+
// ▐████████▀ ▄▄▄▄ ▀████████▀██▀█▌
|
|
6
|
+
// ████████ ███▀▀ ████▀ █▀ █▀ Leviathan Crypto Library
|
|
7
|
+
// ███████▌ ▀██▀ ███
|
|
8
|
+
// ███████ ▀███ ▀██ ▀█▄ Repository & Mirror:
|
|
9
|
+
// ▀██████ ▄▄██ ▀▀ ██▄ github.com/xero/leviathan-crypto
|
|
10
|
+
// ▀█████▄ ▄██▄ ▄▀▄▀ unpkg.com/leviathan-crypto
|
|
11
|
+
// ▀████▄ ▄██▄
|
|
12
|
+
// ▐████ ▐███ Author: xero (https://x-e.ro)
|
|
13
|
+
// ▄▄██████████ ▐███ ▄▄ License: MIT
|
|
14
|
+
// ▄██▀▀▀▀▀▀▀▀▀▀ ▄████ ▄██▀
|
|
15
|
+
// ▄▀ ▄▄█████████▄▄ ▀▀▀▀▀ ▄███ This file is provided completely
|
|
16
|
+
// ▄██████▀▀▀▀▀▀██████▄ ▀▄▄▄▄████▀ free, "as is", and without
|
|
17
|
+
// ████▀ ▄▄▄▄▄▄▄ ▀████▄ ▀█████▀ ▄▄▄▄ warranty of any kind. The author
|
|
18
|
+
// █████▄▄█████▀▀▀▀▀▀▄ ▀███▄ ▄████ assumes absolutely no liability
|
|
19
|
+
// ▀██████▀ ▀████▄▄▄████▀ for its {ab,mis,}use.
|
|
20
|
+
// ▀█████▀▀
|
|
21
|
+
//
|
|
22
|
+
// src/ts/sign/verify-stream.ts
|
|
23
|
+
//
|
|
24
|
+
// VerifyStream class, buffered streaming verification for
|
|
25
|
+
// StreamableSignatureSuite. Holds payload chunks internally; on finalize
|
|
26
|
+
// verifies and returns the payload, or throws and wipes.
|
|
27
|
+
//
|
|
28
|
+
// Wire format and parser flow: docs/signing.md#attached-envelope.
|
|
29
|
+
import { constantTimeEqual, concat, wipe } from '../utils.js';
|
|
30
|
+
import { SigningError } from '../errors.js';
|
|
31
|
+
import { createRunningHash } from './hasher.js';
|
|
32
|
+
var State;
|
|
33
|
+
(function (State) {
|
|
34
|
+
State[State["ParsingHeader"] = 0] = "ParsingHeader";
|
|
35
|
+
State[State["ParsingPayload"] = 1] = "ParsingPayload";
|
|
36
|
+
State[State["ParsingSig"] = 2] = "ParsingSig";
|
|
37
|
+
State[State["Finalized"] = 3] = "Finalized";
|
|
38
|
+
State[State["Disposed"] = 4] = "Disposed";
|
|
39
|
+
})(State || (State = {}));
|
|
40
|
+
export class VerifyStream {
|
|
41
|
+
suite;
|
|
42
|
+
pk;
|
|
43
|
+
expectedCtx;
|
|
44
|
+
state = State.ParsingHeader;
|
|
45
|
+
headerBuf = new Uint8Array(0);
|
|
46
|
+
payloadChunks = [];
|
|
47
|
+
payloadHasher;
|
|
48
|
+
payloadRemaining = 0;
|
|
49
|
+
sigBuf = new Uint8Array(0);
|
|
50
|
+
constructor(suite, pk, ctx) {
|
|
51
|
+
this.suite = suite;
|
|
52
|
+
this.pk = pk;
|
|
53
|
+
this.expectedCtx = ctx;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Feed bytes from the wire. Header parsing is byte-by-byte tolerant;
|
|
57
|
+
* payload bytes accumulate up to the wire-declared payload_len; the
|
|
58
|
+
* trailing sig bytes accumulate until finalize.
|
|
59
|
+
*/
|
|
60
|
+
update(chunk) {
|
|
61
|
+
if (this.state === State.Disposed)
|
|
62
|
+
throw new SigningError('sig-stream-disposed');
|
|
63
|
+
if (this.state === State.Finalized)
|
|
64
|
+
throw new SigningError('sig-stream-finalized');
|
|
65
|
+
let rest = chunk;
|
|
66
|
+
if (this.state === State.ParsingHeader) {
|
|
67
|
+
rest = this.consumeHeaderBytes(rest);
|
|
68
|
+
if (this.state === State.ParsingHeader)
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
if (rest.length === 0)
|
|
72
|
+
return;
|
|
73
|
+
if (this.state === State.ParsingPayload) {
|
|
74
|
+
rest = this.consumePayloadBytes(rest);
|
|
75
|
+
if (rest.length === 0)
|
|
76
|
+
return;
|
|
77
|
+
}
|
|
78
|
+
if (this.state === State.ParsingSig) {
|
|
79
|
+
this.consumeSigBytes(rest);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Verify the buffered signature. Returns the payload on success.
|
|
84
|
+
* Throws and wipes the buffered payload on verification failure.
|
|
85
|
+
*/
|
|
86
|
+
finalize() {
|
|
87
|
+
if (this.state === State.Disposed)
|
|
88
|
+
throw new SigningError('sig-stream-disposed');
|
|
89
|
+
if (this.state === State.Finalized)
|
|
90
|
+
throw new SigningError('sig-stream-finalized');
|
|
91
|
+
// From here on, the stream transitions to Finalized regardless of
|
|
92
|
+
// success/failure so a partial parse cannot leave the hasher (and
|
|
93
|
+
// its WASM module) held.
|
|
94
|
+
const priorState = this.state;
|
|
95
|
+
this.state = State.Finalized;
|
|
96
|
+
const h = this.payloadHasher;
|
|
97
|
+
this.payloadHasher = undefined;
|
|
98
|
+
try {
|
|
99
|
+
if (priorState !== State.ParsingSig) {
|
|
100
|
+
this.wipeBuffers();
|
|
101
|
+
throw new SigningError('sig-blob-too-short', 'finalize before payload completed');
|
|
102
|
+
}
|
|
103
|
+
if (this.sigBuf.length === 0) {
|
|
104
|
+
this.wipeBuffers();
|
|
105
|
+
throw new SigningError('sig-blob-too-short', 'finalize before any sig bytes arrived');
|
|
106
|
+
}
|
|
107
|
+
if (this.sigBuf.length > this.suite.sigMaxSize) {
|
|
108
|
+
this.wipeBuffers();
|
|
109
|
+
throw new SigningError('sig-blob-too-short', `trailing sig ${this.sigBuf.length} > suite.sigMaxSize ${this.suite.sigMaxSize}`);
|
|
110
|
+
}
|
|
111
|
+
const digest = h.finalize();
|
|
112
|
+
try {
|
|
113
|
+
const sig = this.sigBuf;
|
|
114
|
+
try {
|
|
115
|
+
if (!this.suite.verifyPrehashed(this.pk, digest, sig, this.expectedCtx)) {
|
|
116
|
+
this.wipeBuffers();
|
|
117
|
+
throw new SigningError('verify-failed');
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
catch (e) {
|
|
121
|
+
this.wipeBuffers();
|
|
122
|
+
throw e;
|
|
123
|
+
}
|
|
124
|
+
const out = concat(...this.payloadChunks);
|
|
125
|
+
this.wipeBuffers();
|
|
126
|
+
return out;
|
|
127
|
+
}
|
|
128
|
+
finally {
|
|
129
|
+
wipe(digest);
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
finally {
|
|
133
|
+
if (h !== undefined)
|
|
134
|
+
h.dispose();
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
/** Wipe all internal state. Idempotent. */
|
|
138
|
+
dispose() {
|
|
139
|
+
if (this.state === State.Disposed)
|
|
140
|
+
return;
|
|
141
|
+
this.state = State.Disposed;
|
|
142
|
+
if (this.payloadHasher !== undefined) {
|
|
143
|
+
this.payloadHasher.dispose();
|
|
144
|
+
this.payloadHasher = undefined;
|
|
145
|
+
}
|
|
146
|
+
this.wipeBuffers();
|
|
147
|
+
}
|
|
148
|
+
consumeHeaderBytes(chunk) {
|
|
149
|
+
const combined = new Uint8Array(this.headerBuf.length + chunk.length);
|
|
150
|
+
combined.set(this.headerBuf, 0);
|
|
151
|
+
combined.set(chunk, this.headerBuf.length);
|
|
152
|
+
if (combined.length < 2) {
|
|
153
|
+
this.headerBuf = combined;
|
|
154
|
+
return new Uint8Array(0);
|
|
155
|
+
}
|
|
156
|
+
const suiteByte = combined[0];
|
|
157
|
+
if (suiteByte !== this.suite.formatEnum) {
|
|
158
|
+
this.state = State.Finalized;
|
|
159
|
+
this.wipeBuffers();
|
|
160
|
+
throw new SigningError('sig-suite-mismatch', `wire suite 0x${suiteByte.toString(16)} != suite.formatEnum 0x${this.suite.formatEnum.toString(16)}`);
|
|
161
|
+
}
|
|
162
|
+
const ctxLen = combined[1];
|
|
163
|
+
const headerEnd = 2 + ctxLen + 4;
|
|
164
|
+
if (combined.length < headerEnd) {
|
|
165
|
+
this.headerBuf = combined;
|
|
166
|
+
return new Uint8Array(0);
|
|
167
|
+
}
|
|
168
|
+
const wireCtx = combined.subarray(2, 2 + ctxLen);
|
|
169
|
+
if (!constantTimeEqual(wireCtx, this.expectedCtx)) {
|
|
170
|
+
this.state = State.Finalized;
|
|
171
|
+
this.wipeBuffers();
|
|
172
|
+
throw new SigningError('sig-ctx-mismatch');
|
|
173
|
+
}
|
|
174
|
+
// payload_len lives at offset 2 + ctxLen, u32 BE per the v3
|
|
175
|
+
// envelope wire. Multiply the high byte instead of <<24 so a
|
|
176
|
+
// 0x80-or-higher high byte does not turn the result negative
|
|
177
|
+
// and silently bypass the payload-overflow check downstream.
|
|
178
|
+
const lOff = 2 + ctxLen;
|
|
179
|
+
this.payloadRemaining =
|
|
180
|
+
combined[lOff] * 0x1000000
|
|
181
|
+
+ ((combined[lOff + 1] << 16)
|
|
182
|
+
| (combined[lOff + 2] << 8)
|
|
183
|
+
| combined[lOff + 3]);
|
|
184
|
+
this.payloadHasher = createRunningHash(this.suite.prehashAlgorithm);
|
|
185
|
+
this.headerBuf = new Uint8Array(0);
|
|
186
|
+
this.state = this.payloadRemaining === 0
|
|
187
|
+
? State.ParsingSig
|
|
188
|
+
: State.ParsingPayload;
|
|
189
|
+
return combined.subarray(headerEnd);
|
|
190
|
+
}
|
|
191
|
+
consumePayloadBytes(chunk) {
|
|
192
|
+
if (this.payloadRemaining === 0) {
|
|
193
|
+
this.state = State.ParsingSig;
|
|
194
|
+
return chunk;
|
|
195
|
+
}
|
|
196
|
+
const take = Math.min(chunk.length, this.payloadRemaining);
|
|
197
|
+
const segment = chunk.subarray(0, take);
|
|
198
|
+
// Copy so a caller-side mutation cannot retroactively alter the
|
|
199
|
+
// buffered payload we return at finalize.
|
|
200
|
+
const owned = new Uint8Array(segment);
|
|
201
|
+
this.payloadChunks.push(owned);
|
|
202
|
+
this.payloadHasher.update(owned);
|
|
203
|
+
this.payloadRemaining -= take;
|
|
204
|
+
if (this.payloadRemaining === 0)
|
|
205
|
+
this.state = State.ParsingSig;
|
|
206
|
+
return chunk.subarray(take);
|
|
207
|
+
}
|
|
208
|
+
consumeSigBytes(chunk) {
|
|
209
|
+
const combined = new Uint8Array(this.sigBuf.length + chunk.length);
|
|
210
|
+
combined.set(this.sigBuf, 0);
|
|
211
|
+
combined.set(chunk, this.sigBuf.length);
|
|
212
|
+
this.sigBuf = combined;
|
|
213
|
+
}
|
|
214
|
+
wipeBuffers() {
|
|
215
|
+
for (const c of this.payloadChunks)
|
|
216
|
+
c.fill(0);
|
|
217
|
+
this.payloadChunks = [];
|
|
218
|
+
if (this.sigBuf.length > 0) {
|
|
219
|
+
this.sigBuf.fill(0);
|
|
220
|
+
this.sigBuf = new Uint8Array(0);
|
|
221
|
+
}
|
|
222
|
+
if (this.headerBuf.length > 0) {
|
|
223
|
+
this.headerBuf.fill(0);
|
|
224
|
+
this.headerBuf = new Uint8Array(0);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { WASM_GZ_BASE64 as slhdsaWasm } from '../embedded/slhdsa.js';
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// ▄▄▄▄▄▄▄▄▄▄
|
|
2
|
+
// ▄████████████████████▄▄ ▒ ▄▀▀ ▒ ▒ █ ▄▀▄ ▀█▀ █ ▒ ▄▀▄ █▀▄
|
|
3
|
+
// ▄██████████████████████ ▀████▄ ▓ ▓▀ ▓ ▓ ▓ ▓▄▓ ▓ ▓▀▓ ▓▄▓ ▓ ▓
|
|
4
|
+
// ▄█████████▀▀▀ ▀███████▄▄███████▌ ▀▄ ▀▄▄ ▀▄▀ ▒ ▒ ▒ ▒ ▒ █ ▒ ▒ ▒ █
|
|
5
|
+
// ▐████████▀ ▄▄▄▄ ▀████████▀██▀█▌
|
|
6
|
+
// ████████ ███▀▀ ████▀ █▀ █▀ Leviathan Crypto Library
|
|
7
|
+
// ███████▌ ▀██▀ ███
|
|
8
|
+
// ███████ ▀███ ▀██ ▀█▄ Repository & Mirror:
|
|
9
|
+
// ▀██████ ▄▄██ ▀▀ ██▄ github.com/xero/leviathan-crypto
|
|
10
|
+
// ▀█████▄ ▄██▄ ▄▀▄▀ unpkg.com/leviathan-crypto
|
|
11
|
+
// ▀████▄ ▄██▄
|
|
12
|
+
// ▐████ ▐███ Author: xero (https://x-e.ro)
|
|
13
|
+
// ▄▄██████████ ▐███ ▄▄ License: MIT
|
|
14
|
+
// ▄██▀▀▀▀▀▀▀▀▀▀ ▄████ ▄██▀
|
|
15
|
+
// ▄▀ ▄▄█████████▄▄ ▀▀▀▀▀ ▄███ This file is provided completely
|
|
16
|
+
// ▄██████▀▀▀▀▀▀██████▄ ▀▄▄▄▄████▀ free, "as is", and without
|
|
17
|
+
// ████▀ ▄▄▄▄▄▄▄ ▀████▄ ▀█████▀ ▄▄▄▄ warranty of any kind. The author
|
|
18
|
+
// █████▄▄█████▀▀▀▀▀▀▄ ▀███▄ ▄████ assumes absolutely no liability
|
|
19
|
+
// ▀██████▀ ▀████▄▄▄████▀ for its {ab,mis,}use.
|
|
20
|
+
// ▀█████▀▀
|
|
21
|
+
//
|
|
22
|
+
// src/ts/slhdsa/embedded.ts
|
|
23
|
+
//
|
|
24
|
+
// Exports the gzip+base64 slhdsa WASM blob for use as a WasmSource.
|
|
25
|
+
// Import via `leviathan-crypto/slhdsa/embedded`.
|
|
26
|
+
export { WASM_GZ_BASE64 as slhdsaWasm } from '../embedded/slhdsa.js';
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import { isInitialized } from '../init.js';
|
|
2
|
+
import type { WasmSource } from '../wasm-source.js';
|
|
3
|
+
import type { SlhDsaExports, SlhDsaKeyPair } from './types.js';
|
|
4
|
+
import { type SlhDsaParams, SLHDSA128F, SLHDSA192F, SLHDSA256F } from './params.js';
|
|
5
|
+
import { type PreHashAlgorithm } from './prehash.js';
|
|
6
|
+
export declare function slhdsaInit(source: WasmSource): Promise<void>;
|
|
7
|
+
export type { WasmSource };
|
|
8
|
+
export type { SlhDsaExports, SlhDsaKeyPair } from './types.js';
|
|
9
|
+
export { SLHDSA128F, SLHDSA192F, SLHDSA256F };
|
|
10
|
+
export type { SlhDsaParams };
|
|
11
|
+
export type { PreHashAlgorithm } from './prehash.js';
|
|
12
|
+
export { isInitialized };
|
|
13
|
+
/** Return the slhdsa WASM instance exports. Internal helper for tests that
|
|
14
|
+
* need raw access to the ADRS / hash / sponge primitives; consumers use
|
|
15
|
+
* the SlhDsa* classes below. */
|
|
16
|
+
export declare function getSlhDsaExports(): SlhDsaExports;
|
|
17
|
+
export declare class SlhDsaBase {
|
|
18
|
+
readonly params: SlhDsaParams;
|
|
19
|
+
constructor(params: SlhDsaParams);
|
|
20
|
+
private get x();
|
|
21
|
+
private get sx();
|
|
22
|
+
private get sha2x();
|
|
23
|
+
/**
|
|
24
|
+
* Deterministic key generation, FIPS 205 §9.1 Algorithm 18.
|
|
25
|
+
* @param seed 3n bytes laid out as `SK.seed ‖ SK.prf ‖ PK.seed`. Each
|
|
26
|
+
* component is `n` bytes (16 for 128f, 24 for 192f, 32 for
|
|
27
|
+
* 256f). The slh_keygen_internal entry consumes this layout
|
|
28
|
+
* directly.
|
|
29
|
+
*/
|
|
30
|
+
keygenDerand(seed: Uint8Array): SlhDsaKeyPair;
|
|
31
|
+
/** Random key generation, wraps `keygenDerand` with `randomBytes(3n)`. */
|
|
32
|
+
keygen(): SlhDsaKeyPair;
|
|
33
|
+
/**
|
|
34
|
+
* Hedged signing, FIPS 205 §3.4 / §10.2.1 Algorithm 22.
|
|
35
|
+
* Generates a fresh n-byte addrnd (opt_rand) per signature; two
|
|
36
|
+
* signatures over the same (sk, M, ctx) produce different bytes.
|
|
37
|
+
* Hedged signing is recommended over deterministic because hedged
|
|
38
|
+
* signatures remain unforgeable under fault attacks that bias the
|
|
39
|
+
* rejection-sampling stream (FIPS 205 §3.4 / §9.2).
|
|
40
|
+
*/
|
|
41
|
+
sign(sk: Uint8Array, M: Uint8Array, ctx?: Uint8Array): Uint8Array;
|
|
42
|
+
/**
|
|
43
|
+
* Deterministic signing, FIPS 205 §3.4. Sets opt_rand ← PK.seed so two
|
|
44
|
+
* signatures over the same (sk, M, ctx) produce identical bytes.
|
|
45
|
+
* Caller accepts the §3.4 caveat: deterministic signatures are
|
|
46
|
+
* vulnerable to fault attacks that bias secret-derived intermediates;
|
|
47
|
+
* use only when no entropy is available or determinism is a hard
|
|
48
|
+
* protocol requirement. PK.seed lives at sk[2n..3n] inside the
|
|
49
|
+
* `SK.seed ‖ SK.prf ‖ PK.seed ‖ PK.root` encoding (FIPS 205 §9.1).
|
|
50
|
+
*/
|
|
51
|
+
signDeterministic(sk: Uint8Array, M: Uint8Array, ctx?: Uint8Array): Uint8Array;
|
|
52
|
+
/**
|
|
53
|
+
* Externally-randomised signing, testing / CAVP API. Caller supplies
|
|
54
|
+
* the n-byte opt_rand; library does not mix in additional entropy.
|
|
55
|
+
* Hard contract on the caller: opt_rand MUST come from an approved
|
|
56
|
+
* RBG and MUST NOT be reused across signatures. ACVP SLH-DSA sigGen
|
|
57
|
+
* vectors (with a supplied additionalRandomness) drive this path.
|
|
58
|
+
*/
|
|
59
|
+
signDerand(sk: Uint8Array, M: Uint8Array, optRand: Uint8Array, ctx?: Uint8Array): Uint8Array;
|
|
60
|
+
/**
|
|
61
|
+
* Pure SLH-DSA verify, FIPS 205 §10.3 Algorithm 24 / §9.3 Algorithm 20.
|
|
62
|
+
*
|
|
63
|
+
* Returns boolean. Wrong-length pk / sig return false (FIPS 205 §3.6.2
|
|
64
|
+
* structural mismatch; same posture as ML-DSA verify). Throws
|
|
65
|
+
* `SigningError('sig-ctx-too-long')` only on the caller-side contract
|
|
66
|
+
* violation `ctx.length > 255`.
|
|
67
|
+
*/
|
|
68
|
+
verify(pk: Uint8Array, M: Uint8Array, sig: Uint8Array, ctx?: Uint8Array): boolean;
|
|
69
|
+
private _assertHashPrereqs;
|
|
70
|
+
/**
|
|
71
|
+
* Hedged HashSLH-DSA sign, FIPS 205 §10.2.2 Algorithm 23.
|
|
72
|
+
*
|
|
73
|
+
* Pre-hashes `M` with the chosen approved function `ph`, builds
|
|
74
|
+
* M' = 0x01 ‖ |ctx| ‖ ctx ‖ OID(ph) ‖ PH_M, then drives
|
|
75
|
+
* slh_sign_internal with a fresh n-byte opt_rand (FIPS 205 §3.4
|
|
76
|
+
* recommended default; see {@link sign} for the rationale).
|
|
77
|
+
*/
|
|
78
|
+
signHash(sk: Uint8Array, M: Uint8Array, ph: PreHashAlgorithm, ctx?: Uint8Array): Uint8Array;
|
|
79
|
+
/**
|
|
80
|
+
* Deterministic HashSLH-DSA sign, FIPS 205 §10.2.2 Algorithm 23 with
|
|
81
|
+
* opt_rand ← PK.seed (the deterministic substitute per FIPS 205 §3.4).
|
|
82
|
+
* Same fault-attack caveat as {@link signDeterministic}.
|
|
83
|
+
*/
|
|
84
|
+
signHashDeterministic(sk: Uint8Array, M: Uint8Array, ph: PreHashAlgorithm, ctx?: Uint8Array): Uint8Array;
|
|
85
|
+
/**
|
|
86
|
+
* Externally-randomised HashSLH-DSA sign, testing / CAVP API. Caller
|
|
87
|
+
* supplies the n-byte opt_rand (same contract as {@link signDerand}).
|
|
88
|
+
* Used to oracle ACVP HashSLH-DSA sigGen vectors with byte-identical
|
|
89
|
+
* output.
|
|
90
|
+
*/
|
|
91
|
+
signHashDerand(sk: Uint8Array, M: Uint8Array, ph: PreHashAlgorithm, optRand: Uint8Array, ctx?: Uint8Array): Uint8Array;
|
|
92
|
+
/**
|
|
93
|
+
* HashSLH-DSA verify, FIPS 205 §10.3 Algorithm 25.
|
|
94
|
+
*
|
|
95
|
+
* Same return / throw posture as {@link verify}: returns boolean for
|
|
96
|
+
* every signature outcome (including malformed-σ → false), throws
|
|
97
|
+
* `SigningError` only on caller-side contract violations
|
|
98
|
+
* (`ctx.length > 255`) or `RangeError` on category violations and
|
|
99
|
+
* unsupported `ph`.
|
|
100
|
+
*/
|
|
101
|
+
verifyHash(pk: Uint8Array, M: Uint8Array, sig: Uint8Array, ph: PreHashAlgorithm, ctx?: Uint8Array): boolean;
|
|
102
|
+
/**
|
|
103
|
+
* Hedged HashSLH-DSA sign with a caller-supplied prehash. FIPS 205
|
|
104
|
+
* §10.2.2 Algorithm 23 lines 18-25 (the post-PH path).
|
|
105
|
+
*
|
|
106
|
+
* `digest` must be exactly `digestSize(ph)` bytes; a mismatch throws
|
|
107
|
+
* `SigningError('sig-malformed-input')`. The caller owns `digest`
|
|
108
|
+
* and is responsible for wiping it; this method never mutates the
|
|
109
|
+
* buffer. Hedged variant generates a fresh n-byte opt_rand per call.
|
|
110
|
+
*/
|
|
111
|
+
signHashPrehashed(sk: Uint8Array, digest: Uint8Array, ph: PreHashAlgorithm, ctx?: Uint8Array): Uint8Array;
|
|
112
|
+
/**
|
|
113
|
+
* Deterministic HashSLH-DSA sign with a caller-supplied prehash,
|
|
114
|
+
* opt_rand ← PK.seed per FIPS 205 §3.4. Same fault-attack caveat as
|
|
115
|
+
* {@link signDeterministic}.
|
|
116
|
+
*/
|
|
117
|
+
signHashPrehashedDeterministic(sk: Uint8Array, digest: Uint8Array, ph: PreHashAlgorithm, ctx?: Uint8Array): Uint8Array;
|
|
118
|
+
/**
|
|
119
|
+
* Externally-randomised HashSLH-DSA sign with a caller-supplied
|
|
120
|
+
* prehash, testing / CAVP API. Caller supplies the n-byte opt_rand:
|
|
121
|
+
* MUST come from an approved RBG and MUST NOT be reused across
|
|
122
|
+
* signatures.
|
|
123
|
+
*/
|
|
124
|
+
signHashPrehashedDerand(sk: Uint8Array, digest: Uint8Array, ph: PreHashAlgorithm, optRand: Uint8Array, ctx?: Uint8Array): Uint8Array;
|
|
125
|
+
/**
|
|
126
|
+
* HashSLH-DSA verify with a caller-supplied prehash. FIPS 205 §10.3
|
|
127
|
+
* Algorithm 25 lines 16-19 (the post-PH path).
|
|
128
|
+
*
|
|
129
|
+
* Returns boolean for every signature outcome. Wrong-length pk / σ
|
|
130
|
+
* and wrong-size `digest` all return `false` (FIPS 205 §3.6.2 /
|
|
131
|
+
* §10.3 structural mismatch). Throws on caller-side contract
|
|
132
|
+
* violations only (`ctx.length > 255`, unsupported `ph`, category
|
|
133
|
+
* mismatch).
|
|
134
|
+
*/
|
|
135
|
+
verifyHashPrehashed(pk: Uint8Array, digest: Uint8Array, sig: Uint8Array, ph: PreHashAlgorithm, ctx?: Uint8Array): boolean;
|
|
136
|
+
dispose(): void;
|
|
137
|
+
}
|
|
138
|
+
/** SLH-DSA-SHAKE-128f, FIPS 205 §11.1 Table 2 (NIST security category 1). */
|
|
139
|
+
export declare class SlhDsa128f extends SlhDsaBase {
|
|
140
|
+
constructor();
|
|
141
|
+
}
|
|
142
|
+
/** SLH-DSA-SHAKE-192f, FIPS 205 §11.1 Table 2 (NIST security category 3). */
|
|
143
|
+
export declare class SlhDsa192f extends SlhDsaBase {
|
|
144
|
+
constructor();
|
|
145
|
+
}
|
|
146
|
+
/** SLH-DSA-SHAKE-256f, FIPS 205 §11.1 Table 2 (NIST security category 5). */
|
|
147
|
+
export declare class SlhDsa256f extends SlhDsaBase {
|
|
148
|
+
constructor();
|
|
149
|
+
}
|