Commit e28b73e1 authored by Steven Fackler's avatar Steven Fackler
Browse files

Merge pull request #259 from jedisct1/dh

Add support for DHE for forward secrecy
parents ad475989 9add4e10
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -21,6 +21,7 @@ aes_xts = []
aes_ctr = []
npn = []
alpn = []
rfc5114 = []

[dependencies]
libc = "0.1"
+14 −0
Original line number Diff line number Diff line
@@ -20,6 +20,7 @@ pub type BIO_METHOD = c_void;
pub type BN_CTX = c_void;
pub type COMP_METHOD = c_void;
pub type CRYPTO_EX_DATA = c_void;
pub type DH = c_void;
pub type ENGINE = c_void;
pub type EVP_CIPHER = c_void;
pub type EVP_CIPHER_CTX = c_void;
@@ -380,6 +381,17 @@ extern "C" {
    pub fn CRYPTO_memcmp(a: *const c_void, b: *const c_void,
                         len: size_t) -> c_int;

    pub fn DH_free(dh: *mut DH);

    #[cfg(feature = "rfc5114")]
    pub fn DH_get_1024_160() -> *mut DH;
    #[cfg(feature = "rfc5114")]
    pub fn DH_get_2048_224() -> *mut DH;
    #[cfg(feature = "rfc5114")]
    pub fn DH_get_2048_256() -> *mut DH;

    pub fn DH_new_from_params(p: *mut BIGNUM, g: *mut BIGNUM, q: *mut BIGNUM) -> *mut DH;

    pub fn ERR_get_error() -> c_ulong;

    pub fn ERR_lib_error_string(err: c_ulong) -> *const c_char;
@@ -664,6 +676,8 @@ extern "C" {
    pub fn SSL_CTX_set_read_ahead(ctx: *mut SSL_CTX, m: c_long) -> c_long;
    #[link_name = "SSL_set_tlsext_host_name_shim"]
    pub fn SSL_set_tlsext_host_name(s: *mut SSL, name: *const c_char) -> c_long;
    #[link_name = "SSL_CTX_set_tmp_dh_shim"]
    pub fn SSL_CTX_set_tmp_dh(s: *mut SSL, dh: *const DH) -> c_long;
    #[link_name = "X509_get_extensions_shim"]
    pub fn X509_get_extensions(x: *mut X509) -> *mut stack_st_X509_EXTENSION;
}
+18 −0
Original line number Diff line number Diff line
#include <openssl/hmac.h>
#include <openssl/ssl.h>
#include <openssl/dh.h>
#include <openssl/bn.h>

#if OPENSSL_VERSION_NUMBER < 0x1000000L
// Copied from openssl crypto/hmac/hmac.c
@@ -79,6 +81,22 @@ long SSL_CTX_set_read_ahead_shim(SSL_CTX *ctx, long m) {
    return SSL_CTX_set_read_ahead(ctx, m);
}

long SSL_CTX_set_tmp_dh_shim(SSL_CTX *ctx, DH *dh) {
    return SSL_CTX_set_tmp_dh(ctx, dh);
}

DH *DH_new_from_params(BIGNUM *p, BIGNUM *g, BIGNUM *q) {
    DH *dh;

    if ((dh = DH_new()) == NULL) {
        return NULL;
    }
    dh->p = p;
    dh->g = g;
    dh->q = q;
    return dh;
}

long SSL_set_tlsext_host_name_shim(SSL *s, char *name) {
    return SSL_set_tlsext_host_name(s, name);
}
+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ aes_xts = ["openssl-sys/aes_xts"]
aes_ctr = ["openssl-sys/aes_ctr"]
npn = ["openssl-sys/npn"]
alpn = ["openssl-sys/alpn"]
rfc5114 = ["openssl-sys/rfc5114"]

[dependencies.openssl-sys]
path = "../openssl-sys"
+2 −2
Original line number Diff line number Diff line
@@ -397,12 +397,12 @@ impl BigNum {
        (self.num_bits() + 7) / 8
    }

    unsafe fn raw(&self) -> *mut ffi::BIGNUM {
    pub unsafe fn raw(&self) -> *mut ffi::BIGNUM {
        let BigNum(n) = *self;
        n
    }

    unsafe fn raw_ptr(&self) -> *const *mut ffi::BIGNUM {
    pub unsafe fn raw_ptr(&self) -> *const *mut ffi::BIGNUM {
        let BigNum(ref n) = *self;
        n
    }
Loading