Foundational Cryptography in Spark A team used AI to produce SPARK Platinum formally verified implementations of AES (128, 192, 256), SHA-256 and HMAC-SHA-256, published in a fork of the National Security Agency's Foundation repository, which the NSA posted to GitHub in July with formal Cryptol specifications and a proven Rust AES implementation. No direct human intervention was required beyond reviewing the specifications and making minor non-functional stylistic improvements, and correctness was established four ways: SPARK specifications proven functionally equivalent to the NSA's Cryptol specifications for selected message, key and text lengths, implementations proven to satisfy their functional specifications, implementations proven equivalent to the Cryptol specifications, and testing against the Cryptol specifications reaching 100% MC/DC coverage. The work follows Anthropic's research post on using LLMs in formal software verification and is presented as a demonstration of SPARK combined with AI. Foundational Cryptography in SPARK Recently, Anthropic https://www.anthropic.com/ published a research post in which they touted the use of LLMs in formal software verification https://www.anthropic.com/research/formal-verification . We’re excited that they’re excited Of course, we’ve been talking about this all year and before . We agree that AI makes formal software verification feasible in ways it simply wasn’t before. Here’s our latest example. In July, the United States National Security Agency https://www.nsa.gov/ published to GitHub https://github.com/NationalSecurityAgency a repository of formal specifications of cryptographic algorithms. They call the repository Foundation https://github.com/NationalSecurityAgency/Foundation . As a demonstration of their work, they include a proven Rust implementation of AES. Naturally, we saw this as an opportunity to demonstrate SPARK and, more importantly, SPARK + AI. You can find our work on a fork here https://github.com/manthonyaiello/Foundation/tree/spark-v1.0 ; see the README in the spark folder here https://github.com/manthonyaiello/Foundation/tree/spark-v1.0/spark . Using AI, we obtained formal specifications and proven implementations of AES 128, 192, 256 , SHA-256, and HMAC-SHA-256 in SPARK. No direct human intervention was required, although we reviewed the specifications and offered minor stylistic non-functional improvements. This is SPARK Platinum code: full functional correctness. We are confident in the correctness of the work because we have verified correctness four different ways: 1. the SPARK specifications are proven to be functionally equivalent to the NSA’s Cryptol https://tools.galois.com/cryptol specifications for selected message, key, and text lengths; 2. the SPARK implementations are proven to satisfy their functional specifications; 3. the SPARK implementations are proven to be functionally equivalent to the NSA’s Cryptol specifications for selected message, key, and text lengths; and 4. the SPARK is tested against the Cryptol specifications So even though the SPARK specifications and implementations were authored entirely by AI, we have multiple formal proofs plus extensive specification-based tests reaching 100% MC/DC coverage that the AI’s work is correct and complete. The NSA’s Foundation Foundation is an NSA public repository of cryptographic algorithms that are formally specified using Galois https://www.galois.com/ ’s Cryptol, a formal specification language designed specifically to specify cryptography. The NSA provides many algorithms; for some, they provide a reference implementation in Rust. Our Picks: AES, SHA-256, HMAC-SHA-256 As a starting point, we picked three algorithms: The details of these algorithms are beyond the scope of this blog post; the links above lead to their Wikipedia entries. We chose AES because it’s commonly used, because the NSA provided a Rust reference implementation, and because it’s challenging to specify. We chose SHA-256 because it’s also commonly used, and having a second algorithm offers evidence that our approach is replicable i.e., AES isn’t somehow especially easy for SPARK . We chose HMAC because three is a nice number, and it builds on the SHA-256 work. Additionally, these three algorithms illustrate different properties of interest: - AES depends on arithmetic over the Galois fields GF 2 and GF 2