aboutsummaryrefslogtreecommitdiff
path: root/openssl
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2016-11-12 14:14:56 +0000
committerSteven Fackler <[email protected]>2016-11-12 14:20:43 +0000
commit796d7b4deb547f1cd0bce0d54dea2dc5cdf650bb (patch)
tree725d3c9c684689f28b16b2dd31f41e4c0460e621 /openssl
parentAdd SslRef::set_{tmp_dh,tmp_ecdh,ecdh_auto} (diff)
downloadrust-openssl-796d7b4deb547f1cd0bce0d54dea2dc5cdf650bb.tar.xz
rust-openssl-796d7b4deb547f1cd0bce0d54dea2dc5cdf650bb.zip
Add constructors for various standard primes
Diffstat (limited to 'openssl')
-rw-r--r--openssl/src/bn.rs73
1 files changed, 73 insertions, 0 deletions
diff --git a/openssl/src/bn.rs b/openssl/src/bn.rs
index d52be884..73482432 100644
--- a/openssl/src/bn.rs
+++ b/openssl/src/bn.rs
@@ -10,6 +10,21 @@ use crypto::CryptoString;
use error::ErrorStack;
use types::{OpenSslType, OpenSslTypeRef};
+#[cfg(ossl10x)]
+use ffi::{get_rfc2409_prime_768 as BN_get_rfc2409_prime_768,
+ get_rfc2409_prime_1024 as BN_get_rfc2409_prime_1024,
+ get_rfc3526_prime_1536 as BN_get_rfc3526_prime_1536,
+ get_rfc3526_prime_2048 as BN_get_rfc3526_prime_2048,
+ get_rfc3526_prime_3072 as BN_get_rfc3526_prime_3072,
+ get_rfc3526_prime_4096 as BN_get_rfc3526_prime_4096,
+ get_rfc3526_prime_6144 as BN_get_rfc3526_prime_6144,
+ get_rfc3526_prime_8192 as BN_get_rfc3526_prime_8192};
+
+#[cfg(ossl110)]
+use ffi::{BN_get_rfc2409_prime_768, BN_get_rfc2409_prime_1024, BN_get_rfc3526_prime_1536,
+ BN_get_rfc3526_prime_2048, BN_get_rfc3526_prime_3072, BN_get_rfc3526_prime_4096,
+ BN_get_rfc3526_prime_6144, BN_get_rfc3526_prime_8192};
+
/// Options for the most significant bits of a randomly generated `BigNum`.
pub struct MsbOption(c_int);
@@ -516,6 +531,7 @@ impl BigNum {
/// Creates a `BigNum` from a decimal string.
pub fn from_dec_str(s: &str) -> Result<BigNum, ErrorStack> {
unsafe {
+ ffi::init();
let c_str = CString::new(s.as_bytes()).unwrap();
let mut bn = ptr::null_mut();
try!(cvt(ffi::BN_dec2bn(&mut bn, c_str.as_ptr() as *const _)));
@@ -526,6 +542,7 @@ impl BigNum {
/// Creates a `BigNum` from a hexadecimal string.
pub fn from_hex_str(s: &str) -> Result<BigNum, ErrorStack> {
unsafe {
+ ffi::init();
let c_str = CString::new(s.as_bytes()).unwrap();
let mut bn = ptr::null_mut();
try!(cvt(ffi::BN_hex2bn(&mut bn, c_str.as_ptr() as *const _)));
@@ -533,6 +550,62 @@ impl BigNum {
}
}
+ pub fn get_rfc2409_prime_768() -> Result<BigNum, ErrorStack> {
+ unsafe {
+ ffi::init();
+ cvt_p(BN_get_rfc2409_prime_768(ptr::null_mut())).map(BigNum)
+ }
+ }
+
+ pub fn get_rfc2409_prime_1024() -> Result<BigNum, ErrorStack> {
+ unsafe {
+ ffi::init();
+ cvt_p(BN_get_rfc2409_prime_1024(ptr::null_mut())).map(BigNum)
+ }
+ }
+
+ pub fn get_rfc3526_prime_1536() -> Result<BigNum, ErrorStack> {
+ unsafe {
+ ffi::init();
+ cvt_p(BN_get_rfc3526_prime_1536(ptr::null_mut())).map(BigNum)
+ }
+ }
+
+ pub fn get_rfc3526_prime_2048() -> Result<BigNum, ErrorStack> {
+ unsafe {
+ ffi::init();
+ cvt_p(BN_get_rfc3526_prime_2048(ptr::null_mut())).map(BigNum)
+ }
+ }
+
+ pub fn get_rfc3526_prime_3072() -> Result<BigNum, ErrorStack> {
+ unsafe {
+ ffi::init();
+ cvt_p(BN_get_rfc3526_prime_3072(ptr::null_mut())).map(BigNum)
+ }
+ }
+
+ pub fn get_rfc3526_prime_4096() -> Result<BigNum, ErrorStack> {
+ unsafe {
+ ffi::init();
+ cvt_p(BN_get_rfc3526_prime_4096(ptr::null_mut())).map(BigNum)
+ }
+ }
+
+ pub fn get_rfc3526_prime_6144() -> Result<BigNum, ErrorStack> {
+ unsafe {
+ ffi::init();
+ cvt_p(BN_get_rfc3526_prime_6144(ptr::null_mut())).map(BigNum)
+ }
+ }
+
+ pub fn get_rfc3526_prime_8192() -> Result<BigNum, ErrorStack> {
+ unsafe {
+ ffi::init();
+ cvt_p(BN_get_rfc3526_prime_8192(ptr::null_mut())).map(BigNum)
+ }
+ }
+
/// Creates a new `BigNum` from an unsigned, big-endian encoded number of arbitrary length.
///
/// ```