@amritk/nish-aarch64-linux 0.49.1 → 0.51.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 (107) hide show
  1. package/INSTALL.md +1 -1
  2. package/bin/nish +0 -0
  3. package/docs/AI.md +237 -160
  4. package/package.json +1 -1
  5. package/runtime/gfx/nish-gfx.h +373 -61
  6. package/runtime/nish.d.ts +94 -11
  7. package/runtime/nish.h +5 -0
  8. package/runtime/runtime-host.c +21 -5
  9. package/std/README.md +14 -11
  10. package/std/base64.ts +74 -35
  11. package/std/bytes.ts +207 -97
  12. package/std/cli-args.ts +150 -107
  13. package/std/compress/checksum.ts +68 -10
  14. package/std/compress/deflate.ts +213 -115
  15. package/std/compress/gzip.ts +124 -49
  16. package/std/compress/zlib.ts +57 -15
  17. package/std/crypto/aes.ts +51 -9
  18. package/std/crypto/base64url.ts +93 -66
  19. package/std/crypto/bcrypt.ts +25 -21
  20. package/std/crypto/ed25519.ts +12 -10
  21. package/std/crypto/hkdf.ts +405 -283
  22. package/std/crypto/hmac.ts +484 -149
  23. package/std/crypto/jwt.ts +51 -40
  24. package/std/crypto/p256.ts +14 -19
  25. package/std/crypto/pki-roots.ts +35 -12
  26. package/std/crypto/pki.ts +43 -55
  27. package/std/crypto/rsa-sign.ts +1635 -0
  28. package/std/crypto/rsa.ts +26 -4
  29. package/std/crypto/sha256.ts +212 -90
  30. package/std/crypto/sha512.ts +135 -49
  31. package/std/crypto/x25519.ts +12 -11
  32. package/std/crypto/x509.ts +164 -40
  33. package/std/gpu/sys.ts +490 -0
  34. package/std/json-equal.ts +33 -18
  35. package/std/json-format.ts +39 -8
  36. package/std/json-number.ts +15 -3
  37. package/std/json-tokenizer.ts +4 -3
  38. package/std/json-typed.ts +12 -6
  39. package/std/json-value.ts +236 -119
  40. package/std/json.ts +81 -46
  41. package/std/net/buffer-pool.ts +25 -14
  42. package/std/net/dns-config.ts +18 -5
  43. package/std/net/dns-message.ts +60 -27
  44. package/std/net/dns-resolver.ts +35 -16
  45. package/std/net/dns.ts +3 -2
  46. package/std/net/fetch.ts +224 -61
  47. package/std/net/handler.ts +189 -88
  48. package/std/net/hpack.ts +216 -103
  49. package/std/net/http-compress.ts +104 -42
  50. package/std/net/http-fields.ts +327 -31
  51. package/std/net/http-server.ts +326 -24
  52. package/std/net/http1-client-codec.ts +159 -55
  53. package/std/net/http1-codec.ts +427 -237
  54. package/std/net/http1-server.ts +220 -38
  55. package/std/net/http2-cleartext.ts +10 -4
  56. package/std/net/http2-frame.ts +2 -2
  57. package/std/net/http2-tls.ts +3 -3
  58. package/std/net/http2.ts +69 -15
  59. package/std/net/http3-frame.ts +11 -14
  60. package/std/net/http3-server.ts +139 -60
  61. package/std/net/http3.ts +140 -79
  62. package/std/net/multipart.ts +592 -0
  63. package/std/net/outbound.ts +24 -8
  64. package/std/net/postgres-async.ts +97 -64
  65. package/std/net/postgres-carrier.ts +28 -4
  66. package/std/net/postgres.ts +166 -65
  67. package/std/net/prefork.ts +86 -5
  68. package/std/net/protobuf.ts +6 -2
  69. package/std/net/qpack.ts +147 -40
  70. package/std/net/quic-conn-ack.ts +27 -7
  71. package/std/net/quic-conn-cid.ts +13 -7
  72. package/std/net/quic-datagram.ts +6 -5
  73. package/std/net/quic-frame.ts +67 -23
  74. package/std/net/quic-listener.ts +61 -39
  75. package/std/net/quic-packet.ts +91 -50
  76. package/std/net/quic-recovery.ts +11 -9
  77. package/std/net/quic-stream.ts +36 -27
  78. package/std/net/quic.ts +84 -54
  79. package/std/net/router.ts +136 -24
  80. package/std/net/serve.ts +59 -5
  81. package/std/net/static.ts +86 -36
  82. package/std/net/tls/client.ts +81 -34
  83. package/std/net/tls/codec.ts +3 -4
  84. package/std/net/tls/record.ts +80 -35
  85. package/std/net/tls/schedule.ts +339 -149
  86. package/std/net/tls/ticket.ts +6 -5
  87. package/std/net/tls-tcp.ts +69 -30
  88. package/std/net/tls.ts +194 -50
  89. package/std/net/upstream.ts +83 -38
  90. package/std/net/url.ts +170 -94
  91. package/std/net/websocket.ts +19 -20
  92. package/std/net/webtransport.ts +123 -33
  93. package/std/raster.ts +12 -2
  94. package/std/regex.ts +600 -388
  95. package/std/sqlite.ts +37 -19
  96. package/std/sync/ring.ts +232 -115
  97. package/std/sync/shm.ts +11 -4
  98. package/std/temporal.ts +232 -133
  99. package/std/term-io.ts +12 -6
  100. package/std/term-pixels.ts +176 -24
  101. package/std/term-rate.ts +8 -3
  102. package/std/term.ts +4 -4
  103. package/std/text.ts +38 -16
  104. package/std/yaml-json.ts +238 -106
  105. package/std/yaml-lines.ts +47 -27
  106. package/std/yaml-write.ts +58 -24
  107. package/std/yaml.ts +808 -395
@@ -47,50 +47,51 @@
47
47
  */
48
48
 
49
49
  /**
50
- * All ones when `lo <= c <= hi`, else zero, without a branch. `c` is a byte or
51
- * a sextet, so neither subtraction could leave `i32`; they are written in
52
- * `u32`, which wraps by definition, because a signed one would be checked for
53
- * an overflow it cannot have, and the check is a branch on the secret. The
54
- * sign bit `>> 31` reads is the same either way. `base64urlCharOf` and
55
- * `base64urlSextetOf` do their sums in `u32` for the same reason.
50
+ * All ones when `lo <= c <= hi`, else zero, without a branch. `c` is a
51
+ * character code or a sextet, below 2^16; `d` is `c` narrowed to that so the
52
+ * compiler proves neither subtraction leaves `i32`. A checked subtraction it
53
+ * could not prove would be a branch on the secret. `base64urlCharOf` and
54
+ * `base64urlSextetOf` narrow their argument the same way.
56
55
  */
57
- const base64urlRangeMask = (c: i32, lo: i32, hi: i32): i32 =>
58
- toI32((toU32(lo) - 1 - toU32(c)) & (toU32(c) - toU32(hi) - 1)) >> 31
56
+ const base64urlRangeMask = (c: i32, lo: integer<0, 255>, hi: integer<0, 255>): i32 => {
57
+ const d: i32 = c & 0xffff
58
+ return ((lo - 1 - d) & (d - hi - 1)) >> 31
59
+ }
59
60
 
60
61
  /**
61
- * The URL-alphabet character for the sextet `v` (`0 <= v <= 63`).
62
- *
62
+ * The URL-alphabet character for the sextet `v`. Every caller passes `0 <= v
63
+ * <= 63`; `v` is masked to its low six bits, so a wider value aliases.
63
64
  * It starts from `'A' + v` and adds, for each range `v` has passed, the step
64
65
  * from the previous range's first character to this one's: 26 lands on `a`, 52
65
66
  * on `0`, 62 on `-` and 63 on `_`.
66
67
  */
67
- const base64urlCharOf = (v: i32): i32 =>
68
- toI32(
68
+ const base64urlCharOf = (v: i32): i32 => {
69
+ const s: i32 = v & 63
70
+ return (
71
+ s +
69
72
  65 +
70
- toU32(v) +
71
- toU32(base64urlRangeMask(v, 26, 63) & 6) -
72
- toU32(base64urlRangeMask(v, 52, 63) & 75) -
73
- toU32(base64urlRangeMask(v, 62, 63) & 13) +
74
- toU32(base64urlRangeMask(v, 63, 63) & 49)
73
+ (base64urlRangeMask(s, 26, 63) & 6) -
74
+ (base64urlRangeMask(s, 52, 63) & 75) -
75
+ (base64urlRangeMask(s, 62, 63) & 13) +
76
+ (base64urlRangeMask(s, 63, 63) & 49)
75
77
  )
78
+ }
76
79
 
77
80
  /**
78
- * The sextet the byte `c` stands for, or `-1` when `c` is not in the alphabet.
79
- * Each range contributes its value under its own mask, and a byte in none of
80
- * them has every bit set by the final OR.
81
+ * The sextet the character code `code` (a `charCodeAt` or a byte, below 2^16:
82
+ * it is masked to 16 bits, so a wider value aliases) stands for, or `-1`. Each
83
+ * range adds its value under its own mask; none of them sets every bit.
81
84
  */
82
- const base64urlSextetOf = (c: i32): i32 => {
85
+ const base64urlSextetOf = (code: i32): i32 => {
86
+ // A character code is 16 bits: the mask proves each sum below in range.
87
+ const c: i32 = code & 0xffff
83
88
  const upper: i32 = base64urlRangeMask(c, 65, 90)
84
89
  const lower: i32 = base64urlRangeMask(c, 97, 122)
85
90
  const digit: i32 = base64urlRangeMask(c, 48, 57)
86
91
  const dash: i32 = base64urlRangeMask(c, 45, 45)
87
92
  const underscore: i32 = base64urlRangeMask(c, 95, 95)
88
93
  const value: i32 =
89
- (upper & toI32(toU32(c) - 65)) |
90
- (lower & toI32(toU32(c) - 71)) |
91
- (digit & toI32(toU32(c) + 4)) |
92
- (dash & 62) |
93
- (underscore & 63)
94
+ (upper & (c - 65)) | (lower & (c - 71)) | (digit & (c + 4)) | (dash & 62) | (underscore & 63)
94
95
  return value | ~(upper | lower | digit | dash | underscore)
95
96
  }
96
97
 
@@ -177,9 +178,16 @@ export const base64urlDecode = (text: string): u8[] | null => {
177
178
  return null
178
179
  }
179
180
  // Three bytes per full group of four, and one fewer than the characters in a
180
- // short final group; `n * 3 / 4` would overflow for a text over 700 MB. The
181
- // sum is a `u32`, exact for any `n` here.
182
- const out: u8[] = new Array<u8>(toU32(n >> 2) * 3 + (tail === 0 ? 0 : toU32(tail) - 1))
181
+ // short final group; `n * 3 / 4` would overflow for a text over 700 MB.
182
+ // Both parts are `i32`s the bounds prover reads as non-negative, and their
183
+ // sum, at most three quarters of `n`, as in range, so the allocation is
184
+ // proven rather than checked.
185
+ let short: i32 = 0
186
+ if (tail > 1) {
187
+ short = tail - 1
188
+ }
189
+ const whole: i32 = (n >> 2) * 3
190
+ const out: u8[] = new Array<u8>(whole + short)
183
191
  // All ones once any character is outside the alphabet (a sextet of `-1`
184
192
  // shifted right by 31), and non-zero once the text ends on a bit that
185
193
  // encodes no byte.
@@ -244,32 +252,31 @@ export const base64urlDecode = (text: string): u8[] | null => {
244
252
  // ---------------------------------------------------------------------------
245
253
 
246
254
  /**
247
- * The standard-alphabet character for the sextet `v`: the same steps as
248
- * `base64urlCharOf` until 62, which lands on `+` and 63 on `/`.
255
+ * The standard-alphabet character for the sextet `v` (`0 <= v <= 63`, masked as
256
+ * `base64urlCharOf` masks it): its steps until 62, which lands on `+`, 63 `/`.
249
257
  */
250
- const base64StdPadCharOf = (v: i32): i32 =>
251
- toI32(
258
+ const base64StdPadCharOf = (v: i32): i32 => {
259
+ const s: i32 = v & 63
260
+ return (
261
+ s +
252
262
  65 +
253
- toU32(v) +
254
- toU32(base64urlRangeMask(v, 26, 63) & 6) -
255
- toU32(base64urlRangeMask(v, 52, 63) & 75) -
256
- toU32(base64urlRangeMask(v, 62, 63) & 15) +
257
- toU32(base64urlRangeMask(v, 63, 63) & 3)
263
+ (base64urlRangeMask(s, 26, 63) & 6) -
264
+ (base64urlRangeMask(s, 52, 63) & 75) -
265
+ (base64urlRangeMask(s, 62, 63) & 15) +
266
+ (base64urlRangeMask(s, 63, 63) & 3)
258
267
  )
268
+ }
259
269
 
260
- /** The sextet the byte `c` stands for in standard base64, or `-1` when it is not in the alphabet. */
261
- const base64StdPadSextetOf = (c: i32): i32 => {
270
+ /** The sextet the character code `code` (below 2^16, masked as `base64urlSextetOf` masks it) stands for in standard base64, or `-1`. */
271
+ const base64StdPadSextetOf = (code: i32): i32 => {
272
+ // A character code is 16 bits: the mask proves each sum below in range.
273
+ const c: i32 = code & 0xffff
262
274
  const upper: i32 = base64urlRangeMask(c, 65, 90)
263
275
  const lower: i32 = base64urlRangeMask(c, 97, 122)
264
276
  const digit: i32 = base64urlRangeMask(c, 48, 57)
265
277
  const plus: i32 = base64urlRangeMask(c, 43, 43)
266
278
  const slash: i32 = base64urlRangeMask(c, 47, 47)
267
- const value: i32 =
268
- (upper & toI32(toU32(c) - 65)) |
269
- (lower & toI32(toU32(c) - 71)) |
270
- (digit & toI32(toU32(c) + 4)) |
271
- (plus & 62) |
272
- (slash & 63)
279
+ const value: i32 = (upper & (c - 65)) | (lower & (c - 71)) | (digit & (c + 4)) | (plus & 62) | (slash & 63)
273
280
  return value | ~(upper | lower | digit | plus | slash)
274
281
  }
275
282
 
@@ -327,13 +334,11 @@ export const base64StdPadEncodeInto = (data: u8[], start: i32, length: i32, out:
327
334
  if (start < 0 || length < 0 || start > toI32(data.length) - length || length > 1610612733) {
328
335
  panic("base64StdPadEncodeInto: bytes outside their buffer")
329
336
  }
330
- // The text's length, and the room after `at`, as `u32`s: exact, since
331
- // `length` is at most 1610612733 and `at` at most `out.length`.
332
- const textLength: u32 = ((toU32(length) + 2) / 3) * 4
333
- if (at < 0 || at > toI32(out.length) || textLength > toU32(toI32(out.length)) - toU32(at)) {
337
+ // The text's length fits an `i32`, since `length` is at most 1610612733.
338
+ const textLength: i32 = ((length + 2) / 3) * 4
339
+ if (at < 0 || at > toI32(out.length) || textLength > toI32(out.length) - at) {
334
340
  panic("base64StdPadEncodeInto: text that does not fit its buffer")
335
341
  }
336
- const end: i32 = toI32(toU32(at) + textLength)
337
342
  // `k` runs through `data[start .. start + length)` and `j` through the text;
338
343
  // the bounds on them only let the prover see what the tests above checked.
339
344
  let j: i32 = at
@@ -352,11 +357,14 @@ export const base64StdPadEncodeInto = (data: u8[], start: i32, length: i32, out:
352
357
  if (bits > 0) {
353
358
  j = base64Put(out, j, toU8(base64StdPadCharOf((acc << toI32(6 - bits)) & 63)))
354
359
  }
355
- while (j >= 0 && j < end && j < toI32(out.length)) {
360
+ // The `=`s that bring the text to a multiple of four characters: two after
361
+ // one byte left over, one after two, none after none.
362
+ const padCount: i32 = ((length % 3) * 2) % 3
363
+ for (let q: i32 = 0; q < padCount && j >= 0 && j < toI32(out.length); q++) {
356
364
  out[j] = 61
357
365
  j += 1
358
366
  }
359
- return end
367
+ return j
360
368
  }
361
369
 
362
370
  /**
@@ -376,21 +384,25 @@ export const base64StdPadDecodedLength = (text: u8[], start: i32, length: i32):
376
384
  if (text.length > 2147483647) {
377
385
  panic("base64StdPadDecodedLength: a buffer longer than 2^31 - 1 bytes")
378
386
  }
379
- if (start < 0 || length < 0 || start > toI32(text.length) - length) {
387
+ // The room before the range's end; a negative `length` panics below.
388
+ const before: i32 = length < 0 ? -1 : toI32(text.length) - length
389
+ if (start < 0 || length < 0 || start > before) {
380
390
  panic("base64StdPadDecodedLength: text outside its buffer")
381
391
  }
382
- if ((length & 3) !== 0) {
392
+ // What follows the range in `text`, never negative after the test above.
393
+ const rest: i32 = before - start
394
+ if ((length & 3) !== 0 || rest < 0) {
383
395
  return -1
384
396
  }
385
- // The text's last character, a `u32` sum that is exact once the range is
386
- // inside `text`; a length that is a multiple of four and not 0 is at least 4,
397
+ // The text's last character, `start + length - 1` counted back from the
398
+ // buffer's end; a length that is a multiple of four and not 0 is at least 4,
387
399
  // so the character before it is in the range too.
388
- const last: i32 = toI32(toU32(start) + toU32(length) - 1)
389
- let pad: u32 = 0
400
+ const last: i32 = toI32(text.length) - rest - 1
401
+ let pad: integer<0, 2> = 0
390
402
  if (length > 0 && last >= 1 && last < toI32(text.length) && toI32(text[last]) === 61) {
391
403
  pad = toI32(text[last - 1]) === 61 ? 2 : 1
392
404
  }
393
- const chars: i32 = toI32(toU32(length) - pad)
405
+ const chars: i32 = length - pad
394
406
  let bad: i32 = 0
395
407
  let acc: i32 = 0
396
408
  let bits: u32 = 0
@@ -409,7 +421,7 @@ export const base64StdPadDecodedLength = (text: u8[], start: i32, length: i32):
409
421
  if (bad !== 0) {
410
422
  return -1
411
423
  }
412
- return toI32(toU32(length >> 2) * 3 - pad)
424
+ return (length >> 2) * 3 - pad
413
425
  }
414
426
 
415
427
  /**
@@ -434,13 +446,28 @@ export const base64StdPadDecode = (text: string): u8[] | null => {
434
446
  if ((n & 3) !== 0) {
435
447
  return null
436
448
  }
437
- // A length that is a multiple of four and not 0 is at least 4.
438
- let pad: u32 = 0
439
- if (n >= 4 && toI32(text.charCodeAt(n - 1)) === 61) {
449
+ // The empty text spells no bytes; any other length that is a multiple of
450
+ // four is at least 4.
451
+ if (n < 4) {
452
+ return new Array<u8>(0)
453
+ }
454
+ let pad: integer<0, 2> = 0
455
+ if (toI32(text.charCodeAt(n - 1)) === 61) {
440
456
  pad = toI32(text.charCodeAt(n - 2)) === 61 ? 2 : 1
441
457
  }
442
- const chars: i32 = toI32(toU32(n) - pad)
443
- const out: u8[] = new Array<u8>(toU32(n >> 2) * 3 - pad)
458
+ // Three bytes per group before the last, and three less the padding in the
459
+ // last: two `i32`s the bounds prover reads as non-negative, so the
460
+ // allocation is proven rather than checked.
461
+ let last: i32 = 3
462
+ if (pad === 1) {
463
+ last = 2
464
+ }
465
+ if (pad === 2) {
466
+ last = 1
467
+ }
468
+ const whole: i32 = ((n >> 2) - 1) * 3
469
+ const out: u8[] = new Array<u8>(whole + last)
470
+ const chars: i32 = n - pad
444
471
  let bad: i32 = 0
445
472
  let acc: i32 = 0
446
473
  let bits: u32 = 0
@@ -189,38 +189,42 @@ interface BcryptParsed {
189
189
 
190
190
  /**
191
191
  * All ones when `lo <= c <= hi`, else zero, without a branch: the encoding
192
- * reads the digest, which is the stored hash when the password is right. The
193
- * sums are in `u32`, as in `base64urlRangeMask` (std/crypto/base64url.ts), so
194
- * no overflow check branches on them.
192
+ * reads the digest, which is the stored hash when the password is right. As in
193
+ * `base64urlRangeMask` (std/crypto/base64url.ts), `c` is narrowed to the
194
+ * character codes it is, below 2^16, so the compiler proves both subtractions
195
+ * fit; a checked subtraction it could not prove would branch on `c`.
195
196
  */
196
- const bcryptRangeMask = (c: i32, lo: i32, hi: i32): i32 =>
197
- toI32((toU32(lo) - 1 - toU32(c)) & (toU32(c) - toU32(hi) - 1)) >> 31
197
+ const bcryptRangeMask = (c: i32, lo: integer<0, 255>, hi: integer<0, 255>): i32 => {
198
+ const d: i32 = c & 0xffff
199
+ return ((lo - 1 - d) & (d - hi - 1)) >> 31
200
+ }
198
201
 
199
202
  /**
200
- * The bcrypt alphabet's character for the sextet `v`, `./A-Za-z0-9`: `.` + `v`,
201
- * plus the step to each range `v` has reached (2 lands on `A`, 28 on `a`, 54
202
- * on `0`).
203
+ * The bcrypt alphabet's character for the sextet `v` (every caller passes `0 <=
204
+ * v <= 63`; it is masked to six bits, so a wider value aliases): `.` + `v`, plus
205
+ * the step to each range `v` has reached (2 lands on `A`, 28 on `a`, 54 `0`).
203
206
  */
204
- const bcryptCharOf = (v: i32): u8 =>
205
- toU8(
206
- 46 +
207
- toU32(v) +
208
- toU32(bcryptRangeMask(v, 2, 63) & 17) +
209
- toU32(bcryptRangeMask(v, 28, 63) & 6) -
210
- toU32(bcryptRangeMask(v, 54, 63) & 75)
207
+ const bcryptCharOf = (v: i32): u8 => {
208
+ // Narrowed to the sextet it is, so the compiler proves the sum fits.
209
+ const s: i32 = v & 63
210
+ return toU8(
211
+ s +
212
+ 46 +
213
+ (bcryptRangeMask(s, 2, 63) & 17) +
214
+ (bcryptRangeMask(s, 28, 63) & 6) -
215
+ (bcryptRangeMask(s, 54, 63) & 75)
211
216
  )
217
+ }
212
218
 
213
219
  /** The sextet of a bcrypt alphabet character, or -1 for any other byte, without a branch. */
214
- const bcryptSextetOf = (c: i32): i32 => {
220
+ const bcryptSextetOf = (c: integer<0, 65535>): i32 => {
215
221
  const punct: i32 = bcryptRangeMask(c, 46, 47)
216
222
  const upper: i32 = bcryptRangeMask(c, 65, 90)
217
223
  const lower: i32 = bcryptRangeMask(c, 97, 122)
218
224
  const digit: i32 = bcryptRangeMask(c, 48, 57)
219
- const value: i32 =
220
- (punct & toI32(toU32(c) - 46)) |
221
- (upper & toI32(toU32(c) - 63)) |
222
- (lower & toI32(toU32(c) - 69)) |
223
- (digit & toI32(toU32(c) + 6))
225
+ // `c` is a character code, so each offset is proven to fit and no overflow
226
+ // check branches on it.
227
+ const value: i32 = (punct & (c - 46)) | (upper & (c - 63)) | (lower & (c - 69)) | (digit & (c + 6))
224
228
  return value | ~(punct | upper | lower | digit)
225
229
  }
226
230
 
@@ -117,9 +117,6 @@ export const ED25519_PUBLIC_KEY_SIZE: i32 = 32
117
117
  /** The length in bytes of a signature, `R || S`. */
118
118
  export const ED25519_SIGNATURE_SIZE: i32 = 64
119
119
 
120
- /** Where a method call starts reading an array: its first byte. */
121
- const ED25519_FROM: i32 = 0
122
-
123
120
  /** Where the prefix starts in the seed's hash, and how long R, A and a scalar are. */
124
121
  const ED25519_HALF: i32 = 32
125
122
 
@@ -763,7 +760,8 @@ const ed25519ScalarCanonical = (s: u8[]): boolean => {
763
760
  */
764
761
  const ed25519Expand = (seed: u8[]): u8[] => {
765
762
  const hasher = new Sha512()
766
- hasher.update(seed, ED25519_FROM, ED25519_SEED_SIZE)
763
+ // The whole seed: both callers have checked it is ED25519_SEED_SIZE bytes.
764
+ hasher.engine.absorbWhole(seed)
767
765
  const h: u8[] = hasher.digest()
768
766
  ed25519WipeHasher(hasher)
769
767
  // SHA-512's 64 bytes, as a literal the prover reads for h[0] and h[31].
@@ -778,9 +776,11 @@ const ed25519Expand = (seed: u8[]): u8[] => {
778
776
  /** k = SHA-512(R || A || M) mod L (§5.1.6 step 4, §5.1.7 step 2); public. */
779
777
  const ed25519Challenge = (r: u8[], pub: u8[], msg: u8[]): u8[] => {
780
778
  const hasher = new Sha512()
781
- hasher.update(r, ED25519_FROM, ED25519_HALF)
782
- hasher.update(pub, ED25519_FROM, ED25519_HALF)
783
- hasher.update(msg, ED25519_FROM, toI32(msg.length))
779
+ // Each array whole: R and A are 32 bytes, from `ed25519Encode` or checked
780
+ // by `ed25519Verify`, and the message is the whole message signed.
781
+ hasher.engine.absorbWhole(r)
782
+ hasher.engine.absorbWhole(pub)
783
+ hasher.engine.absorbWhole(msg)
784
784
  const k: u8[] = new Array<u8>(32)
785
785
  ed25519Reduce(k, hasher.digest())
786
786
  return k
@@ -848,8 +848,10 @@ const ed25519SignExposed = (seed: u8[], msg: u8[]): u8[] | null => {
848
848
  const pub: u8[] = ed25519Encode(point, s)
849
849
 
850
850
  const nonceHasher = new Sha512()
851
- nonceHasher.update(h, ED25519_HALF, ED25519_HALF)
852
- nonceHasher.update(msg, ED25519_FROM, toI32(msg.length))
851
+ // The prefix, h's upper half: `false` only for an `h` shorter than its 64
852
+ // bytes, answered as `null` once everything is wiped below.
853
+ const prefixFed: boolean = nonceHasher.update(h, ED25519_HALF, ED25519_HALF)
854
+ nonceHasher.engine.absorbWhole(msg)
853
855
  const nonceWide: u8[] = nonceHasher.digest()
854
856
  ed25519WipeHasher(nonceHasher)
855
857
  const nonce: u8[] = new Array<u8>(32)
@@ -868,7 +870,7 @@ const ed25519SignExposed = (seed: u8[], msg: u8[]): u8[] | null => {
868
870
  ed25519WipeScratch(s)
869
871
 
870
872
  const sig: u8[] = new Array<u8>(64)
871
- if (toI32(r.length) < 32 || toI32(sBytes.length) < 32) {
873
+ if (!prefixFed || toI32(r.length) < 32 || toI32(sBytes.length) < 32) {
872
874
  return null
873
875
  }
874
876
  for (let i: i32 = 0; i < 32; i++) {