GCD: Garbled, Corrected, Demonstrandum -- Fixing and Proving Go's Extended GCD Implementation
summary
The gist
We verify and fix deviations in Go's standard library extended GCD implementation, which is critical for RSA key generation, by identifying subtle bugs that break algorithmic invariants and proposing
In short
Researchers verified and fixed subtle bugs in Go's standard library extended GCD implementation to ensure correctness for RSA key generation. They found deviations from a reference implementation regarding coefficient updates and input domain handling, which broke mathematical invariants. Using formal verification tools like Gobra, they proposed fixes that improved performance by about 24% on average.
Key concepts
- Unsynchronized Subtractions Deviation
- The Go code updated coefficients in an unsynchronized way when the sum exceeded the modulus. The reference implementation uses a synchronized reduction to keep coefficients within bounds. This change broke the core mathematical invariants of the extended GCD algorithm.
- Input Domain Deviation
- The Go function allowed inputs where 'a' was greater than or equal to 'n', violating a requirement for the proof. This deviation broke critical invariants used in the formal verification process. The fix extends the proof to handle these larger inputs correctly.
- Gobra Verifier
- Gobra is a deductive program verifier for Go that translates annotated code into Viper, which uses an SMT solver (Z3). It checks program correctness by verifying specifications like preconditions and postconditions. This tool was central to proving the mathematical correctness of the extended GCD function.
- Loop Invariants
- These are conditions that must remain true before and after every iteration of a loop. The paper adapted these invariants to account for input domain changes. They used these invariants, along with showing that an expression involving the GCD strictly decreases, to prove termination.
Terminology used across episodes
This episode discusses
- GCD: Garbled, Corrected, Demonstrandum -- Fixing and Proving Go's Extended GCD Implementation · Paper Radio
The paper
GCD: Garbled, Corrected, Demonstrandum -- Fixing and Proving Go's Extended GCD Implementation · Read on arXiv
National University of Singapore
We verify the 'extendedGCD' implementation in Go's standard library ('crypto/internal/fips140/bigmod'), which plays a crucial role in the generation of RSA key pairs. Even though the Go implementation is supposedly a direct port of BoringSSL's implementation, we uncovered two deviations that each break the invariants of an existing proof for BoringSSL: (1) the Go implementation deviates in the way coefficients are updated, and (2) it permits a larger input domain. We prove correctness and termination of both the existing Go implementation and a fixed implementation using Gobra, a deductive program verifier for Go. Where necessary, we used Lean to prove key lemmata on non-linear arithmetic, which we import into Gobra. For the existing implementation, we devise new invariants that accommodate the deviating coefficient updates; for the fixed implementation, we align the coefficient updates with BoringSSL's and port the existing proof. In both cases, we extend the proof to cover the larger input domain. Our fixed implementation updates coefficients in-place and, thus, reduces memory allocations, memory initializations, and memory copying operations resulting in an average speedup of 24% over the existing implementation. Our verification effort reveals three key insights: subtle bugs can slip into even well-reviewed code with surprising ease; formal verification is a powerful tool for uncovering them; and AI agents can facilitate the verification process by iteratively refining invariants and lemmata based on Gobra's error messages.
Transcript
Introduction to the show: ident: Security Radio. Generated commentary on the latest security and cryptography papers.
Nadia: I'm Nadia, and with me are Elias and Priya, guest researcher.
Elias: Today's paper: "GCD: Garbled, Corrected, Demonstrandum -- Fixing and Proving Go's Extended GCD Implementation".
Nadia: We verify and fix deviations in Go's standard library extended GCD implementation, which is critical for RSA key generation,
Elias: First, who's behind it and why it matters.
Paper summary: Nadia: So, wrapping up this discussion on "GCD: Garbled, Corrected, Demonstrandum -- Fixing and Proving Go's Extended GCD Implementation," the authors are showing how subtle bugs in a critical function like extended GCD can slip through even well-reviewed code.
Elias: They achieved that by identifying two specific deviations: incorrect coefficient updates and an input domain issue that violated the necessary proof assumptions.
Priya: The implications seem to be that formal verification, using tools like Gobra and Lean, is a powerful way to uncover these kinds of errors in foundational cryptographic primitives before they become exploited.
Nadia: It confirms that for components central to RSA key generation, rigorously proving correctness against a reference implementation can provide substantial confidence in the resulting keys.
Elias: This work also shows how adapting existing proofs, like those from Fiat Cryptography, allows them to handle these kinds of algorithmic changes systematically across different implementations.
Priya: I think what this means for us is that when we use standard library components, knowing that they've undergone this kind of deep structural verification offers a layer of assurance regarding their mathematical integrity.
Nadia: Ultimately, the title "GCD: Garbled, Corrected, Demonstrandum" points to the entire process: finding flaws in the original version, correcting them with performance improvements and mathematical fixes, and then proving they work correctly.
Elias: It highlights that even seemingly straightforward implementations require this level of formal scrutiny to ensure they meet the strict requirements of cryptographic standards like those used for RSA key generation.
Conclusion: Nadia: So, we've seen how they went through some deep verification on Go’s extended GCD, and now it’s time to talk about what that whole title really means for us as listeners.
Elias: I think the title "GCD: Garbled, Corrected, Demonstrandum" suggests a very thorough process of finding and fixing errors in a complex mathematical routine.
Priya: From a privacy standpoint, if this verification is successful, it suggests that the underlying mathematical operations used in key generation are much more trustworthy than we might assume.
Nadia: Exactly; when you fix subtle bugs like those coefficient updates, you're not just making code run faster; you’re ensuring the cryptographic foundation holds up under pressure.
Elias: And the authors clearly focused on showing that their fixes don't just patch things but actually prove the algorithm remains sound against known mathematical invariants.
Priya: I’m curious if this level of proof is something we can expect to see applied to other sensitive protocols, like secure communication channels or digital signatures.
Nadia: That’s the big question—if you can verify this piece of the puzzle, what's next on the list for us to scrutinize?
Elias: It opens up a discussion about how we build trust in open-source cryptographic libraries when they handle things as sensitive as RSA key generation.
Priya: It really brings up the question of where these formal verification tools fit into the broader security landscape for privacy researchers.
More episodes
- 2610.10597-Certified Corruption Budgets: Anytime-Valid Leaderboard Claims under Adaptive Rigging
- 2610.10608-From Investigation Failures to Reliable SOC Agents: Understanding and Improving LLM-Based Alert Triage
- 2610.10612-PyCache Trap: The Inspection-Execution Gap in Agent Skill Scanners
- 2610.10644-SoK: Failure Modes in Common Criteria Product Evaluation - A Taxonomy and Design-for-Evaluability Guidance
- 2610.10617-MRCert: Towards Post-deployment Patch Robustness Certification for Adversarially Patched Samples via Type-specific Masking
- 2610.10620-When AI Finds Hidden Messages, Does It Report?
- 2610.10625-Safe at One Loop, Risky at Another: Aligning Safety Across Recurrent Depths in Looped Language Models
- 2610.10992-The Hint Weight of ML-DSA Signatures Is Key-Dependent: An Empirical Study across the Three FIPS 204 Parameter Sets
- 2610.10659-Applying Security by Design at the Point of Execution: How Governed Security Requirements Affect the Security of AI-Generated Code
- 2610.10735-DITTO: A Context-aware Pickle-based Pre-Trained Model Scanner for Effective Security Audits