-
Notifications
You must be signed in to change notification settings - Fork 6
feat(sdk): add ML-KEM key access objects (DSPX-3229) #933
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
19f18bd
feat(sdk): add ML-KEM (FIPS 203) key access and rewrap support (DSPX-…
dmihalcik-virtru 908d9b1
fix(sdk): enforce requested wrapping key algorithm (DSPX-3229)
dmihalcik-virtru eae2355
fix(sdk): preserve same-KAS key alternatives (DSPX-3229)
dmihalcik-virtru c8c754a
fix(web-app): report exact wrapped key sizes (DSPX-3229)
dmihalcik-virtru fae87de
revert: enforce requested wrapping key algorithm
dmihalcik-virtru a3f8e18
fix(sdk): address PR #933 review feedback (DSPX-3229)
dmihalcik-virtru a85d8ff
fix(sdk): make ML-KEM CryptoService methods optional (DSPX-3229)
dmihalcik-virtru 5bce5d6
Apply suggestion from @dmihalcik-virtru
dmihalcik-virtru 70fa389
refactor(sdk): parse SPKI algorithm OID via structural DER walk
dmihalcik-virtru 54d59c6
Apply suggestion from @dmihalcik-virtru
dmihalcik-virtru aa06e54
fix(sdk): harden ASN.1/SPKI DER parsing against malformed input (DSPX…
dmihalcik-virtru ee2bd83
Apply suggestion from @dmihalcik-virtru
dmihalcik-virtru File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| AGENTS.md |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| // Generic ASN.1 / DER primitives shared by the SPKI and ML-KEM codecs. | ||
| // Definite-length BER/DER only; that is all X.509 SubjectPublicKeyInfo needs. | ||
|
|
||
| export function encodeLength(len: number): Uint8Array { | ||
| if (!Number.isSafeInteger(len) || len < 0) { | ||
| throw new Error(`Invalid ASN.1 length: ${len}`); | ||
| } | ||
| if (len < 0x80) return new Uint8Array([len]); | ||
| if (len < 0x100) return new Uint8Array([0x81, len]); | ||
| if (len < 0x10000) return new Uint8Array([0x82, (len >> 8) & 0xff, len & 0xff]); | ||
| throw new Error(`ASN.1 length too large: ${len}`); | ||
| } | ||
|
|
||
| export function decodeLength( | ||
| bytes: Uint8Array, | ||
| offset: number | ||
| ): { length: number; bytesConsumed: number } { | ||
| const first = bytes[offset]; | ||
| if (first < 0x80) return { length: first, bytesConsumed: 1 }; | ||
| const numOctets = first & 0x7f; | ||
| if (numOctets === 0 || numOctets > 3) { | ||
| throw new Error(`Unsupported ASN.1 length octets: ${numOctets}`); | ||
| } | ||
| // Reject truncated encodings and non-minimal long form (leading zero octet). | ||
| if (offset + 1 + numOctets > bytes.length || bytes[offset + 1] === 0) { | ||
| throw new Error('Invalid ASN.1 length encoding'); | ||
| } | ||
| let length = 0; | ||
| for (let i = 0; i < numOctets; i++) { | ||
| length = (length << 8) | bytes[offset + 1 + i]; | ||
| } | ||
| // Long form must not encode a value that fits in short form. | ||
| if (length < 0x80) { | ||
| throw new Error('Non-canonical DER length encoding'); | ||
| } | ||
| return { length, bytesConsumed: 1 + numOctets }; | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| } | ||
|
|
||
| export type Tlv = { | ||
| /** Identifier octet (tag). */ | ||
| tag: number; | ||
| /** Index of the first content byte. */ | ||
| contentStart: number; | ||
| /** Index one past the last content byte. */ | ||
| contentEnd: number; | ||
| /** Start of the following TLV; equals contentEnd for definite-length values. */ | ||
| next: number; | ||
| }; | ||
|
|
||
| /** | ||
| * Read a single definite-length TLV (tag-length-value) starting at `offset`. | ||
| * Throws if the declared length runs past the end of `bytes`. | ||
| */ | ||
| export function readTlv(bytes: Uint8Array, offset: number): Tlv { | ||
| if (offset >= bytes.length) { | ||
| throw new Error(`ASN.1 read past end of buffer at offset ${offset}`); | ||
| } | ||
| const tag = bytes[offset]; | ||
| const { length, bytesConsumed } = decodeLength(bytes, offset + 1); | ||
| const contentStart = offset + 1 + bytesConsumed; | ||
| const contentEnd = contentStart + length; | ||
| if (contentEnd > bytes.length) { | ||
| throw new Error('ASN.1 TLV length exceeds buffer size'); | ||
| } | ||
| return { tag, contentStart, contentEnd, next: contentEnd }; | ||
| } | ||
|
|
||
| export function bytesEqual(a: Uint8Array, b: Uint8Array): boolean { | ||
| if (a.length !== b.length) return false; | ||
| for (let i = 0; i < a.length; i++) { | ||
| if (a[i] !== b[i]) return false; | ||
| } | ||
| return true; | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.