Bouncy Castle CTR keystream-reuse boundary check¶
Source: hourly offensive-security scan, 2026-07-01. Primary entry: GitHub Advisory Database GHSA-574f-3g2m-x479 / CVE-2025-14813.
This advisory is durable for operators because it turns a library bug into a repeatable crypto-integration test: a CTR-mode counter that wraps after 255 blocks can reuse keystream and expose relationships between plaintexts when the same key/IV pair is used.
What changed¶
| Advisory | Component | Boundary | Operator value |
|---|---|---|---|
| GHSA-574f-3g2m-x479 / CVE-2025-14813 | Bouncy Castle Java GOST 28147 CTR mode | G3413CTRBlockCipher only incremented the final counter byte, causing keystream reuse after 255 blocks | Crypto integration reviews should include block-boundary known-plaintext harnesses for stream/CTR modes, especially in custom or regional algorithm modes. |
Adjacent Netty HTTP/3 QPACK and Micronaut Accept-Language cache advisories were processed without promotion because they were resource-exhaustion focused. The FlashAttention checkpoint advisory is already covered in the May 18 ML/parser batch, Jackson Databind authorization edge cases are covered in the June 23 Jackson batch, the updated TinyMCE media-plugin advisory is covered in the June 5 Twig/Shopper/TinyMCE batch, and duplicate Open Babel/Fory/Spring Security updates are covered by the June 30 model parser/deserialization/identity page.
Replayable validation boundary¶
Bouncy Castle CTR keystream-reuse harness¶
- Preconditions: local Java harness using affected Bouncy Castle
bcprov, synthetic plaintexts longer than 255 GOST blocks, a disposable key/IV, and no production ciphertexts. - Encrypt two known plaintext buffers with the same key/IV through
G3413CTRBlockCipherand compare ciphertext blocks around the counter wrap boundary. - Positive evidence is repeated keystream behavior:
ciphertextA XOR ciphertextBequalsplaintextA XOR plaintextBfor blocks after wrap, or identical plaintext blocks produce identical ciphertext blocks where they should not. - Keep proof fully offline. Do not recover real plaintexts, test against live customer traffic, or publish keys, protocol secrets, or exploit tooling for deployed systems.
- Negative controls: Bouncy Castle 1.84 or fixed backports 1.80.2 / 1.81.1, protocol-level nonce uniqueness checks, and regression tests that cover counter carry across multiple bytes.
Reporting notes¶
- Lead with the precise boundary crossed: CTR counter wrap to keystream reuse.
- Include affected and fixed versions, exact cipher/mode, synthetic plaintext size, block index where reuse appears, observed XOR relationship, and a fixed-version negative control.
- Keep evidence scoped and inert: disposable keys, synthetic plaintexts, local unit tests, and offline crypto harnesses only.
October 9 follow-up: Bouncy Castle Java LTS native one-shot CTR packet cipher repeats keystream within one packet (GHSA-qgfp-x9w9-pwj2 / CVE-2026-71884, high, fixed LTS 2.73.13)¶
The same counter-space boundary this page was built around, now in a different implementation path: BC's native one-shot CTR packet cipher never validated that the input length fit the counter space the IV left. A 13-15 byte IV leaves a 1-3 byte counter (256 / 65,536 / 16,777,216 blocks); given longer input the counter wrapped mid-packet, the keystream repeated from the start of the same packet, and the call returned full input length as if every byte transformed correctly, no exception, no short length. Two segments of one message encrypted under the same keystream → their plaintexts recoverable from ciphertext alone, key-free. The streaming implementation validates at init and during processing, and the portable AESCTRPacketCipher rejects with "Counter in CTR/SIC mode out of range", only the native one-shot entry point skipped the preflight. Fix adds the counter-range preflight before any output.
Operator extensions of this page's harness:
- Implementation-path parity is the finding: one library ships three CTR packet paths (streaming, portable one-shot, native one-shot) and only one was broken. The July 1 harness (two known plaintexts, same key/IV, XOR-compare around the wrap index) should be run against every entry point the library exposes, not one representative. Fingerprint: short-IV + long-message behavior differs per API, if one call path errors with a counter-range message and another returns success for the same (13-byte IV, oversized plaintext) pair, the silent-success path is the vulnerability.
- Silent-crypto-failure detection battery: any crypto API that "returns full length" on a wrap/overflow condition is worse than one that throws, integrators have no signal. For packet-mode ciphers, test the boundary triplet IV length × message length × {streaming, one-shot, native/provider-backed} and record which cells reject, which error late, and which return plausible bytes.
- Target-facing relevance: the LTS band (2.7.x) ships in long-lived enterprise/telecom stacks where native fast paths are explicitly enabled for throughput, precisely the deployments handling the most long-lived secrets. Lab-only, synthetic plaintexts, disposable keys, same as the original rules.
November 20 follow-up: crypto11 (PKCS#11 Go wrapper) hands any nonce to the token, empty nonce = keystream reuse plus GHASH key recovery (CVE-2026-115407 / GHSA-9q64-h4f4-jp28, critical, eclipse-keypont/crypto11/v2 <= 2.0.0-rc8; v1 lines: eclipse-keypont/crypto11 <= 1.6.8, ThalesGroup/crypto11 <= 1.7.0-rc1, ThalesIgnite/crypto11 <= 1.2.5)¶
The same keystream-reuse boundary, this time one layer up: a wrapper that validates nothing between the caller and the HSM. SecretKey.NewGCM()'s cipher.AEAD passes whatever nonce it receives straight into CK_GCM_PARAMS with no length check against NonceSize(), and an empty nonce is accepted. On a token that tolerates a zero-length GCM IV (SoftHSM2 does), every Seal with an empty nonce encrypts under the same IV: keystream reuse across all messages and GHASH authentication-key exposure, which yields forgeries. Two adjacent config-path failures ride along:
Config.UseGCMIVFromHSMsends a NULL IV with length zero unlessGCMIVFromHSMControl.SupplyIvForHSMGCMEncryptis also set, so the token has nowhere to write its generated IV: a non-empty-nonceSealpanics after the plaintext was already encrypted, and an empty-nonceSealreturns ciphertext under an empty IV without error. The v1 line additionally never copies the token-generated IV back to the caller, so callers keep tracking their own nonce while data was encrypted under another one.- Operator rules for any HSM/KMS/crypto-wrapper engagement:
- Nonce-contract parity test: for every AEAD factory in a wrapper, assert
aead.NonceSize()is actually enforced. CallSealwith nonce lengths {NonceSize, NonceSize+1, 1, 0} and record which cells the wrapper rejects vs. forwards to the token. A wrapper that forwards is trusting the token's strictness, which is per-token behavior, not a library guarantee. SoftHSM2 as the lab token is a legitimate test oracle: real deployments run real tokens whose tolerance profiles differ, so "SoftHSM2 accepts empty IV" is a differential signal about token-side validation, not just a SoftHSM bug. - Nonce-carrying fidelity: in HSM-generated-IV modes, verify the IV returned to the caller equals the IV used on-wire (seal, decrypt round-trip plus an external decrypt with the token-reported IV). The v1 "caller keeps its own nonce while data used another" leg is the same class as the Sept 18 Net::DNS finding: the bookkeeping value and the wire value are different objects.
- Panic-after-encrypt is an information-disclosure tell: an API that crashes after the crypto side effect has happened means the plaintext crossed the boundary the caller believed was gated. Same silent-crypto-failure battery as the October 9 leg, extended with a panic column: reject / late-error / silent-success / panic-post-side-effect.
- Fingerprint for hunting: grep PKCS#11 wrappers for direct
CK_GCM_PARAMSpopulation without a preceding length comparison against the AEAD interface'sNonceSize(); the bug shape is "interface method exists but is never consulted on the seal path." - Proof boundaries: disposable SoftHSM2 token, synthetic plaintexts, own keys only; keystream-reuse evidence is two empty-nonce seals of known plaintexts XOR-compared, per this page's original harness. Never extract production keys or test against shared tokens.
November 23 follow-up: secp256k1-native (Ruby) constant-time scalar mult leaks key bits because GCC 15.2 -O2 reconstructed a branch from branchless source (CVE-2026-63410 / GHSA-vp2j-gqfm-r3cf, medium, < 0.18.0)¶
The same page's thesis, one layer below the source: a constant-time property is a property of the (source, compiler, flags) triple, not of the source. Point#mul is the library's headline secret-scalar operation, written deliberately branchless: uint256_select computes r = (a & ~mask) | (b & mask) with an all-ones/all-zeros mask. GCC 15.2 at -O2 pattern-matches the select idiom, reconstructs the original boolean condition, and emits a secret-dependent je/jne in the Montgomery ladder. Taken/not-taken timing then correlates with private-key bits, the classic Brumley-Boneh setting for anyone exposing the signing path to an online timing measurement. The sting: this silently undid the library's own 0.17.0 constant-time fix, which relied on that exact select compiling branchlessly, and neither source review nor the deterministic ctgrind check catches it when the validation toolchain is a non-reconstructing compiler. The 0.18.0 patch routes every select mask through a value barrier (__asm__ volatile("" : "+r"(x)), the libsecp256k1/BoringSSL idiom) at all nine mask-select sites.
Operator rules extending this page's crypto-integration harness:
- Ground truth is measurement on the shipped binary, not source inspection. When a target performs secret-key operations with attacker-influodable timing (online signing oracle, wallet service, HSM emulator exposing per-request latency), the only reliable constant-time audit is statistical timing on the exact deployed build. A clean ctgrind/valgrind run on a different toolchain proves nothing about the production binary.
- Grep for missing value barriers as a defect fingerprint. Branchless select idioms (
(a & ~mask) | (b & mask), mask-from-flag) without an intervening__asm__ volatile("" : "+r"(x))barrier are the at-risk shape. In native crypto extensions bundled with interpreted languages (Rubyextconf.rb, Python C extensions, Node native addons), also check the shipped optimization level: this extension hardcodes-O2inextconf.rb, so the published gem binary is the affected configuration by default. - Fix-note fingerprint for sibling hunting: any advisory whose text says the compiler "reconstructed a branch", "optimized away constant-time", or credits a value barrier/optimization barrier as the fix is telling you the whole library's branchless idioms deserve the battery, not just the reported site. The secp256k1 maintainers hardened nine select sites as defense-in-depth while only one actively branchified: assume the others are one compiler release away from joining it, and re-test after toolchain upgrades.
- Regression direction matters: constant-time code can regress with zero source changes, purely from a compiler upgrade. A service that passed a timing audit last year on GCC 13 can be leaky on GCC 15 with the identical source, so timing regression checks belong in the toolchain-upgrade path, not just the code-review path.
- Validation boundaries: lab-only, own keys only; statistical scalar-bit recovery attempts run against your own signing harness with synthetic nonces (Brumley-Boneh-style measurement on a disposable oracle), never against production signers, HSMs serving live keys, or third-party services.