diff options
| author | Steven Fackler <[email protected]> | 2016-08-09 22:52:12 -0700 |
|---|---|---|
| committer | Steven Fackler <[email protected]> | 2016-08-09 22:52:12 -0700 |
| commit | 67b5b4d814066eaf0debbe3b95d68ae0d7b9226a (patch) | |
| tree | f8c2565e72f41cab21bead5aadadbbdb17dd7afe /openssl/src | |
| parent | Fix build (diff) | |
| download | rust-openssl-67b5b4d814066eaf0debbe3b95d68ae0d7b9226a.tar.xz rust-openssl-67b5b4d814066eaf0debbe3b95d68ae0d7b9226a.zip | |
Make hmac support optional and remove openssl-sys-extras
rust-openssl no longer requires headers for the default feature set.
Diffstat (limited to 'openssl/src')
| -rw-r--r-- | openssl/src/c_helpers.c | 34 | ||||
| -rw-r--r-- | openssl/src/c_helpers.rs | 5 | ||||
| -rw-r--r-- | openssl/src/crypto/hmac.rs | 36 | ||||
| -rw-r--r-- | openssl/src/crypto/mod.rs | 1 | ||||
| -rw-r--r-- | openssl/src/lib.rs | 1 |
5 files changed, 59 insertions, 18 deletions
diff --git a/openssl/src/c_helpers.c b/openssl/src/c_helpers.c index f8bc2d0d..4a2021e4 100644 --- a/openssl/src/c_helpers.c +++ b/openssl/src/c_helpers.c @@ -1,4 +1,7 @@ +#include <openssl/hmac.h> #include <openssl/ssl.h> +#include <openssl/dh.h> +#include <openssl/bn.h> void rust_SSL_CTX_clone(SSL_CTX *ctx) { CRYPTO_add(&ctx->references,1,CRYPTO_LOCK_SSL_CTX); @@ -11,3 +14,34 @@ void rust_X509_clone(X509 *x509) { STACK_OF(X509_EXTENSION) *rust_X509_get_extensions(X509 *x) { return x->cert_info ? x->cert_info->extensions : NULL; } + +#if OPENSSL_VERSION_NUMBER < 0x10000000L +int rust_HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len, const EVP_MD *md, ENGINE *impl) { + HMAC_Init_ex(ctx, key, key_len, md, impl); + return 1; +} + +int rust_HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len) { + HMAC_Update(ctx, data, len); + return 1; +} + +int rust_HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len) { + HMAC_Final(ctx, md, len); + return 1; +} + +#else + +int rust_HMAC_Init_ex(HMAC_CTX *ctx, const void *key, int key_len, const EVP_MD *md, ENGINE *impl) { + return HMAC_Init_ex(ctx, key, key_len, md, impl); +} + +int rust_HMAC_Update(HMAC_CTX *ctx, const unsigned char *data, int len) { + return HMAC_Update(ctx, data, len); +} + +int rust_HMAC_Final(HMAC_CTX *ctx, unsigned char *md, unsigned int *len) { + return HMAC_Final(ctx, md, len); +} +#endif diff --git a/openssl/src/c_helpers.rs b/openssl/src/c_helpers.rs index f074d404..a195d88f 100644 --- a/openssl/src/c_helpers.rs +++ b/openssl/src/c_helpers.rs @@ -1,8 +1,13 @@ use ffi; +use libc::{c_int, c_void, c_uint, c_uchar}; #[allow(dead_code)] extern "C" { pub fn rust_SSL_CTX_clone(cxt: *mut ffi::SSL_CTX); pub fn rust_X509_clone(x509: *mut ffi::X509); pub fn rust_X509_get_extensions(x: *mut ffi::X509) -> *mut ffi::stack_st_X509_EXTENSION; + + pub fn rust_HMAC_Init_ex(ctx: *mut ffi::HMAC_CTX, key: *const c_void, keylen: c_int, md: *const ffi::EVP_MD, impl_: *mut ffi::ENGINE) -> c_int; + pub fn rust_HMAC_Final(ctx: *mut ffi::HMAC_CTX, output: *mut c_uchar, len: *mut c_uint) -> c_int; + pub fn rust_HMAC_Update(ctx: *mut ffi::HMAC_CTX, input: *const c_uchar, len: c_uint) -> c_int; } diff --git a/openssl/src/crypto/hmac.rs b/openssl/src/crypto/hmac.rs index 453511ac..857be339 100644 --- a/openssl/src/crypto/hmac.rs +++ b/openssl/src/crypto/hmac.rs @@ -18,11 +18,11 @@ use std::io; use std::io::prelude::*; use std::cmp; use ffi; -use ffi_extras; use HashTypeInternals; use crypto::hash::Type; use error::ErrorStack; +use c_helpers; #[derive(PartialEq, Copy, Clone)] enum State { @@ -35,6 +35,8 @@ use self::State::*; /// Provides HMAC computation. /// +/// Requires the `hmac` feature. +/// /// # Examples /// /// Calculate a HMAC in one go. @@ -65,7 +67,6 @@ use self::State::*; /// ``` pub struct HMAC { ctx: ffi::HMAC_CTX, - type_: Type, state: State, } @@ -83,7 +84,6 @@ impl HMAC { let mut h = HMAC { ctx: ctx, - type_: ty, state: Finalized, }; try!(h.init_once(md, key)); @@ -92,11 +92,11 @@ impl HMAC { fn init_once(&mut self, md: *const ffi::EVP_MD, key: &[u8]) -> Result<(), ErrorStack> { unsafe { - try_ssl!(ffi_extras::HMAC_Init_ex(&mut self.ctx, - key.as_ptr(), - key.len() as c_int, - md, - 0 as *const _)); + try_ssl!(c_helpers::rust_HMAC_Init_ex(&mut self.ctx, + key.as_ptr() as *const _, + key.len() as c_int, + md, + 0 as *mut _)); } self.state = Reset; Ok(()) @@ -113,11 +113,11 @@ impl HMAC { // If the key and/or md is not supplied it's reused from the last time // avoiding redundant initializations unsafe { - try_ssl!(ffi_extras::HMAC_Init_ex(&mut self.ctx, - 0 as *const _, - 0, - 0 as *const _, - 0 as *const _)); + try_ssl!(c_helpers::rust_HMAC_Init_ex(&mut self.ctx, + 0 as *const _, + 0, + 0 as *const _, + 0 as *mut _)); } self.state = Reset; Ok(()) @@ -130,7 +130,7 @@ impl HMAC { while !data.is_empty() { let len = cmp::min(data.len(), c_uint::max_value() as usize); unsafe { - try_ssl!(ffi_extras::HMAC_Update(&mut self.ctx, data.as_ptr(), len as c_uint)); + try_ssl!(c_helpers::rust_HMAC_Update(&mut self.ctx, data.as_ptr(), len as c_uint)); } data = &data[len..]; } @@ -147,7 +147,7 @@ impl HMAC { unsafe { let mut len = ffi::EVP_MAX_MD_SIZE; let mut res = vec![0; len as usize]; - try_ssl!(ffi_extras::HMAC_Final(&mut self.ctx, res.as_mut_ptr(), &mut len)); + try_ssl!(c_helpers::rust_HMAC_Final(&mut self.ctx, res.as_mut_ptr(), &mut len)); res.truncate(len as usize); self.state = Finalized; Ok(res) @@ -167,17 +167,18 @@ impl Write for HMAC { } } +#[cfg(feature = "hmac_clone")] impl Clone for HMAC { + /// Requires the `hmac_clone` feature. fn clone(&self) -> HMAC { let mut ctx: ffi::HMAC_CTX; unsafe { ctx = ::std::mem::uninitialized(); - let r = ffi_extras::HMAC_CTX_copy(&mut ctx, &self.ctx); + let r = ffi::HMAC_CTX_copy(&mut ctx, &self.ctx); assert_eq!(r, 1); } HMAC { ctx: ctx, - type_: self.type_, state: self.state, } } @@ -288,6 +289,7 @@ mod tests { } #[test] + #[cfg(feature = "hmac_clone")] fn test_clone() { let tests: [(Vec<u8>, Vec<u8>, Vec<u8>); 2] = [(repeat(0xaa_u8).take(80).collect(), diff --git a/openssl/src/crypto/mod.rs b/openssl/src/crypto/mod.rs index 453291aa..93aba9eb 100644 --- a/openssl/src/crypto/mod.rs +++ b/openssl/src/crypto/mod.rs @@ -15,6 +15,7 @@ // pub mod hash; +#[cfg(feature = "hmac")] pub mod hmac; pub mod pkcs5; pub mod pkey; diff --git a/openssl/src/lib.rs b/openssl/src/lib.rs index 2f3664ac..fdf9548c 100644 --- a/openssl/src/lib.rs +++ b/openssl/src/lib.rs @@ -6,7 +6,6 @@ extern crate libc; #[macro_use] extern crate lazy_static; extern crate openssl_sys as ffi; -extern crate openssl_sys_extras as ffi_extras; #[cfg(test)] extern crate rustc_serialize as serialize; |