Skip to the content.


A specification language for crypto primitives in Rust.

This is the successor of

For a quick intro, you can look at the presentation slides. More information is available in the book. Also, see the Publications below.


Name Docs CI
hacspec ย  Build & Test Status
hacspec-lib Docs Build & Test Status


Writing hacspec

hacspec is always valid Rust code such that starting to write hacspec is as simple as writing Rust code that is compliant with the language specification. However, this is very tedious. It is recommended to use the hacspec standard library to write hacspec. In order to ensure that the code is a hacspec one can use the typecheker.


Make sure you have at least rustup 1.23.0. The rust-toolchain automatically picks the correct Rust nightly version and components. The compiler version is currently pinned to nightly-2023-01-15.

Installing the typechecker from the repository

cargo install --path language

Installing the typechecker from (not always up to date)

cargo install hacspec --version 0.2.0-beta.4

Manually installing dependencies

First ensure that Rust nightly is installed and the typechecker is installed.

cd language
rustup toolchain install nightly-2023-01-15
rustup component add --toolchain nightly-2023-01-15 rustc-dev
cargo +nightly-2023-01-15 install hacspec

Depending on your system you might also need llvm-tools-preview

rustup component add --toolchain nightly-2023-01-15 llvm-tools-preview


In a hacspec crate or workspace directory typechecking can be done as follows now: (Specifying +nightly-2023-01-15 is only necessary if itโ€™s not specified in the toolchain as it is in this main repository.)

cargo +nightly-2023-01-15 hacspec <crate-name>

Note that the crate dependencies need to be compiled before it can be typechecked.

cargo +nightly-2023-01-15 build

If typechecking succeeds, it should show

> Successfully typechecked.

Generating code

To generate F*, EasyCrypt, or Coq code from hacspec the typechecker (see above) is required.

cargo +nightly-2021-11-14 hacspec -o <fst-name>.fst <crate-name>
cargo +nightly-2021-11-14 hacspec -o <ec-name>.ec <crate-name>
cargo +nightly-2021-11-14 hacspec -o <coq-name>.v <crate-name>

Publications & Other material

Secondary literature, using hacspec:

Repository Structure

This is a cargo workspace consisting of three main crates:

The three main crates make use of a set of additional crates:

Compiled code:


Before starting any work please join the Zulip chat, start a discussion on Github, or file an issue to discuss your contribution.

The main entry points for contributions and some general work items are


Thereโ€™s a set of example specs, divided between the safe and unsafe. To run all examples one can use cargo test.


Unsafe examples