Add constructors for various standard primes
This commit is contained in:
parent
96d24c8957
commit
796d7b4deb
|
|
@ -548,6 +548,16 @@ extern {
|
|||
pub fn BIO_new(type_: *mut BIO_METHOD) -> *mut BIO;
|
||||
pub fn BIO_s_file() -> *mut BIO_METHOD;
|
||||
pub fn BIO_s_mem() -> *mut BIO_METHOD;
|
||||
|
||||
pub fn get_rfc2409_prime_768(bn: *mut BIGNUM) -> *mut BIGNUM;
|
||||
pub fn get_rfc2409_prime_1024(bn: *mut BIGNUM) -> *mut BIGNUM;
|
||||
pub fn get_rfc3526_prime_1536(bn: *mut BIGNUM) -> *mut BIGNUM;
|
||||
pub fn get_rfc3526_prime_2048(bn: *mut BIGNUM) -> *mut BIGNUM;
|
||||
pub fn get_rfc3526_prime_3072(bn: *mut BIGNUM) -> *mut BIGNUM;
|
||||
pub fn get_rfc3526_prime_4096(bn: *mut BIGNUM) -> *mut BIGNUM;
|
||||
pub fn get_rfc3526_prime_6144(bn: *mut BIGNUM) -> *mut BIGNUM;
|
||||
pub fn get_rfc3526_prime_8192(bn: *mut BIGNUM) -> *mut BIGNUM;
|
||||
|
||||
pub fn CRYPTO_free(buf: *mut c_void);
|
||||
pub fn CRYPTO_num_locks() -> c_int;
|
||||
pub fn CRYPTO_set_locking_callback(func: unsafe extern "C" fn(mode: c_int,
|
||||
|
|
|
|||
|
|
@ -52,9 +52,21 @@ extern {
|
|||
pub fn BIO_new(type_: *const BIO_METHOD) -> *mut BIO;
|
||||
pub fn BIO_s_file() -> *const BIO_METHOD;
|
||||
pub fn BIO_s_mem() -> *const BIO_METHOD;
|
||||
|
||||
pub fn BN_get_rfc2409_prime_768(bn: *mut BIGNUM) -> *mut BIGNUM;
|
||||
pub fn BN_get_rfc2409_prime_1024(bn: *mut BIGNUM) -> *mut BIGNUM;
|
||||
pub fn BN_get_rfc3526_prime_1536(bn: *mut BIGNUM) -> *mut BIGNUM;
|
||||
pub fn BN_get_rfc3526_prime_2048(bn: *mut BIGNUM) -> *mut BIGNUM;
|
||||
pub fn BN_get_rfc3526_prime_3072(bn: *mut BIGNUM) -> *mut BIGNUM;
|
||||
pub fn BN_get_rfc3526_prime_4096(bn: *mut BIGNUM) -> *mut BIGNUM;
|
||||
pub fn BN_get_rfc3526_prime_6144(bn: *mut BIGNUM) -> *mut BIGNUM;
|
||||
pub fn BN_get_rfc3526_prime_8192(bn: *mut BIGNUM) -> *mut BIGNUM;
|
||||
|
||||
pub fn CRYPTO_free(buf: *mut c_void, file: *const c_char, line: c_int);
|
||||
|
||||
pub fn HMAC_CTX_new() -> *mut HMAC_CTX;
|
||||
pub fn HMAC_CTX_free(ctx: *mut HMAC_CTX);
|
||||
|
||||
pub fn TLS_method() -> *const ::SSL_METHOD;
|
||||
pub fn DTLS_method() -> *const ::SSL_METHOD;
|
||||
pub fn SSL_CIPHER_get_version(cipher: *const ::SSL_CIPHER) -> *const c_char;
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
///
|
||||
/// ```
|
||||
|
|
|
|||
Loading…
Reference in New Issue