From FIPS-197 to a proved C implementation of AES-128 in 48 minutes

By CTO and Co-Founder Benjamin Monate

An empty directory turned into a proved AES-128 timeline of the 48-minute session using TrustInSoft Analyzer.

In 48 minutes, starting from an empty directory, an AI agent driving TrustInSoft Analyzer did the following. It downloaded the public AES reference material, wrote a C implementation of AES-128 and specified it formally. AES-128 is the Advanced Encryption Standard with a 128-bit key: the block cipher standardised by NIST in FIPS-197, which protects most encrypted data today, from HTTPS connections to disk encryption. Specifying it formally means writing down, in a precise mathematical language, what each function must compute, so that a tool can check the code against that description for all inputs rather than against a handful of tests. It then proved that the C code computes AES-128, exactly as defined by the FIPS-197 standard defined by the US government, for every key and every plaintext.

The proof covers all 2^256 (a 78-digit-long number) key and plaintext pairs, not a sample. It is machine-checked: 130 of 130 proof obligations are discharged by SMT solvers and the Rocq proof assistant (formerly Coq). It also replays with a single invocation of TrustInSoft Analyzer in under seven minutes, with no AI and no human in the loop.

This post explains what was built, what exactly was proved, how the 48 minutes were spent, and where human judgment has to focus to ratify the outcome.

What was built

The starting point was public. The NSA's Foundation project publishes AES as a Cryptol specification of FIPS-197 and a Rust implementation. The agent found both on its own, pinned a public fork at tag spark-v1.0, and recorded a SHA-256 for each of the 51 reference files.

From there, it produced three things:

• A C implementation: 90 lines in 13 small functions, one per AES building block: S-box, xtime, SubBytes, ShiftRows, MixColumns, AddRoundKey, the key-schedule step, one round, and the full encryption. It passes blocks by value, so there are no pointers, no heap and no loops.

• A formal specification: about 60 lines of ACSL, the C specification language, transcribed from Foundation's byte-level Cryptol. It defines AES128_Encrypt as a plain mathematical function: ten round keys, an initial key addition, nine full rounds and a final round without MixColumns.

• A proof that each C function returns exactly its ACSL counterpart, checked by J3, the deductive verification engine in TrustInSoft Analyzer. J3 turns each function and its contract into mathematical proof obligations and hands them to automatic and interactive provers; a function is accepted only when every obligation is proved.

each C function returns exactly its ACSL counterpart, checked by J3, the deductive verification engine in TrustInSoft Analyzer

The AI agent does the work; TrustInSoft Analyzer guarantees it. Everything the agent writes is a proposal, and it is accepted only once J3 has proved it. What remains for people is to check that the short specification says AES-128.

The public entry point is a single line:

aes_block aes128_encrypt_block(aes_block key, aes_block plaintext);

What exactly is proved

The headline theorem is the contract on the entry point:

/*@ assigns \nothing;
    ensures exact_aes128_encrypt_block:
      \result == AES128_Encrypt(key, plaintext);
*/

In plain words: for every key and every plaintext, the function returns exactly the AES-128 ciphertext defined by the specification. It writes no memory, and it never triggers undefined behavior. That rules out uninitialised reads, out-of-bounds table accesses, invalid shifts and signed overflow.

Three properties make this stronger than it may look:

  • Total. There are no preconditions, so no caller can break an assumption.
  • Exact. The result is equal to a fully defined function, not merely related to it. There is no uninterpreted symbol hiding behind an axiom.
  • Closed. Every one of the 13 functions is proved against its own contract in the same run, so each call relies on a proved result.

This matters for cryptographic code because cipher bugs live in rare cases: a wrong round constant, one mis-indexed byte in ShiftRows, a missing reduction in the field multiplication. Tests sample a few thousand of the 2^256 possible inputs. A proof covers all of them. The specification that the proof refers to is short enough to read against FIPS-197 in an afternoon.

48 minutes, start to finish

The session log records the request at 12:38:31 UTC and completion at 13:26:56 UTC: 48 minutes and 25 seconds of wall-clock time. That covers everything: finding and downloading the references, writing the C code and the specification, developing the proof, running tests and negative controls, and writing the verification report.

timeline of the 48-minute session and finding and downloading the references, writing the C code and the specification, developing the proof, running tests and negative controls, and writing the verification report.

Above: From empty directory to proved AES-128 timeline of the 48-minute session.

Read from the last-modified time of each file, so the minute marks are approximate. The proof itself took the longest stretch: 33 minutes in, every goal but one was proved, and the last one needed Rocq.

How the proof works

The proof is modular. Each C function has a contract saying it returns exactly the matching ACSL definition: aes_mix_word returns AES_MixWord(a), aes_round returns AES_Round(a, k), and so on. J3, TrustInSoft Analyzer's deductive verification engine, proves each body against its own contract and then uses those contracts at the call sites. Because the C call structure mirrors the specification, every step is small.

SMT solvers handle the bytes. J3 chooses its memory and arithmetic model automatically. It uses bit-vectors where XOR, shifts and truncation matter, such as xtime and MixColumns, and mathematical integers elsewhere. CVC5 and Alt-Ergo, two widely used open-source SMT solvers (automatic provers for logical formulas over bit-vectors, integers and arrays), closed 129 of the 130 goals, including the 256-entry S-box table matched against its logical definition.

Rocq handles the composition. One goal resisted SMT: showing that the chain of 23 calls in aes128_encrypt_block equals the ten-round nested specification. Solvers try to expand the whole AES expression and run out of time. J3 exported that single goal to Rocq. The proof that closes it is 26 lines of ordinary tactics:

pose proof tmp_21_contents.   (* final call's proved contract )
( ... the 23 other call-site equalities ... )
unfold aES128_Encrypt, aES_State9, ( ... *) aES_K2.
congruence.

It loads the proved call results, unfolds only the round and key-schedule chain, and closes the goal by rewriting equals for equals. It adds no lemma, no axiom and no Admitted. The Rocq kernel re-checks it on every replay.

Why you can trust it

A result produced this fast deserves suspicion, and the campaign was built to answer it. "All goals proved" can still be hollow: the context may be contradictory, obligations may have been filtered out, or a proof script may never have run. Each of these was checked:

The whole proof replays with a single invocation of TrustInSoft Analyzer, with no AI and no human in the loop. A measured replay took 392 seconds of elapsed time on a 4-core workstation. Acceptance is based on the actual goal results, not on exit codes, and a SHA-256 is pinned for every source and configuration file, so any change forces a fresh review.

In an independent audit for this post, the ACSL definitions were re-implemented separately and evaluated directly. They reproduce the FIPS-197 Appendix C.1 test vector, which is not in the project's own test suite.

What the 48 minutes do not cover

The proof shows that the C code matches the ACSL specification. Whether that specification is AES-128 is a human judgment. It rests on about 60 lines of definitions and a 256-entry table that a reviewer must compare with FIPS-197 and Foundation's Cryptol. The tests and the independent vector check support that review, but they do not replace it. The 48 minutes do not include that review time.

The proof also has a deliberate scope:

• It reasons about C source semantics. The compiled binary is tested, not proved.

• It says nothing about timing side channels. The S-box is a table lookup indexed by secret data.

• It covers one-block AES-128 encryption only: no decryption, cipher modes, padding or other key sizes.

These limits are stated in the verification report rather than left for a reader to discover.

What this changes

For engineering teams, this shifts the economics of formal proof: The expensive part is no longer writing the proof but agreeing on what the code is supposed to do.

Here the proof was produced in under an hour. What is left for people is reading a short specification and deciding whether it says the right thing, which is the part that most needs human judgment.

The combination is what makes this work. An AI agent is fast at porting code, writing specifications and trying proof strategies. A deductive verifier like J3, backed by SMT solvers and the Rocq kernel, guarantees that none of that speed costs correctness. An agent can propose a wrong proof, but it cannot get one accepted.

We see this AES-128 pilot as the first step. Natural next targets are the other key sizes, decryption, and the rest of the Foundation library. If you maintain C code that must be right for every input, such as cryptography, parsers or protocol stacks, get in touch to see what a few hours of this approach can give you.

Sources

Newsletter

Contact Our Team!

Whether you're interested in a demo, need pricing information, have a support question, or want to learn more about our solutions, our team is here to help.

Get In Touch