Skip to content

feat(crypto): add hybrid X-Wing KEM support for TDF key wrapping#3253

Draft
sujankota wants to merge 1 commit intomainfrom
feat/hybrid-xwing-kem-support-codex
Draft

feat(crypto): add hybrid X-Wing KEM support for TDF key wrapping#3253
sujankota wants to merge 1 commit intomainfrom
feat/hybrid-xwing-kem-support-codex

Conversation

@sujankota
Copy link
Copy Markdown
Contributor

  • This PR adds hybrid X-Wing KEM support for TDF key wrapping, introducing a new hybrid-wrapped scheme backed by hpqt:xwing. It extends lib/ocrypto, KAS/service key handling, policy/KAS registry algorithm enums, and the SDK so hybrid public keys can be stored, served, used to wrap DEKs, and later rewrapped without adding new KAO fields.

  • The implementation uses a custom X-Wing PEM format for composite public/private keys and an ASN.1 envelope in wrapped_key for the hybrid ciphertext plus AES-GCM-encrypted DEK. It also adds the required feature flagging, enum/mapping updates, generated protobuf/doc refreshes, manifest schema updates, and coverage for the new X-Wing wrapping and unwrap flows.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Apr 2, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: fcf6c895-1d47-4dfa-b30e-936dc7ea4d60

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/hybrid-xwing-kem-support-codex

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions github-actions bot added comp:policy Policy Configuration ( attributes, subject mappings, resource mappings, kas registry) comp:sdk A software development kit, including library, for client applications and inter-service communicati comp:kas Key Access Server comp:examples comp:lib:fixtures comp:lib:flattening comp:lib:ocrypto labels Apr 2, 2026
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces hybrid X-Wing KEM support into the TDF key wrapping workflow. By integrating this post-quantum capable hybrid scheme, the platform enhances its cryptographic agility, allowing for secure DEK wrapping and rewrapping flows. The changes span the core cryptographic libraries, service-level key handling, and protocol definitions to ensure seamless adoption of the new algorithm.

Highlights

  • Hybrid X-Wing KEM Support: Added support for the hybrid X-Wing Key Encapsulation Mechanism (KEM) for TDF key wrapping, utilizing the hpqt:xwing scheme.
  • Cryptographic Infrastructure Updates: Extended lib/ocrypto and KAS service handling to support storage, serving, and wrapping of DEKs using the new hybrid scheme without requiring additional KAO fields.
  • Protocol and Schema Enhancements: Updated protobuf definitions, manifest schemas, and enum mappings to include the new X-Wing algorithm, alongside necessary feature flagging.
  • Implementation Details: Implemented custom X-Wing PEM formats for keys and an ASN.1 envelope structure for hybrid ciphertexts and AES-GCM encrypted DEKs.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Ignored Files
  • Ignored by pattern: protocol/**/* (3)
    • protocol/go/go.mod
    • protocol/go/go.sum
    • protocol/go/policy/objects.pb.go
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.


Hybrid keys in code we weave, / X-Wing strength we now achieve. / Quantum threats may come to play, / But our TDF keeps keys at bay.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for X-Wing hybrid post-quantum cryptography across the platform, including the ocrypto library, SDK, and KAS service. It adds key generation, PEM handling, and DEK wrapping/unwrapping for the new hpqt:xwing algorithm. Feedback highlights a potential double-encoding issue when base64 encoding the wrapped key in the SDK and suggests iterating through all PEM blocks when decoding public keys to correctly handle multi-block inputs.

if err != nil {
return "", fmt.Errorf("generateWrapKeyWithXWing: XWingWrapDEK failed: %w", err)
}
return string(ocrypto.Base64Encode(wrappedDER)), nil
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The WrappedKey field in the TDF specification and the corresponding protobuf definitions are typically defined as bytes. By base64 encoding the DER-encoded ASN.1 envelope here and returning it as a string, you might be causing double-encoding if the protobuf marshaler also base64 encodes the field for JSON transport. Ensure that the receiving end (KAS) is prepared to handle this or consider returning the raw bytes if the proto field is of type bytes.

Suggested change
return string(ocrypto.Base64Encode(wrappedDER)), nil
return string(wrappedDER), nil

Comment on lines +74 to +75
block, _ := pem.Decode([]byte(publicKeyInPem))
if block != nil && block.Type == PEMBlockXWingPublicKey {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The current implementation only checks the first PEM block for the X-Wing public key type. If a PEM file contains multiple blocks (e.g., a certificate chain or multiple keys), and the X-Wing key is not the first block, it will be ignored. Consider iterating through all PEM blocks in the input string.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp:examples comp:kas Key Access Server comp:lib:fixtures comp:lib:flattening comp:lib:ocrypto comp:policy Policy Configuration ( attributes, subject mappings, resource mappings, kas registry) comp:sdk A software development kit, including library, for client applications and inter-service communicati size/xl

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant