Struct openssl::bn::BigNum [−][src]
pub struct BigNum(_);
A signed arbitrary-precision integer.
BigNum
provides wrappers around OpenSSL's checked arithmetic functions. Additionally, it
implements the standard operators (std::ops
), which perform unchecked arithmetic, unwrapping
the returned Result
of the checked operations.
Methods
impl BigNum
[src]
impl BigNum
pub fn new() -> Result<BigNum, SslError>
[src]
pub fn new() -> Result<BigNum, SslError>
Creates a new BigNum
with the value 0.
pub fn new_from(n: u64) -> Result<BigNum, SslError>
[src]
pub fn new_from(n: u64) -> Result<BigNum, SslError>
Creates a new BigNum
with the given value.
pub fn from_dec_str(s: &str) -> Result<BigNum, SslError>
[src]
pub fn from_dec_str(s: &str) -> Result<BigNum, SslError>
Creates a BigNum
from a decimal string.
pub fn from_hex_str(s: &str) -> Result<BigNum, SslError>
[src]
pub fn from_hex_str(s: &str) -> Result<BigNum, SslError>
Creates a BigNum
from a hexadecimal string.
pub unsafe fn new_from_ffi(orig: *mut BIGNUM) -> Result<BigNum, SslError>
[src]
pub unsafe fn new_from_ffi(orig: *mut BIGNUM) -> Result<BigNum, SslError>
pub fn new_from_slice(n: &[u8]) -> Result<BigNum, SslError>
[src]
pub fn new_from_slice(n: &[u8]) -> Result<BigNum, SslError>
Creates a new BigNum
from an unsigned, big-endian encoded number of arbitrary length.
let bignum = BigNum::new_from_slice(&[0x12, 0x00, 0x34]).unwrap(); assert_eq!(bignum, BigNum::new_from(0x120034).unwrap());
pub fn checked_sqr(&self) -> Result<BigNum, SslError>
[src]
pub fn checked_sqr(&self) -> Result<BigNum, SslError>
Returns the square of self
.
let ref n = BigNum::new_from(10).unwrap(); let squared = BigNum::new_from(100).unwrap(); assert_eq!(n.checked_sqr().unwrap(), squared); assert_eq!(n * n, squared);
pub fn checked_nnmod(&self, n: &BigNum) -> Result<BigNum, SslError>
[src]
pub fn checked_nnmod(&self, n: &BigNum) -> Result<BigNum, SslError>
Returns the unsigned remainder of the division self / n
.
pub fn checked_mod_add(
&self,
a: &BigNum,
n: &BigNum
) -> Result<BigNum, SslError>
[src]
pub fn checked_mod_add(
&self,
a: &BigNum,
n: &BigNum
) -> Result<BigNum, SslError>
Equivalent to (self + a) mod n
.
let ref s = BigNum::new_from(10).unwrap(); let ref a = BigNum::new_from(20).unwrap(); let ref n = BigNum::new_from(29).unwrap(); let result = BigNum::new_from(1).unwrap(); assert_eq!(s.checked_mod_add(a, n).unwrap(), result);
pub fn checked_mod_sub(
&self,
a: &BigNum,
n: &BigNum
) -> Result<BigNum, SslError>
[src]
pub fn checked_mod_sub(
&self,
a: &BigNum,
n: &BigNum
) -> Result<BigNum, SslError>
Equivalent to (self - a) mod n
.
pub fn checked_mod_mul(
&self,
a: &BigNum,
n: &BigNum
) -> Result<BigNum, SslError>
[src]
pub fn checked_mod_mul(
&self,
a: &BigNum,
n: &BigNum
) -> Result<BigNum, SslError>
Equivalent to (self * a) mod n
.
pub fn checked_mod_sqr(&self, n: &BigNum) -> Result<BigNum, SslError>
[src]
pub fn checked_mod_sqr(&self, n: &BigNum) -> Result<BigNum, SslError>
Equivalent to self² mod n
.
pub fn checked_exp(&self, p: &BigNum) -> Result<BigNum, SslError>
[src]
pub fn checked_exp(&self, p: &BigNum) -> Result<BigNum, SslError>
Raises self
to the p
th power.
pub fn checked_mod_exp(
&self,
p: &BigNum,
n: &BigNum
) -> Result<BigNum, SslError>
[src]
pub fn checked_mod_exp(
&self,
p: &BigNum,
n: &BigNum
) -> Result<BigNum, SslError>
Equivalent to self.checked_exp(p) mod n
.
pub fn checked_mod_inv(&self, n: &BigNum) -> Result<BigNum, SslError>
[src]
pub fn checked_mod_inv(&self, n: &BigNum) -> Result<BigNum, SslError>
Calculates the modular multiplicative inverse of self
modulo n
, that is, an integer r
such that (self * r) % n == 1
.
pub fn add_word(&mut self, w: c_ulong) -> Result<(), SslError>
[src]
pub fn add_word(&mut self, w: c_ulong) -> Result<(), SslError>
Add an unsigned long
to self
. This is more efficient than adding a BigNum
.
pub fn sub_word(&mut self, w: c_ulong) -> Result<(), SslError>
[src]
pub fn sub_word(&mut self, w: c_ulong) -> Result<(), SslError>
pub fn mul_word(&mut self, w: c_ulong) -> Result<(), SslError>
[src]
pub fn mul_word(&mut self, w: c_ulong) -> Result<(), SslError>
pub fn div_word(&mut self, w: c_ulong) -> Result<c_ulong, SslError>
[src]
pub fn div_word(&mut self, w: c_ulong) -> Result<c_ulong, SslError>
pub fn mod_word(&self, w: c_ulong) -> Result<c_ulong, SslError>
[src]
pub fn mod_word(&self, w: c_ulong) -> Result<c_ulong, SslError>
pub fn checked_gcd(&self, a: &BigNum) -> Result<BigNum, SslError>
[src]
pub fn checked_gcd(&self, a: &BigNum) -> Result<BigNum, SslError>
Computes the greatest common denominator of self
and a
.
pub fn checked_generate_prime(
bits: i32,
safe: bool,
add: Option<&BigNum>,
rem: Option<&BigNum>
) -> Result<BigNum, SslError>
[src]
pub fn checked_generate_prime(
bits: i32,
safe: bool,
add: Option<&BigNum>,
rem: Option<&BigNum>
) -> Result<BigNum, SslError>
Generates a prime number.
Parameters
bits
: The length of the prime in bits (lower bound).safe
: If true, returns a "safe" primep
so that(p-1)/2
is also prime.add
/rem
: Ifadd
is set toSome(add)
,p % add == rem
will hold, wherep
is the generated prime andrem
is1
if not specified (None
).
pub fn is_prime(&self, checks: i32) -> Result<bool, SslError>
[src]
pub fn is_prime(&self, checks: i32) -> Result<bool, SslError>
Checks whether self
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
.
pub fn is_prime_fast(
&self,
checks: i32,
do_trial_division: bool
) -> Result<bool, SslError>
[src]
pub fn is_prime_fast(
&self,
checks: i32,
do_trial_division: bool
) -> Result<bool, SslError>
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
.
pub fn checked_new_random(
bits: i32,
prop: RNGProperty,
odd: bool
) -> Result<BigNum, SslError>
[src]
pub fn checked_new_random(
bits: i32,
prop: RNGProperty,
odd: bool
) -> Result<BigNum, SslError>
Generates a cryptographically strong pseudo-random BigNum
.
Parameters
bits
: Length of the number in bits.prop
: The desired properties of the number.odd
: Iftrue
, the generated number will be odd.
pub fn checked_new_pseudo_random(
bits: i32,
prop: RNGProperty,
odd: bool
) -> Result<BigNum, SslError>
[src]
pub fn checked_new_pseudo_random(
bits: i32,
prop: RNGProperty,
odd: bool
) -> Result<BigNum, SslError>
The cryptographically weak counterpart to checked_new_random
.
pub fn checked_rand_in_range(&self) -> Result<BigNum, SslError>
[src]
pub fn checked_rand_in_range(&self) -> Result<BigNum, SslError>
Generates a cryptographically strong pseudo-random BigNum
r
in the range
0 <= r < self
.
pub fn checked_pseudo_rand_in_range(&self) -> Result<BigNum, SslError>
[src]
pub fn checked_pseudo_rand_in_range(&self) -> Result<BigNum, SslError>
The cryptographically weak counterpart to checked_rand_in_range
.
pub fn set_bit(&mut self, n: i32) -> Result<(), SslError>
[src]
pub fn set_bit(&mut self, n: i32) -> Result<(), SslError>
Sets bit n
. Equivalent to self |= (1 << n)
.
When setting a bit outside of self
, it is expanded.
pub fn clear_bit(&mut self, n: i32) -> Result<(), SslError>
[src]
pub fn clear_bit(&mut self, n: i32) -> Result<(), SslError>
Clears bit n
, setting it to 0. Equivalent to self &= ~(1 << n)
.
When clearing a bit outside of self
, an error is returned.
pub fn is_bit_set(&self, n: i32) -> bool
[src]
pub fn is_bit_set(&self, n: i32) -> bool
Returns true
if the n
th bit of self
is set to 1, false
otherwise.
pub fn mask_bits(&mut self, n: i32) -> Result<(), SslError>
[src]
pub fn mask_bits(&mut self, n: i32) -> Result<(), SslError>
Truncates self
to the lowest n
bits.
An error occurs if self
is already shorter than n
bits.
pub fn checked_shl1(&self) -> Result<BigNum, SslError>
[src]
pub fn checked_shl1(&self) -> Result<BigNum, SslError>
Returns self
, shifted left by 1 bit. self
may be negative.
let ref s = BigNum::new_from(0b0100).unwrap(); let result = BigNum::new_from(0b1000).unwrap(); assert_eq!(s.checked_shl1().unwrap(), result);
let ref s = -BigNum::new_from(8).unwrap(); let result = -BigNum::new_from(16).unwrap(); // (-8) << 1 == -16 assert_eq!(s.checked_shl1().unwrap(), result);
pub fn checked_shr1(&self) -> Result<BigNum, SslError>
[src]
pub fn checked_shr1(&self) -> Result<BigNum, SslError>
Returns self
, shifted right by 1 bit. self
may be negative.
pub fn checked_add(&self, a: &BigNum) -> Result<BigNum, SslError>
[src]
pub fn checked_add(&self, a: &BigNum) -> Result<BigNum, SslError>
pub fn checked_sub(&self, a: &BigNum) -> Result<BigNum, SslError>
[src]
pub fn checked_sub(&self, a: &BigNum) -> Result<BigNum, SslError>
pub fn checked_mul(&self, a: &BigNum) -> Result<BigNum, SslError>
[src]
pub fn checked_mul(&self, a: &BigNum) -> Result<BigNum, SslError>
pub fn checked_div(&self, a: &BigNum) -> Result<BigNum, SslError>
[src]
pub fn checked_div(&self, a: &BigNum) -> Result<BigNum, SslError>
pub fn checked_mod(&self, a: &BigNum) -> Result<BigNum, SslError>
[src]
pub fn checked_mod(&self, a: &BigNum) -> Result<BigNum, SslError>
pub fn checked_shl(&self, a: &i32) -> Result<BigNum, SslError>
[src]
pub fn checked_shl(&self, a: &i32) -> Result<BigNum, SslError>
pub fn checked_shr(&self, a: &i32) -> Result<BigNum, SslError>
[src]
pub fn checked_shr(&self, a: &i32) -> Result<BigNum, SslError>
pub fn negate(&mut self)
[src]
pub fn negate(&mut self)
Inverts the sign of self
.
let mut s = BigNum::new_from(8).unwrap(); s.negate(); assert_eq!(s, -BigNum::new_from(8).unwrap()); s.negate(); assert_eq!(s, BigNum::new_from(8).unwrap());
pub fn abs_cmp(&self, oth: BigNum) -> Ordering
[src]
pub fn abs_cmp(&self, oth: BigNum) -> Ordering
Compare the absolute values of self
and oth
.
let s = -BigNum::new_from(8).unwrap(); let o = BigNum::new_from(8).unwrap(); assert_eq!(s.abs_cmp(o), Ordering::Equal);
pub fn is_negative(&self) -> bool
[src]
pub fn is_negative(&self) -> bool
pub fn num_bits(&self) -> i32
[src]
pub fn num_bits(&self) -> i32
Returns the number of significant bits in self
.
pub fn num_bytes(&self) -> i32
[src]
pub fn num_bytes(&self) -> i32
Returns the size of self
in bytes.
pub unsafe fn raw(&self) -> *mut BIGNUM
[src]
pub unsafe fn raw(&self) -> *mut BIGNUM
pub unsafe fn raw_ptr(&self) -> *const *mut BIGNUM
[src]
pub unsafe fn raw_ptr(&self) -> *const *mut BIGNUM
pub fn into_raw(self) -> *mut BIGNUM
[src]
pub fn into_raw(self) -> *mut BIGNUM
pub fn to_vec(&self) -> Vec<u8>
[src]
pub 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::new_from(4543).unwrap(); let r = BigNum::new_from(4543).unwrap(); let s_vec = s.to_vec(); assert_eq!(BigNum::new_from_slice(&s_vec).unwrap(), r);
pub fn to_dec_str(&self) -> String
[src]
pub fn to_dec_str(&self) -> String
Returns a decimal string representation of self
.
let s = -BigNum::new_from(12345).unwrap(); assert_eq!(s.to_dec_str(), "-12345");
pub fn to_hex_str(&self) -> String
[src]
pub fn to_hex_str(&self) -> String
Returns a hexadecimal string representation of self
.
let s = -BigNum::new_from(0x99ff).unwrap(); assert_eq!(s.to_hex_str(), "-99FF");
Trait Implementations
impl<'a> Add<&'a BigNum> for &'a BigNum
[src]
impl<'a> Add<&'a BigNum> for &'a BigNum
type Output = BigNum
The resulting type after applying the +
operator.
fn add(self, oth: &'a BigNum) -> BigNum
[src]
fn add(self, oth: &'a BigNum) -> BigNum
Performs the +
operation.
impl<'a> Sub<&'a BigNum> for &'a BigNum
[src]
impl<'a> Sub<&'a BigNum> for &'a BigNum
type Output = BigNum
The resulting type after applying the -
operator.
fn sub(self, oth: &'a BigNum) -> BigNum
[src]
fn sub(self, oth: &'a BigNum) -> BigNum
Performs the -
operation.
impl<'a> Mul<&'a BigNum> for &'a BigNum
[src]
impl<'a> Mul<&'a BigNum> for &'a BigNum
type Output = BigNum
The resulting type after applying the *
operator.
fn mul(self, oth: &'a BigNum) -> BigNum
[src]
fn mul(self, oth: &'a BigNum) -> BigNum
Performs the *
operation.
impl<'a> Div<&'a BigNum> for &'a BigNum
[src]
impl<'a> Div<&'a BigNum> for &'a BigNum
type Output = BigNum
The resulting type after applying the /
operator.
fn div(self, oth: &'a BigNum) -> BigNum
[src]
fn div(self, oth: &'a BigNum) -> BigNum
Performs the /
operation.
impl<'a> Rem<&'a BigNum> for &'a BigNum
[src]
impl<'a> Rem<&'a BigNum> for &'a BigNum
type Output = BigNum
The resulting type after applying the %
operator.
fn rem(self, oth: &'a BigNum) -> BigNum
[src]
fn rem(self, oth: &'a BigNum) -> BigNum
Performs the %
operation.
impl<'a> Shl<i32> for &'a BigNum
[src]
impl<'a> Shl<i32> for &'a BigNum
type Output = BigNum
The resulting type after applying the <<
operator.
fn shl(self, n: i32) -> BigNum
[src]
fn shl(self, n: i32) -> BigNum
Performs the <<
operation.
impl<'a> Shr<i32> for &'a BigNum
[src]
impl<'a> Shr<i32> for &'a BigNum
type Output = BigNum
The resulting type after applying the >>
operator.
fn shr(self, n: i32) -> BigNum
[src]
fn shr(self, n: i32) -> BigNum
Performs the >>
operation.
impl Clone for BigNum
[src]
impl Clone for BigNum
fn clone(&self) -> BigNum
[src]
fn clone(&self) -> BigNum
Returns a copy of the value. Read more
fn clone_from(&mut self, source: &Self)
1.0.0[src]
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
impl Neg for BigNum
[src]
impl Neg for BigNum
type Output = BigNum
The resulting type after applying the -
operator.
fn neg(self) -> BigNum
[src]
fn neg(self) -> BigNum
Performs the unary -
operation.
impl Debug for BigNum
[src]
impl Debug for BigNum
fn fmt(&self, f: &mut Formatter) -> Result
[src]
fn fmt(&self, f: &mut Formatter) -> Result
Formats the value using the given formatter. Read more
impl Eq for BigNum
[src]
impl Eq for BigNum
impl PartialEq for BigNum
[src]
impl PartialEq for BigNum
fn eq(&self, oth: &BigNum) -> bool
[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) -> bool
1.0.0[src]
fn ne(&self, other: &Rhs) -> bool
This method tests for !=
.
impl Ord for BigNum
[src]
impl Ord for BigNum
fn cmp(&self, oth: &BigNum) -> Ordering
[src]
fn cmp(&self, oth: &BigNum) -> Ordering
This method returns an Ordering
between self
and other
. Read more
fn max(self, other: Self) -> Self
1.21.0[src]
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
fn min(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
impl PartialOrd for BigNum
[src]
impl PartialOrd for BigNum
fn partial_cmp(&self, oth: &BigNum) -> Option<Ordering>
[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) -> bool
1.0.0[src]
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
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
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
fn gt(&self, other: &Rhs) -> bool
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
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
impl Drop for BigNum
[src]
impl Drop for BigNum