@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.
Files changed (124) hide show
  1. package/CHANGELOG.md +228 -0
  2. package/LICENSE +201 -0
  3. package/README.md +275 -0
  4. package/SECURITY.md +130 -0
  5. package/dist/format/header.d.ts +73 -0
  6. package/dist/format/header.d.ts.map +1 -0
  7. package/dist/format/header.js +230 -0
  8. package/dist/format/header.js.map +1 -0
  9. package/dist/identity/index.d.ts +119 -0
  10. package/dist/identity/index.d.ts.map +1 -0
  11. package/dist/identity/index.js +217 -0
  12. package/dist/identity/index.js.map +1 -0
  13. package/dist/identity/sign.d.ts +92 -0
  14. package/dist/identity/sign.d.ts.map +1 -0
  15. package/dist/identity/sign.js +182 -0
  16. package/dist/identity/sign.js.map +1 -0
  17. package/dist/index.d.ts +58 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +146 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/internal/encoding.d.ts +33 -0
  22. package/dist/internal/encoding.d.ts.map +1 -0
  23. package/dist/internal/encoding.js +135 -0
  24. package/dist/internal/encoding.js.map +1 -0
  25. package/dist/internal/hkdf.d.ts +14 -0
  26. package/dist/internal/hkdf.d.ts.map +1 -0
  27. package/dist/internal/hkdf.js +27 -0
  28. package/dist/internal/hkdf.js.map +1 -0
  29. package/dist/internal/hmac.d.ts +9 -0
  30. package/dist/internal/hmac.d.ts.map +1 -0
  31. package/dist/internal/hmac.js +18 -0
  32. package/dist/internal/hmac.js.map +1 -0
  33. package/dist/internal/runtime.d.ts +29 -0
  34. package/dist/internal/runtime.d.ts.map +1 -0
  35. package/dist/internal/runtime.js +67 -0
  36. package/dist/internal/runtime.js.map +1 -0
  37. package/dist/internal/sodium.d.ts +12 -0
  38. package/dist/internal/sodium.d.ts.map +1 -0
  39. package/dist/internal/sodium.js +34 -0
  40. package/dist/internal/sodium.js.map +1 -0
  41. package/dist/internal/types.d.ts +98 -0
  42. package/dist/internal/types.d.ts.map +1 -0
  43. package/dist/internal/types.js +70 -0
  44. package/dist/internal/types.js.map +1 -0
  45. package/dist/kdf/argon2id.d.ts +72 -0
  46. package/dist/kdf/argon2id.d.ts.map +1 -0
  47. package/dist/kdf/argon2id.js +98 -0
  48. package/dist/kdf/argon2id.js.map +1 -0
  49. package/dist/migration/v0-bridge.d.ts +94 -0
  50. package/dist/migration/v0-bridge.d.ts.map +1 -0
  51. package/dist/migration/v0-bridge.js +203 -0
  52. package/dist/migration/v0-bridge.js.map +1 -0
  53. package/dist/streams/aes-gcm-v1.d.ts +144 -0
  54. package/dist/streams/aes-gcm-v1.d.ts.map +1 -0
  55. package/dist/streams/aes-gcm-v1.js +456 -0
  56. package/dist/streams/aes-gcm-v1.js.map +1 -0
  57. package/dist/streams/pq-hybrid-v1.d.ts +219 -0
  58. package/dist/streams/pq-hybrid-v1.d.ts.map +1 -0
  59. package/dist/streams/pq-hybrid-v1.js +473 -0
  60. package/dist/streams/pq-hybrid-v1.js.map +1 -0
  61. package/dist/suites/aes-gcm-v0/api.d.ts +48 -0
  62. package/dist/suites/aes-gcm-v0/api.d.ts.map +1 -0
  63. package/dist/suites/aes-gcm-v0/api.js +110 -0
  64. package/dist/suites/aes-gcm-v0/api.js.map +1 -0
  65. package/dist/suites/aes-gcm-v1/api.d.ts +54 -0
  66. package/dist/suites/aes-gcm-v1/api.d.ts.map +1 -0
  67. package/dist/suites/aes-gcm-v1/api.js +181 -0
  68. package/dist/suites/aes-gcm-v1/api.js.map +1 -0
  69. package/dist/suites/aes-gcm-v1/index.d.ts +59 -0
  70. package/dist/suites/aes-gcm-v1/index.d.ts.map +1 -0
  71. package/dist/suites/aes-gcm-v1/index.js +177 -0
  72. package/dist/suites/aes-gcm-v1/index.js.map +1 -0
  73. package/dist/suites/aes-gcm-v2/api.d.ts +44 -0
  74. package/dist/suites/aes-gcm-v2/api.d.ts.map +1 -0
  75. package/dist/suites/aes-gcm-v2/api.js +162 -0
  76. package/dist/suites/aes-gcm-v2/api.js.map +1 -0
  77. package/dist/suites/aes-gcm-v2/index.d.ts +63 -0
  78. package/dist/suites/aes-gcm-v2/index.d.ts.map +1 -0
  79. package/dist/suites/aes-gcm-v2/index.js +193 -0
  80. package/dist/suites/aes-gcm-v2/index.js.map +1 -0
  81. package/dist/suites/pq-hybrid-v1/api.d.ts +67 -0
  82. package/dist/suites/pq-hybrid-v1/api.d.ts.map +1 -0
  83. package/dist/suites/pq-hybrid-v1/api.js +190 -0
  84. package/dist/suites/pq-hybrid-v1/api.js.map +1 -0
  85. package/dist/suites/pq-hybrid-v1/index.d.ts +101 -0
  86. package/dist/suites/pq-hybrid-v1/index.d.ts.map +1 -0
  87. package/dist/suites/pq-hybrid-v1/index.js +225 -0
  88. package/dist/suites/pq-hybrid-v1/index.js.map +1 -0
  89. package/dist/suites/xchacha-v1/api.d.ts +29 -0
  90. package/dist/suites/xchacha-v1/api.d.ts.map +1 -0
  91. package/dist/suites/xchacha-v1/api.js +154 -0
  92. package/dist/suites/xchacha-v1/api.js.map +1 -0
  93. package/dist/suites/xchacha-v1/index.d.ts +50 -0
  94. package/dist/suites/xchacha-v1/index.d.ts.map +1 -0
  95. package/dist/suites/xchacha-v1/index.js +133 -0
  96. package/dist/suites/xchacha-v1/index.js.map +1 -0
  97. package/package.json +124 -0
  98. package/spec/format-v0.md +81 -0
  99. package/spec/format-v1.md +400 -0
  100. package/spec/key-derivation.md +167 -0
  101. package/spec/threat-model.md +242 -0
  102. package/src/format/header.ts +316 -0
  103. package/src/identity/index.ts +371 -0
  104. package/src/identity/sign.ts +221 -0
  105. package/src/index.ts +224 -0
  106. package/src/internal/encoding.ts +152 -0
  107. package/src/internal/hkdf.ts +47 -0
  108. package/src/internal/hmac.ts +33 -0
  109. package/src/internal/runtime.ts +80 -0
  110. package/src/internal/sodium.ts +38 -0
  111. package/src/internal/types.ts +134 -0
  112. package/src/kdf/argon2id.ts +165 -0
  113. package/src/migration/v0-bridge.ts +347 -0
  114. package/src/streams/aes-gcm-v1.ts +647 -0
  115. package/src/streams/pq-hybrid-v1.ts +722 -0
  116. package/src/suites/aes-gcm-v0/api.ts +155 -0
  117. package/src/suites/aes-gcm-v1/api.ts +292 -0
  118. package/src/suites/aes-gcm-v1/index.ts +269 -0
  119. package/src/suites/aes-gcm-v2/api.ts +268 -0
  120. package/src/suites/aes-gcm-v2/index.ts +289 -0
  121. package/src/suites/pq-hybrid-v1/api.ts +299 -0
  122. package/src/suites/pq-hybrid-v1/index.ts +343 -0
  123. package/src/suites/xchacha-v1/api.ts +254 -0
  124. package/src/suites/xchacha-v1/index.ts +213 -0
@@ -0,0 +1,190 @@
1
+ /**
2
+ * High-level encrypt/decrypt API for the PQ-hybrid v1 suite.
3
+ *
4
+ * Differs from aes-gcm-v1 / xchacha-v1 because content key derivation is
5
+ * not a single random 32-byte buffer — instead, the combined key is
6
+ * recovered from the on-disk suite payload (PQ ciphertext + wrapped
7
+ * classical share) and the recipient's PQ secret key + envelope key.
8
+ *
9
+ * The header MAC is keyed by the *combined* key, so a successful header
10
+ * MAC verification proves both the PQ KEM and the classical wrap were
11
+ * recovered correctly.
12
+ */
13
+ import { buildAuthenticatedHeader, parseHeader, verifyHeaderMac, HeaderError, } from '../../format/header.js';
14
+ import { PQ_HYBRID_V1_SUITE_PAYLOAD_LENGTH, PQ_HYBRID_V1_TAG_BYTES, createChunkContext, decapsulateFromHeader, decryptChunk, encapsulateForRecipient, encryptChunk, } from './index.js';
15
+ import { DEFAULT_CHUNK_SIZE, HEADER_SIZES, MAX_TOTAL_CHUNKS, SUITE, } from '../../internal/types.js';
16
+ import { asBlobPart, readUint32BE, uint32BE, } from '../../internal/encoding.js';
17
+ import { randomBytes } from '../../internal/runtime.js';
18
+ // Re-exports of suite primitives that are useful to callers outside the
19
+ // streaming/whole-blob API surfaces. `decapsulateFromHeader` lets a
20
+ // caller that already has the parsed suite_payload + KEM material
21
+ // recover the combined key K out-of-band (e.g., a share-link generator
22
+ // that wraps K under a separate password for recipients who never see
23
+ // ML-KEM secrets).
24
+ export { decapsulateFromHeader, deriveMlKemKeypair, encapsulateForRecipient, generateMlKemKeypair, PQ_HYBRID_V1_SUITE_PAYLOAD_LENGTH, } from './index.js';
25
+ const LENGTH_PREFIX_BYTES = 4;
26
+ /**
27
+ * Encrypt a Blob under suite 0x03 (PQ-hybrid XChaCha20-Poly1305 +
28
+ * ML-KEM-1024). Returns the encrypted file alongside the combined
29
+ * content key used to produce it.
30
+ *
31
+ * SECURITY: The returned `combinedKey` grants permanent decryption
32
+ * capability for any file whose header was produced with it. Treat
33
+ * as cryptographic secret material: hold only in memory for the
34
+ * duration of the operation, do not persist to disk or storage, do
35
+ * not log, do not transmit. The only safe way to reproduce it on
36
+ * another machine is to re-encapsulate via the recipient's ML-KEM
37
+ * public key.
38
+ */
39
+ export async function encryptBlob(options) {
40
+ const { blob, recipientPublicKey, envelopeKey, onProgress } = options;
41
+ if (!(blob instanceof Blob)) {
42
+ throw new TypeError('encryptBlob: blob must be a Blob or File');
43
+ }
44
+ const chunkSize = options.chunkSize ?? DEFAULT_CHUNK_SIZE;
45
+ if (!Number.isSafeInteger(chunkSize) || chunkSize <= 0) {
46
+ throw new RangeError('encryptBlob: chunkSize must be a positive integer');
47
+ }
48
+ const plaintextSize = blob.size;
49
+ const totalChunks = plaintextSize === 0 ? 0 : Math.ceil(plaintextSize / chunkSize);
50
+ if (totalChunks > MAX_TOTAL_CHUNKS) {
51
+ throw new RangeError('encryptBlob: file would exceed total_chunks limit');
52
+ }
53
+ const fileId = options.fileId ?? randomBytes(HEADER_SIZES.FILE_ID);
54
+ if (fileId.length !== HEADER_SIZES.FILE_ID) {
55
+ throw new RangeError('encryptBlob: fileId must be 16 bytes');
56
+ }
57
+ // PQ + classical encapsulation produces the suite payload AND the
58
+ // combined key in one step. The combined key is what authenticates the
59
+ // header and encrypts every chunk.
60
+ const { suitePayload, combinedKey } = await encapsulateForRecipient({
61
+ recipientPublicKey,
62
+ envelopeKey,
63
+ fileId,
64
+ });
65
+ const header = await buildAuthenticatedHeader({
66
+ suite: SUITE.PQ_HYBRID_XCHACHA_MLKEM1024_V1,
67
+ fileId,
68
+ chunkSize,
69
+ totalChunks,
70
+ plaintextSize,
71
+ suitePayload,
72
+ }, combinedKey);
73
+ const ctx = await createChunkContext(combinedKey, fileId, totalChunks);
74
+ const parts = [asBlobPart(header)];
75
+ for (let i = 0; i < totalChunks; i += 1) {
76
+ const start = i * chunkSize;
77
+ const end = Math.min(start + chunkSize, plaintextSize);
78
+ const plaintextBytes = new Uint8Array(await blob.slice(start, end).arrayBuffer());
79
+ const ciphertext = await encryptChunk(ctx, i, plaintextBytes);
80
+ parts.push(asBlobPart(uint32BE(ciphertext.length)));
81
+ parts.push(asBlobPart(ciphertext));
82
+ onProgress?.((i + 1) / Math.max(totalChunks, 1));
83
+ }
84
+ if (totalChunks === 0)
85
+ onProgress?.(1);
86
+ return {
87
+ blob: new Blob(parts, { type: 'application/octet-stream' }),
88
+ suite: SUITE.PQ_HYBRID_XCHACHA_MLKEM1024_V1,
89
+ fileId,
90
+ chunkSize,
91
+ totalChunks,
92
+ plaintextSize,
93
+ combinedKey,
94
+ };
95
+ }
96
+ export async function decryptBlob(options) {
97
+ const { blob, recipientSecretKey, envelopeKey, onProgress } = options;
98
+ if (!(blob instanceof Blob)) {
99
+ throw new TypeError('decryptBlob: blob must be a Blob or File');
100
+ }
101
+ // The header for this suite is large because suite_payload is 1664 bytes.
102
+ // Probe enough bytes to capture it.
103
+ const headerProbeSize = Math.min(blob.size, HEADER_SIZES.MAGIC +
104
+ HEADER_SIZES.SUITE +
105
+ HEADER_SIZES.FLAGS +
106
+ HEADER_SIZES.FILE_ID +
107
+ HEADER_SIZES.CHUNK_SIZE +
108
+ HEADER_SIZES.TOTAL_CHUNKS +
109
+ HEADER_SIZES.PLAINTEXT_SIZE +
110
+ HEADER_SIZES.SUITE_PAYLOAD_LEN +
111
+ PQ_HYBRID_V1_SUITE_PAYLOAD_LENGTH +
112
+ HEADER_SIZES.HEADER_MAC +
113
+ 32);
114
+ const headerProbeBytes = new Uint8Array(await blob.slice(0, headerProbeSize).arrayBuffer());
115
+ const parsed = parseHeader(headerProbeBytes);
116
+ if (parsed.suite !== SUITE.PQ_HYBRID_XCHACHA_MLKEM1024_V1) {
117
+ throw new HeaderError(`decryptBlob: this entry point only supports pq-hybrid-xchacha-mlkem1024-v1; got suite 0x${parsed.suite.toString(16)}`);
118
+ }
119
+ // Recover the combined key — this is where PQ decapsulation happens.
120
+ const { combinedKey } = await decapsulateFromHeader({
121
+ suitePayload: parsed.suitePayload,
122
+ recipientSecretKey,
123
+ envelopeKey,
124
+ fileId: parsed.fileId,
125
+ });
126
+ // The header MAC implicitly verifies that the right combined key was
127
+ // recovered (i.e., the PQ secret + envelope key match the file).
128
+ await verifyHeaderMac(parsed, combinedKey);
129
+ const ctx = await createChunkContext(combinedKey, parsed.fileId, parsed.totalChunks);
130
+ const plaintextParts = [];
131
+ let cursor = parsed.headerLength;
132
+ let bytesEmitted = 0;
133
+ for (let i = 0; i < parsed.totalChunks; i += 1) {
134
+ if (cursor + LENGTH_PREFIX_BYTES > blob.size) {
135
+ throw new HeaderError('chunk_length_truncated');
136
+ }
137
+ const lenBytes = new Uint8Array(await blob.slice(cursor, cursor + LENGTH_PREFIX_BYTES).arrayBuffer());
138
+ cursor += LENGTH_PREFIX_BYTES;
139
+ const cipherLen = readUint32BE(lenBytes);
140
+ const isFinal = i === parsed.totalChunks - 1;
141
+ const minCipher = 1 + PQ_HYBRID_V1_TAG_BYTES;
142
+ const maxCipher = parsed.chunkSize + PQ_HYBRID_V1_TAG_BYTES;
143
+ if (cipherLen < minCipher || cipherLen > maxCipher) {
144
+ throw new HeaderError('chunk_length_out_of_range');
145
+ }
146
+ if (!isFinal && cipherLen !== maxCipher) {
147
+ throw new HeaderError('non_final_chunk_wrong_size');
148
+ }
149
+ if (cursor + cipherLen > blob.size) {
150
+ throw new HeaderError('chunk_truncated');
151
+ }
152
+ const cipherBytes = new Uint8Array(await blob.slice(cursor, cursor + cipherLen).arrayBuffer());
153
+ cursor += cipherLen;
154
+ const plaintext = await decryptChunk(ctx, i, cipherBytes);
155
+ bytesEmitted += plaintext.length;
156
+ plaintextParts.push(asBlobPart(plaintext));
157
+ onProgress?.((i + 1) / Math.max(parsed.totalChunks, 1));
158
+ }
159
+ if (bytesEmitted !== parsed.plaintextSize) {
160
+ throw new HeaderError('plaintext_size_mismatch');
161
+ }
162
+ if (cursor !== blob.size) {
163
+ throw new HeaderError('trailing_bytes_after_last_chunk');
164
+ }
165
+ if (parsed.totalChunks === 0)
166
+ onProgress?.(1);
167
+ return new Blob(plaintextParts, { type: 'application/octet-stream' });
168
+ }
169
+ /**
170
+ * Encrypt a Uint8Array under suite 0x03 (PQ-hybrid XChaCha20-Poly1305 +
171
+ * ML-KEM-1024). Returns the encrypted file alongside the combined
172
+ * content key used to produce it.
173
+ *
174
+ * SECURITY: The returned `combinedKey` grants permanent decryption
175
+ * capability for any file whose header was produced with it. Treat
176
+ * as cryptographic secret material: hold only in memory for the
177
+ * duration of the operation, do not persist to disk or storage, do
178
+ * not log, do not transmit. The only safe way to reproduce it on
179
+ * another machine is to re-encapsulate via the recipient's ML-KEM
180
+ * public key.
181
+ */
182
+ export async function encryptBytes(bytes, options) {
183
+ const blob = new Blob([asBlobPart(bytes)]);
184
+ return encryptBlob({ blob, ...options });
185
+ }
186
+ export async function decryptToBytes(options) {
187
+ const blob = await decryptBlob(options);
188
+ return new Uint8Array(await blob.arrayBuffer());
189
+ }
190
+ //# sourceMappingURL=api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.js","sourceRoot":"","sources":["../../../src/suites/pq-hybrid-v1/api.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,wBAAwB,EACxB,WAAW,EACX,eAAe,EACf,WAAW,GACZ,MAAM,wBAAwB,CAAA;AAC/B,OAAO,EACL,iCAAiC,EACjC,sBA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;QAC1C,MAAM,IAAI,WAAW,CAAC,yBAAyB,CAAC,CAAA;IAClD,CAAC;IACD,IAAI,MAAM,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC;QACzB,MAAM,IAAI,WAAW,CAAC,iCAAiC,CAAC,CAAA;IAC1D,CAAC;IAED,IAAI,MAAM,CAAC,WAAW,KAAK,CAAC;QAAE,UAAU,EAAE,CAAC,CAAC,CAAC,CAAA;IAE7C,OAAO,IAAI,IAAI,CAAC,cAAc,EAAE,EAAE,IAAI,EAAE,0BAA0B,EAAE,CAAC,CAAA;AACvE,CAAC;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,KAAiB,EACjB,OAA6C;IAE7C,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAC1C,OAAO,WAAW,CAAC,EAAE,IAAI,EAAE,GAAG,OAAO,EAAE,CAAC,CAAA;AAC1C,CAAC;AAED,MAAM,CAAC,KAAK,UAAU,cAAc,CAClC,OAA+B;IAE/B,MAAM,IAAI,GAAG,MAAM,WAAW,CAAC,OAAO,CAAC,CAAA;IACvC,OAAO,IAAI,UAAU,CAAC,MAAM,IAAI,CAAC,WAAW,EAAE,CAAC,CAAA;AACjD,CAAC"}
@@ -0,0 +1,101 @@
1
+ /**
2
+ * Cipher suite 0x03: PQ-hybrid XChaCha20-Poly1305 + ML-KEM-1024 v1.
3
+ *
4
+ * The default suite for new files. Combines a classical 32-byte secret with
5
+ * an ML-KEM-1024 encapsulated 32-byte shared secret. The combined key is
6
+ * derived via HKDF-SHA-256 with the file_id as salt.
7
+ *
8
+ * Security: an adversary must break BOTH ML-KEM-1024 AND the classical
9
+ * KDF/wrap to recover plaintext. ML-KEM-1024 is FIPS 203, security level
10
+ * 5 (≈AES-256 against quantum search).
11
+ *
12
+ * Implementation:
13
+ * - Classical share encrypted under envelope key with XSalsa20-Poly1305
14
+ * secretbox (libsodium).
15
+ * - PQ encapsulation via @noble/post-quantum's ML-KEM-1024.
16
+ * - Chunk AEAD identical to xchacha-v1 once the combined key is derived.
17
+ */
18
+ import { type ParsedHeader } from '../../internal/types.js';
19
+ export declare const PQ_HYBRID_V1_KEY_BYTES = 32;
20
+ export declare const PQ_HYBRID_V1_NONCE_BYTES = 24;
21
+ export declare const PQ_HYBRID_V1_TAG_BYTES = 16;
22
+ /** ML-KEM-1024 ciphertext length per FIPS 203. */
23
+ export declare const ML_KEM_1024_CIPHERTEXT_BYTES = 1568;
24
+ /** ML-KEM-1024 public key length per FIPS 203. */
25
+ export declare const ML_KEM_1024_PUBLIC_KEY_BYTES = 1568;
26
+ /** ML-KEM-1024 secret key length per FIPS 203. */
27
+ export declare const ML_KEM_1024_SECRET_KEY_BYTES = 3168;
28
+ /**
29
+ * Suite payload layout:
30
+ * mlkem_ciphertext (1568 bytes)
31
+ * classical_wrapped (72 bytes — 48 bytes secretbox + 24 bytes reserved zero pad)
32
+ * classical_nonce (24 bytes)
33
+ * Total: 1664 bytes
34
+ */
35
+ export declare const PQ_HYBRID_V1_SUITE_PAYLOAD_LENGTH: number;
36
+ export interface PqHybridV1SuitePayload {
37
+ mlkemCiphertext: Uint8Array;
38
+ classicalWrapped: Uint8Array;
39
+ classicalNonce: Uint8Array;
40
+ }
41
+ export declare function buildPqHybridV1SuitePayload(payload: PqHybridV1SuitePayload): Uint8Array;
42
+ export declare function parsePqHybridV1SuitePayload(bytes: Uint8Array): PqHybridV1SuitePayload;
43
+ /**
44
+ * Generate an ML-KEM-1024 keypair. In production the keypair is derived
45
+ * deterministically from the user's master secret via HKDF; this function
46
+ * is exposed for testing and advanced callers.
47
+ */
48
+ export declare function generateMlKemKeypair(): {
49
+ publicKey: Uint8Array;
50
+ secretKey: Uint8Array;
51
+ };
52
+ /**
53
+ * Derive an ML-KEM-1024 keypair deterministically from a master secret.
54
+ * The seed input is 64 bytes; we derive it via HKDF so the same master
55
+ * secret always yields the same keypair across sessions and devices.
56
+ */
57
+ export declare function deriveMlKemKeypair(masterSecret: Uint8Array): Promise<{
58
+ publicKey: Uint8Array;
59
+ secretKey: Uint8Array;
60
+ }>;
61
+ export interface PqHybridV1ChunkContext {
62
+ combinedKey: Uint8Array;
63
+ noncePrefix: Uint8Array;
64
+ totalChunks: number;
65
+ }
66
+ export declare function encryptChunk(ctx: PqHybridV1ChunkContext, chunkIndex: number, plaintext: Uint8Array): Promise<Uint8Array>;
67
+ export declare function decryptChunk(ctx: PqHybridV1ChunkContext, chunkIndex: number, ciphertext: Uint8Array): Promise<Uint8Array>;
68
+ /**
69
+ * Sender side: produce the suite payload and the combined key.
70
+ *
71
+ * Inputs:
72
+ * - recipient's ML-KEM public key
73
+ * - envelopeKey: classical key under which the classical share is wrapped
74
+ * - fileId: per-file ID used as HKDF salt
75
+ *
76
+ * Outputs:
77
+ * - the suite payload bytes
78
+ * - the combined content key (used for header MAC and chunk AEAD)
79
+ */
80
+ export declare function encapsulateForRecipient(options: {
81
+ recipientPublicKey: Uint8Array;
82
+ envelopeKey: Uint8Array;
83
+ fileId: Uint8Array;
84
+ }): Promise<{
85
+ suitePayload: Uint8Array;
86
+ combinedKey: Uint8Array;
87
+ }>;
88
+ /**
89
+ * Recipient side: recover the combined content key from the suite payload.
90
+ */
91
+ export declare function decapsulateFromHeader(options: {
92
+ suitePayload: Uint8Array;
93
+ recipientSecretKey: Uint8Array;
94
+ envelopeKey: Uint8Array;
95
+ fileId: Uint8Array;
96
+ }): Promise<{
97
+ combinedKey: Uint8Array;
98
+ }>;
99
+ export declare function createChunkContext(combinedKey: Uint8Array, fileId: Uint8Array, totalChunks: number): Promise<PqHybridV1ChunkContext>;
100
+ export declare function getSuitePayloadFromHeader(header: ParsedHeader): PqHybridV1SuitePayload;
101
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/suites/pq-hybrid-v1/index.ts"],"names":[],"mappings":"AAAA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AChC,GAAG,EAAE,sBAAsB,EAC3B,UAAU,EAAE,MAAM,EAClB,UAAU,EAAE,UAAU,GACrB,OAAO,CAAC,UAAU,CAAC,CAYrB;AAED;;;;;;;;;;;GAWG;AACH,wBAAsB,uBAAuB,CAAC,OAAO,EAAE;IACrD,kBAAkB,EAAE,UAAU,CAAA;IAC9B,WAAW,EAAE,UAAU,CAAA;IACvB,MAAM,EAAE,UAAU,CAAA;CACnB,GAAG,OAAO,CAAC;IAAE,YAAY,EAAE,UAAU,CAAC;IAAC,WAAW,EAAE,UAAU,CAAA;CAAE,CAAC,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"}
@@ -0,0 +1,225 @@
1
+ /**
2
+ * Cipher suite 0x03: PQ-hybrid XChaCha20-Poly1305 + ML-KEM-1024 v1.
3
+ *
4
+ * The default suite for new files. Combines a classical 32-byte secret with
5
+ * an ML-KEM-1024 encapsulated 32-byte shared secret. The combined key is
6
+ * derived via HKDF-SHA-256 with the file_id as salt.
7
+ *
8
+ * Security: an adversary must break BOTH ML-KEM-1024 AND the classical
9
+ * KDF/wrap to recover plaintext. ML-KEM-1024 is FIPS 203, security level
10
+ * 5 (≈AES-256 against quantum search).
11
+ *
12
+ * Implementation:
13
+ * - Classical share encrypted under envelope key with XSalsa20-Poly1305
14
+ * secretbox (libsodium).
15
+ * - PQ encapsulation via @noble/post-quantum's ML-KEM-1024.
16
+ * - Chunk AEAD identical to xchacha-v1 once the combined key is derived.
17
+ */
18
+ import { ml_kem1024 } from '@noble/post-quantum/ml-kem.js';
19
+ import { buildChunkAad } from '../../format/header.js';
20
+ import { HKDF_INFO, HEADER_SIZES, } from '../../internal/types.js';
21
+ import { concatBytes, uint64BE } from '../../internal/encoding.js';
22
+ import { hkdfSha256 } from '../../internal/hkdf.js';
23
+ import { randomBytes } from '../../internal/runtime.js';
24
+ import { getSodium } from '../../internal/sodium.js';
25
+ export const PQ_HYBRID_V1_KEY_BYTES = 32;
26
+ export const PQ_HYBRID_V1_NONCE_BYTES = 24;
27
+ export const PQ_HYBRID_V1_TAG_BYTES = 16;
28
+ /** ML-KEM-1024 ciphertext length per FIPS 203. */
29
+ export const ML_KEM_1024_CIPHERTEXT_BYTES = 1568;
30
+ /** ML-KEM-1024 public key length per FIPS 203. */
31
+ export const ML_KEM_1024_PUBLIC_KEY_BYTES = 1568;
32
+ /** ML-KEM-1024 secret key length per FIPS 203. */
33
+ export const ML_KEM_1024_SECRET_KEY_BYTES = 3168;
34
+ /**
35
+ * Suite payload layout:
36
+ * mlkem_ciphertext (1568 bytes)
37
+ * classical_wrapped (72 bytes — 48 bytes secretbox + 24 bytes reserved zero pad)
38
+ * classical_nonce (24 bytes)
39
+ * Total: 1664 bytes
40
+ */
41
+ export const PQ_HYBRID_V1_SUITE_PAYLOAD_LENGTH = ML_KEM_1024_CIPHERTEXT_BYTES + 72 + 24;
42
+ export function buildPqHybridV1SuitePayload(payload) {
43
+ if (payload.mlkemCiphertext.length !== ML_KEM_1024_CIPHERTEXT_BYTES) {
44
+ throw new RangeError('pq-hybrid-v1: mlkemCiphertext must be 1568 bytes');
45
+ }
46
+ if (payload.classicalWrapped.length !== 72) {
47
+ throw new RangeError('pq-hybrid-v1: classicalWrapped must be 72 bytes');
48
+ }
49
+ if (payload.classicalNonce.length !== 24) {
50
+ throw new RangeError('pq-hybrid-v1: classicalNonce must be 24 bytes');
51
+ }
52
+ return concatBytes([
53
+ payload.mlkemCiphertext,
54
+ payload.classicalWrapped,
55
+ payload.classicalNonce,
56
+ ]);
57
+ }
58
+ export function parsePqHybridV1SuitePayload(bytes) {
59
+ if (bytes.length !== PQ_HYBRID_V1_SUITE_PAYLOAD_LENGTH) {
60
+ throw new RangeError(`pq-hybrid-v1: suite payload must be ${PQ_HYBRID_V1_SUITE_PAYLOAD_LENGTH} bytes`);
61
+ }
62
+ return {
63
+ mlkemCiphertext: bytes.slice(0, ML_KEM_1024_CIPHERTEXT_BYTES),
64
+ classicalWrapped: bytes.slice(ML_KEM_1024_CIPHERTEXT_BYTES, ML_KEM_1024_CIPHERTEXT_BYTES + 72),
65
+ classicalNonce: bytes.slice(ML_KEM_1024_CIPHERTEXT_BYTES + 72, PQ_HYBRID_V1_SUITE_PAYLOAD_LENGTH),
66
+ };
67
+ }
68
+ /**
69
+ * Generate an ML-KEM-1024 keypair. In production the keypair is derived
70
+ * deterministically from the user's master secret via HKDF; this function
71
+ * is exposed for testing and advanced callers.
72
+ */
73
+ export function generateMlKemKeypair() {
74
+ const seed = randomBytes(64);
75
+ return ml_kem1024.keygen(seed);
76
+ }
77
+ /**
78
+ * Derive an ML-KEM-1024 keypair deterministically from a master secret.
79
+ * The seed input is 64 bytes; we derive it via HKDF so the same master
80
+ * secret always yields the same keypair across sessions and devices.
81
+ */
82
+ export async function deriveMlKemKeypair(masterSecret) {
83
+ const seed = await hkdfSha256({
84
+ ikm: masterSecret,
85
+ info: HKDF_INFO.ML_KEM_1024_SEED,
86
+ length: 64,
87
+ });
88
+ return ml_kem1024.keygen(seed);
89
+ }
90
+ /**
91
+ * Compute the combined content key from classical and PQ shares.
92
+ *
93
+ * K = HKDF-SHA-256(
94
+ * ikm = classical_share || pq_share,
95
+ * salt = file_id,
96
+ * info = "shieldfive/v1/pq-hybrid/combine",
97
+ * L = 32
98
+ * )
99
+ */
100
+ async function combineKeys(classicalShare, pqShare, fileId) {
101
+ if (classicalShare.length !== 32 || pqShare.length !== 32) {
102
+ throw new RangeError('combineKeys: both shares must be 32 bytes');
103
+ }
104
+ return hkdfSha256({
105
+ ikm: concatBytes([classicalShare, pqShare]),
106
+ salt: fileId,
107
+ info: HKDF_INFO.PQ_HYBRID_COMBINE,
108
+ length: 32,
109
+ });
110
+ }
111
+ async function deriveChunkContext(combinedKey, fileId, totalChunks) {
112
+ // Reuse the xchacha derivation domain — semantically the same chunk-key role.
113
+ const chunkKey = await hkdfSha256({
114
+ ikm: combinedKey,
115
+ salt: fileId,
116
+ info: HKDF_INFO.XCHACHA_CHUNK_KEY,
117
+ length: 32,
118
+ });
119
+ const noncePrefix = await hkdfSha256({
120
+ ikm: fileId,
121
+ info: HKDF_INFO.XCHACHA_NONCE_PREFIX,
122
+ length: 16,
123
+ });
124
+ return { combinedKey: chunkKey, noncePrefix, totalChunks };
125
+ }
126
+ function buildNonce(noncePrefix, chunkIndex) {
127
+ const nonce = new Uint8Array(PQ_HYBRID_V1_NONCE_BYTES);
128
+ nonce.set(noncePrefix, 0);
129
+ nonce.set(uint64BE(chunkIndex), 16);
130
+ return nonce;
131
+ }
132
+ export async function encryptChunk(ctx, chunkIndex, plaintext) {
133
+ const sodium = await getSodium();
134
+ const isFinal = chunkIndex === ctx.totalChunks - 1;
135
+ const aad = buildChunkAad(chunkIndex, ctx.totalChunks, isFinal);
136
+ const nonce = buildNonce(ctx.noncePrefix, chunkIndex);
137
+ return sodium.crypto_aead_xchacha20poly1305_ietf_encrypt(plaintext, aad, null, nonce, ctx.combinedKey);
138
+ }
139
+ export async function decryptChunk(ctx, chunkIndex, ciphertext) {
140
+ const sodium = await getSodium();
141
+ const isFinal = chunkIndex === ctx.totalChunks - 1;
142
+ const aad = buildChunkAad(chunkIndex, ctx.totalChunks, isFinal);
143
+ const nonce = buildNonce(ctx.noncePrefix, chunkIndex);
144
+ return sodium.crypto_aead_xchacha20poly1305_ietf_decrypt(null, ciphertext, aad, nonce, ctx.combinedKey);
145
+ }
146
+ /**
147
+ * Sender side: produce the suite payload and the combined key.
148
+ *
149
+ * Inputs:
150
+ * - recipient's ML-KEM public key
151
+ * - envelopeKey: classical key under which the classical share is wrapped
152
+ * - fileId: per-file ID used as HKDF salt
153
+ *
154
+ * Outputs:
155
+ * - the suite payload bytes
156
+ * - the combined content key (used for header MAC and chunk AEAD)
157
+ */
158
+ export async function encapsulateForRecipient(options) {
159
+ const sodium = await getSodium();
160
+ const { recipientPublicKey, envelopeKey, fileId } = options;
161
+ if (recipientPublicKey.length !== ML_KEM_1024_PUBLIC_KEY_BYTES) {
162
+ throw new RangeError('encapsulate: public key must be 1568 bytes');
163
+ }
164
+ if (envelopeKey.length !== 32) {
165
+ throw new RangeError('encapsulate: envelopeKey must be 32 bytes');
166
+ }
167
+ if (fileId.length !== HEADER_SIZES.FILE_ID) {
168
+ throw new RangeError('encapsulate: fileId must be 16 bytes');
169
+ }
170
+ // 1) ML-KEM encapsulation: produces (mlkem_ciphertext, S_pq).
171
+ const { cipherText: mlkemCiphertext, sharedSecret: pqShare } = ml_kem1024.encapsulate(recipientPublicKey);
172
+ // 2) Generate classical share and wrap it under the envelope key.
173
+ const classicalShare = randomBytes(32);
174
+ const classicalNonce = randomBytes(24);
175
+ const classicalWrappedShort = sodium.crypto_secretbox_easy(classicalShare, classicalNonce, envelopeKey);
176
+ if (classicalWrappedShort.length !== 48) {
177
+ throw new Error('encapsulate: unexpected secretbox length');
178
+ }
179
+ const classicalWrapped = new Uint8Array(72);
180
+ classicalWrapped.set(classicalWrappedShort, 0);
181
+ // 3) Combine.
182
+ const combinedKey = await combineKeys(classicalShare, pqShare, fileId);
183
+ // 4) Pack suite_payload.
184
+ const suitePayload = buildPqHybridV1SuitePayload({
185
+ mlkemCiphertext,
186
+ classicalWrapped,
187
+ classicalNonce,
188
+ });
189
+ return { suitePayload, combinedKey };
190
+ }
191
+ /**
192
+ * Recipient side: recover the combined content key from the suite payload.
193
+ */
194
+ export async function decapsulateFromHeader(options) {
195
+ const sodium = await getSodium();
196
+ const { suitePayload, recipientSecretKey, envelopeKey, fileId } = options;
197
+ if (recipientSecretKey.length !== ML_KEM_1024_SECRET_KEY_BYTES) {
198
+ throw new RangeError('decapsulate: secret key must be 3168 bytes');
199
+ }
200
+ if (envelopeKey.length !== 32) {
201
+ throw new RangeError('decapsulate: envelopeKey must be 32 bytes');
202
+ }
203
+ if (fileId.length !== HEADER_SIZES.FILE_ID) {
204
+ throw new RangeError('decapsulate: fileId must be 16 bytes');
205
+ }
206
+ const parsed = parsePqHybridV1SuitePayload(suitePayload);
207
+ // 1) PQ decapsulation.
208
+ const pqShare = ml_kem1024.decapsulate(parsed.mlkemCiphertext, recipientSecretKey);
209
+ // 2) Classical unwrap.
210
+ const wrapped48 = parsed.classicalWrapped.slice(0, 48);
211
+ const classicalShare = sodium.crypto_secretbox_open_easy(wrapped48, parsed.classicalNonce, envelopeKey);
212
+ if (!classicalShare) {
213
+ throw new Error('decapsulate: classical unwrap failed');
214
+ }
215
+ // 3) Combine.
216
+ const combinedKey = await combineKeys(classicalShare, pqShare, fileId);
217
+ return { combinedKey };
218
+ }
219
+ export async function createChunkContext(combinedKey, fileId, totalChunks) {
220
+ return deriveChunkContext(combinedKey, fileId, totalChunks);
221
+ }
222
+ export function getSuitePayloadFromHeader(header) {
223
+ return parsePqHybridV1SuitePayload(header.suitePayload);
224
+ }
225
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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,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OAAO,EAAE,CAAC;QAC3C,MAAM,IAAI,UAAU,CAAC,sCAAsC,CAAC,CAAA;IAC9D,CAAC;IAED,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"}
@@ -0,0 +1,29 @@
1
+ /**
2
+ * High-level encrypt/decrypt API for the XChaCha20-Poly1305 v1 suite.
3
+ * Mirrors the shape of the AES-GCM v1 API; behavior is identical at the
4
+ * format layer.
5
+ */
6
+ import { type EncryptedFile, type ProgressCallback } from '../../internal/types.js';
7
+ export interface XChaChaEncryptOptions {
8
+ blob: Blob;
9
+ contentKey?: Uint8Array;
10
+ fileId?: Uint8Array;
11
+ suitePayloadOverride?: Uint8Array;
12
+ chunkSize?: number;
13
+ onProgress?: ProgressCallback;
14
+ }
15
+ export declare function encryptBlob(options: XChaChaEncryptOptions): Promise<EncryptedFile & {
16
+ contentKey: Uint8Array;
17
+ }>;
18
+ export interface XChaChaDecryptOptions {
19
+ blob: Blob;
20
+ contentKey: Uint8Array;
21
+ onProgress?: ProgressCallback;
22
+ allowedSuites?: ReadonlyArray<number>;
23
+ }
24
+ export declare function decryptBlob(options: XChaChaDecryptOptions): Promise<Blob>;
25
+ export declare function encryptBytes(bytes: Uint8Array, options: Omit<XChaChaEncryptOptions, 'blob'>): Promise<EncryptedFile & {
26
+ contentKey: Uint8Array;
27
+ }>;
28
+ export declare function decryptToBytes(options: XChaChaDecryptOptions): Promise<Uint8Array>;
29
+ //# sourceMappingURL=api.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../../src/suites/xchacha-v1/api.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAiBH,OAAO,EAEL,KAAK,aAAa,EAGlB,KAAK,gBAAgB,EAEtB,MAAM,yBAAyB,CAAA;AAShC,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,IAAI,CAAA;IACV,UAAU,CAAC,EAAE,UAAU,CAAA;IACvB,MAAM,CAAC,EAAE,UAAU,CAAA;IACnB,oBAAoB,CAAC,EAAE,UAAU,CAAA;IACjC,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,UAAU,CAAC,EAAE,gBAAgB,CAAA;CAC9B;AAED,wBAAsB,WAAW,CAC/B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,aAAa,GAAG;IAAE,UAAU,EAAE,UAAU,CAAA;CAAE,CAAC,CA2ErD;AAED,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,IAAI,CAAA;IACV,UAAU,EAAE,UAAU,CAAA;IACtB,UAAU,CAAC,EAAE,gBAAgB,CAAA;IAC7B,aAAa,CAAC,EAAE,aAAa,CAAC,MAAM,CAAC,CAAA;CACtC;AAED,wBAAsB,WAAW,CAC/B,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,IAAI,CAAC,CAwGf;AAED,wBAAsB,YAAY,CAChC,KAAK,EAAE,UAAU,EACjB,OAAO,EAAE,IAAI,CAAC,qBAAqB,EAAE,MAAM,CAAC,GAC3C,OAAO,CAAC,aAAa,GAAG;IAAE,UAAU,EAAE,UAAU,CAAA;CAAE,CAAC,CAGrD;AAED,wBAAsB,cAAc,CAClC,OAAO,EAAE,qBAAqB,GAC7B,OAAO,CAAC,UAAU,CAAC,CAGrB"}