Skip to content

Commit 412d14a

Browse files
committed
adds a AssociatedHashingAlgorithm to bridge to rustcrypto
Signed-off-by: Arthur Gautier <[email protected]>
1 parent 1ff6a4e commit 412d14a

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-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/abstraction/hashing.rs

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright 2024 Contributors to the Parsec project.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use crate::interface_types::algorithm::HashingAlgorithm;
5+
6+
/// Provides the value of the digest used in this crate for the digest.
7+
pub trait AssociatedHashingAlgorithm {
8+
/// Value of the digest when interacting with the TPM.
9+
const TPM_DIGEST: HashingAlgorithm;
10+
}
11+
12+
#[cfg(feature = "sha1")]
13+
impl AssociatedHashingAlgorithm for sha1::Sha1 {
14+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha1;
15+
}
16+
17+
#[cfg(feature = "sha2")]
18+
impl AssociatedHashingAlgorithm for sha2::Sha256 {
19+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha256;
20+
}
21+
22+
#[cfg(feature = "sha2")]
23+
impl AssociatedHashingAlgorithm for sha2::Sha384 {
24+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha384;
25+
}
26+
27+
#[cfg(feature = "sha2")]
28+
impl AssociatedHashingAlgorithm for sha2::Sha512 {
29+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha512;
30+
}
31+
32+
#[cfg(feature = "sm3")]
33+
impl AssociatedHashingAlgorithm for sm3::Sm3 {
34+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sm3_256;
35+
}
36+
37+
#[cfg(feature = "sha3")]
38+
impl AssociatedHashingAlgorithm for sha3::Sha3_256 {
39+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_256;
40+
}
41+
42+
#[cfg(feature = "sha3")]
43+
impl AssociatedHashingAlgorithm for sha3::Sha3_384 {
44+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_384;
45+
}
46+
47+
#[cfg(feature = "sha3")]
48+
impl AssociatedHashingAlgorithm for sha3::Sha3_512 {
49+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_512;
50+
}

tss-esapi/src/abstraction/mod.rs

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ pub mod pcr;
99
pub mod public;
1010
pub mod transient;
1111

12+
mod hashing;
13+
pub use hashing::AssociatedHashingAlgorithm;
14+
1215
use std::convert::TryFrom;
1316

1417
use crate::{

0 commit comments

Comments
 (0)