Trait ScalarField

Source
pub trait ScalarField:
    PrimeField
    + FromUniformBytes<64>
    + From<bool>
    + Hash
    + Ord {
    // Required methods
    fn to_u64_limbs(self, num_limbs: usize, bit_len: usize) -> Vec<u64>;
    fn to_bytes_le(&self) -> Vec<u8> ;

    // Provided methods
    fn from_bytes_le(bytes: &[u8]) -> Self { ... }
    fn get_lower_32(&self) -> u32 { ... }
    fn get_lower_64(&self) -> u64 { ... }
}
Expand description

Helper trait to represent a field element that can be converted into u64 limbs.

Note: Since the number of bits necessary to represent a field element is larger than the number of bits in a u64, we decompose the integer representation of the field element into multiple u64 values e.g. limbs.

Required Methods§

Source

fn to_u64_limbs(self, num_limbs: usize, bit_len: usize) -> Vec<u64>

Returns the base 2<sup>bit_len</sup> little endian representation of the ScalarField element up to num_limbs number of limbs (truncates any extra limbs).

Assumes bit_len < 64.

  • num_limbs: number of limbs to return
  • bit_len: number of bits in each limb
Source

fn to_bytes_le(&self) -> Vec<u8>

Returns the little endian byte representation of the element.

Provided Methods§

Source

fn from_bytes_le(bytes: &[u8]) -> Self

Creates a field element from a little endian byte representation.

The default implementation assumes that PrimeField::from_repr is implemented for little-endian. It should be overriden if this is not the case.

Source

fn get_lower_32(&self) -> u32

Gets the least significant 32 bits of the field element.

Source

fn get_lower_64(&self) -> u64

Gets the least significant 64 bits of the field element.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl ScalarField for Fq

Source§

fn to_u64_limbs(self, num_limbs: usize, bit_len: usize) -> Vec<u64>

Source§

fn to_bytes_le(&self) -> Vec<u8>

Source§

fn get_lower_32(&self) -> u32

Source§

fn get_lower_64(&self) -> u64

Source§

impl ScalarField for Fr

Source§

fn to_u64_limbs(self, num_limbs: usize, bit_len: usize) -> Vec<u64>

Source§

fn to_bytes_le(&self) -> Vec<u8>

Source§

fn get_lower_32(&self) -> u32

Source§

fn get_lower_64(&self) -> u64

Source§

impl ScalarField for Fp

Source§

fn to_u64_limbs(self, num_limbs: usize, bit_len: usize) -> Vec<u64>

Source§

fn to_bytes_le(&self) -> Vec<u8>

Source§

fn get_lower_32(&self) -> u32

Source§

fn get_lower_64(&self) -> u64

Source§

impl ScalarField for Fq

Source§

fn to_u64_limbs(self, num_limbs: usize, bit_len: usize) -> Vec<u64>

Source§

fn to_bytes_le(&self) -> Vec<u8>

Source§

fn get_lower_32(&self) -> u32

Source§

fn get_lower_64(&self) -> u64

Implementors§