@amritk/nish-x86_64-linux 0.18.0 → 0.21.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/INSTALL.md +58 -28
- package/bin/nish +0 -0
- package/docs/AI.md +2759 -0
- package/package.json +3 -2
- package/runtime/browser.d.ts +14 -0
- package/runtime/browser.mjs +88 -0
- package/runtime/core/arrays.d.ts +18 -0
- package/runtime/core/arrays.mjs +125 -0
- package/runtime/core/checks.mjs +20 -0
- package/runtime/core/host.d.ts +70 -0
- package/runtime/core/host.mjs +311 -0
- package/runtime/core/numbers.d.ts +53 -0
- package/runtime/core/numbers.mjs +316 -0
- package/runtime/core/result.d.ts +41 -0
- package/runtime/core/result.mjs +127 -0
- package/runtime/core/strings.d.ts +14 -0
- package/runtime/core/strings.mjs +169 -0
- package/runtime/core.d.ts +9 -0
- package/runtime/core.mjs +55 -0
- package/runtime/host.d.ts +6 -0
- package/runtime/nish.d.ts +99 -5
- package/runtime/nish.h +289 -19
- package/runtime/nish.mjs +39 -3
- package/runtime/node.mjs +383 -0
- package/runtime/runtime-aes.c +490 -0
- package/runtime/runtime-bytes.c +401 -0
- package/runtime/runtime-cross.c +366 -0
- package/runtime/runtime-host.c +8 -7
- package/runtime/runtime-net.c +93 -34
- package/runtime/runtime-os.c +214 -16
- package/runtime/runtime-parallel.c +590 -107
- package/runtime/runtime-simd.c +235 -11
- package/runtime/runtime-term.c +504 -0
- package/runtime/runtime-wasm.c +5 -14
- package/runtime/runtime.c +257 -17
- package/runtime/shim.mjs +6 -915
- package/runtime/sqlite/LICENSE.md +85 -0
- package/runtime/sqlite/README.md +45 -0
- package/runtime/sqlite/nish-sqlite.c +359 -0
- package/runtime/sqlite/sqlite3.c +271131 -0
- package/runtime/sqlite/sqlite3.h +14447 -0
- package/scripts/build.sh +437 -28
- package/std/LICENSE-fast-float +23 -0
- package/std/LICENSE-fdlibm +8 -0
- package/std/README.md +108 -58
- package/std/base64.ts +116 -0
- package/std/bytes.ts +419 -0
- package/std/cli.ts +328 -0
- package/std/collections.ts +6 -5
- package/std/crypto/LICENSE-crypt_blowfish +26 -0
- package/std/crypto/LICENSE-libsecp256k1 +19 -0
- package/std/crypto/aes.ts +238 -76
- package/std/crypto/base64url.ts +125 -0
- package/std/crypto/bcrypt.ts +760 -0
- package/std/crypto/chacha20poly1305.ts +43 -9
- package/std/crypto/ed25519.ts +840 -0
- package/std/crypto/hkdf.ts +304 -12
- package/std/crypto/hmac.ts +382 -54
- package/std/crypto/p256.ts +932 -61
- package/std/crypto/x25519.ts +55 -37
- package/std/crypto/x509-random.ts +71 -0
- package/std/crypto/x509.ts +20 -131
- package/std/json-tokenizer.ts +4237 -0
- package/std/json-typed.ts +1014 -0
- package/std/json-value.ts +1182 -0
- package/std/json.ts +1202 -34
- package/std/math.ts +608 -0
- package/std/net/buffer-pool.ts +151 -0
- package/std/net/hpack.ts +416 -112
- package/std/net/http-fields.ts +93 -0
- package/std/net/http1-server.ts +501 -62
- package/std/net/http1.ts +31 -6
- package/std/net/http2-tls.ts +112 -24
- package/std/net/http2.ts +333 -75
- package/std/net/http3-server.ts +261 -43
- package/std/net/http3.ts +187 -28
- package/std/net/postgres.ts +1875 -0
- package/std/net/prefork.ts +412 -0
- package/std/net/quic-listener.ts +108 -11
- package/std/net/quic-packet.ts +243 -82
- package/std/net/quic-recovery.ts +361 -30
- package/std/net/quic-stream.ts +424 -24
- package/std/net/quic.ts +519 -167
- package/std/net/router.ts +676 -0
- package/std/net/tls/codec.ts +426 -27
- package/std/net/tls/record-server.ts +478 -132
- package/std/net/tls/record.ts +133 -42
- package/std/net/tls/schedule.ts +464 -55
- package/std/net/tls/ticket.ts +610 -0
- package/std/net/tls-tcp.ts +196 -53
- package/std/net/tls.ts +1018 -260
- package/std/net/url.ts +571 -0
- package/std/random.ts +94 -0
- package/std/regex.ts +4274 -0
- package/std/sqlite.ts +391 -0
- package/std/term-io.ts +978 -0
- package/std/term-pixels.ts +874 -0
- package/std/term-probe.ts +459 -0
- package/std/term-rate.ts +993 -0
- package/std/term.ts +2453 -0
- package/std/text.ts +90 -7
- package/std/threads.ts +438 -14
- package/std/yaml-lines.ts +141 -0
- package/std/yaml.ts +4675 -0
|
@@ -22,6 +22,14 @@
|
|
|
22
22
|
* array so that the words stay in registers, and, as RFC 8439 §3 suggests,
|
|
23
23
|
* the state is built once per message and only its counter moves per block.
|
|
24
24
|
*
|
|
25
|
+
* **What is wiped.** Every array a call fills from the key — the ChaCha20
|
|
26
|
+
* state, the keystream block, the Poly1305 one-time key, its `r` and the
|
|
27
|
+
* accumulator, and on open the tag computed for comparison — is zeroed with
|
|
28
|
+
* `wipe`'s volatile stores before the call returns, on the refusal path too,
|
|
29
|
+
* so that no optimiser can drop the zeroing of an array about to die. The
|
|
30
|
+
* caller's own key, and the words the rounds keep in registers, are not this
|
|
31
|
+
* module's to reach.
|
|
32
|
+
*
|
|
25
33
|
* **Poly1305** keeps its accumulator and its key `r` as five limbs of 26 bits
|
|
26
34
|
* each in `u64`, so limb `i` holds bits `26i` to `26i + 25` of a 130-bit
|
|
27
35
|
* number. RFC 8439 §3 asks for constant-time arithmetic without saying how;
|
|
@@ -54,6 +62,8 @@
|
|
|
54
62
|
* namespace (`docs/wp26-stdlib.md` §3e).
|
|
55
63
|
*/
|
|
56
64
|
|
|
65
|
+
import { wipe } from "nish:secret"
|
|
66
|
+
|
|
57
67
|
/** The length of a ChaCha20 key in bytes (RFC 8439 §2.3). */
|
|
58
68
|
export const CHACHA20_KEY_SIZE: i32 = 32
|
|
59
69
|
|
|
@@ -240,7 +250,8 @@ const chacha20Core = (state: u32[], out: u32[]): void => {
|
|
|
240
250
|
* `dst[dstAt + i] = src[srcAt + i] ^ keystream` for `len` bytes, the keystream
|
|
241
251
|
* running from `state`'s counter on, and the counter left one past the last
|
|
242
252
|
* block used (RFC 8439 §2.4). The caller has checked every window and that
|
|
243
|
-
* the counter does not wrap.
|
|
253
|
+
* the counter does not wrap. The last keystream block is wiped before it
|
|
254
|
+
* returns; `state` is the caller's to wipe.
|
|
244
255
|
*/
|
|
245
256
|
const chacha20XorInto = (state: u32[], src: u8[], srcAt: i32, len: i32, dst: u8[], dstAt: i32): void => {
|
|
246
257
|
const keystream: u32[] = new Array<u32>(16)
|
|
@@ -266,6 +277,7 @@ const chacha20XorInto = (state: u32[], src: u8[], srcAt: i32, len: i32, dst: u8[
|
|
|
266
277
|
}
|
|
267
278
|
done = done + take
|
|
268
279
|
}
|
|
280
|
+
wipe(keystream)
|
|
269
281
|
}
|
|
270
282
|
|
|
271
283
|
/**
|
|
@@ -329,7 +341,9 @@ export const chacha20Block = (key: u8[], counter: u32, nonce: u8[]): u8[] | null
|
|
|
329
341
|
return null
|
|
330
342
|
}
|
|
331
343
|
const out: u8[] = new Array<u8>(CHACHA20_BLOCK_SIZE)
|
|
332
|
-
|
|
344
|
+
const state: u32[] = chacha20State(key, counter, nonce, 0)
|
|
345
|
+
chacha20XorInto(state, out, 0, CHACHA20_BLOCK_SIZE, out, 0)
|
|
346
|
+
wipe(state)
|
|
333
347
|
return out
|
|
334
348
|
}
|
|
335
349
|
|
|
@@ -350,7 +364,9 @@ export const chacha20 = (key: u8[], counter: u32, nonce: u8[], data: u8[]): u8[]
|
|
|
350
364
|
return null
|
|
351
365
|
}
|
|
352
366
|
const out: u8[] = new Array<u8>(len)
|
|
353
|
-
|
|
367
|
+
const state: u32[] = chacha20State(key, counter, nonce, 0)
|
|
368
|
+
chacha20XorInto(state, data, 0, len, out, 0)
|
|
369
|
+
wipe(state)
|
|
354
370
|
return out
|
|
355
371
|
}
|
|
356
372
|
|
|
@@ -566,6 +582,8 @@ export const poly1305 = (key: u8[], msg: u8[]): u8[] | null => {
|
|
|
566
582
|
poly1305Absorb(h, r, msg, 0, toI32(msg.length), false)
|
|
567
583
|
const tag: u8[] = new Array<u8>(POLY1305_TAG_SIZE)
|
|
568
584
|
poly1305Finish(h, key, tag)
|
|
585
|
+
wipe(h)
|
|
586
|
+
wipe(r)
|
|
569
587
|
return tag
|
|
570
588
|
}
|
|
571
589
|
|
|
@@ -579,7 +597,10 @@ export const poly1305KeyGen = (key: u8[], nonce: u8[]): u8[] | null => {
|
|
|
579
597
|
if (toI32(key.length) !== CHACHA20_KEY_SIZE || toI32(nonce.length) !== CHACHA20POLY1305_NONCE_SIZE) {
|
|
580
598
|
return null
|
|
581
599
|
}
|
|
582
|
-
|
|
600
|
+
const state: u32[] = chacha20State(key, 0, nonce, 0)
|
|
601
|
+
const polyKey: u8[] = chacha20Poly1305Setup(state)
|
|
602
|
+
wipe(state)
|
|
603
|
+
return polyKey
|
|
583
604
|
}
|
|
584
605
|
|
|
585
606
|
/**
|
|
@@ -602,6 +623,8 @@ const chacha20Poly1305Tag = (polyKey: u8[], aad: u8[], ct: u8[], at: i32, len: i
|
|
|
602
623
|
poly1305Block(h, r, lengths, 0, toU64(POLY1305_HIGH_BIT))
|
|
603
624
|
const tag: u8[] = new Array<u8>(POLY1305_TAG_SIZE)
|
|
604
625
|
poly1305Finish(h, polyKey, tag)
|
|
626
|
+
wipe(h)
|
|
627
|
+
wipe(r)
|
|
605
628
|
return tag
|
|
606
629
|
}
|
|
607
630
|
|
|
@@ -664,6 +687,8 @@ export const chacha20Poly1305Seal = (key: u8[], nonce: u8[], aad: u8[], plaintex
|
|
|
664
687
|
for (let i: i32 = 0; i < toI32(tag.length); i++) {
|
|
665
688
|
sealed[len + i] = tag[i]
|
|
666
689
|
}
|
|
690
|
+
wipe(state)
|
|
691
|
+
wipe(polyKey)
|
|
667
692
|
return sealed
|
|
668
693
|
}
|
|
669
694
|
|
|
@@ -694,11 +719,18 @@ export const chacha20Poly1305Open = (key: u8[], nonce: u8[], aad: u8[], sealed:
|
|
|
694
719
|
const tag: u8[] = chacha20Poly1305Tag(polyKey, aad, sealed, 0, len)
|
|
695
720
|
// The one branch on the comparison, and it is on the answer the caller is
|
|
696
721
|
// about to learn anyway.
|
|
697
|
-
|
|
698
|
-
|
|
722
|
+
const match: u32 = chacha20Poly1305TagMatch(tag, sealed, len)
|
|
723
|
+
wipe(polyKey)
|
|
724
|
+
wipe(tag)
|
|
725
|
+
let plaintext: u8[] | null = null
|
|
726
|
+
if (match !== 0) {
|
|
727
|
+
const opened: u8[] = new Array<u8>(len)
|
|
728
|
+
chacha20XorInto(state, sealed, 0, len, opened, 0)
|
|
729
|
+
plaintext = opened
|
|
699
730
|
}
|
|
700
|
-
|
|
701
|
-
|
|
731
|
+
// One wipe both paths reach, rather than one on each, so that each is a
|
|
732
|
+
// store of its own the -O2 count can see go missing.
|
|
733
|
+
wipe(state)
|
|
702
734
|
return plaintext
|
|
703
735
|
}
|
|
704
736
|
|
|
@@ -714,6 +746,8 @@ export const chacha20HeaderMask = (hpKey: u8[], sample: u8[]): u8[] | null => {
|
|
|
714
746
|
return null
|
|
715
747
|
}
|
|
716
748
|
const mask: u8[] = new Array<u8>(CHACHA20_HEADER_MASK_SIZE)
|
|
717
|
-
|
|
749
|
+
const state: u32[] = chacha20State(hpKey, chacha20Word(sample, 0), sample, 4)
|
|
750
|
+
chacha20XorInto(state, mask, 0, 5, mask, 0)
|
|
751
|
+
wipe(state)
|
|
718
752
|
return mask
|
|
719
753
|
}
|