@shieldfive/crypto 1.0.0-alpha.11
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/CHANGELOG.md +228 -0
- package/LICENSE +201 -0
- package/README.md +275 -0
- package/SECURITY.md +130 -0
- package/dist/format/header.d.ts +73 -0
- package/dist/format/header.d.ts.map +1 -0
- package/dist/format/header.js +230 -0
- package/dist/format/header.js.map +1 -0
- package/dist/identity/index.d.ts +119 -0
- package/dist/identity/index.d.ts.map +1 -0
- package/dist/identity/index.js +217 -0
- package/dist/identity/index.js.map +1 -0
- package/dist/identity/sign.d.ts +92 -0
- package/dist/identity/sign.d.ts.map +1 -0
- package/dist/identity/sign.js +182 -0
- package/dist/identity/sign.js.map +1 -0
- package/dist/index.d.ts +58 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +146 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/encoding.d.ts +33 -0
- package/dist/internal/encoding.d.ts.map +1 -0
- package/dist/internal/encoding.js +135 -0
- package/dist/internal/encoding.js.map +1 -0
- package/dist/internal/hkdf.d.ts +14 -0
- package/dist/internal/hkdf.d.ts.map +1 -0
- package/dist/internal/hkdf.js +27 -0
- package/dist/internal/hkdf.js.map +1 -0
- package/dist/internal/hmac.d.ts +9 -0
- package/dist/internal/hmac.d.ts.map +1 -0
- package/dist/internal/hmac.js +18 -0
- package/dist/internal/hmac.js.map +1 -0
- package/dist/internal/runtime.d.ts +29 -0
- package/dist/internal/runtime.d.ts.map +1 -0
- package/dist/internal/runtime.js +67 -0
- package/dist/internal/runtime.js.map +1 -0
- package/dist/internal/sodium.d.ts +12 -0
- package/dist/internal/sodium.d.ts.map +1 -0
- package/dist/internal/sodium.js +34 -0
- package/dist/internal/sodium.js.map +1 -0
- package/dist/internal/types.d.ts +98 -0
- package/dist/internal/types.d.ts.map +1 -0
- package/dist/internal/types.js +70 -0
- package/dist/internal/types.js.map +1 -0
- package/dist/kdf/argon2id.d.ts +72 -0
- package/dist/kdf/argon2id.d.ts.map +1 -0
- package/dist/kdf/argon2id.js +98 -0
- package/dist/kdf/argon2id.js.map +1 -0
- package/dist/migration/v0-bridge.d.ts +94 -0
- package/dist/migration/v0-bridge.d.ts.map +1 -0
- package/dist/migration/v0-bridge.js +203 -0
- package/dist/migration/v0-bridge.js.map +1 -0
- package/dist/streams/aes-gcm-v1.d.ts +144 -0
- package/dist/streams/aes-gcm-v1.d.ts.map +1 -0
- package/dist/streams/aes-gcm-v1.js +456 -0
- package/dist/streams/aes-gcm-v1.js.map +1 -0
- package/dist/streams/pq-hybrid-v1.d.ts +219 -0
- package/dist/streams/pq-hybrid-v1.d.ts.map +1 -0
- package/dist/streams/pq-hybrid-v1.js +473 -0
- package/dist/streams/pq-hybrid-v1.js.map +1 -0
- package/dist/suites/aes-gcm-v0/api.d.ts +48 -0
- package/dist/suites/aes-gcm-v0/api.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v0/api.js +110 -0
- package/dist/suites/aes-gcm-v0/api.js.map +1 -0
- package/dist/suites/aes-gcm-v1/api.d.ts +54 -0
- package/dist/suites/aes-gcm-v1/api.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v1/api.js +181 -0
- package/dist/suites/aes-gcm-v1/api.js.map +1 -0
- package/dist/suites/aes-gcm-v1/index.d.ts +59 -0
- package/dist/suites/aes-gcm-v1/index.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v1/index.js +177 -0
- package/dist/suites/aes-gcm-v1/index.js.map +1 -0
- package/dist/suites/aes-gcm-v2/api.d.ts +44 -0
- package/dist/suites/aes-gcm-v2/api.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v2/api.js +162 -0
- package/dist/suites/aes-gcm-v2/api.js.map +1 -0
- package/dist/suites/aes-gcm-v2/index.d.ts +63 -0
- package/dist/suites/aes-gcm-v2/index.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v2/index.js +193 -0
- package/dist/suites/aes-gcm-v2/index.js.map +1 -0
- package/dist/suites/pq-hybrid-v1/api.d.ts +67 -0
- package/dist/suites/pq-hybrid-v1/api.d.ts.map +1 -0
- package/dist/suites/pq-hybrid-v1/api.js +190 -0
- package/dist/suites/pq-hybrid-v1/api.js.map +1 -0
- package/dist/suites/pq-hybrid-v1/index.d.ts +101 -0
- package/dist/suites/pq-hybrid-v1/index.d.ts.map +1 -0
- package/dist/suites/pq-hybrid-v1/index.js +225 -0
- package/dist/suites/pq-hybrid-v1/index.js.map +1 -0
- package/dist/suites/xchacha-v1/api.d.ts +29 -0
- package/dist/suites/xchacha-v1/api.d.ts.map +1 -0
- package/dist/suites/xchacha-v1/api.js +154 -0
- package/dist/suites/xchacha-v1/api.js.map +1 -0
- package/dist/suites/xchacha-v1/index.d.ts +50 -0
- package/dist/suites/xchacha-v1/index.d.ts.map +1 -0
- package/dist/suites/xchacha-v1/index.js +133 -0
- package/dist/suites/xchacha-v1/index.js.map +1 -0
- package/package.json +124 -0
- package/spec/format-v0.md +81 -0
- package/spec/format-v1.md +400 -0
- package/spec/key-derivation.md +167 -0
- package/spec/threat-model.md +242 -0
- package/src/format/header.ts +316 -0
- package/src/identity/index.ts +371 -0
- package/src/identity/sign.ts +221 -0
- package/src/index.ts +224 -0
- package/src/internal/encoding.ts +152 -0
- package/src/internal/hkdf.ts +47 -0
- package/src/internal/hmac.ts +33 -0
- package/src/internal/runtime.ts +80 -0
- package/src/internal/sodium.ts +38 -0
- package/src/internal/types.ts +134 -0
- package/src/kdf/argon2id.ts +165 -0
- package/src/migration/v0-bridge.ts +347 -0
- package/src/streams/aes-gcm-v1.ts +647 -0
- package/src/streams/pq-hybrid-v1.ts +722 -0
- package/src/suites/aes-gcm-v0/api.ts +155 -0
- package/src/suites/aes-gcm-v1/api.ts +292 -0
- package/src/suites/aes-gcm-v1/index.ts +269 -0
- package/src/suites/aes-gcm-v2/api.ts +268 -0
- package/src/suites/aes-gcm-v2/index.ts +289 -0
- package/src/suites/pq-hybrid-v1/api.ts +299 -0
- package/src/suites/pq-hybrid-v1/index.ts +343 -0
- package/src/suites/xchacha-v1/api.ts +254 -0
- package/src/suites/xchacha-v1/index.ts +213 -0
package/README.md
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
1
|
+
# @shieldfive/crypto
|
|
2
|
+
|
|
3
|
+
> Post-quantum-hybrid client-side encryption with a self-describing,
|
|
4
|
+
> cipher-suite-agile on-disk format. The cryptographic core of
|
|
5
|
+
> [ShieldFive](https://shieldfive.com), released as a standalone library.
|
|
6
|
+
|
|
7
|
+
[](LICENSE)
|
|
8
|
+
[](tests/)
|
|
9
|
+
[](#status)
|
|
10
|
+
|
|
11
|
+
## Status & honest scope
|
|
12
|
+
|
|
13
|
+
This library is **alpha**. The wire format is frozen for the v1 release;
|
|
14
|
+
the public TypeScript API may make minor adjustments before v1.0.0 stable.
|
|
15
|
+
It has **not** undergone external cryptographic audit. Until it does,
|
|
16
|
+
treat this library as a serious work-in-progress rather than a finished
|
|
17
|
+
product.
|
|
18
|
+
|
|
19
|
+
The design choices documented in [`spec/`](spec/) are deliberate and
|
|
20
|
+
reviewable. The implementation is covered by 155 passing tests including
|
|
21
|
+
truncation, reordering, splice, and tampering detection across all four
|
|
22
|
+
suites. That is enough for internal dogfooding. It is **not** enough to
|
|
23
|
+
claim "most secure crypto library" — that claim requires external review
|
|
24
|
+
this library has not yet received.
|
|
25
|
+
|
|
26
|
+
## Design positions
|
|
27
|
+
|
|
28
|
+
This library makes specific design choices that differ from existing
|
|
29
|
+
open-source client-side encryption libraries in the encrypted-cloud-storage
|
|
30
|
+
space. The table below summarizes those positions; each row links to the
|
|
31
|
+
spec section that documents the choice.
|
|
32
|
+
|
|
33
|
+
| Property | This library | Proton OpenPGP.js | Internxt SDK | MEGA SDK |
|
|
34
|
+
| ------------------------------------------ | :----------: | :---------------: | :----------: | :------: |
|
|
35
|
+
| Post-quantum hybrid by default | ✅ | ⚠️ | ⚠️ | ❌ |
|
|
36
|
+
| ML-KEM-1024 (NIST PQC level 5) | ✅ | ❌ | ❌ (Kyber-512) | ❌ |
|
|
37
|
+
| Self-describing on-disk file format | ✅ | ✅ | ⚠️ | ⚠️ |
|
|
38
|
+
| Cipher-suite agile (one byte selects) | ✅ | ⚠️ | ❌ | ❌ |
|
|
39
|
+
| Truncation detection bound to AEAD | ✅ | ✅ | ❌ | ❌ |
|
|
40
|
+
| Cross-file splice prevention (file_id AAD) | ✅ | ✅ | ❌ | ❌ |
|
|
41
|
+
| Streaming AEAD with random-access chunks | ✅ | ⚠️ | ✅ | ✅ |
|
|
42
|
+
| WebCrypto-only path (no WASM required) | ✅ | ❌ | ❌ | ❌ |
|
|
43
|
+
| Apache 2.0 (patent grant) | ✅ | ⚠️ (LGPL) | ⚠️ | ⚠️ |
|
|
44
|
+
|
|
45
|
+
⚠️ = partial or feature-flagged. See [`spec/threat-model.md`](spec/threat-model.md)
|
|
46
|
+
for the comparison methodology and source citations. Proton OpenPGP.js
|
|
47
|
+
added optional post-quantum (ML-KEM + ECC hybrid) support via OpenPGP v6
|
|
48
|
+
in May 2026 (proton.me/blog/introducing-post-quantum-encryption); it is
|
|
49
|
+
opt-in, not default — hence ⚠️ rather than ✅ in the table. Comparison
|
|
50
|
+
cells reflect publicly available specifications and audit reports as of
|
|
51
|
+
2026-05-18 and will be updated as upstreams change.
|
|
52
|
+
|
|
53
|
+
## Quick start
|
|
54
|
+
|
|
55
|
+
```bash
|
|
56
|
+
npm install @shieldfive/crypto
|
|
57
|
+
# Optional, only if you use suites 0x02 or 0x03:
|
|
58
|
+
npm install libsodium-wrappers-sumo
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
### Encrypt a file with the post-quantum hybrid suite (default)
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
import {
|
|
65
|
+
encryptBlob,
|
|
66
|
+
decryptBlob,
|
|
67
|
+
generateMlKemKeypair,
|
|
68
|
+
} from '@shieldfive/crypto/pq-hybrid-v1'
|
|
69
|
+
|
|
70
|
+
// Recipient generates a long-lived ML-KEM-1024 keypair (typically derived
|
|
71
|
+
// from their master secret — see deriveMlKemKeypair).
|
|
72
|
+
const { publicKey, secretKey } = generateMlKemKeypair()
|
|
73
|
+
|
|
74
|
+
// A classical envelope key (e.g. the user's vault key, 32 bytes).
|
|
75
|
+
const envelopeKey = crypto.getRandomValues(new Uint8Array(32))
|
|
76
|
+
|
|
77
|
+
// Encrypt
|
|
78
|
+
const file = new File([myData], 'document.pdf')
|
|
79
|
+
const result = await encryptBlob({
|
|
80
|
+
blob: file,
|
|
81
|
+
recipientPublicKey: publicKey,
|
|
82
|
+
envelopeKey,
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
// Upload result.blob to your storage backend. It is self-describing.
|
|
86
|
+
|
|
87
|
+
// Later, decrypt
|
|
88
|
+
const plaintext = await decryptBlob({
|
|
89
|
+
blob: result.blob,
|
|
90
|
+
recipientSecretKey: secretKey,
|
|
91
|
+
envelopeKey,
|
|
92
|
+
})
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Encrypt with the WebCrypto-only suite (no WASM dependency)
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
import { encryptBlob, decryptBlob } from '@shieldfive/crypto/aes-gcm-v1'
|
|
99
|
+
|
|
100
|
+
const result = await encryptBlob({ blob: file })
|
|
101
|
+
// result.contentKey is your 32-byte fresh per-file key — store it wrapped
|
|
102
|
+
// under your envelope key.
|
|
103
|
+
|
|
104
|
+
const plaintext = await decryptBlob({
|
|
105
|
+
blob: result.blob,
|
|
106
|
+
contentKey: result.contentKey,
|
|
107
|
+
})
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
### Auto-routing decryptor
|
|
111
|
+
|
|
112
|
+
If you accept files written by any v1 suite and don't know which in advance:
|
|
113
|
+
|
|
114
|
+
```ts
|
|
115
|
+
import { autoDecryptBlob } from '@shieldfive/crypto'
|
|
116
|
+
|
|
117
|
+
const plaintext = await autoDecryptBlob({
|
|
118
|
+
blob: encryptedBlob,
|
|
119
|
+
contentKey, // for aes-gcm-v1 / xchacha-v1
|
|
120
|
+
recipientSecretKey, // for pq-hybrid-v1
|
|
121
|
+
envelopeKey, // for pq-hybrid-v1
|
|
122
|
+
})
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
### Reading legacy v0 files
|
|
126
|
+
|
|
127
|
+
The pre-v1 ShieldFive production format is supported read-only:
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
import { decryptV0 } from '@shieldfive/crypto/legacy-v0'
|
|
131
|
+
|
|
132
|
+
const plaintext = await decryptV0({
|
|
133
|
+
blob: legacyBlob,
|
|
134
|
+
contentKey,
|
|
135
|
+
noncePrefix, // 4 bytes, from the database
|
|
136
|
+
chunkSize, // 5 * 1024 * 1024 typically
|
|
137
|
+
})
|
|
138
|
+
```
|
|
139
|
+
|
|
140
|
+
There is no `encryptV0`. New writes must use a v1 suite.
|
|
141
|
+
|
|
142
|
+
### Decrypting an exported ShieldFive backup
|
|
143
|
+
|
|
144
|
+
A ShieldFive user can export their account at any time and
|
|
145
|
+
decrypt the resulting bundle offline using this library plus the
|
|
146
|
+
small Node script that ships at
|
|
147
|
+
[shieldfive.com/export](https://shieldfive.com/export). The
|
|
148
|
+
recipe walks the key hierarchy (master password → user key →
|
|
149
|
+
root key → folder keys → per-file content keys), re-derives the
|
|
150
|
+
ML-KEM-1024 secret for Suite 0x03 files deterministically from
|
|
151
|
+
the root key (per `spec/key-derivation.md`), and feeds each blob
|
|
152
|
+
into `autoDecryptBlob` here.
|
|
153
|
+
|
|
154
|
+
The recipe and the script live in the web repository so that the
|
|
155
|
+
documented version stays in lock-step with the API surface; this
|
|
156
|
+
library is the decryption primitive the script depends on. If
|
|
157
|
+
you want to reproduce the path from first principles (with no
|
|
158
|
+
ShieldFive code in the loop), `spec/format-v1.md` and
|
|
159
|
+
`spec/key-derivation.md` together describe everything needed.
|
|
160
|
+
|
|
161
|
+
## File format
|
|
162
|
+
|
|
163
|
+
The complete v1 wire format is documented in
|
|
164
|
+
[`spec/format-v1.md`](spec/format-v1.md). The short version:
|
|
165
|
+
|
|
166
|
+
```
|
|
167
|
+
header := magic(5) = "SF5\x01\x00"
|
|
168
|
+
|| suite(1) = 0x01 | 0x02 | 0x03
|
|
169
|
+
|| flags(1) = 0x00 (reserved)
|
|
170
|
+
|| file_id(16) = random per-file
|
|
171
|
+
|| chunk_size(4) = uint32 BE
|
|
172
|
+
|| total_chunks(8) = uint64 BE
|
|
173
|
+
|| plaintext_size(8) = uint64 BE
|
|
174
|
+
|| suite_payload_len(2)
|
|
175
|
+
|| suite_payload(variable)
|
|
176
|
+
|| header_mac(32) = HMAC-SHA-256, keyed from content key
|
|
177
|
+
|
|
178
|
+
chunk_i := length_prefix(4) || AEAD-ciphertext-with-tag
|
|
179
|
+
```
|
|
180
|
+
|
|
181
|
+
Every chunk's AEAD authenticator binds the chunk index, total chunk count,
|
|
182
|
+
final-chunk flag, and file_id. This makes truncation, reordering, and
|
|
183
|
+
cross-file splicing structurally detectable rather than relying on
|
|
184
|
+
application-layer hashes.
|
|
185
|
+
|
|
186
|
+
## Cipher suites
|
|
187
|
+
|
|
188
|
+
| ID | Name | Default | Notes |
|
|
189
|
+
| ---- | ----------------------------------- | ------- | -------------------------------------- |
|
|
190
|
+
| 0x01 | `aes-256-gcm-v1` | | WebCrypto-only, hardware-accelerated |
|
|
191
|
+
| 0x02 | `xchacha20-poly1305-v1` | | libsodium, 192-bit nonces |
|
|
192
|
+
| 0x03 | `pq-hybrid-xchacha-mlkem1024-v1` | ✅ | XChaCha20-Poly1305 + ML-KEM-1024 hybrid |
|
|
193
|
+
|
|
194
|
+
ML-KEM-1024 is FIPS 203 (NIST PQC standard, security level 5). Files
|
|
195
|
+
encrypted with suite 0x03 remain confidential against an adversary who
|
|
196
|
+
breaks *either* the classical or the post-quantum primitive — only a
|
|
197
|
+
break of *both* compromises the file.
|
|
198
|
+
|
|
199
|
+
## Threat model
|
|
200
|
+
|
|
201
|
+
Documented at length in [`spec/threat-model.md`](spec/threat-model.md). The
|
|
202
|
+
short summary: this library protects file confidentiality and integrity
|
|
203
|
+
against an honest-but-curious server, an active network adversary, and a
|
|
204
|
+
"harvest now, decrypt later" quantum adversary. It does *not* protect
|
|
205
|
+
against malicious client delivery, endpoint compromise, side channels in
|
|
206
|
+
the host crypto runtime, or metadata leakage at the storage layer. Those
|
|
207
|
+
are addressed by the host application, not the crypto layer.
|
|
208
|
+
|
|
209
|
+
## Performance
|
|
210
|
+
|
|
211
|
+
Benchmarks live in `bench/throughput.ts`. Run them on your hardware:
|
|
212
|
+
|
|
213
|
+
```bash
|
|
214
|
+
npx tsx bench/throughput.ts
|
|
215
|
+
```
|
|
216
|
+
|
|
217
|
+
Throughput depends heavily on CPU model, AES-NI availability, and Node
|
|
218
|
+
version. The PQ KEM is a constant per-file cost (~ML-KEM-1024 keygen +
|
|
219
|
+
encapsulation latency), independent of file size. Streaming chunk
|
|
220
|
+
throughput tracks the underlying classical AEAD.
|
|
221
|
+
|
|
222
|
+
We do not publish reference numbers here because numbers without source
|
|
223
|
+
hardware are misleading; numbers with source hardware get cherry-picked.
|
|
224
|
+
Run the benchmark on your target hardware and report what you see.
|
|
225
|
+
|
|
226
|
+
## Building from source
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
npm install
|
|
230
|
+
npm test
|
|
231
|
+
npm run build # emits dist/
|
|
232
|
+
```
|
|
233
|
+
|
|
234
|
+
Requires Node 20+.
|
|
235
|
+
|
|
236
|
+
## Status
|
|
237
|
+
|
|
238
|
+
**Alpha.** The wire format is frozen for the v1 release, but the public
|
|
239
|
+
TypeScript API may make small adjustments before 1.0.0 stable. Test
|
|
240
|
+
coverage is comprehensive (155 tests, all four suites, all architectural
|
|
241
|
+
guarantees verified). A formal third-party security audit is planned for
|
|
242
|
+
the 1.0.0 stable milestone — until that audit lands, treat this library
|
|
243
|
+
as a serious work-in-progress rather than a finished product.
|
|
244
|
+
|
|
245
|
+
## License
|
|
246
|
+
|
|
247
|
+
[Apache 2.0](LICENSE). The Apache 2.0 patent grant is important for a
|
|
248
|
+
crypto library; we chose it over MIT for that reason.
|
|
249
|
+
|
|
250
|
+
## Reporting vulnerabilities
|
|
251
|
+
|
|
252
|
+
See [`SECURITY.md`](SECURITY.md). Coordinate with us at
|
|
253
|
+
`security@shieldfive.com` (PGP key in SECURITY.md). 72-hour acknowledgement,
|
|
254
|
+
30-day target patch window for high-severity issues. Researchers acting
|
|
255
|
+
in good faith are protected under the safe-harbor clause.
|
|
256
|
+
|
|
257
|
+
## Acknowledgements
|
|
258
|
+
|
|
259
|
+
- [@noble/post-quantum](https://github.com/paulmillr/noble-post-quantum)
|
|
260
|
+
by Paul Miller — clean, minimal ML-KEM-1024 (FIPS 203)
|
|
261
|
+
implementation. ShieldFive pins `^0.6.0`, which resolves to the 0.6.1
|
|
262
|
+
release. Upstream completed a maintainer self-audit at 0.6.1 in
|
|
263
|
+
April 2026 (see the
|
|
264
|
+
["Security"](https://github.com/paulmillr/noble-post-quantum#security)
|
|
265
|
+
section of the upstream README) and has **not** been independently
|
|
266
|
+
audited by an external firm. ShieldFive's PQ-hybrid construction on
|
|
267
|
+
top of the library — the HKDF-SHA-256 combiner that mixes the
|
|
268
|
+
classical and ML-KEM shares — has also not received an independent
|
|
269
|
+
external audit. A third-party audit of the ShieldFive layer is
|
|
270
|
+
planned for the v1.0.0 stable milestone.
|
|
271
|
+
- [libsodium](https://github.com/jedisct1/libsodium) — XChaCha20-Poly1305
|
|
272
|
+
and XSalsa20-Poly1305 secretbox.
|
|
273
|
+
- The NIST PQC competition and FIPS 203 authors.
|
|
274
|
+
|
|
275
|
+
— Cho Garcia, maintainer
|
package/SECURITY.md
ADDED
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
# Security Policy
|
|
2
|
+
|
|
3
|
+
ShieldFive takes the security of `@shieldfive/crypto` seriously. This
|
|
4
|
+
document describes how to report a vulnerability, what we commit to, and
|
|
5
|
+
the safe-harbor terms for security researchers.
|
|
6
|
+
|
|
7
|
+
## Reporting a vulnerability
|
|
8
|
+
|
|
9
|
+
**Do not open a public GitHub issue for security reports.** Instead, email
|
|
10
|
+
us directly:
|
|
11
|
+
|
|
12
|
+
- **Email:** `security@shieldfive.com`
|
|
13
|
+
- **PGP key:** Not yet published. Encrypt with a temporary key on
|
|
14
|
+
request, or send in plaintext — we'd rather know about the issue
|
|
15
|
+
than have it sit in your inbox. The permanent PGP key fingerprint
|
|
16
|
+
will be published at v1.0.0 stable release alongside the URL
|
|
17
|
+
`https://shieldfive.com/.well-known/security/pgp-key.txt`.
|
|
18
|
+
|
|
19
|
+
If you cannot encrypt the report, send it in plaintext anyway — we would
|
|
20
|
+
rather hear about a vulnerability in plaintext than not at all. We will
|
|
21
|
+
follow up over an encrypted channel.
|
|
22
|
+
|
|
23
|
+
### What to include
|
|
24
|
+
|
|
25
|
+
1. A description of the vulnerability and its impact.
|
|
26
|
+
2. Steps to reproduce, including a minimal proof-of-concept if possible.
|
|
27
|
+
3. The library version and runtime environment (Node version, browser,
|
|
28
|
+
bundler).
|
|
29
|
+
4. Whether the issue is already public or has been disclosed elsewhere.
|
|
30
|
+
5. Your name and a way to contact you (or "anonymous" if you prefer).
|
|
31
|
+
|
|
32
|
+
## Our commitments
|
|
33
|
+
|
|
34
|
+
| Severity | Acknowledgement | Initial response | Patch target |
|
|
35
|
+
| ----------------------------- | :-------------: | :--------------: | :----------: |
|
|
36
|
+
| Critical (key recovery, RCE) | 24 hours | 48 hours | 7 days |
|
|
37
|
+
| High (integrity bypass) | 48 hours | 5 days | 14 days |
|
|
38
|
+
| Medium (DoS, info leakage) | 72 hours | 7 days | 30 days |
|
|
39
|
+
| Low (defense-in-depth) | 7 days | 14 days | 90 days |
|
|
40
|
+
|
|
41
|
+
We will:
|
|
42
|
+
|
|
43
|
+
- Acknowledge your report within the windows above.
|
|
44
|
+
- Keep you informed of our investigation.
|
|
45
|
+
- Credit you in the release notes (with your permission, or anonymously).
|
|
46
|
+
- Coordinate public disclosure with you. We default to a 90-day disclosure
|
|
47
|
+
window, but will move faster if there is active exploitation in the
|
|
48
|
+
wild and slower if a coordinated multi-party fix is in progress.
|
|
49
|
+
- Publish a CVE when appropriate.
|
|
50
|
+
|
|
51
|
+
We will *not*:
|
|
52
|
+
|
|
53
|
+
- Take legal action against researchers acting in good faith (see
|
|
54
|
+
Safe Harbor below).
|
|
55
|
+
- Demand silence as a condition of bounty or credit.
|
|
56
|
+
|
|
57
|
+
## Safe Harbor
|
|
58
|
+
|
|
59
|
+
Security research conducted in accordance with this policy is authorized.
|
|
60
|
+
Specifically, we will not pursue civil claims or refer law enforcement
|
|
61
|
+
investigations against researchers who:
|
|
62
|
+
|
|
63
|
+
1. Make a good-faith effort to avoid privacy violations, destruction of
|
|
64
|
+
data, and interruption or degradation of our services.
|
|
65
|
+
2. Do not access, modify, or exfiltrate data belonging to anyone other
|
|
66
|
+
than themselves or research accounts.
|
|
67
|
+
3. Report the vulnerability promptly through this policy's channels.
|
|
68
|
+
4. Do not exploit the vulnerability beyond what is necessary to confirm
|
|
69
|
+
it.
|
|
70
|
+
5. Do not publicly disclose the vulnerability before we have had a
|
|
71
|
+
reasonable opportunity to remediate it (the timelines above).
|
|
72
|
+
|
|
73
|
+
Activities consistent with this policy are considered authorized conduct,
|
|
74
|
+
and we will not initiate legal action against you. If a third party
|
|
75
|
+
initiates legal action against you for activities conducted under this
|
|
76
|
+
policy, we will make this authorization clear.
|
|
77
|
+
|
|
78
|
+
## Bug bounty
|
|
79
|
+
|
|
80
|
+
ShieldFive operates a paid bug bounty program covering this
|
|
81
|
+
open-source crypto library. Reward tiers:
|
|
82
|
+
|
|
83
|
+
- Critical: up to €1000
|
|
84
|
+
- High: up to €500
|
|
85
|
+
- Medium: up to €250
|
|
86
|
+
|
|
87
|
+
Lower-impact findings receive public credit (CVE, release notes,
|
|
88
|
+
dedicated thank-you page) and product credits.
|
|
89
|
+
|
|
90
|
+
For current scope, rules of engagement, submission instructions,
|
|
91
|
+
and the safe-harbor statement, see
|
|
92
|
+
https://shieldfive.com/security/bug-bounty.
|
|
93
|
+
|
|
94
|
+
## Out of scope
|
|
95
|
+
|
|
96
|
+
The following are *not* in scope for this library's security policy and
|
|
97
|
+
should be reported elsewhere or not at all:
|
|
98
|
+
|
|
99
|
+
- Vulnerabilities in dependencies (`@noble/post-quantum`,
|
|
100
|
+
`libsodium-wrappers-sumo`) — report those upstream.
|
|
101
|
+
- Vulnerabilities in the host application running this library — those
|
|
102
|
+
are the application's responsibility.
|
|
103
|
+
- Side-channel attacks against the underlying crypto runtime
|
|
104
|
+
(browser SubtleCrypto, libsodium) — those are out of scope per the
|
|
105
|
+
threat model in `spec/threat-model.md`.
|
|
106
|
+
- Theoretical attacks on the underlying primitives (AES, ChaCha20,
|
|
107
|
+
ML-KEM-1024) — these belong in the academic literature.
|
|
108
|
+
- Vulnerabilities that require an attacker to already control the user's
|
|
109
|
+
device.
|
|
110
|
+
|
|
111
|
+
## Cryptographic specifications
|
|
112
|
+
|
|
113
|
+
Implementation choices and threat model are documented in:
|
|
114
|
+
|
|
115
|
+
- [`spec/format-v1.md`](spec/format-v1.md) — wire format specification
|
|
116
|
+
- [`spec/format-v0.md`](spec/format-v0.md) — legacy format (read-only)
|
|
117
|
+
- [`spec/threat-model.md`](spec/threat-model.md) — adversary model and
|
|
118
|
+
comparisons
|
|
119
|
+
|
|
120
|
+
If your report concerns a property claimed in those documents not actually
|
|
121
|
+
holding, please cite the specific paragraph.
|
|
122
|
+
|
|
123
|
+
## Acknowledgements
|
|
124
|
+
|
|
125
|
+
(This list will be populated as reports come in. Researchers are credited
|
|
126
|
+
with their consent.)
|
|
127
|
+
|
|
128
|
+
---
|
|
129
|
+
|
|
130
|
+
Last updated: v1.0.0-alpha.7
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* v1 header builder and parser.
|
|
3
|
+
*
|
|
4
|
+
* The header is constructed without the MAC, then the MAC is computed
|
|
5
|
+
* with the content key, then the MAC is appended. On decode, the parser
|
|
6
|
+
* reads everything up to (but not including) the MAC, then the caller
|
|
7
|
+
* verifies the MAC before trusting any field.
|
|
8
|
+
*/
|
|
9
|
+
import { type ParsedHeader, type SuiteId } from '../internal/types.js';
|
|
10
|
+
export interface HeaderInputs {
|
|
11
|
+
suite: SuiteId;
|
|
12
|
+
fileId: Uint8Array;
|
|
13
|
+
chunkSize: number;
|
|
14
|
+
totalChunks: number;
|
|
15
|
+
plaintextSize: number;
|
|
16
|
+
suitePayload: Uint8Array;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Build the unauthenticated header bytes (everything before the MAC).
|
|
20
|
+
* The caller appends the MAC after deriving header_mac_key.
|
|
21
|
+
*/
|
|
22
|
+
export declare function buildHeaderUnauthenticated(input: HeaderInputs): Uint8Array;
|
|
23
|
+
/**
|
|
24
|
+
* Derive the per-file header MAC key from the content key + file_id.
|
|
25
|
+
*/
|
|
26
|
+
export declare function deriveHeaderMacKey(contentKey: Uint8Array, fileId: Uint8Array): Promise<Uint8Array>;
|
|
27
|
+
/**
|
|
28
|
+
* Build a complete authenticated header. `contentKey` is the suite-specific
|
|
29
|
+
* key used to authenticate the header. For the PQ-hybrid suite this is the
|
|
30
|
+
* combined key K (post-HKDF); for AES-GCM and XChaCha suites this is the
|
|
31
|
+
* raw 32-byte content key.
|
|
32
|
+
*/
|
|
33
|
+
export declare function buildAuthenticatedHeader(input: HeaderInputs, contentKey: Uint8Array): Promise<Uint8Array>;
|
|
34
|
+
/**
|
|
35
|
+
* Parse a header from a byte slice. Returns the parsed fields and the
|
|
36
|
+
* total bytes consumed. Does NOT verify the MAC — callers must call
|
|
37
|
+
* `verifyHeaderMac` separately, after deriving the key.
|
|
38
|
+
*
|
|
39
|
+
* Two-phase parse-then-verify keeps the parser usable for tooling that
|
|
40
|
+
* inspects encrypted files without holding the key.
|
|
41
|
+
*
|
|
42
|
+
* parseHeader does not verify the header MAC. For non-KEM suites
|
|
43
|
+
* (0x01 aes-gcm-v1, 0x02 xchacha-v1), callers MUST call
|
|
44
|
+
* verifyHeaderMac BEFORE doing anything with parsed.suitePayload,
|
|
45
|
+
* including length checks, field extraction, or downstream parsing.
|
|
46
|
+
* KEM suites (0x03 pq-hybrid-v1) cannot follow this rule by
|
|
47
|
+
* construction; see spec/format-v1.md § "0x03 — pq-hybrid" for the
|
|
48
|
+
* required ordering and security argument.
|
|
49
|
+
*
|
|
50
|
+
* Cross-field consistency (totalChunks / chunkSize / plaintextSize) is
|
|
51
|
+
* enforced here via `assertHeaderConsistency`. The same helper runs in
|
|
52
|
+
* `validateHeaderInputs` so encode and decode share one source of
|
|
53
|
+
* truth; both paths MUST stay in sync.
|
|
54
|
+
*/
|
|
55
|
+
export declare function parseHeader(input: Uint8Array): ParsedHeader & {
|
|
56
|
+
unauthenticatedBytes: Uint8Array;
|
|
57
|
+
mac: Uint8Array;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Verify the parsed header's MAC under the supplied content key.
|
|
61
|
+
* Throws on failure; returns the parsed header on success.
|
|
62
|
+
*/
|
|
63
|
+
export declare function verifyHeaderMac(parsed: ReturnType<typeof parseHeader>, contentKey: Uint8Array): Promise<void>;
|
|
64
|
+
/**
|
|
65
|
+
* Build the AAD bound into every chunk's AEAD: domain || index || total || is_final.
|
|
66
|
+
*/
|
|
67
|
+
export declare function buildChunkAad(chunkIndex: number, totalChunks: number, isFinal: boolean): Uint8Array;
|
|
68
|
+
/** Recognizable error class so callers can catch parse failures specifically */
|
|
69
|
+
export declare class HeaderError extends Error {
|
|
70
|
+
readonly code: string;
|
|
71
|
+
constructor(code: string);
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=header.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"header.d.ts","sourceRoot":"","sources":["../../src/format/header.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAUL,KAAK,YAAY,EAEjB,KAAK,OAAO,EACb,MAAM,sBAAsB,CAAA;AAkB7B,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,OAAO,CAAA;IACd,MAAM,EAAE,UAAU,CAAA;IAClB,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,EAAE,MAAM,CAAA;IACrB,YAAY,EAAE,UAAU,CAAA;CACzB;AAED;;;GAGG;AACH,wBAAgB,0BAA0B,CAAC,KAAK,EAAE,YAAY,GAAG,UAAU,CAa1E;AAED;;GAEG;AACH,wBAAsB,kBAAkB,CACtC,UAAU,EAAE,UAAU,EACtB,MAAM,EAAE,UAAU,GACjB,OAAO,CAAC,UAAU,CAAC,CAOrB;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,KAAK,EAAE,YAAY,EACnB,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,UAAU,CAAC,CAKrB;AAED;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,UAAU,GAAG,YAAY,GAAG;IAC7D,oBAAoB,EAAE,UAAU,CAAA;IAChC,GAAG,EAAE,UAAU,CAAA;CAChB,CA0EA;AAED;;;GAGG;AACH,wBAAsB,eAAe,CACnC,MAAM,EAAE,UAAU,CAAC,OAAO,WAAW,CAAC,EACtC,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,IAAI,CAAC,CAUf;AAED;;GAEG;AACH,wBAAgB,aAAa,CAC3B,UAAU,EAAE,MAAM,EAClB,WAAW,EAAE,MAAM,EACnB,OAAO,EAAE,OAAO,GACf,UAAU,CAaZ;AAqED,gFAAgF;AAChF,qBAAa,WAAY,SAAQ,KAAK;IACpC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;gBACT,IAAI,EAAE,MAAM;CAKzB"}
|