@amritk/nish-aarch64-linux 0.35.0 → 0.37.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 +73 -59
- package/bin/nish +0 -0
- package/docs/AI.md +50 -4
- package/package.json +1 -1
- package/runtime/async.d.mts +2 -0
- package/runtime/async.mjs +7 -0
- package/runtime/nish.d.ts +4849 -430
- package/runtime/nish.h +25 -0
- package/runtime/page.d.ts +53 -0
- package/runtime/page.mjs +146 -0
- package/runtime/runtime-async.c +557 -0
- package/runtime/runtime-wasm.c +63 -7
- package/runtime/vite.d.ts +30 -0
- package/runtime/vite.mjs +150 -0
- package/scripts/build.sh +252 -15
- package/std/README.md +107 -82
- package/std/base64.ts +34 -5
- package/std/bytes.ts +279 -59
- package/std/cli-args.ts +296 -70
- package/std/cli-flags.ts +184 -19
- package/std/cli.ts +475 -54
- package/std/collections.ts +121 -23
- package/std/compress/checksum.ts +44 -14
- package/std/compress/deflate.ts +224 -111
- package/std/compress/gzip.ts +217 -53
- package/std/compress/zlib.ts +63 -7
- package/std/crypto/aes.ts +128 -52
- package/std/crypto/base64url.ts +29 -5
- package/std/crypto/bcrypt-batch.ts +101 -34
- package/std/crypto/bcrypt.ts +93 -27
- package/std/crypto/chacha20poly1305.ts +69 -14
- package/std/crypto/ct.ts +32 -13
- package/std/crypto/ed25519.ts +66 -16
- package/std/crypto/hkdf.ts +198 -13
- package/std/crypto/hmac.ts +242 -37
- package/std/crypto/jwt.ts +204 -72
- package/std/crypto/p256.ts +222 -72
- package/std/crypto/p384.ts +51 -23
- package/std/crypto/pki-roots.ts +32 -2
- package/std/crypto/pki.ts +99 -30
- package/std/crypto/rsa.ts +56 -22
- package/std/crypto/sha1.ts +3 -0
- package/std/crypto/sha256.ts +24 -1
- package/std/crypto/sha512.ts +99 -14
- package/std/crypto/x25519.ts +163 -24
- package/std/crypto/x509-random.ts +10 -0
- package/std/crypto/x509.ts +133 -66
- package/std/host/ring.ts +124 -0
- package/std/json-equal.ts +31 -11
- package/std/json-format.ts +112 -13
- package/std/json-number.ts +76 -26
- package/std/json-pointer.ts +23 -1
- package/std/json-tokenizer.ts +126 -51
- package/std/json-typed.ts +757 -96
- package/std/json-value.ts +438 -157
- package/std/json.ts +170 -38
- package/std/map.ts +25 -7
- package/std/math.ts +36 -4
- package/std/net/buffer-pool.ts +42 -11
- package/std/net/dns-config.ts +109 -23
- package/std/net/dns-message.ts +62 -7
- package/std/net/dns-resolver.ts +247 -53
- package/std/net/dns.ts +203 -35
- package/std/net/fetch.ts +1267 -290
- package/std/net/handler.ts +296 -80
- package/std/net/hpack.ts +290 -77
- package/std/net/http-compress.ts +152 -36
- package/std/net/http-fields.ts +85 -9
- package/std/net/http1-client-codec.ts +129 -44
- package/std/net/http1-codec.ts +279 -114
- package/std/net/http1-server.ts +409 -139
- package/std/net/http2-frame.ts +289 -51
- package/std/net/http2-tls.ts +152 -49
- package/std/net/http2.ts +314 -160
- package/std/net/http3-frame.ts +165 -27
- package/std/net/http3-server.ts +282 -131
- package/std/net/http3.ts +377 -173
- package/std/net/outbound.ts +37 -3
- package/std/net/postgres-carrier.ts +144 -8
- package/std/net/postgres.ts +898 -260
- package/std/net/prefork.ts +202 -65
- package/std/net/qpack.ts +120 -32
- package/std/net/quic-conn-ack.ts +60 -12
- package/std/net/quic-conn-cid.ts +135 -27
- package/std/net/quic-conn-params.ts +109 -22
- package/std/net/quic-datagram.ts +50 -3
- package/std/net/quic-frame.ts +333 -23
- package/std/net/quic-listener.ts +161 -75
- package/std/net/quic-packet.ts +373 -73
- package/std/net/quic-recovery.ts +287 -65
- package/std/net/quic-stream.ts +436 -146
- package/std/net/quic.ts +693 -323
- package/std/net/router.ts +87 -40
- package/std/net/tls/client.ts +167 -51
- package/std/net/tls/codec.ts +494 -68
- package/std/net/tls/record-client.ts +140 -73
- package/std/net/tls/record-server.ts +233 -105
- package/std/net/tls/record.ts +142 -36
- package/std/net/tls/schedule.ts +235 -26
- package/std/net/tls/ticket.ts +161 -40
- package/std/net/tls/verify.ts +57 -10
- package/std/net/tls-tcp.ts +308 -95
- package/std/net/tls.ts +276 -102
- package/std/net/upstream.ts +81 -45
- package/std/net/url.ts +109 -22
- package/std/net/websocket.ts +140 -26
- package/std/net/webtransport.ts +243 -106
- package/std/pair.ts +10 -2
- package/std/random.ts +42 -15
- package/std/regex.ts +422 -257
- package/std/region.ts +70 -15
- package/std/secret.ts +52 -11
- package/std/sort.ts +17 -2
- package/std/sqlite.ts +256 -35
- package/std/sync/ring.ts +229 -56
- package/std/sync/shm.ts +203 -23
- package/std/term-io.ts +154 -78
- package/std/term-pixels.ts +144 -19
- package/std/term-probe.ts +77 -35
- package/std/term-rate.ts +199 -118
- package/std/term.ts +400 -175
- package/std/testing.ts +130 -32
- package/std/text.ts +84 -17
- package/std/threads.ts +248 -56
- package/std/yaml-json.ts +111 -97
- package/std/yaml-lines.ts +47 -15
- package/std/yaml-write.ts +45 -30
- package/std/yaml.ts +764 -384
package/std/crypto/hmac.ts
CHANGED
|
@@ -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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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
|
-
/**
|
|
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")
|
|
@@ -783,13 +934,22 @@ const pbkdf2HmacSha256Exposed = (password: u8[], request: Pbkdf2Request): u8[] |
|
|
|
783
934
|
* Bad input answers `null` and never panics: an iteration count or a length
|
|
784
935
|
* below 1, or a password or salt longer than 2^31 - 1 bytes. The password is
|
|
785
936
|
* read only inside `exposeWith`, and every U_j, every T_i, both keyed hashers
|
|
786
|
-
* and the working one are wiped before the key is answered; the digests on
|
|
787
|
-
*
|
|
937
|
+
* and the working one are wiped before the key is answered; the digests on the
|
|
938
|
+
* way are wiped in the call that made them. The time taken depends on
|
|
788
939
|
* `iterations`, `dkLen` and the password's length past a block, all of which
|
|
789
|
-
* RFC 8018 treats as public, and on nothing of the password's bytes.
|
|
790
|
-
*
|
|
791
|
-
*
|
|
792
|
-
*
|
|
940
|
+
* RFC 8018 treats as public, and on nothing of the password's bytes.
|
|
941
|
+
*
|
|
942
|
+
* The time is linear in `iterations` and nothing here bounds it, so a caller
|
|
943
|
+
* that takes the count from an untrusted peer (a SCRAM server's `i=`) must cap
|
|
944
|
+
* it first: 2^31 - 1 rounds is about 2^32 compressions.
|
|
945
|
+
*
|
|
946
|
+
* @param password The password P, read only inside `exposeWith`; the caller
|
|
947
|
+
* still owns and wipes it.
|
|
948
|
+
* @param salt The salt S, public.
|
|
949
|
+
* @param iterations The round count `c`; below 1 answers `null`.
|
|
950
|
+
* @param length The derived key's length `dkLen` in bytes; below 1 answers
|
|
951
|
+
* `null`.
|
|
952
|
+
* @returns The derived key, which the caller wipes, or `null` for bad input.
|
|
793
953
|
*/
|
|
794
954
|
export const pbkdf2HmacSha256 = (
|
|
795
955
|
password: Secret<u8[]>,
|
|
@@ -923,27 +1083,53 @@ const hmacMidstates512 = (out: u64[], inner: u64[], outer: u64[]): void => {
|
|
|
923
1083
|
* therefore used by one computation at a time, as a `Sha256` is.
|
|
924
1084
|
*/
|
|
925
1085
|
export class HmacKey {
|
|
926
|
-
/**
|
|
1086
|
+
/**
|
|
1087
|
+
* Words 0 to 7: the keyed inner chaining value; 8 to 15: the keyed outer one.
|
|
1088
|
+
*
|
|
1089
|
+
* @internal Read by `hmacKeyedInto`, `hmacKeyedVerify` and their helpers.
|
|
1090
|
+
*/
|
|
927
1091
|
readonly pads: Secret<u64[]>
|
|
928
|
-
/**
|
|
1092
|
+
/**
|
|
1093
|
+
* SHA-256's work hashers; idle and wiped between tags.
|
|
1094
|
+
*
|
|
1095
|
+
* @internal Read by `hmacKeyedInto`, `hmacKeyedVerify` and their helpers.
|
|
1096
|
+
*/
|
|
929
1097
|
readonly inner256: Sha256
|
|
1098
|
+
/** @internal Read by `hmacKeyedInto`, `hmacKeyedVerify` and their helpers. */
|
|
930
1099
|
readonly outer256: Sha256
|
|
931
1100
|
/**
|
|
932
1101
|
* SHA-384's and SHA-512's work hashers: SHA-384 is SHA-512's compression
|
|
933
1102
|
* from another start, cut to 48 bytes, so resumed from a chaining value the
|
|
934
1103
|
* two are one hasher and differ only in the digest length taken.
|
|
1104
|
+
*
|
|
1105
|
+
* @internal Read by `hmacKeyedInto`, `hmacKeyedVerify` and their helpers.
|
|
935
1106
|
*/
|
|
936
1107
|
readonly inner512: Sha512
|
|
1108
|
+
/** @internal Read by `hmacKeyedInto`, `hmacKeyedVerify` and their helpers. */
|
|
937
1109
|
readonly outer512: Sha512
|
|
938
|
-
/**
|
|
1110
|
+
/**
|
|
1111
|
+
* `HMAC_SHA256`, `HMAC_SHA384` or `HMAC_SHA512`.
|
|
1112
|
+
*
|
|
1113
|
+
* @internal Read by `hmacKeyedInto`, `hmacKeyedVerify` and their helpers.
|
|
1114
|
+
*/
|
|
939
1115
|
readonly hash: i32
|
|
940
1116
|
/**
|
|
941
1117
|
* Whether the key still MACs: `wipe()` clears it. A wiped key's chaining
|
|
942
1118
|
* values are zeros anyone can resume from, so a tag under them proves
|
|
943
1119
|
* nothing and none is computed.
|
|
1120
|
+
*
|
|
1121
|
+
* @internal Read by `hmacKeyedInto`, `hmacKeyedVerify` and their helpers.
|
|
944
1122
|
*/
|
|
945
1123
|
live: boolean
|
|
946
1124
|
|
|
1125
|
+
/**
|
|
1126
|
+
* Absorbs `key`'s two pad blocks for `hash` and keeps the chaining values. An
|
|
1127
|
+
* unknown `hash` panics.
|
|
1128
|
+
*
|
|
1129
|
+
* @param hash Which HMAC: `HMAC_SHA256`, `HMAC_SHA384` or `HMAC_SHA512`.
|
|
1130
|
+
* @param key The key, read only inside `exposeWith`; the caller still owns
|
|
1131
|
+
* and wipes it.
|
|
1132
|
+
*/
|
|
947
1133
|
constructor(hash: i32, key: Secret<u8[]>) {
|
|
948
1134
|
if (hmacTagSize(hash) === 0) {
|
|
949
1135
|
panic("HmacKey: an unknown hash")
|
|
@@ -961,7 +1147,11 @@ export class HmacKey {
|
|
|
961
1147
|
this.live = true
|
|
962
1148
|
}
|
|
963
1149
|
|
|
964
|
-
/**
|
|
1150
|
+
/**
|
|
1151
|
+
* The tag length in bytes.
|
|
1152
|
+
*
|
|
1153
|
+
* @returns 32 for `HMAC_SHA256`, 48 for `HMAC_SHA384`, 64 for `HMAC_SHA512`.
|
|
1154
|
+
*/
|
|
965
1155
|
size(): i32 {
|
|
966
1156
|
return hmacTagSize(this.hash)
|
|
967
1157
|
}
|
|
@@ -1052,6 +1242,13 @@ const hmacKeyedTag = (key: HmacKey, data: u8[], off: i32, len: i32): u8[] => {
|
|
|
1052
1242
|
* `out[at .. at + key.size())`. A window outside its array panics before
|
|
1053
1243
|
* anything is read. It runs in an arena block of its own and stores nothing,
|
|
1054
1244
|
* so a tag leaves the arena where it was.
|
|
1245
|
+
*
|
|
1246
|
+
* @param key The absorbed key; a wiped one panics.
|
|
1247
|
+
* @param data The buffer holding the message.
|
|
1248
|
+
* @param off Where the message starts in `data`.
|
|
1249
|
+
* @param len The message's length in bytes.
|
|
1250
|
+
* @param out The caller's array the tag is written into.
|
|
1251
|
+
* @param at Where the tag starts in `out`.
|
|
1055
1252
|
*/
|
|
1056
1253
|
export const hmacKeyedInto = (key: HmacKey, data: u8[], off: i32, len: i32, out: u8[], at: i32): void => {
|
|
1057
1254
|
const size: i32 = key.size()
|
|
@@ -1078,6 +1275,14 @@ export const hmacKeyedInto = (key: HmacKey, data: u8[], off: i32, len: i32, out:
|
|
|
1078
1275
|
* computed tag wiped, since it is the one tag a forger needs. A tag window
|
|
1079
1276
|
* that does not fit answers `false`; a message window outside its array
|
|
1080
1277
|
* panics. It runs in an arena block of its own and stores nothing.
|
|
1278
|
+
*
|
|
1279
|
+
* @param key The absorbed key; a wiped one answers `false`.
|
|
1280
|
+
* @param data The buffer holding the message.
|
|
1281
|
+
* @param off Where the message starts in `data`.
|
|
1282
|
+
* @param len The message's length in bytes.
|
|
1283
|
+
* @param tag The buffer holding the tag to check.
|
|
1284
|
+
* @param tagAt Where the tag starts in `tag`.
|
|
1285
|
+
* @returns `true` only if the tag window holds the correct tag.
|
|
1081
1286
|
*/
|
|
1082
1287
|
export const hmacKeyedVerify = (
|
|
1083
1288
|
key: HmacKey,
|