From f7c8e71ecd8c3559ad543bb6856ff90f7ccc32c7 Mon Sep 17 00:00:00 2001 From: Xynnn007 Date: Thu, 7 Aug 2025 15:52:11 +0800 Subject: [PATCH] hash algorithm: add sm3 algorithm Signed-off-by: Xynnn007 --- Cargo.toml | 9 +++++---- src/hash_algorithm.rs | 8 ++++++++ 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index d3504a4..2726292 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,11 +8,11 @@ repository = "https://github.com/virtee/kbs-types" license = "Apache-2.0" [features] -default = [ "std" ] -alloc = ["base64/alloc", "serde/alloc", "serde_json/alloc" ] +default = ["std"] +alloc = ["base64/alloc", "serde/alloc", "serde_json/alloc"] std = ["base64/std", "serde/std", "serde_json/std", "thiserror/std"] -tee-sev = [ "sev" ] -tee-snp = [ "sev" ] +tee-sev = ["sev"] +tee-snp = ["sev"] [dependencies] base64 = { version = "0.22.1", default-features = false } @@ -20,6 +20,7 @@ serde = { version = "1.0", default-features = false, features = ["derive"] } serde_json = { version = "1.0", default-features = false } sev = { version = "6.0.0", features = ["openssl"], optional = true } sha2 = "0.10" +sm3 = "0.4.2" strum = { version = "0.27", features = ["derive"] } thiserror = { version = "2.0.3", default-features = false } diff --git a/src/hash_algorithm.rs b/src/hash_algorithm.rs index dbddcba..882fb91 100644 --- a/src/hash_algorithm.rs +++ b/src/hash_algorithm.rs @@ -1,5 +1,6 @@ use serde::{Deserialize, Serialize}; use sha2::{Digest, Sha256, Sha384, Sha512}; +use sm3::Sm3; use strum::{AsRefStr, Display, EnumString}; #[cfg(all(feature = "alloc", not(feature = "std")))] @@ -20,6 +21,10 @@ pub enum HashAlgorithm { #[strum(ascii_case_insensitive)] #[strum(serialize = "sha512")] Sha512, + + #[strum(ascii_case_insensitive)] + #[strum(serialize = "sm3")] + Sm3, } impl Default for HashAlgorithm { @@ -39,6 +44,7 @@ impl HashAlgorithm { HashAlgorithm::Sha256 => 32, HashAlgorithm::Sha384 => 48, HashAlgorithm::Sha512 => 64, + HashAlgorithm::Sm3 => 32, } } @@ -47,6 +53,7 @@ impl HashAlgorithm { HashAlgorithm::Sha256 => hash_reportdata::(material), HashAlgorithm::Sha384 => hash_reportdata::(material), HashAlgorithm::Sha512 => hash_reportdata::(material), + HashAlgorithm::Sm3 => hash_reportdata::(material), } } @@ -56,6 +63,7 @@ impl HashAlgorithm { HashAlgorithm::Sha256, HashAlgorithm::Sha384, HashAlgorithm::Sha512, + HashAlgorithm::Sm3, ] } }