apupier opened a new pull request, #30489: URL: https://github.com/apache/camel/pull/30489
Fixes [CAMEL-27293](https://issues.apache.org/jira/browse/CAMEL-27293): `PQCSABERGenerateEncapsulationAESNoAutowiredTest` is flaky since 7 November. ## Root cause Every SABER key of a parameter set points to one static Bouncy Castle `SABERParameters` constant, which owns a single `SABEREngine` whose SHA-3 state is mutated by each encapsulation and decapsulation. The KEM operations only synchronized on the `KeyGenerator` they use, and `PQCProducer` creates a fresh `KeyGenerator` per exchange. Concurrent SABER exchanges therefore ran on different locks and corrupted each other, with either `IllegalStateException: attempt to absorb while squeezing`, or an extracted secret that differs from the encapsulated one (the `assertTrue` failure seen in CI). It surfaced on 7 November because CAMEL-24290 (#29354) turned on parallel test classes for camel-pqc, so `PQCSABERGenerateEncapsulationAESTest` and `PQCSABERGenerateEncapsulationAESNoAutowiredTest` started to overlap. This is a production race, not a test problem: two routes encapsulating with SABER at the same time can hit it. ## Fix `PQCKemLocks.lockFor(generator, key)` returns one JVM-wide monitor for SABER keys and the `KeyGenerator` itself for every other algorithm. `PQCProducer`, `PQCDataFormat` and `HybridKEM` use it around their `init()` / `generateKey()` sequences. I checked the other algorithms by running concurrent encapsulation and extraction on separate `KeyGenerator` instances (8 threads x 30 round trips each): only SABER fails (147 of 240); MLKEM, BIKE, HQC, CMCE, FRODO, NTRU, NTRULPRime, SNTRUPrime and KYBER have no failures. The non-stateful signature algorithms were checked the same way and are fine. HQC and SmaugT also hold an engine in their static parameter constants, but in HQC it only contains final sizes and a helper without mutable state. ## Tests New deterministic tests, parameterized over every `PQCKeyEncapsulationAlgorithms` value, for the producer, the data format and the hybrid KEM. They use the existing `InterleavingProbe` / `ProbedKeyGenerator`: one exchange is held between `init()` and `generateKey()` of its own generator while a second exchange starts on another generator, so the result does not depend on thread scheduling. Without the production change exactly the SABER case fails in all three; with it everything passes. The full camel-pqc suite passes (397 tests). `PQCKemLocks.sharesEngineAcrossKeyGenerators(algorithm)` is the single definition of "this algorithm needs the shared lock", used by the lock and by the tests. If a future Bouncy Castle release shares an engine for another algorithm, extending it makes the matching test case enforce the lock. --- _AI-generated: Bob (IBM Bob 2.2.1) on behalf of @apupier._ -- 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]
