BigInteger

Trait BigInteger 

Source
pub trait BigInteger:
    'static
    + Copy
    + Clone
    + Debug
    + Default
    + Display
    + Eq
    + Ord
    + Send
    + Sized
    + Sync
    + Zeroize
    + From<u128>
    + From<u64>
    + From<u32>
    + From<u16>
    + From<u8>
    + BitXorAssign<Self>
    + for<'a> BitXorAssign<&'a Self>
    + BitXor<Self, Output = Self>
    + for<'a> BitXor<&'a Self, Output = Self>
    + BitAndAssign<Self>
    + for<'a> BitAndAssign<&'a Self>
    + BitAnd<Self, Output = Self>
    + for<'a> BitAnd<&'a Self, Output = Self>
    + BitOrAssign<Self>
    + for<'a> BitOrAssign<&'a Self>
    + BitOr<Self, Output = Self>
    + for<'a> BitOr<&'a Self, Output = Self>
    + Shr<u32, Output = Self>
    + ShrAssign<u32>
    + Shl<u32, Output = Self>
    + ShlAssign<u32>
    + BitIteratorBE {
    const NUM_LIMBS: usize;
    const LIMB_BITS: usize;
    const MAX: Self;
    const ONE: Self;
    const ZERO: Self;
    const BITS: usize = _;
    const BYTES: usize = _;

    // Required methods
    fn is_odd(&self) -> bool;
    fn is_even(&self) -> bool;
    fn is_zero(&self) -> bool;
    fn num_bits(&self) -> usize;
    fn get_bit(&self, i: usize) -> bool;
    fn from_bytes_le(bytes: &[u8]) -> Self;
    fn into_bytes_le(self) -> Vec<u8> ;
}
Expand description

Defines a big integer with a constant length.

Required Associated Constants§

Source

const NUM_LIMBS: usize

Number of usize limbs representing Self.

Source

const LIMB_BITS: usize

Number of bits in a limb.

Source

const MAX: Self

The largest value that can be represented by this integer type.

Source

const ONE: Self

The multiplicative identity element of Self, 1.

Source

const ZERO: Self

The additive identity element of Self, 0.

Provided Associated Constants§

Source

const BITS: usize = _

Number of bits in the integer.

Source

const BYTES: usize = _

Number of bytes in the integer.

Required Methods§

Source

fn is_odd(&self) -> bool

Returns true if this number is odd.

§Examples
use openzeppelin_crypto::arithmetic::{BigInteger, uint::U64};

let mut one = U64::from(1u64);
assert!(one.is_odd());
Source

fn is_even(&self) -> bool

Returns true if this number is even.

§Examples
use openzeppelin_crypto::arithmetic::{BigInteger, uint::U64};

let mut two = U64::from(2u64);
assert!(two.is_even());
Source

fn is_zero(&self) -> bool

Returns true if this number is zero.

§Examples
use openzeppelin_crypto::arithmetic::{BigInteger, uint::U64};

let mut zero = U64::from(0u64);
assert!(zero.is_zero());
Source

fn num_bits(&self) -> usize

Return the minimum number of bits needed to encode this number.

One bit is necessary to encode zero.

§Examples
use openzeppelin_crypto::arithmetic::{BigInteger, uint::U64};

let zero = U64::from(0u64);
assert_eq!(zero.num_bits(), 1);
let one = U64::from(1u64);
assert_eq!(one.num_bits(), 1);
let max = U64::from(u64::MAX);
assert_eq!(max.num_bits(), 64);
let u32_max = U64::from(u32::MAX as u64);
assert_eq!(u32_max.num_bits(), 32);
Source

fn get_bit(&self, i: usize) -> bool

Find the i-th bit of self.

§Examples
use openzeppelin_crypto::arithmetic::{BigInteger, uint::U64};

let mut one = U64::from(1u64);
assert!(one.get_bit(0));
assert!(!one.get_bit(1));
Source

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

Create bigint from little-endian bytes.

§Panics
  • If the number of bytes is not equal to Self::BYTES.
Source

fn into_bytes_le(self) -> Vec<u8>

Convert bigint to little-endian bytes.

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§

Source§

impl<const N: usize> BigInteger for Uint<N>

Source§

const LIMB_BITS: usize = 64usize

Source§

const MAX: Self

Source§

const NUM_LIMBS: usize = N

Source§

const ONE: Self

Source§

const ZERO: Self