@amritk/nish-x86_64-linux 0.14.0 → 0.16.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 +15 -6
- package/bin/nish +0 -0
- package/package.json +1 -1
- package/runtime/nish.d.ts +91 -0
- package/runtime/nish.h +97 -5
- package/runtime/nish.mjs +23 -0
- package/runtime/runtime-host.c +29 -2
- package/runtime/runtime-net.c +534 -0
- package/runtime/runtime-os.c +77 -37
- package/runtime/runtime-parallel.c +5 -1
- package/runtime/runtime-wasm.c +25 -2
- package/runtime/runtime.c +40 -6
- package/runtime/shim.mjs +15 -0
- package/scripts/build.sh +8 -7
- package/std/README.md +88 -23
- package/std/crypto/LICENSE-bearssl +21 -0
- package/std/crypto/LICENSE-fiat-crypto +21 -0
- package/std/crypto/aes.ts +939 -0
- package/std/crypto/base64url.ts +18 -5
- package/std/crypto/chacha20poly1305.ts +705 -0
- package/std/crypto/ct.ts +8 -2
- package/std/crypto/hkdf.ts +21 -5
- package/std/crypto/hmac.ts +18 -2
- package/std/crypto/p256.ts +4342 -0
- package/std/crypto/sha256.ts +12 -1
- package/std/crypto/sha512.ts +16 -2
- package/std/crypto/x25519.ts +26 -10
- package/std/crypto/x509.ts +1331 -0
package/std/crypto/ct.ts
CHANGED
|
@@ -23,12 +23,18 @@
|
|
|
23
23
|
*
|
|
24
24
|
* Arrays of different lengths answer `false` at once, because a length is
|
|
25
25
|
* public; arrays of one length are compared in full, with no early exit.
|
|
26
|
+
*
|
|
27
|
+
* The lengths are compared as the `number`s they are, before any `toI32`:
|
|
28
|
+
* under `--number-mode f64` `toI32` saturates at 2^31 - 1, so two arrays past
|
|
29
|
+
* it would have looked the same length and been compared only that far. An
|
|
30
|
+
* array longer than that answers `false` too — no `i32` index reaches its end,
|
|
31
|
+
* and a compare that cannot read every byte must not say "equal".
|
|
26
32
|
*/
|
|
27
33
|
export const timingSafeEqual = (a: u8[], b: u8[]): boolean => {
|
|
28
|
-
|
|
29
|
-
if (n !== toI32(b.length)) {
|
|
34
|
+
if (a.length !== b.length || a.length > 2147483647) {
|
|
30
35
|
return false
|
|
31
36
|
}
|
|
37
|
+
const n: i32 = toI32(a.length)
|
|
32
38
|
let diff: i32 = 0
|
|
33
39
|
// Bounded by both lengths, which are equal here, so the prover drops both
|
|
34
40
|
// bounds checks rather than trusting the comparison above.
|
package/std/crypto/hkdf.ts
CHANGED
|
@@ -16,7 +16,11 @@
|
|
|
16
16
|
* The counter `i` is one byte, so `L` is at most 255 × HashLen (§2.3): 8160
|
|
17
17
|
* bytes for SHA-256 and 12240 for SHA-384. A longer `L`, or a negative one,
|
|
18
18
|
* answers `null` rather than panicking, because `L` usually comes from a
|
|
19
|
-
* protocol field; `L = 0` answers an empty array.
|
|
19
|
+
* protocol field; `L = 0` answers an empty array. So does an `info` longer
|
|
20
|
+
* than 2^31 - 1 bytes, which `toI32` would cut to a prefix under
|
|
21
|
+
* `--number-mode f64`, so that two `info`s sharing it gave one key, and a PRK
|
|
22
|
+
* shorter than HashLen, which §2.3 does not allow: an empty one is a key
|
|
23
|
+
* anybody can compute with.
|
|
20
24
|
*
|
|
21
25
|
* HKDF-Expand-Label, TLS 1.3's wrapper around `expand`, belongs with TLS and is
|
|
22
26
|
* not here. Written from RFC 5869, not ported from another implementation.
|
|
@@ -64,10 +68,16 @@ export const hkdfExtractSha384 = (salt: u8[], ikm: u8[]): u8[] => hmacSha384(hkd
|
|
|
64
68
|
/**
|
|
65
69
|
* HKDF-Expand with HMAC-SHA-256 (RFC 5869 §2.3): `length` bytes of output
|
|
66
70
|
* keying material from `prk` and `info`, or `null` when `length` is negative
|
|
67
|
-
* or past 255 × 32
|
|
71
|
+
* or past 255 × 32, when `info` is longer than 2^31 - 1 bytes, or when `prk`
|
|
72
|
+
* is shorter than 32 bytes.
|
|
68
73
|
*/
|
|
69
74
|
export const hkdfExpandSha256 = (prk: u8[], info: u8[], length: i32): u8[] | null => {
|
|
70
|
-
if (
|
|
75
|
+
if (
|
|
76
|
+
length < 0 ||
|
|
77
|
+
length > HKDF_MAX_BLOCKS * SHA256_SIZE ||
|
|
78
|
+
info.length > 2147483647 ||
|
|
79
|
+
toI32(prk.length) < SHA256_SIZE
|
|
80
|
+
) {
|
|
71
81
|
return null
|
|
72
82
|
}
|
|
73
83
|
const out: u8[] = new Array<u8>(length)
|
|
@@ -92,10 +102,16 @@ export const hkdfExpandSha256 = (prk: u8[], info: u8[], length: i32): u8[] | nul
|
|
|
92
102
|
/**
|
|
93
103
|
* HKDF-Expand with HMAC-SHA-384 (RFC 5869 §2.3): `length` bytes of output
|
|
94
104
|
* keying material from `prk` and `info`, or `null` when `length` is negative
|
|
95
|
-
* or past 255 × 48
|
|
105
|
+
* or past 255 × 48, when `info` is longer than 2^31 - 1 bytes, or when `prk`
|
|
106
|
+
* is shorter than 48 bytes.
|
|
96
107
|
*/
|
|
97
108
|
export const hkdfExpandSha384 = (prk: u8[], info: u8[], length: i32): u8[] | null => {
|
|
98
|
-
if (
|
|
109
|
+
if (
|
|
110
|
+
length < 0 ||
|
|
111
|
+
length > HKDF_MAX_BLOCKS * SHA384_SIZE ||
|
|
112
|
+
info.length > 2147483647 ||
|
|
113
|
+
toI32(prk.length) < SHA384_SIZE
|
|
114
|
+
) {
|
|
99
115
|
return null
|
|
100
116
|
}
|
|
101
117
|
const out: u8[] = new Array<u8>(length)
|
package/std/crypto/hmac.ts
CHANGED
|
@@ -127,15 +127,31 @@ export class HmacSha384 {
|
|
|
127
127
|
}
|
|
128
128
|
}
|
|
129
129
|
|
|
130
|
-
/**
|
|
130
|
+
/**
|
|
131
|
+
* The HMAC-SHA-256 of all of `data` under `key`, as a fresh 32-byte array.
|
|
132
|
+
*
|
|
133
|
+
* `data` longer than 2^31 - 1 bytes panics, as `sha256` does and for its
|
|
134
|
+
* reason: under `--number-mode f64` the tag would be of a prefix, and a tag
|
|
135
|
+
* that verifies every message sharing that prefix is a forgery. A key that
|
|
136
|
+
* long reaches `sha256` in the constructor and panics there.
|
|
137
|
+
*/
|
|
131
138
|
export const hmacSha256 = (key: u8[], data: u8[]): u8[] => {
|
|
139
|
+
if (data.length > 2147483647) {
|
|
140
|
+
panic("hmacSha256: a message longer than 2^31 - 1 bytes")
|
|
141
|
+
}
|
|
132
142
|
const mac = new HmacSha256(key)
|
|
133
143
|
mac.update(data, HMAC_FROM, toI32(data.length))
|
|
134
144
|
return mac.digest()
|
|
135
145
|
}
|
|
136
146
|
|
|
137
|
-
/**
|
|
147
|
+
/**
|
|
148
|
+
* The HMAC-SHA-384 of all of `data` under `key`, as a fresh 48-byte array.
|
|
149
|
+
* `data` longer than 2^31 - 1 bytes panics, as in `hmacSha256`.
|
|
150
|
+
*/
|
|
138
151
|
export const hmacSha384 = (key: u8[], data: u8[]): u8[] => {
|
|
152
|
+
if (data.length > 2147483647) {
|
|
153
|
+
panic("hmacSha384: a message longer than 2^31 - 1 bytes")
|
|
154
|
+
}
|
|
139
155
|
const mac = new HmacSha384(key)
|
|
140
156
|
mac.update(data, HMAC_FROM, toI32(data.length))
|
|
141
157
|
return mac.digest()
|