Merge pull request #31 from yjerem/master

Add new HashType RIPEMD160
This commit is contained in:
Steven Fackler 2014-08-04 14:50:13 -07:00
commit 2b0a778846
2 changed files with 23 additions and 8 deletions

View File

@ -8,7 +8,8 @@ pub enum HashType {
SHA224,
SHA256,
SHA384,
SHA512
SHA512,
RIPEMD160
}
#[allow(dead_code)]
@ -39,6 +40,7 @@ extern {
fn EVP_sha256() -> *const EVP_MD;
fn EVP_sha384() -> *const EVP_MD;
fn EVP_sha512() -> *const EVP_MD;
fn EVP_ripemd160() -> *const EVP_MD;
fn EVP_DigestInit(ctx: *mut EVP_MD_CTX, typ: *const EVP_MD);
fn EVP_DigestUpdate(ctx: *mut EVP_MD_CTX, data: *const u8, n: c_uint);
@ -54,6 +56,7 @@ pub fn evpmd(t: HashType) -> (*const EVP_MD, uint) {
SHA256 => (EVP_sha256(), 32u),
SHA384 => (EVP_sha384(), 48u),
SHA512 => (EVP_sha512(), 64u),
RIPEMD160 => (EVP_ripemd160(), 20u),
}
}
}
@ -184,4 +187,15 @@ mod tests {
hash_test(super::SHA256, test);
}
}
#[test]
fn test_ripemd160() {
let tests = [
HashTest("616263", "8eb208f7e05d987a9b044a8e98c6b087f15a0bfc")
];
for test in tests.iter() {
hash_test(super::RIPEMD160, test);
}
}
}

View File

@ -2,7 +2,7 @@ use libc::{c_char, c_int, c_uint};
use libc;
use std::mem;
use std::ptr;
use crypto::hash::{HashType, MD5, SHA1, SHA224, SHA256, SHA384, SHA512};
use crypto::hash::{HashType, MD5, SHA1, SHA224, SHA256, SHA384, SHA512, RIPEMD160};
#[allow(non_camel_case_types)]
pub type EVP_PKEY = *mut libc::c_void;
@ -70,6 +70,7 @@ fn openssl_hash_nid(hash: HashType) -> c_int {
SHA256 => 672, // NID_sha256
SHA384 => 673, // NID_sha384
SHA512 => 674, // NID_sha512
RIPEMD160 => 117, // NID_ripemd160
}
}