Git Product home page Git Product logo

hacspec hacspec chat

A specification language for crypto primitives in Rust.

This is the successor of https://github.com/HACS-workshop/hacspec but a predecessor of https://github.com/hacspec/hax. Development in this repository has mostly stopped, see hax instead.

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

Crates

Name Crates.io Docs CI
hacspec crates.io Docs Build & Test Status
hacspec-lib crates.io Docs Build & Test Status
hacspec-provider crates.io Docs Build & Test Status

Usage

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.

Typechecking

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 crates.io (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

Usage

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:

  • hacspec: the compiler, typechecker and language infrastructure for the hacspec subset of Rust
    • Note that the language infrastructure is excluded from the main workspace of crates, so it won't be build when you launch cargo build from the root of the repository.
  • hacspec-lib: the standard library of hacspec programs
  • hacspec-provider: a cryptography provider with a set of cryptographic primitives written in hacspec
    • This combines the individual crates from the examples directory and implements the RustCrypto API on top to use them from regular Rust code.

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

  • abstract-integers: wrapper around BigInt for modular natural integers
  • secret-integers: wrapper around integer types for constant-timedness
  • unsafe-hacspec-examples: cryptographic specs written in hacspec but not formally typechecked yet(hence the unsafety) as hacspec is a work in progress
  • examples: cryptographic primitives that have passed the hacspec typechecking
  • hacspec-attributes: helper for the hacspec library
  • hacspec-dev: utilities that are not part of the language

Compiled code:

  • fstar: contains F* translations of the cryptographic specs, produced by the hacspec compiler
  • easycrypt: contains EasyCrypt translations of the cryptographic specs, produced by the hacspec compiler
  • coq: contains Coq translations of the cryptographic specs, produced by the hacspec compiler

Contributing

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

  • the language if you want to work on the hacspec language itself
    • improve the typechecker
    • improve the existing compiler backends (F* and EasyCrypt)
    • add a new compiler backend
  • hacspec implementations
    • implementing new cryptographic primitives in hacspec
    • improve the provider
  • the standard library
    • enhance numeric implementations
    • enhance vector arithmetic

Examples

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

Examples

Unsafe examples

hacspec's Projects

creusot icon creusot

deductive verification of Rust code. (semi) automatically prove your code satisfies your specifications!

hacspec icon hacspec

Please see https://github.com/hacspec/hax

hacspec-python icon hacspec-python

Please check out https://github.com/hacspec/hacspec for more information on hacspec

hacspec-rust icon hacspec-rust

DEPRECATED (will be archived); Use https://github.com/hacspec/hacspec

hacspecs-rust icon hacspecs-rust

DEPRECATED (will be archived); Use https://github.com/hacspec/hacspec

hax icon hax

A Rust verification tool

rust-clippy icon rust-clippy

A bunch of lints to catch common mistakes and improve your Rust code

specs icon specs

Specifications written in hacspec

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.