Commit dd46d192 authored by Valerii Hiora's avatar Valerii Hiora
Browse files

Correct init mutexes and locking function

`libcrypto` uses locks quite intensively even without SSL. 
So they should be initialized before everything else to 
function properly in multi-threaded apps in which SSL 
operations are absent or delayed.

Finishes #79
parent c415f122
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -20,6 +20,8 @@ impl Asn1Time {
    }

    fn new_with_period(period: u64) -> Result<Asn1Time, SslError> {
        ffi::init();

        let handle = unsafe {
            try_ssl_null!(ffi::X509_gmtime_adj(ptr::null_mut(),
                                               period as c_long))
+2 −0
Original line number Diff line number Diff line
@@ -24,6 +24,8 @@ impl Drop for MemBio {
impl MemBio {
    /// Creates a new owned memory based BIO
    pub fn new() -> Result<MemBio, SslError> {
        ffi::init();

        let bio = unsafe { ffi::BIO_new(ffi::BIO_s_mem()) };
        try_ssl_null!(bio);

+4 −0
Original line number Diff line number Diff line
@@ -79,8 +79,10 @@ macro_rules! with_bn_in_ctx(
)

impl BigNum {
    // FIXME: squash 3 constructors into one
    pub fn new() -> Result<BigNum, SslError> {
        unsafe {
            ffi::init();
            let v = ffi::BN_new();
            if v.is_null() {
                Err(SslError::get())
@@ -92,6 +94,7 @@ impl BigNum {

    pub fn new_from(n: u64) -> Result<BigNum, SslError> {
        unsafe {
            ffi::init();
            let bn = ffi::BN_new();
            if bn.is_null() || ffi::BN_set_word(bn, n as c_ulong) == 0 {
                Err(SslError::get())
@@ -103,6 +106,7 @@ impl BigNum {

    pub fn new_from_slice(n: &[u8]) -> Result<BigNum, SslError> {
        unsafe {
            ffi::init();
            let bn = ffi::BN_new();
            if bn.is_null() || ffi::BN_bin2bn(n.as_ptr(), n.len() as c_int, bn).is_null() {
                Err(SslError::get())
+2 −0
Original line number Diff line number Diff line
@@ -36,6 +36,8 @@ pub struct Hasher {

impl Hasher {
    pub fn new(ht: HashType) -> Hasher {
        ffi::init();

        let ctx = unsafe { ffi::EVP_MD_CTX_create() };
        let (evp, mdlen) = evpmd(ht);
        unsafe {
+2 −0
Original line number Diff line number Diff line
@@ -27,6 +27,8 @@ pub struct HMAC {
#[allow(non_snake_case)]
pub fn HMAC(ht: hash::HashType, key: &[u8]) -> HMAC {
    unsafe {
        ffi::init();

        let (evp, mdlen) = hash::evpmd(ht);

        let mut ctx : ffi::HMAC_CTX = ::std::mem::uninitialized();
Loading