Struct openssl::bn::BigNumRef []

pub struct BigNumRef(_);

Reference to a BigNum

Methods

impl BigNumRef
[src]

[src]

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.

OpenSSL documentation at BN_clear

[src]

Adds a u32 to self.

OpenSSL documentation at BN_add_word

[src]

Subtracts a u32 from self.

OpenSSL documentation at BN_sub_word

[src]

Multiplies a u32 by self.

OpenSSL documentation at BN_mul_word

[src]

Divides self by a u32, returning the remainder.

OpenSSL documentation at BN_div_word

[src]

Returns the result of self modulo w.

OpenSSL documentation at BN_mod_word

[src]

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

OpenSSL documentation at BN_rand_range

[src]

The cryptographically weak counterpart to rand_in_range.

OpenSSL documentation at BN_pseudo_rand_range

[src]

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

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

OpenSSL documentation at BN_set_bit

[src]

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

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

OpenSSL documentation at BN_clear_bit

[src]

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

OpenSSL documentation at BN_is_bit_set

[src]

Truncates self to the lowest n bits.

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

OpenSSL documentation at BN_mask_bits

[src]

Places a << 1 in self. Equivalent to self * 2.

OpenSSL documentation at BN_lshift1

[src]

Places a >> 1 in self. Equivalent to self / 2.

OpenSSL documentation at BN_rshift1

[src]

Places a + b in self. core::ops::Add is also implemented for BigNumRef.

OpenSSL documentation at BN_add

[src]

Places a - b in self. core::ops::Sub is also implemented for BigNumRef.

OpenSSL documentation at BN_sub

[src]

Places a << n in self. Equivalent to a * 2 ^ n.

OpenSSL documentation at BN_lshift

[src]

Places a >> n in self. Equivalent to a / 2 ^ n.

OpenSSL documentation at BN_rshift

[src]

Creates a new BigNum with the same value.

OpenSSL documentation at BN_dup

[src]

Sets the sign of self. Pass true to set self to a negative. False sets self positive.

[src]

Compare the absolute values of self and oth.

OpenSSL documentation at BN_ucmp

Examples

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

assert_eq!(s.ucmp(&o), Ordering::Equal);

[src]

Returns true if self is negative.

[src]

Returns the number of significant bits in self.

OpenSSL documentation at BN_num_bits

[src]

Returns the size of self in bytes. Implemented natively.

[src]

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 most significant bit. See constants.
  • odd: If true, the generated number will be odd.

Examples

use openssl::bn::{BigNum,MSB_MAYBE_ZERO};
use openssl::error::ErrorStack;

fn generate_random() -> Result< BigNum, ErrorStack > {
   let mut big = BigNum::new()?;

   // Generates a 128-bit odd random number
   big.rand(128, MSB_MAYBE_ZERO, true);
   Ok((big))
}

OpenSSL documentation at BN_rand

[src]

The cryptographically weak counterpart to rand. Not suitable for key generation.

OpenSSL documentation at BN_psuedo_rand

[src]

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

Examples

use openssl::bn::BigNum;
use openssl::error::ErrorStack;

fn generate_weak_prime() -> Result< BigNum, ErrorStack > {
   let mut big = BigNum::new()?;

   // Generates a 128-bit simple prime number
   big.generate_prime(128, false, None, None);
   Ok((big))
}

OpenSSL documentation at BN_generate_prime_ex

[src]

Places the result of a * b in self. core::ops::Mul is also implemented for BigNumRef.

OpenSSL documentation at BN_mul

[src]

Places the result of a / b in self. The remainder is discarded. core::ops::Div is also implemented for BigNumRef.

OpenSSL documentation at BN_div

[src]

Places the result of a % b in self.

OpenSSL documentation at BN_div

[src]

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

OpenSSL documentation at BN_div

[src]

Places the result of in self.

OpenSSL documentation at BN_sqr

[src]

Places the result of a mod m in self. As opposed to div_rem the result is non-negative.

OpenSSL documentation at BN_nnmod

[src]

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

OpenSSL documentation at BN_mod_add

[src]

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

OpenSSL documentation at BN_mod_sub

[src]

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

OpenSSL documentation at BN_mod_mul

[src]

Places the result of a² mod m in self.

OpenSSL documentation at BN_mod_sqr

[src]

Places the result of a^p in self.

OpenSSL documentation at BN_exp

[src]

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

OpenSSL documentation at BN_mod_exp

[src]

Places the inverse of a modulo n in self.

[src]

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

OpenSSL documentation at BN_gcd

[src]

Checks whether self is prime.

Performs a Miller-Rabin probabilistic primality test with checks iterations.

OpenSSL documentation at BN_is_prime_ex

Return Value

Returns true if self is prime with an error probability of less than 0.25 ^ checks.

[src]

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.

OpenSSL documentation at BN_is_prime_fasttest_ex

Return Value

Returns true if self is prime with an error probability of less than 0.25 ^ checks.

[src]

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

[src]

Returns a decimal string representation of self.

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

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

[src]

Returns a hexadecimal string representation of self.

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

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

[src]

Returns an Asn1Integer containing the value of self.

Trait Implementations

impl ForeignTypeRef for BigNumRef

The raw C type.

[src]

Constructs a shared instance of this type from its raw type.

[src]

Constructs a mutable reference of this type from its raw type.

[src]

Returns a raw pointer to the wrapped value.

impl Send for BigNumRef
[src]

impl Sync for BigNumRef
[src]

impl Debug for BigNumRef
[src]

[src]

Formats the value using the given formatter.

impl Display for BigNumRef
[src]

[src]

Formats the value using the given formatter. Read more

impl PartialEq<BigNumRef> for BigNumRef
[src]

[src]

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

1.0.0
[src]

This method tests for !=.

impl PartialEq<BigNum> for BigNumRef
[src]

[src]

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

1.0.0
[src]

This method tests for !=.

impl Eq for BigNumRef
[src]

impl PartialOrd<BigNumRef> for BigNumRef
[src]

[src]

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

1.0.0
[src]

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

1.0.0
[src]

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

1.0.0
[src]

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

1.0.0
[src]

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

impl PartialOrd<BigNum> for BigNumRef
[src]

[src]

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

1.0.0
[src]

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

1.0.0
[src]

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

1.0.0
[src]

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

1.0.0
[src]

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

impl Ord for BigNumRef
[src]

[src]

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

1.22.0
[src]

Compares and returns the maximum of two values. Read more

1.22.0
[src]

Compares and returns the minimum of two values. Read more

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

The resulting type after applying the + operator.

[src]

Performs the + operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

The resulting type after applying the - operator.

[src]

Performs the - operation.

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

The resulting type after applying the * operator.

[src]

Performs the * operation.

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

The resulting type after applying the * operator.

[src]

Performs the * operation.

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

The resulting type after applying the / operator.

[src]

Performs the / operation.

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

The resulting type after applying the / operator.

[src]

Performs the / operation.

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

The resulting type after applying the % operator.

[src]

Performs the % operation.

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

The resulting type after applying the % operator.

[src]

Performs the % operation.

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

The resulting type after applying the << operator.

[src]

Performs the << operation.

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

The resulting type after applying the >> operator.

[src]

Performs the >> operation.

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

The resulting type after applying the - operator.

[src]

Performs the unary - operation.