gnodet opened a new pull request, #30777: URL: https://github.com/apache/camel/pull/30777
## Summary Implements the hybrid wire format v2 in `camel-pqc` that `pqc-hybrid.adoc` documents as the default since Camel 4.19 but that was never actually written or read by the code. Also fixes the `PQCAlgorithmId` JCA name mismatches that made `fromJcaName()` return `UNKNOWN` for all real algorithm names. ## Root Cause Three separate gaps between the documentation and the implementation: 1. **Wire format v2 not implemented**: `HybridSignature.sign()` and `HybridKEM.encapsulate()` produced the legacy v1 format (`[4 bytes: length][classical][pqc]`) while the docs described a self-describing v2 format with magic bytes, version, format type, and 16-bit algorithm IDs. `parse()` only handled v1. 2. **`HybridSignatureComponents` missing accessors**: The adoc showed a code snippet calling `components.classicalAlgorithmId()`, `components.pqcAlgorithmId()`, and `components.version()` — none of which existed. The snippet would not compile. 3. **`PQCAlgorithmId` JCA name mismatches**: `DILITHIUM` was mapped to the string `"DILITHIUM"` (not `"ML-DSA"`), `SPHINCSPLUS` to `"SPHINCSPLUS"` (not `"SLH-DSA"`), `KYBER` to `"KYBER"` (not `"ML-KEM"`), and `FRODO` to `"FRODO"` (not `"FrodoKEM"`). `fromJcaName()` returned `UNKNOWN` for all of these. `PICNIC` was included but Picnic is no longer in BouncyCastle. ## Fix **`HybridSignature`** - `sign()` now emits wire format v2: magic bytes `0x50 0x51`, version `0x02`, format type `0x01`, two 16-bit algorithm IDs resolved via `PQCAlgorithmId.fromJcaName(signer.getAlgorithm())`, then the existing length+payload structure. - `parse()` auto-detects v1 vs v2 by checking the first two bytes for the magic sequence. The v1 path is preserved unchanged for backward compatibility. - `combineSignatures(classical, pqc)` now produces v2 (with `UNKNOWN` IDs); the full `combineSignatures(classical, pqc, classicalAlgId, pqcAlgId)` overload is added for callers that have the IDs. - `HybridSignatureComponents` gains `classicalAlgorithmId()`, `pqcAlgorithmId()`, and `version()` record components. v1-parsed components carry `null` IDs and version `1`. **`HybridKEM`**: identical treatment with format type `0x02`. **`PQCAlgorithmId`** - Removed `DILITHIUM` (wrong JCA name; `ML_DSA` already covers `"ML-DSA"`), `SPHINCSPLUS` (wrong JCA name; `SLH_DSA` already covers `"SLH-DSA"`), `KYBER` (wrong JCA name; `ML_KEM` already covers `"ML-KEM"`), and `PICNIC` (no longer in BC). - Fixed `FRODO` JCA name from `"FRODO"` to `"FrodoKEM"` to match `PQCKeyEncapsulationAlgorithms.FRODO`. - Static initializer now uses `putIfAbsent` so the first canonical constant for each JCA name wins (guards against future aliases being added). ## Tests - `HybridSignatureTest.testSignProducesV2WireFormat`: verifies magic bytes in the output of `sign()` and that `parse()` returns `version==2` with algorithm IDs `SHA256_WITH_ECDSA` and `ML_DSA`. - `HybridSignatureTest.testParseV1BackwardCompatibility`: verifies that a hand-crafted v1 blob (no magic bytes) is parsed correctly and returns `version==1`, `null` algorithm IDs. - Equivalent tests in `HybridKEMTest`. - Updated `testParseHybridSignature` / `testParseHybridEncapsulation` to assert `version==2` since `combineSignatures`/`combineEncapsulations` now produce v2. All 18 targeted tests and the full module `verify` (including ITs) pass locally. Fixes CAMEL-25803 --- _Hermes Agent (Claude Sonnet 4.6) on behalf of Guillaume Nodet_ -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
