Skip to content

Conversation

@cconlon
Copy link
Member

@cconlon cconlon commented Nov 13, 2025

This PR adds validation to EC KeyPairGenerator.initialize(int keysize) to only accept standard NIST key sizes (192, 224, 256, 384, 521 bits), matching SunEC and Bouncy Castle behavior. Invalid sizes now throw InvalidParameterException instead of being silently accepted.

For non-NIST curves (secp256k1, Brainpool, etc), users must use ECGenParameterSpec explicitly.

This fixes compatibility with SunJCE security/KeyAgreement/NegativeTest.java test.

@cconlon cconlon self-assigned this Nov 13, 2025
@cconlon cconlon requested a review from Copilot November 13, 2025 23:08
Copilot finished reviewing on behalf of cconlon November 13, 2025 23:14
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances EC key pair generation by adding validation to restrict KeyPairGenerator.initialize(int keysize) to standard NIST curve sizes (192, 224, 256, 384, 521 bits), matching SunEC and Bouncy Castle behavior. Invalid sizes now throw InvalidParameterException instead of being silently accepted.

Key changes:

  • EC key sizes are validated and mapped to specific NIST curves (secp192r1, secp224r1, secp256r1, secp384r1, secp521r1)
  • Non-NIST curves must now be requested explicitly via ECGenParameterSpec
  • Test cases updated to work with bit sizes and validate the new exception behavior

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 6 comments.

File Description
src/main/java/com/wolfssl/provider/jce/WolfCryptKeyPairGenerator.java Adds EC key size validation with NIST curve mapping and availability checking in the initialize(int keysize) method
src/test/java/com/wolfssl/provider/jce/test/WolfCryptKeyPairGeneratorTest.java Updates existing test to use bit sizes correctly and adds comprehensive new tests for invalid sizes, valid NIST curve mapping, and non-standard curve requirements

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@cconlon cconlon force-pushed the keyPairGenChecks branch 3 times, most recently from 72a43a0 to f066bf5 Compare November 14, 2025 00:11
@cconlon cconlon assigned rlm2002 and unassigned cconlon Nov 14, 2025
@rlm2002 rlm2002 merged commit ee1edae into wolfSSL:master Nov 14, 2025
46 checks passed
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