Struct openssl::bn::BigNum  
                   
                       [−]
                   
               [src]
pub struct BigNum(_);
Methods
impl BigNum[src]
fn new() -> Result<BigNum, ErrorStack>
Creates a new BigNum with the value 0.
fn from_u32(n: u32) -> Result<BigNum, ErrorStack>
Creates a new BigNum with the given value.
fn from_dec_str(s: &str) -> Result<BigNum, ErrorStack>
Creates a BigNum from a decimal string.
fn from_hex_str(s: &str) -> Result<BigNum, ErrorStack>
Creates a BigNum from a hexadecimal string.
fn get_rfc2409_prime_768() -> Result<BigNum, ErrorStack>
fn get_rfc2409_prime_1024() -> Result<BigNum, ErrorStack>
fn get_rfc3526_prime_1536() -> Result<BigNum, ErrorStack>
fn get_rfc3526_prime_2048() -> Result<BigNum, ErrorStack>
fn get_rfc3526_prime_3072() -> Result<BigNum, ErrorStack>
fn get_rfc3526_prime_4096() -> Result<BigNum, ErrorStack>
fn get_rfc3526_prime_6144() -> Result<BigNum, ErrorStack>
fn get_rfc3526_prime_8192() -> Result<BigNum, ErrorStack>
fn from_slice(n: &[u8]) -> Result<BigNum, ErrorStack>
Creates a new BigNum from an unsigned, big-endian encoded number of arbitrary length.
let bignum = BigNum::from_slice(&[0x12, 0x00, 0x34]).unwrap(); assert_eq!(bignum, BigNum::from_u32(0x120034).unwrap());
Methods from Deref<Target=BigNumRef>
fn clear(&mut self)
Erases the memory used by this BigNum, resetting its value to 0.
This can be used to destroy sensitive data such as keys when they are no longer needed.
fn add_word(&mut self, w: u32) -> Result<(), ErrorStack>
Adds a u32 to self.
fn sub_word(&mut self, w: u32) -> Result<(), ErrorStack>
Subtracts a u32 from self.
fn mul_word(&mut self, w: u32) -> Result<(), ErrorStack>
Multiplies a u32 by self.
fn div_word(&mut self, w: u32) -> Result<u64, ErrorStack>
Divides self by a u32, returning the remainder.
fn mod_word(&self, w: u32) -> Result<u64, ErrorStack>
Returns the result of self modulo w.
fn rand_range(&self, rnd: &mut BigNumRef) -> Result<(), ErrorStack>
Places a cryptographically-secure pseudo-random number nonnegative
number less than self in rnd.
fn pseudo_rand_range(&self, rnd: &mut BigNumRef) -> Result<(), ErrorStack>
The cryptographically weak counterpart to rand_in_range.
fn set_bit(&mut self, n: i32) -> Result<(), ErrorStack>
Sets bit n. Equivalent to self |= (1 << n).
When setting a bit outside of self, it is expanded.
fn clear_bit(&mut self, n: i32) -> Result<(), ErrorStack>
Clears bit n, setting it to 0. Equivalent to self &= ~(1 << n).
When clearing a bit outside of self, an error is returned.
fn is_bit_set(&self, n: i32) -> bool
Returns true if the nth bit of self is set to 1, false otherwise.
fn mask_bits(&mut self, n: i32) -> Result<(), ErrorStack>
Truncates self to the lowest n bits.
An error occurs if self is already shorter than n bits.
fn lshift1(&mut self, a: &BigNumRef) -> Result<(), ErrorStack>
Places a << 1 in self.
fn rshift1(&mut self, a: &BigNumRef) -> Result<(), ErrorStack>
Places a >> 1 in self.
fn checked_add(&mut self,
               a: &BigNumRef,
               b: &BigNumRef)
               -> Result<(), ErrorStack>
a: &BigNumRef,
b: &BigNumRef)
-> Result<(), ErrorStack>
Places a + b in self.
fn checked_sub(&mut self,
               a: &BigNumRef,
               b: &BigNumRef)
               -> Result<(), ErrorStack>
a: &BigNumRef,
b: &BigNumRef)
-> Result<(), ErrorStack>
Places a - b in self.
fn lshift(&mut self, a: &BigNumRef, n: i32) -> Result<(), ErrorStack>
Places a << n in self.
fn rshift(&mut self, a: &BigNumRef, n: i32) -> Result<(), ErrorStack>
Places a >> n in self.
fn to_owned(&self) -> Result<BigNum, ErrorStack>
fn set_negative(&mut self, negative: bool)
Sets the sign of self.
fn ucmp(&self, oth: &BigNumRef) -> Ordering
Compare the absolute values of self and oth.
let s = -BigNum::from_u32(8).unwrap(); let o = BigNum::from_u32(8).unwrap(); assert_eq!(s.ucmp(&o), Ordering::Equal);
fn is_negative(&self) -> bool
fn num_bits(&self) -> i32
Returns the number of significant bits in self.
fn num_bytes(&self) -> i32
Returns the size of self in bytes.
fn rand(&mut self,
        bits: i32,
        msb: MsbOption,
        odd: bool)
        -> Result<(), ErrorStack>
bits: i32,
msb: MsbOption,
odd: bool)
-> Result<(), ErrorStack>
Generates a cryptographically strong pseudo-random BigNum, placing it in self.
Parameters
- bits: Length of the number in bits.
- msb: The desired properties of the number.
- odd: If- true, the generated number will be odd.
fn pseudo_rand(&mut self,
               bits: i32,
               msb: MsbOption,
               odd: bool)
               -> Result<(), ErrorStack>
bits: i32,
msb: MsbOption,
odd: bool)
-> Result<(), ErrorStack>
The cryptographically weak counterpart to rand.
fn generate_prime(&mut self,
                  bits: i32,
                  safe: bool,
                  add: Option<&BigNumRef>,
                  rem: Option<&BigNumRef>)
                  -> Result<(), ErrorStack>
bits: i32,
safe: bool,
add: Option<&BigNumRef>,
rem: Option<&BigNumRef>)
-> Result<(), ErrorStack>
Generates a prime number, placing it in self.
Parameters
- bits: The length of the prime in bits (lower bound).
- safe: If true, returns a "safe" prime- pso that- (p-1)/2is also prime.
- add/- rem: If- addis set to- Some(add),- p % add == remwill hold, where- pis the generated prime and- remis- 1if not specified (- None).
fn checked_mul(&mut self,
               a: &BigNumRef,
               b: &BigNumRef,
               ctx: &mut BigNumContextRef)
               -> Result<(), ErrorStack>
a: &BigNumRef,
b: &BigNumRef,
ctx: &mut BigNumContextRef)
-> Result<(), ErrorStack>
Places the result of a * b in self.
fn checked_div(&mut self,
               a: &BigNumRef,
               b: &BigNumRef,
               ctx: &mut BigNumContextRef)
               -> Result<(), ErrorStack>
a: &BigNumRef,
b: &BigNumRef,
ctx: &mut BigNumContextRef)
-> Result<(), ErrorStack>
Places the result of a / b in self.
fn checked_rem(&mut self,
               a: &BigNumRef,
               b: &BigNumRef,
               ctx: &mut BigNumContextRef)
               -> Result<(), ErrorStack>
a: &BigNumRef,
b: &BigNumRef,
ctx: &mut BigNumContextRef)
-> Result<(), ErrorStack>
Places the result of a % b in self.
fn div_rem(&mut self,
           rem: &mut BigNumRef,
           a: &BigNumRef,
           b: &BigNumRef,
           ctx: &mut BigNumContextRef)
           -> Result<(), ErrorStack>
rem: &mut BigNumRef,
a: &BigNumRef,
b: &BigNumRef,
ctx: &mut BigNumContextRef)
-> Result<(), ErrorStack>
Places the result of a / b in self and a % b in rem.
fn sqr(&mut self,
       a: &BigNumRef,
       ctx: &mut BigNumContextRef)
       -> Result<(), ErrorStack>
a: &BigNumRef,
ctx: &mut BigNumContextRef)
-> Result<(), ErrorStack>
Places the result of a² in self.
fn nnmod(&mut self,
         a: &BigNumRef,
         m: &BigNumRef,
         ctx: &mut BigNumContextRef)
         -> Result<(), ErrorStack>
a: &BigNumRef,
m: &BigNumRef,
ctx: &mut BigNumContextRef)
-> Result<(), ErrorStack>
Places the result of a mod m in self.
fn mod_add(&mut self,
           a: &BigNumRef,
           b: &BigNumRef,
           m: &BigNumRef,
           ctx: &mut BigNumContextRef)
           -> Result<(), ErrorStack>
a: &BigNumRef,
b: &BigNumRef,
m: &BigNumRef,
ctx: &mut BigNumContextRef)
-> Result<(), ErrorStack>
Places the result of (a + b) mod m in self.
fn mod_sub(&mut self,
           a: &BigNumRef,
           b: &BigNumRef,
           m: &BigNumRef,
           ctx: &mut BigNumContextRef)
           -> Result<(), ErrorStack>
a: &BigNumRef,
b: &BigNumRef,
m: &BigNumRef,
ctx: &mut BigNumContextRef)
-> Result<(), ErrorStack>
Places the result of (a - b) mod m in self.
fn mod_mul(&mut self,
           a: &BigNumRef,
           b: &BigNumRef,
           m: &BigNumRef,
           ctx: &mut BigNumContextRef)
           -> Result<(), ErrorStack>
a: &BigNumRef,
b: &BigNumRef,
m: &BigNumRef,
ctx: &mut BigNumContextRef)
-> Result<(), ErrorStack>
Places the result of (a * b) mod m in self.
fn mod_sqr(&mut self,
           a: &BigNumRef,
           m: &BigNumRef,
           ctx: &mut BigNumContextRef)
           -> Result<(), ErrorStack>
a: &BigNumRef,
m: &BigNumRef,
ctx: &mut BigNumContextRef)
-> Result<(), ErrorStack>
Places the result of a² mod m in self.
fn exp(&mut self,
       a: &BigNumRef,
       p: &BigNumRef,
       ctx: &mut BigNumContextRef)
       -> Result<(), ErrorStack>
a: &BigNumRef,
p: &BigNumRef,
ctx: &mut BigNumContextRef)
-> Result<(), ErrorStack>
Places the result of a^p in self.
fn mod_exp(&mut self,
           a: &BigNumRef,
           p: &BigNumRef,
           m: &BigNumRef,
           ctx: &mut BigNumContextRef)
           -> Result<(), ErrorStack>
a: &BigNumRef,
p: &BigNumRef,
m: &BigNumRef,
ctx: &mut BigNumContextRef)
-> Result<(), ErrorStack>
Places the result of a^p mod m in self.
fn mod_inverse(&mut self,
               a: &BigNumRef,
               n: &BigNumRef,
               ctx: &mut BigNumContextRef)
               -> Result<(), ErrorStack>
a: &BigNumRef,
n: &BigNumRef,
ctx: &mut BigNumContextRef)
-> Result<(), ErrorStack>
Places the inverse of a modulo n in self.
fn gcd(&mut self,
       a: &BigNumRef,
       b: &BigNumRef,
       ctx: &mut BigNumContextRef)
       -> Result<(), ErrorStack>
a: &BigNumRef,
b: &BigNumRef,
ctx: &mut BigNumContextRef)
-> Result<(), ErrorStack>
Places the greatest common denominator of a and b in self.
fn is_prime(&self,
            checks: i32,
            ctx: &mut BigNumContextRef)
            -> Result<bool, ErrorStack>
checks: i32,
ctx: &mut BigNumContextRef)
-> Result<bool, ErrorStack>
Checks whether self is prime.
Performs a Miller-Rabin probabilistic primality test with checks iterations.
Returns true if self is prime with an error probability of less than 0.25 ^ checks.
fn is_prime_fasttest(&self,
                     checks: i32,
                     ctx: &mut BigNumContextRef,
                     do_trial_division: bool)
                     -> Result<bool, ErrorStack>
checks: i32,
ctx: &mut BigNumContextRef,
do_trial_division: bool)
-> Result<bool, ErrorStack>
Checks whether self is prime with optional trial division.
If do_trial_division is true, first performs trial division by a number of small primes.
Then, like is_prime, performs a Miller-Rabin probabilistic primality test with checks
iterations.
Return Value
Returns true if self is prime with an error probability of less than 0.25 ^ checks.
fn to_vec(&self) -> Vec<u8>
Returns a big-endian byte vector representation of the absolute value of self.
self can be recreated by using new_from_slice.
let s = -BigNum::from_u32(4543).unwrap(); let r = BigNum::from_u32(4543).unwrap(); let s_vec = s.to_vec(); assert_eq!(BigNum::from_slice(&s_vec).unwrap(), r);
fn to_dec_str(&self) -> Result<CryptoString, ErrorStack>
Returns a decimal string representation of self.
let s = -BigNum::from_u32(12345).unwrap(); assert_eq!(&*s.to_dec_str().unwrap(), "-12345");
fn to_hex_str(&self) -> Result<CryptoString, ErrorStack>
Returns a hexadecimal string representation of self.
let s = -BigNum::from_u32(0x99ff).unwrap(); assert_eq!(&*s.to_hex_str().unwrap(), "-99FF");
Trait Implementations
impl OpenSslType for BigNum[src]
type CType = BIGNUM
The raw C type.
type Ref = BigNumRef
The type representing a reference to this type.
unsafe fn from_ptr(ptr: *mut BIGNUM) -> BigNum
Constructs an instance of this type from its raw type.
impl Drop for BigNum[src]
impl Deref for BigNum[src]
type Target = BigNumRef
The resulting type after dereferencing
fn deref(&self) -> &BigNumRef
The method called to dereference a value
impl DerefMut for BigNum[src]
impl AsRef<BigNumRef> for BigNum[src]
impl Debug for BigNum[src]
impl Display for BigNum[src]
impl PartialEq for BigNum[src]
fn eq(&self, oth: &BigNum) -> bool
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0
This method tests for !=.
impl PartialEq<BigNumRef> for BigNum[src]
fn eq(&self, oth: &BigNumRef) -> bool
This method tests for self and other values to be equal, and is used by ==. Read more
fn ne(&self, other: &Rhs) -> bool1.0.0
This method tests for !=.
impl Eq for BigNum[src]
impl PartialOrd for BigNum[src]
fn partial_cmp(&self, oth: &BigNum) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool1.0.0
This method tests less than (for self and other) and is used by the < operator. Read more
fn le(&self, other: &Rhs) -> bool1.0.0
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
fn gt(&self, other: &Rhs) -> bool1.0.0
This method tests greater than (for self and other) and is used by the > operator. Read more
fn ge(&self, other: &Rhs) -> bool1.0.0
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
impl PartialOrd<BigNumRef> for BigNum[src]
fn partial_cmp(&self, oth: &BigNumRef) -> Option<Ordering>
This method returns an ordering between self and other values if one exists. Read more
fn lt(&self, other: &Rhs) -> bool1.0.0
This method tests less than (for self and other) and is used by the < operator. Read more
fn le(&self, other: &Rhs) -> bool1.0.0
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
fn gt(&self, other: &Rhs) -> bool1.0.0
This method tests greater than (for self and other) and is used by the > operator. Read more
fn ge(&self, other: &Rhs) -> bool1.0.0
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
impl Ord for BigNum[src]
fn cmp(&self, oth: &BigNum) -> Ordering
This method returns an Ordering between self and other. Read more
impl<'a, 'b> Add<&'b BigNumRef> for &'a BigNum[src]
type Output = BigNum
The resulting type after applying the + operator
fn add(self, oth: &BigNumRef) -> BigNum
The method for the + operator
impl<'a, 'b> Add<&'b BigNum> for &'a BigNum[src]
type Output = BigNum
The resulting type after applying the + operator
fn add(self, oth: &BigNum) -> BigNum
The method for the + operator
impl<'a, 'b> Sub<&'b BigNumRef> for &'a BigNum[src]
type Output = BigNum
The resulting type after applying the - operator
fn sub(self, oth: &BigNumRef) -> BigNum
The method for the - operator
impl<'a, 'b> Sub<&'b BigNum> for &'a BigNum[src]
type Output = BigNum
The resulting type after applying the - operator
fn sub(self, oth: &BigNum) -> BigNum
The method for the - operator
impl<'a, 'b> Mul<&'b BigNumRef> for &'a BigNum[src]
type Output = BigNum
The resulting type after applying the * operator
fn mul(self, oth: &BigNumRef) -> BigNum
The method for the * operator
impl<'a, 'b> Mul<&'b BigNum> for &'a BigNum[src]
type Output = BigNum
The resulting type after applying the * operator
fn mul(self, oth: &BigNum) -> BigNum
The method for the * operator
impl<'a, 'b> Div<&'b BigNumRef> for &'a BigNum[src]
type Output = BigNum
The resulting type after applying the / operator
fn div(self, oth: &BigNumRef) -> BigNum
The method for the / operator
impl<'a, 'b> Div<&'b BigNum> for &'a BigNum[src]
type Output = BigNum
The resulting type after applying the / operator
fn div(self, oth: &BigNum) -> BigNum
The method for the / operator
impl<'a, 'b> Rem<&'b BigNumRef> for &'a BigNum[src]
type Output = BigNum
The resulting type after applying the % operator
fn rem(self, oth: &BigNumRef) -> BigNum
The method for the % operator
impl<'a, 'b> Rem<&'b BigNum> for &'a BigNum[src]
type Output = BigNum
The resulting type after applying the % operator
fn rem(self, oth: &BigNum) -> BigNum
The method for the % operator
impl<'a> Shl<i32> for &'a BigNum[src]
type Output = BigNum
The resulting type after applying the << operator
fn shl(self, n: i32) -> BigNum
The method for the << operator
impl<'a> Shr<i32> for &'a BigNum[src]
type Output = BigNum
The resulting type after applying the >> operator
fn shr(self, n: i32) -> BigNum
The method for the >> operator
impl<'a> Neg for &'a BigNum[src]
type Output = BigNum
The resulting type after applying the - operator
fn neg(self) -> BigNum
The method for the unary - operator