Skip to content

Commit 562ad61

Browse files
committed
adds a AssociatedHashingAlgorithm to bridge to rustcrypto
Signed-off-by: Arthur Gautier <[email protected]>
1 parent 3d0ade5 commit 562ad61

File tree

2 files changed

+53
-0
lines changed

2 files changed

+53
-0
lines changed

tss-esapi/src/abstraction/hashing.rs

Lines changed: 50 additions & 0 deletions
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(all(feature = "rustcrypto", feature = "sha1"))]
13+
impl AssociatedHashingAlgorithm for sha1::Sha1 {
14+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha1;
15+
}
16+
17+
#[cfg(all(feature = "rustcrypto", feature = "sha2"))]
18+
impl AssociatedHashingAlgorithm for sha2::Sha256 {
19+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha256;
20+
}
21+
22+
#[cfg(all(feature = "rustcrypto", feature = "sha2"))]
23+
impl AssociatedHashingAlgorithm for sha2::Sha384 {
24+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha384;
25+
}
26+
27+
#[cfg(all(feature = "rustcrypto", feature = "sha2"))]
28+
impl AssociatedHashingAlgorithm for sha2::Sha512 {
29+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha512;
30+
}
31+
32+
#[cfg(all(feature = "rustcrypto", feature = "sm3"))]
33+
impl AssociatedHashingAlgorithm for sm3::Sm3 {
34+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sm3_256;
35+
}
36+
37+
#[cfg(all(feature = "rustcrypto", feature = "sha3"))]
38+
impl AssociatedHashingAlgorithm for sha3::Sha3_256 {
39+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_256;
40+
}
41+
42+
#[cfg(all(feature = "rustcrypto", feature = "sha3"))]
43+
impl AssociatedHashingAlgorithm for sha3::Sha3_384 {
44+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_384;
45+
}
46+
47+
#[cfg(all(feature = "rustcrypto", feature = "sha3"))]
48+
impl AssociatedHashingAlgorithm for sha3::Sha3_512 {
49+
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_512;
50+
}

tss-esapi/src/abstraction/mod.rs

Lines changed: 3 additions & 0 deletions
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)