aboutsummaryrefslogtreecommitdiff
path: root/openssl/src/dh/mod.rs
diff options
context:
space:
mode:
authorSteven Fackler <[email protected]>2016-10-14 11:39:43 -0700
committerGitHub <[email protected]>2016-10-14 11:39:43 -0700
commit98e71596fb48ce7cdabd46e581f32a9a54398cce (patch)
tree7d600055248d58edfccd4ed5577c32c86bac3ff2 /openssl/src/dh/mod.rs
parentRename NoPadding to None (diff)
parentIgnore DTLS tests on Windows/ARM for now (diff)
downloadrust-openssl-98e71596fb48ce7cdabd46e581f32a9a54398cce.tar.xz
rust-openssl-98e71596fb48ce7cdabd46e581f32a9a54398cce.zip
Merge pull request #464 from alexcrichton/systest
Add support for OpenSSL 1.1.0
Diffstat (limited to 'openssl/src/dh/mod.rs')
-rw-r--r--openssl/src/dh/mod.rs59
1 files changed, 39 insertions, 20 deletions
diff --git a/openssl/src/dh/mod.rs b/openssl/src/dh/mod.rs
index e0cf885a..b716ffe0 100644
--- a/openssl/src/dh/mod.rs
+++ b/openssl/src/dh/mod.rs
@@ -3,24 +3,22 @@ use error::ErrorStack;
use bio::MemBioSlice;
use std::ptr;
-#[cfg(feature = "dh_from_params")]
use bn::BigNum;
-#[cfg(feature = "dh_from_params")]
use std::mem;
pub struct DH(*mut ffi::DH);
impl DH {
- /// Requires the `dh_from_params` feature.
- #[cfg(feature = "dh_from_params")]
pub fn from_params(p: BigNum, g: BigNum, q: BigNum) -> Result<DH, ErrorStack> {
- let dh = unsafe {
- try_ssl_null!(::c_helpers::rust_0_8_DH_new_from_params(p.as_ptr(), g.as_ptr(), q.as_ptr()))
- };
- mem::forget(p);
- mem::forget(g);
- mem::forget(q);
- Ok(DH(dh))
+ unsafe {
+ let dh = DH(try_ssl_null!(ffi::DH_new()));
+ try_ssl!(compat::DH_set0_pqg(dh.0,
+ p.as_ptr(),
+ q.as_ptr(),
+ g.as_ptr()));
+ mem::forget((p, g, q));
+ Ok(dh)
+ }
}
pub fn from_pem(buf: &[u8]) -> Result<DH, ErrorStack> {
@@ -32,19 +30,19 @@ impl DH {
Ok(DH(dh))
}
- #[cfg(feature = "rfc5114")]
+ #[cfg(feature = "openssl-102")]
pub fn get_1024_160() -> Result<DH, ErrorStack> {
let dh = try_ssl_null!(unsafe { ffi::DH_get_1024_160() });
Ok(DH(dh))
}
- #[cfg(feature = "rfc5114")]
+ #[cfg(feature = "openssl-102")]
pub fn get_2048_224() -> Result<DH, ErrorStack> {
let dh = try_ssl_null!(unsafe { ffi::DH_get_2048_224() });
Ok(DH(dh))
}
- #[cfg(feature = "rfc5114")]
+ #[cfg(feature = "openssl-102")]
pub fn get_2048_256() -> Result<DH, ErrorStack> {
let dh = try_ssl_null!(unsafe { ffi::DH_get_2048_256() });
Ok(DH(dh))
@@ -64,17 +62,39 @@ impl Drop for DH {
}
}
+#[cfg(ossl110)]
+mod compat {
+ pub use ffi::DH_set0_pqg;
+}
+
+#[cfg(ossl10x)]
+#[allow(bad_style)]
+mod compat {
+ use ffi;
+ use libc::c_int;
+
+ pub unsafe fn DH_set0_pqg(dh: *mut ffi::DH,
+ p: *mut ffi::BIGNUM,
+ q: *mut ffi::BIGNUM,
+ g: *mut ffi::BIGNUM) -> c_int {
+ (*dh).p = p;
+ (*dh).q = q;
+ (*dh).g = g;
+ 1
+ }
+}
+
#[cfg(test)]
mod tests {
use super::DH;
use bn::BigNum;
use ssl::SslContext;
- use ssl::SslMethod::Sslv23;
+ use ssl::SslMethod::Tls;
#[test]
- #[cfg(feature = "rfc5114")]
+ #[cfg(feature = "openssl-102")]
fn test_dh_rfc5114() {
- let mut ctx = SslContext::new(Sslv23).unwrap();
+ let mut ctx = SslContext::new(Tls).unwrap();
let dh1 = DH::get_1024_160().unwrap();
ctx.set_tmp_dh(&dh1).unwrap();
let dh2 = DH::get_2048_224().unwrap();
@@ -84,9 +104,8 @@ mod tests {
}
#[test]
- #[cfg(feature = "dh_from_params")]
fn test_dh() {
- let mut ctx = SslContext::new(Sslv23).unwrap();
+ let mut ctx = SslContext::new(Tls).unwrap();
let p = BigNum::from_hex_str("87A8E61DB4B6663CFFBBD19C651959998CEEF608660DD0F25D2CEED4435\
E3B00E00DF8F1D61957D4FAF7DF4561B2AA3016C3D91134096FAA3BF429\
6D830E9A7C209E0C6497517ABD5A8A9D306BCF67ED91F9E6725B4758C02\
@@ -116,7 +135,7 @@ mod tests {
#[test]
fn test_dh_from_pem() {
- let mut ctx = SslContext::new(Sslv23).unwrap();
+ let mut ctx = SslContext::new(Tls).unwrap();
let params = include_bytes!("../../test/dhparams.pem");
let dh = DH::from_pem(params).ok().expect("Failed to load PEM");
ctx.set_tmp_dh(&dh).unwrap();