summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Fackler <sfackler@gmail.com>2021-03-08 21:14:29 -0500
committerGitHub <noreply@github.com>2021-03-08 21:14:29 -0500
commitff94c7f5030a0fa012a37e76cd2fa2d8896360dc (patch)
treeae3b8a36ac7f52c7414cd9fd72af9f5a047d903b
parentad741f88f2136a82c0557179fb420cd6283b610a (diff)
parentfb5f94e0346135540dab354311f31561d84a5dee (diff)
downloadrust-openssl-master.zip
Merge pull request #1427 from jiegec/add-sm3HEADmaster
Add sm3 cryptographic hash support
-rw-r--r--openssl-sys/build/expando.c4
-rw-r--r--openssl-sys/src/evp.rs2
-rw-r--r--openssl-sys/src/obj_mac.rs8
-rw-r--r--openssl/src/hash.rs18
4 files changed, 32 insertions, 0 deletions
diff --git a/openssl-sys/build/expando.c b/openssl-sys/build/expando.c
index 2f8b1b4d..dd3dace0 100644
--- a/openssl-sys/build/expando.c
+++ b/openssl-sys/build/expando.c
@@ -81,3 +81,7 @@ RUST_CONF_OPENSSL_NO_TLSEXT
#ifdef OPENSSL_NO_STDIO
RUST_CONF_OPENSSL_NO_STDIO
#endif
+
+#ifdef OPENSSL_NO_SM3
+RUST_CONF_OPENSSL_NO_SM3
+#endif
diff --git a/openssl-sys/src/evp.rs b/openssl-sys/src/evp.rs
index ec5df30a..893e9828 100644
--- a/openssl-sys/src/evp.rs
+++ b/openssl-sys/src/evp.rs
@@ -243,6 +243,8 @@ extern "C" {
#[cfg(ossl111)]
pub fn EVP_shake256() -> *const EVP_MD;
pub fn EVP_ripemd160() -> *const EVP_MD;
+ #[cfg(all(any(ossl111, libressl291), 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;
diff --git a/openssl-sys/src/obj_mac.rs b/openssl-sys/src/obj_mac.rs
index d78416da..63f5cb38 100644
--- a/openssl-sys/src/obj_mac.rs
+++ b/openssl-sys/src/obj_mac.rs
@@ -920,3 +920,11 @@ pub const NID_X448: c_int = 1035;
pub const NID_ED25519: c_int = 1087;
#[cfg(ossl111)]
pub const NID_ED448: c_int = 1088;
+#[cfg(ossl111)]
+pub const NID_sm3: c_int = 1143;
+#[cfg(libressl291)]
+pub const NID_sm3: c_int = 968;
+#[cfg(ossl111)]
+pub const NID_sm3WithRSAEncryption: c_int = 1144;
+#[cfg(libressl291)]
+pub const NID_sm3WithRSAEncryption: c_int = 969;
diff --git a/openssl/src/hash.rs b/openssl/src/hash.rs
index 317d20e2..666022c7 100644
--- a/openssl/src/hash.rs
+++ b/openssl/src/hash.rs
@@ -128,6 +128,11 @@ impl MessageDigest {
unsafe { MessageDigest(ffi::EVP_ripemd160()) }
}
+ #[cfg(all(any(ossl111, libressl291), 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,19 @@ mod tests {
}
}
+ #[cfg(all(any(ossl111, libressl291), not(osslconf = "OPENSSL_NO_SM3")))]
+ #[test]
+ fn test_sm3() {
+ let tests = [(
+ "616263",
+ "66c7f0f462eeedd9d1f2d46bdc10e4e24167c4875cf2f7a2297da02b8f4ba8e0",
+ )];
+
+ for test in tests.iter() {
+ hash_test(MessageDigest::sm3(), test);
+ }
+ }
+
#[test]
fn from_nid() {
assert_eq!(