Skip to content

Commit 106a25a

Browse files
committed
Implement object duplication
Key attestation using object duplication are [on the horizon], and we'll need supporting routines for that. This brings a `create_duplicate` that will make the two layers of wraps around the object to protect. [on the horizon]: https://trustedcomputinggroup.org/wp-content/uploads/EK-Based-Key-Attestation-with-TPM-Firmware-Version-V1-RC1_9July2025.pdf Signed-off-by: Arthur Gautier <arthur.gautier@arista.com>
1 parent 98e18d9 commit 106a25a

File tree

10 files changed

+734
-5
lines changed

10 files changed

+734
-5
lines changed

Cargo.lock

Lines changed: 28 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,6 @@ sm2 = { git = "https://github.com/RustCrypto/elliptic-curves.git" }
1414
concat-kdf = { git = "https://github.com/RustCrypto/KDFs.git" }
1515

1616
rsa = { git = "https://github.com/RustCrypto/RSA.git" }
17+
18+
camellia = { git = "https://github.com/RustCrypto/block-ciphers.git" }
19+
sm4 = { git = "https://github.com/RustCrypto/block-ciphers.git" }

tss-esapi/Cargo.toml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ tss-esapi-sys = { path = "../tss-esapi-sys", version = "0.5.0" }
3737
x509-cert = { version = "0.3.0-rc.1", optional = true }
3838
aes = { version = "0.9.0-rc.1", optional = true }
3939
byte-strings = { version = "0.3.1", optional = true }
40-
cipher = { version = "0.5.0-rc.1", optional = true }
40+
camellia = { version = "0.2.0-pre", optional = true }
4141
cfb-mode = { version = "0.9.0-rc.1", optional = true }
42+
cipher = { version = "0.5.0-rc.1", optional = true, default-features = false, features = ["zeroize"] }
4243
ecdsa = { version = "0.17.0-rc.0", features = [
4344
"der",
4445
"hazmat",
@@ -62,6 +63,7 @@ sha2 = { version = "0.11.0-rc.2", optional = true }
6263
sha3 = { version = "0.11.0-rc.3", optional = true }
6364
sm2 = { version = "0.14.0-pre", optional = true }
6465
sm3 = { version = "0.5.0-pre.5", optional = true }
66+
sm4 = { version = "0.6.0-pre", optional = true }
6567
digest = { version = "0.11.0-rc.3", optional = true }
6668
signature = { version = "3.0.0-rc.0", features = [
6769
"alloc",
@@ -118,6 +120,7 @@ rustcrypto = [
118120
rustcrypto-full = [
119121
"rustcrypto",
120122
"aes",
123+
"camellia",
121124
"p192",
122125
"p224",
123126
"p256",
@@ -129,6 +132,7 @@ rustcrypto-full = [
129132
"sha3",
130133
"sm2",
131134
"sm3",
135+
"sm4",
132136
]
133137

134138
rsa = ["dep:rsa", "kbkdf"]

tss-esapi/src/structures/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ pub use self::capability_data::CapabilityData;
2222
// The names section
2323
// //////////////////////////////////////////////////////
2424
mod names;
25+
#[cfg(feature = "rustcrypto")]
26+
pub(crate) use names::name::make_name;
2527
pub use names::name::Name;
2628
// //////////////////////////////////////////////////////
2729
// The result section

tss-esapi/src/structures/names/name.rs

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,44 @@ impl AsRef<TPM2B_NAME> for Name {
6565
&self.value
6666
}
6767
}
68+
69+
#[cfg(feature = "rustcrypto")]
70+
mod as_name {
71+
use digest::{Digest, Update};
72+
use log::error;
73+
74+
use super::{Name, TPM2B_NAME};
75+
use crate::{
76+
error::{Error, Result, WrapperErrorKind},
77+
traits::Marshall,
78+
utils::hash_object,
79+
};
80+
81+
#[cfg(feature = "rustcrypto")]
82+
pub(crate) fn make_name<D, T>(object: &T) -> Result<Name>
83+
where
84+
D: Digest + Update,
85+
T: Marshall,
86+
{
87+
let mut hasher = D::new();
88+
89+
hash_object(&mut hasher, object)?;
90+
91+
let bytes = hasher.finalize();
92+
if bytes.len() > Name::MAX_SIZE {
93+
error!("Invalid Digest output size (> {})", Name::MAX_SIZE);
94+
return Err(Error::local_error(WrapperErrorKind::WrongParamSize));
95+
}
96+
let size = bytes.len() as u16;
97+
98+
let mut name = [0; Name::MAX_SIZE];
99+
name[..bytes.len()].copy_from_slice(&bytes);
100+
101+
Ok(Name {
102+
value: TPM2B_NAME { size, name },
103+
})
104+
}
105+
}
106+
107+
#[cfg(feature = "rustcrypto")]
108+
pub(crate) use self::as_name::make_name;

tss-esapi/src/structures/tagged/public.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ pub mod rsa;
77
use crate::{
88
attributes::ObjectAttributes,
99
interface_types::algorithm::{HashingAlgorithm, PublicAlgorithm},
10-
structures::{Digest, EccPoint, PublicKeyRsa, SymmetricCipherParameters},
10+
structures::{Digest, EccPoint, Name, PublicKeyRsa, SymmetricCipherParameters},
1111
traits::{impl_mu_standard, Marshall},
1212
tss2_esys::{TPM2B_PUBLIC, TPMT_PUBLIC},
1313
Error, Result, ReturnCode, WrapperErrorKind,
@@ -586,3 +586,15 @@ impl TryFrom<Public> for TPM2B_PUBLIC {
586586
})
587587
}
588588
}
589+
590+
#[cfg(feature = "rustcrypto")]
591+
impl Public {
592+
pub fn name(&self) -> Result<Name> {
593+
macro_rules! make_name {
594+
($hash: ty) => {
595+
crate::structures::make_name::<$hash, _>(self)
596+
};
597+
}
598+
crate::utils::match_name_hashing_algorithm!(self, make_name)
599+
}
600+
}

0 commit comments

Comments
 (0)