#derive #finite-fields #prime #finite-field #macro #finite #ff #zeroize

macro ff_derive-zeroize

Procedural macro library used to build custom prime field implementations

1 unstable release

0.6.2 Mar 26, 2020

#1017 in Rust patterns

Download history 1599/week @ 2021-09-28 1962/week @ 2021-10-05 2503/week @ 2021-10-12 2364/week @ 2021-10-19 1715/week @ 2021-10-26 1677/week @ 2021-11-02 1815/week @ 2021-11-09 1810/week @ 2021-11-16 2035/week @ 2021-11-23 2786/week @ 2021-11-30 2887/week @ 2021-12-07 2840/week @ 2021-12-14 1664/week @ 2021-12-21 1706/week @ 2021-12-28 2243/week @ 2022-01-04 2196/week @ 2022-01-11

8,351 downloads per month
Used in 26 crates (via ff-zeroize)


823 lines


ff is a finite field library written in pure Rust, with no unsafe{} code.


  • This library does not provide constant-time guarantees. The traits enable downstream users to expose constant-time logic, but #[derive(PrimeField)] in particular does not generate constant-time code (even for trait methods that return constant-time-compatible values).


Add the ff crate to your Cargo.toml:

ff = "0.11"

The ff crate contains the Field and PrimeField traits. See the documentation for more.


If you need an implementation of a prime field, this library also provides a procedural macro that will expand into an efficient implementation of a prime field when supplied with the modulus. PrimeFieldGenerator must be an element of Fp of p-1 order, that is also quadratic nonresidue.

First, enable the derive crate feature:

ff = { version = "0.11", features = ["derive"] }

And then use the macro like so:

extern crate ff;

#[PrimeFieldModulus = "52435875175126190479447740508185965837690552500527637822603658699938581184513"]
#[PrimeFieldGenerator = "7"]
#[PrimeFieldReprEndianness = "little"]
struct Fp([u64; 4]);

And that's it! Fp now implements Field and PrimeField.

Minimum Supported Rust Version

Requires Rust 1.51 or higher.

Minimum supported Rust version can be changed in the future, but it will be done with a minor version bump.


Licensed under either of

at your option.


Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.


~28K SLoC