diff options
| author | Valerii Hiora <[email protected]> | 2014-09-28 08:15:51 +0300 |
|---|---|---|
| committer | Valerii Hiora <[email protected]> | 2014-09-30 08:21:31 +0300 |
| commit | 02637ec7d451c38792c42c5c2cb4d59505e13ced (patch) | |
| tree | 12a842f098c7cdbea5190097647666d34eabc093 /src/crypto/hmac.rs | |
| parent | Merge pull request #53 from vhbit/cert-gen (diff) | |
| download | rust-openssl-02637ec7d451c38792c42c5c2cb4d59505e13ced.tar.xz rust-openssl-02637ec7d451c38792c42c5c2cb4d59505e13ced.zip | |
single `ffi` module
Diffstat (limited to 'src/crypto/hmac.rs')
| -rw-r--r-- | src/crypto/hmac.rs | 46 |
1 files changed, 12 insertions, 34 deletions
diff --git a/src/crypto/hmac.rs b/src/crypto/hmac.rs index 5bf62586..0d945200 100644 --- a/src/crypto/hmac.rs +++ b/src/crypto/hmac.rs @@ -14,35 +14,13 @@ * limitations under the License. */ -use libc::{c_uchar, c_int, c_uint}; -use crypto::hash; - -#[allow(dead_code)] -#[allow(non_camel_case_types)] -#[repr(C)] -pub struct HMAC_CTX { - md: *mut hash::EVP_MD, - md_ctx: hash::EVP_MD_CTX, - i_ctx: hash::EVP_MD_CTX, - o_ctx: hash::EVP_MD_CTX, - key_length: c_uint, - key: [c_uchar, ..128] -} +use libc::{c_int, c_uint}; -#[link(name = "crypto")] -extern { - fn HMAC_CTX_init(ctx: *mut HMAC_CTX); - fn HMAC_Init_ex(ctx: *mut HMAC_CTX, key: *const u8, keylen: c_int, md: *const hash::EVP_MD, imple: *const ENGINE); - fn HMAC_Update(ctx: *mut HMAC_CTX, input: *const u8, len: c_uint); - fn HMAC_Final(ctx: *mut HMAC_CTX, output: *mut u8, len: *mut c_uint); -} - -#[allow(non_camel_case_types)] -#[repr(C)] -struct ENGINE; +use crypto::hash; +use ffi; pub struct HMAC { - ctx: HMAC_CTX, + ctx: ffi::HMAC_CTX, len: uint, } @@ -51,13 +29,13 @@ pub fn HMAC(ht: hash::HashType, key: &[u8]) -> HMAC { unsafe { let (evp, mdlen) = hash::evpmd(ht); - let mut ctx : HMAC_CTX = ::std::mem::uninitialized(); + let mut ctx : ffi::HMAC_CTX = ::std::mem::uninitialized(); - HMAC_CTX_init(&mut ctx); - HMAC_Init_ex(&mut ctx, - key.as_ptr(), - key.len() as c_int, - evp, 0 as *const _); + ffi::HMAC_CTX_init(&mut ctx); + ffi::HMAC_Init_ex(&mut ctx, + key.as_ptr(), + key.len() as c_int, + evp, 0 as *const _); HMAC { ctx: ctx, len: mdlen } } @@ -66,7 +44,7 @@ pub fn HMAC(ht: hash::HashType, key: &[u8]) -> HMAC { impl HMAC { pub fn update(&mut self, data: &[u8]) { unsafe { - HMAC_Update(&mut self.ctx, data.as_ptr(), data.len() as c_uint) + ffi::HMAC_Update(&mut self.ctx, data.as_ptr(), data.len() as c_uint) } } @@ -74,7 +52,7 @@ impl HMAC { unsafe { let mut res = Vec::from_elem(self.len, 0u8); let mut outlen = 0; - HMAC_Final(&mut self.ctx, res.as_mut_ptr(), &mut outlen); + ffi::HMAC_Final(&mut self.ctx, res.as_mut_ptr(), &mut outlen); assert!(self.len == outlen as uint) res } |