pub trait FieldImplementationwhere
    for<'b> Self: Copy + Debug + ConditionallySelectable + ConstantTimeEq + PartialEq + AddAssign<&'b Self> + SubAssign<&'b Self> + MulAssign<&'b Self>,
    for<'a, 'b> &'a Self: Add<&'b Self, Output = Self> + Neg<Output = Self> + Sub<&'b Self, Output = Self> + Mul<&'b Self, Output = Self>,{
    type Limbs;

    const ZERO: Self;
    const ONE: Self;
    const D: Self;
    const D2: Self;
    const APLUS2_OVER_FOUR: Self;
    const EDWARDS_BASEPOINT_X: Self;
    const EDWARDS_BASEPOINT_Y: Self;
    const I: Self;
    const MONTGOMERY_BASEPOINT_U: Self;

    // Required methods
    fn to_bytes(&self) -> [u8; 32];
    fn from_bytes_unchecked(bytes: &[u8; 32]) -> Self;
    fn inverse(&self) -> Self;
    fn pow2523(&self) -> Self;

    // Provided methods
    fn from_unreduced_bytes(bytes: &[u8; 32]) -> Self { ... }
    fn from_bytes(bytes: &[u8; 32]) -> Result<Self> { ... }
    fn parity(&self) -> u8 { ... }
    fn squared(&self) -> Self { ... }
}
Expand description

Requirements on an implementation of the base field.

There are many ways to implement field arithmetic in the base field of integers modulo 2**255 - 19.

This trait specifies our requirements, such that end users can experiment with their own ideas.

This crate, as of now, offers two implementations:

  • TweetNaCl: a transliteration of the TweetNaCl code to Rust
  • Haase: a fast implementation in assembly, due to Bjoern Haase

Planned: Schoolbook: our own attempt at a fast yet readable implementation

Originally, the plan was to have everything generic over the field implementation, so far we have not been successful in convincing the Rust compiler of this. Therefore, currently the implementations must be selected at compile time using feature flags.

Required Associated Types§

source

type Limbs

Internal representation as limbs

Required Associated Constants§

source

const ZERO: Self

source

const ONE: Self

source

const D: Self

source

const D2: Self

source

const APLUS2_OVER_FOUR: Self

source

const EDWARDS_BASEPOINT_X: Self

source

const EDWARDS_BASEPOINT_Y: Self

source

const I: Self

source

const MONTGOMERY_BASEPOINT_U: Self

Required Methods§

source

fn to_bytes(&self) -> [u8; 32]

to canonical representation as little-endian bytes

source

fn from_bytes_unchecked(bytes: &[u8; 32]) -> Self

construct from canonical representation as little-endian bytes

source

fn inverse(&self) -> Self

source

fn pow2523(&self) -> Self

Provided Methods§

source

fn from_unreduced_bytes(bytes: &[u8; 32]) -> Self

construct from possibly non-canonical representation as little-endian bytes

source

fn from_bytes(bytes: &[u8; 32]) -> Result<Self>

construct from canonical representation as little-endian bytes, with validity check

source

fn parity(&self) -> u8

parity of field element, viewed as integer modulo 2**255 - 19

source

fn squared(&self) -> Self

default implementation, actual implementation may override this with a faster version

Object Safety§

This trait is not object safe.

Implementors§

source§

impl FieldImplementation for FieldElement

§

type Limbs = [i64; 16]

source§

const ZERO: Self = _

source§

const ONE: Self = _

source§

const D: Self = _

source§

const D2: Self = _

source§

const EDWARDS_BASEPOINT_X: Self = _

source§

const EDWARDS_BASEPOINT_Y: Self = _

source§

const I: Self = _

source§

const APLUS2_OVER_FOUR: Self = _

source§

const MONTGOMERY_BASEPOINT_U: Self = _