IntMod

Trait IntMod 

Source
pub trait IntMod:
    Sized
    + Eq
    + Clone
    + Debug
    + Neg<Output = Self>
    + Add<Output = Self>
    + Sub<Output = Self>
    + Mul<Output = Self>
    + DivUnsafe<Output = Self>
    + Sum
    + Product
    + for<'a> Add<&'a Self, Output = Self>
    + for<'a> Sub<&'a Self, Output = Self>
    + for<'a> Mul<&'a Self, Output = Self>
    + for<'a> DivUnsafe<&'a Self, Output = Self>
    + for<'a> Sum<&'a Self>
    + for<'a> Product<&'a Self>
    + AddAssign
    + SubAssign
    + MulAssign
    + DivAssignUnsafe
    + for<'a> AddAssign<&'a Self>
    + for<'a> SubAssign<&'a Self>
    + for<'a> MulAssign<&'a Self>
    + for<'a> DivAssignUnsafe<&'a Self> {
    type Repr: AsRef<[u8]> + AsMut<[u8]>;
    type SelfRef<'a>: Add<&'a Self, Output = Self> + Sub<&'a Self, Output = Self> + Neg<Output = Self> + Mul<&'a Self, Output = Self> + DivUnsafe<&'a Self, Output = Self>
       where Self: 'a;

    const MODULUS: Self::Repr;
    const NUM_LIMBS: usize;
    const ZERO: Self;
    const ONE: Self;
Show 24 methods // Required methods fn from_repr(repr: Self::Repr) -> Self; fn from_le_bytes(bytes: &[u8]) -> Option<Self>; fn from_be_bytes(bytes: &[u8]) -> Option<Self>; fn from_le_bytes_unchecked(bytes: &[u8]) -> Self; fn from_be_bytes_unchecked(bytes: &[u8]) -> Self; fn from_u8(val: u8) -> Self; fn from_u32(val: u32) -> Self; fn from_u64(val: u64) -> Self; fn as_le_bytes(&self) -> &[u8] ; fn to_be_bytes(&self) -> Self::Repr; fn modulus_biguint() -> BigUint; fn from_biguint(biguint: BigUint) -> Self; fn as_biguint(&self) -> BigUint; fn neg_assign(&mut self); fn double_assign(&mut self); fn square_assign(&mut self); fn assert_reduced(&self); fn is_reduced(&self) -> bool; fn set_up_once(); unsafe fn eq_impl<const CHECK_SETUP: bool>(&self, other: &Self) -> bool; unsafe fn add_ref<const CHECK_SETUP: bool>(&self, other: &Self) -> Self; // Provided methods fn double(&self) -> Self { ... } fn square(&self) -> Self { ... } fn cube(&self) -> Self { ... }
}
Expand description

Trait definition for OpenVM modular integers, where each operation is done modulo MODULUS.

Division is only defined over the group of units in the ring of integers modulo MODULUS. It is undefined behavior outside of this group.

Required Associated Constants§

Source

const MODULUS: Self::Repr

Modulus as a Repr.

Source

const NUM_LIMBS: usize

Number of limbs used to internally represent an element of Self.

Source

const ZERO: Self

The zero element (i.e. the additive identity).

Source

const ONE: Self

The one element (i.e. the multiplicative identity).

Required Associated Types§

Source

type Repr: AsRef<[u8]> + AsMut<[u8]>

Underlying representation of IntMod. Usually of the form [u8; NUM_LIMBS].

Source

type SelfRef<'a>: Add<&'a Self, Output = Self> + Sub<&'a Self, Output = Self> + Neg<Output = Self> + Mul<&'a Self, Output = Self> + DivUnsafe<&'a Self, Output = Self> where Self: 'a

SelfRef<'a> should almost always be &'a Self. This is a way to include implementations of binary operations where both sides are &'a Self.

Required Methods§

Source

fn from_repr(repr: Self::Repr) -> Self

Creates a new IntMod from an instance of Repr. Does not enforce the integer value of bytes must be less than the modulus.

Source

fn from_le_bytes(bytes: &[u8]) -> Option<Self>

Creates a new IntMod from an array of bytes, little endian. Returns None if the integer value of bytes is greater than or equal to the modulus.

Source

fn from_be_bytes(bytes: &[u8]) -> Option<Self>

Creates a new IntMod from an array of bytes, big endian. Returns None if the integer value of bytes is greater than or equal to the modulus.

Source

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

Creates a new IntMod from an array of bytes, little endian. Does not enforce the integer value of bytes must be less than the modulus.

Source

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

Creates a new IntMod from an array of bytes, big endian. Does not enforce the integer value of bytes must be less than the modulus.

Source

fn from_u8(val: u8) -> Self

Creates a new IntMod from a u8. Does not enforce the integer value of bytes must be less than the modulus.

Source

fn from_u32(val: u32) -> Self

Creates a new IntMod from a u32. Does not enforce the integer value of bytes must be less than the modulus.

Source

fn from_u64(val: u64) -> Self

Creates a new IntMod from a u64. Does not enforce the integer value of bytes must be less than the modulus.

Source

fn as_le_bytes(&self) -> &[u8]

Value of this IntMod as an array of bytes, little endian.

Source

fn to_be_bytes(&self) -> Self::Repr

Value of this IntMod as an array of bytes, big endian.

Source

fn modulus_biguint() -> BigUint

Modulus N as a BigUint.

Source

fn from_biguint(biguint: BigUint) -> Self

Creates a new IntMod from a BigUint.

Source

fn as_biguint(&self) -> BigUint

Value of this IntMod as a BigUint.

Source

fn neg_assign(&mut self)

Source

fn double_assign(&mut self)

Doubles self in-place.

Source

fn square_assign(&mut self)

Squares self in-place.

Source

fn assert_reduced(&self)

VM specific concept: during guest execution, it is not enforced that the representation of Self must be the unique integer less than the modulus. The guest code may sometimes want to enforce that the representation is the canonical one less than the modulus. the host to an honest host to provide the canonical representation less than the modulus.

This function should enforce that guest execution proceeds if and only if self is in the unique representation less than the modulus.

Source

fn is_reduced(&self) -> bool

Is the integer representation of self less than the modulus?

Source

fn set_up_once()

Calls any setup required for this modulus. The implementation should internally use OnceBool to ensure that setup is only called once.

Source

unsafe fn eq_impl<const CHECK_SETUP: bool>(&self, other: &Self) -> bool

Returns whether the two integers are congrument modulo the modulus.

§Safety
  • If CHECK_SETUP is true, checks if setup has been called for this curve and if not, calls Self::set_up_once(). Only set CHECK_SETUP to false if you are sure that setup has been called already.
Source

unsafe fn add_ref<const CHECK_SETUP: bool>(&self, other: &Self) -> Self

Add two elements.

§Safety
  • If CHECK_SETUP is true, checks if setup has been called for this curve and if not, calls Self::set_up_once(). Only set CHECK_SETUP to false if you are sure that setup has been called already.

Provided Methods§

Source

fn double(&self) -> Self

Doubles this IntMod.

Source

fn square(&self) -> Self

Squares this IntMod.

Source

fn cube(&self) -> Self

Cubes this IntMod.

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.

Implementors§