leviathan-crypto 2.0.1 → 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.
Files changed (312) hide show
  1. package/CLAUDE.md +88 -281
  2. package/LICENSE +4 -0
  3. package/README.md +275 -87
  4. package/dist/aes/aes-cbc.d.ts +40 -0
  5. package/dist/aes/aes-cbc.js +158 -0
  6. package/dist/aes/aes-ctr.d.ts +50 -0
  7. package/dist/aes/aes-ctr.js +141 -0
  8. package/dist/aes/aes-gcm-siv.d.ts +67 -0
  9. package/dist/aes/aes-gcm-siv.js +217 -0
  10. package/dist/aes/aes-gcm.d.ts +61 -0
  11. package/dist/aes/aes-gcm.js +226 -0
  12. package/dist/aes/cipher-suite.d.ts +21 -0
  13. package/dist/aes/cipher-suite.js +179 -0
  14. package/dist/aes/embedded.d.ts +1 -0
  15. package/dist/aes/embedded.js +26 -0
  16. package/dist/aes/generator.d.ts +14 -0
  17. package/dist/aes/generator.js +103 -0
  18. package/dist/aes/index.d.ts +58 -0
  19. package/dist/aes/index.js +125 -0
  20. package/dist/aes/ops.d.ts +60 -0
  21. package/dist/aes/ops.js +164 -0
  22. package/dist/aes/pool-worker.d.ts +1 -0
  23. package/dist/aes/pool-worker.js +92 -0
  24. package/dist/aes/types.d.ts +1 -0
  25. package/dist/aes/types.js +23 -0
  26. package/dist/aes.wasm +0 -0
  27. package/dist/blake3/embedded.d.ts +1 -0
  28. package/dist/blake3/embedded.js +26 -0
  29. package/dist/blake3/index.d.ts +143 -0
  30. package/dist/blake3/index.js +620 -0
  31. package/dist/blake3/types.d.ts +102 -0
  32. package/dist/blake3/types.js +31 -0
  33. package/dist/blake3/validate.d.ts +29 -0
  34. package/dist/blake3/validate.js +80 -0
  35. package/dist/blake3.wasm +0 -0
  36. package/dist/chacha20/cipher-suite.d.ts +10 -0
  37. package/dist/chacha20/cipher-suite.js +98 -13
  38. package/dist/chacha20/generator.d.ts +12 -0
  39. package/dist/chacha20/generator.js +91 -0
  40. package/dist/chacha20/index.d.ts +100 -3
  41. package/dist/chacha20/index.js +169 -35
  42. package/dist/chacha20/ops.d.ts +57 -6
  43. package/dist/chacha20/ops.js +107 -27
  44. package/dist/chacha20/pool-worker.js +14 -0
  45. package/dist/chacha20/types.d.ts +1 -32
  46. package/dist/cte-wasm.d.ts +1 -0
  47. package/dist/cte-wasm.js +3 -0
  48. package/dist/cte.wasm +0 -0
  49. package/dist/curve25519.wasm +0 -0
  50. package/dist/ecdsa/der.d.ts +23 -0
  51. package/dist/ecdsa/der.js +192 -0
  52. package/dist/ecdsa/ecprivatekey-der.d.ts +32 -0
  53. package/dist/ecdsa/ecprivatekey-der.js +230 -0
  54. package/dist/ecdsa/embedded.d.ts +1 -0
  55. package/dist/ecdsa/embedded.js +25 -0
  56. package/dist/ecdsa/index.d.ts +124 -0
  57. package/dist/ecdsa/index.js +366 -0
  58. package/dist/ecdsa/types.d.ts +31 -0
  59. package/dist/ecdsa/types.js +28 -0
  60. package/dist/ecdsa/validate.d.ts +18 -0
  61. package/dist/ecdsa/validate.js +92 -0
  62. package/dist/ed25519/embedded.d.ts +1 -0
  63. package/dist/ed25519/embedded.js +31 -0
  64. package/dist/ed25519/index.d.ts +70 -0
  65. package/dist/ed25519/index.js +308 -0
  66. package/dist/ed25519/types.d.ts +27 -0
  67. package/dist/ed25519/types.js +27 -0
  68. package/dist/ed25519/validate.d.ts +7 -0
  69. package/dist/ed25519/validate.js +77 -0
  70. package/dist/embedded/aes-pool-worker.d.ts +1 -0
  71. package/dist/embedded/aes-pool-worker.js +5 -0
  72. package/dist/embedded/aes.d.ts +1 -0
  73. package/dist/embedded/aes.js +3 -0
  74. package/dist/embedded/blake3.d.ts +1 -0
  75. package/dist/embedded/blake3.js +3 -0
  76. package/dist/embedded/chacha20-pool-worker.d.ts +1 -0
  77. package/dist/embedded/chacha20-pool-worker.js +5 -0
  78. package/dist/embedded/chacha20.d.ts +1 -1
  79. package/dist/embedded/chacha20.js +2 -2
  80. package/dist/embedded/curve25519.d.ts +1 -0
  81. package/dist/embedded/curve25519.js +3 -0
  82. package/dist/embedded/mldsa.d.ts +1 -0
  83. package/dist/embedded/mldsa.js +3 -0
  84. package/dist/embedded/mlkem.d.ts +1 -0
  85. package/dist/embedded/mlkem.js +3 -0
  86. package/dist/embedded/p256.d.ts +1 -0
  87. package/dist/embedded/p256.js +3 -0
  88. package/dist/embedded/serpent-pool-worker.d.ts +1 -0
  89. package/dist/embedded/serpent-pool-worker.js +5 -0
  90. package/dist/embedded/serpent.d.ts +1 -1
  91. package/dist/embedded/serpent.js +2 -2
  92. package/dist/embedded/sha2.d.ts +1 -1
  93. package/dist/embedded/sha2.js +2 -2
  94. package/dist/embedded/sha3.d.ts +1 -1
  95. package/dist/embedded/sha3.js +2 -2
  96. package/dist/embedded/slhdsa.d.ts +1 -0
  97. package/dist/embedded/slhdsa.js +3 -0
  98. package/dist/errors.d.ts +92 -1
  99. package/dist/errors.js +111 -1
  100. package/dist/fortuna.d.ts +18 -12
  101. package/dist/fortuna.js +166 -99
  102. package/dist/index.d.ts +42 -11
  103. package/dist/index.js +65 -20
  104. package/dist/init.d.ts +1 -3
  105. package/dist/init.js +73 -7
  106. package/dist/keccak/embedded.js +1 -1
  107. package/dist/keccak/index.d.ts +2 -0
  108. package/dist/keccak/index.js +4 -2
  109. package/dist/loader.d.ts +1 -19
  110. package/dist/loader.js +26 -32
  111. package/dist/merkle/blake3-tree.d.ts +35 -0
  112. package/dist/merkle/blake3-tree.js +187 -0
  113. package/dist/merkle/checkpoint.d.ts +58 -0
  114. package/dist/merkle/checkpoint.js +217 -0
  115. package/dist/merkle/index.d.ts +19 -0
  116. package/dist/merkle/index.js +37 -0
  117. package/dist/merkle/merkle-log.d.ts +130 -0
  118. package/dist/merkle/merkle-log.js +207 -0
  119. package/dist/merkle/merkle-verifier.d.ts +126 -0
  120. package/dist/merkle/merkle-verifier.js +296 -0
  121. package/dist/merkle/proof.d.ts +70 -0
  122. package/dist/merkle/proof.js +300 -0
  123. package/dist/merkle/sha256-tree.d.ts +33 -0
  124. package/dist/merkle/sha256-tree.js +145 -0
  125. package/dist/merkle/signed-log.d.ts +156 -0
  126. package/dist/merkle/signed-log.js +356 -0
  127. package/dist/merkle/signed-note.d.ts +309 -0
  128. package/dist/merkle/signed-note.js +648 -0
  129. package/dist/merkle/sth.d.ts +31 -0
  130. package/dist/merkle/sth.js +31 -0
  131. package/dist/merkle/storage.d.ts +40 -0
  132. package/dist/merkle/storage.js +71 -0
  133. package/dist/merkle/tree.d.ts +68 -0
  134. package/dist/merkle/tree.js +94 -0
  135. package/dist/mldsa/embedded.d.ts +1 -0
  136. package/dist/{kyber → mldsa}/embedded.js +5 -5
  137. package/dist/mldsa/expand.d.ts +53 -0
  138. package/dist/mldsa/expand.js +188 -0
  139. package/dist/mldsa/format.d.ts +16 -0
  140. package/dist/mldsa/format.js +68 -0
  141. package/dist/mldsa/hashvariant.d.ts +32 -0
  142. package/dist/mldsa/hashvariant.js +248 -0
  143. package/dist/mldsa/index.d.ts +142 -0
  144. package/dist/mldsa/index.js +463 -0
  145. package/dist/mldsa/keygen.d.ts +16 -0
  146. package/dist/mldsa/keygen.js +232 -0
  147. package/dist/mldsa/params.d.ts +21 -0
  148. package/dist/mldsa/params.js +55 -0
  149. package/dist/mldsa/sha3-helpers.d.ts +30 -0
  150. package/dist/mldsa/sha3-helpers.js +124 -0
  151. package/dist/mldsa/sign.d.ts +36 -0
  152. package/dist/mldsa/sign.js +380 -0
  153. package/dist/mldsa/types.d.ts +91 -0
  154. package/dist/mldsa/types.js +25 -0
  155. package/dist/mldsa/validate.d.ts +55 -0
  156. package/dist/mldsa/validate.js +125 -0
  157. package/dist/mldsa/verify.d.ts +29 -0
  158. package/dist/mldsa/verify.js +269 -0
  159. package/dist/mldsa.wasm +0 -0
  160. package/dist/mlkem/embedded.d.ts +1 -0
  161. package/dist/mlkem/embedded.js +27 -0
  162. package/dist/mlkem/indcpa.d.ts +49 -0
  163. package/dist/{kyber → mlkem}/indcpa.js +48 -48
  164. package/dist/mlkem/index.d.ts +37 -0
  165. package/dist/{kyber → mlkem}/index.js +41 -31
  166. package/dist/mlkem/kem.d.ts +21 -0
  167. package/dist/{kyber → mlkem}/kem.js +48 -13
  168. package/dist/{kyber → mlkem}/params.d.ts +4 -4
  169. package/dist/{kyber → mlkem}/params.js +2 -2
  170. package/dist/mlkem/suite.d.ts +12 -0
  171. package/dist/{kyber → mlkem}/suite.js +17 -12
  172. package/dist/{kyber → mlkem}/types.d.ts +4 -3
  173. package/dist/{kyber → mlkem}/types.js +1 -1
  174. package/dist/mlkem/validate.d.ts +23 -0
  175. package/dist/{kyber → mlkem}/validate.js +24 -20
  176. package/dist/{kyber.wasm → mlkem.wasm} +0 -0
  177. package/dist/p256.wasm +0 -0
  178. package/dist/ratchet/index.d.ts +8 -0
  179. package/dist/ratchet/index.js +38 -0
  180. package/dist/ratchet/kdf-chain.d.ts +13 -0
  181. package/dist/ratchet/kdf-chain.js +85 -0
  182. package/dist/ratchet/ratchet-keypair.d.ts +9 -0
  183. package/dist/ratchet/ratchet-keypair.js +61 -0
  184. package/dist/ratchet/root-kdf.d.ts +4 -0
  185. package/dist/ratchet/root-kdf.js +124 -0
  186. package/dist/ratchet/skipped-key-store.d.ts +14 -0
  187. package/dist/ratchet/skipped-key-store.js +154 -0
  188. package/dist/ratchet/types.d.ts +36 -0
  189. package/dist/ratchet/types.js +26 -0
  190. package/dist/serpent/cipher-suite.d.ts +10 -0
  191. package/dist/serpent/cipher-suite.js +144 -56
  192. package/dist/serpent/generator.d.ts +12 -0
  193. package/dist/serpent/generator.js +97 -0
  194. package/dist/serpent/index.d.ts +62 -1
  195. package/dist/serpent/index.js +97 -21
  196. package/dist/serpent/pool-worker.js +28 -102
  197. package/dist/serpent/serpent-cbc.d.ts +16 -6
  198. package/dist/serpent/serpent-cbc.js +58 -37
  199. package/dist/serpent/shared-ops.d.ts +63 -0
  200. package/dist/serpent/shared-ops.js +178 -0
  201. package/dist/serpent/types.d.ts +1 -5
  202. package/dist/serpent.wasm +0 -0
  203. package/dist/sha2/hash.d.ts +2 -0
  204. package/dist/sha2/hash.js +53 -0
  205. package/dist/sha2/hkdf.js +5 -5
  206. package/dist/sha2/index.d.ts +22 -1
  207. package/dist/sha2/index.js +80 -11
  208. package/dist/sha2/types.d.ts +41 -2
  209. package/dist/sha2.wasm +0 -0
  210. package/dist/sha3/hash.d.ts +2 -0
  211. package/dist/sha3/hash.js +53 -0
  212. package/dist/sha3/index.d.ts +87 -3
  213. package/dist/sha3/index.js +317 -19
  214. package/dist/sha3/kmac.d.ts +121 -0
  215. package/dist/sha3/kmac.js +800 -0
  216. package/dist/sha3.wasm +0 -0
  217. package/dist/shared/pkcs7.d.ts +22 -0
  218. package/dist/shared/pkcs7.js +84 -0
  219. package/dist/sign/ctx.d.ts +41 -0
  220. package/dist/sign/ctx.js +102 -0
  221. package/dist/sign/envelope.d.ts +45 -0
  222. package/dist/sign/envelope.js +152 -0
  223. package/dist/sign/hasher.d.ts +9 -0
  224. package/dist/sign/hasher.js +132 -0
  225. package/dist/sign/index.d.ts +11 -0
  226. package/dist/sign/index.js +34 -0
  227. package/dist/sign/sign-stream.d.ts +25 -0
  228. package/dist/sign/sign-stream.js +112 -0
  229. package/dist/sign/suites/ecdsa-p256.d.ts +2 -0
  230. package/dist/sign/suites/ecdsa-p256.js +120 -0
  231. package/dist/sign/suites/ed25519.d.ts +3 -0
  232. package/dist/sign/suites/ed25519.js +165 -0
  233. package/dist/sign/suites/hybrid-classical.d.ts +23 -0
  234. package/dist/sign/suites/hybrid-classical.js +526 -0
  235. package/dist/sign/suites/hybrid-pq.d.ts +4 -0
  236. package/dist/sign/suites/hybrid-pq.js +234 -0
  237. package/dist/sign/suites/mldsa.d.ts +7 -0
  238. package/dist/sign/suites/mldsa.js +161 -0
  239. package/dist/sign/suites/slhdsa.d.ts +7 -0
  240. package/dist/sign/suites/slhdsa.js +176 -0
  241. package/dist/sign/types.d.ts +106 -0
  242. package/dist/sign/types.js +28 -0
  243. package/dist/sign/verify-stream.d.ts +30 -0
  244. package/dist/sign/verify-stream.js +227 -0
  245. package/dist/slhdsa/embedded.d.ts +1 -0
  246. package/dist/slhdsa/embedded.js +26 -0
  247. package/dist/slhdsa/index.d.ts +149 -0
  248. package/dist/slhdsa/index.js +493 -0
  249. package/dist/slhdsa/params.d.ts +26 -0
  250. package/dist/slhdsa/params.js +70 -0
  251. package/dist/slhdsa/prehash.d.ts +68 -0
  252. package/dist/slhdsa/prehash.js +307 -0
  253. package/dist/slhdsa/sign.d.ts +39 -0
  254. package/dist/slhdsa/sign.js +116 -0
  255. package/dist/slhdsa/types.d.ts +129 -0
  256. package/dist/slhdsa/types.js +27 -0
  257. package/dist/slhdsa/validate.d.ts +60 -0
  258. package/dist/slhdsa/validate.js +127 -0
  259. package/dist/slhdsa/verify.d.ts +32 -0
  260. package/dist/slhdsa/verify.js +107 -0
  261. package/dist/slhdsa.wasm +0 -0
  262. package/dist/stream/header.js +8 -8
  263. package/dist/stream/index.d.ts +1 -0
  264. package/dist/stream/index.js +1 -0
  265. package/dist/stream/open-stream.js +65 -22
  266. package/dist/stream/seal-stream-pool.d.ts +2 -0
  267. package/dist/stream/seal-stream-pool.js +100 -33
  268. package/dist/stream/seal-stream.d.ts +1 -1
  269. package/dist/stream/seal-stream.js +48 -19
  270. package/dist/stream/seal.js +6 -6
  271. package/dist/stream/types.d.ts +3 -1
  272. package/dist/stream/types.js +1 -1
  273. package/dist/types.d.ts +22 -1
  274. package/dist/types.js +1 -1
  275. package/dist/utils.d.ts +9 -10
  276. package/dist/utils.js +84 -59
  277. package/dist/wasm-source.d.ts +9 -8
  278. package/dist/wasm-source.js +1 -1
  279. package/dist/x25519/embedded.d.ts +1 -0
  280. package/dist/x25519/embedded.js +31 -0
  281. package/dist/x25519/index.d.ts +43 -0
  282. package/dist/x25519/index.js +159 -0
  283. package/dist/x25519/types.d.ts +25 -0
  284. package/dist/x25519/types.js +27 -0
  285. package/dist/x25519/validate.d.ts +2 -0
  286. package/dist/x25519/validate.js +39 -0
  287. package/package.json +123 -64
  288. package/SECURITY.md +0 -276
  289. package/dist/ct-wasm.d.ts +0 -1
  290. package/dist/ct-wasm.js +0 -3
  291. package/dist/ct.wasm +0 -0
  292. package/dist/docs/aead.md +0 -323
  293. package/dist/docs/architecture.md +0 -932
  294. package/dist/docs/argon2id.md +0 -302
  295. package/dist/docs/chacha20.md +0 -674
  296. package/dist/docs/exports.md +0 -241
  297. package/dist/docs/fortuna.md +0 -313
  298. package/dist/docs/init.md +0 -302
  299. package/dist/docs/loader.md +0 -161
  300. package/dist/docs/serpent.md +0 -519
  301. package/dist/docs/sha2.md +0 -613
  302. package/dist/docs/sha3.md +0 -546
  303. package/dist/docs/types.md +0 -276
  304. package/dist/docs/utils.md +0 -367
  305. package/dist/embedded/kyber.d.ts +0 -1
  306. package/dist/embedded/kyber.js +0 -3
  307. package/dist/kyber/embedded.d.ts +0 -1
  308. package/dist/kyber/indcpa.d.ts +0 -49
  309. package/dist/kyber/index.d.ts +0 -38
  310. package/dist/kyber/kem.d.ts +0 -21
  311. package/dist/kyber/suite.d.ts +0 -13
  312. package/dist/kyber/validate.d.ts +0 -19
@@ -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
+ }