pub struct BigNum(/* private fields */);
Expand description
Dynamically sized large number implementation
Perform large number mathematics. Create a new BigNum
with new
. Perform standard mathematics on large numbers using
methods from Dref<Target = BigNumRef>
OpenSSL documentation at BN_new
.
§Examples
use openssl::bn::BigNum;
let little_big = BigNum::from_u32(std::u32::MAX)?;
assert_eq!(*&little_big.num_bytes(), 4);
Implementations§
Source§impl BigNum
impl BigNum
Sourcepub fn new() -> Result<BigNum, ErrorStack>
pub fn new() -> Result<BigNum, ErrorStack>
Creates a new BigNum
with the value 0.
This corresponds to BN_new
.
Sourcepub fn new_secure() -> Result<BigNum, ErrorStack>
pub fn new_secure() -> Result<BigNum, ErrorStack>
Returns a new secure BigNum
.
This corresponds to BN_secure_new
.
Sourcepub fn from_u32(n: u32) -> Result<BigNum, ErrorStack>
pub fn from_u32(n: u32) -> Result<BigNum, ErrorStack>
Creates a new BigNum
with the given value.
This corresponds to BN_set_word
.
Sourcepub fn from_dec_str(s: &str) -> Result<BigNum, ErrorStack>
pub fn from_dec_str(s: &str) -> Result<BigNum, ErrorStack>
Creates a BigNum
from a decimal string.
This corresponds to BN_dec2bn
.
Sourcepub fn from_hex_str(s: &str) -> Result<BigNum, ErrorStack>
pub fn from_hex_str(s: &str) -> Result<BigNum, ErrorStack>
Creates a BigNum
from a hexadecimal string.
This corresponds to BN_hex2bn
.
Sourcepub fn get_rfc2409_prime_768() -> Result<BigNum, ErrorStack>
pub fn get_rfc2409_prime_768() -> Result<BigNum, ErrorStack>
Returns a constant used in IKE as defined in RFC 2409
. This prime number is in
the order of magnitude of 2 ^ 768
. This number is used during calculated key
exchanges such as Diffie-Hellman. This number is labeled Oakley group id 1.
This corresponds to BN_get_rfc2409_prime_768
.
Sourcepub fn get_rfc2409_prime_1024() -> Result<BigNum, ErrorStack>
pub fn get_rfc2409_prime_1024() -> Result<BigNum, ErrorStack>
Returns a constant used in IKE as defined in RFC 2409
. This prime number is in
the order of magnitude of 2 ^ 1024
. This number is used during calculated key
exchanges such as Diffie-Hellman. This number is labeled Oakly group 2.
This corresponds to BN_get_rfc2409_prime_1024
.
Sourcepub fn get_rfc3526_prime_1536() -> Result<BigNum, ErrorStack>
pub fn get_rfc3526_prime_1536() -> Result<BigNum, ErrorStack>
Returns a constant used in IKE as defined in RFC 3526
. The prime is in the order
of magnitude of 2 ^ 1536
. This number is used during calculated key
exchanges such as Diffie-Hellman. This number is labeled MODP group 5.
This corresponds to BN_get_rfc3526_prime_1536
.
Sourcepub fn get_rfc3526_prime_2048() -> Result<BigNum, ErrorStack>
pub fn get_rfc3526_prime_2048() -> Result<BigNum, ErrorStack>
Returns a constant used in IKE as defined in RFC 3526
. The prime is in the order
of magnitude of 2 ^ 2048
. This number is used during calculated key
exchanges such as Diffie-Hellman. This number is labeled MODP group 14.
This corresponds to BN_get_rfc3526_prime_2048
.
Sourcepub fn get_rfc3526_prime_3072() -> Result<BigNum, ErrorStack>
pub fn get_rfc3526_prime_3072() -> Result<BigNum, ErrorStack>
Returns a constant used in IKE as defined in RFC 3526
. The prime is in the order
of magnitude of 2 ^ 3072
. This number is used during calculated key
exchanges such as Diffie-Hellman. This number is labeled MODP group 15.
This corresponds to BN_get_rfc3526_prime_3072
.
Sourcepub fn get_rfc3526_prime_4096() -> Result<BigNum, ErrorStack>
pub fn get_rfc3526_prime_4096() -> Result<BigNum, ErrorStack>
Returns a constant used in IKE as defined in RFC 3526
. The prime is in the order
of magnitude of 2 ^ 4096
. This number is used during calculated key
exchanges such as Diffie-Hellman. This number is labeled MODP group 16.
This corresponds to BN_get_rfc3526_prime_4096
.
Sourcepub fn get_rfc3526_prime_6144() -> Result<BigNum, ErrorStack>
pub fn get_rfc3526_prime_6144() -> Result<BigNum, ErrorStack>
Returns a constant used in IKE as defined in RFC 3526
. The prime is in the order
of magnitude of 2 ^ 6144
. This number is used during calculated key
exchanges such as Diffie-Hellman. This number is labeled MODP group 17.
This corresponds to BN_get_rfc3526_prime_6114
.
Sourcepub fn get_rfc3526_prime_8192() -> Result<BigNum, ErrorStack>
pub fn get_rfc3526_prime_8192() -> Result<BigNum, ErrorStack>
Returns a constant used in IKE as defined in RFC 3526
. The prime is in the order
of magnitude of 2 ^ 8192
. This number is used during calculated key
exchanges such as Diffie-Hellman. This number is labeled MODP group 18.
This corresponds to BN_get_rfc3526_prime_8192
.
Sourcepub fn from_slice(n: &[u8]) -> Result<BigNum, ErrorStack>
pub fn from_slice(n: &[u8]) -> Result<BigNum, ErrorStack>
Sourcepub fn copy_from_slice(&mut self, n: &[u8]) -> Result<(), ErrorStack>
pub fn copy_from_slice(&mut self, n: &[u8]) -> Result<(), ErrorStack>
Copies data from a slice overwriting what was in the BigNum.
This function can be used to copy data from a slice to a secure BigNum.
§Examples
let mut bignum = BigNum::new().unwrap();
bignum.copy_from_slice(&[0x12, 0x00, 0x34]).unwrap();
assert_eq!(bignum, BigNum::from_u32(0x120034).unwrap());
This corresponds to BN_bin2bn
.
Methods from Deref<Target = BigNumRef>§
Sourcepub fn clear(&mut self)
pub 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.
This corresponds to BN_clear
.
Sourcepub fn add_word(&mut self, w: u32) -> Result<(), ErrorStack>
pub fn add_word(&mut self, w: u32) -> Result<(), ErrorStack>
Adds a u32
to self
.
This corresponds to BN_add_word
.
Sourcepub fn sub_word(&mut self, w: u32) -> Result<(), ErrorStack>
pub fn sub_word(&mut self, w: u32) -> Result<(), ErrorStack>
Subtracts a u32
from self
.
This corresponds to BN_sub_word
.
Sourcepub fn mul_word(&mut self, w: u32) -> Result<(), ErrorStack>
pub fn mul_word(&mut self, w: u32) -> Result<(), ErrorStack>
Multiplies a u32
by self
.
This corresponds to BN_mul_word
.
Sourcepub fn div_word(&mut self, w: u32) -> Result<u64, ErrorStack>
pub fn div_word(&mut self, w: u32) -> Result<u64, ErrorStack>
Divides self
by a u32
, returning the remainder.
This corresponds to BN_div_word
.
Sourcepub fn mod_word(&self, w: u32) -> Result<u64, ErrorStack>
pub fn mod_word(&self, w: u32) -> Result<u64, ErrorStack>
Returns the result of self
modulo w
.
This corresponds to BN_mod_word
.
Sourcepub fn rand_range(&self, rnd: &mut BigNumRef) -> Result<(), ErrorStack>
pub fn rand_range(&self, rnd: &mut BigNumRef) -> Result<(), ErrorStack>
Places a cryptographically-secure pseudo-random nonnegative
number less than self
in rnd
.
This corresponds to BN_rand_range
.
Sourcepub fn pseudo_rand_range(&self, rnd: &mut BigNumRef) -> Result<(), ErrorStack>
pub fn pseudo_rand_range(&self, rnd: &mut BigNumRef) -> Result<(), ErrorStack>
The cryptographically weak counterpart to rand_in_range
.
This corresponds to BN_pseudo_rand_range
.
Sourcepub fn set_bit(&mut self, n: i32) -> Result<(), ErrorStack>
pub 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.
This corresponds to BN_set_bit
.
Sourcepub fn clear_bit(&mut self, n: i32) -> Result<(), ErrorStack>
pub 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.
This corresponds to BN_clear_bit
.
Sourcepub fn is_bit_set(&self, n: i32) -> bool
pub fn is_bit_set(&self, n: i32) -> bool
Returns true
if the n
th bit of self
is set to 1, false
otherwise.
This corresponds to BN_is_bit_set
.
Sourcepub fn mask_bits(&mut self, n: i32) -> Result<(), ErrorStack>
pub 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.
This corresponds to BN_mask_bits
.
Sourcepub fn lshift1(&mut self, a: &BigNumRef) -> Result<(), ErrorStack>
pub fn lshift1(&mut self, a: &BigNumRef) -> Result<(), ErrorStack>
Places a << 1
in self
. Equivalent to self * 2
.
This corresponds to BN_lshift1
.
Sourcepub fn rshift1(&mut self, a: &BigNumRef) -> Result<(), ErrorStack>
pub fn rshift1(&mut self, a: &BigNumRef) -> Result<(), ErrorStack>
Places a >> 1
in self
. Equivalent to self / 2
.
This corresponds to BN_rshift1
.
Sourcepub fn checked_add(
&mut self,
a: &BigNumRef,
b: &BigNumRef,
) -> Result<(), ErrorStack>
pub fn checked_add( &mut self, a: &BigNumRef, b: &BigNumRef, ) -> Result<(), ErrorStack>
Places a + b
in self
. core::ops::Add
is also implemented for BigNumRef
.
This corresponds to BN_add
.
Sourcepub fn checked_sub(
&mut self,
a: &BigNumRef,
b: &BigNumRef,
) -> Result<(), ErrorStack>
pub fn checked_sub( &mut self, a: &BigNumRef, b: &BigNumRef, ) -> Result<(), ErrorStack>
Places a - b
in self
. core::ops::Sub
is also implemented for BigNumRef
.
This corresponds to BN_sub
.
Sourcepub fn lshift(&mut self, a: &BigNumRef, n: i32) -> Result<(), ErrorStack>
pub fn lshift(&mut self, a: &BigNumRef, n: i32) -> Result<(), ErrorStack>
Places a << n
in self
. Equivalent to a * 2 ^ n
.
This corresponds to BN_lshift
.
Sourcepub fn rshift(&mut self, a: &BigNumRef, n: i32) -> Result<(), ErrorStack>
pub fn rshift(&mut self, a: &BigNumRef, n: i32) -> Result<(), ErrorStack>
Places a >> n
in self
. Equivalent to a / 2 ^ n
.
This corresponds to BN_rshift
.
Sourcepub fn to_owned(&self) -> Result<BigNum, ErrorStack>
pub fn to_owned(&self) -> Result<BigNum, ErrorStack>
Creates a new BigNum with the same value.
This corresponds to BN_dup
.
Sourcepub fn set_negative(&mut self, negative: bool)
pub fn set_negative(&mut self, negative: bool)
Sets the sign of self
. Pass true to set self
to a negative. False sets
self
positive.
This corresponds to BN_set_negative
.
Sourcepub fn is_negative(&self) -> bool
pub fn is_negative(&self) -> bool
Returns true
if self
is negative.
This corresponds to BN_is_negative
.
Sourcepub fn is_even(&self) -> bool
pub fn is_even(&self) -> bool
Returns true
is self
is even.
This corresponds to BN_is_even
.
Sourcepub fn num_bits(&self) -> i32
pub fn num_bits(&self) -> i32
Returns the number of significant bits in self
.
This corresponds to BN_num_bits
.
Sourcepub fn rand(
&mut self,
bits: i32,
msb: MsbOption,
odd: bool,
) -> Result<(), ErrorStack>
pub fn rand( &mut self, 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 most significant bit. Seeconstants
.odd
: Iftrue
, the generated number will be odd.
§Examples
use openssl::bn::{BigNum, MsbOption};
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, MsbOption::MAYBE_ZERO, true);
Ok((big))
}
This corresponds to BN_rand
.
Sourcepub fn pseudo_rand(
&mut self,
bits: i32,
msb: MsbOption,
odd: bool,
) -> Result<(), ErrorStack>
pub fn pseudo_rand( &mut self, bits: i32, msb: MsbOption, odd: bool, ) -> Result<(), ErrorStack>
The cryptographically weak counterpart to rand
. Not suitable for key generation.
This corresponds to BN_pseudo_rand
.
Sourcepub fn generate_prime(
&mut self,
bits: i32,
safe: bool,
add: Option<&BigNumRef>,
rem: Option<&BigNumRef>,
) -> Result<(), ErrorStack>
pub fn generate_prime( &mut self, 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” 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
).
§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))
}
This corresponds to BN_generate_prime_ex
.
Sourcepub fn checked_mul(
&mut self,
a: &BigNumRef,
b: &BigNumRef,
ctx: &mut BigNumContextRef,
) -> Result<(), ErrorStack>
pub fn checked_mul( &mut self, a: &BigNumRef, b: &BigNumRef, ctx: &mut BigNumContextRef, ) -> Result<(), ErrorStack>
Places the result of a * b
in self
.
core::ops::Mul
is also implemented for BigNumRef
.
This corresponds to BN_mul
.
Sourcepub fn checked_div(
&mut self,
a: &BigNumRef,
b: &BigNumRef,
ctx: &mut BigNumContextRef,
) -> Result<(), ErrorStack>
pub fn checked_div( &mut self, a: &BigNumRef, b: &BigNumRef, ctx: &mut BigNumContextRef, ) -> Result<(), ErrorStack>
Places the result of a / b
in self
. The remainder is discarded.
core::ops::Div
is also implemented for BigNumRef
.
This corresponds to BN_div
.
Sourcepub fn checked_rem(
&mut self,
a: &BigNumRef,
b: &BigNumRef,
ctx: &mut BigNumContextRef,
) -> Result<(), ErrorStack>
pub fn checked_rem( &mut self, a: &BigNumRef, b: &BigNumRef, ctx: &mut BigNumContextRef, ) -> Result<(), ErrorStack>
Places the result of a % b
in self
.
This corresponds to BN_div
.
Sourcepub fn div_rem(
&mut self,
rem: &mut BigNumRef,
a: &BigNumRef,
b: &BigNumRef,
ctx: &mut BigNumContextRef,
) -> Result<(), ErrorStack>
pub fn div_rem( &mut self, 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
.
This corresponds to BN_div
.
Sourcepub fn sqr(
&mut self,
a: &BigNumRef,
ctx: &mut BigNumContextRef,
) -> Result<(), ErrorStack>
pub fn sqr( &mut self, a: &BigNumRef, ctx: &mut BigNumContextRef, ) -> Result<(), ErrorStack>
Places the result of a²
in self
.
This corresponds to BN_sqr
.
Sourcepub fn nnmod(
&mut self,
a: &BigNumRef,
m: &BigNumRef,
ctx: &mut BigNumContextRef,
) -> Result<(), ErrorStack>
pub fn nnmod( &mut self, a: &BigNumRef, m: &BigNumRef, ctx: &mut BigNumContextRef, ) -> Result<(), ErrorStack>
Places the result of a mod m
in self
. As opposed to div_rem
the result is non-negative.
This corresponds to BN_nnmod
.
Sourcepub fn mod_add(
&mut self,
a: &BigNumRef,
b: &BigNumRef,
m: &BigNumRef,
ctx: &mut BigNumContextRef,
) -> Result<(), ErrorStack>
pub fn mod_add( &mut self, a: &BigNumRef, b: &BigNumRef, m: &BigNumRef, ctx: &mut BigNumContextRef, ) -> Result<(), ErrorStack>
Places the result of (a + b) mod m
in self
.
This corresponds to BN_mod_add
.
Sourcepub fn mod_sub(
&mut self,
a: &BigNumRef,
b: &BigNumRef,
m: &BigNumRef,
ctx: &mut BigNumContextRef,
) -> Result<(), ErrorStack>
pub fn mod_sub( &mut self, a: &BigNumRef, b: &BigNumRef, m: &BigNumRef, ctx: &mut BigNumContextRef, ) -> Result<(), ErrorStack>
Places the result of (a - b) mod m
in self
.
This corresponds to BN_mod_sub
.
Sourcepub fn mod_mul(
&mut self,
a: &BigNumRef,
b: &BigNumRef,
m: &BigNumRef,
ctx: &mut BigNumContextRef,
) -> Result<(), ErrorStack>
pub fn mod_mul( &mut self, a: &BigNumRef, b: &BigNumRef, m: &BigNumRef, ctx: &mut BigNumContextRef, ) -> Result<(), ErrorStack>
Places the result of (a * b) mod m
in self
.
This corresponds to BN_mod_mul
.
Sourcepub fn mod_sqr(
&mut self,
a: &BigNumRef,
m: &BigNumRef,
ctx: &mut BigNumContextRef,
) -> Result<(), ErrorStack>
pub fn mod_sqr( &mut self, a: &BigNumRef, m: &BigNumRef, ctx: &mut BigNumContextRef, ) -> Result<(), ErrorStack>
Places the result of a² mod m
in self
.
This corresponds to BN_mod_sqr
.
Sourcepub fn mod_sqrt(
&mut self,
a: &BigNumRef,
p: &BigNumRef,
ctx: &mut BigNumContextRef,
) -> Result<(), ErrorStack>
pub fn mod_sqrt( &mut self, a: &BigNumRef, p: &BigNumRef, ctx: &mut BigNumContextRef, ) -> Result<(), ErrorStack>
Places into self
the modular square root of a
such that self^2 = a (mod p)
This corresponds to BN_mod_sqrt
.
Sourcepub fn exp(
&mut self,
a: &BigNumRef,
p: &BigNumRef,
ctx: &mut BigNumContextRef,
) -> Result<(), ErrorStack>
pub fn exp( &mut self, a: &BigNumRef, p: &BigNumRef, ctx: &mut BigNumContextRef, ) -> Result<(), ErrorStack>
Places the result of a^p
in self
.
This corresponds to BN_exp
.
Sourcepub fn mod_exp(
&mut self,
a: &BigNumRef,
p: &BigNumRef,
m: &BigNumRef,
ctx: &mut BigNumContextRef,
) -> Result<(), ErrorStack>
pub fn mod_exp( &mut self, a: &BigNumRef, p: &BigNumRef, m: &BigNumRef, ctx: &mut BigNumContextRef, ) -> Result<(), ErrorStack>
Places the result of a^p mod m
in self
.
This corresponds to BN_mod_exp
.
Sourcepub fn mod_inverse(
&mut self,
a: &BigNumRef,
n: &BigNumRef,
ctx: &mut BigNumContextRef,
) -> Result<(), ErrorStack>
pub fn mod_inverse( &mut self, a: &BigNumRef, n: &BigNumRef, ctx: &mut BigNumContextRef, ) -> Result<(), ErrorStack>
Places the inverse of a
modulo n
in self
.
This corresponds to BN_mod_inverse
.
Sourcepub fn gcd(
&mut self,
a: &BigNumRef,
b: &BigNumRef,
ctx: &mut BigNumContextRef,
) -> Result<(), ErrorStack>
pub fn gcd( &mut self, a: &BigNumRef, b: &BigNumRef, ctx: &mut BigNumContextRef, ) -> Result<(), ErrorStack>
Places the greatest common denominator of a
and b
in self
.
This corresponds to BN_gcd
.
Sourcepub fn is_prime(
&self,
checks: i32,
ctx: &mut BigNumContextRef,
) -> Result<bool, ErrorStack>
pub fn is_prime( &self, checks: i32, ctx: &mut BigNumContextRef, ) -> Result<bool, ErrorStack>
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
.
This corresponds to BN_is_prime_ex
.
Sourcepub fn is_prime_fasttest(
&self,
checks: i32,
ctx: &mut BigNumContextRef,
do_trial_division: bool,
) -> Result<bool, ErrorStack>
pub fn is_prime_fasttest( &self, 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
.
This corresponds to BN_is_prime_fasttest_ex
.
Sourcepub fn to_vec(&self) -> Vec<u8> ⓘ
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 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);
This corresponds to BN_bn2bin
.
Sourcepub fn to_vec_padded(&self, pad_to: i32) -> Result<Vec<u8>, ErrorStack>
pub fn to_vec_padded(&self, pad_to: i32) -> Result<Vec<u8>, ErrorStack>
Returns a big-endian byte vector representation of the absolute value of self
padded
to pad_to
bytes.
If pad_to
is less than self.num_bytes()
then an error is returned.
self
can be recreated by using from_slice
.
let bn = BigNum::from_u32(0x4543).unwrap();
let bn_vec = bn.to_vec_padded(4).unwrap();
assert_eq!(&bn_vec, &[0, 0, 0x45, 0x43]);
let r = bn.to_vec_padded(1);
assert!(r.is_err());
let bn = -BigNum::from_u32(0x4543).unwrap();
let bn_vec = bn.to_vec_padded(4).unwrap();
assert_eq!(&bn_vec, &[0, 0, 0x45, 0x43]);
This corresponds to BN_bn2binpad
.
Sourcepub fn to_dec_str(&self) -> Result<OpensslString, ErrorStack>
pub fn to_dec_str(&self) -> Result<OpensslString, ErrorStack>
Returns a decimal string representation of self
.
let s = -BigNum::from_u32(12345).unwrap();
assert_eq!(&**s.to_dec_str().unwrap(), "-12345");
This corresponds to BN_bn2dec
.
Sourcepub fn to_hex_str(&self) -> Result<OpensslString, ErrorStack>
pub fn to_hex_str(&self) -> Result<OpensslString, ErrorStack>
Returns a hexadecimal string representation of self
.
let s = -BigNum::from_u32(0x99ff).unwrap();
assert_eq!(s.to_hex_str().unwrap().to_uppercase(), "-99FF");
This corresponds to BN_bn2hex
.
Sourcepub fn to_asn1_integer(&self) -> Result<Asn1Integer, ErrorStack>
pub fn to_asn1_integer(&self) -> Result<Asn1Integer, ErrorStack>
Returns an Asn1Integer
containing the value of self
.
This corresponds to BN_to_ASN1_INTEGER
.
Sourcepub fn set_const_time(&mut self)
pub fn set_const_time(&mut self)
Force constant time computation on this value.
This corresponds to BN_set_flags
.
Sourcepub fn is_const_time(&self) -> bool
pub fn is_const_time(&self) -> bool
Returns true if self
is in const time mode.
This corresponds to BN_get_flags
.
Sourcepub fn is_secure(&self) -> bool
pub fn is_secure(&self) -> bool
Returns true if self
was created with BigNum::new_secure
.
This corresponds to BN_get_flags
.
Trait Implementations§
Source§impl ForeignType for BigNum
impl ForeignType for BigNum
Source§impl Ord for BigNum
impl Ord for BigNum
Source§impl PartialOrd<BigNum> for BigNumRef
impl PartialOrd<BigNum> for BigNumRef
Source§impl PartialOrd<BigNumRef> for BigNum
impl PartialOrd<BigNumRef> for BigNum
Source§impl PartialOrd for BigNum
impl PartialOrd for BigNum
impl Eq for BigNum
impl Send for BigNum
impl Sync for BigNum
Auto Trait Implementations§
impl Freeze for BigNum
impl RefUnwindSafe for BigNum
impl Unpin for BigNum
impl UnwindSafe for BigNum
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Layout§
Note: Most layout information is completely unstable and may even differ between compilations. The only exception is types with certain repr(...)
attributes. Please see the Rust Reference's “Type Layout” chapter for details on type layout guarantees.
Size: 8 bytes