Skip to content

Commit

Permalink
adds a AssociatedHashingAlgorithm to bridge to rustcrypto
Browse files Browse the repository at this point in the history
Signed-off-by: Arthur Gautier <arthur.gautier@arista.com>
  • Loading branch information
baloo committed Aug 4, 2024
1 parent 1ff6a4e commit 412d14a
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 2 deletions.
8 changes: 6 additions & 2 deletions tss-esapi/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,12 @@ p224 = { version = "0.13.2", optional = true }
p256 = { version = "0.13.2", optional = true }
p384 = { version = "0.13.0", optional = true }
p521 = { version = "0.13.3", optional = true }
sm2 = { version = "0.13.3", optional = true }
rsa = { version = "0.9", optional = true }
sha1 = { version = "0.10.6", optional = true }
sha2 = { version = "0.10.8", optional = true }
sha3 = { version = "0.10.8", optional = true }
sm2 = { version = "0.13.3", optional = true }
sm3 = { version = "0.4.2", optional = true }
digest = "0.10.7"
cfg-if = "1.0.0"
strum = { version = "0.25.0", optional = true }
Expand All @@ -54,5 +58,5 @@ semver = "1.0.7"
[features]
default = ["abstraction"]
generate-bindings = ["tss-esapi-sys/generate-bindings"]
abstraction = ["elliptic-curve", "rsa", "x509-cert", "p192", "p224", "p256", "p384", "p521", "sm2"]
abstraction = ["elliptic-curve", "rsa", "x509-cert", "p192", "p224", "p256", "p384", "p521", "sha1", "sha2", "sha3", "sm2", "sm3"]
integration-tests = ["strum", "strum_macros"]
50 changes: 50 additions & 0 deletions tss-esapi/src/abstraction/hashing.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright 2024 Contributors to the Parsec project.
// SPDX-License-Identifier: Apache-2.0

use crate::interface_types::algorithm::HashingAlgorithm;

/// Provides the value of the digest used in this crate for the digest.
pub trait AssociatedHashingAlgorithm {
/// Value of the digest when interacting with the TPM.
const TPM_DIGEST: HashingAlgorithm;
}

#[cfg(feature = "sha1")]
impl AssociatedHashingAlgorithm for sha1::Sha1 {
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha1;
}

#[cfg(feature = "sha2")]
impl AssociatedHashingAlgorithm for sha2::Sha256 {
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha256;
}

#[cfg(feature = "sha2")]
impl AssociatedHashingAlgorithm for sha2::Sha384 {
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha384;
}

#[cfg(feature = "sha2")]
impl AssociatedHashingAlgorithm for sha2::Sha512 {
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha512;
}

#[cfg(feature = "sm3")]
impl AssociatedHashingAlgorithm for sm3::Sm3 {
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sm3_256;
}

#[cfg(feature = "sha3")]
impl AssociatedHashingAlgorithm for sha3::Sha3_256 {
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_256;
}

#[cfg(feature = "sha3")]
impl AssociatedHashingAlgorithm for sha3::Sha3_384 {
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_384;
}

#[cfg(feature = "sha3")]
impl AssociatedHashingAlgorithm for sha3::Sha3_512 {
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_512;
}
3 changes: 3 additions & 0 deletions tss-esapi/src/abstraction/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ pub mod pcr;
pub mod public;
pub mod transient;

mod hashing;
pub use hashing::AssociatedHashingAlgorithm;

use std::convert::TryFrom;

use crate::{
Expand Down

0 comments on commit 412d14a

Please sign in to comment.