Commit 7103b6ad authored by jiegec's avatar jiegec
Browse files

Add sm3 cryptographic hash support

parent ad741f88
Loading
Loading
Loading
Loading
+2 −0
Original line number Diff line number Diff line
@@ -243,6 +243,8 @@ extern "C" {
    #[cfg(ossl111)]
    pub fn EVP_shake256() -> *const EVP_MD;
    pub fn EVP_ripemd160() -> *const EVP_MD;
    #[cfg(all(ossl111, not(osslconf = "OPENSSL_NO_SM3")))]
    pub fn EVP_sm3() -> *const EVP_MD;
    pub fn EVP_des_ecb() -> *const EVP_CIPHER;
    pub fn EVP_des_ede3() -> *const EVP_CIPHER;
    pub fn EVP_des_ede3_cbc() -> *const EVP_CIPHER;
+17 −0
Original line number Diff line number Diff line
@@ -128,6 +128,11 @@ impl MessageDigest {
        unsafe { MessageDigest(ffi::EVP_ripemd160()) }
    }

    #[cfg(all(ossl111, not(osslconf = "OPENSSL_NO_SM3")))]
    pub fn sm3() -> MessageDigest {
        unsafe { MessageDigest(ffi::EVP_sm3()) }
    }

    #[allow(clippy::trivially_copy_pass_by_ref)]
    pub fn as_ptr(&self) -> *const ffi::EVP_MD {
        self.0
@@ -626,6 +631,18 @@ mod tests {
        }
    }

    #[test]
    fn test_sm3() {
        let tests = [(
            "616263",
            "66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0",
        )];

        for test in tests.iter() {
            hash_test(MessageDigest::sm3(), test);
        }
    }

    #[test]
    fn from_nid() {
        assert_eq!(