Struct openssl::bn::BigNum []

pub struct BigNum(_);

Methods

impl BigNum
[src]

Creates a new BigNum with the value 0.

Creates a new BigNum with the given value.

Creates a BigNum from a decimal string.

Creates a BigNum from a hexadecimal string.

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>

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.

Adds a u32 to self.

Subtracts a u32 from self.

Multiplies a u32 by self.

Divides self by a u32, returning the remainder.

Returns the result of self modulo w.

Places a cryptographically-secure pseudo-random number nonnegative number less than self in rnd.

The cryptographically weak counterpart to rand_in_range.

Sets bit n. Equivalent to self |= (1 << n).

When setting a bit outside of self, it is expanded.

Clears bit n, setting it to 0. Equivalent to self &= ~(1 << n).

When clearing a bit outside of self, an error is returned.

Returns true if the nth bit of self is set to 1, false otherwise.

Truncates self to the lowest n bits.

An error occurs if self is already shorter than n bits.

Places a << 1 in self.

Places a >> 1 in self.

Places a + b in self.

Places a - b in self.

Places a << n in self.

Places a >> n in self.

Sets the sign of self.

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

Returns the number of significant bits in self.

Returns the size of self in bytes.

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.

The cryptographically weak counterpart to rand.

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 p so that (p-1)/2 is also prime.
  • add/rem: If add is set to Some(add), p % add == rem will hold, where p is the generated prime and rem is 1 if not specified (None).

Places the result of a * b in self.

Places the result of a / b in self.

Places the result of a % b in self.

Places the result of a / b in self and a % b in rem.

Places the result of in self.

Places the result of a mod m in self.

Places the result of (a + b) mod m in self.

Places the result of (a - b) mod m in self.

Places the result of (a * b) mod m in self.

Places the result of a² mod m in self.

Places the result of a^p in self.

Places the result of a^p mod m in self.

Places the inverse of a modulo n in self.

Places the greatest common denominator of a and b in self.

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.

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.

Returns a big-endian byte vector representation of the absolute value of self.

self can be recreated by using 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);

Returns a decimal string representation of self.

let s = -BigNum::from_u32(12345).unwrap();

assert_eq!(&**s.to_dec_str().unwrap(), "-12345");

Returns a hexadecimal string representation of self.

let s = -BigNum::from_u32(0x99ff).unwrap();

assert_eq!(&**s.to_hex_str().unwrap(), "-99FF");

Returns an Asn1Integer containing the value of self.

Trait Implementations

impl ForeignType for BigNum

The raw C type.

The type representing a reference to this type.

Constructs an instance of this type from its raw type.

Returns a raw pointer to the wrapped value.

impl Drop for BigNum

A method called when the value goes out of scope. Read more

impl Deref for BigNum

The resulting type after dereferencing

The method called to dereference a value

impl DerefMut for BigNum

The method called to mutably dereference a value

impl AsRef<BigNumRef> for BigNum
[src]

Performs the conversion.

impl Debug for BigNum
[src]

Formats the value using the given formatter.

impl Display for BigNum
[src]

Formats the value using the given formatter. Read more

impl PartialEq for BigNum
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl PartialEq<BigNumRef> for BigNum
[src]

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

impl Eq for BigNum
[src]

impl PartialOrd for BigNum
[src]

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

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

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

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

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]

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

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

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

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

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]

This method returns an Ordering between self and other. Read more

🔬 This is a nightly-only experimental API. (ord_max_min)

Compares and returns the maximum of two values. Read more

🔬 This is a nightly-only experimental API. (ord_max_min)

Compares and returns the minimum of two values. Read more

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

The resulting type after applying the + operator

The method for the + operator

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

The resulting type after applying the + operator

The method for the + operator

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

The resulting type after applying the - operator

The method for the - operator

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

The resulting type after applying the - operator

The method for the - operator

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

The resulting type after applying the * operator

The method for the * operator

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

The resulting type after applying the * operator

The method for the * operator

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

The resulting type after applying the / operator

The method for the / operator

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

The resulting type after applying the / operator

The method for the / operator

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

The resulting type after applying the % operator

The method for the % operator

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

The resulting type after applying the % operator

The method for the % operator

impl<'a> Shl<i32> for &'a BigNum
[src]

The resulting type after applying the << operator

The method for the << operator

impl<'a> Shr<i32> for &'a BigNum
[src]

The resulting type after applying the >> operator

The method for the >> operator

impl<'a> Neg for &'a BigNum
[src]

The resulting type after applying the - operator

The method for the unary - operator

impl Neg for BigNum
[src]

The resulting type after applying the - operator

The method for the unary - operator