Announcing Verified Garbage: An experimental formally verified cryptography library

Implementors of cryptographic libraries face complicated trade-offs. Some of the most challenging trade-offs are between performance, security and verifiability, complexity, and cross-platform support. For example, writing in assembly is great for performance, but makes code hard to review and ensure correctness. Similarly, writing in a high level language makes it easier to avoid buffer overflows or undefined behavior, but makes it harder to ensure code is constant-time. These trade-offs, and the consequences of making poor choices around security and verifiability, are why development of cryptography libraries is so heavily discouraged. Verified Garbage is a new cryptography library we’ve developed which attempts to address these trade-offs – building on great ideas we’ve seen in other cryptography libraries.

The core of the Verified Garbage approach is to write everything in assembly, and then formally verify that the assembly has the properties we want (correctness, well-definedness, constant-timeness). This approach is inspired by AWS’s s2n-bignum library. Doing this at the scale of “every single algorithm, for every single ISA” is made possible through the use of LLMs, described in more detail below.

Verified Garbage starts with writing Lean specifications for cryptographic algorithms (such as AES-GCM or X25519). We also write specifications for CPU instruction sets, modeling their instructions and behaviors. Finally, we write assembly to implement each algorithm for each architecture, and formally prove that under that ISA the assembly is equivalent to the specified algorithm and also constant time.1 This means that we can make the assembly arbitrarily sophisticated in pursuit of performance, because the formal verification ensures that it’s safe.

The things that make Verified Garbage distinctive are:

  1. The breadth of algorithms we support – we include support for every single cryptographic algorithm used by pyca/cryptography, all of them formally verified.
  2. The breadth of instruction sets we support – Verified Garbage runs on x86, x86-64, ARMv7, ARM64, PPC64le, and RISCV64.
  3. The extent to which we have been able to use this platform to ruthlessly optimize algorithms and achieve exceptional performance.

Benchmarks

In order to assess performance, we have a benchmark suite that measures the performance of every algorithm in Verified Garbage, and we use this both to detect regressions and to compare ourselves with other libraries. We have also built a crypto provider for rustls – a Rust TLS library – and use the rustls benchmarks to measure end-to-end performance for real applications. What follows are a set of benchmark results for a set of representative benchmarks.

Benchmarks were performed on an AMD Ryzen 9 9950X running Ubuntu 26.04 pinned to one core, as well as an Apple M1 Max, running macOS 27. The OpenSSL we’re comparing with is 4.1.0, built from source. The AWS-LC we’re comparing with is 5.12.0 as bundled in aws-lc-rs 1.19.0.

All numbers are throughput relative to a 1.0 baseline for OpenSSL. Please note that the relative performance of different cryptographic libraries can vary depending on the instruction set and which extensions a given CPU supports. While we have done our best to ensure consistently good performance in Verified Garbage, the data presented here (x86-64 and ARM64, with modern extensions) does represent a target for which we have spent the most time and energy optimizing.

ML-KEM

ML-KEM throughput on AMD Ryzen 9 9950X

ML-KEM throughput on Apple M1 Max

ML-DSA

ML-DSA throughput on AMD Ryzen 9 9950X

ML-DSA throughput on Apple M1 Max

ECDH

X25519 and ECDH throughput on AMD Ryzen 9 9950X

X25519 and ECDH throughput on Apple M1 Max

ECDSA

ECDSA throughput on AMD Ryzen 9 9950X

ECDSA throughput on Apple M1 Max

RSA PKCS#1

RSA PKCS#1 throughput on AMD Ryzen 9 9950X

RSA PKCS#1 throughput on Apple M1 Max

RSA PSS

RSA PSS throughput on AMD Ryzen 9 9950X

RSA PSS throughput on Apple M1 Max

AES-128-GCM

AES-128-GCM throughput on AMD Ryzen 9 9950X

AES-128-GCM throughput on Apple M1 Max

ChaCha20Poly1305

ChaCha20-Poly1305 throughput on AMD Ryzen 9 9950X

ChaCha20-Poly1305 throughput on Apple M1 Max

SHA256

SHA-256 throughput on AMD Ryzen 9 9950X

SHA-256 throughput on Apple M1 Max

HMAC-SHA256

HMAC-SHA-256 throughput on AMD Ryzen 9 9950X

HMAC-SHA-256 throughput on Apple M1 Max

Rustls TLS 1.3 handshakes (baseline is AWS-LC, not OpenSSL)

rustls TLS 1.3 handshake throughput on AMD Ryzen 9 9950X

rustls TLS 1.3 handshake throughput on Apple M1 Max

Rustls TLS 1.3 bulk data (baseline is AWS-LC, not OpenSSL)

rustls TLS 1.3 bulk data throughput on AMD Ryzen 9 9950X

rustls TLS 1.3 bulk data throughput on Apple M1 Max

Conclusion

We accomplish all of this through the use of LLMs. Given our formal verification scaffolding, we can let LLMs run wild, implementing sophisticated optimizations, with complete confidence in the correctness of the assembly.

That said, the correctness of the library depends on the correctness of the specifications we have for cryptographic algorithms and ISAs. Unlike the assembly and proofs, which are formally verified and thus do not require review, these specifications form our trusted computing base and must be hand-reviewed to establish correctness. Our specifications were also written by LLMs, and then reviewed by humans. This project represents two independent observations: 1) that given a TCB, LLMs are incredibly effective at hill-climbining improving performance and then formally verifying the validity of those optimizations, 2) that we’re able to build that TCB and then turn it into a useful library.

We know that many are likely to be skeptical of a new cryptography library – perhaps particularly one whose development involved heavy use of LLMs. As long-time maintainers of widely-used cryptographic libraries, this library reflects our best ideas for how to build a trustworthy cryptography library. That said, this is a new library, and it is ultimately an experiment in whether this approach is an effective one, and it will benefit from time and feedback.

If you find Verified Garbage interesting, we have packaged it as a Rust library, which you can find on https://crates.io/crates/verified-garbage (cargo add verified-garbage). We’ve also built a rustls provider (https://crates.io/crates/rustls-verified-garbage), which lets you use Verified Garbage’s crypto in TLS.

Finally, this library would not exist without innumerable sources of inspiration. In particularly we want to recognize, AWS’s s2n-bignum, Joe Birr-Pixton’s graviola, Bobby Powers, and the many people we’ve spoken to about ideas like these over the years at events like Real World Crypto and the High Assurance Cryptography Software Workshop (HACS).

What’s next?

First, we plan to continue to obsessively optimize. There are a lot of algorithms, and a lot of architectures, and our goal is to have the fastest implementation possible for every single one of them on every single CPU.

Second, we want to find ways to bolster trust in our TCB. We’re interested in a number of possible approaches to do this, including potentially replacing our LLM authored specifications with community maintained, human authored, specifications for cryptographic algorithms.

But most importantly, we’re interested in hearing from potential users on what would make this library valuable for them? What would it take for you to use this?

Frequently Asked Questions

Q. What’s with the name?
A. It’s an ironic take on the classic Charles Babbage quip, “On two occasions I have been asked, ‘Pray, Mr. Babbage, if you put into the machine wrong figures, will the right answers come out?’ I am not able rightly to apprehend the kind of confusion of ideas that could provoke such a question.”, better known as “garbage in, garbage out”, crossed with the reality that many would consider this library to be slop.

Q. You both maintain the pyca/cryptography library, do you plan to replace its use of OpenSSL?
A. Not at the moment. But it’s certainly a question that’s on our minds. Before we’d consider it, we have a lot of work to do – both technical and social – to ensure that a transition like that would be seamless for users. It’s not a step we’d take lightly, and if we do get to that point where we’re ready to consider it, you’ll hear about it.

  1. We use the standard definition of constant-timeness: the instruction trace does not depend on any secret inputs, and no instruction that handles secret data has data-dependent timing. ↩