Add precise parameter detection for BC KEM and digest constructors#421
Open
Sanchay117 wants to merge 1 commit into
Open
Add precise parameter detection for BC KEM and digest constructors#421Sanchay117 wants to merge 1 commit into
Sanchay117 wants to merge 1 commit into
Conversation
Signed-off-by: sanchaysingh <sanchay072@gmail.com>
1e84413 to
d83c49e
Compare
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.
Fixes #149
Overview
This PR improves the detection precision of the BouncyCastle rules in the Sonar Cryptography Plugin. It replaces generic
withAnyParameters()matches with precise constructor parameter capture rules. This enables the plugin to capture and distinguish specific parameter/algorithm sets (e.g., distinguishing betweenkyber512vskyber1024, orAsconHashvsAsconHashA) rather than only detecting the generic top-level algorithm family.Key Changes
1. New KEM Parameter Detection Rules (8 New Classes)
Added 8 new cipher parameter classes under
com.ibm.plugin.rules.detection.bc.cipherparametersto map and capture specific algorithm configurations usingAlgorithmParameterFactory:BcBIKEParameters: CapturesBIKEParametersfromBIKEKeyParameters,BIKEPrivateKeyParameters, andBIKEPublicKeyParameters.BcCMCEParameters: CapturesCMCEParametersfrom Classic McEliece key parameters.BcFrodoParameters: CapturesFrodoParametersfrom FrodoKEM key parameters.BcHQCParameters: CapturesHQCParametersfrom HQC key parameters.BcKyberParameters: CapturesKyberParametersfrom legacy Kyber key parameters.BcNTRUParameters: CapturesNTRUParametersfrom NTRU key parameters.BcNTRULPRimeParameters: CapturesNTRULPRimeParametersfrom NTRULPRime key parameters.BcSNTRUPrimeParameters: CapturesSNTRUPrimeParametersfrom Streamlined NTRU Prime key parameters.These 8 new rules have been wired into the central registry in
BcCipherParameters.java.2. Precise KEM Extractor Signatures
BcEncapsulatedSecretExtractor.javato replace the wildcardwithAnyParameters()constructor match with explicit, type-safe constructor matches.*PrivateKeyParametersclasses (e.g.,BIKEPrivateKeyParameters,HQCPrivateKeyParameters) and chain intoBcCipherParameters.rules()for full parameter-set extraction.3. Precise Ascon Digest Signatures
BcDigests.javato moveAsconDigestandAsconXofout of the wildcardregularConstructors()loop.AsconDigest(AsconDigest.AsconParameters)andAsconXof(AsconXof.AsconParameters).AlgorithmParameterFactoryto correctly extract the exact configuration (e.g.,AsconHash,AsconHashA,AsconXof, orAsconXofA) passing through.4. Tests and Verification
BcBIKEKEMExtractorTest.javato assert the newly resolved child node under the KEM finding: aParameterSetIdentifiercontaining the detected parameter set (which maps fromBIKEParameters.bike128in the test file).mvn spotless:apply).