Crate primefield

Crate primefield 

Source
Expand description

§RustCrypto: Generic Prime Fields

crate Docs Build Status Apache2/MIT licensed Rust Version Project Chat

Generic implementation of prime fields built on crypto-bigint, along with macros for writing field element newtypes including ones with formally verified arithmetic using fiat-crypto.

Documentation

§About

A prime field is a finite field of order 𝑝, where 𝑝 is a prime number. Because 𝑝 is prime, every non-zero element of the field has a modular inverse.

Prime fields are notable for their use in cryptography, particularly for their use as coordinates (a.k.a. base field) and the scalar field of elliptic curve implementations.

The implementation provided by this crate is built on crypto_bigint::modular, which provides a generic implementation of modular arithmetic with a modulus fixed at compile-time.

§Minimum Supported Rust Version (MSRV) Policy

MSRV increases are not considered breaking changes and can happen in patch releases.

The crate MSRV accounts for all supported targets and crate feature combinations, excluding explicitly unstable features.

§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.

Re-exports§

pub use bigint;
pub use bigint::hybrid_array as array;
pub use ff;
pub use rand_core;
pub use subtle;
pub use zeroize;

Modules§

consts

Macros§

fiat_bernstein_yang_invert
Emit wrapper function for a fiat-crypto generated implementation of the Bernstein-Yang (a.k.a. safegcd) modular inversion algorithm.
field_op
Emit a core::ops trait wrapper for an inherent method which is expected to be provided by a backend arithmetic implementation (e.g. fiat-crypto)
monty_field_arithmetic
Add const fn methods to the given field element for performing field arithmetic operations, e.g. add, double, sub, multiply, neg.
monty_field_element
Implements a field element type whose internal representation is in Montgomery form, providing a combination of trait impls and inherent impls which are const fn where possible.
monty_field_fiat_arithmetic
Add fiat-crypto synthesized arithmetic impls to the given field element.
monty_field_params
Creates a ZST representing the Montgomery parameters for a given field modulus.
monty_field_params_with_root_of_unity
Same as monty_field_params!, but with a precomputed ROOT_OF_UNITY constant.
test_field_identity
Implement field element identity tests.
test_field_invert
Implement field element inversion tests.
test_field_sqrt
Implement field element square root tests.
test_primefield
Implement all tests for a type which impls the PrimeField trait.
test_primefield_constants
Implement tests for constants defined by the PrimeField trait.

Structs§

Error
Error type.
MontyFieldElement
Field element type which uses an internal Montgomery form representation.

Enums§

ByteOrder
Byte order used when encoding/decoding field elements as bytestrings.

Traits§

MontyFieldParams
Extension trait for defining additional field parameters beyond the ones provided by ConstMontyParams.

Functions§

compute_t
Compute t = (modulus - 1) >> S

Type Aliases§

MontyFieldBytes
Serialized representation of a field element.
Result
Result type.