@shieldfive/crypto 1.0.0-alpha.9 → 1.0.0-beta.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.
- package/CHANGELOG.md +129 -0
- package/README.md +32 -15
- package/SECURITY.md +1 -1
- package/dist/identity/index.d.ts +16 -0
- package/dist/identity/index.d.ts.map +1 -1
- package/dist/identity/index.js +84 -22
- package/dist/identity/index.js.map +1 -1
- package/dist/identity/sign.d.ts +92 -0
- package/dist/identity/sign.d.ts.map +1 -0
- package/dist/identity/sign.js +182 -0
- package/dist/identity/sign.js.map +1 -0
- package/dist/index.d.ts +10 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -4
- package/dist/index.js.map +1 -1
- package/dist/internal/encoding.d.ts.map +1 -1
- package/dist/internal/encoding.js +0 -1
- package/dist/internal/encoding.js.map +1 -1
- package/dist/internal/types.d.ts +4 -1
- package/dist/internal/types.d.ts.map +1 -1
- package/dist/internal/types.js +8 -0
- package/dist/internal/types.js.map +1 -1
- package/dist/streams/aes-gcm-v1.d.ts +71 -3
- package/dist/streams/aes-gcm-v1.d.ts.map +1 -1
- package/dist/streams/aes-gcm-v1.js +183 -49
- package/dist/streams/aes-gcm-v1.js.map +1 -1
- package/dist/streams/pq-hybrid-v1.d.ts +34 -3
- package/dist/streams/pq-hybrid-v1.d.ts.map +1 -1
- package/dist/streams/pq-hybrid-v1.js +114 -49
- package/dist/streams/pq-hybrid-v1.js.map +1 -1
- package/dist/suites/aes-gcm-v1/api.d.ts.map +1 -1
- package/dist/suites/aes-gcm-v1/api.js +1 -1
- package/dist/suites/aes-gcm-v1/api.js.map +1 -1
- package/dist/suites/aes-gcm-v1/index.d.ts +3 -0
- package/dist/suites/aes-gcm-v1/index.d.ts.map +1 -1
- package/dist/suites/aes-gcm-v1/index.js +3 -0
- package/dist/suites/aes-gcm-v1/index.js.map +1 -1
- package/dist/suites/aes-gcm-v2/api.d.ts +44 -0
- package/dist/suites/aes-gcm-v2/api.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v2/api.js +162 -0
- package/dist/suites/aes-gcm-v2/api.js.map +1 -0
- package/dist/suites/aes-gcm-v2/index.d.ts +63 -0
- package/dist/suites/aes-gcm-v2/index.d.ts.map +1 -0
- package/dist/suites/aes-gcm-v2/index.js +193 -0
- package/dist/suites/aes-gcm-v2/index.js.map +1 -0
- package/dist/suites/pq-hybrid-v1/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 +12 -2
- package/spec/format-v1.md +200 -7
- package/spec/key-derivation.md +18 -2
- package/spec/threat-model.md +36 -21
- package/src/identity/index.ts +107 -28
- package/src/identity/sign.ts +221 -0
- package/src/index.ts +32 -5
- package/src/internal/encoding.ts +0 -1
- package/src/internal/types.ts +9 -0
- package/src/streams/aes-gcm-v1.ts +263 -59
- package/src/streams/pq-hybrid-v1.ts +169 -59
- package/src/suites/aes-gcm-v1/api.ts +0 -1
- package/src/suites/aes-gcm-v1/index.ts +3 -0
- package/src/suites/aes-gcm-v2/api.ts +268 -0
- package/src/suites/aes-gcm-v2/index.ts +289 -0
- package/src/suites/pq-hybrid-v1/index.ts +25 -4
|
@@ -0,0 +1,289 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Cipher suite 0x04: AES-256-GCM v2.
|
|
3
|
+
*
|
|
4
|
+
* Per-file content key. Per-chunk AEAD with file_id-bound AAD that
|
|
5
|
+
* authenticates chunk index, total chunks, and the is-final flag. The
|
|
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 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
|
+
*/
|
|
14
|
+
|
|
15
|
+
import { buildChunkAad } from '../../format/header.js'
|
|
16
|
+
import {
|
|
17
|
+
HKDF_INFO,
|
|
18
|
+
HEADER_SIZES,
|
|
19
|
+
type ParsedHeader,
|
|
20
|
+
} from '../../internal/types.js'
|
|
21
|
+
import { concatBytes, uint32BE } from '../../internal/encoding.js'
|
|
22
|
+
import { hkdfSha256 } from '../../internal/hkdf.js'
|
|
23
|
+
import { getSubtle, randomBytes } from '../../internal/runtime.js'
|
|
24
|
+
|
|
25
|
+
export const AES_GCM_V2_TAG_BYTES = 16
|
|
26
|
+
export const AES_GCM_V2_IV_BYTES = 12
|
|
27
|
+
export const AES_GCM_V2_KEY_BYTES = 32
|
|
28
|
+
export const AES_GCM_V2_NONCE_PREFIX_LENGTH = 8
|
|
29
|
+
export const AES_GCM_V2_MAX_CHUNK_INDEX = 0xffff_ffff
|
|
30
|
+
|
|
31
|
+
/** Suite payload layout: 60-byte wrapped key + 12-byte wrap IV = 72 bytes. */
|
|
32
|
+
export const AES_GCM_V2_SUITE_PAYLOAD_LENGTH = 72
|
|
33
|
+
|
|
34
|
+
export interface AesGcmV2SuitePayload {
|
|
35
|
+
wrappedKey: Uint8Array // 60 bytes (32-byte key + 16-byte tag + 12-byte AAD-padded reserved zeros)
|
|
36
|
+
wrapIv: Uint8Array // 12 bytes
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function buildAesGcmV2SuitePayload(
|
|
40
|
+
payload: AesGcmV2SuitePayload,
|
|
41
|
+
): Uint8Array {
|
|
42
|
+
if (payload.wrappedKey.length !== 60) {
|
|
43
|
+
throw new RangeError('aes-gcm-v2: wrappedKey must be 60 bytes')
|
|
44
|
+
}
|
|
45
|
+
if (payload.wrapIv.length !== AES_GCM_V2_IV_BYTES) {
|
|
46
|
+
throw new RangeError('aes-gcm-v2: wrapIv must be 12 bytes')
|
|
47
|
+
}
|
|
48
|
+
return concatBytes([payload.wrappedKey, payload.wrapIv])
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function parseAesGcmV2SuitePayload(
|
|
52
|
+
bytes: Uint8Array,
|
|
53
|
+
): AesGcmV2SuitePayload {
|
|
54
|
+
if (bytes.length !== AES_GCM_V2_SUITE_PAYLOAD_LENGTH) {
|
|
55
|
+
throw new RangeError('aes-gcm-v2: suite payload must be 72 bytes')
|
|
56
|
+
}
|
|
57
|
+
return {
|
|
58
|
+
wrappedKey: bytes.slice(0, 60),
|
|
59
|
+
wrapIv: bytes.slice(60, 72),
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Derive the per-file chunk key from the content key. The chunk-key HKDF
|
|
65
|
+
* info matches v1 because the chunk-key derivation is unchanged across
|
|
66
|
+
* versions; only the nonce-prefix derivation differs. Files of either
|
|
67
|
+
* suite encrypted with the same content_key + file_id derive identical
|
|
68
|
+
* chunk keys, but their `(prefix, counter)` spaces are disjoint because
|
|
69
|
+
* the prefix info string differs.
|
|
70
|
+
*/
|
|
71
|
+
async function deriveChunkKey(
|
|
72
|
+
contentKey: Uint8Array,
|
|
73
|
+
fileId: Uint8Array,
|
|
74
|
+
): Promise<Uint8Array> {
|
|
75
|
+
return hkdfSha256({
|
|
76
|
+
ikm: contentKey,
|
|
77
|
+
salt: fileId,
|
|
78
|
+
info: HKDF_INFO.AES_GCM_CHUNK_KEY,
|
|
79
|
+
length: AES_GCM_V2_KEY_BYTES,
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Derive the 8-byte nonce prefix from file_id. Stable per file. The wider
|
|
85
|
+
* prefix is the entire point of the v2 suite — see this file's top
|
|
86
|
+
* docstring.
|
|
87
|
+
*/
|
|
88
|
+
async function deriveNoncePrefix(fileId: Uint8Array): Promise<Uint8Array> {
|
|
89
|
+
return hkdfSha256({
|
|
90
|
+
ikm: fileId,
|
|
91
|
+
info: HKDF_INFO.AES_GCM_V2_NONCE_PREFIX,
|
|
92
|
+
length: AES_GCM_V2_NONCE_PREFIX_LENGTH,
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function buildIv(noncePrefix: Uint8Array, chunkIndex: number): Uint8Array {
|
|
97
|
+
if (
|
|
98
|
+
!Number.isSafeInteger(chunkIndex) ||
|
|
99
|
+
chunkIndex < 0 ||
|
|
100
|
+
chunkIndex > AES_GCM_V2_MAX_CHUNK_INDEX
|
|
101
|
+
) {
|
|
102
|
+
throw new RangeError(
|
|
103
|
+
'aes-gcm-v2: chunkIndex must be in [0, 2^32)',
|
|
104
|
+
)
|
|
105
|
+
}
|
|
106
|
+
if (noncePrefix.length !== AES_GCM_V2_NONCE_PREFIX_LENGTH) {
|
|
107
|
+
throw new RangeError('aes-gcm-v2: noncePrefix must be 8 bytes')
|
|
108
|
+
}
|
|
109
|
+
const iv = new Uint8Array(AES_GCM_V2_IV_BYTES)
|
|
110
|
+
iv.set(noncePrefix, 0)
|
|
111
|
+
iv.set(uint32BE(chunkIndex), AES_GCM_V2_NONCE_PREFIX_LENGTH)
|
|
112
|
+
return iv
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
async function importAesGcmKey(
|
|
116
|
+
keyBytes: Uint8Array,
|
|
117
|
+
usages: KeyUsage[],
|
|
118
|
+
): Promise<CryptoKey> {
|
|
119
|
+
if (keyBytes.length !== AES_GCM_V2_KEY_BYTES) {
|
|
120
|
+
throw new RangeError('aes-gcm-v2: key must be 32 bytes')
|
|
121
|
+
}
|
|
122
|
+
return getSubtle().importKey(
|
|
123
|
+
'raw',
|
|
124
|
+
keyBytes as Uint8Array<ArrayBuffer>,
|
|
125
|
+
{ name: 'AES-GCM' },
|
|
126
|
+
false,
|
|
127
|
+
usages,
|
|
128
|
+
)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Generate a fresh per-file content key and file_id. */
|
|
132
|
+
export function generateContentMaterial(): {
|
|
133
|
+
contentKey: Uint8Array
|
|
134
|
+
fileId: Uint8Array
|
|
135
|
+
} {
|
|
136
|
+
return {
|
|
137
|
+
contentKey: randomBytes(AES_GCM_V2_KEY_BYTES),
|
|
138
|
+
fileId: randomBytes(HEADER_SIZES.FILE_ID),
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
export interface AesGcmV2ChunkContext {
|
|
143
|
+
cryptoKey: CryptoKey
|
|
144
|
+
noncePrefix: Uint8Array
|
|
145
|
+
totalChunks: number
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
export async function createChunkContext(
|
|
149
|
+
contentKey: Uint8Array,
|
|
150
|
+
fileId: Uint8Array,
|
|
151
|
+
totalChunks: number,
|
|
152
|
+
): Promise<AesGcmV2ChunkContext> {
|
|
153
|
+
if (totalChunks > AES_GCM_V2_MAX_CHUNK_INDEX + 1) {
|
|
154
|
+
// Defense in depth — header-layer MAX_TOTAL_CHUNKS already caps this
|
|
155
|
+
// well below 2^32, but the suite enforces its own ceiling.
|
|
156
|
+
throw new RangeError(
|
|
157
|
+
'aes-gcm-v2: totalChunks exceeds 2^32 chunk-index space',
|
|
158
|
+
)
|
|
159
|
+
}
|
|
160
|
+
const chunkKeyBytes = await deriveChunkKey(contentKey, fileId)
|
|
161
|
+
const noncePrefix = await deriveNoncePrefix(fileId)
|
|
162
|
+
const cryptoKey = await importAesGcmKey(chunkKeyBytes, ['encrypt', 'decrypt'])
|
|
163
|
+
return { cryptoKey, noncePrefix, totalChunks }
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
export async function encryptChunk(
|
|
167
|
+
ctx: AesGcmV2ChunkContext,
|
|
168
|
+
chunkIndex: number,
|
|
169
|
+
plaintext: Uint8Array,
|
|
170
|
+
): Promise<Uint8Array> {
|
|
171
|
+
const isFinal = chunkIndex === ctx.totalChunks - 1
|
|
172
|
+
const aad = buildChunkAad(chunkIndex, ctx.totalChunks, isFinal)
|
|
173
|
+
const iv = buildIv(ctx.noncePrefix, chunkIndex)
|
|
174
|
+
const ct = await getSubtle().encrypt(
|
|
175
|
+
{
|
|
176
|
+
name: 'AES-GCM',
|
|
177
|
+
iv: iv as Uint8Array<ArrayBuffer>,
|
|
178
|
+
additionalData: aad as Uint8Array<ArrayBuffer>,
|
|
179
|
+
tagLength: 128,
|
|
180
|
+
},
|
|
181
|
+
ctx.cryptoKey,
|
|
182
|
+
plaintext as Uint8Array<ArrayBuffer>,
|
|
183
|
+
)
|
|
184
|
+
return new Uint8Array(ct)
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export async function decryptChunk(
|
|
188
|
+
ctx: AesGcmV2ChunkContext,
|
|
189
|
+
chunkIndex: number,
|
|
190
|
+
ciphertext: Uint8Array,
|
|
191
|
+
): Promise<Uint8Array> {
|
|
192
|
+
const isFinal = chunkIndex === ctx.totalChunks - 1
|
|
193
|
+
const aad = buildChunkAad(chunkIndex, ctx.totalChunks, isFinal)
|
|
194
|
+
const iv = buildIv(ctx.noncePrefix, chunkIndex)
|
|
195
|
+
const pt = await getSubtle().decrypt(
|
|
196
|
+
{
|
|
197
|
+
name: 'AES-GCM',
|
|
198
|
+
iv: iv as Uint8Array<ArrayBuffer>,
|
|
199
|
+
additionalData: aad as Uint8Array<ArrayBuffer>,
|
|
200
|
+
tagLength: 128,
|
|
201
|
+
},
|
|
202
|
+
ctx.cryptoKey,
|
|
203
|
+
ciphertext as Uint8Array<ArrayBuffer>,
|
|
204
|
+
)
|
|
205
|
+
return new Uint8Array(pt)
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Wrap (encrypt) a content key under an envelope key (folder/vault key).
|
|
210
|
+
* The wrap layer is identical to v1: it is a one-shot AES-GCM encryption
|
|
211
|
+
* of a 32-byte key under a fresh 12-byte IV, which has no counter-mode
|
|
212
|
+
* collision concern.
|
|
213
|
+
*/
|
|
214
|
+
export async function wrapContentKey(options: {
|
|
215
|
+
contentKey: Uint8Array
|
|
216
|
+
envelopeKey: Uint8Array
|
|
217
|
+
envelopeAad?: Uint8Array
|
|
218
|
+
}): Promise<{ wrapped: Uint8Array; wrapIv: Uint8Array }> {
|
|
219
|
+
const { contentKey, envelopeKey } = options
|
|
220
|
+
if (contentKey.length !== AES_GCM_V2_KEY_BYTES) {
|
|
221
|
+
throw new RangeError('wrapContentKey: contentKey must be 32 bytes')
|
|
222
|
+
}
|
|
223
|
+
if (envelopeKey.length !== AES_GCM_V2_KEY_BYTES) {
|
|
224
|
+
throw new RangeError('wrapContentKey: envelopeKey must be 32 bytes')
|
|
225
|
+
}
|
|
226
|
+
const wrapIv = randomBytes(AES_GCM_V2_IV_BYTES)
|
|
227
|
+
const wrapKey = await importAesGcmKey(envelopeKey, ['encrypt'])
|
|
228
|
+
const wrapped = await getSubtle().encrypt(
|
|
229
|
+
{
|
|
230
|
+
name: 'AES-GCM',
|
|
231
|
+
iv: wrapIv as Uint8Array<ArrayBuffer>,
|
|
232
|
+
additionalData:
|
|
233
|
+
(options.envelopeAad ?? new Uint8Array(0)) as Uint8Array<ArrayBuffer>,
|
|
234
|
+
tagLength: 128,
|
|
235
|
+
},
|
|
236
|
+
wrapKey,
|
|
237
|
+
contentKey as Uint8Array<ArrayBuffer>,
|
|
238
|
+
)
|
|
239
|
+
const wrappedBytes = new Uint8Array(wrapped)
|
|
240
|
+
if (wrappedBytes.length !== 48) {
|
|
241
|
+
throw new Error('wrapContentKey: unexpected wrapped length')
|
|
242
|
+
}
|
|
243
|
+
const padded = new Uint8Array(60)
|
|
244
|
+
padded.set(wrappedBytes, 0)
|
|
245
|
+
return { wrapped: padded, wrapIv }
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
export async function unwrapContentKey(options: {
|
|
249
|
+
envelopeKey: Uint8Array
|
|
250
|
+
wrappedField: Uint8Array
|
|
251
|
+
wrapIv: Uint8Array
|
|
252
|
+
envelopeAad?: Uint8Array
|
|
253
|
+
}): Promise<Uint8Array> {
|
|
254
|
+
const { envelopeKey, wrappedField, wrapIv } = options
|
|
255
|
+
if (envelopeKey.length !== AES_GCM_V2_KEY_BYTES) {
|
|
256
|
+
throw new RangeError('unwrapContentKey: envelopeKey must be 32 bytes')
|
|
257
|
+
}
|
|
258
|
+
if (wrappedField.length !== 60) {
|
|
259
|
+
throw new RangeError('unwrapContentKey: wrappedField must be 60 bytes')
|
|
260
|
+
}
|
|
261
|
+
if (wrapIv.length !== AES_GCM_V2_IV_BYTES) {
|
|
262
|
+
throw new RangeError('unwrapContentKey: wrapIv must be 12 bytes')
|
|
263
|
+
}
|
|
264
|
+
const wrapped = wrappedField.slice(0, 48)
|
|
265
|
+
const wrapKey = await importAesGcmKey(envelopeKey, ['decrypt'])
|
|
266
|
+
const pt = await getSubtle().decrypt(
|
|
267
|
+
{
|
|
268
|
+
name: 'AES-GCM',
|
|
269
|
+
iv: wrapIv as Uint8Array<ArrayBuffer>,
|
|
270
|
+
additionalData:
|
|
271
|
+
(options.envelopeAad ?? new Uint8Array(0)) as Uint8Array<ArrayBuffer>,
|
|
272
|
+
tagLength: 128,
|
|
273
|
+
},
|
|
274
|
+
wrapKey,
|
|
275
|
+
wrapped as Uint8Array<ArrayBuffer>,
|
|
276
|
+
)
|
|
277
|
+
const ptBytes = new Uint8Array(pt)
|
|
278
|
+
if (ptBytes.length !== AES_GCM_V2_KEY_BYTES) {
|
|
279
|
+
throw new Error('unwrapContentKey: bad plaintext length')
|
|
280
|
+
}
|
|
281
|
+
return ptBytes
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/** Header parser hook — exposes ParsedHeader convenience for suite consumers. */
|
|
285
|
+
export function getSuitePayloadFromHeader(
|
|
286
|
+
header: ParsedHeader,
|
|
287
|
+
): AesGcmV2SuitePayload {
|
|
288
|
+
return parseAesGcmV2SuitePayload(header.suitePayload)
|
|
289
|
+
}
|
|
@@ -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,
|