Struct mbedtls::bignum::Mpi

source ·
pub struct Mpi { /* private fields */ }

Implementations§

source§

impl Mpi

source

pub fn new(value: mpi_sint) -> Result<Mpi>

source

pub fn from_binary(num: &[u8]) -> Result<Mpi>

Initialize an MPI number from big endian binary data

source

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

source

pub fn set_bit(&mut self, bit: usize, val: bool) -> Result<()>

source

pub fn less_than_const_time(&self, other: &Mpi) -> Result<bool>

Checks if an Mpi is less than the other in constant time.

Will return Error::MpiBadInputData if the allocated length of the two input Mpis is not the same.

source

pub fn cmp_const_time(&self, other: &Mpi) -> Result<Ordering>

Compares an Mpi with the other in constant time.

Will return Error::MpiBadInputData if the allocated length of the two input Mpis is not the same.

source

pub fn eq_const_time(&self, other: &Mpi) -> Result<bool>

Checks equalness with the other in constant time.

source

pub fn as_u32(&self) -> Result<u32>

source

pub fn sign(&self) -> Sign

source

pub fn to_string_radix(&self, radix: i32) -> Result<String>

source

pub fn to_binary(&self) -> Result<Vec<u8>>

Serialize the MPI as big endian binary data

source

pub fn to_binary_padded(&self, min_len: usize) -> Result<Vec<u8>>

Serialize the MPI as big endian binary data, padding to at least min_len bytes

source

pub fn bit_length(&self) -> Result<usize>

Return size of this MPI in bits

source

pub fn byte_length(&self) -> Result<usize>

Return size of this MPI in bytes (rounded up)

source

pub fn divrem(&self, other: &Mpi) -> Result<(Mpi, Mpi)>

source

pub fn modulo(&self, other: &Mpi) -> Result<Mpi>

Reduce self modulo other

source

pub fn divrem_int(&self, other: mpi_sint) -> Result<(Mpi, Mpi)>

source

pub fn modinv(&self, modulus: &Mpi) -> Result<Mpi>

source

pub fn mod_sqrt(&self, p: &Mpi) -> Result<Mpi>

Returns an integer a such that (a*a) === self (mod p)

The modulus must be prime; computing a square root modulo a composite number is equivalent to factoring the composite.

source

pub fn trailing_zeros(&self) -> usize

source

pub fn jacobi(&self, n: &Mpi) -> Result<i32>

Calculates Jacobi symbol (self|N)

source

pub fn mod_exp(&self, exponent: &Mpi, modulus: &Mpi) -> Result<Mpi>

Return (self^exponent) % n

source

pub fn is_probably_prime<F: Random>(&self, k: u32, rng: &mut F) -> Result<()>

The Miller-Rabin primality test with k rounds. Returns MpiNotAcceptable if self is definitely not prime. If no error is returned, self is prime with a probability of 1 - 1/2^{2k}. See mbedtls_mpi_is_prime.

Trait Implementations§

source§

impl<'a, 'b> Add<&'a Mpi> for &'b Mpi

§

type Output = Result<Mpi, Error>

The resulting type after applying the + operator.
source§

fn add(self, other: &Mpi) -> Result<Mpi>

Performs the + operation. Read more
source§

impl<'a> Add<i64> for &'a Mpi

§

type Output = Result<Mpi, Error>

The resulting type after applying the + operator.
source§

fn add(self, other: mpi_sint) -> Result<Mpi>

Performs the + operation. Read more
source§

impl<'a> AddAssign<&'a Mpi> for Mpi

source§

fn add_assign(&mut self, other: &Mpi)

Performs the += operation. Read more
source§

impl AddAssign<i64> for Mpi

source§

fn add_assign(&mut self, other: mpi_sint)

Performs the += operation. Read more
source§

impl AddAssign for Mpi

source§

fn add_assign(&mut self, other: Mpi)

Performs the += operation. Read more
source§

impl Binary for Mpi

source§

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

Formats the value using the given formatter.
source§

impl Clone for Mpi

source§

fn clone(&self) -> Self

Returns a copy 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 Mpi

source§

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

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

impl Display for Mpi

source§

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

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

impl<'a, 'b> Div<&'b Mpi> for &'a Mpi

§

type Output = Result<Mpi, Error>

The resulting type after applying the / operator.
source§

fn div(self, other: &Mpi) -> Result<Mpi>

Performs the / operation. Read more
source§

impl<'a> Div<Mpi> for &'a Mpi

§

type Output = Result<Mpi, Error>

The resulting type after applying the / operator.
source§

fn div(self, other: Mpi) -> Result<Mpi>

Performs the / operation. Read more
source§

impl<'a> Div<i64> for &'a Mpi

§

type Output = Result<Mpi, Error>

The resulting type after applying the / operator.
source§

fn div(self, other: mpi_sint) -> Result<Mpi>

Performs the / operation. Read more
source§

impl<'a> DivAssign<&'a Mpi> for Mpi

Note this will panic if other == 0

source§

fn div_assign(&mut self, other: &Mpi)

Performs the /= operation. Read more
source§

impl DivAssign<i64> for Mpi

Note this will panic if other == 0

source§

fn div_assign(&mut self, other: mpi_sint)

Performs the /= operation. Read more
source§

impl DivAssign for Mpi

Note this will panic if other == 0

source§

fn div_assign(&mut self, other: Mpi)

Performs the /= operation. Read more
source§

impl Drop for Mpi

source§

fn drop(&mut self)

Executes the destructor for this type. Read more
source§

impl FromStr for Mpi

§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Mpi>

Parses a string s to return a value of this type. Read more
source§

impl<'a> Into<*const mpi> for &'a Mpi

source§

fn into(self) -> *const mpi

Converts this type into the (usually inferred) input type.
source§

impl<'a> Into<*mut mpi> for &'a mut Mpi

source§

fn into(self) -> *mut mpi

Converts this type into the (usually inferred) input type.
source§

impl<'a, 'b> Mul<&'a Mpi> for &'b Mpi

§

type Output = Result<Mpi, Error>

The resulting type after applying the * operator.
source§

fn mul(self, other: &Mpi) -> Result<Mpi>

Performs the * operation. Read more
source§

impl<'a> Mul<i64> for &'a Mpi

§

type Output = Result<Mpi, Error>

The resulting type after applying the * operator.
source§

fn mul(self, other: mpi_sint) -> Result<Mpi>

Performs the * operation. Read more
source§

impl<'a> MulAssign<&'a Mpi> for Mpi

source§

fn mul_assign(&mut self, other: &Mpi)

Performs the *= operation. Read more
source§

impl MulAssign<i64> for Mpi

source§

fn mul_assign(&mut self, other: mpi_sint)

Performs the *= operation. Read more
source§

impl MulAssign for Mpi

source§

fn mul_assign(&mut self, other: Mpi)

Performs the *= operation. Read more
source§

impl Octal for Mpi

source§

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

Formats the value using the given formatter.
source§

impl Ord for Mpi

source§

fn cmp(&self, other: &Mpi) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Mpi

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Mpi

source§

fn partial_cmp(&self, other: &Mpi) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

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

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

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

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

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

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<'a, 'b> Rem<&'b Mpi> for &'a Mpi

§

type Output = Result<Mpi, Error>

The resulting type after applying the % operator.
source§

fn rem(self, other: &Mpi) -> Result<Mpi>

Performs the % operation. Read more
source§

impl<'a> Rem<Mpi> for &'a Mpi

§

type Output = Result<Mpi, Error>

The resulting type after applying the % operator.
source§

fn rem(self, other: Mpi) -> Result<Mpi>

Performs the % operation. Read more
source§

impl<'a> Rem<i64> for &'a Mpi

§

type Output = Result<Mpi, Error>

The resulting type after applying the % operator.
source§

fn rem(self, other: mpi_sint) -> Result<Mpi>

Performs the % operation. Read more
source§

impl Rem<i64> for Mpi

§

type Output = Result<Mpi, Error>

The resulting type after applying the % operator.
source§

fn rem(self, other: mpi_sint) -> Result<Mpi>

Performs the % operation. Read more
source§

impl<'a> RemAssign<&'a Mpi> for Mpi

Note this will panic if other == 0

source§

fn rem_assign(&mut self, other: &Mpi)

Performs the %= operation. Read more
source§

impl RemAssign<i64> for Mpi

Note this will panic if other == 0

source§

fn rem_assign(&mut self, other: mpi_sint)

Performs the %= operation. Read more
source§

impl RemAssign for Mpi

Note this will panic if other == 0

source§

fn rem_assign(&mut self, other: Mpi)

Performs the %= operation. Read more
source§

impl<'a> Shl<usize> for &'a Mpi

§

type Output = Result<Mpi, Error>

The resulting type after applying the << operator.
source§

fn shl(self, shift: usize) -> Result<Mpi>

Performs the << operation. Read more
source§

impl Shl<usize> for Mpi

§

type Output = Result<Mpi, Error>

The resulting type after applying the << operator.
source§

fn shl(self, shift: usize) -> Result<Mpi>

Performs the << operation. Read more
source§

impl ShlAssign<usize> for Mpi

source§

fn shl_assign(&mut self, shift: usize)

Performs the <<= operation. Read more
source§

impl<'a> Shr<usize> for &'a Mpi

§

type Output = Result<Mpi, Error>

The resulting type after applying the >> operator.
source§

fn shr(self, shift: usize) -> Result<Mpi>

Performs the >> operation. Read more
source§

impl Shr<usize> for Mpi

§

type Output = Result<Mpi, Error>

The resulting type after applying the >> operator.
source§

fn shr(self, shift: usize) -> Result<Mpi>

Performs the >> operation. Read more
source§

impl ShrAssign<usize> for Mpi

source§

fn shr_assign(&mut self, shift: usize)

Performs the >>= operation. Read more
source§

impl<'a, 'b> Sub<&'a Mpi> for &'b Mpi

§

type Output = Result<Mpi, Error>

The resulting type after applying the - operator.
source§

fn sub(self, other: &Mpi) -> Result<Mpi>

Performs the - operation. Read more
source§

impl<'a> Sub<i64> for &'a Mpi

§

type Output = Result<Mpi, Error>

The resulting type after applying the - operator.
source§

fn sub(self, other: mpi_sint) -> Result<Mpi>

Performs the - operation. Read more
source§

impl<'a> SubAssign<&'a Mpi> for Mpi

source§

fn sub_assign(&mut self, other: &Mpi)

Performs the -= operation. Read more
source§

impl SubAssign<i64> for Mpi

source§

fn sub_assign(&mut self, other: mpi_sint)

Performs the -= operation. Read more
source§

impl SubAssign for Mpi

source§

fn sub_assign(&mut self, other: Mpi)

Performs the -= operation. Read more
source§

impl UpperHex for Mpi

source§

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

Formats the value using the given formatter.
source§

impl Eq for Mpi

source§

impl Send for Mpi

Auto Trait Implementations§

§

impl RefUnwindSafe for Mpi

§

impl !Sync for Mpi

§

impl Unpin for Mpi

§

impl UnwindSafe for Mpi

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> 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,

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.