Skip to content

Conversation

mkleene
Copy link
Contributor

@mkleene mkleene commented Jul 25, 2025

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

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
@mkleene mkleene requested review from a team as code owners July 25, 2025 12:50
@mkleene mkleene changed the title fix(sdk): create AES-256 keys of the correct length with all curves fix: create AES-256 keys of the correct length with all curves Jul 25, 2025
Copy link
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.

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 to calculateSHA256HKDF in ECKeyPair.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 across KASClient.java, NanoTDF.java, and TDF.java have been updated to use the newly renamed calculateSHA256HKDF 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

  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
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 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.

mkleene and others added 2 commits July 25, 2025 14:53
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Copy link

@mkleene mkleene merged commit 95c20b3 into main Jul 28, 2025
12 checks passed
@mkleene mkleene deleted the fix-key-length branch July 28, 2025 19:44
ttschampel pushed a commit that referenced this pull request Sep 2, 2025
🤖 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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants