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

Merge pull request #474 from sfackler/digest

Signature/Digest API
parents 64b8e5e5 4ed81d64
Loading
Loading
Loading
Loading
+28 −0
Original line number Diff line number Diff line
@@ -109,6 +109,7 @@ pub const CRYPTO_LOCK: c_int = 1;

pub const EVP_MAX_MD_SIZE: c_uint = 64;
pub const EVP_PKEY_RSA: c_int = NID_rsaEncryption;
pub const EVP_PKEY_HMAC: c_int = NID_hmac;

pub const MBSTRING_ASC:  c_int = MBSTRING_FLAG | 1;
pub const MBSTRING_BMP:  c_int = MBSTRING_FLAG | 2;
@@ -119,6 +120,7 @@ pub const MBSTRING_UTF8: c_int = MBSTRING_FLAG;
pub const NID_rsaEncryption: c_int = 6;
pub const NID_ext_key_usage: c_int = 126;
pub const NID_key_usage:     c_int = 83;
pub const NID_hmac:          c_int = 855;

pub const PKCS5_SALT_LEN: c_int = 8;

@@ -489,6 +491,28 @@ extern {
    pub fn EVP_DigestFinal(ctx: *mut EVP_MD_CTX, res: *mut u8, n: *mut u32) -> c_int;
    pub fn EVP_DigestFinal_ex(ctx: *mut EVP_MD_CTX, res: *mut u8, n: *mut u32) -> c_int;

    pub fn EVP_DigestSignInit(ctx: *mut EVP_MD_CTX,
                              pctx: *mut *mut EVP_PKEY_CTX,
                              type_: *const EVP_MD,
                              e: *mut ENGINE,
                              pkey: *mut EVP_PKEY) -> c_int;
    pub fn EVP_DigestSignFinal(ctx: *mut EVP_MD_CTX,
                               sig: *mut c_uchar,
                               siglen: *mut size_t) -> c_int;
    pub fn EVP_DigestVerifyInit(ctx: *mut EVP_MD_CTX,
                                pctx: *mut *mut EVP_PKEY_CTX,
                                type_: *const EVP_MD,
                                e: *mut ENGINE,
                                pkey: *mut EVP_PKEY) -> c_int;
    #[cfg(ossl101)]
    pub fn EVP_DigestVerifyFinal(ctx: *mut EVP_MD_CTX,
                                 sigret: *mut c_uchar,
                                 siglen: size_t) -> c_int;
    #[cfg(not(ossl101))]
    pub fn EVP_DigestVerifyFinal(ctx: *mut EVP_MD_CTX,
                                 sigret: *const c_uchar,
                                 siglen: size_t) -> c_int;

    pub fn EVP_MD_CTX_copy_ex(dst: *mut EVP_MD_CTX, src: *const EVP_MD_CTX) -> c_int;

    pub fn EVP_PKEY_new() -> *mut EVP_PKEY;
@@ -498,6 +522,10 @@ extern {
    pub fn EVP_PKEY_get1_RSA(k: *mut EVP_PKEY) -> *mut RSA;
    pub fn EVP_PKEY_set1_RSA(k: *mut EVP_PKEY, r: *mut RSA) -> c_int;
    pub fn EVP_PKEY_cmp(a: *const EVP_PKEY, b: *const EVP_PKEY) -> c_int;
    pub fn EVP_PKEY_new_mac_key(type_: c_int,
                                e: *mut ENGINE,
                                key: *const c_uchar,
                                keylen: c_int) -> *mut EVP_PKEY;

    pub fn HMAC_CTX_copy(dst: *mut HMAC_CTX, src: *mut HMAC_CTX) -> c_int;

+3 −1
Original line number Diff line number Diff line
@@ -2,7 +2,9 @@ use std::sync::{Mutex, MutexGuard};
use std::sync::{Once, ONCE_INIT};
use std::mem;

use libc::{c_int, c_char, c_void, c_long, c_uchar, size_t, c_uint, c_ulong, time_t};
use libc::{c_int, c_char, c_void, c_long, c_uchar, size_t, c_uint, c_ulong};
#[cfg(not(ossl101))]
use libc::time_t;

#[repr(C)]
pub struct stack_st_ASN1_OBJECT {

openssl/src/crypto/hmac.rs

deleted100644 → 0
+0 −565

File deleted.

Preview size limit exceeded, changes collapsed.

+7 −6
Original line number Diff line number Diff line
@@ -14,14 +14,15 @@
// limitations under the License.
//

mod util;
pub mod dsa;
pub mod hash;
pub mod hmac;
pub mod pkcs5;
pub mod memcmp;
pub mod pkcs12;
pub mod pkcs5;
pub mod pkey;
pub mod rand;
pub mod symm;
pub mod memcmp;
pub mod rsa;
pub mod dsa;
mod util;
pub mod sign;
pub mod symm;
+13 −1
Original line number Diff line number Diff line
use libc::{c_void, c_char};
use libc::{c_void, c_char, c_int};
use std::ptr;
use std::mem;
use ffi;
@@ -26,6 +26,18 @@ impl PKey {
        }
    }

    /// Create a new `PKey` containing an HMAC key.
    pub fn hmac(key: &[u8]) -> Result<PKey, ErrorStack> {
        unsafe {
            assert!(key.len() <= c_int::max_value() as usize);
            let key = try_ssl_null!(ffi::EVP_PKEY_new_mac_key(ffi::EVP_PKEY_HMAC,
                                                              ptr::null_mut(),
                                                              key.as_ptr() as *const _,
                                                              key.len() as c_int));
            Ok(PKey(key))
        }
    }

    pub unsafe fn from_ptr(handle: *mut ffi::EVP_PKEY) -> PKey {
        PKey(handle)
    }
Loading