@shieldfive/crypto 1.0.0-alpha.12 → 1.0.0-alpha.14
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 +66 -0
- package/README.md +19 -10
- package/SECURITY.md +1 -1
- package/dist/identity/index.d.ts +14 -0
- package/dist/identity/index.d.ts.map +1 -1
- package/dist/identity/index.js +83 -21
- package/dist/identity/index.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/types.d.ts +1 -0
- package/dist/internal/types.d.ts.map +1 -1
- package/dist/internal/types.js +5 -0
- package/dist/internal/types.js.map +1 -1
- package/dist/suites/aes-gcm-v2/index.d.ts +6 -6
- package/dist/suites/aes-gcm-v2/index.js +6 -6
- package/dist/suites/pq-hybrid-v1/index.d.ts +4 -0
- package/dist/suites/pq-hybrid-v1/index.d.ts.map +1 -1
- package/dist/suites/pq-hybrid-v1/index.js +15 -1
- package/dist/suites/pq-hybrid-v1/index.js.map +1 -1
- package/package.json +1 -1
- package/spec/format-v1.md +85 -5
- package/spec/key-derivation.md +13 -0
- package/src/identity/index.ts +93 -27
- package/src/index.ts +1 -1
- package/src/internal/types.ts +5 -0
- package/src/suites/aes-gcm-v2/index.ts +6 -6
- package/src/suites/pq-hybrid-v1/index.ts +25 -4
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,72 @@ All notable changes to `@shieldfive/crypto` will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## 1.0.0-alpha.14 — 2026-06-10
|
|
9
|
+
|
|
10
|
+
> Pre-launch security hardening of the `0x03` PQ-hybrid share bundle. The
|
|
11
|
+
> share-bundle wire format changes; the on-disk file format and the `0x03`
|
|
12
|
+
> file decryption path are unchanged, so existing `cipher_version-3` files
|
|
13
|
+
> remain decryptable.
|
|
14
|
+
|
|
15
|
+
### Changed (BREAKING — share-bundle wire format only)
|
|
16
|
+
|
|
17
|
+
- **Share bundle (`0x03`) re-keyed and versioned (audit H2).** The share
|
|
18
|
+
transport key is now derived from the KEM/envelope secret under a dedicated
|
|
19
|
+
HKDF label `shieldfive/v1/share-transport` instead of reusing the
|
|
20
|
+
file-combiner label `shieldfive/v1/pq-hybrid/combine`, so a share transport
|
|
21
|
+
key can never equal a file's combined key. The combined key is now wrapped
|
|
22
|
+
with XChaCha20-Poly1305 whose AAD authenticates the **whole** bundle
|
|
23
|
+
(`magic || uint32_be(pq_len) || pq_payload || wrap_nonce`) rather than an
|
|
24
|
+
AAD-less secretbox that authenticated only the 32-byte key — PQ material
|
|
25
|
+
can no longer be substituted or stripped undetected. The bundle now carries
|
|
26
|
+
a `"SF5S"` + version-2 magic prefix so the hardened format is
|
|
27
|
+
distinguishable from (and not confusable with) the earlier unversioned one.
|
|
28
|
+
Share bundles produced by earlier alpha builds are rejected and must be
|
|
29
|
+
re-issued; no real shares exist pre-launch, so this is a clean break. See
|
|
30
|
+
`spec/format-v1.md` § "Share bundle".
|
|
31
|
+
|
|
32
|
+
### Security
|
|
33
|
+
|
|
34
|
+
- **Reserved-pad enforcement (`0x03`, audit M6).** The `0x03` suite-payload
|
|
35
|
+
parser now rejects a non-zero reserved pad in `classical_wrapped` (the 24
|
|
36
|
+
bytes after the 48-byte secretbox), closing a malleable unauthenticated
|
|
37
|
+
field. The default suite combine label and file path are unchanged.
|
|
38
|
+
|
|
39
|
+
### Documentation
|
|
40
|
+
|
|
41
|
+
- README/spec: corrected the "cross-file splice prevention (file_id AAD)"
|
|
42
|
+
table cell and prose — `file_id` is NOT in the chunk AAD; splice resistance
|
|
43
|
+
is structural via `file_id` as the HKDF salt in the chunk-key derivation
|
|
44
|
+
(audit INFO). Noted that the "no parallel implementation" scope is the
|
|
45
|
+
file-content cipher suites; the keyring/envelope layer uses WebCrypto
|
|
46
|
+
AES-GCM/HMAC directly.
|
|
47
|
+
- **Planned (not in this release): suite-id binding in `0x03` chunk derivation
|
|
48
|
+
(audit M5).** The `0x03` chunk-key / nonce-prefix derivations reuse the
|
|
49
|
+
`0x02` xchacha HKDF labels and do not bind the suite id. This is **not
|
|
50
|
+
exploitable** (the header MAC authenticates the suite byte) and is left
|
|
51
|
+
**unchanged** — production `cipher_version-3` files depend on it and would
|
|
52
|
+
become undecryptable if altered. A future suite version (a new suite id,
|
|
53
|
+
not `0x03`) will bind the suite id into the chunk derivation. Recorded in
|
|
54
|
+
`spec/format-v1.md` and `spec/key-derivation.md`.
|
|
55
|
+
|
|
56
|
+
### Tests
|
|
57
|
+
|
|
58
|
+
- Added share-bundle PQ-substitution/forgery, dedicated-transport-key,
|
|
59
|
+
non-zero reserved-pad rejection, and share-bundle version-marker tests
|
|
60
|
+
(182 → 188 passing).
|
|
61
|
+
|
|
62
|
+
## 1.0.0-alpha.13 — 2026-06-09
|
|
63
|
+
|
|
64
|
+
### Fixed
|
|
65
|
+
|
|
66
|
+
- `SHIELDFIVE_CRYPTO_VERSION` now reports the actual package version
|
|
67
|
+
(it was pinned at `1.0.0-alpha.11`). The constant is informational
|
|
68
|
+
only — it is never written into file output or any test vector.
|
|
69
|
+
- Corrected a backwards source comment in the `aes-gcm-v2` suite: the
|
|
70
|
+
cross-file nonce-prefix space *widens* from 2^32 to 2^64 (the comment
|
|
71
|
+
previously said "shrinks"). No behavior change — the README and
|
|
72
|
+
CHANGELOG already described it correctly as widening.
|
|
73
|
+
|
|
8
74
|
## 1.0.0-alpha.12 — 2026-06-09
|
|
9
75
|
|
|
10
76
|
### Documentation
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
> [ShieldFive](https://shieldfive.com), released as a standalone library.
|
|
6
6
|
|
|
7
7
|
[](LICENSE)
|
|
8
|
-
[](tests/)
|
|
9
9
|
[](#status)
|
|
10
10
|
|
|
11
11
|
## Status & honest scope
|
|
@@ -17,12 +17,17 @@ treat this library as a serious work-in-progress rather than a finished
|
|
|
17
17
|
product.
|
|
18
18
|
|
|
19
19
|
The design choices documented in [`spec/`](spec/) are deliberate and
|
|
20
|
-
reviewable. The implementation is covered by
|
|
20
|
+
reviewable. The implementation is covered by 188 passing tests including
|
|
21
21
|
truncation, reordering, splice, and tampering detection across all four
|
|
22
22
|
suites. That is enough for internal dogfooding. It is **not** enough to
|
|
23
23
|
claim "most secure crypto library" — that claim requires external review
|
|
24
24
|
this library has not yet received.
|
|
25
25
|
|
|
26
|
+
When this library says it avoids a parallel cryptographic implementation,
|
|
27
|
+
that scope is the file-content cipher suites. The keyring/envelope layer
|
|
28
|
+
that wraps content keys is built directly on WebCrypto AES-GCM and HMAC
|
|
29
|
+
(via `crypto.subtle`), not on a second hand-rolled implementation.
|
|
30
|
+
|
|
26
31
|
## Design positions
|
|
27
32
|
|
|
28
33
|
This library makes specific design choices that differ from existing
|
|
@@ -37,7 +42,7 @@ spec section that documents the choice.
|
|
|
37
42
|
| Self-describing on-disk file format | ✅ | ✅ | ⚠️ | ⚠️ |
|
|
38
43
|
| Cipher-suite agile (one byte selects) | ✅ | ⚠️ | ❌ | ❌ |
|
|
39
44
|
| Truncation detection bound to AEAD | ✅ | ✅ | ❌ | ❌ |
|
|
40
|
-
| Cross-file splice prevention (file_id
|
|
45
|
+
| Cross-file splice prevention (file_id via HKDF salt) | ✅ | ✅ | ❌ | ❌ |
|
|
41
46
|
| Streaming AEAD with random-access chunks | ✅ | ⚠️ | ✅ | ✅ |
|
|
42
47
|
| WebCrypto-only path (no WASM required) | ✅ | ❌ | ❌ | ❌ |
|
|
43
48
|
| Apache 2.0 (patent grant) | ✅ | ⚠️ (LGPL) | ⚠️ | ⚠️ |
|
|
@@ -151,9 +156,11 @@ ML-KEM-1024 secret for Suite 0x03 files deterministically from
|
|
|
151
156
|
the root key (per `spec/key-derivation.md`), and feeds each blob
|
|
152
157
|
into `autoDecryptBlob` here.
|
|
153
158
|
|
|
154
|
-
The recipe
|
|
155
|
-
|
|
156
|
-
|
|
159
|
+
The recipe lives at [shieldfive.com/export](https://shieldfive.com/export)
|
|
160
|
+
and the script ships in this repository as
|
|
161
|
+
[`examples/decrypt-one.mjs`](examples/decrypt-one.mjs), kept in
|
|
162
|
+
lock-step with the API surface; this library is the decryption
|
|
163
|
+
primitive the script depends on. If
|
|
157
164
|
you want to reproduce the path from first principles (with no
|
|
158
165
|
ShieldFive code in the loop), `spec/format-v1.md` and
|
|
159
166
|
`spec/key-derivation.md` together describe everything needed.
|
|
@@ -179,9 +186,11 @@ chunk_i := length_prefix(4) || AEAD-ciphertext-with-tag
|
|
|
179
186
|
```
|
|
180
187
|
|
|
181
188
|
Every chunk's AEAD authenticator binds the chunk index, total chunk count,
|
|
182
|
-
final-chunk flag
|
|
183
|
-
|
|
184
|
-
|
|
189
|
+
and final-chunk flag. The `file_id` is NOT part of the AAD; cross-file
|
|
190
|
+
splice resistance is structural, coming from the suite-specific chunk-key
|
|
191
|
+
and nonce-prefix derivations that mix `file_id` in as the HKDF salt/IKM.
|
|
192
|
+
Together these make truncation, reordering, and cross-file splicing
|
|
193
|
+
detectable by the AEAD rather than by application-layer hashes.
|
|
185
194
|
|
|
186
195
|
## Cipher suites
|
|
187
196
|
|
|
@@ -244,7 +253,7 @@ Requires Node 20+.
|
|
|
244
253
|
|
|
245
254
|
**Alpha.** The wire format is frozen for the v1 release, but the public
|
|
246
255
|
TypeScript API may make small adjustments before 1.0.0 stable. Test
|
|
247
|
-
coverage is comprehensive (
|
|
256
|
+
coverage is comprehensive (188 tests, all four suites, all architectural
|
|
248
257
|
guarantees verified). A formal third-party security audit is planned for
|
|
249
258
|
the 1.0.0 stable milestone — until that audit lands, treat this library
|
|
250
259
|
as a serious work-in-progress rather than a finished product.
|
package/SECURITY.md
CHANGED
package/dist/identity/index.d.ts
CHANGED
|
@@ -101,6 +101,20 @@ export interface ShareFileInput {
|
|
|
101
101
|
* key. To make sharing work, we use a different construction: we wrap
|
|
102
102
|
* the existing combined key under (recipient PQ KEM ⊕ recipient
|
|
103
103
|
* envelope) and emit only the wrapped form.
|
|
104
|
+
*
|
|
105
|
+
* Two properties this construction must hold (audit H2/M6):
|
|
106
|
+
* 1. The wrapping key is NOT the raw KEM/envelope combined key (which
|
|
107
|
+
* reuses the file-combiner HKDF label). We run it through one more
|
|
108
|
+
* HKDF under the dedicated `SHARE_TRANSPORT` label so a share key is
|
|
109
|
+
* never equal to a file's combined key.
|
|
110
|
+
* 2. The wrap authenticates the WHOLE bundle, not just the 32-byte
|
|
111
|
+
* combined key: the XChaCha20-Poly1305 AAD covers the version marker,
|
|
112
|
+
* the length prefix, the entire pqPayload (including its reserved pad)
|
|
113
|
+
* and the nonce, so PQ material cannot be substituted or stripped
|
|
114
|
+
* without breaking the tag.
|
|
115
|
+
*
|
|
116
|
+
* The bundle is prefixed with `SHARE_BUNDLE_MAGIC` ("SF5S" + version) so the
|
|
117
|
+
* hardened format is distinguishable from the earlier unversioned one.
|
|
104
118
|
*/
|
|
105
119
|
export declare function buildShareForRecipient(input: ShareFileInput): Promise<{
|
|
106
120
|
shareBundle: Uint8Array;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAWH,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,WAAW,CAAA;AAClB,YAAY,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAyB/C,MAAM,WAAW,oBAAoB;IACnC,0CAA0C;IAC1C,cAAc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K,EAAE,cAAc,GACpB,OAAO,CAAC;IAAE,WAAW,EAAE,UAAU,CAAA;CAAE,CAAC,CAwDtC;AAED;;;;GAIG;AACH,wBAAsB,oBAAoB,CAAC,KAAK,EAAE;IAChD,WAAW,EAAE,UAAU,CAAA;IACvB,MAAM,EAAE,UAAU,CAAA;IAClB,kBAAkB,EAAE,UAAU,CAAA;IAC9B,oBAAoB,EAAE,UAAU,CAAA;CACjC,GAAG,OAAO,CAAC,UAAU,CAAC,CAwEtB"}
|
package/dist/identity/index.js
CHANGED
|
@@ -17,12 +17,21 @@
|
|
|
17
17
|
* want stronger identity (e.g. SAS verification, gossiped signatures),
|
|
18
18
|
* they wrap this module rather than modify it.
|
|
19
19
|
*/
|
|
20
|
-
import { ML_KEM_1024_PUBLIC_KEY_BYTES, ML_KEM_1024_SECRET_KEY_BYTES, deriveMlKemKeypair, generateMlKemKeypair, encapsulateForRecipient, decapsulateFromHeader, parsePqHybridV1SuitePayload,
|
|
20
|
+
import { ML_KEM_1024_PUBLIC_KEY_BYTES, ML_KEM_1024_SECRET_KEY_BYTES, deriveMlKemKeypair, generateMlKemKeypair, encapsulateForRecipient, decapsulateFromHeader, parsePqHybridV1SuitePayload, } from '../suites/pq-hybrid-v1/index.js';
|
|
21
21
|
export { SIGNATURE_ALGO_ED25519, SIGNATURE_ALGO_ML_DSA_65, ED25519_PUBLIC_KEY_LENGTH, ED25519_SECRET_KEY_LENGTH, ED25519_SIGNATURE_LENGTH, SignatureError, buildSignatureBlock, deriveEd25519PublicKey, parseSignatureBlock, signHeaderAndMacs, verifyHeaderAndMacs, } from './sign.js';
|
|
22
22
|
import { bytesToBase64, base64ToBytes, concatBytes, uint16BE, uint32BE, readUint16BE, readUint32BE, } from '../internal/encoding.js';
|
|
23
23
|
import { randomBytes } from '../internal/runtime.js';
|
|
24
24
|
import { getSodium } from '../internal/sodium.js';
|
|
25
|
+
import { hkdfSha256 } from '../internal/hkdf.js';
|
|
26
|
+
import { HKDF_INFO } from '../internal/types.js';
|
|
25
27
|
const IDENTITY_BUNDLE_MAGIC = new Uint8Array([0x53, 0x46, 0x35, 0x49, 0x01]); // "SF5I" + version
|
|
28
|
+
// Share-bundle magic: "SF5S" + version byte. Version 0x02 marks the hardened
|
|
29
|
+
// share construction (audit H2/M6): a domain-separated transport key and an
|
|
30
|
+
// AEAD wrap whose AAD authenticates the whole bundle. Earlier alpha builds
|
|
31
|
+
// emitted an unversioned bundle (an AAD-less secretbox under the raw transport
|
|
32
|
+
// secret); those are NOT readable here and are rejected by the magic check.
|
|
33
|
+
// No real shares exist pre-launch, so this is a deliberate clean break.
|
|
34
|
+
const SHARE_BUNDLE_MAGIC = new Uint8Array([0x53, 0x46, 0x35, 0x53, 0x02]); // "SF5S" + version 2
|
|
26
35
|
/**
|
|
27
36
|
* Wire format for an identity bundle:
|
|
28
37
|
*
|
|
@@ -140,30 +149,60 @@ export async function createIdentity(options) {
|
|
|
140
149
|
* key. To make sharing work, we use a different construction: we wrap
|
|
141
150
|
* the existing combined key under (recipient PQ KEM ⊕ recipient
|
|
142
151
|
* envelope) and emit only the wrapped form.
|
|
152
|
+
*
|
|
153
|
+
* Two properties this construction must hold (audit H2/M6):
|
|
154
|
+
* 1. The wrapping key is NOT the raw KEM/envelope combined key (which
|
|
155
|
+
* reuses the file-combiner HKDF label). We run it through one more
|
|
156
|
+
* HKDF under the dedicated `SHARE_TRANSPORT` label so a share key is
|
|
157
|
+
* never equal to a file's combined key.
|
|
158
|
+
* 2. The wrap authenticates the WHOLE bundle, not just the 32-byte
|
|
159
|
+
* combined key: the XChaCha20-Poly1305 AAD covers the version marker,
|
|
160
|
+
* the length prefix, the entire pqPayload (including its reserved pad)
|
|
161
|
+
* and the nonce, so PQ material cannot be substituted or stripped
|
|
162
|
+
* without breaking the tag.
|
|
163
|
+
*
|
|
164
|
+
* The bundle is prefixed with `SHARE_BUNDLE_MAGIC` ("SF5S" + version) so the
|
|
165
|
+
* hardened format is distinguishable from the earlier unversioned one.
|
|
143
166
|
*/
|
|
144
167
|
export async function buildShareForRecipient(input) {
|
|
145
168
|
const sodium = await getSodium();
|
|
146
|
-
// Generate a fresh transport
|
|
169
|
+
// Generate a fresh transport secret for this share.
|
|
147
170
|
// ML-KEM encapsulation gives us the PQ-half of the transport secret.
|
|
148
|
-
const { suitePayload: pqPayload, combinedKey:
|
|
171
|
+
const { suitePayload: pqPayload, combinedKey: transportSecret } = await encapsulateForRecipient({
|
|
149
172
|
recipientPublicKey: input.recipient.mlKemPublicKey,
|
|
150
173
|
envelopeKey: input.recipientEnvelopeKey,
|
|
151
174
|
fileId: input.fileId,
|
|
152
175
|
});
|
|
153
|
-
|
|
154
|
-
// XSalsa20-Poly1305 secretbox.
|
|
155
|
-
if (transportKey.length !== 32) {
|
|
176
|
+
if (transportSecret.length !== 32) {
|
|
156
177
|
throw new Error('buildShareForRecipient: transport key length wrong');
|
|
157
178
|
}
|
|
179
|
+
// (1) Domain-separate the share transport key from the file-combiner output.
|
|
180
|
+
const shareTransportKey = await hkdfSha256({
|
|
181
|
+
ikm: transportSecret,
|
|
182
|
+
salt: input.fileId,
|
|
183
|
+
info: HKDF_INFO.SHARE_TRANSPORT,
|
|
184
|
+
length: 32,
|
|
185
|
+
});
|
|
186
|
+
// (2) Wrap the original combined key with an AEAD whose AAD authenticates
|
|
187
|
+
// the whole bundle prefix (magic || length || pqPayload || nonce). Binding
|
|
188
|
+
// the magic means the version marker cannot be stripped or downgraded
|
|
189
|
+
// without breaking the tag.
|
|
158
190
|
const wrapNonce = randomBytes(24);
|
|
159
|
-
const
|
|
191
|
+
const aad = concatBytes([
|
|
192
|
+
SHARE_BUNDLE_MAGIC,
|
|
193
|
+
uint32BE(pqPayload.length),
|
|
194
|
+
pqPayload,
|
|
195
|
+
wrapNonce,
|
|
196
|
+
]);
|
|
197
|
+
const wrappedCombinedKey = sodium.crypto_aead_xchacha20poly1305_ietf_encrypt(input.combinedKey, aad, null, wrapNonce, shareTransportKey);
|
|
160
198
|
if (wrappedCombinedKey.length !== 32 + 16) {
|
|
161
|
-
throw new Error('buildShareForRecipient:
|
|
199
|
+
throw new Error('buildShareForRecipient: AEAD produced unexpected length');
|
|
162
200
|
}
|
|
163
201
|
// Share record format:
|
|
164
|
-
// [4 bytes BE length of pqPayload][pqPayload][24-byte wrap nonce][48-byte wrapped combined key]
|
|
202
|
+
// [5-byte magic][4 bytes BE length of pqPayload][pqPayload][24-byte wrap nonce][48-byte wrapped combined key]
|
|
165
203
|
return {
|
|
166
204
|
shareBundle: concatBytes([
|
|
205
|
+
SHARE_BUNDLE_MAGIC,
|
|
167
206
|
uint32BE(pqPayload.length),
|
|
168
207
|
pqPayload,
|
|
169
208
|
wrapNonce,
|
|
@@ -178,10 +217,18 @@ export async function buildShareForRecipient(input) {
|
|
|
178
217
|
*/
|
|
179
218
|
export async function openShareAsRecipient(input) {
|
|
180
219
|
const sodium = await getSodium();
|
|
181
|
-
if (input.shareBundle.length < 4) {
|
|
220
|
+
if (input.shareBundle.length < SHARE_BUNDLE_MAGIC.length + 4) {
|
|
182
221
|
throw new Error('openShareAsRecipient: share too short');
|
|
183
222
|
}
|
|
184
|
-
|
|
223
|
+
// Reject anything that isn't a current ("SF5S" + version) share bundle.
|
|
224
|
+
// Earlier-alpha unversioned bundles fail here rather than producing an
|
|
225
|
+
// opaque authentication error later.
|
|
226
|
+
for (let i = 0; i < SHARE_BUNDLE_MAGIC.length; i += 1) {
|
|
227
|
+
if (input.shareBundle[i] !== SHARE_BUNDLE_MAGIC[i]) {
|
|
228
|
+
throw new Error('openShareAsRecipient: bad magic / unsupported share bundle version');
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
let offset = SHARE_BUNDLE_MAGIC.length;
|
|
185
232
|
const pqLen = readUint32BE(input.shareBundle, offset);
|
|
186
233
|
offset += 4;
|
|
187
234
|
if (offset + pqLen + 24 + 48 !== input.shareBundle.length) {
|
|
@@ -192,22 +239,37 @@ export async function openShareAsRecipient(input) {
|
|
|
192
239
|
const wrapNonce = input.shareBundle.slice(offset, offset + 24);
|
|
193
240
|
offset += 24;
|
|
194
241
|
const wrappedCombinedKey = input.shareBundle.slice(offset, offset + 48);
|
|
195
|
-
//
|
|
242
|
+
// Structurally validate the suite payload. This rejects a non-zero reserved
|
|
243
|
+
// pad in classical_wrapped (M6) before any decapsulation work.
|
|
196
244
|
parsePqHybridV1SuitePayload(pqPayload);
|
|
197
|
-
|
|
198
|
-
const checkBytes = buildPqHybridV1SuitePayload(parsePqHybridV1SuitePayload(pqPayload));
|
|
199
|
-
if (checkBytes.length !== pqPayload.length) {
|
|
200
|
-
throw new Error('openShareAsRecipient: pq payload self-check failed');
|
|
201
|
-
}
|
|
202
|
-
const { combinedKey: transportKey } = await decapsulateFromHeader({
|
|
245
|
+
const { combinedKey: transportSecret } = await decapsulateFromHeader({
|
|
203
246
|
suitePayload: pqPayload,
|
|
204
247
|
recipientSecretKey: input.recipientSecretKey,
|
|
205
248
|
envelopeKey: input.recipientEnvelopeKey,
|
|
206
249
|
fileId: input.fileId,
|
|
207
250
|
});
|
|
208
|
-
const
|
|
209
|
-
|
|
210
|
-
|
|
251
|
+
const shareTransportKey = await hkdfSha256({
|
|
252
|
+
ikm: transportSecret,
|
|
253
|
+
salt: input.fileId,
|
|
254
|
+
info: HKDF_INFO.SHARE_TRANSPORT,
|
|
255
|
+
length: 32,
|
|
256
|
+
});
|
|
257
|
+
// The AAD must reproduce exactly what the builder authenticated: it binds
|
|
258
|
+
// the version marker, the length prefix, the whole pqPayload (incl. reserved
|
|
259
|
+
// pad) and the nonce, so any substitution/stripping of PQ material breaks
|
|
260
|
+
// the tag.
|
|
261
|
+
const aad = concatBytes([
|
|
262
|
+
SHARE_BUNDLE_MAGIC,
|
|
263
|
+
uint32BE(pqPayload.length),
|
|
264
|
+
pqPayload,
|
|
265
|
+
wrapNonce,
|
|
266
|
+
]);
|
|
267
|
+
let unwrapped;
|
|
268
|
+
try {
|
|
269
|
+
unwrapped = sodium.crypto_aead_xchacha20poly1305_ietf_decrypt(null, wrappedCombinedKey, aad, wrapNonce, shareTransportKey);
|
|
270
|
+
}
|
|
271
|
+
catch {
|
|
272
|
+
throw new Error('openShareAsRecipient: share authentication failed — wrong recipient or tampered share');
|
|
211
273
|
}
|
|
212
274
|
if (unwrapped.length !== 32) {
|
|
213
275
|
throw new Error('openShareAsRecipient: bad combined key length');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC5B,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACvB,qBAAqB,EACrB,2BAA2B,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/identity/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,EACL,4BAA4B,EAC5B,4BAA4B,EAC5B,kBAAkB,EAClB,oBAAoB,EACpB,uBAAuB,EACvB,qBAAqB,EACrB,2BAA2B,GAC5B,MAAM,iCAAiC,CAAA;AACxC,OAAO,EACL,sBAAsB,EACtB,wBAAwB,EACxB,yBAAyB,EACzB,yBAAyB,EACzB,wBAAwB,EACxB,cAAc,EACd,mBAAmB,EACnB,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,WAAW,CAAA;AAElB,OAAO,EACL,aAAa,EACb,aAAa,EACb,WAAW,EACX,QAAQ,EACR,QAAQ,EACR,YAAY,EACZ,YAAY,GACb,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,MAAM,wBAAwB,CAAA;AACpD,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjD,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAA;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AAEhD,MAA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CAAC;QACzC,GAAG,EAAE,eAAe;QACpB,IAAI,EAAE,KAAK,CAAC,MAAM;QAClB,IAAI,EAAE,SAAS,CAAC,eAAe;QAC/B,MAAM,EAAE,EAAE;KACX,CAAC,CAAA;IAEF,0EAA0E;IAC1E,6EAA6E;IAC7E,0EAA0E;IAC1E,WAAW;IACX,MAAM,GAAG,GAAG,WAAW,CAAC;QACtB,kBAAkB;QAClB,QAAQ,CAAC,SAAS,CAAC,MAAM,CAAC;QAC1B,SAAS;QACT,SAAS;KACV,CAAC,CAAA;IACF,IAAI,SAAqB,CAAA;IACzB,IAAI,CAAC;QACH,SAAS,GAAG,MAAM,CAAC,0CAA0C,CAC3D,IAAI,EACJ,kBAAkB,EAClB,GAAG,EACH,SAAS,EACT,iBAAiB,CAClB,CAAA;IACH,CAAC;IAAC,MAAM,CAAC;QACP,MAAM,IAAI,KAAK,CACb,uFAAuF,CACxF,CAAA;IACH,CAAC;IACD,IAAI,SAAS,CAAC,MAAM,KAAK,EAAE,EAAE,CAAC;QAC5B,MAAM,IAAI,KAAK,CAAC,+CAA+C,CAAC,CAAA;IAClE,CAAC;IACD,OAAO,IAAI,UAAU,CAAC,SAAS,CAAC,CAAA;AAClC,CAAC"}
|
package/dist/index.d.ts
CHANGED
|
@@ -52,7 +52,7 @@ export interface AutoDecryptOptions {
|
|
|
52
52
|
*/
|
|
53
53
|
export declare function autoDecryptBlob(options: AutoDecryptOptions): Promise<Blob>;
|
|
54
54
|
/** Library version, also written into format documentation. */
|
|
55
|
-
export declare const SHIELDFIVE_CRYPTO_VERSION = "1.0.0-alpha.
|
|
55
|
+
export declare const SHIELDFIVE_CRYPTO_VERSION = "1.0.0-alpha.14";
|
|
56
56
|
/** Default cipher suite for new files when not specified by the caller. */
|
|
57
57
|
export declare const DEFAULT_SUITE: 3;
|
|
58
58
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -140,7 +140,7 @@ export async function autoDecryptBlob(options) {
|
|
|
140
140
|
}
|
|
141
141
|
}
|
|
142
142
|
/** Library version, also written into format documentation. */
|
|
143
|
-
export const SHIELDFIVE_CRYPTO_VERSION = '1.0.0-alpha.
|
|
143
|
+
export const SHIELDFIVE_CRYPTO_VERSION = '1.0.0-alpha.14';
|
|
144
144
|
/** Default cipher suite for new files when not specified by the caller. */
|
|
145
145
|
export const DEFAULT_SUITE = SUITE.PQ_HYBRID_XCHACHA_MLKEM1024_V1;
|
|
146
146
|
//# sourceMappingURL=index.js.map
|
package/dist/internal/types.d.ts
CHANGED
|
@@ -55,6 +55,7 @@ export declare const HKDF_INFO: Readonly<{
|
|
|
55
55
|
XCHACHA_NONCE_PREFIX: "shieldfive/v1/xchacha/nonce-prefix";
|
|
56
56
|
PQ_HYBRID_COMBINE: "shieldfive/v1/pq-hybrid/combine";
|
|
57
57
|
ML_KEM_1024_SEED: "shieldfive/v1/pq-hybrid/ml-kem-1024-seed";
|
|
58
|
+
SHARE_TRANSPORT: "shieldfive/v1/share-transport";
|
|
58
59
|
ARGON2ID_SALT_COMPRESSION: "shieldfive/v1/argon2id/salt-compression";
|
|
59
60
|
}>;
|
|
60
61
|
/** AAD domain string mixed into every chunk's authenticator */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,MAAM,MAAM,MAAM,GAAG;IACnB,MAAM,EAAE,YAAY,CAAA;IACpB,eAAe,CAAC,CAAC,SAAS,eAAe,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAAA;CACxD,CAAA;AAED,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,YAAY,CAAA;AAElD;;;GAGG;AACH,eAAO,MAAM,KAAK;;;;;CAKR,CAAA;AAEV,MAAM,MAAM,OAAO,GAAG,CAAC,OAAO,KAAK,CAAC,CAAC,MAAM,OAAO,KAAK,CAAC,CAAA;AAExD,MAAM,MAAM,SAAS,GACjB,gBAAgB,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ive/v1/pq-hybrid/combine',
|
|
64
64
|
ML_KEM_1024_SEED: 'shieldfive/v1/pq-hybrid/ml-kem-1024-seed',
|
|
65
|
+
// Re-encrypting a file's combined key to a share recipient wraps it under a
|
|
66
|
+
// transport key derived with THIS label, distinct from the file-combiner
|
|
67
|
+
// label above, so a share transport key is never equal to a file's
|
|
68
|
+
// combined key for the same (recipient, envelope, file_id).
|
|
69
|
+
SHARE_TRANSPORT: 'shieldfive/v1/share-transport',
|
|
65
70
|
ARGON2ID_SALT_COMPRESSION: 'shieldfive/v1/argon2id/salt-compression',
|
|
66
71
|
});
|
|
67
72
|
/** AAD domain string mixed into every chunk's authenticator */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/internal/types.ts"],"names":[],"mappings":"AAAA;;GAEG;AASH;;;GAGG;AACH,MAAM,CAAC,MAAM,KAAK,GAAG;IACnB,cAAc,EAAE,IAAI;IACpB,qBAAqB,EAAE,IAAI;IAC3B,8BAA8B,EAAE,IAAI;IACpC,cAAc,EAAE,IAAI;CACZ,CAAA;AAUV,MAAM,CAAC,MAAM,WAAW,GAA+B;IACrD,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE,gBAAgB;IACxC,CAAC,KAAK,CAAC,qBAAqB,CAAC,EAAE,uBAAuB;IACtD,CAAC,KAAK,CAAC,8BAA8B,CAAC,EAAE,gCAAgC;IACxE,CAAC,KAAK,CAAC,cAAc,CAAC,EAAE,gBAAgB;CACzC,CAAA;AAED;;;GAGG;AACH,MAAM,CAAC,MAAM,YAAY,GAAe,IAAI,UAAU,CAAC;IACrD,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI;CAC7B,CAAC,CAAA;AAEF,MAAM,CAAC,MAAM,mBAAmB,GAAG,CAAC,CAAA;AAEpC,iDAAiD;AACjD,MAAM,CAAC,MAAM,YAAY,GAAG,MAAM,CAAC,MAAM,CAAC;IACxC,KAAK,EAAE,CAAC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EhC,gEAAgE;AAChE,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAAC,GAAG,IAAI,GAAG,IAAI,CAAA;AAEjD,8DAA8D;AAC9D,MAAM,CAAC,MAAM,cAAc,GAAG,WAAW,CAAA;AAEzC,+EAA+E;AAC/E,MAAM,CAAC,MAAM,gBAAgB,GAAG,aAAa,CAAA;AAE7C,gFAAgF;AAChF,MAAM,CAAC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC;IACrC,UAAU,EAAE,0BAA0B;IACtC,iBAAiB,EAAE,iCAAiC;IACpD,oBAAoB,EAAE,oCAAoC;IAC1D,uBAAuB,EAAE,uCAAuC;IAChE,iBAAiB,EAAE,iCAAiC;IACpD,oBAAoB,EAAE,oCAAoC;IAC1D,iBAAiB,EAAE,iCAAiC;IACpD,gBAAgB,EAAE,0CAA0C;IAC5D,4EAA4E;IAC5E,yEAAyE;IACzE,mEAAmE;IACnE,4DAA4D;IAC5D,eAAe,EAAE,+BAA+B;IAChD,yBAAyB,EAAE,yCAAyC;CACrE,CAAC,CAAA;AAEF,+DAA+D;AAC/D,MAAM,CAAC,MAAM,gBAAgB,GAAG,qBAAqB,CAAA;AACrD,MAAM,CAAC,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,MAAM,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAA"}
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
* Per-file content key. Per-chunk AEAD with file_id-bound AAD that
|
|
5
5
|
* authenticates chunk index, total chunks, and the is-final flag. The
|
|
6
6
|
* 12-byte GCM IV is split into an 8-byte file-derived prefix and a 4-byte
|
|
7
|
-
* big-endian counter — a wider prefix than v1 (0x01) so the
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* 2^64 to 2^32 chunks, which is still well above any
|
|
11
|
-
* the format permits (`MAX_TOTAL_CHUNKS` is 1e9 and
|
|
12
|
-
* safe JS integer).
|
|
7
|
+
* big-endian counter — a wider prefix than v1 (0x01) so the cross-file
|
|
8
|
+
* nonce-prefix space widens from 2^32 to 2^64, shrinking the chance of an
|
|
9
|
+
* IV collision across files that share a content key. The per-file chunk
|
|
10
|
+
* ceiling drops from 2^64 to 2^32 chunks, which is still well above any
|
|
11
|
+
* practical bound the format permits (`MAX_TOTAL_CHUNKS` is 1e9 and
|
|
12
|
+
* `chunkIndex` is a safe JS integer).
|
|
13
13
|
*/
|
|
14
14
|
import { type ParsedHeader } from '../../internal/types.js';
|
|
15
15
|
export declare const AES_GCM_V2_TAG_BYTES = 16;
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
* Per-file content key. Per-chunk AEAD with file_id-bound AAD that
|
|
5
5
|
* authenticates chunk index, total chunks, and the is-final flag. The
|
|
6
6
|
* 12-byte GCM IV is split into an 8-byte file-derived prefix and a 4-byte
|
|
7
|
-
* big-endian counter — a wider prefix than v1 (0x01) so the
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* 2^64 to 2^32 chunks, which is still well above any
|
|
11
|
-
* the format permits (`MAX_TOTAL_CHUNKS` is 1e9 and
|
|
12
|
-
* safe JS integer).
|
|
7
|
+
* big-endian counter — a wider prefix than v1 (0x01) so the cross-file
|
|
8
|
+
* nonce-prefix space widens from 2^32 to 2^64, shrinking the chance of an
|
|
9
|
+
* IV collision across files that share a content key. The per-file chunk
|
|
10
|
+
* ceiling drops from 2^64 to 2^32 chunks, which is still well above any
|
|
11
|
+
* practical bound the format permits (`MAX_TOTAL_CHUNKS` is 1e9 and
|
|
12
|
+
* `chunkIndex` is a safe JS integer).
|
|
13
13
|
*/
|
|
14
14
|
import { buildChunkAad } from '../../format/header.js';
|
|
15
15
|
import { HKDF_INFO, HEADER_SIZES, } from '../../internal/types.js';
|
|
@@ -31,6 +31,10 @@ export declare const ML_KEM_1024_SECRET_KEY_BYTES = 3168;
|
|
|
31
31
|
* classical_wrapped (72 bytes — 48 bytes secretbox + 24 bytes reserved zero pad)
|
|
32
32
|
* classical_nonce (24 bytes)
|
|
33
33
|
* Total: 1664 bytes
|
|
34
|
+
*
|
|
35
|
+
* The 24 reserved pad bytes (offsets 48..72 of classical_wrapped) MUST be
|
|
36
|
+
* zero. The parser rejects a non-zero pad (audit M6) so the field cannot be
|
|
37
|
+
* used as a malleable, unauthenticated side channel.
|
|
34
38
|
*/
|
|
35
39
|
export declare const PQ_HYBRID_V1_SUITE_PAYLOAD_LENGTH: number;
|
|
36
40
|
export interface PqHybridV1SuitePayload {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/suites/pq-hybrid-v1/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,yBAAyB,CAAA;AAMhC,eAAO,MAAM,sBAAsB,KAAK,CAAA;AACxC,eAAO,MAAM,wBAAwB,KAAK,CAAA;AAC1C,eAAO,MAAM,sBAAsB,KAAK,CAAA;AAExC,kDAAkD;AAClD,eAAO,MAAM,4BAA4B,OAAO,CAAA;AAChD,kDAAkD;AAClD,eAAO,MAAM,4BAA4B,OAAO,CAAA;AAChD,kDAAkD;AAClD,eAAO,MAAM,4BAA4B,OAAO,CAAA;AAEhD
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/suites/pq-hybrid-v1/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAKH,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,yBAAyB,CAAA;AAMhC,eAAO,MAAM,sBAAsB,KAAK,CAAA;AACxC,eAAO,MAAM,wBAAwB,KAAK,CAAA;AAC1C,eAAO,MAAM,sBAAsB,KAAK,CAAA;AAExC,kDAAkD;AAClD,eAAO,MAAM,4BAA4B,OAAO,CAAA;AAChD,kDAAkD;AAClD,eAAO,MAAM,4BAA4B,OAAO,CAAA;AAChD,kDAAkD;AAClD,eAAO,MAAM,4BAA4B,OAAO,CAAA;AAEhD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AAC,CA2CjE;AAED;;GAEG;AACH,wBAAsB,qBAAqB,CAAC,OAAO,EAAE;IACnD,YAAY,EAAE,UAAU,CAAA;IACxB,kBAAkB,EAAE,UAAU,CAAA;IAC9B,WAAW,EAAE,UAAU,CAAA;IACvB,MAAM,EAAE,UAAU,CAAA;CACnB,GAAG,OAAO,CAAC;IAAE,WAAW,EAAE,UAAU,CAAA;CAAE,CAAC,CAqCvC;AAED,wBAAsB,kBAAkB,CACtC,WAAW,EAAE,UAAU,EACvB,MAAM,EAAE,UAAU,EAClB,WAAW,EAAE,MAAM,GAClB,OAAO,CAAC,sBAAsB,CAAC,CAEjC;AAED,wBAAgB,yBAAyB,CACvC,MAAM,EAAE,YAAY,GACnB,sBAAsB,CAExB"}
|
|
@@ -37,8 +37,14 @@ export const ML_KEM_1024_SECRET_KEY_BYTES = 3168;
|
|
|
37
37
|
* classical_wrapped (72 bytes — 48 bytes secretbox + 24 bytes reserved zero pad)
|
|
38
38
|
* classical_nonce (24 bytes)
|
|
39
39
|
* Total: 1664 bytes
|
|
40
|
+
*
|
|
41
|
+
* The 24 reserved pad bytes (offsets 48..72 of classical_wrapped) MUST be
|
|
42
|
+
* zero. The parser rejects a non-zero pad (audit M6) so the field cannot be
|
|
43
|
+
* used as a malleable, unauthenticated side channel.
|
|
40
44
|
*/
|
|
41
45
|
export const PQ_HYBRID_V1_SUITE_PAYLOAD_LENGTH = ML_KEM_1024_CIPHERTEXT_BYTES + 72 + 24;
|
|
46
|
+
/** Bytes of real secretbox at the start of the 72-byte classical_wrapped field. */
|
|
47
|
+
const CLASSICAL_WRAPPED_SECRETBOX_BYTES = 48;
|
|
42
48
|
export function buildPqHybridV1SuitePayload(payload) {
|
|
43
49
|
if (payload.mlkemCiphertext.length !== ML_KEM_1024_CIPHERTEXT_BYTES) {
|
|
44
50
|
throw new RangeError('pq-hybrid-v1: mlkemCiphertext must be 1568 bytes');
|
|
@@ -59,9 +65,17 @@ export function parsePqHybridV1SuitePayload(bytes) {
|
|
|
59
65
|
if (bytes.length !== PQ_HYBRID_V1_SUITE_PAYLOAD_LENGTH) {
|
|
60
66
|
throw new RangeError(`pq-hybrid-v1: suite payload must be ${PQ_HYBRID_V1_SUITE_PAYLOAD_LENGTH} bytes`);
|
|
61
67
|
}
|
|
68
|
+
const classicalWrapped = bytes.slice(ML_KEM_1024_CIPHERTEXT_BYTES, ML_KEM_1024_CIPHERTEXT_BYTES + 72);
|
|
69
|
+
// M6: the 24-byte reserved pad after the 48-byte secretbox MUST be all
|
|
70
|
+
// zero. Reject otherwise so the field cannot carry unauthenticated bytes.
|
|
71
|
+
for (let i = CLASSICAL_WRAPPED_SECRETBOX_BYTES; i < classicalWrapped.length; i += 1) {
|
|
72
|
+
if (classicalWrapped[i] !== 0) {
|
|
73
|
+
throw new RangeError('pq-hybrid-v1: reserved classical_wrapped pad must be zero');
|
|
74
|
+
}
|
|
75
|
+
}
|
|
62
76
|
return {
|
|
63
77
|
mlkemCiphertext: bytes.slice(0, ML_KEM_1024_CIPHERTEXT_BYTES),
|
|
64
|
-
classicalWrapped
|
|
78
|
+
classicalWrapped,
|
|
65
79
|
classicalNonce: bytes.slice(ML_KEM_1024_CIPHERTEXT_BYTES + 72, PQ_HYBRID_V1_SUITE_PAYLOAD_LENGTH),
|
|
66
80
|
};
|
|
67
81
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/suites/pq-hybrid-v1/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,+BAA+B,CAAA;AAE1D,OAAO,EAAE,aAAa,EAAE,MAAM,wBAAwB,CAAA;AACtD,OAAO,EACL,SAAS,EACT,YAAY,GAEb,MAAM,yBAAyB,CAAA;AAChC,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAA;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CA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ED,MAAM,MAAM,GAAG,2BAA2B,CAAC,YAAY,CAAC,CAAA;IAExD,uBAAuB;IACvB,MAAM,OAAO,GAAG,UAAU,CAAC,WAAW,CACpC,MAAM,CAAC,eAAe,EACtB,kBAAkB,CACnB,CAAA;IAED,uBAAuB;IACvB,MAAM,SAAS,GAAG,MAAM,CAAC,gBAAgB,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAA;IACtD,MAAM,cAAc,GAAG,MAAM,CAAC,0BAA0B,CACtD,SAAS,EACT,MAAM,CAAC,cAAc,EACrB,WAAW,CACZ,CAAA;IACD,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CAAC,sCAAsC,CAAC,CAAA;IACzD,CAAC;IAED,cAAc;IACd,MAAM,WAAW,GAAG,MAAM,WAAW,CAAC,cAAc,EAAE,OAAO,EAAE,MAAM,CAAC,CAAA;IAEtE,OAAO,EAAE,WAAW,EAAE,CAAA;AACxB,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,WAAuB,EACvB,MAAkB,EAClB,WAAmB;IAEnB,OAAO,kBAAkB,CAAC,WAAW,EAAE,MAAM,EAAE,WAAW,CAAC,CAAA;AAC7D,CAAC;AAED,MAAM,UAAU,yBAAyB,CACvC,MAAoB;IAEpB,OAAO,2BAA2B,CAAC,MAAM,CAAC,YAAY,CAAC,CAAA;AACzD,CAAC"}
|
package/package.json
CHANGED
package/spec/format-v1.md
CHANGED
|
@@ -214,10 +214,18 @@ wrapped key from the out-of-band channel. The field length is fixed at
|
|
|
214
214
|
|
|
215
215
|
```
|
|
216
216
|
suite_payload := mlkem_ciphertext (1568 bytes) = ML-KEM-1024 ciphertext
|
|
217
|
-
|| classical_wrapped (72 bytes) = secretbox-wrapped
|
|
217
|
+
|| classical_wrapped (72 bytes) = 48-byte secretbox-wrapped
|
|
218
|
+
classical share || 24-byte
|
|
219
|
+
reserved pad
|
|
218
220
|
|| classical_nonce (24 bytes) = secretbox nonce for classical wrap
|
|
219
221
|
```
|
|
220
222
|
|
|
223
|
+
`classical_wrapped` is a fixed 72 bytes: the first 48 are the
|
|
224
|
+
XSalsa20-Poly1305 secretbox of the 32-byte classical share, and the
|
|
225
|
+
trailing 24 bytes are a reserved pad that MUST be all-zero. Readers MUST
|
|
226
|
+
reject a suite payload whose reserved pad is non-zero, so the field
|
|
227
|
+
cannot be used as a malleable, unauthenticated side channel.
|
|
228
|
+
|
|
221
229
|
The recipient holds:
|
|
222
230
|
|
|
223
231
|
- A classical key `K_c` (32 bytes), wrapped at the envelope layer like the
|
|
@@ -233,10 +241,25 @@ Encryption:
|
|
|
233
241
|
3. Combined content key `K = HKDF-SHA-256(ikm = S_c || S_pq, salt = file_id,
|
|
234
242
|
info = "shieldfive/v1/pq-hybrid/combine", L = 32)`.
|
|
235
243
|
4. Sender wraps `S_c` with `K_c` using XSalsa20-Poly1305 secretbox to
|
|
236
|
-
produce
|
|
237
|
-
`
|
|
238
|
-
|
|
239
|
-
|
|
244
|
+
produce the 48-byte secretbox, then left-pads it into the 72-byte
|
|
245
|
+
`classical_wrapped` field with a 24-byte all-zero reserved pad. (The PQ
|
|
246
|
+
share is recovered from `mlkem_ciphertext` via decapsulation; only the
|
|
247
|
+
classical share needs wrapping.)
|
|
248
|
+
5. Subsequent chunks use the XChaCha20-Poly1305 chunk format with `K`. The
|
|
249
|
+
chunk-key and nonce-prefix derivations are identical to the `0x02`
|
|
250
|
+
XChaCha suite's, with `K` in the role of the content key. See
|
|
251
|
+
`spec/key-derivation.md` for why reusing those labels is safe here.
|
|
252
|
+
|
|
253
|
+
> **Planned hardening — suite-id binding (audit M5, future suite version).**
|
|
254
|
+
> The `0x03` chunk-key / nonce-prefix derivations currently reuse the `0x02`
|
|
255
|
+
> XChaCha HKDF labels and do not fold the suite id into the IKM. This is
|
|
256
|
+
> **not exploitable**: the header MAC authenticates the suite byte, so a
|
|
257
|
+
> `0x02` and a `0x03` file are never interchangeable in practice. The
|
|
258
|
+
> `0x03` derivation is intentionally left **unchanged** here — production
|
|
259
|
+
> `cipher_version-3` files already exist and depend on it, and altering it
|
|
260
|
+
> would render them undecryptable. A future suite version (a new suite id,
|
|
261
|
+
> not `0x03`) will additionally bind the suite id into the chunk-key
|
|
262
|
+
> derivation; this document will be updated when that suite is defined.
|
|
240
263
|
|
|
241
264
|
Decryption:
|
|
242
265
|
|
|
@@ -301,6 +324,63 @@ decapsulation) and therefore cannot be stored out-of-band. The full
|
|
|
301
324
|
1664-byte `suite_payload` MUST be present inline in every PQ-hybrid
|
|
302
325
|
file.
|
|
303
326
|
|
|
327
|
+
#### Share bundle (re-encrypting `K` to another recipient)
|
|
328
|
+
|
|
329
|
+
Sharing a `0x03` file with an additional recipient does not re-encrypt the
|
|
330
|
+
chunks. The owner recovers the file's combined key `K` and produces a
|
|
331
|
+
per-recipient *share bundle* that re-wraps `K` to the recipient's ML-KEM
|
|
332
|
+
public key + envelope key. The share bundle is an application-layer record
|
|
333
|
+
(it is not part of the on-disk file), but its wire format is specified here
|
|
334
|
+
because it carries `0x03` key material. It carries its own magic and version
|
|
335
|
+
byte (`magic`, below) — distinct from the `SF5` file magic — so the hardened
|
|
336
|
+
format is unambiguously distinguishable from the earlier unversioned one.
|
|
337
|
+
|
|
338
|
+
```
|
|
339
|
+
share_bundle := magic (5 bytes) = "SF5S" (0x53 46 35 53) || version (0x02)
|
|
340
|
+
|| pq_len (4 bytes) = uint32 BE, length of pq_payload (= 1664)
|
|
341
|
+
|| pq_payload (1664 bytes) = a 0x03 suite_payload encapsulated to the recipient
|
|
342
|
+
|| wrap_nonce (24 bytes) = XChaCha20-Poly1305 nonce
|
|
343
|
+
|| wrapped_key (48 bytes) = AEAD(K) = 32-byte K + 16-byte tag
|
|
344
|
+
```
|
|
345
|
+
|
|
346
|
+
Construction:
|
|
347
|
+
|
|
348
|
+
1. The owner encapsulates to the recipient (ML-KEM + classical wrap under
|
|
349
|
+
the recipient's envelope key), yielding `pq_payload` and a transport
|
|
350
|
+
secret `T` (the `0x03` combined key for the recipient, derived under
|
|
351
|
+
`info="shieldfive/v1/pq-hybrid/combine"`).
|
|
352
|
+
2. The wrapping key is domain-separated from `T` — it is NOT `T` directly,
|
|
353
|
+
so a share key can never equal a file's combined key:
|
|
354
|
+
|
|
355
|
+
```
|
|
356
|
+
share_transport_key = HKDF(ikm=T, salt=file_id,
|
|
357
|
+
info="shieldfive/v1/share-transport", L=32)
|
|
358
|
+
```
|
|
359
|
+
3. `K` is wrapped with XChaCha20-Poly1305 under `share_transport_key`, with
|
|
360
|
+
the AAD authenticating the WHOLE bundle prefix — including the magic and
|
|
361
|
+
version — so neither the version marker nor any PQ material can be
|
|
362
|
+
substituted, stripped, or downgraded:
|
|
363
|
+
|
|
364
|
+
```
|
|
365
|
+
aad = magic || uint32_be(pq_len) || pq_payload || wrap_nonce
|
|
366
|
+
wrapped_key = XChaCha20-Poly1305-Encrypt(key=share_transport_key,
|
|
367
|
+
nonce=wrap_nonce, aad=aad, plaintext=K)
|
|
368
|
+
```
|
|
369
|
+
|
|
370
|
+
The recipient reverses this: verify `magic` (rejecting any bundle without
|
|
371
|
+
the `"SF5S"` + version-2 prefix), parse the bundle (rejecting a non-zero
|
|
372
|
+
reserved pad in `pq_payload`), decapsulate to recover `T`, derive
|
|
373
|
+
`share_transport_key`, reconstruct `aad`, and AEAD-open `wrapped_key`. Any
|
|
374
|
+
modification to `magic`, `pq_len`, `pq_payload`, or `wrap_nonce` breaks the
|
|
375
|
+
tag.
|
|
376
|
+
|
|
377
|
+
> **Wire-format change (alpha):** earlier alpha builds emitted an
|
|
378
|
+
> *unversioned* bundle (no magic): the wrapping key was derived directly
|
|
379
|
+
> from `T` (reusing the file-combiner label) and `K` was wrapped with an
|
|
380
|
+
> XSalsa20-Poly1305 secretbox that authenticated only `K` (no AAD over
|
|
381
|
+
> `pq_payload`). Such bundles are rejected by the magic check and must be
|
|
382
|
+
> re-issued. No real shares exist pre-launch, so this is a clean break.
|
|
383
|
+
|
|
304
384
|
### `0x04` — `aes-256-gcm-v2`
|
|
305
385
|
|
|
306
386
|
```
|
package/spec/key-derivation.md
CHANGED
|
@@ -111,6 +111,18 @@ file-bound HKDF output `K`. Both are 32 bytes of uniformly random or
|
|
|
111
111
|
pseudorandom material per file; cross-suite output collision
|
|
112
112
|
probability is `2^-256`.
|
|
113
113
|
|
|
114
|
+
> **Planned hardening — suite-id binding (audit M5, future suite version).**
|
|
115
|
+
> The reuse above is safe but implicit: it relies on the `content_key` /`K`
|
|
116
|
+
> input spaces being disjoint rather than binding the suite id directly into
|
|
117
|
+
> the derivation. This is **not exploitable** in the current format — the
|
|
118
|
+
> header MAC authenticates the suite byte, so a `0x02` and a `0x03` file are
|
|
119
|
+
> never interchangeable. The `0x03` derivation is therefore left
|
|
120
|
+
> **unchanged**: production `cipher_version-3` files already depend on it,
|
|
121
|
+
> and changing the labels would make them undecryptable. A future suite
|
|
122
|
+
> version (a new suite id, not `0x03`) will fold the suite id into the
|
|
123
|
+
> chunk-key / nonce-prefix IKM and use dedicated `pq-hybrid` labels; this
|
|
124
|
+
> section will be updated when that suite is defined.
|
|
125
|
+
|
|
114
126
|
## Forbidden cross-context usage
|
|
115
127
|
|
|
116
128
|
These domain strings are consumed by the crypto layer. The host
|
|
@@ -125,6 +137,7 @@ shieldfive/v1/xchacha/chunk-key
|
|
|
125
137
|
shieldfive/v1/xchacha/nonce-prefix
|
|
126
138
|
shieldfive/v1/pq-hybrid/combine
|
|
127
139
|
shieldfive/v1/pq-hybrid/ml-kem-1024-seed
|
|
140
|
+
shieldfive/v1/share-transport
|
|
128
141
|
shieldfive/v1/argon2id/salt-compression
|
|
129
142
|
```
|
|
130
143
|
|
package/src/identity/index.ts
CHANGED
|
@@ -26,7 +26,6 @@ import {
|
|
|
26
26
|
encapsulateForRecipient,
|
|
27
27
|
decapsulateFromHeader,
|
|
28
28
|
parsePqHybridV1SuitePayload,
|
|
29
|
-
buildPqHybridV1SuitePayload,
|
|
30
29
|
} from '../suites/pq-hybrid-v1/index.js'
|
|
31
30
|
export {
|
|
32
31
|
SIGNATURE_ALGO_ED25519,
|
|
@@ -53,9 +52,19 @@ import {
|
|
|
53
52
|
} from '../internal/encoding.js'
|
|
54
53
|
import { randomBytes } from '../internal/runtime.js'
|
|
55
54
|
import { getSodium } from '../internal/sodium.js'
|
|
55
|
+
import { hkdfSha256 } from '../internal/hkdf.js'
|
|
56
|
+
import { HKDF_INFO } from '../internal/types.js'
|
|
56
57
|
|
|
57
58
|
const IDENTITY_BUNDLE_MAGIC = new Uint8Array([0x53, 0x46, 0x35, 0x49, 0x01]) // "SF5I" + version
|
|
58
59
|
|
|
60
|
+
// Share-bundle magic: "SF5S" + version byte. Version 0x02 marks the hardened
|
|
61
|
+
// share construction (audit H2/M6): a domain-separated transport key and an
|
|
62
|
+
// AEAD wrap whose AAD authenticates the whole bundle. Earlier alpha builds
|
|
63
|
+
// emitted an unversioned bundle (an AAD-less secretbox under the raw transport
|
|
64
|
+
// secret); those are NOT readable here and are rejected by the magic check.
|
|
65
|
+
// No real shares exist pre-launch, so this is a deliberate clean break.
|
|
66
|
+
const SHARE_BUNDLE_MAGIC = new Uint8Array([0x53, 0x46, 0x35, 0x53, 0x02]) // "SF5S" + version 2
|
|
67
|
+
|
|
59
68
|
export interface PublicIdentityBundle {
|
|
60
69
|
/** ML-KEM-1024 public key (1568 bytes) */
|
|
61
70
|
mlKemPublicKey: Uint8Array
|
|
@@ -268,40 +277,73 @@ export interface ShareFileInput {
|
|
|
268
277
|
* key. To make sharing work, we use a different construction: we wrap
|
|
269
278
|
* the existing combined key under (recipient PQ KEM ⊕ recipient
|
|
270
279
|
* envelope) and emit only the wrapped form.
|
|
280
|
+
*
|
|
281
|
+
* Two properties this construction must hold (audit H2/M6):
|
|
282
|
+
* 1. The wrapping key is NOT the raw KEM/envelope combined key (which
|
|
283
|
+
* reuses the file-combiner HKDF label). We run it through one more
|
|
284
|
+
* HKDF under the dedicated `SHARE_TRANSPORT` label so a share key is
|
|
285
|
+
* never equal to a file's combined key.
|
|
286
|
+
* 2. The wrap authenticates the WHOLE bundle, not just the 32-byte
|
|
287
|
+
* combined key: the XChaCha20-Poly1305 AAD covers the version marker,
|
|
288
|
+
* the length prefix, the entire pqPayload (including its reserved pad)
|
|
289
|
+
* and the nonce, so PQ material cannot be substituted or stripped
|
|
290
|
+
* without breaking the tag.
|
|
291
|
+
*
|
|
292
|
+
* The bundle is prefixed with `SHARE_BUNDLE_MAGIC` ("SF5S" + version) so the
|
|
293
|
+
* hardened format is distinguishable from the earlier unversioned one.
|
|
271
294
|
*/
|
|
272
295
|
export async function buildShareForRecipient(
|
|
273
296
|
input: ShareFileInput,
|
|
274
297
|
): Promise<{ shareBundle: Uint8Array }> {
|
|
275
298
|
const sodium = await getSodium()
|
|
276
299
|
|
|
277
|
-
// Generate a fresh transport
|
|
300
|
+
// Generate a fresh transport secret for this share.
|
|
278
301
|
// ML-KEM encapsulation gives us the PQ-half of the transport secret.
|
|
279
|
-
const { suitePayload: pqPayload, combinedKey:
|
|
302
|
+
const { suitePayload: pqPayload, combinedKey: transportSecret } =
|
|
280
303
|
await encapsulateForRecipient({
|
|
281
304
|
recipientPublicKey: input.recipient.mlKemPublicKey,
|
|
282
305
|
envelopeKey: input.recipientEnvelopeKey,
|
|
283
306
|
fileId: input.fileId,
|
|
284
307
|
})
|
|
285
308
|
|
|
286
|
-
|
|
287
|
-
// XSalsa20-Poly1305 secretbox.
|
|
288
|
-
if (transportKey.length !== 32) {
|
|
309
|
+
if (transportSecret.length !== 32) {
|
|
289
310
|
throw new Error('buildShareForRecipient: transport key length wrong')
|
|
290
311
|
}
|
|
312
|
+
// (1) Domain-separate the share transport key from the file-combiner output.
|
|
313
|
+
const shareTransportKey = await hkdfSha256({
|
|
314
|
+
ikm: transportSecret,
|
|
315
|
+
salt: input.fileId,
|
|
316
|
+
info: HKDF_INFO.SHARE_TRANSPORT,
|
|
317
|
+
length: 32,
|
|
318
|
+
})
|
|
319
|
+
|
|
320
|
+
// (2) Wrap the original combined key with an AEAD whose AAD authenticates
|
|
321
|
+
// the whole bundle prefix (magic || length || pqPayload || nonce). Binding
|
|
322
|
+
// the magic means the version marker cannot be stripped or downgraded
|
|
323
|
+
// without breaking the tag.
|
|
291
324
|
const wrapNonce = randomBytes(24)
|
|
292
|
-
const
|
|
325
|
+
const aad = concatBytes([
|
|
326
|
+
SHARE_BUNDLE_MAGIC,
|
|
327
|
+
uint32BE(pqPayload.length),
|
|
328
|
+
pqPayload,
|
|
329
|
+
wrapNonce,
|
|
330
|
+
])
|
|
331
|
+
const wrappedCombinedKey = sodium.crypto_aead_xchacha20poly1305_ietf_encrypt(
|
|
293
332
|
input.combinedKey,
|
|
333
|
+
aad,
|
|
334
|
+
null,
|
|
294
335
|
wrapNonce,
|
|
295
|
-
|
|
336
|
+
shareTransportKey,
|
|
296
337
|
)
|
|
297
338
|
if (wrappedCombinedKey.length !== 32 + 16) {
|
|
298
|
-
throw new Error('buildShareForRecipient:
|
|
339
|
+
throw new Error('buildShareForRecipient: AEAD produced unexpected length')
|
|
299
340
|
}
|
|
300
341
|
|
|
301
342
|
// Share record format:
|
|
302
|
-
// [4 bytes BE length of pqPayload][pqPayload][24-byte wrap nonce][48-byte wrapped combined key]
|
|
343
|
+
// [5-byte magic][4 bytes BE length of pqPayload][pqPayload][24-byte wrap nonce][48-byte wrapped combined key]
|
|
303
344
|
return {
|
|
304
345
|
shareBundle: concatBytes([
|
|
346
|
+
SHARE_BUNDLE_MAGIC,
|
|
305
347
|
uint32BE(pqPayload.length),
|
|
306
348
|
pqPayload,
|
|
307
349
|
wrapNonce,
|
|
@@ -322,10 +364,20 @@ export async function openShareAsRecipient(input: {
|
|
|
322
364
|
recipientEnvelopeKey: Uint8Array
|
|
323
365
|
}): Promise<Uint8Array> {
|
|
324
366
|
const sodium = await getSodium()
|
|
325
|
-
if (input.shareBundle.length < 4) {
|
|
367
|
+
if (input.shareBundle.length < SHARE_BUNDLE_MAGIC.length + 4) {
|
|
326
368
|
throw new Error('openShareAsRecipient: share too short')
|
|
327
369
|
}
|
|
328
|
-
|
|
370
|
+
// Reject anything that isn't a current ("SF5S" + version) share bundle.
|
|
371
|
+
// Earlier-alpha unversioned bundles fail here rather than producing an
|
|
372
|
+
// opaque authentication error later.
|
|
373
|
+
for (let i = 0; i < SHARE_BUNDLE_MAGIC.length; i += 1) {
|
|
374
|
+
if (input.shareBundle[i] !== SHARE_BUNDLE_MAGIC[i]) {
|
|
375
|
+
throw new Error(
|
|
376
|
+
'openShareAsRecipient: bad magic / unsupported share bundle version',
|
|
377
|
+
)
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
let offset = SHARE_BUNDLE_MAGIC.length
|
|
329
381
|
const pqLen = readUint32BE(input.shareBundle, offset)
|
|
330
382
|
offset += 4
|
|
331
383
|
if (offset + pqLen + 24 + 48 !== input.shareBundle.length) {
|
|
@@ -337,31 +389,45 @@ export async function openShareAsRecipient(input: {
|
|
|
337
389
|
offset += 24
|
|
338
390
|
const wrappedCombinedKey = input.shareBundle.slice(offset, offset + 48)
|
|
339
391
|
|
|
340
|
-
//
|
|
392
|
+
// Structurally validate the suite payload. This rejects a non-zero reserved
|
|
393
|
+
// pad in classical_wrapped (M6) before any decapsulation work.
|
|
341
394
|
parsePqHybridV1SuitePayload(pqPayload)
|
|
342
|
-
// Round-trip through builder to ensure we got back the same bytes.
|
|
343
|
-
const checkBytes = buildPqHybridV1SuitePayload(
|
|
344
|
-
parsePqHybridV1SuitePayload(pqPayload),
|
|
345
|
-
)
|
|
346
|
-
if (checkBytes.length !== pqPayload.length) {
|
|
347
|
-
throw new Error('openShareAsRecipient: pq payload self-check failed')
|
|
348
|
-
}
|
|
349
395
|
|
|
350
|
-
const { combinedKey:
|
|
396
|
+
const { combinedKey: transportSecret } = await decapsulateFromHeader({
|
|
351
397
|
suitePayload: pqPayload,
|
|
352
398
|
recipientSecretKey: input.recipientSecretKey,
|
|
353
399
|
envelopeKey: input.recipientEnvelopeKey,
|
|
354
400
|
fileId: input.fileId,
|
|
355
401
|
})
|
|
402
|
+
const shareTransportKey = await hkdfSha256({
|
|
403
|
+
ikm: transportSecret,
|
|
404
|
+
salt: input.fileId,
|
|
405
|
+
info: HKDF_INFO.SHARE_TRANSPORT,
|
|
406
|
+
length: 32,
|
|
407
|
+
})
|
|
356
408
|
|
|
357
|
-
|
|
358
|
-
|
|
409
|
+
// The AAD must reproduce exactly what the builder authenticated: it binds
|
|
410
|
+
// the version marker, the length prefix, the whole pqPayload (incl. reserved
|
|
411
|
+
// pad) and the nonce, so any substitution/stripping of PQ material breaks
|
|
412
|
+
// the tag.
|
|
413
|
+
const aad = concatBytes([
|
|
414
|
+
SHARE_BUNDLE_MAGIC,
|
|
415
|
+
uint32BE(pqPayload.length),
|
|
416
|
+
pqPayload,
|
|
359
417
|
wrapNonce,
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
418
|
+
])
|
|
419
|
+
let unwrapped: Uint8Array
|
|
420
|
+
try {
|
|
421
|
+
unwrapped = sodium.crypto_aead_xchacha20poly1305_ietf_decrypt(
|
|
422
|
+
null,
|
|
423
|
+
wrappedCombinedKey,
|
|
424
|
+
aad,
|
|
425
|
+
wrapNonce,
|
|
426
|
+
shareTransportKey,
|
|
427
|
+
)
|
|
428
|
+
} catch {
|
|
363
429
|
throw new Error(
|
|
364
|
-
'openShareAsRecipient:
|
|
430
|
+
'openShareAsRecipient: share authentication failed — wrong recipient or tampered share',
|
|
365
431
|
)
|
|
366
432
|
}
|
|
367
433
|
if (unwrapped.length !== 32) {
|
package/src/index.ts
CHANGED
|
@@ -218,7 +218,7 @@ export async function autoDecryptBlob(
|
|
|
218
218
|
}
|
|
219
219
|
|
|
220
220
|
/** Library version, also written into format documentation. */
|
|
221
|
-
export const SHIELDFIVE_CRYPTO_VERSION = '1.0.0-alpha.
|
|
221
|
+
export const SHIELDFIVE_CRYPTO_VERSION = '1.0.0-alpha.14'
|
|
222
222
|
|
|
223
223
|
/** Default cipher suite for new files when not specified by the caller. */
|
|
224
224
|
export const DEFAULT_SUITE = SUITE.PQ_HYBRID_XCHACHA_MLKEM1024_V1
|
package/src/internal/types.ts
CHANGED
|
@@ -88,6 +88,11 @@ export const HKDF_INFO = Object.freeze({
|
|
|
88
88
|
XCHACHA_NONCE_PREFIX: 'shieldfive/v1/xchacha/nonce-prefix',
|
|
89
89
|
PQ_HYBRID_COMBINE: 'shieldfive/v1/pq-hybrid/combine',
|
|
90
90
|
ML_KEM_1024_SEED: 'shieldfive/v1/pq-hybrid/ml-kem-1024-seed',
|
|
91
|
+
// Re-encrypting a file's combined key to a share recipient wraps it under a
|
|
92
|
+
// transport key derived with THIS label, distinct from the file-combiner
|
|
93
|
+
// label above, so a share transport key is never equal to a file's
|
|
94
|
+
// combined key for the same (recipient, envelope, file_id).
|
|
95
|
+
SHARE_TRANSPORT: 'shieldfive/v1/share-transport',
|
|
91
96
|
ARGON2ID_SALT_COMPRESSION: 'shieldfive/v1/argon2id/salt-compression',
|
|
92
97
|
})
|
|
93
98
|
|
|
@@ -4,12 +4,12 @@
|
|
|
4
4
|
* Per-file content key. Per-chunk AEAD with file_id-bound AAD that
|
|
5
5
|
* authenticates chunk index, total chunks, and the is-final flag. The
|
|
6
6
|
* 12-byte GCM IV is split into an 8-byte file-derived prefix and a 4-byte
|
|
7
|
-
* big-endian counter — a wider prefix than v1 (0x01) so the
|
|
8
|
-
*
|
|
9
|
-
*
|
|
10
|
-
* 2^64 to 2^32 chunks, which is still well above any
|
|
11
|
-
* the format permits (`MAX_TOTAL_CHUNKS` is 1e9 and
|
|
12
|
-
* safe JS integer).
|
|
7
|
+
* big-endian counter — a wider prefix than v1 (0x01) so the cross-file
|
|
8
|
+
* nonce-prefix space widens from 2^32 to 2^64, shrinking the chance of an
|
|
9
|
+
* IV collision across files that share a content key. The per-file chunk
|
|
10
|
+
* ceiling drops from 2^64 to 2^32 chunks, which is still well above any
|
|
11
|
+
* practical bound the format permits (`MAX_TOTAL_CHUNKS` is 1e9 and
|
|
12
|
+
* `chunkIndex` is a safe JS integer).
|
|
13
13
|
*/
|
|
14
14
|
|
|
15
15
|
import { buildChunkAad } from '../../format/header.js'
|
|
@@ -46,10 +46,17 @@ export const ML_KEM_1024_SECRET_KEY_BYTES = 3168
|
|
|
46
46
|
* classical_wrapped (72 bytes — 48 bytes secretbox + 24 bytes reserved zero pad)
|
|
47
47
|
* classical_nonce (24 bytes)
|
|
48
48
|
* Total: 1664 bytes
|
|
49
|
+
*
|
|
50
|
+
* The 24 reserved pad bytes (offsets 48..72 of classical_wrapped) MUST be
|
|
51
|
+
* zero. The parser rejects a non-zero pad (audit M6) so the field cannot be
|
|
52
|
+
* used as a malleable, unauthenticated side channel.
|
|
49
53
|
*/
|
|
50
54
|
export const PQ_HYBRID_V1_SUITE_PAYLOAD_LENGTH =
|
|
51
55
|
ML_KEM_1024_CIPHERTEXT_BYTES + 72 + 24
|
|
52
56
|
|
|
57
|
+
/** Bytes of real secretbox at the start of the 72-byte classical_wrapped field. */
|
|
58
|
+
const CLASSICAL_WRAPPED_SECRETBOX_BYTES = 48
|
|
59
|
+
|
|
53
60
|
export interface PqHybridV1SuitePayload {
|
|
54
61
|
mlkemCiphertext: Uint8Array // 1568 bytes
|
|
55
62
|
classicalWrapped: Uint8Array // 72 bytes
|
|
@@ -83,12 +90,26 @@ export function parsePqHybridV1SuitePayload(
|
|
|
83
90
|
`pq-hybrid-v1: suite payload must be ${PQ_HYBRID_V1_SUITE_PAYLOAD_LENGTH} bytes`,
|
|
84
91
|
)
|
|
85
92
|
}
|
|
93
|
+
const classicalWrapped = bytes.slice(
|
|
94
|
+
ML_KEM_1024_CIPHERTEXT_BYTES,
|
|
95
|
+
ML_KEM_1024_CIPHERTEXT_BYTES + 72,
|
|
96
|
+
)
|
|
97
|
+
// M6: the 24-byte reserved pad after the 48-byte secretbox MUST be all
|
|
98
|
+
// zero. Reject otherwise so the field cannot carry unauthenticated bytes.
|
|
99
|
+
for (
|
|
100
|
+
let i = CLASSICAL_WRAPPED_SECRETBOX_BYTES;
|
|
101
|
+
i < classicalWrapped.length;
|
|
102
|
+
i += 1
|
|
103
|
+
) {
|
|
104
|
+
if (classicalWrapped[i] !== 0) {
|
|
105
|
+
throw new RangeError(
|
|
106
|
+
'pq-hybrid-v1: reserved classical_wrapped pad must be zero',
|
|
107
|
+
)
|
|
108
|
+
}
|
|
109
|
+
}
|
|
86
110
|
return {
|
|
87
111
|
mlkemCiphertext: bytes.slice(0, ML_KEM_1024_CIPHERTEXT_BYTES),
|
|
88
|
-
classicalWrapped
|
|
89
|
-
ML_KEM_1024_CIPHERTEXT_BYTES,
|
|
90
|
-
ML_KEM_1024_CIPHERTEXT_BYTES + 72,
|
|
91
|
-
),
|
|
112
|
+
classicalWrapped,
|
|
92
113
|
classicalNonce: bytes.slice(
|
|
93
114
|
ML_KEM_1024_CIPHERTEXT_BYTES + 72,
|
|
94
115
|
PQ_HYBRID_V1_SUITE_PAYLOAD_LENGTH,
|