feat(crypto): add hybrid X-Wing KEM support for TDF key wrapping#3253
feat(crypto): add hybrid X-Wing KEM support for TDF key wrapping#3253
Conversation
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
Summary of ChangesHello, 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
🧠 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
| return string(ocrypto.Base64Encode(wrappedDER)), nil | |
| return string(wrappedDER), nil |
| block, _ := pem.Decode([]byte(publicKeyInPem)) | ||
| if block != nil && block.Type == PEMBlockXWingPublicKey { |
There was a problem hiding this comment.
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.
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.