@amritk/nish-aarch64-linux 0.35.0 → 0.36.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 (119) hide show
  1. package/INSTALL.md +6 -1
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +9 -2
  4. package/package.json +1 -1
  5. package/runtime/nish.d.ts +4612 -430
  6. package/runtime/vite.d.ts +30 -0
  7. package/runtime/vite.mjs +150 -0
  8. package/scripts/build.sh +108 -13
  9. package/std/base64.ts +34 -5
  10. package/std/bytes.ts +256 -40
  11. package/std/cli-args.ts +296 -70
  12. package/std/cli-flags.ts +184 -19
  13. package/std/cli.ts +475 -54
  14. package/std/collections.ts +121 -23
  15. package/std/compress/checksum.ts +44 -14
  16. package/std/compress/deflate.ts +224 -111
  17. package/std/compress/gzip.ts +217 -53
  18. package/std/compress/zlib.ts +63 -7
  19. package/std/crypto/aes.ts +80 -9
  20. package/std/crypto/base64url.ts +22 -0
  21. package/std/crypto/bcrypt-batch.ts +88 -21
  22. package/std/crypto/bcrypt.ts +60 -0
  23. package/std/crypto/chacha20poly1305.ts +53 -0
  24. package/std/crypto/ct.ts +32 -13
  25. package/std/crypto/ed25519.ts +47 -0
  26. package/std/crypto/hkdf.ts +198 -13
  27. package/std/crypto/hmac.ts +235 -31
  28. package/std/crypto/jwt.ts +192 -63
  29. package/std/crypto/p256.ts +159 -16
  30. package/std/crypto/p384.ts +28 -3
  31. package/std/crypto/pki-roots.ts +32 -2
  32. package/std/crypto/pki.ts +81 -15
  33. package/std/crypto/rsa.ts +33 -3
  34. package/std/crypto/sha1.ts +3 -0
  35. package/std/crypto/sha256.ts +24 -1
  36. package/std/crypto/sha512.ts +99 -14
  37. package/std/crypto/x25519.ts +152 -14
  38. package/std/crypto/x509-random.ts +10 -0
  39. package/std/crypto/x509.ts +67 -7
  40. package/std/json-equal.ts +19 -0
  41. package/std/json-format.ts +112 -13
  42. package/std/json-number.ts +64 -14
  43. package/std/json-pointer.ts +23 -1
  44. package/std/json-tokenizer.ts +100 -29
  45. package/std/json-typed.ts +713 -66
  46. package/std/json-value.ts +400 -124
  47. package/std/json.ts +138 -10
  48. package/std/map.ts +25 -7
  49. package/std/math.ts +36 -4
  50. package/std/net/buffer-pool.ts +42 -11
  51. package/std/net/dns-config.ts +109 -23
  52. package/std/net/dns-message.ts +62 -7
  53. package/std/net/dns-resolver.ts +247 -53
  54. package/std/net/dns.ts +203 -35
  55. package/std/net/fetch.ts +151 -61
  56. package/std/net/handler.ts +278 -80
  57. package/std/net/hpack.ts +262 -52
  58. package/std/net/http-compress.ts +125 -15
  59. package/std/net/http-fields.ts +85 -9
  60. package/std/net/http1-client-codec.ts +100 -19
  61. package/std/net/http1-codec.ts +235 -27
  62. package/std/net/http1-server.ts +343 -85
  63. package/std/net/http2-frame.ts +272 -35
  64. package/std/net/http2-tls.ts +135 -34
  65. package/std/net/http2.ts +247 -106
  66. package/std/net/http3-frame.ts +154 -17
  67. package/std/net/http3-server.ts +246 -96
  68. package/std/net/http3.ts +307 -115
  69. package/std/net/outbound.ts +37 -3
  70. package/std/net/postgres-carrier.ts +144 -8
  71. package/std/net/postgres.ts +723 -103
  72. package/std/net/prefork.ts +164 -31
  73. package/std/net/qpack.ts +105 -18
  74. package/std/net/quic-conn-ack.ts +59 -12
  75. package/std/net/quic-conn-cid.ts +124 -27
  76. package/std/net/quic-conn-params.ts +70 -10
  77. package/std/net/quic-datagram.ts +43 -3
  78. package/std/net/quic-frame.ts +286 -12
  79. package/std/net/quic-listener.ts +101 -32
  80. package/std/net/quic-packet.ts +302 -21
  81. package/std/net/quic-recovery.ts +228 -44
  82. package/std/net/quic-stream.ts +353 -91
  83. package/std/net/quic.ts +489 -171
  84. package/std/net/router.ts +87 -40
  85. package/std/net/tls/client.ts +166 -51
  86. package/std/net/tls/codec.ts +413 -56
  87. package/std/net/tls/record-client.ts +110 -55
  88. package/std/net/tls/record-server.ts +159 -59
  89. package/std/net/tls/record.ts +109 -12
  90. package/std/net/tls/schedule.ts +235 -26
  91. package/std/net/tls/ticket.ts +159 -40
  92. package/std/net/tls/verify.ts +49 -3
  93. package/std/net/tls-tcp.ts +250 -45
  94. package/std/net/tls.ts +221 -59
  95. package/std/net/upstream.ts +81 -45
  96. package/std/net/url.ts +97 -13
  97. package/std/net/websocket.ts +122 -12
  98. package/std/net/webtransport.ts +220 -89
  99. package/std/pair.ts +10 -2
  100. package/std/random.ts +34 -9
  101. package/std/regex.ts +352 -198
  102. package/std/region.ts +70 -15
  103. package/std/secret.ts +52 -11
  104. package/std/sort.ts +17 -2
  105. package/std/sqlite.ts +256 -35
  106. package/std/sync/ring.ts +205 -35
  107. package/std/sync/shm.ts +194 -16
  108. package/std/term-io.ts +137 -64
  109. package/std/term-pixels.ts +144 -19
  110. package/std/term-probe.ts +66 -25
  111. package/std/term-rate.ts +128 -57
  112. package/std/term.ts +332 -121
  113. package/std/testing.ts +130 -32
  114. package/std/text.ts +73 -7
  115. package/std/threads.ts +229 -41
  116. package/std/yaml-json.ts +94 -82
  117. package/std/yaml-lines.ts +47 -15
  118. package/std/yaml-write.ts +24 -16
  119. package/std/yaml.ts +764 -384
@@ -254,6 +254,9 @@ export class HmacSha256 {
254
254
  /**
255
255
  * Keys the computation. A key longer than 64 bytes is replaced by its
256
256
  * SHA-256 (RFC 2104 §2), which is wiped once used (`hmacKeySha256`).
257
+ *
258
+ * @param key The secret key; it is read, not kept, and the caller still
259
+ * wipes it.
257
260
  */
258
261
  constructor(key: u8[]) {
259
262
  this.inner = new Sha256()
@@ -261,12 +264,23 @@ export class HmacSha256 {
261
264
  hmacKeySha256(this.inner, this.outer, key)
262
265
  }
263
266
 
264
- /** Absorbs `data[off .. off + len)`; a window outside `data` panics in `Sha256.update`. */
267
+ /**
268
+ * Absorbs `data[off .. off + len)`; a window outside `data` panics in
269
+ * `Sha256.update`.
270
+ *
271
+ * @param data The buffer holding the window; it is read, not kept.
272
+ * @param off Where the window starts in `data`.
273
+ * @param len How many bytes to absorb; 0 absorbs nothing.
274
+ */
265
275
  update(data: u8[], off: i32, len: i32): void {
266
276
  this.inner.update(data, off, len)
267
277
  }
268
278
 
269
- /** The 32-byte tag, in a fresh array. Ends the computation, and wipes both hashers. */
279
+ /**
280
+ * Ends the computation and wipes both hashers.
281
+ *
282
+ * @returns A fresh 32-byte tag, which the caller owns.
283
+ */
270
284
  digest(): u8[] {
271
285
  const innerDigest: u8[] = this.inner.digest()
272
286
  this.outer.update(innerDigest, HMAC_FROM, SHA256_SIZE)
@@ -288,19 +302,36 @@ export class HmacSha384 {
288
302
  /** H(K XOR opad, …), fed the key block in the constructor and the inner digest last. */
289
303
  outer: Sha384
290
304
 
291
- /** Keys the computation. A key longer than 128 bytes is replaced by its SHA-384 (RFC 2104 §2). */
305
+ /**
306
+ * Keys the computation. A key longer than 128 bytes is replaced by its
307
+ * SHA-384 (RFC 2104 §2).
308
+ *
309
+ * @param key The secret key; it is read, not kept, and the caller still
310
+ * wipes it.
311
+ */
292
312
  constructor(key: u8[]) {
293
313
  this.inner = new Sha384()
294
314
  this.outer = new Sha384()
295
315
  hmacKeySha384(this.inner, this.outer, key)
296
316
  }
297
317
 
298
- /** Absorbs `data[off .. off + len)`; a window outside `data` panics in `Sha384.update`. */
318
+ /**
319
+ * Absorbs `data[off .. off + len)`; a window outside `data` panics in
320
+ * `Sha384.update`.
321
+ *
322
+ * @param data The buffer holding the window; it is read, not kept.
323
+ * @param off Where the window starts in `data`.
324
+ * @param len How many bytes to absorb; 0 absorbs nothing.
325
+ */
299
326
  update(data: u8[], off: i32, len: i32): void {
300
327
  this.inner.update(data, off, len)
301
328
  }
302
329
 
303
- /** The 48-byte tag, in a fresh array. Ends the computation, and wipes both hashers. */
330
+ /**
331
+ * Ends the computation and wipes both hashers.
332
+ *
333
+ * @returns A fresh 48-byte tag, which the caller owns.
334
+ */
304
335
  digest(): u8[] {
305
336
  const innerDigest: u8[] = this.inner.digest()
306
337
  this.outer.update(innerDigest, HMAC_FROM, SHA384_SIZE)
@@ -322,19 +353,36 @@ export class HmacSha512 {
322
353
  /** H(K XOR opad, …), fed the key block in the constructor and the inner digest last. */
323
354
  outer: Sha512
324
355
 
325
- /** Keys the computation. A key longer than 128 bytes is replaced by its SHA-512 (RFC 2104 §2). */
356
+ /**
357
+ * Keys the computation. A key longer than 128 bytes is replaced by its
358
+ * SHA-512 (RFC 2104 §2).
359
+ *
360
+ * @param key The secret key; it is read, not kept, and the caller still
361
+ * wipes it.
362
+ */
326
363
  constructor(key: u8[]) {
327
364
  this.inner = new Sha512()
328
365
  this.outer = new Sha512()
329
366
  hmacKeySha512(this.inner, this.outer, key)
330
367
  }
331
368
 
332
- /** Absorbs `data[off .. off + len)`; a window outside `data` panics in `Sha512.update`. */
369
+ /**
370
+ * Absorbs `data[off .. off + len)`; a window outside `data` panics in
371
+ * `Sha512.update`.
372
+ *
373
+ * @param data The buffer holding the window; it is read, not kept.
374
+ * @param off Where the window starts in `data`.
375
+ * @param len How many bytes to absorb; 0 absorbs nothing.
376
+ */
333
377
  update(data: u8[], off: i32, len: i32): void {
334
378
  this.inner.update(data, off, len)
335
379
  }
336
380
 
337
- /** The 64-byte tag, in a fresh array. Ends the computation, and wipes both hashers. */
381
+ /**
382
+ * Ends the computation and wipes both hashers.
383
+ *
384
+ * @returns A fresh 64-byte tag, which the caller owns.
385
+ */
338
386
  digest(): u8[] {
339
387
  const innerDigest: u8[] = this.inner.digest()
340
388
  this.outer.update(innerDigest, HMAC_FROM, SHA512_SIZE)
@@ -353,6 +401,10 @@ export class HmacSha512 {
353
401
  * reason: under `--number-mode f64` the tag would be of a prefix, and a tag
354
402
  * that verifies every message sharing that prefix is a forgery. A key that
355
403
  * long panics in the constructor for the same reason.
404
+ *
405
+ * @param key The secret key; it is read, not kept.
406
+ * @param data The whole message.
407
+ * @returns A fresh 32-byte tag, which the caller owns.
356
408
  */
357
409
  export const hmacSha256 = (key: u8[], data: u8[]): u8[] => {
358
410
  if (data.length > 2147483647) {
@@ -366,6 +418,10 @@ export const hmacSha256 = (key: u8[], data: u8[]): u8[] => {
366
418
  /**
367
419
  * The HMAC-SHA-384 of all of `data` under `key`, as a fresh 48-byte array.
368
420
  * `data` longer than 2^31 - 1 bytes panics, as in `hmacSha256`.
421
+ *
422
+ * @param key The secret key; it is read, not kept.
423
+ * @param data The whole message.
424
+ * @returns A fresh 48-byte tag, which the caller owns.
369
425
  */
370
426
  export const hmacSha384 = (key: u8[], data: u8[]): u8[] => {
371
427
  if (data.length > 2147483647) {
@@ -379,6 +435,10 @@ export const hmacSha384 = (key: u8[], data: u8[]): u8[] => {
379
435
  /**
380
436
  * The HMAC-SHA-512 of all of `data` under `key`, as a fresh 64-byte array.
381
437
  * `data` longer than 2^31 - 1 bytes panics, as in `hmacSha256`.
438
+ *
439
+ * @param key The secret key; it is read, not kept.
440
+ * @param data The whole message.
441
+ * @returns A fresh 64-byte tag, which the caller owns.
382
442
  */
383
443
  export const hmacSha512 = (key: u8[], data: u8[]): u8[] => {
384
444
  if (data.length > 2147483647) {
@@ -392,13 +452,29 @@ export const hmacSha512 = (key: u8[], data: u8[]): u8[] => {
392
452
  /**
393
453
  * `hmacSha256` under a key held as a `Secret`, read only inside `exposeWith`.
394
454
  * The tag is public, so it is answered plain; the caller still wipes the key.
455
+ *
456
+ * @param key The secret key; the caller still owns and wipes it.
457
+ * @param data The whole message.
458
+ * @returns A fresh 32-byte tag, plain because a tag is public.
395
459
  */
396
460
  export const hmacSha256Secret = (key: Secret<u8[]>, data: u8[]): u8[] => exposeWith(key, data, hmacSha256)
397
461
 
398
- /** `hmacSha384` under a key held as a `Secret`, as `hmacSha256Secret` is. */
462
+ /**
463
+ * `hmacSha384` under a key held as a `Secret`, as `hmacSha256Secret` is.
464
+ *
465
+ * @param key The secret key; the caller still owns and wipes it.
466
+ * @param data The whole message.
467
+ * @returns A fresh 48-byte tag, plain because a tag is public.
468
+ */
399
469
  export const hmacSha384Secret = (key: Secret<u8[]>, data: u8[]): u8[] => exposeWith(key, data, hmacSha384)
400
470
 
401
- /** `hmacSha512` under a key held as a `Secret`, as `hmacSha256Secret` is. */
471
+ /**
472
+ * `hmacSha512` under a key held as a `Secret`, as `hmacSha256Secret` is.
473
+ *
474
+ * @param key The secret key; the caller still owns and wipes it.
475
+ * @param data The whole message.
476
+ * @returns A fresh 64-byte tag, plain because a tag is public.
477
+ */
402
478
  export const hmacSha512Secret = (key: Secret<u8[]>, data: u8[]): u8[] => exposeWith(key, data, hmacSha512)
403
479
 
404
480
  /**
@@ -406,15 +482,36 @@ export const hmacSha512Secret = (key: Secret<u8[]>, data: u8[]): u8[] => exposeW
406
482
  * `timingSafeEqual`. A tag that is not 32 bytes answers `false` without a
407
483
  * byte compare, since its length is public; one that is is compared in full,
408
484
  * so the time taken does not say how many leading bytes were right.
485
+ *
486
+ * @param key The secret key.
487
+ * @param data The whole message the tag claims to cover.
488
+ * @param tag The tag to check, as received.
489
+ * @returns `true` only if `tag` is the full, correct tag.
409
490
  */
410
491
  export const hmacSha256Verify = (key: u8[], data: u8[], tag: u8[]): boolean =>
411
492
  timingSafeEqual(hmacSha256(key, data), tag)
412
493
 
413
- /** Whether `tag` is the HMAC-SHA-384 of `data` under `key`, compared as `hmacSha256Verify` does. */
494
+ /**
495
+ * Whether `tag` is the HMAC-SHA-384 of `data` under `key`, compared as
496
+ * `hmacSha256Verify` does.
497
+ *
498
+ * @param key The secret key.
499
+ * @param data The whole message the tag claims to cover.
500
+ * @param tag The tag to check, as received.
501
+ * @returns `true` only if `tag` is the full, correct tag.
502
+ */
414
503
  export const hmacSha384Verify = (key: u8[], data: u8[], tag: u8[]): boolean =>
415
504
  timingSafeEqual(hmacSha384(key, data), tag)
416
505
 
417
- /** Whether `tag` is the HMAC-SHA-512 of `data` under `key`, compared as `hmacSha256Verify` does. */
506
+ /**
507
+ * Whether `tag` is the HMAC-SHA-512 of `data` under `key`, compared as
508
+ * `hmacSha256Verify` does.
509
+ *
510
+ * @param key The secret key.
511
+ * @param data The whole message the tag claims to cover.
512
+ * @param tag The tag to check, as received.
513
+ * @returns `true` only if `tag` is the full, correct tag.
514
+ */
418
515
  export const hmacSha512Verify = (key: u8[], data: u8[], tag: u8[]): boolean =>
419
516
  timingSafeEqual(hmacSha512(key, data), tag)
420
517
 
@@ -437,6 +534,9 @@ export const hmacSha512Verify = (key: u8[], data: u8[], tag: u8[]): boolean =>
437
534
  * nothing is allocated. Copying from a hasher nothing has been fed starts `to`
438
535
  * again. It is here rather than beside `Sha256` because the scratch below and
439
536
  * the TLS transcript are what need it, and HMAC is the module both sit on.
537
+ *
538
+ * @param from The hasher to copy; it is not changed.
539
+ * @param to The hasher overwritten with `from`'s position.
440
540
  */
441
541
  export const hmacCopySha256 = (from: Sha256, to: Sha256): void => {
442
542
  const fromState: u32[] = from.state
@@ -454,7 +554,12 @@ export const hmacCopySha256 = (from: Sha256, to: Sha256): void => {
454
554
  to.finished = from.finished
455
555
  }
456
556
 
457
- /** `hmacCopySha256` for SHA-384: `to` made the hasher `from` is, in place. */
557
+ /**
558
+ * `hmacCopySha256` for SHA-384: `to` made the hasher `from` is, in place.
559
+ *
560
+ * @param from The hasher to copy; it is not changed.
561
+ * @param to The hasher overwritten with `from`'s position.
562
+ */
458
563
  export const hmacCopySha384 = (from: Sha384, to: Sha384): void => {
459
564
  const fromState: u64[] = from.engine.state
460
565
  const toState: u64[] = to.engine.state
@@ -500,12 +605,15 @@ export class HmacSha256Scratch {
500
605
  /** H(K XOR opad, …): keyed by `begin`, fed the inner digest by `finishInto`. */
501
606
  outer: Sha256
502
607
  /** A hasher nothing is ever fed: the initial hash value `begin` copies from. */
503
- fresh: Sha256
608
+ private fresh: Sha256
504
609
  /** One key block XOR a pad, wiped as soon as it is absorbed. */
505
- pad: u8[]
610
+ private pad: u8[]
506
611
  /** The SHA-256 of a key longer than a block, which RFC 2104 §2 keys with instead; wiped once used. */
507
- keyHash: u8[]
612
+ private keyHash: u8[]
508
613
 
614
+ /**
615
+ * Allocates the hashers and buffers every tag reuses; `begin` keys them.
616
+ */
509
617
  constructor() {
510
618
  this.inner = new Sha256()
511
619
  this.outer = new Sha256()
@@ -514,7 +622,14 @@ export class HmacSha256Scratch {
514
622
  this.keyHash = new Array<u8>(SHA256_SIZE)
515
623
  }
516
624
 
517
- /** Keys a new computation with `key[off .. off + len)`, a key longer than 64 bytes by its SHA-256 (RFC 2104 §2). */
625
+ /**
626
+ * Keys a new computation with `key[off .. off + len)`, a key longer than 64
627
+ * bytes by its SHA-256 (RFC 2104 §2).
628
+ *
629
+ * @param key The buffer holding the key; it is read, not kept.
630
+ * @param off Where the key starts in `key`.
631
+ * @param len The key's length in bytes.
632
+ */
518
633
  begin(key: u8[], off: i32, len: i32): void {
519
634
  if (!hmacWindowFits(toI32(key.length), off, len)) {
520
635
  panic("HmacSha256Scratch: the key window is outside its array")
@@ -541,7 +656,7 @@ export class HmacSha256Scratch {
541
656
  * caller's key in a local it reassigns, which would make the key look
542
657
  * stored to the arena analysis.
543
658
  */
544
- keyBlocks(key: u8[], off: i32, len: i32): void {
659
+ private keyBlocks(key: u8[], off: i32, len: i32): void {
545
660
  // Starting a hasher again copies only the live part of `fresh`, so the
546
661
  // last computation's block and schedule are wiped first (K1-7).
547
662
  hmacWipeSha256(this.inner)
@@ -555,12 +670,25 @@ export class HmacSha256Scratch {
555
670
  secureZero(this.pad)
556
671
  }
557
672
 
558
- /** Absorbs `data[off .. off + len)`; a window outside `data` panics in `Sha256.update`. */
673
+ /**
674
+ * Absorbs `data[off .. off + len)`; a window outside `data` panics in
675
+ * `Sha256.update`.
676
+ *
677
+ * @param data The buffer holding the window; it is read, not kept.
678
+ * @param off Where the window starts in `data`.
679
+ * @param len How many bytes to absorb; 0 absorbs nothing.
680
+ */
559
681
  update(data: u8[], off: i32, len: i32): void {
560
682
  this.inner.update(data, off, len)
561
683
  }
562
684
 
563
- /** Writes the 32-byte tag at `out[at]` and ends the computation; a window outside `out` panics. */
685
+ /**
686
+ * Writes the 32-byte tag at `out[at]` and ends the computation; a window
687
+ * outside `out` panics.
688
+ *
689
+ * @param out The caller's array the tag is written into.
690
+ * @param at Where the 32 tag bytes start in `out`.
691
+ */
564
692
  finishInto(out: u8[], at: i32): void {
565
693
  if (!hmacWindowFits(toI32(out.length), at, SHA256_SIZE)) {
566
694
  panic("HmacSha256Scratch: the tag window is outside its array")
@@ -592,12 +720,15 @@ export class HmacSha384Scratch {
592
720
  /** H(K XOR opad, …): keyed by `begin`, fed the inner digest by `finishInto`. */
593
721
  outer: Sha384
594
722
  /** A hasher nothing is ever fed: the initial hash value `begin` copies from. */
595
- fresh: Sha384
723
+ private fresh: Sha384
596
724
  /** One key block XOR a pad, wiped as soon as it is absorbed. */
597
- pad: u8[]
725
+ private pad: u8[]
598
726
  /** The SHA-384 of a key longer than a block; wiped once used. */
599
- keyHash: u8[]
727
+ private keyHash: u8[]
600
728
 
729
+ /**
730
+ * Allocates the hashers and buffers every tag reuses; `begin` keys them.
731
+ */
601
732
  constructor() {
602
733
  this.inner = new Sha384()
603
734
  this.outer = new Sha384()
@@ -606,7 +737,14 @@ export class HmacSha384Scratch {
606
737
  this.keyHash = new Array<u8>(SHA384_SIZE)
607
738
  }
608
739
 
609
- /** Keys a new computation with `key[off .. off + len)`, a key longer than 128 bytes by its SHA-384 (RFC 2104 §2). */
740
+ /**
741
+ * Keys a new computation with `key[off .. off + len)`, a key longer than 128
742
+ * bytes by its SHA-384 (RFC 2104 §2).
743
+ *
744
+ * @param key The buffer holding the key; it is read, not kept.
745
+ * @param off Where the key starts in `key`.
746
+ * @param len The key's length in bytes.
747
+ */
610
748
  begin(key: u8[], off: i32, len: i32): void {
611
749
  if (!hmacWindowFits(toI32(key.length), off, len)) {
612
750
  panic("HmacSha384Scratch: the key window is outside its array")
@@ -633,7 +771,7 @@ export class HmacSha384Scratch {
633
771
  * caller's key in a local it reassigns, which would make the key look
634
772
  * stored to the arena analysis.
635
773
  */
636
- keyBlocks(key: u8[], off: i32, len: i32): void {
774
+ private keyBlocks(key: u8[], off: i32, len: i32): void {
637
775
  // Starting a hasher again copies only the live part of `fresh`, so the
638
776
  // last computation's block and schedule are wiped first (K1-7).
639
777
  hmacWipeSha384(this.inner)
@@ -647,12 +785,25 @@ export class HmacSha384Scratch {
647
785
  secureZero(this.pad)
648
786
  }
649
787
 
650
- /** Absorbs `data[off .. off + len)`; a window outside `data` panics in the hasher. */
788
+ /**
789
+ * Absorbs `data[off .. off + len)`; a window outside `data` panics in the
790
+ * hasher.
791
+ *
792
+ * @param data The buffer holding the window; it is read, not kept.
793
+ * @param off Where the window starts in `data`.
794
+ * @param len How many bytes to absorb; 0 absorbs nothing.
795
+ */
651
796
  update(data: u8[], off: i32, len: i32): void {
652
797
  this.inner.update(data, off, len)
653
798
  }
654
799
 
655
- /** Writes the 48-byte tag at `out[at]` and ends the computation; a window outside `out` panics. */
800
+ /**
801
+ * Writes the 48-byte tag at `out[at]` and ends the computation; a window
802
+ * outside `out` panics.
803
+ *
804
+ * @param out The caller's array the tag is written into.
805
+ * @param at Where the 48 tag bytes start in `out`.
806
+ */
656
807
  finishInto(out: u8[], at: i32): void {
657
808
  if (!hmacWindowFits(toI32(out.length), at, SHA384_SIZE)) {
658
809
  panic("HmacSha384Scratch: the tag window is outside its array")
@@ -790,6 +941,14 @@ const pbkdf2HmacSha256Exposed = (password: u8[], request: Pbkdf2Request): u8[] |
790
941
  * is linear in `iterations` and nothing here bounds it, so a caller that takes
791
942
  * the count from an untrusted peer (a SCRAM server's `i=`) must cap it first:
792
943
  * 2^31 - 1 rounds is about 2^32 compressions.
944
+ *
945
+ * @param password The password P, read only inside `exposeWith`; the caller
946
+ * still owns and wipes it.
947
+ * @param salt The salt S, public.
948
+ * @param iterations The round count `c`; below 1 answers `null`.
949
+ * @param length The derived key's length `dkLen` in bytes; below 1 answers
950
+ * `null`.
951
+ * @returns The derived key, which the caller wipes, or `null` for bad input.
793
952
  */
794
953
  export const pbkdf2HmacSha256 = (
795
954
  password: Secret<u8[]>,
@@ -923,27 +1082,53 @@ const hmacMidstates512 = (out: u64[], inner: u64[], outer: u64[]): void => {
923
1082
  * therefore used by one computation at a time, as a `Sha256` is.
924
1083
  */
925
1084
  export class HmacKey {
926
- /** Words 0 to 7: the keyed inner chaining value; 8 to 15: the keyed outer one. */
1085
+ /**
1086
+ * Words 0 to 7: the keyed inner chaining value; 8 to 15: the keyed outer one.
1087
+ *
1088
+ * @internal Read by `hmacKeyedInto`, `hmacKeyedVerify` and their helpers.
1089
+ */
927
1090
  readonly pads: Secret<u64[]>
928
- /** SHA-256's work hashers; idle and wiped between tags. */
1091
+ /**
1092
+ * SHA-256's work hashers; idle and wiped between tags.
1093
+ *
1094
+ * @internal Read by `hmacKeyedInto`, `hmacKeyedVerify` and their helpers.
1095
+ */
929
1096
  readonly inner256: Sha256
1097
+ /** @internal Read by `hmacKeyedInto`, `hmacKeyedVerify` and their helpers. */
930
1098
  readonly outer256: Sha256
931
1099
  /**
932
1100
  * SHA-384's and SHA-512's work hashers: SHA-384 is SHA-512's compression
933
1101
  * from another start, cut to 48 bytes, so resumed from a chaining value the
934
1102
  * two are one hasher and differ only in the digest length taken.
1103
+ *
1104
+ * @internal Read by `hmacKeyedInto`, `hmacKeyedVerify` and their helpers.
935
1105
  */
936
1106
  readonly inner512: Sha512
1107
+ /** @internal Read by `hmacKeyedInto`, `hmacKeyedVerify` and their helpers. */
937
1108
  readonly outer512: Sha512
938
- /** `HMAC_SHA256`, `HMAC_SHA384` or `HMAC_SHA512`. */
1109
+ /**
1110
+ * `HMAC_SHA256`, `HMAC_SHA384` or `HMAC_SHA512`.
1111
+ *
1112
+ * @internal Read by `hmacKeyedInto`, `hmacKeyedVerify` and their helpers.
1113
+ */
939
1114
  readonly hash: i32
940
1115
  /**
941
1116
  * Whether the key still MACs: `wipe()` clears it. A wiped key's chaining
942
1117
  * values are zeros anyone can resume from, so a tag under them proves
943
1118
  * nothing and none is computed.
1119
+ *
1120
+ * @internal Read by `hmacKeyedInto`, `hmacKeyedVerify` and their helpers.
944
1121
  */
945
1122
  live: boolean
946
1123
 
1124
+ /**
1125
+ * Absorbs `key`'s two pad blocks for `hash` and keeps the chaining values. An
1126
+ * unknown `hash` panics.
1127
+ *
1128
+ * @param hash Which HMAC: `HMAC_SHA256`, `HMAC_SHA384` or `HMAC_SHA512`.
1129
+ * @param key The key, read only inside `exposeWith`; the caller still owns
1130
+ * and wipes it.
1131
+ */
947
1132
  constructor(hash: i32, key: Secret<u8[]>) {
948
1133
  if (hmacTagSize(hash) === 0) {
949
1134
  panic("HmacKey: an unknown hash")
@@ -961,7 +1146,11 @@ export class HmacKey {
961
1146
  this.live = true
962
1147
  }
963
1148
 
964
- /** The tag length in bytes: 32, 48 or 64. */
1149
+ /**
1150
+ * The tag length in bytes.
1151
+ *
1152
+ * @returns 32 for `HMAC_SHA256`, 48 for `HMAC_SHA384`, 64 for `HMAC_SHA512`.
1153
+ */
965
1154
  size(): i32 {
966
1155
  return hmacTagSize(this.hash)
967
1156
  }
@@ -1052,6 +1241,13 @@ const hmacKeyedTag = (key: HmacKey, data: u8[], off: i32, len: i32): u8[] => {
1052
1241
  * `out[at .. at + key.size())`. A window outside its array panics before
1053
1242
  * anything is read. It runs in an arena block of its own and stores nothing,
1054
1243
  * so a tag leaves the arena where it was.
1244
+ *
1245
+ * @param key The absorbed key; a wiped one panics.
1246
+ * @param data The buffer holding the message.
1247
+ * @param off Where the message starts in `data`.
1248
+ * @param len The message's length in bytes.
1249
+ * @param out The caller's array the tag is written into.
1250
+ * @param at Where the tag starts in `out`.
1055
1251
  */
1056
1252
  export const hmacKeyedInto = (key: HmacKey, data: u8[], off: i32, len: i32, out: u8[], at: i32): void => {
1057
1253
  const size: i32 = key.size()
@@ -1078,6 +1274,14 @@ export const hmacKeyedInto = (key: HmacKey, data: u8[], off: i32, len: i32, out:
1078
1274
  * computed tag wiped, since it is the one tag a forger needs. A tag window
1079
1275
  * that does not fit answers `false`; a message window outside its array
1080
1276
  * panics. It runs in an arena block of its own and stores nothing.
1277
+ *
1278
+ * @param key The absorbed key; a wiped one answers `false`.
1279
+ * @param data The buffer holding the message.
1280
+ * @param off Where the message starts in `data`.
1281
+ * @param len The message's length in bytes.
1282
+ * @param tag The buffer holding the tag to check.
1283
+ * @param tagAt Where the tag starts in `tag`.
1284
+ * @returns `true` only if the tag window holds the correct tag.
1081
1285
  */
1082
1286
  export const hmacKeyedVerify = (
1083
1287
  key: HmacKey,