Commit 9f2a9c85 authored by Jeremy Ruten's avatar Jeremy Ruten
Browse files

Add new HashType RIPEMD160

parent 0c41d3b1
Loading
Loading
Loading
Loading
+15 −1
Original line number Diff line number Diff line
@@ -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);
        }
    }
}
+8 −7
Original line number Diff line number Diff line
@@ -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
    }
}