Struct botan::MPI[][src]

pub struct MPI { /* fields omitted */ }

A big integer type

Implementations

impl MPI[src]

pub fn new() -> Result<MPI>[src]

Crate a new (zero-valued) MPI

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

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

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

Crate a new MPI setting value from a i32

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

Crate a new MPI setting value from a u32

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

Crate a new MPI duplicating the value of self

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

Set self to value specified with an i32

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

Set self to value specified with a string

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

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

pub fn clear(&self) -> Result<()>[src]

Set self to zero

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

Set a specific bit of self

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

Clear a specific bit of self

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

Return the value of a bit in self

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

Randomize self to an integer of specified bit size

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

Randomize self to an integer within specified range

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

Return value of self as decimal string

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

Return value of self as hex string

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

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

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

Return number of significant bits

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

Return number of significant bytes

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

Return self as a u32, if it fits

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

Return true if self is an integer >= 0

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

Return true if self is an integer < 0

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

Return true if self is an integer == 0

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

Return true if self is odd

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

Return true if self is even

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

Return true if self equals other

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

Compare self with other

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

Flip the sign of self

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

Addition operator

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

Addition operator, assignment version

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

Addition operator

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

Addition operator, assignment version

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

Subtraction operator

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

Subtraction operator, assignment version

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

Subtraction operator

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

Subtraction operator, assignment version

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

Multiplication operator

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

Multiplication operator, assignment version

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

Bitwise left shift

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

Bitwise left shift, assignment version

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

Bitwise right shift

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

Bitwise right shift, assignment version

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

Division/modulo operator

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

Swap two MPI values

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

Perform a primality test on self

Examples

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

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

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());

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

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

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

Return (x^e) mod m

Trait Implementations

impl<'a> Add<&'a MPI> for MPI[src]

type Output = MPI

The resulting type after applying the + operator.

impl<'a, 'b> Add<&'a MPI> for &'b MPI[src]

type Output = MPI

The resulting type after applying the + operator.

impl Add<u32> for MPI[src]

type Output = MPI

The resulting type after applying the + operator.

impl<'a> Add<u32> for &'a MPI[src]

type Output = MPI

The resulting type after applying the + operator.

impl<'a> AddAssign<&'a MPI> for MPI[src]

impl AddAssign<u32> for MPI[src]

impl Clone for MPI[src]

impl Debug for MPI[src]

impl Display for MPI[src]

impl<'a, 'b> Div<&'b MPI> for &'a MPI[src]

type Output = MPI

The resulting type after applying the / operator.

impl<'a> DivAssign<&'a MPI> for MPI[src]

impl Drop for MPI[src]

impl Eq for MPI[src]

impl FromStr for MPI[src]

type Err = Error

The associated error which can be returned from parsing.

impl LowerHex for MPI[src]

impl<'a> Mul<&'a MPI> for MPI[src]

type Output = MPI

The resulting type after applying the * operator.

impl<'a, 'b> Mul<&'a MPI> for &'b MPI[src]

type Output = MPI

The resulting type after applying the * operator.

impl<'a> MulAssign<&'a MPI> for MPI[src]

impl Neg for MPI[src]

type Output = MPI

The resulting type after applying the - operator.

impl Ord for MPI[src]

impl PartialEq<MPI> for MPI[src]

impl PartialOrd<MPI> for MPI[src]

impl<'a, 'b> Rem<&'b MPI> for &'a MPI[src]

type Output = MPI

The resulting type after applying the % operator.

impl<'a> RemAssign<&'a MPI> for MPI[src]

impl<'a> Shl<usize> for &'a MPI[src]

type Output = MPI

The resulting type after applying the << operator.

impl ShlAssign<usize> for MPI[src]

impl<'a> Shr<usize> for &'a MPI[src]

type Output = MPI

The resulting type after applying the >> operator.

impl ShrAssign<usize> for MPI[src]

impl<'a> Sub<&'a MPI> for MPI[src]

type Output = MPI

The resulting type after applying the - operator.

impl<'a, 'b> Sub<&'a MPI> for &'b MPI[src]

type Output = MPI

The resulting type after applying the - operator.

impl Sub<u32> for MPI[src]

type Output = MPI

The resulting type after applying the - operator.

impl<'a> Sub<u32> for &'a MPI[src]

type Output = MPI

The resulting type after applying the - operator.

impl<'a> SubAssign<&'a MPI> for MPI[src]

impl SubAssign<u32> for MPI[src]

impl UpperHex for MPI[src]

Auto Trait Implementations

impl RefUnwindSafe for MPI

impl !Send for MPI

impl !Sync for MPI

impl Unpin for MPI

impl UnwindSafe for MPI

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.