|
8 | 8 | TypedArrayOf, |
9 | 9 | TypedArrayPrototypeGetBuffer, |
10 | 10 | TypedArrayPrototypeGetByteLength, |
| 11 | + TypedArrayPrototypeGetByteOffset, |
11 | 12 | TypedArrayPrototypeGetLength, |
12 | 13 | TypedArrayPrototypeSet, |
13 | | - TypedArrayPrototypeSubarray, |
14 | 14 | Uint8Array, |
15 | 15 | } = primordials; |
16 | 16 |
|
@@ -111,6 +111,12 @@ const kEncapsulationUsages = ['encapsulateKey', 'encapsulateBits']; |
111 | 111 | const kDecapsulationUsages = ['decapsulateKey', 'decapsulateBits']; |
112 | 112 | const kUsages = createKeyUsages(kEncapsulationUsages, kDecapsulationUsages); |
113 | 113 |
|
| 114 | +function getByteView(data, start, end = TypedArrayPrototypeGetByteLength(data)) { |
| 115 | + return new Uint8Array(TypedArrayPrototypeGetBuffer(data), |
| 116 | + TypedArrayPrototypeGetByteOffset(data) + start, |
| 117 | + end - start); |
| 118 | +} |
| 119 | + |
114 | 120 | /** |
115 | 121 | * Adds lengths that are the concatenation of the PQ KEM component and the |
116 | 122 | * traditional group component. |
@@ -289,8 +295,8 @@ function validateLength(data, length) { |
289 | 295 | function splitAt(data, offset) { |
290 | 296 | return { |
291 | 297 | __proto__: null, |
292 | | - head: TypedArrayPrototypeSubarray(data, 0, offset), |
293 | | - tail: TypedArrayPrototypeSubarray(data, offset), |
| 298 | + head: getByteView(data, 0, offset), |
| 299 | + tail: getByteView(data, offset), |
294 | 300 | }; |
295 | 301 | } |
296 | 302 |
|
@@ -353,7 +359,7 @@ function randomScalar(seed, config) { |
353 | 359 | offset + groupScalarLength <= TypedArrayPrototypeGetLength(seed); |
354 | 360 | offset += groupScalarLength) { |
355 | 361 | const scalar = copyBytes( |
356 | | - TypedArrayPrototypeSubarray(seed, offset, offset + groupScalarLength)); |
| 362 | + getByteView(seed, offset, offset + groupScalarLength)); |
357 | 363 | const value = os2ip(scalar); |
358 | 364 | if (value !== 0n && value < groupOrder) |
359 | 365 | return scalar; |
@@ -761,7 +767,7 @@ function combineSharedSecret( |
761 | 767 | config) { |
762 | 768 | // C2PRICombiner(ss_PQ, ss_T, ct_T, ek_T, Label). |
763 | 769 | // https://www.ietf.org/archive/id/draft-irtf-cfrg-hybrid-kems-12.html#section-5.1.3 |
764 | | - const encapsulationKeyT = TypedArrayPrototypeSubarray( |
| 770 | + const encapsulationKeyT = getByteView( |
765 | 771 | encapsulationKey, |
766 | 772 | config.kemPqEncapsulationKeyLength); |
767 | 773 | const inputLength = |
|
0 commit comments