-
Notifications
You must be signed in to change notification settings - Fork 2
fix: create AES-256 keys of the correct length with all curves #282
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
Conversation
We previously output a key that was the same length as the shared secret. This isn't what we want since AES-256 always uses keys of the same length
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Summary of Changes
Hello @mkleene, 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 addresses a critical bug in the SDK's cryptographic key generation process. Previously, AES-256 keys derived from shared secrets via HKDF could have variable lengths depending on the elliptic curve used, which is incorrect for AES-256. The changes ensure that all derived AES-256 keys are consistently 32 bytes (256 bits) long, improving the security and correctness of cryptographic operations within the SDK.
Highlights
- Cryptographic Key Generation Fix: Ensured that AES-256 keys generated using HKDF (HMAC-based Key Derivation Function) are consistently 32 bytes (256 bits) long, regardless of the underlying elliptic curve used for the shared secret. This addresses a previous issue where the key length could vary based on the shared secret's length, which is incorrect for fixed-size AES keys.
- Method Renaming and Refactoring: Renamed the
calculateHKDF
method tocalculateSHA256HKDF
inECKeyPair.java
to explicitly indicate that SHA-256 is used as the hash function within the HKDF, improving clarity and maintainability. - Codebase Updates: All instances where the
calculateHKDF
method was called acrossKASClient.java
,NanoTDF.java
, andTDF.java
have been updated to use the newly renamedcalculateSHA256HKDF
method, ensuring consistency and correct key derivation throughout the SDK. - Test Enhancements: Added new assertions and a dedicated test case in
ECKeyPairTest.java
to specifically verify that the generated symmetric keys are always 32 bytes, even when using different elliptic curves like SECP384R1, ensuring the fix is robust and covers various scenarios.
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 in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
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 issue 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 or fill out our survey to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
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. ↩
There was a problem hiding this 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 fixes a critical bug where AES-256 keys were being created with an incorrect length, dependent on the elliptic curve's shared secret size. The fix correctly uses HKDF with SHA-256 to derive a 32-byte key, ensuring the proper key length for AES-256. The changes are well-implemented and include a new test case that specifically validates the fix for different curves.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
|
🤖 I have created a release *beep* *boop* --- <details><summary>0.10.0</summary> ## [0.10.0](v0.9.0...v0.10.0) (2025-09-02) ### ⚠ BREAKING CHANGES * **sdk:** add base key and support for key grants in ZTDF ([#271](#271)) ### Features * ability to set connect-rpc protocol ([#285](#285)) ([47041c5](47041c5)) * add system metadata assertion ([#270](#270)) ([d235f13](d235f13)) * expose AuthorizationService v2 ([#287](#287)) ([d1fd106](d1fd106)) * introduce the base key for nano flows ([#273](#273)) ([d337704](d337704)) * **sdk:** add base key and support for key grants in ZTDF ([#271](#271)) ([c3b79db](c3b79db)) ### Bug Fixes * **ci:** Update codeql.yaml to run on all pull requests ([#283](#283)) ([9e318bb](9e318bb)) * create AES-256 keys of the correct length with all curves ([#282](#282)) ([95c20b3](95c20b3)) * **sdk:** add methods to examine Manifest and Policy ([#278](#278)) ([03d5d41](03d5d41)) * **sdk:** parse the component sizes ([#286](#286)) ([3b1bb69](3b1bb69)) </details> --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: opentdf-automation[bot] <149537512+opentdf-automation[bot]@users.noreply.github.com>
We previously output a key that was the same length as the shared secret. This isn't what we want since AES-256 always uses keys of the same length