BigInt

Struct BigInt 

Source
pub struct BigInt { /* private fields */ }
Expand description

BigInt wrapper around clock-bigint’s U256.

Implementations§

Source§

impl BigInt

Source

pub fn from_limbs(limbs: &[u64; 4]) -> Self

Create a BigInt from u64 limbs (little-endian).

Source

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

Create a BigInt from bytes (little-endian).

Source

pub fn from_u64(value: u64) -> Self

Create a BigInt from a u64 value.

Source

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

Convert to little-endian bytes.

Source

pub fn limbs(&self) -> [u64; 4]

Get the limbs (little-endian).

Source

pub fn add(&self, rhs: &Self) -> Self

Constant-time addition.

Source

pub fn sub(&self, rhs: &Self) -> Self

Constant-time subtraction.

Source

pub fn mul(&self, rhs: &Self) -> Self

Constant-time multiplication with proper overflow handling.

Returns the full 256-bit product. For modular arithmetic, the caller is responsible for reduction if needed.

Source

pub fn mul_wide(&self, rhs: &Self) -> (Self, Self)

Wide multiplication returning the full 512-bit result as (low, high) BigInts.

Source

pub fn div_rem(&self, divisor: &Self) -> (Self, Self)

Division with remainder using binary long division.

Returns (quotient, remainder) where self = quotient * divisor + remainder. This implementation uses binary long division which is much more efficient than repeated subtraction.

Source

pub fn shl(&self, bits: u32) -> Self

Constant-time left shift.

Source

pub fn shr(&self, bits: u32) -> Self

Constant-time right shift.

Source

pub fn cmp(&self, rhs: &Self) -> Ordering

Constant-time comparison.

Source

pub fn is_zero(&self) -> bool

Constant-time zero check.

Source

pub fn get_bit(&self, bit_position: u32) -> u64

Get the bit at the specified position (constant-time).

Returns 1 if the bit is set, 0 otherwise. Bit positions start from 0 (least significant bit).

Source

pub fn bit_length(&self) -> u32

Get the number of bits needed to represent this BigInt.

Returns the position of the highest set bit plus one. Returns 0 for zero.

Trait Implementations§

Source§

impl BigIntOps for BigInt

Source§

fn add(&self, rhs: &Self) -> Self

Constant-time addition.
Source§

fn sub(&self, rhs: &Self) -> Self

Constant-time subtraction.
Source§

fn mul(&self, rhs: &Self) -> Self

Constant-time multiplication. Read more
Source§

fn mul_wide(&self, rhs: &Self) -> (Self, Self)

Wide multiplication returning the full 512-bit result as (low, high) BigInts.
Source§

fn shl(&self, bits: u32) -> Self

Constant-time left shift.
Source§

fn shr(&self, bits: u32) -> Self

Constant-time right shift.
Source§

fn cmp(&self, rhs: &Self) -> Ordering

Constant-time comparison.
Source§

fn is_zero(&self) -> bool

Constant-time zero check.
Source§

fn get_bit(&self, bit_position: u32) -> u64

Get the bit at the specified position (constant-time). Read more
Source§

fn bit_length(&self) -> u32

Get the number of bits needed to represent this BigInt. Read more
Source§

impl Clone for BigInt

Source§

fn clone(&self) -> BigInt

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for BigInt

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BigInt

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl PartialEq for BigInt

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for BigInt

Source§

impl Eq for BigInt

Auto Trait Implementations§

§

impl Freeze for BigInt

§

impl RefUnwindSafe for BigInt

§

impl Send for BigInt

§

impl Sync for BigInt

§

impl Unpin for BigInt

§

impl UnwindSafe for BigInt

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.