improve ML-KEM algorithm handling and test coverage#1443
Open
jasonkatonica wants to merge 1 commit intoIBM:mainfrom
Open
improve ML-KEM algorithm handling and test coverage#1443jasonkatonica wants to merge 1 commit intoIBM:mainfrom
jasonkatonica wants to merge 1 commit intoIBM:mainfrom
Conversation
6c2e3ee to
b2bda69
Compare
edc51bc to
2053b69
Compare
- Fix ML-KEM encapsulation length calculation to use actual key algorithm instead of generic 'ML-KEM' string - Add validation for encapsulation message length in decapsulation - Improve key conversion to use actual algorithm from key instead of generic algorithm parameter - Add comprehensive test for invalid encapsulation length handling - Refactor test skip conditions to use assumeFalse for better JUnit 5 compatibility - Add new interoperability tests using NamedParameterSpec: * testMLKEMInteropWithNamedParameterSpec * testMLKEMInteropEmptyParamsWithNamedParameterSpec * testMLKEMInteropSmallerSecretWithNamedParameterSpec * testMLKEMBidirectionalInteropWithNamedParameterSpec - Remove test unused imports and improve code consistency This ensures ML-KEM operations correctly handle different parameter sets (ML-KEM-512, ML-KEM-768, ML-KEM-1024) and provides better error messages when encapsulation length mismatches occur. Signed-off-by: Jason Katonica <katonica@us.ibm.com>
2053b69 to
3942042
Compare
| } | ||
|
|
||
| private int getEncapsulationLength() { | ||
| private int getEncapsulationLength(String algorithm) { |
Member
There was a problem hiding this comment.
Since, this is no longer using the Algorithm for this Implementation instance. Couldn't this cause issues with callers mix matching things easier?
| // Use the key's actual algorithm, not the generic "ML-KEM" | ||
| try { | ||
| KeyFactory kf = KeyFactory.getInstance(this.alg, this.provider.getName()); | ||
| KeyFactory kf = KeyFactory.getInstance(keyAlgorithm, this.provider.getName()); |
Member
There was a problem hiding this comment.
This can cause a algorithm miss match if they create this instance as ML-KEM-786, but pass in a ML-KEM-512 key that should not be allowed.
| public KEM.Encapsulated engineEncapsulate(int from, int to, String algorithm) { | ||
| int encapLen = getEncapsulationLength(); | ||
| // Get the actual algorithm from the public key | ||
| String keyAlgorithm = publicKey.getAlgorithm(); |
|
|
||
| return getEncapsulationLength(); | ||
| String keyAlgorithm = privateKey.getAlgorithm(); | ||
| return getEncapsulationLength(keyAlgorithm); |
Member
There was a problem hiding this comment.
Same type of issue here too. The algorithm the should be based on the one requested when this was created.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This ensures ML-KEM operations correctly handle different parameter sets (ML-KEM-512, ML-KEM-768, ML-KEM-1024) and provides better error messages when encapsulation length mismatches occur.
Signed-off-by: Jason Katonica katonica@us.ibm.com