@amritk/nish-aarch64-linux 0.14.0 → 0.15.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/bin/nish +0 -0
- package/package.json +1 -1
- package/runtime/nish.d.ts +91 -0
- package/runtime/nish.h +58 -0
- package/runtime/nish.mjs +23 -0
- package/runtime/runtime-net.c +528 -0
- package/runtime/shim.mjs +15 -0
- package/scripts/build.sh +8 -7
- package/std/README.md +54 -14
- package/std/crypto/LICENSE-bearssl +21 -0
- package/std/crypto/LICENSE-fiat-crypto +21 -0
- package/std/crypto/aes.ts +899 -0
- package/std/crypto/chacha20poly1305.ts +698 -0
- package/std/crypto/p256.ts +4337 -0
- package/std/crypto/x25519.ts +22 -7
- package/std/crypto/x509.ts +1214 -0
package/std/README.md
CHANGED
|
@@ -19,12 +19,18 @@ whatever program imports it, and subject to the same rules as `examples/` or
|
|
|
19
19
|
## `nish/crypto` — the primitives under TLS 1.3
|
|
20
20
|
|
|
21
21
|
The first lanes of [WP34](../docs/wp34-hosting-cs.md) §5: K1's hashes, MACs and
|
|
22
|
-
key derivation, and K4's key exchange,
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
its
|
|
26
|
-
|
|
27
|
-
|
|
22
|
+
key derivation, K2's and K3's AEADs, K4's key exchange, K5's signatures and
|
|
23
|
+
K6's certificates, in
|
|
24
|
+
pure Nish (decision S1), each module imported by its own specifier. Every one
|
|
25
|
+
is written from its specification, with two exceptions that keep their
|
|
26
|
+
upstream notice: `crypto/aes.ts`'s `ghashMul32` is adapted from BearSSL, and
|
|
27
|
+
`crypto/p256.ts`'s field and scalar arithmetic is ported from fiat-crypto
|
|
28
|
+
([`THIRD_PARTY_NOTICES.md`](../THIRD_PARTY_NOTICES.md)). Each reproduces its
|
|
29
|
+
specification's published vectors in its `tests/link/crypto_*` programs. The
|
|
30
|
+
performance gate compiles every module with no diagnostics under both
|
|
31
|
+
`--number-mode i32` and `f64`, and the hashes, HMAC, HKDF, X25519,
|
|
32
|
+
ChaCha20-Poly1305, AES-GCM, P-256 and X.509 also run their vectors in `f64`
|
|
33
|
+
(`crypto_*_f64`).
|
|
28
34
|
|
|
29
35
|
| Module | What it is | Reproduces |
|
|
30
36
|
| --- | --- | --- |
|
|
@@ -35,6 +41,10 @@ HMAC, HKDF and X25519 also run their vectors in `f64` (`crypto_*_f64`).
|
|
|
35
41
|
| [`crypto/ct.ts`](./crypto/ct.ts) | `timingSafeEqual(a, b)`, which reads every byte whatever it holds, and `timingSafeEqualAt(a, aOff, b, bOff, len)` over two windows, which answers `false` for a window outside its array. Two lengths that differ answer `false` at once, because a length is public | — |
|
|
36
42
|
| [`crypto/base64url.ts`](./crypto/base64url.ts) | `base64urlEncode(data)` and `base64urlDecode(text)`, unpadded. Decoding is strict, so every byte string has one spelling: a `=`, a character outside the alphabet, a length of 1 mod 4 or nonzero unused low bits answer `null` | RFC 4648 §5, §10 |
|
|
37
43
|
| [`crypto/x25519.ts`](./crypto/x25519.ts) | `x25519(scalar, u)` and `x25519Base(scalar)`, on ten 25.5-bit limbs in `i64`. Either answers `null` unless its arguments are `X25519_SIZE` (32) bytes; the scalar is clamped on a copy | RFC 7748 §5.2, §6.1 |
|
|
44
|
+
| [`crypto/chacha20poly1305.ts`](./crypto/chacha20poly1305.ts) | `chacha20Poly1305Seal(key, nonce, aad, plaintext)`, which answers the ciphertext followed by the 16-byte tag, and `chacha20Poly1305Open`, which checks the whole tag before it decrypts anything and answers `null` for a message that does not authenticate. Beneath them `chacha20Block`, `chacha20`, `chacha20QuarterRound`, `poly1305` and `poly1305KeyGen`, and `chacha20HeaderMask`, QUIC's 5-byte header-protection mask. Every input of the wrong length answers `null` | RFC 8439 §2, RFC 9001 §5.4.4 |
|
|
45
|
+
| [`crypto/aes.ts`](./crypto/aes.ts) | AES-128 and AES-256, bitsliced four blocks at a time with the Boyar–Peralta S-box circuit, so no table is read: `aesKey(key)` expands a 16- or 32-byte key into an `AesKey`, then `aesEncryptBlock`, `aesGcmSeal` / `aesGcmOpen` (tag last, checked in full before anything is decrypted; any non-empty IV) and `aesHeaderMask`. AES-192 is out of scope, and a wrong length answers `null` | FIPS 197, SP 800-38D, RFC 9001 §5.4.3, Wycheproof `aes_gcm` |
|
|
46
|
+
| [`crypto/p256.ts`](./crypto/p256.ts) | ECDSA over P-256 with RFC 6979's deterministic nonces: `p256PublicKey(priv)` (65-byte uncompressed SEC1), `p256Sign` / `p256Verify` over a digest and `p256SignSha256` / `p256VerifySha256` over a message; a signature is `r` and `s`, 32 big-endian bytes each, not DER. A malformed key, a point off the curve or an `r` or `s` out of range answers `null` or `false`, never a panic | RFC 6979 A.2.5, Wycheproof `ecdsa_secp256r1_sha256` |
|
|
47
|
+
| [`crypto/x509.ts`](./crypto/x509.ts) | DER, PEM and X.509 over P-256: `pemToDer` / `derToPem` (RFC 7468, padded standard base64, strict labels), `x509ParseP256PrivateKey` (SEC1 or PKCS#8), `x509ParseCertificate` / `x509ParseChain` into an `X509Certificate`, `x509VerifySignature` (ecdsa-with-SHA256 under an issuer's key), `x509MintSelfSigned`, the 1-to-14-day self-signed P-256 certificate WebTransport's `serverCertificateHashes` accepts, and `x509CertificateHash`, its SHA-256. DER is read strictly — non-minimal lengths and integers, indefinite lengths and trailing bytes answer `null` | X.690, RFC 5280, RFC 7468, RFC 5915, RFC 5208 / 5958; certificates checked against OpenSSL |
|
|
38
48
|
|
|
39
49
|
Three rules hold across the modules:
|
|
40
50
|
|
|
@@ -47,14 +57,44 @@ Three rules hold across the modules:
|
|
|
47
57
|
- **An all-zero X25519 result is returned, not refused.** It is what a
|
|
48
58
|
low-order `u` gives, and RFC 7748 §6.1 leaves the check to the protocol; TLS
|
|
49
59
|
1.3 (WP34 T1) makes it. A key exchange outside TLS has to make it itself.
|
|
50
|
-
- **Constant time by construction,
|
|
51
|
-
or indexes by, a secret: comparisons OR the differences
|
|
52
|
-
test it once, the ladder swaps with a mask and always runs
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
60
|
+
- **Constant time by construction, and verified where the check reaches.** No
|
|
61
|
+
module branches on, or indexes by, a secret: comparisons OR the differences
|
|
62
|
+
into one word and test it once, the ladder swaps with a mask and always runs
|
|
63
|
+
255 steps, AES reads no table, P-256's window reads all sixteen entries and
|
|
64
|
+
keeps one by mask, and base64url maps characters by arithmetic on range masks
|
|
65
|
+
rather than a table. Every branch is on a length, a loop counter or a bit
|
|
66
|
+
position. WP34 N6 checks that the machine code kept that shape:
|
|
67
|
+
`tests/ct-asm.js` disassembles golden fixtures on x86-64 and aarch64 and
|
|
68
|
+
refuses a branch, a call or a secret-addressed load in them. What it holds,
|
|
69
|
+
per module, is what that module's header says:
|
|
70
|
+
- `tests/cases/ct_asm_mac` pins the two loop shapes the others are built
|
|
71
|
+
from, a full tag compare and a masked table read. `crypto/ct.ts` and
|
|
72
|
+
`crypto/hmac.ts`'s verifiers compare in the first shape and
|
|
73
|
+
`crypto/base64url.ts` selects by mask, but none of those K1 modules is
|
|
74
|
+
itself in a fixture, so they remain discipline.
|
|
75
|
+
- `tests/cases/ct_asm_x25519`: X25519's field multiply, square, add,
|
|
76
|
+
subtract and multiply by a24, its conditional swap, and one step of the
|
|
77
|
+
Montgomery ladder, the check following each call into the field functions.
|
|
78
|
+
The 255-step loop that drives the ladder, the inversion and the encodings
|
|
79
|
+
remain discipline.
|
|
80
|
+
- `tests/cases/ct_asm_chacha20poly1305`: Poly1305's key clamp, one block,
|
|
81
|
+
the final reduction with `s`, and the tag compare. The ChaCha20 rounds and
|
|
82
|
+
the loops that drive both halves remain discipline.
|
|
83
|
+
- `tests/cases/ct_asm_aes`: one full bitsliced round, one GHASH multiply and
|
|
84
|
+
the tag compare. Packing, the key schedule and the loops over blocks
|
|
85
|
+
remain discipline.
|
|
86
|
+
- `tests/cases/ct_asm_p256`: fiat's field multiply, square, add and
|
|
87
|
+
subtract, its scalar multiply and its conditional move; the sixteen-entry
|
|
88
|
+
table read by a secret digit; the complete doubling and addition; and one
|
|
89
|
+
window step of the scalar multiplication (four doublings, the table read
|
|
90
|
+
and an addition), the check following each call into the field functions.
|
|
91
|
+
The 64-window loop, the table build, the inversions, the encodings and
|
|
92
|
+
RFC 6979's nonce derivation remain discipline.
|
|
93
|
+
|
|
94
|
+
The SHA-2 hashes and HKDF are additions, rotations and xors that branch
|
|
95
|
+
only on lengths, and are not in a fixture either; nor is `crypto/x509.ts`,
|
|
96
|
+
whose one secret, a private key, is base64-decoded by range masks and
|
|
97
|
+
otherwise only copied and handed to `crypto/p256.ts`.
|
|
58
98
|
|
|
59
99
|
## How a program imports it
|
|
60
100
|
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
Copyright (c) 2016 Thomas Pornin <pornin@bolet.org>
|
|
2
|
+
|
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
4
|
+
a copy of this software and associated documentation files (the
|
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
9
|
+
the following conditions:
|
|
10
|
+
|
|
11
|
+
The above copyright notice and this permission notice shall be
|
|
12
|
+
included in all copies or substantial portions of the Software.
|
|
13
|
+
|
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
|
18
|
+
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
|
19
|
+
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
20
|
+
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2015-2020 the fiat-crypto authors (see the AUTHORS file).
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|