@shieldfive/crypto 1.0.0-beta.3 → 1.0.0-rc.1

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.
Files changed (59) hide show
  1. package/CHANGELOG.md +93 -0
  2. package/README.md +73 -20
  3. package/SECURITY.md +38 -24
  4. package/dist/identity/index.d.ts +1 -1
  5. package/dist/identity/index.d.ts.map +1 -1
  6. package/dist/identity/index.js +1 -1
  7. package/dist/identity/index.js.map +1 -1
  8. package/dist/identity/sign.d.ts +73 -21
  9. package/dist/identity/sign.d.ts.map +1 -1
  10. package/dist/identity/sign.js +105 -35
  11. package/dist/identity/sign.js.map +1 -1
  12. package/dist/index.d.ts +3 -2
  13. package/dist/index.d.ts.map +1 -1
  14. package/dist/index.js +1 -1
  15. package/dist/index.js.map +1 -1
  16. package/dist/streams/aes-gcm-v1.d.ts +9 -5
  17. package/dist/streams/aes-gcm-v1.d.ts.map +1 -1
  18. package/dist/streams/aes-gcm-v1.js +26 -24
  19. package/dist/streams/aes-gcm-v1.js.map +1 -1
  20. package/dist/streams/pq-hybrid-v1.d.ts +4 -3
  21. package/dist/streams/pq-hybrid-v1.d.ts.map +1 -1
  22. package/dist/streams/pq-hybrid-v1.js +20 -18
  23. package/dist/streams/pq-hybrid-v1.js.map +1 -1
  24. package/dist/suites/aes-gcm-v0/api.d.ts +2 -1
  25. package/dist/suites/aes-gcm-v0/api.d.ts.map +1 -1
  26. package/dist/suites/aes-gcm-v0/api.js +1 -0
  27. package/dist/suites/aes-gcm-v0/api.js.map +1 -1
  28. package/dist/suites/aes-gcm-v1/api.d.ts +15 -2
  29. package/dist/suites/aes-gcm-v1/api.d.ts.map +1 -1
  30. package/dist/suites/aes-gcm-v1/api.js.map +1 -1
  31. package/dist/suites/aes-gcm-v2/api.d.ts +15 -2
  32. package/dist/suites/aes-gcm-v2/api.d.ts.map +1 -1
  33. package/dist/suites/aes-gcm-v2/api.js.map +1 -1
  34. package/dist/suites/pq-hybrid-v1/api.d.ts +6 -6
  35. package/dist/suites/pq-hybrid-v1/api.d.ts.map +1 -1
  36. package/dist/suites/pq-hybrid-v1/api.js +2 -1
  37. package/dist/suites/pq-hybrid-v1/api.js.map +1 -1
  38. package/dist/suites/pq-hybrid-v1/index.d.ts.map +1 -1
  39. package/dist/suites/pq-hybrid-v1/index.js +11 -4
  40. package/dist/suites/pq-hybrid-v1/index.js.map +1 -1
  41. package/dist/suites/xchacha-v1/api.d.ts +15 -6
  42. package/dist/suites/xchacha-v1/api.d.ts.map +1 -1
  43. package/dist/suites/xchacha-v1/api.js +2 -1
  44. package/dist/suites/xchacha-v1/api.js.map +1 -1
  45. package/package.json +2 -1
  46. package/spec/format-v1.md +59 -17
  47. package/spec/key-derivation.md +9 -2
  48. package/spec/threat-model.md +8 -2
  49. package/src/identity/index.ts +3 -2
  50. package/src/identity/sign.ts +118 -40
  51. package/src/index.ts +3 -3
  52. package/src/streams/aes-gcm-v1.ts +37 -30
  53. package/src/streams/pq-hybrid-v1.ts +29 -21
  54. package/src/suites/aes-gcm-v0/api.ts +2 -1
  55. package/src/suites/aes-gcm-v1/api.ts +15 -2
  56. package/src/suites/aes-gcm-v2/api.ts +15 -2
  57. package/src/suites/pq-hybrid-v1/api.ts +10 -8
  58. package/src/suites/pq-hybrid-v1/index.ts +14 -8
  59. package/src/suites/xchacha-v1/api.ts +19 -8
@@ -1 +1 @@
1
- {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/suites/xchacha-v1/api.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,wBAAwB,EACxB,WAAW,EACX,eAAe,EACf,WAAW,GACZ,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,+BAA+B,EAC/B,oBAAoB,EACpB,kBAAkB,EAClB,YAAY,EACZ,YAAY,EACZ,uBAAuB,EACvB,0BAA0B,GAC3B,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,kBAAkB,EAElB,YAAY,EACZ,gBAAgB,E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.0-beta.3",
3
+ "version": "1.0.0-rc.1",
4
4
  "description": "Client-side post-quantum hybrid encryption for cloud storage. The cryptographic core of ShieldFive.",
5
5
  "type": "module",
6
6
  "license": "Apache-2.0",
@@ -112,6 +112,7 @@
112
112
  },
113
113
  "dependencies": {
114
114
  "@noble/curves": "^2.2.0",
115
+ "@noble/hashes": "^2.2.0",
115
116
  "@noble/post-quantum": "^0.6.0"
116
117
  },
117
118
  "devDependencies": {
package/spec/format-v1.md CHANGED
@@ -429,12 +429,22 @@ the wrapped key from the out-of-band channel.
429
429
  ## Signature block
430
430
 
431
431
  The signature block is an OPTIONAL trailing structure that carries a
432
- detached sender signature over `header_unauthenticated_bytes ||
433
- concat(per-chunk MAC tags)`. It provides *sender attribution*: a
434
- recipient who trusts a sender's public key can verify the file was
435
- produced by that sender. It does NOT add confidentiality or chunk
436
- integrity — those are provided by the per-suite AEAD and by
437
- `header_mac` regardless of whether a signature block is present.
432
+ detached sender signature over a transcript that commits to the header
433
+ and every chunk's full ciphertext (see `signed_message` below). It
434
+ provides *sender attribution*: a recipient who trusts a sender's public
435
+ key can verify the file content was produced by that sender. It does NOT
436
+ add confidentiality — that is provided by the per-suite AEAD regardless
437
+ of whether a signature block is present.
438
+
439
+ The transcript commits to the ciphertext bytes themselves, not to the
440
+ per-chunk AEAD tags. This is deliberate: an AEAD tag (GHASH for AES-GCM,
441
+ Poly1305 for the PQ suite) is a keyed polynomial authenticator that a
442
+ holder of the content key can forge — they can rewrite ciphertext while
443
+ keeping the 16-byte tag byte-identical. Signing only the tags would let
444
+ such a holder alter the plaintext other recipients see while the
445
+ signature still verified, defeating attribution against exactly the
446
+ principal it is meant to bind. Signing the ciphertext under a
447
+ collision-resistant hash closes that gap.
438
448
 
439
449
  ```
440
450
  signature_block := algorithm (1 byte) = signature algorithm identifier
@@ -453,19 +463,34 @@ signature_block := algorithm (1 byte) = signature algorithm identifier
453
463
  | `0x02` | ML-DSA-65 | 1952 bytes | 3309 bytes | reserved (not yet implemented) |
454
464
  | `0x80` | (reserved, custom-algorithm range begins) | — | — | reserved |
455
465
 
456
- The message signed for `0x01 = Ed25519` is the byte string
466
+ The message signed for `0x01 = Ed25519` is the 32-byte SHA-256 digest of
467
+ a domain-separated, length-framed transcript:
457
468
 
458
469
  ```
459
- signed_message := header_unauthenticated_bytes
460
- || concat(chunk_0_mac, chunk_1_mac, ..., chunk_{n-1}_mac)
470
+ signed_message := SHA-256(
471
+ "shieldfive/crypto/v1/sender-sig" (31-byte ASCII domain tag)
472
+ || u64be(len(header_unauthenticated_bytes)) || header_unauthenticated_bytes
473
+ || u64be(total_chunks)
474
+ || for each chunk i in 0..total_chunks-1:
475
+ u64be(i) || u64be(len(ciphertext_i)) || ciphertext_i
476
+ )
461
477
  ```
462
478
 
463
479
  where `header_unauthenticated_bytes` is exactly the bytes covered by
464
480
  `header_mac` (i.e. everything in the header before the `header_mac`
465
- field itself), and each `chunk_i_mac` is the suite's AEAD authenticator
466
- tag for chunk `i`. For all suites defined in this version the AEAD tag
467
- is the trailing 16 bytes of the chunk's ciphertext field (AES-GCM-128
468
- and Poly1305 both append a 16-byte tag).
481
+ field itself); `u64be(x)` is `x` as an 8-byte big-endian integer; the
482
+ domain tag is the 31 ASCII bytes `shieldfive/crypto/v1/sender-sig` with
483
+ no trailing byte; and `ciphertext_i` is the ENTIRE
484
+ per-chunk ciphertext field for chunk `i` (encrypted body followed by the
485
+ 16-byte AEAD tag) — the same bytes the chunk's length prefix counts, not
486
+ just the trailing tag. Ed25519 signs the resulting 32-byte digest.
487
+ Framing every length as `u64be` and binding each chunk index means the
488
+ transcript also commits to chunk count and order, so truncation,
489
+ reordering, or splicing changes the digest.
490
+
491
+ Because the transcript is hashed incrementally, a writer or reader never
492
+ holds more than one chunk plus the running hash state in memory,
493
+ regardless of file size.
469
494
 
470
495
  The signature block is OPTIONAL. Implementations:
471
496
 
@@ -486,10 +511,27 @@ The signature block is OPTIONAL. Implementations:
486
511
  without raising and lets the application policy decide.
487
512
 
488
513
  A signature block does not weaken the format's existing security
489
- guarantees: an attacker who tampers with any byte covered by `header_mac`
490
- fails MAC verification under the content key, and an attacker who
491
- tampers with any chunk ciphertext fails per-chunk AEAD verification. The
492
- signature is a separate, application-level trust layer.
514
+ guarantees against an attacker WITHOUT the content key: tampering with
515
+ any byte covered by `header_mac` fails MAC verification under the content
516
+ key, and tampering with any chunk ciphertext fails per-chunk AEAD
517
+ verification. The signature is a separate trust layer that additionally
518
+ binds authorship against a content-key HOLDER: because the signed
519
+ transcript commits to the ciphertext bytes, a recipient who has the
520
+ content key (and could therefore forge an AEAD tag) still cannot alter
521
+ the plaintext other recipients see without invalidating the signature.
522
+ Verification with a caller-supplied public key returns `verified = true`
523
+ only when the signer signed exactly the ciphertext presented.
524
+
525
+ > Security note. Before this revision the signed transcript was
526
+ > `header_unauthenticated_bytes || concat(per-chunk AEAD tags)`. Because
527
+ > AEAD tags are forgeable by a content-key holder, that transcript did
528
+ > not bind ciphertext content and did not provide attribution against a
529
+ > recipient/collaborator. Any `0x01` signature produced by a library
530
+ > version predating this revision therefore does not carry the
531
+ > attribution guarantee and will not verify against the current
532
+ > transcript. The signature block is optional and was not consumed by any
533
+ > production ShieldFive deployment, so no interoperable signed files exist
534
+ > under the old transcript.
493
535
 
494
536
  ## Versioning policy
495
537
 
@@ -80,8 +80,8 @@ backup) has a worse failure mode (data loss).
80
80
  Once the envelope key is in hand, per-file keys are derived as:
81
81
 
82
82
  ```
83
- content_key = randomBytes(32) (fresh per file, never derived)
84
- file_id = randomBytes(16) (fresh per file, never derived)
83
+ content_key = randomBytes(32) (default path: fresh per file)
84
+ file_id = randomBytes(16) (default path: fresh per file)
85
85
 
86
86
  header_mac_key = HKDF(content_key, salt=file_id,
87
87
  info="shieldfive/v1/header-mac")
@@ -98,6 +98,13 @@ iv / nonce_i = nonce_prefix || counter
98
98
  8-byte prefix; uint64_be(chunk_index) otherwise)
99
99
  ```
100
100
 
101
+ Both `content_key` and `file_id` are generated fresh per file on the normal
102
+ path. The high-level and streaming encrypt APIs also accept them as explicit
103
+ overrides; when both are supplied the library cannot detect reuse, so
104
+ uniqueness of the `(content_key, file_id)` pair across distinct plaintexts
105
+ becomes the caller's responsibility. Reusing a pair reuses the AEAD key and
106
+ nonce and is catastrophic (see `threat-model.md`, known limitations).
107
+
101
108
  For the PQ-hybrid suite, `content_key` is replaced by the combined key
102
109
  `K = HKDF(classical_share || pq_share, salt=file_id,
103
110
  info="shieldfive/v1/pq-hybrid/combine", L=32)`. The chunk-key and
@@ -225,8 +225,14 @@ These are intentional tradeoffs documented for transparency:
225
225
  1. **Per-file random nonce prefix is derived, not stored.** Under correct
226
226
  use this is safer (no risk of replay due to RNG failure during write).
227
227
  Under incorrect use (key reuse across files), it offers no defense
228
- beyond what AES-GCM/XChaCha already provide. This is acceptable because
229
- the crypto layer enforces fresh per-file content keys.
228
+ beyond what AES-GCM/XChaCha already provide. On the normal path the
229
+ library generates a fresh `content_key` and `file_id` per file, so this
230
+ does not arise. The library does not, however, *enforce* uniqueness when
231
+ a caller supplies both the `contentKey` and `fileId` overrides: it cannot
232
+ tell that an explicitly supplied pair is being reused. Pair-uniqueness
233
+ across distinct plaintexts is therefore a caller obligation whenever the
234
+ override parameters are used; reusing a `(content_key, file_id)` pair is
235
+ catastrophic (AEAD key + nonce reuse). See `key-derivation.md`.
230
236
 
231
237
  2. **No padding for size obfuscation.** A 5MB ciphertext implies a ~5MB
232
238
  plaintext (within chunk granularity). Applications wanting size privacy
@@ -37,8 +37,9 @@ export {
37
37
  buildSignatureBlock,
38
38
  deriveEd25519PublicKey,
39
39
  parseSignatureBlock,
40
- signHeaderAndMacs,
41
- verifyHeaderAndMacs,
40
+ SenderSigTranscript,
41
+ signSenderTranscript,
42
+ verifySenderTranscript,
42
43
  } from './sign.js'
43
44
  export type { SignatureBlock } from './sign.js'
44
45
  import {
@@ -3,14 +3,28 @@
3
3
  *
4
4
  * The v1 file format already authenticates with HMAC under the content
5
5
  * key (`header_mac`) and per-chunk AEAD tags, so a recipient can be sure
6
- * the file decrypts to bytes the encryptor produced. What it does NOT
7
- * tell them is WHO encrypted it — anyone with the content key could have
8
- * written the file.
6
+ * the file decrypts to bytes *some* content-key holder produced. What it
7
+ * does NOT tell them is WHO produced it — anyone with the content key
8
+ * could have written the file.
9
9
  *
10
- * This module adds an optional detached signature over
11
- * `header_unauthenticated_bytes || concat(per-chunk MAC tags)` so that a
10
+ * This module adds an optional detached Ed25519 signature so that a
12
11
  * recipient who trusts a sender's public key can verify authorship. The
13
- * signature lives in an optional trailing structure (see
12
+ * signed message is a domain-separated, length-framed SHA-256 transcript
13
+ * that commits to the header AND every chunk's full ciphertext (body +
14
+ * AEAD tag) — see {@link SenderSigTranscript}.
15
+ *
16
+ * It deliberately does NOT sign the AEAD tags alone. An AEAD tag (GHASH
17
+ * for AES-GCM, Poly1305 for the PQ suite) is a keyed polynomial MAC that
18
+ * a *content-key holder* can forge: knowing the key, they can rewrite
19
+ * chunk ciphertext while holding the 16-byte tag byte-identical. Since
20
+ * the entire point of attribution is to bind content against exactly such
21
+ * a holder (an outsider without the content key cannot decrypt at all),
22
+ * the signature must commit to the ciphertext bytes themselves, not to a
23
+ * value the holder can keep fixed under a chosen-plaintext change. The
24
+ * transcript is hashed incrementally, so signing/verifying stays O(1) in
25
+ * memory for multi-gigabyte streams.
26
+ *
27
+ * The signature lives in an optional trailing structure (see
14
28
  * `spec/format-v1.md § "Signature block"`); legacy files without that
15
29
  * structure continue to decrypt unchanged, with the receiving side
16
30
  * reporting `signature: null`.
@@ -21,11 +35,13 @@
21
35
  */
22
36
 
23
37
  import { ed25519 } from '@noble/curves/ed25519.js'
38
+ import { sha256 } from '@noble/hashes/sha2.js'
24
39
 
25
40
  import {
26
41
  concatBytes,
27
42
  readUint16BE,
28
43
  uint16BE,
44
+ uint64BE,
29
45
  } from '../internal/encoding.js'
30
46
 
31
47
  /** Signature algorithm: Ed25519 (RFC 8032). 32-byte key, 64-byte signature. */
@@ -56,65 +72,127 @@ export class SignatureError extends Error {
56
72
  }
57
73
  }
58
74
 
59
- function buildSignedMessage(
60
- header: Uint8Array,
61
- chunkMacs: ReadonlyArray<Uint8Array>,
62
- ): Uint8Array {
63
- let totalMacLen = 0
64
- for (const mac of chunkMacs) totalMacLen += mac.length
65
- const out = new Uint8Array(header.length + totalMacLen)
66
- out.set(header, 0)
67
- let offset = header.length
68
- for (const mac of chunkMacs) {
69
- out.set(mac, offset)
70
- offset += mac.length
71
- }
72
- return out
73
- }
75
+ /**
76
+ * Domain separator for the sender-attribution signature transcript.
77
+ *
78
+ * Frozen wire constant: these exact bytes are hashed into every
79
+ * signature. Changing them changes every signature and invalidates
80
+ * verification of any previously signed file. Do not edit.
81
+ */
82
+ const SENDER_SIG_DOMAIN = new TextEncoder().encode(
83
+ 'shieldfive/crypto/v1/sender-sig',
84
+ )
74
85
 
75
86
  /**
76
- * Produce a detached Ed25519 signature over
77
- * `header_unauthenticated_bytes || concat(chunk_macs)`.
87
+ * Incremental transcript for the sender-attribution signature.
78
88
  *
79
- * `header` MUST be the exact bytes covered by the file's `header_mac`
80
- * (i.e. the output of `buildHeaderUnauthenticated` or
81
- * `parseHeader().unauthenticatedBytes`). `chunkMacs` MUST be the per-chunk
82
- * AEAD tags in chunk-index order. For suites defined in v1 (AES-GCM-128,
83
- * ChaCha20-Poly1305) the tag is the trailing 16 bytes of the chunk's
84
- * ciphertext field.
89
+ * The signed message commits to the file header (exactly the bytes under
90
+ * `header_mac`) and to EVERY chunk's full ciphertext field (body + AEAD
91
+ * tag), each length-framed and preceded by a domain separator:
92
+ *
93
+ * ```
94
+ * digest = SHA-256(
95
+ * SENDER_SIG_DOMAIN
96
+ * || u64be(len(header)) || header
97
+ * || u64be(total_chunks)
98
+ * || for each chunk i in order: u64be(i) || u64be(len(ct_i)) || ct_i
99
+ * )
100
+ * ```
101
+ *
102
+ * The 32-byte digest is what Ed25519 signs. Because the transcript binds
103
+ * the ciphertext bytes (not just the malleable per-chunk AEAD tags), a
104
+ * content-key holder cannot alter plaintext while keeping a signature
105
+ * valid: any change to a ciphertext byte changes the digest, and forging
106
+ * an Ed25519 signature over the new digest requires the signing key.
107
+ * Length-framing the chunk index and each ciphertext also binds chunk
108
+ * order and count, so truncation/reorder/splice change the digest too.
109
+ *
110
+ * Only the running SHA-256 state is retained, never the ciphertext, so
111
+ * signing or verifying a multi-gigabyte file uses O(1) memory.
112
+ */
113
+ export class SenderSigTranscript {
114
+ private readonly hash = sha256.create()
115
+ private headerAbsorbed = false
116
+
117
+ constructor() {
118
+ this.hash.update(SENDER_SIG_DOMAIN)
119
+ }
120
+
121
+ /**
122
+ * Absorb the header and the total chunk count. MUST be called exactly
123
+ * once, before any chunk. `header` MUST be the exact bytes covered by
124
+ * `header_mac` (`buildHeaderUnauthenticated` output /
125
+ * `parseHeader().unauthenticatedBytes`).
126
+ */
127
+ absorbHeader(header: Uint8Array, totalChunks: number): void {
128
+ if (this.headerAbsorbed) {
129
+ throw new SignatureError('transcript_header_already_absorbed')
130
+ }
131
+ this.hash.update(uint64BE(header.length))
132
+ this.hash.update(header)
133
+ this.hash.update(uint64BE(totalChunks))
134
+ this.headerAbsorbed = true
135
+ }
136
+
137
+ /**
138
+ * Absorb one chunk's FULL ciphertext field (body + tag), in chunk-index
139
+ * order. The index and length are framed alongside the bytes so
140
+ * reordering or splicing a chunk changes the digest.
141
+ */
142
+ absorbChunk(chunkIndex: number, ciphertext: Uint8Array): void {
143
+ if (!this.headerAbsorbed) {
144
+ throw new SignatureError('transcript_header_not_absorbed')
145
+ }
146
+ this.hash.update(uint64BE(chunkIndex))
147
+ this.hash.update(uint64BE(ciphertext.length))
148
+ this.hash.update(ciphertext)
149
+ }
150
+
151
+ /** Finalize and return the 32-byte transcript digest. Single-use. */
152
+ digest(): Uint8Array {
153
+ if (!this.headerAbsorbed) {
154
+ throw new SignatureError('transcript_header_not_absorbed')
155
+ }
156
+ return this.hash.digest()
157
+ }
158
+ }
159
+
160
+ /**
161
+ * Produce a detached Ed25519 signature over a {@link SenderSigTranscript}
162
+ * digest (see the class docstring for the transcript definition).
85
163
  *
86
164
  * Returns the raw 64-byte signature. Callers wrap it in a signature block
87
165
  * via `buildSignatureBlock`.
88
166
  */
89
- export function signHeaderAndMacs(input: {
167
+ export function signSenderTranscript(input: {
90
168
  ed25519SecretKey: Uint8Array
91
- header: Uint8Array
92
- chunkMacs: ReadonlyArray<Uint8Array>
169
+ transcriptDigest: Uint8Array
93
170
  }): Uint8Array {
94
171
  if (input.ed25519SecretKey.length !== ED25519_SECRET_KEY_LENGTH) {
95
172
  throw new SignatureError('ed25519_secret_key_wrong_length')
96
173
  }
97
- const message = buildSignedMessage(input.header, input.chunkMacs)
98
- return ed25519.sign(message, input.ed25519SecretKey)
174
+ return ed25519.sign(input.transcriptDigest, input.ed25519SecretKey)
99
175
  }
100
176
 
101
177
  /**
102
- * Verify a detached Ed25519 signature produced by `signHeaderAndMacs`.
178
+ * Verify a detached Ed25519 signature produced by `signSenderTranscript`.
103
179
  * Returns `true` on success, `false` on any failure (wrong length,
104
180
  * malformed point, bad signature). Never throws on a verification
105
181
  * mismatch — failures are not exceptional.
106
182
  */
107
- export function verifyHeaderAndMacs(input: {
183
+ export function verifySenderTranscript(input: {
108
184
  ed25519PublicKey: Uint8Array
109
- header: Uint8Array
110
- chunkMacs: ReadonlyArray<Uint8Array>
185
+ transcriptDigest: Uint8Array
111
186
  signature: Uint8Array
112
187
  }): boolean {
113
188
  if (input.ed25519PublicKey.length !== ED25519_PUBLIC_KEY_LENGTH) return false
114
189
  if (input.signature.length !== ED25519_SIGNATURE_LENGTH) return false
115
- const message = buildSignedMessage(input.header, input.chunkMacs)
116
190
  try {
117
- return ed25519.verify(input.signature, message, input.ed25519PublicKey)
191
+ return ed25519.verify(
192
+ input.signature,
193
+ input.transcriptDigest,
194
+ input.ed25519PublicKey,
195
+ )
118
196
  } catch {
119
197
  // Malformed pubkey or sig encoding — noble throws; we treat as not-verified.
120
198
  return false
package/src/index.ts CHANGED
@@ -103,7 +103,7 @@ export * as migrationV0 from './migration/v0-bridge.js'
103
103
  // Auto-routing decryptor
104
104
  // ──────────────────────────────────────────────────────────────────────
105
105
  import { parseHeader, HeaderError } from './format/header.js'
106
- import { SUITE, type SuiteId } from './internal/types.js'
106
+ import { SUITE, type SuiteId, type ProgressCallback } from './internal/types.js'
107
107
  import * as aes from './suites/aes-gcm-v1/api.js'
108
108
  import * as aesV2 from './suites/aes-gcm-v2/api.js'
109
109
  import * as xchacha from './suites/xchacha-v1/api.js'
@@ -118,7 +118,7 @@ export interface AutoDecryptOptions {
118
118
  /** Required for PQ-hybrid: classical 32-byte envelope key */
119
119
  envelopeKey?: Uint8Array
120
120
  /** Optional progress callback (0..1) */
121
- onProgress?: (progress: number) => void
121
+ onProgress?: ProgressCallback
122
122
  }
123
123
 
124
124
  /**
@@ -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-beta.3'
221
+ export const SHIELDFIVE_CRYPTO_VERSION = '1.0.0-rc.1'
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
@@ -47,11 +47,12 @@ import {
47
47
  deriveEd25519PublicKey,
48
48
  ED25519_SECRET_KEY_LENGTH,
49
49
  parseSignatureBlock,
50
+ SenderSigTranscript,
50
51
  SIGNATURE_ALGO_ED25519,
51
- signHeaderAndMacs,
52
+ signSenderTranscript,
52
53
  type SignatureBlock,
53
54
  SignatureError,
54
- verifyHeaderAndMacs,
55
+ verifySenderTranscript,
55
56
  } from '../identity/sign.js'
56
57
 
57
58
  const LENGTH_PREFIX_BYTES = 4
@@ -73,9 +74,10 @@ export interface AesGcmV1EncryptStreamOptions {
73
74
  suitePayloadOverride?: Uint8Array
74
75
  /**
75
76
  * Optional 32-byte Ed25519 secret seed. When provided, the stream
76
- * appends a signature block over `header_unauthenticated_bytes ||
77
- * concat(chunk_macs)` after the final chunk. When omitted, no block
78
- * is emitted and the file decrypts as unsigned (legacy behavior).
77
+ * appends a signature block after the final chunk, signing a transcript
78
+ * that commits to the header and every chunk's full ciphertext (see
79
+ * {@link SenderSigTranscript}). When omitted, no block is emitted and
80
+ * the file decrypts as unsigned (legacy behavior).
79
81
  */
80
82
  ed25519SecretKey?: Uint8Array
81
83
  }
@@ -152,15 +154,14 @@ export function createAesGcmV1EncryptStream(
152
154
  // - chunk index counter
153
155
  // - bytes consumed counter (for sanity check vs plaintextSize)
154
156
  // - context (lazily initialized)
155
- // - unauthenticated header bytes (kept for signing)
156
- // - per-chunk MAC tags (last 16 bytes of each chunk ciphertext)
157
+ // - signature transcript (present only when signing): commits to the
158
+ // header and every chunk's full ciphertext, hashed incrementally
157
159
  let pending = new Uint8Array(0)
158
160
  let chunkIndex = 0
159
161
  let bytesConsumed = 0
160
162
  let contextPromise: ReturnType<typeof createChunkContext> | null = null
161
163
  let headerEmitted = false
162
- let unauthenticatedHeader: Uint8Array | null = null
163
- const chunkMacs: Uint8Array[] = []
164
+ const transcript = ed25519SecretKey ? new SenderSigTranscript() : null
164
165
 
165
166
  async function ensureHeader(
166
167
  controller: TransformStreamDefaultController<Uint8Array>,
@@ -176,7 +177,7 @@ export function createAesGcmV1EncryptStream(
176
177
  })
177
178
  const macKey = await deriveHeaderMacKey(contentKey, fileId)
178
179
  const mac = await hmacSha256(macKey, unauth)
179
- unauthenticatedHeader = unauth
180
+ transcript?.absorbHeader(unauth, totalChunks)
180
181
  controller.enqueue(concatBytes([unauth, mac]))
181
182
  headerEmitted = true
182
183
  }
@@ -192,10 +193,9 @@ export function createAesGcmV1EncryptStream(
192
193
  const ct = await encryptChunk(ctx, chunkIndex, plaintext)
193
194
  controller.enqueue(uint32BE(ct.length))
194
195
  controller.enqueue(ct)
195
- if (ed25519SecretKey) {
196
- // AEAD tag is the trailing AES_GCM_V1_TAG_BYTES of the chunk ct.
197
- chunkMacs.push(ct.slice(ct.length - AES_GCM_V1_TAG_BYTES))
198
- }
196
+ // Commit the FULL chunk ciphertext (body + tag) to the signature
197
+ // transcript, not just the malleable AEAD tag.
198
+ transcript?.absorbChunk(chunkIndex, ct)
199
199
  chunkIndex += 1
200
200
  }
201
201
 
@@ -251,16 +251,15 @@ export function createAesGcmV1EncryptStream(
251
251
  return
252
252
  }
253
253
  if (ed25519SecretKey) {
254
- if (!unauthenticatedHeader) {
254
+ if (!transcript) {
255
255
  controller.error(
256
- new Error('encrypt stream: header not finalized before signing'),
256
+ new Error('encrypt stream: signature transcript not initialized'),
257
257
  )
258
258
  return
259
259
  }
260
- const signature = signHeaderAndMacs({
260
+ const signature = signSenderTranscript({
261
261
  ed25519SecretKey,
262
- header: unauthenticatedHeader,
263
- chunkMacs,
262
+ transcriptDigest: transcript.digest(),
264
263
  })
265
264
  const publicKey = deriveEd25519PublicKey(ed25519SecretKey)
266
265
  controller.enqueue(
@@ -372,7 +371,9 @@ export function createAesGcmV1DecryptStream(
372
371
  let bytesEmitted = 0
373
372
  let nextCipherLen = -1
374
373
  let contextPromise: ReturnType<typeof createChunkContext> | null = null
375
- const chunkMacs: Uint8Array[] = []
374
+ // Rebuilds the signer's transcript as chunks arrive so a trailing
375
+ // signature block can be verified against the actual ciphertext.
376
+ const transcript = new SenderSigTranscript()
376
377
 
377
378
  function append(input: Uint8Array): void {
378
379
  const merged = new Uint8Array(buffer.length + input.length)
@@ -440,6 +441,11 @@ export function createAesGcmV1DecryptStream(
440
441
  // authenticated bytes.
441
442
  parseAesGcmV1SuitePayload(parsedHeader.suitePayload)
442
443
 
444
+ transcript.absorbHeader(
445
+ parsedHeader.unauthenticatedBytes,
446
+ parsedHeader.totalChunks,
447
+ )
448
+
443
449
  contextPromise = createChunkContext(
444
450
  contentKey,
445
451
  parsedHeader.fileId,
@@ -486,9 +492,9 @@ export function createAesGcmV1DecryptStream(
486
492
  const pt = await decryptChunk(ctx, chunkIndex, ctBytes)
487
493
  bytesEmitted += pt.length
488
494
  controller.enqueue(pt)
489
- // AEAD tag is the trailing AES_GCM_V1_TAG_BYTES of ctBytes. Kept
490
- // for optional signature verification at flush time.
491
- chunkMacs.push(ctBytes.slice(ctBytes.length - AES_GCM_V1_TAG_BYTES))
495
+ // Commit the FULL chunk ciphertext (body + tag) to the transcript for
496
+ // optional signature verification at flush time.
497
+ transcript.absorbChunk(chunkIndex, ctBytes)
492
498
  chunkIndex += 1
493
499
  return true
494
500
  }
@@ -532,8 +538,7 @@ export function createAesGcmV1DecryptStream(
532
538
  }
533
539
  const signatureResult = finalizeSignatureMetadata({
534
540
  trailingBytes: buffer,
535
- header: parsedHeader.unauthenticatedBytes,
536
- chunkMacs,
541
+ transcriptDigest: transcript.digest(),
537
542
  expectedSignerPublicKey,
538
543
  })
539
544
  buffer = new Uint8Array(0)
@@ -598,13 +603,16 @@ export function decryptStreamAesGcmV1(
598
603
  * residual buffer, optionally verifying it against the caller's
599
604
  * trusted public key.
600
605
  *
606
+ * `transcriptDigest` is the {@link SenderSigTranscript} digest rebuilt
607
+ * over the header and every chunk's full ciphertext as it was decrypted,
608
+ * so `verified: true` means the signer signed exactly these bytes.
609
+ *
601
610
  * Shared between the AES-GCM and PQ-hybrid stream decoders so the
602
611
  * signature semantics live in one place.
603
612
  */
604
613
  export function finalizeSignatureMetadata(input: {
605
614
  trailingBytes: Uint8Array
606
- header: Uint8Array
607
- chunkMacs: ReadonlyArray<Uint8Array>
615
+ transcriptDigest: Uint8Array
608
616
  expectedSignerPublicKey: Uint8Array | undefined
609
617
  }): VerifiedSignature | null {
610
618
  if (input.trailingBytes.length === 0) {
@@ -638,10 +646,9 @@ export function finalizeSignatureMetadata(input: {
638
646
  // the file was signed by the key the caller expected.
639
647
  verified =
640
648
  bytesEqualConstantTime(publicKey, input.expectedSignerPublicKey) &&
641
- verifyHeaderAndMacs({
649
+ verifySenderTranscript({
642
650
  ed25519PublicKey: input.expectedSignerPublicKey,
643
- header: input.header,
644
- chunkMacs: input.chunkMacs,
651
+ transcriptDigest: input.transcriptDigest,
645
652
  signature,
646
653
  })
647
654
  }