Skip to content

Commit d5e7e18

Browse files
committed
adds a AssociatedHashingAlgorithm to bind to bridge to rustcrypto
Signed-off-by: Arthur Gautier <arthur.gautier@arista.com>
1 parent 9489a9b commit d5e7e18

File tree

2 files changed

+52
-2
lines changed

2 files changed

+52
-2
lines changed

tss-esapi/Cargo.toml

+6-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,12 @@ p224 = { version = "0.13.2", optional = true }
3434
p256 = { version = "0.13.2", optional = true }
3535
p384 = { version = "0.13.0", optional = true }
3636
p521 = { version = "0.13.3", optional = true }
37-
sm2 = { version = "0.13.3", optional = true }
3837
rsa = { version = "0.9", optional = true }
38+
sha1 = { version = "0.10.6", optional = true }
39+
sha2 = { version = "0.10.8", optional = true }
40+
sha3 = { version = "0.10.8", optional = true }
41+
sm2 = { version = "0.13.3", optional = true }
42+
sm3 = { version = "0.4.2", optional = true }
3943
digest = "0.10.7"
4044
cfg-if = "1.0.0"
4145
strum = { version = "0.25.0", optional = true }
@@ -54,5 +58,5 @@ semver = "1.0.7"
5458
[features]
5559
default = ["abstraction"]
5660
generate-bindings = ["tss-esapi-sys/generate-bindings"]
57-
abstraction = ["elliptic-curve", "rsa", "x509-cert", "p192", "p224", "p256", "p384", "p521", "sm2"]
61+
abstraction = ["elliptic-curve", "rsa", "x509-cert", "p192", "p224", "p256", "p384", "p521", "sha1", "sha2", "sha3", "sm2", "sm3"]
5862
integration-tests = ["strum", "strum_macros"]

tss-esapi/src/interface_types/algorithm.rs

+46
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,52 @@ impl TryFrom<TPMI_ALG_HASH> for HashingAlgorithm {
7676
}
7777
}
7878

79+
/// Provides the value of the digest used in this crate for the digest.
80+
pub trait AssociatedHashingAlgorithm {
81+
/// Value of the digest when interacting with the TPM.
82+
const TPM_DIGEST: HashingAlgorithm;
83+
}
84+
85+
#[cfg(feature = "sha1")]
86+
impl AssociatedHashingAlgorithm for sha1::Sha1 {
87+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha1;
88+
}
89+
90+
#[cfg(feature = "sha2")]
91+
impl AssociatedHashingAlgorithm for sha2::Sha256 {
92+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha256;
93+
}
94+
95+
#[cfg(feature = "sha2")]
96+
impl AssociatedHashingAlgorithm for sha2::Sha384 {
97+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha384;
98+
}
99+
100+
#[cfg(feature = "sha2")]
101+
impl AssociatedHashingAlgorithm for sha2::Sha512 {
102+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha512;
103+
}
104+
105+
#[cfg(feature = "sm3")]
106+
impl AssociatedHashingAlgorithm for sm3::Sm3 {
107+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sm3_256;
108+
}
109+
110+
#[cfg(feature = "sha3")]
111+
impl AssociatedHashingAlgorithm for sha3::Sha3_256 {
112+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_256;
113+
}
114+
115+
#[cfg(feature = "sha3")]
116+
impl AssociatedHashingAlgorithm for sha3::Sha3_384 {
117+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_384;
118+
}
119+
120+
#[cfg(feature = "sha3")]
121+
impl AssociatedHashingAlgorithm for sha3::Sha3_512 {
122+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_512;
123+
}
124+
79125
/// Enum containing the supported keyed hash scheme
80126
///
81127
/// # Details

0 commit comments

Comments
 (0)