@amritk/nish-x86_64-linux 0.44.0 → 0.45.1
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/bin/nish +0 -0
- package/docs/AI.md +18 -16
- package/package.json +1 -1
- package/runtime/core/numbers.mjs +3 -1
- package/runtime/core/strings.mjs +90 -38
- package/runtime/core.d.ts +8 -0
- package/runtime/core.mjs +16 -0
- package/runtime/nish.d.ts +47 -5
- package/runtime/nish.mjs +4 -0
- package/std/README.md +3 -3
- package/std/array.ts +10 -2
- package/std/bytes.ts +239 -26
- package/std/cli-args.ts +1072 -606
- package/std/cli-flags.ts +180 -98
- package/std/cli.ts +21 -13
- package/std/collections.ts +245 -127
- package/std/compress/checksum.ts +32 -37
- package/std/compress/deflate.ts +1102 -542
- package/std/compress/gzip.ts +290 -145
- package/std/compress/zlib.ts +57 -21
- package/std/crypto/aes.ts +153 -75
- package/std/crypto/base64url.ts +84 -61
- package/std/crypto/bcrypt-batch.ts +164 -90
- package/std/crypto/bcrypt.ts +185 -107
- package/std/crypto/chacha20poly1305.ts +84 -68
- package/std/crypto/ct.ts +9 -7
- package/std/crypto/ed25519.ts +64 -27
- package/std/crypto/hkdf.ts +105 -63
- package/std/crypto/hmac.ts +95 -89
- package/std/crypto/jwt.ts +248 -126
- package/std/crypto/p256.ts +758 -444
- package/std/crypto/p384.ts +20 -13
- package/std/crypto/pki-roots.ts +95 -38
- package/std/crypto/pki.ts +164 -60
- package/std/crypto/rsa.ts +266 -223
- package/std/crypto/scram.ts +3 -4
- package/std/crypto/sha1.ts +107 -65
- package/std/crypto/sha256.ts +502 -422
- package/std/crypto/sha512.ts +204 -135
- package/std/crypto/x509-random.ts +9 -3
- package/std/crypto/x509.ts +331 -171
- package/std/json-equal.ts +35 -19
- package/std/json-format.ts +215 -108
- package/std/json-number.ts +126 -72
- package/std/json-pointer.ts +42 -13
- package/std/json-tokenizer.ts +498 -307
- package/std/json-typed.ts +115 -36
- package/std/json-value.ts +341 -152
- package/std/json.ts +300 -158
- package/std/net/buffer-pool.ts +17 -7
- package/std/net/dns-config.ts +427 -236
- package/std/net/dns-message.ts +114 -47
- package/std/net/dns-resolver.ts +736 -237
- package/std/net/dns.ts +205 -52
- package/std/net/fetch.ts +320 -184
- package/std/net/grpc.ts +948 -0
- package/std/net/handler.ts +1275 -217
- package/std/net/hpack.ts +395 -180
- package/std/net/http-compress.ts +502 -65
- package/std/net/http-fields.ts +85 -49
- package/std/net/http-server.ts +1764 -602
- package/std/net/http1-client-codec.ts +372 -161
- package/std/net/http1-codec.ts +665 -331
- package/std/net/http1-server.ts +660 -278
- package/std/net/http2-cleartext.ts +165 -95
- package/std/net/http2-frame.ts +232 -89
- package/std/net/http2-tls.ts +42 -12
- package/std/net/http2.ts +327 -101
- package/std/net/http3-frame.ts +68 -33
- package/std/net/http3-server.ts +647 -192
- package/std/net/http3.ts +667 -189
- package/std/net/oidc.ts +63 -24
- package/std/net/outbound.ts +207 -142
- package/std/net/postgres-async.ts +1165 -443
- package/std/net/postgres-carrier.ts +575 -372
- package/std/net/postgres.ts +1459 -559
- package/std/net/prefork.ts +254 -98
- package/std/net/protobuf.ts +1017 -0
- package/std/net/qpack.ts +143 -92
- package/std/net/quic-conn-ack.ts +50 -18
- package/std/net/quic-conn-cid.ts +66 -26
- package/std/net/quic-conn-params.ts +13 -7
- package/std/net/quic-datagram.ts +90 -27
- package/std/net/quic-frame.ts +225 -124
- package/std/net/quic-listener.ts +197 -89
- package/std/net/quic-packet.ts +289 -163
- package/std/net/quic-recovery.ts +279 -128
- package/std/net/quic-stream.ts +466 -167
- package/std/net/quic.ts +568 -257
- package/std/net/router.ts +450 -99
- package/std/net/serve.ts +651 -232
- package/std/net/static.ts +1458 -0
- package/std/net/tls/client.ts +140 -45
- package/std/net/tls/codec.ts +510 -260
- package/std/net/tls/record-client.ts +268 -76
- package/std/net/tls/record-server.ts +236 -79
- package/std/net/tls/record.ts +173 -47
- package/std/net/tls/schedule.ts +58 -39
- package/std/net/tls/ticket.ts +295 -103
- package/std/net/tls/verify.ts +1 -1
- package/std/net/tls-tcp.ts +218 -75
- package/std/net/tls.ts +260 -152
- package/std/net/upstream.ts +283 -86
- package/std/net/url.ts +277 -102
- package/std/net/websocket.ts +370 -186
- package/std/net/webtransport.ts +755 -436
- package/std/regex.ts +1659 -829
- package/std/sync/ring.ts +320 -156
- package/std/sync/shm.ts +53 -6
- package/std/text.ts +205 -124
- package/std/threads.ts +22 -2
package/std/crypto/scram.ts
CHANGED
|
@@ -73,11 +73,10 @@ const scramClientProofExposed = (salted: u8[], authMessage: u8[]): u8[] => {
|
|
|
73
73
|
const clientKey: u8[] = hmacSha256(salted, scramAscii("Client Key"))
|
|
74
74
|
const storedKey: u8[] = scramSha256Wiped(clientKey)
|
|
75
75
|
const clientSignature: u8[] = hmacSha256(storedKey, authMessage)
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
76
|
+
// Both are HMAC-SHA-256 tags, 32 bytes each; the bounds below only let the
|
|
77
|
+
// prover see that, and never stop the loop early.
|
|
79
78
|
const proof: u8[] = new Array<u8>(32)
|
|
80
|
-
for (let i: i32 = 0; i < 32; i++) {
|
|
79
|
+
for (let i: i32 = 0; i < 32 && i < toI32(clientKey.length) && i < toI32(clientSignature.length); i++) {
|
|
81
80
|
proof[i] = clientKey[i] ^ clientSignature[i]
|
|
82
81
|
}
|
|
83
82
|
wipe(clientKey)
|
package/std/crypto/sha1.ts
CHANGED
|
@@ -35,22 +35,21 @@ export const SHA1_BLOCK: i32 = 64
|
|
|
35
35
|
/** ROTL^n(x) of FIPS 180-4 §3.2: a left rotation of a 32-bit word, `0 < n < 32`. */
|
|
36
36
|
const sha1Rotl = (x: u32, n: u32): u32 => (x << n) | (x >>> (32 - n))
|
|
37
37
|
|
|
38
|
-
/** The big-endian word at `buf[at .. at + 4)`, as FIPS 180-4 §3.1 orders bytes in a word. */
|
|
39
|
-
const sha1LoadWord = (buf: u8[], at: i32): u32 =>
|
|
40
|
-
(toU32(buf[at]) << 24) | (toU32(buf[at + 1]) << 16) | (toU32(buf[at + 2]) << 8) | toU32(buf[at + 3])
|
|
41
|
-
|
|
42
38
|
/**
|
|
43
39
|
* Folds the 64-byte block at `src[at .. at + 64)` into `h`: FIPS 180-4
|
|
44
40
|
* §6.1.2, steps 1 to 4. `w` is the 80-word schedule, held by the `Sha1`
|
|
45
|
-
* hasher rather than allocated once per block.
|
|
41
|
+
* hasher rather than allocated once per block. Every caller passes a block
|
|
42
|
+
* inside `src` and the hasher's own `h` and `w`; the conditions below are the
|
|
43
|
+
* shapes that prove each index in range, not checks a caller can fail.
|
|
46
44
|
*/
|
|
47
45
|
const sha1Compress = (h: u32[], w: u32[], src: u8[], at: i32): void => {
|
|
48
|
-
|
|
49
|
-
// plain `w[t]` and `h[i]` indices in range (as `sha256Compress` does).
|
|
50
|
-
if (toI32(h.length) >= 5 && toI32(w.length) >= 80 && at >= 0 && at <= toI32(src.length) - SHA1_BLOCK) {
|
|
46
|
+
if (toI32(h.length) >= 5 && toI32(w.length) >= 80) {
|
|
51
47
|
// Step 1: the message schedule, big-endian words (§3.1), then (6.1.2).
|
|
52
|
-
|
|
53
|
-
|
|
48
|
+
const n: i32 = toI32(src.length)
|
|
49
|
+
let p: i32 = at
|
|
50
|
+
for (let t: i32 = 0; t < 16 && p >= 0 && p < n - 3; t += 1) {
|
|
51
|
+
w[t] = (toU32(src[p]) << 24) | (toU32(src[p + 1]) << 16) | (toU32(src[p + 2]) << 8) | toU32(src[p + 3])
|
|
52
|
+
p += 4
|
|
54
53
|
}
|
|
55
54
|
for (let t: i32 = 16; t < 80; t += 1) {
|
|
56
55
|
w[t] = sha1Rotl(w[t - 3] ^ w[t - 8] ^ w[t - 14] ^ w[t - 16], 1)
|
|
@@ -91,8 +90,56 @@ const sha1Compress = (h: u32[], w: u32[], src: u8[], at: i32): void => {
|
|
|
91
90
|
h[2] += c
|
|
92
91
|
h[3] += d
|
|
93
92
|
h[4] += e
|
|
94
|
-
}
|
|
95
|
-
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** Sets `h` to H^(0) of FIPS 180-4 §5.3.1. */
|
|
97
|
+
const sha1Begin = (h: u32[]): void => {
|
|
98
|
+
if (toI32(h.length) >= 5) {
|
|
99
|
+
h[0] = 0x67452301
|
|
100
|
+
h[1] = 0xefcdab89
|
|
101
|
+
h[2] = 0x98badcfe
|
|
102
|
+
h[3] = 0x10325476
|
|
103
|
+
h[4] = 0xc3d2e1f0
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Finishes a digest whose last `tail` bytes (`0 <= tail < 64`) the caller has
|
|
109
|
+
* copied to `last[0 .. tail)`: pads them (FIPS 180-4 §5.1.1) with the message
|
|
110
|
+
* length of `bits` bits, folds the one or two padded blocks into `h`, and
|
|
111
|
+
* writes the digest to `out[at .. at + 20)`, which the caller has checked.
|
|
112
|
+
*/
|
|
113
|
+
const sha1Finish = (h: u32[], w: u32[], last: u8[], tail: i32, bits: u64, out: u8[], at: i32): void => {
|
|
114
|
+
let lastLength: i32 = 64
|
|
115
|
+
if (tail >= 56) {
|
|
116
|
+
lastLength = 128
|
|
117
|
+
}
|
|
118
|
+
const room: i32 = toI32(last.length)
|
|
119
|
+
// The 0x80 that ends the message, then zeros, then the length big-endian.
|
|
120
|
+
let z: i32 = tail
|
|
121
|
+
while (z >= 0 && z < lastLength && z < room) {
|
|
122
|
+
last[z] = z === tail ? 0x80 : 0
|
|
123
|
+
z += 1
|
|
124
|
+
}
|
|
125
|
+
let k: i32 = lastLength - 8
|
|
126
|
+
let shift: u64 = 56
|
|
127
|
+
for (let i: i32 = 0; i < 8 && k >= 0 && k < room; i += 1) {
|
|
128
|
+
last[k] = toU8(bits >>> shift)
|
|
129
|
+
shift -= 8
|
|
130
|
+
k += 1
|
|
131
|
+
}
|
|
132
|
+
for (let off: i32 = 0; off < lastLength; off += 64) {
|
|
133
|
+
sha1Compress(h, w, last, off)
|
|
134
|
+
}
|
|
135
|
+
let p: i32 = at
|
|
136
|
+
for (let i: i32 = 0; i < 5 && i < toI32(h.length) && p >= 0 && p < toI32(out.length) - 3; i += 1) {
|
|
137
|
+
const word: u32 = h[i]
|
|
138
|
+
out[p] = toU8(word >>> 24)
|
|
139
|
+
out[p + 1] = toU8(word >>> 16)
|
|
140
|
+
out[p + 2] = toU8(word >>> 8)
|
|
141
|
+
out[p + 3] = toU8(word)
|
|
142
|
+
p += 4
|
|
96
143
|
}
|
|
97
144
|
}
|
|
98
145
|
|
|
@@ -117,92 +164,87 @@ export class Sha1 {
|
|
|
117
164
|
constructor() {
|
|
118
165
|
this.h = new Array<u32>(5)
|
|
119
166
|
this.w = new Array<u32>(80)
|
|
120
|
-
this.last = new Array<u8>(
|
|
167
|
+
this.last = new Array<u8>(128)
|
|
121
168
|
}
|
|
122
169
|
|
|
123
170
|
/**
|
|
124
171
|
* Writes the SHA-1 digest of `data[start .. start + length)` into
|
|
125
172
|
* `out[at .. at + 20)`, allocating nothing. A range outside `data` or `out`
|
|
126
|
-
*
|
|
173
|
+
* writes nothing and answers `false`.
|
|
127
174
|
*
|
|
128
175
|
* @param data The buffer holding the message; it is read, not changed.
|
|
129
176
|
* @param start Where in `data` the message starts.
|
|
130
177
|
* @param length How many bytes of `data` the message is.
|
|
131
178
|
* @param out The buffer the 20-byte digest is written into.
|
|
132
179
|
* @param at Where in `out` the digest starts.
|
|
180
|
+
* @returns `true` once the digest is written; `false`, with `out` untouched, when either range lies outside its buffer.
|
|
133
181
|
*/
|
|
134
|
-
digestInto(data: u8[], start: i32, length: i32, out: u8[], at: i32):
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
}
|
|
182
|
+
digestInto(data: u8[], start: i32, length: i32, out: u8[], at: i32): boolean {
|
|
183
|
+
// `toI32` of a length past 2^31 - 1 (under `--number-mode f64`) saturates,
|
|
184
|
+
// which only narrows the ranges accepted here: an `i32` range ends below it.
|
|
138
185
|
if (start < 0 || length < 0 || start > toI32(data.length) - length) {
|
|
139
|
-
|
|
186
|
+
return false
|
|
140
187
|
}
|
|
141
188
|
if (at < 0 || at > toI32(out.length) - SHA1_SIZE) {
|
|
142
|
-
|
|
189
|
+
return false
|
|
143
190
|
}
|
|
144
191
|
const h: u32[] = this.h
|
|
145
192
|
const w: u32[] = this.w
|
|
146
193
|
const last: u8[] = this.last
|
|
147
|
-
|
|
148
|
-
panic("sha1: a hasher without its state")
|
|
149
|
-
}
|
|
150
|
-
// H^(0) of FIPS 180-4 §5.3.1.
|
|
151
|
-
h[0] = 0x67452301
|
|
152
|
-
h[1] = 0xefcdab89
|
|
153
|
-
h[2] = 0x98badcfe
|
|
154
|
-
h[3] = 0x10325476
|
|
155
|
-
h[4] = 0xc3d2e1f0
|
|
194
|
+
sha1Begin(h)
|
|
156
195
|
// Whole blocks straight from `data`, then the tail and its padding (§5.1.1)
|
|
157
196
|
// in one or two blocks of `last`.
|
|
158
|
-
const
|
|
159
|
-
|
|
160
|
-
|
|
197
|
+
const size: i32 = toI32(data.length)
|
|
198
|
+
let off: i32 = start
|
|
199
|
+
let left: i32 = length
|
|
200
|
+
while (left >= 64 && off >= 0 && off <= size - 64) {
|
|
201
|
+
sha1Compress(h, w, data, off)
|
|
202
|
+
off += 64
|
|
203
|
+
left -= 64
|
|
161
204
|
}
|
|
162
|
-
|
|
163
|
-
const lastLength: i32 = tail < SHA1_BLOCK - 8 ? SHA1_BLOCK : 2 * SHA1_BLOCK
|
|
205
|
+
let k: i32 = 0
|
|
164
206
|
const room: i32 = toI32(last.length)
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
last[k] = k < tail ? data[start + whole + k] : 0
|
|
170
|
-
}
|
|
171
|
-
last[tail] = 0x80
|
|
172
|
-
const bits: u64 = toU64(toI64(length)) << 3
|
|
173
|
-
for (let i: i32 = 0; i < 8; i += 1) {
|
|
174
|
-
last[lastLength - 1 - i] = toU8(bits >>> toU64(8 * i))
|
|
175
|
-
}
|
|
176
|
-
for (let off: i32 = 0; off < lastLength; off += SHA1_BLOCK) {
|
|
177
|
-
sha1Compress(h, w, last, off)
|
|
178
|
-
}
|
|
179
|
-
for (let i: i32 = 0; i < 5; i += 1) {
|
|
180
|
-
const word: u32 = h[i]
|
|
181
|
-
out[at + 4 * i] = toU8(word >>> 24)
|
|
182
|
-
out[at + 4 * i + 1] = toU8(word >>> 16)
|
|
183
|
-
out[at + 4 * i + 2] = toU8(word >>> 8)
|
|
184
|
-
out[at + 4 * i + 3] = toU8(word)
|
|
207
|
+
while (k < left && k < room && off >= 0 && off < size) {
|
|
208
|
+
last[k] = data[off]
|
|
209
|
+
k += 1
|
|
210
|
+
off += 1
|
|
185
211
|
}
|
|
212
|
+
sha1Finish(h, w, last, k, toU64(toI64(length)) << 3, out, at)
|
|
213
|
+
return true
|
|
186
214
|
}
|
|
187
215
|
}
|
|
188
216
|
|
|
189
217
|
/**
|
|
190
|
-
* The SHA-1 digest of all of `data`, as a fresh 20-byte array
|
|
191
|
-
* `digestInto` over the whole of it, with a hasher of its own.
|
|
218
|
+
* The SHA-1 digest of all of `data`, as a fresh 20-byte array.
|
|
192
219
|
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
220
|
+
* It walks `data` with a `number` offset and copies each block into the
|
|
221
|
+
* hasher's own buffer, so an array longer than 2^31 - 1 bytes (possible under
|
|
222
|
+
* `--number-mode f64`) is hashed whole, never cut to a prefix.
|
|
196
223
|
*
|
|
197
224
|
* @param data The whole message; it is read, not changed.
|
|
198
225
|
* @returns A fresh 20-byte digest.
|
|
199
226
|
*/
|
|
200
227
|
export const sha1 = (data: u8[]): u8[] => {
|
|
201
|
-
if (data.length > 2147483647) {
|
|
202
|
-
panic("sha1: a message longer than 2^31 - 1 bytes")
|
|
203
|
-
}
|
|
204
228
|
const out: u8[] = new Array<u8>(SHA1_SIZE)
|
|
205
|
-
const
|
|
206
|
-
|
|
207
|
-
|
|
229
|
+
const hasher: Sha1 = new Sha1()
|
|
230
|
+
const h: u32[] = hasher.h
|
|
231
|
+
const w: u32[] = hasher.w
|
|
232
|
+
const last: u8[] = hasher.last
|
|
233
|
+
const room: i32 = toI32(last.length)
|
|
234
|
+
sha1Begin(h)
|
|
235
|
+
const n: number = data.length
|
|
236
|
+
let off: number = 0
|
|
237
|
+
while (true) {
|
|
238
|
+
let k: i32 = 0
|
|
239
|
+
while (k < SHA1_BLOCK && k < room && off >= 0 && off < n) {
|
|
240
|
+
last[k] = data[off]
|
|
241
|
+
k += 1
|
|
242
|
+
off += 1
|
|
243
|
+
}
|
|
244
|
+
if (k < SHA1_BLOCK) {
|
|
245
|
+
sha1Finish(h, w, last, k, toU64(toI64(n)) << 3, out, 0)
|
|
246
|
+
return out
|
|
247
|
+
}
|
|
248
|
+
sha1Compress(h, w, last, 0)
|
|
249
|
+
}
|
|
208
250
|
}
|