#prime-field #proc-macro #ff #procedural #finite-fields #traits #derive

macro ff_derive

Procedural macro library used to build custom prime field implementations

14 releases (breaking)

0.13.0 Dec 6, 2022
0.12.1 Oct 28, 2022
0.12.0 May 4, 2022
0.11.0 Sep 2, 2021
0.2.0 Jun 27, 2017

#1111 in Procedural macros

Download history 4483/week @ 2023-11-20 10714/week @ 2023-11-27 9318/week @ 2023-12-04 8719/week @ 2023-12-11 8444/week @ 2023-12-18 3709/week @ 2023-12-25 8511/week @ 2024-01-01 13159/week @ 2024-01-08 13667/week @ 2024-01-15 13938/week @ 2024-01-22 13486/week @ 2024-01-29 12964/week @ 2024-02-05 14447/week @ 2024-02-12 12237/week @ 2024-02-19 12611/week @ 2024-02-26 9356/week @ 2024-03-04

49,537 downloads per month
Used in 61 crates (via ff)

MIT/Apache

48KB
1K SLoC

ff

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

RFC process

This crate follows the zkcrypto RFC process. If you want to propose "substantial" changes to this crate (in particular to the ff traits), please create an RFC for wider discussion.

Disclaimers

  • 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).

Usage

Add the ff crate to your Cargo.toml:

[dependencies]
ff = "0.13"

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

#![derive(PrimeField)]

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:

[dependencies]
ff = { version = "0.13", features = ["derive"] }

And then use the macro like so:

#[macro_use]
extern crate ff;

#[derive(PrimeField)]
#[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.56 or higher.

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

License

Licensed under either of

at your option.

Contribution

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.

Dependencies

~2MB
~44K SLoC