Skip to main content

tss_esapi/abstraction/
hashing.rs

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