Flatten crypto module

This commit is contained in:
Steven Fackler 2016-10-22 09:16:38 -07:00
parent 58f6d1138a
commit 98b7f2f935
17 changed files with 57 additions and 75 deletions

View File

@ -1,28 +0,0 @@
// 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;

View File

@ -7,7 +7,7 @@ use libc::{c_int, c_char, c_void};
use {cvt, cvt_p}; use {cvt, cvt_p};
use bn::BigNumRef; use bn::BigNumRef;
use bio::{MemBio, MemBioSlice}; use bio::{MemBio, MemBioSlice};
use crypto::util::{CallbackState, invoke_passwd_cb}; use util::{CallbackState, invoke_passwd_cb};
/// Builder for upfront DSA parameter generation /// Builder for upfront DSA parameter generation
pub struct DSAParams(*mut ffi::DSA); pub struct DSAParams(*mut ffi::DSA);
@ -248,7 +248,7 @@ mod test {
#[test] #[test]
pub fn test_password() { pub fn test_password() {
let mut password_queried = false; let mut password_queried = false;
let key = include_bytes!("../../test/dsa-encrypted.pem"); let key = include_bytes!("../test/dsa-encrypted.pem");
DSA::private_key_from_pem_cb(key, |password| { DSA::private_key_from_pem_cb(key, |password| {
password_queried = true; password_queried = true;
password[0] = b'm' as c_char; password[0] = b'm' as c_char;

View File

@ -22,17 +22,27 @@ use error::ErrorStack;
mod macros; mod macros;
pub mod asn1;
mod bio; mod bio;
mod opaque;
mod util;
pub mod asn1;
pub mod bn; pub mod bn;
pub mod crypto;
pub mod dh; pub mod dh;
pub mod dsa;
pub mod error; pub mod error;
pub mod hash;
pub mod memcmp;
pub mod nid; 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 ssl;
pub mod symm;
pub mod version; pub mod version;
pub mod x509; pub mod x509;
mod opaque;
pub fn cvt_p<T>(r: *mut T) -> Result<*mut T, ErrorStack> { pub fn cvt_p<T>(r: *mut T) -> Result<*mut T, ErrorStack> {
if r.is_null() { if r.is_null() {

View File

@ -7,7 +7,7 @@ use std::ptr;
use std::ffi::CString; use std::ffi::CString;
use {cvt, cvt_p}; use {cvt, cvt_p};
use crypto::pkey::PKey; use pkey::PKey;
use error::ErrorStack; use error::ErrorStack;
use x509::X509; use x509::X509;
@ -98,14 +98,14 @@ mod compat {
#[cfg(test)] #[cfg(test)]
mod test { mod test {
use crypto::hash::MessageDigest; use hash::MessageDigest;
use serialize::hex::ToHex; use serialize::hex::ToHex;
use super::*; use super::*;
#[test] #[test]
fn parse() { fn parse() {
let der = include_bytes!("../../test/identity.p12"); let der = include_bytes!("../test/identity.p12");
let pkcs12 = Pkcs12::from_der(der).unwrap(); let pkcs12 = Pkcs12::from_der(der).unwrap();
let parsed = pkcs12.parse("mypass").unwrap(); let parsed = pkcs12.parse("mypass").unwrap();

View File

@ -3,8 +3,8 @@ use std::ptr;
use ffi; use ffi;
use cvt; use cvt;
use crypto::hash::MessageDigest; use hash::MessageDigest;
use crypto::symm::Cipher; use symm::Cipher;
use error::ErrorStack; use error::ErrorStack;
#[derive(Clone, Eq, PartialEq, Hash, Debug)] #[derive(Clone, Eq, PartialEq, Hash, Debug)]
@ -98,8 +98,8 @@ pub fn pbkdf2_hmac(pass: &[u8],
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use crypto::hash::MessageDigest; use hash::MessageDigest;
use crypto::symm::Cipher; use symm::Cipher;
// Test vectors from // Test vectors from
// https://git.lysator.liu.se/nettle/nettle/blob/nettle_3.1.1_release_20150424/testsuite/pbkdf2-test.c // https://git.lysator.liu.se/nettle/nettle/blob/nettle_3.1.1_release_20150424/testsuite/pbkdf2-test.c

View File

@ -5,10 +5,10 @@ use ffi;
use {cvt, cvt_p}; use {cvt, cvt_p};
use bio::{MemBio, MemBioSlice}; use bio::{MemBio, MemBioSlice};
use crypto::dsa::DSA; use dsa::DSA;
use crypto::rsa::RSA; use rsa::RSA;
use error::ErrorStack; use error::ErrorStack;
use crypto::util::{CallbackState, invoke_passwd_cb}; use util::{CallbackState, invoke_passwd_cb};
pub struct PKey(*mut ffi::EVP_PKEY); pub struct PKey(*mut ffi::EVP_PKEY);
@ -167,19 +167,19 @@ impl Drop for PKey {
mod tests { mod tests {
#[test] #[test]
fn test_private_key_from_pem() { fn test_private_key_from_pem() {
let key = include_bytes!("../../test/key.pem"); let key = include_bytes!("../test/key.pem");
super::PKey::private_key_from_pem(key).unwrap(); super::PKey::private_key_from_pem(key).unwrap();
} }
#[test] #[test]
fn test_public_key_from_pem() { fn test_public_key_from_pem() {
let key = include_bytes!("../../test/key.pem.pub"); let key = include_bytes!("../test/key.pem.pub");
super::PKey::public_key_from_pem(key).unwrap(); super::PKey::public_key_from_pem(key).unwrap();
} }
#[test] #[test]
fn test_pem() { fn test_pem() {
let key = include_bytes!("../../test/key.pem"); let key = include_bytes!("../test/key.pem");
let key = super::PKey::private_key_from_pem(key).unwrap(); let key = super::PKey::private_key_from_pem(key).unwrap();
let priv_key = key.private_key_to_pem().unwrap(); let priv_key = key.private_key_to_pem().unwrap();

View File

@ -8,7 +8,7 @@ use {cvt, cvt_p, cvt_n};
use bn::{BigNum, BigNumRef}; use bn::{BigNum, BigNumRef};
use bio::{MemBio, MemBioSlice}; use bio::{MemBio, MemBioSlice};
use error::ErrorStack; use error::ErrorStack;
use crypto::util::{CallbackState, invoke_passwd_cb}; use util::{CallbackState, invoke_passwd_cb};
/// Type of encryption padding to use. /// Type of encryption padding to use.
#[derive(Copy, Clone)] #[derive(Copy, Clone)]
@ -421,7 +421,7 @@ mod test {
#[test] #[test]
pub fn test_password() { pub fn test_password() {
let mut password_queried = false; let mut password_queried = false;
let key = include_bytes!("../../test/rsa-encrypted.pem"); let key = include_bytes!("../test/rsa-encrypted.pem");
RSA::private_key_from_pem_cb(key, |password| { RSA::private_key_from_pem_cb(key, |password| {
password_queried = true; password_queried = true;
password[0] = b'm' as c_char; password[0] = b'm' as c_char;
@ -438,7 +438,7 @@ mod test {
#[test] #[test]
pub fn test_public_encrypt_private_decrypt_with_padding() { pub fn test_public_encrypt_private_decrypt_with_padding() {
let key = include_bytes!("../../test/rsa.pem.pub"); let key = include_bytes!("../test/rsa.pem.pub");
let public_key = RSA::public_key_from_pem(key).unwrap(); let public_key = RSA::public_key_from_pem(key).unwrap();
let mut result = vec![0; public_key.size()]; let mut result = vec![0; public_key.size()];
@ -446,7 +446,7 @@ mod test {
let len = public_key.public_encrypt(original_data, &mut result, Padding::pkcs1()).unwrap(); let len = public_key.public_encrypt(original_data, &mut result, Padding::pkcs1()).unwrap();
assert_eq!(len, 256); assert_eq!(len, 256);
let pkey = include_bytes!("../../test/rsa.pem"); let pkey = include_bytes!("../test/rsa.pem");
let private_key = RSA::private_key_from_pem(pkey).unwrap(); let private_key = RSA::private_key_from_pem(pkey).unwrap();
let mut dec_result = vec![0; private_key.size()]; let mut dec_result = vec![0; private_key.size()];
let len = private_key.private_decrypt(&result, &mut dec_result, Padding::pkcs1()).unwrap(); let len = private_key.private_decrypt(&result, &mut dec_result, Padding::pkcs1()).unwrap();

View File

@ -60,8 +60,8 @@ use std::marker::PhantomData;
use std::ptr; use std::ptr;
use {cvt, cvt_p}; use {cvt, cvt_p};
use crypto::hash::MessageDigest; use hash::MessageDigest;
use crypto::pkey::PKey; use pkey::PKey;
use error::ErrorStack; use error::ErrorStack;
#[cfg(ossl110)] #[cfg(ossl110)]
@ -208,11 +208,11 @@ mod test {
use serialize::hex::FromHex; use serialize::hex::FromHex;
use std::iter; use std::iter;
use crypto::hash::MessageDigest; use hash::MessageDigest;
use crypto::sign::{Signer, Verifier}; use sign::{Signer, Verifier};
use crypto::rsa::RSA; use rsa::RSA;
use crypto::dsa::DSA; use dsa::DSA;
use crypto::pkey::PKey; use pkey::PKey;
static INPUT: &'static [u8] = static INPUT: &'static [u8] =
&[101, 121, 74, 104, 98, 71, 99, 105, 79, 105, 74, 83, 85, 122, 73, 49, 78, 105, 74, 57, &[101, 121, 74, 104, 98, 71, 99, 105, 79, 105, 74, 83, 85, 122, 73, 49, 78, 105, 74, 57,
@ -240,7 +240,7 @@ mod test {
#[test] #[test]
fn rsa_sign() { fn rsa_sign() {
let key = include_bytes!("../../test/rsa.pem"); let key = include_bytes!("../test/rsa.pem");
let private_key = RSA::private_key_from_pem(key).unwrap(); let private_key = RSA::private_key_from_pem(key).unwrap();
let pkey = PKey::from_rsa(private_key).unwrap(); let pkey = PKey::from_rsa(private_key).unwrap();
@ -253,7 +253,7 @@ mod test {
#[test] #[test]
fn rsa_verify_ok() { fn rsa_verify_ok() {
let key = include_bytes!("../../test/rsa.pem"); let key = include_bytes!("../test/rsa.pem");
let private_key = RSA::private_key_from_pem(key).unwrap(); let private_key = RSA::private_key_from_pem(key).unwrap();
let pkey = PKey::from_rsa(private_key).unwrap(); let pkey = PKey::from_rsa(private_key).unwrap();
@ -264,7 +264,7 @@ mod test {
#[test] #[test]
fn rsa_verify_invalid() { fn rsa_verify_invalid() {
let key = include_bytes!("../../test/rsa.pem"); let key = include_bytes!("../test/rsa.pem");
let private_key = RSA::private_key_from_pem(key).unwrap(); let private_key = RSA::private_key_from_pem(key).unwrap();
let pkey = PKey::from_rsa(private_key).unwrap(); let pkey = PKey::from_rsa(private_key).unwrap();
@ -279,12 +279,12 @@ mod test {
let input: Vec<u8> = (0..25).cycle().take(1024).collect(); let input: Vec<u8> = (0..25).cycle().take(1024).collect();
let private_key = { let private_key = {
let key = include_bytes!("../../test/dsa.pem"); let key = include_bytes!("../test/dsa.pem");
PKey::from_dsa(DSA::private_key_from_pem(key).unwrap()).unwrap() PKey::from_dsa(DSA::private_key_from_pem(key).unwrap()).unwrap()
}; };
let public_key = { let public_key = {
let key = include_bytes!("../../test/dsa.pem.pub"); let key = include_bytes!("../test/dsa.pem.pub");
PKey::from_dsa(DSA::public_key_from_pem(key).unwrap()).unwrap() PKey::from_dsa(DSA::public_key_from_pem(key).unwrap()).unwrap()
}; };
@ -302,12 +302,12 @@ mod test {
let input: Vec<u8> = (0..25).cycle().take(1024).collect(); let input: Vec<u8> = (0..25).cycle().take(1024).collect();
let private_key = { let private_key = {
let key = include_bytes!("../../test/dsa.pem"); let key = include_bytes!("../test/dsa.pem");
PKey::from_dsa(DSA::private_key_from_pem(key).unwrap()).unwrap() PKey::from_dsa(DSA::private_key_from_pem(key).unwrap()).unwrap()
}; };
let public_key = { let public_key = {
let key = include_bytes!("../../test/dsa.pem.pub"); let key = include_bytes!("../test/dsa.pem.pub");
PKey::from_dsa(DSA::public_key_from_pem(key).unwrap()).unwrap() PKey::from_dsa(DSA::public_key_from_pem(key).unwrap()).unwrap()
}; };

View File

@ -24,7 +24,7 @@ use dh::DH;
use x509::{X509StoreContextRef, X509FileType, X509, X509Ref, X509VerifyError}; use x509::{X509StoreContextRef, X509FileType, X509, X509Ref, X509VerifyError};
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))] #[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
use x509::verify::X509VerifyParamRef; use x509::verify::X509VerifyParamRef;
use crypto::pkey::PKey; use pkey::PKey;
use error::ErrorStack; use error::ErrorStack;
use opaque::Opaque; use opaque::Opaque;

View File

@ -14,7 +14,7 @@ use std::time::Duration;
use tempdir::TempDir; use tempdir::TempDir;
use crypto::hash::MessageDigest; use hash::MessageDigest;
use ssl; use ssl;
use ssl::SSL_VERIFY_PEER; use ssl::SSL_VERIFY_PEER;
use ssl::{SslMethod, HandshakeError}; use ssl::{SslMethod, HandshakeError};
@ -25,7 +25,7 @@ use x509::X509FileType;
use x509::X509; use x509::X509;
#[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))] #[cfg(any(all(feature = "v102", ossl102), all(feature = "v110", ossl110)))]
use x509::verify::X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS; use x509::verify::X509_CHECK_FLAG_NO_PARTIAL_WILDCARDS;
use crypto::pkey::PKey; use pkey::PKey;
use std::net::UdpSocket; use std::net::UdpSocket;
@ -167,7 +167,7 @@ macro_rules! run_test(
use ssl::SslMethod; use ssl::SslMethod;
use ssl::{SslContext, Ssl, SslStream}; use ssl::{SslContext, Ssl, SslStream};
use ssl::SSL_VERIFY_PEER; use ssl::SSL_VERIFY_PEER;
use crypto::hash::MessageDigest; use hash::MessageDigest;
use x509::X509StoreContextRef; use x509::X509StoreContextRef;
use serialize::hex::FromHex; use serialize::hex::FromHex;
use super::Server; use super::Server;
@ -774,7 +774,7 @@ mod dtlsv1 {
use std::net::TcpStream; use std::net::TcpStream;
use std::thread; use std::thread;
use crypto::hash::MessageDigest; use hash::MessageDigest;
use ssl::SslMethod; use ssl::SslMethod;
use ssl::{SslContext, SslStream}; use ssl::{SslContext, SslStream};
use ssl::SSL_VERIFY_PEER; use ssl::SSL_VERIFY_PEER;

View File

@ -15,9 +15,9 @@ use {cvt, cvt_p};
use asn1::Asn1Time; use asn1::Asn1Time;
use asn1::Asn1TimeRef; use asn1::Asn1TimeRef;
use bio::{MemBio, MemBioSlice}; use bio::{MemBio, MemBioSlice};
use crypto::hash::MessageDigest; use hash::MessageDigest;
use crypto::pkey::PKey; use pkey::PKey;
use crypto::rand::rand_bytes; use rand::rand_bytes;
use error::ErrorStack; use error::ErrorStack;
use ffi; use ffi;
use nid::Nid; use nid::Nid;

View File

@ -1,8 +1,8 @@
use serialize::hex::FromHex; use serialize::hex::FromHex;
use crypto::hash::MessageDigest; use hash::MessageDigest;
use crypto::pkey::PKey; use pkey::PKey;
use crypto::rsa::RSA; use rsa::RSA;
use x509::{X509, X509Generator}; use x509::{X509, X509Generator};
use x509::extension::Extension::{KeyUsage, ExtKeyUsage, SubjectAltName, OtherNid, OtherStr}; use x509::extension::Extension::{KeyUsage, ExtKeyUsage, SubjectAltName, OtherNid, OtherStr};
use x509::extension::AltNameOption as SAN; use x509::extension::AltNameOption as SAN;