Struct MPI

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

A big integer type

Implementations§

Source§

impl MPI

Source

pub fn new() -> Result<MPI>

Crate a new (zero-valued) MPI

Source

pub fn new_from_bytes(val: &[u8]) -> Result<MPI>

Crate a new MPI setting value from an array of bytes (big-endian)

Source

pub fn new_from_i32(val: i32) -> Result<MPI>

Crate a new MPI setting value from a i32

Source

pub fn new_from_u32(val: u32) -> Result<MPI>

Crate a new MPI setting value from a u32

Source

pub fn duplicate(&self) -> Result<MPI>

Crate a new MPI duplicating the value of self

Source

pub fn set_i32(&mut self, val: i32) -> Result<()>

Set self to value specified with an i32

Source

pub fn set_str(&mut self, val: &str) -> Result<()>

Set self to value specified with a string

Source

pub fn set_bytes(&mut self, val: &[u8]) -> Result<()>

Set self to value specified with an array of bytes (big-endian)

Source

pub fn clear(&mut self) -> Result<()>

Set self to zero

Source

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

Set a specific bit of self

Source

pub fn clear_bit(&mut self, bit: usize) -> Result<()>

Clear a specific bit of self

Source

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

Return the value of a bit in self

Source

pub fn randomize( &mut self, rng: &mut RandomNumberGenerator, bits: usize, ) -> Result<()>

Randomize self to an integer of specified bit size

Source

pub fn random_range( &mut self, rng: &mut RandomNumberGenerator, lower: &MPI, upper: &MPI, ) -> Result<()>

Randomize self to an integer within specified range

Source

pub fn to_string(&self) -> Result<String>

Return value of self as decimal string

Source

pub fn to_hex(&self) -> Result<String>

Return value of self as hex string

Source

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

Return value of self as a byte array (big endian)

Source

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

Return number of significant bits

Source

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

Return number of significant bytes

Source

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

Return self as a u32, if it fits

Source

pub fn is_positive(&self) -> Result<bool>

Return true if self is an integer >= 0

Source

pub fn is_negative(&self) -> Result<bool>

Return true if self is an integer < 0

Source

pub fn is_zero(&self) -> Result<bool>

Return true if self is an integer == 0

Source

pub fn is_odd(&self) -> Result<bool>

Return true if self is odd

Source

pub fn is_even(&self) -> Result<bool>

Return true if self is even

Source

pub fn equals(&self, other: &MPI) -> Result<bool>

Return true if self equals other

Source

pub fn compare(&self, other: &MPI) -> Result<Ordering>

Compare self with other

Source

pub fn flip_sign(&mut self) -> Result<()>

Flip the sign of self

Source

pub fn mp_add(&self, other: &MPI) -> Result<MPI>

Addition operator

Source

pub fn mp_add_assign(&mut self, other: &MPI) -> Result<()>

Addition operator, assignment version

Source

pub fn mp_add_u32(&self, other: u32) -> Result<MPI>

Addition operator

Source

pub fn mp_add_u32_assign(&mut self, other: u32) -> Result<()>

Addition operator, assignment version

Source

pub fn mp_sub(&self, other: &MPI) -> Result<MPI>

Subtraction operator

Source

pub fn mp_sub_assign(&mut self, other: &MPI) -> Result<()>

Subtraction operator, assignment version

Source

pub fn mp_sub_u32(&self, other: u32) -> Result<MPI>

Subtraction operator

Source

pub fn mp_sub_u32_assign(&mut self, other: u32) -> Result<()>

Subtraction operator, assignment version

Source

pub fn mp_mul(&self, other: &MPI) -> Result<MPI>

Multiplication operator

Source

pub fn mp_mul_assign(&mut self, other: &MPI) -> Result<()>

Multiplication operator, assignment version

Source

pub fn mp_shl(&self, shift: usize) -> Result<MPI>

Bitwise left shift

Source

pub fn mp_shl_assign(&mut self, shift: usize) -> Result<()>

Bitwise left shift, assignment version

Source

pub fn mp_shr(&self, shift: usize) -> Result<MPI>

Bitwise right shift

Source

pub fn mp_shr_assign(&mut self, shift: usize) -> Result<()>

Bitwise right shift, assignment version

Source

pub fn divrem(&self, z: &MPI) -> Result<(MPI, MPI)>

Division/modulo operator

Source

pub fn swap(&mut self, other: &mut MPI) -> Result<()>

Swap two MPI values

Source

pub fn is_prime( &self, rng: &mut RandomNumberGenerator, test_prob: usize, ) -> Result<bool>

Perform a primality test on self

§Examples
use core::str::FromStr;
let n = botan::MPI::from_str("1111111111111111111").unwrap();
let mut rng = botan::RandomNumberGenerator::new_system().unwrap();
assert!(n.is_prime(&mut rng, 128).unwrap());
Source

pub fn gcd(x: &MPI, y: &MPI) -> Result<MPI>

Return the greatest common divisor of x and y

§Examples
use core::str::FromStr;
let x = botan::MPI::from_str("1111111111111111").unwrap();
let y = botan::MPI::from_str("111111111111").unwrap();
assert_eq!(botan::MPI::gcd(&x, &y).unwrap(), botan::MPI::from_str("1111").unwrap());
Source

pub fn modular_inverse(x: &MPI, m: &MPI) -> Result<MPI>

Return the inverse of x modulo m, or 0 if gcd(x,m) > 1

Source

pub fn powmod(x: &MPI, e: &MPI, m: &MPI) -> Result<MPI>

Return (x^e) mod m

Trait Implementations§

Source§

impl Add<&MPI> for &MPI

Source§

type Output = MPI

The resulting type after applying the + operator.
Source§

fn add(self, other: &MPI) -> MPI

Performs the + operation. Read more
Source§

impl Add<&MPI> for MPI

Source§

type Output = MPI

The resulting type after applying the + operator.
Source§

fn add(self, other: &MPI) -> MPI

Performs the + operation. Read more
Source§

impl Add<u32> for &MPI

Source§

type Output = MPI

The resulting type after applying the + operator.
Source§

fn add(self, other: u32) -> MPI

Performs the + operation. Read more
Source§

impl Add<u32> for MPI

Source§

type Output = MPI

The resulting type after applying the + operator.
Source§

fn add(self, other: u32) -> MPI

Performs the + operation. Read more
Source§

impl AddAssign<&MPI> for MPI

Source§

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

Performs the += operation. Read more
Source§

impl AddAssign<u32> for MPI

Source§

fn add_assign(&mut self, other: u32)

Performs the += operation. Read more
Source§

impl Clone for MPI

Source§

fn clone(&self) -> MPI

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 MPI

Source§

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

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

impl Display for MPI

Source§

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

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

impl Div<&MPI> for &MPI

Source§

type Output = MPI

The resulting type after applying the / operator.
Source§

fn div(self, other: &MPI) -> MPI

Performs the / operation. Read more
Source§

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

Source§

fn div_assign(&mut self, other: &'a 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

Source§

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 LowerHex for MPI

Source§

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

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

impl Mul<&MPI> for &MPI

Source§

type Output = MPI

The resulting type after applying the * operator.
Source§

fn mul(self, other: &MPI) -> MPI

Performs the * operation. Read more
Source§

impl Mul<&MPI> for MPI

Source§

type Output = MPI

The resulting type after applying the * operator.
Source§

fn mul(self, other: &MPI) -> MPI

Performs the * operation. Read more
Source§

impl MulAssign<&MPI> for MPI

Source§

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

Performs the *= operation. Read more
Source§

impl Neg for MPI

Source§

type Output = MPI

The resulting type after applying the - operator.
Source§

fn neg(self) -> MPI

Performs the unary - operation. Read more
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,

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

impl PartialEq for MPI

Source§

fn eq(&self, other: &MPI) -> 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 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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Rem<&MPI> for &MPI

Source§

type Output = MPI

The resulting type after applying the % operator.
Source§

fn rem(self, other: &MPI) -> MPI

Performs the % operation. Read more
Source§

impl RemAssign<&MPI> for MPI

Source§

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

Performs the %= operation. Read more
Source§

impl Shl<usize> for &MPI

Source§

type Output = MPI

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

fn shl(self, shift: usize) -> 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 Shr<usize> for &MPI

Source§

type Output = MPI

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

fn shr(self, shift: usize) -> 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 Sub<&MPI> for &MPI

Source§

type Output = MPI

The resulting type after applying the - operator.
Source§

fn sub(self, other: &MPI) -> MPI

Performs the - operation. Read more
Source§

impl Sub<&MPI> for MPI

Source§

type Output = MPI

The resulting type after applying the - operator.
Source§

fn sub(self, other: &MPI) -> MPI

Performs the - operation. Read more
Source§

impl Sub<u32> for &MPI

Source§

type Output = MPI

The resulting type after applying the - operator.
Source§

fn sub(self, other: u32) -> MPI

Performs the - operation. Read more
Source§

impl Sub<u32> for MPI

Source§

type Output = MPI

The resulting type after applying the - operator.
Source§

fn sub(self, other: u32) -> MPI

Performs the - operation. Read more
Source§

impl SubAssign<&MPI> for MPI

Source§

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

Performs the -= operation. Read more
Source§

impl SubAssign<u32> for MPI

Source§

fn sub_assign(&mut self, other: u32)

Performs the -= operation. Read more
Source§

impl UpperHex for MPI

Source§

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

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

impl Eq for MPI

Source§

impl Send for MPI

Source§

impl Sync for MPI

Auto Trait Implementations§

§

impl Freeze for MPI

§

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

Source§

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

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.