Commit cb442568 authored by Steven Fackler's avatar Steven Fackler Committed by GitHub
Browse files

Merge pull request #487 from sfackler/update

Updates
parents 58f6d113 04fc853e
Loading
Loading
Loading
Loading
+910 −3

File changed.

Preview size limit exceeded, changes collapsed.

openssl/src/crypto/mod.rs

deleted100644 → 0
+0 −28
Original line number Diff line number Diff line
// Copyright 2011 Google Inc.
//           2013 Jack Lloyd
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

mod util;
pub mod dsa;
pub mod hash;
pub mod memcmp;
pub mod pkcs12;
pub mod pkcs5;
pub mod pkey;
pub mod rand;
pub mod rsa;
pub mod sign;
pub mod symm;
+25 −25
Original line number Diff line number Diff line
@@ -7,15 +7,15 @@ use libc::{c_int, c_char, c_void};
use {cvt, cvt_p};
use bn::BigNumRef;
use bio::{MemBio, MemBioSlice};
use crypto::util::{CallbackState, invoke_passwd_cb};
use util::{CallbackState, invoke_passwd_cb};

/// Builder for upfront DSA parameter generation
pub struct DSAParams(*mut ffi::DSA);
pub struct DsaParams(*mut ffi::DSA);

impl DSAParams {
    pub fn with_size(size: u32) -> Result<DSAParams, ErrorStack> {
impl DsaParams {
    pub fn with_size(size: u32) -> Result<DsaParams, ErrorStack> {
        unsafe {
            let dsa = DSAParams(try!(cvt_p(ffi::DSA_new())));
            let dsa = DsaParams(try!(cvt_p(ffi::DSA_new())));
            try!(cvt(ffi::DSA_generate_parameters_ex(dsa.0,
                                                     size as c_int,
                                                     ptr::null(),
@@ -28,17 +28,17 @@ impl DSAParams {
    }

    /// Generate a key pair from the initialized parameters
    pub fn generate(self) -> Result<DSA, ErrorStack> {
    pub fn generate(self) -> Result<Dsa, ErrorStack> {
        unsafe {
            try!(cvt(ffi::DSA_generate_key(self.0)));
            let dsa = DSA(self.0);
            let dsa = Dsa(self.0);
            ::std::mem::forget(self);
            Ok(dsa)
        }
    }
}

impl Drop for DSAParams {
impl Drop for DsaParams {
    fn drop(&mut self) {
        unsafe {
            ffi::DSA_free(self.0);
@@ -46,9 +46,9 @@ impl Drop for DSAParams {
    }
}

pub struct DSA(*mut ffi::DSA);
pub struct Dsa(*mut ffi::DSA);

impl Drop for DSA {
impl Drop for Dsa {
    fn drop(&mut self) {
        unsafe {
            ffi::DSA_free(self.0);
@@ -56,20 +56,20 @@ impl Drop for DSA {
    }
}

impl DSA {
    pub unsafe fn from_ptr(dsa: *mut ffi::DSA) -> DSA {
        DSA(dsa)
impl Dsa {
    pub unsafe fn from_ptr(dsa: *mut ffi::DSA) -> Dsa {
        Dsa(dsa)
    }

    /// Generate a DSA key pair
    /// For more complicated key generation scenarios see the `DSAParams` type
    pub fn generate(size: u32) -> Result<DSA, ErrorStack> {
        let params = try!(DSAParams::with_size(size));
    pub fn generate(size: u32) -> Result<Dsa, ErrorStack> {
        let params = try!(DsaParams::with_size(size));
        params.generate()
    }

    /// Reads a DSA private key from PEM formatted data.
    pub fn private_key_from_pem(buf: &[u8]) -> Result<DSA, ErrorStack> {
    pub fn private_key_from_pem(buf: &[u8]) -> Result<Dsa, ErrorStack> {
        ffi::init();
        let mem_bio = try!(MemBioSlice::new(buf));

@@ -78,7 +78,7 @@ impl DSA {
                                                                 ptr::null_mut(),
                                                                 None,
                                                                 ptr::null_mut())));
            Ok(DSA(dsa))
            Ok(Dsa(dsa))
        }
    }

@@ -87,7 +87,7 @@ impl DSA {
    ///
    /// The callback will be passed the password buffer and should return the number of characters
    /// placed into the buffer.
    pub fn private_key_from_pem_cb<F>(buf: &[u8], pass_cb: F) -> Result<DSA, ErrorStack>
    pub fn private_key_from_pem_cb<F>(buf: &[u8], pass_cb: F) -> Result<Dsa, ErrorStack>
        where F: FnOnce(&mut [c_char]) -> usize
    {
        ffi::init();
@@ -100,7 +100,7 @@ impl DSA {
                                                                 ptr::null_mut(),
                                                                 Some(invoke_passwd_cb::<F>),
                                                                 cb_ptr)));
            Ok(DSA(dsa))
            Ok(Dsa(dsa))
        }
    }

@@ -120,7 +120,7 @@ impl DSA {
    }

    /// Reads an DSA public key from PEM formatted data.
    pub fn public_key_from_pem(buf: &[u8]) -> Result<DSA, ErrorStack>
    pub fn public_key_from_pem(buf: &[u8]) -> Result<Dsa, ErrorStack>
    {
        ffi::init();

@@ -130,7 +130,7 @@ impl DSA {
                                                              ptr::null_mut(),
                                                              None,
                                                              ptr::null_mut())));
            Ok(DSA(dsa))
            Ok(Dsa(dsa))
        }
    }

@@ -228,7 +228,7 @@ mod compat {
    }
}

impl fmt::Debug for DSA {
impl fmt::Debug for Dsa {
    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
        write!(f, "DSA")
    }
@@ -242,14 +242,14 @@ mod test {

    #[test]
    pub fn test_generate() {
        DSA::generate(1024).unwrap();
        Dsa::generate(1024).unwrap();
    }

    #[test]
    pub fn test_password() {
        let mut password_queried = false;
        let key = include_bytes!("../../test/dsa-encrypted.pem");
        DSA::private_key_from_pem_cb(key, |password| {
        let key = include_bytes!("../test/dsa-encrypted.pem");
        Dsa::private_key_from_pem_cb(key, |password| {
            password_queried = true;
            password[0] = b'm' as c_char;
            password[1] = b'y' as c_char;
+3 −3
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@ use self::State::*;
/// Calculate a hash in one go.
///
/// ```
/// use openssl::crypto::hash::{hash, MessageDigest};
/// use openssl::hash::{hash, MessageDigest};
///
/// let data = b"\x42\xF4\x97\xE0";
/// let spec = b"\x7c\x43\x0f\x17\x8a\xef\xdf\x14\x87\xfe\xe7\x14\x4e\x96\x41\xe2";
@@ -88,7 +88,7 @@ use self::State::*;
/// Use the `Write` trait to supply the input in chunks.
///
/// ```
/// use openssl::crypto::hash::{Hasher, MessageDigest};
/// use openssl::hash::{Hasher, MessageDigest};
///
/// let data = [b"\x42\xF4", b"\x97\xE0"];
/// let spec = b"\x7c\x43\x0f\x17\x8a\xef\xdf\x14\x87\xfe\xe7\x14\x4e\x96\x41\xe2";
@@ -103,7 +103,7 @@ use self::State::*;
///
/// Don't actually use MD5 and SHA-1 hashes, they're not secure anymore.
///
/// Don't ever hash passwords, use `crypto::pkcs5` or bcrypt/scrypt instead.
/// Don't ever hash passwords, use the functions in the `pkcs5` module or bcrypt/scrypt instead.
pub struct Hasher {
    ctx: *mut ffi::EVP_MD_CTX,
    md: *const ffi::EVP_MD,
+13 −3
Original line number Diff line number Diff line
@@ -22,17 +22,27 @@ use error::ErrorStack;

mod macros;

pub mod asn1;
mod bio;
mod opaque;
mod util;
pub mod asn1;
pub mod bn;
pub mod crypto;
pub mod dh;
pub mod dsa;
pub mod error;
pub mod hash;
pub mod memcmp;
pub mod nid;
pub mod pkcs12;
pub mod pkcs5;
pub mod pkey;
pub mod rand;
pub mod rsa;
pub mod sign;
pub mod ssl;
pub mod symm;
pub mod version;
pub mod x509;
mod opaque;

pub fn cvt_p<T>(r: *mut T) -> Result<*mut T, ErrorStack> {
    if r.is_null() {
Loading