Skip to content

Commit da4ac58

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 <[email protected]>
1 parent f1348ab commit da4ac58

File tree

13 files changed

+1144
-69
lines changed

13 files changed

+1144
-69
lines changed

Cargo.lock

Lines changed: 52 additions & 60 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
@@ -10,3 +10,6 @@ elliptic-curve = { git = "https://github.com/RustCrypto/traits.git" }
1010
p521 = { git = "https://github.com/RustCrypto/elliptic-curves.git" }
1111
primefield = { git = "https://github.com/RustCrypto/elliptic-curves.git" }
1212
sm2 = { git = "https://github.com/RustCrypto/elliptic-curves.git" }
13+
14+
camellia = { git = "https://github.com/RustCrypto/block-ciphers.git" }
15+
sm4 = { git = "https://github.com/RustCrypto/block-ciphers.git" }

tss-esapi/Cargo.toml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ tss-esapi-sys = { path = "../tss-esapi-sys", version = "0.6.0-alpha.1" }
3737
x509-cert = { version = "0.3.0-rc.1", optional = true }
3838
aes = { version = "0.9.0-rc.2", optional = true }
3939
byte-strings = { version = "0.3.1", optional = true }
40-
cipher = { version = "0.5.0-rc.2", 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.2", optional = true, default-features = false, features = ["zeroize"] }
4243
ecdsa = { version = "0.17.0-rc.8", features = [
4344
"algorithm",
4445
"der",
@@ -61,6 +62,7 @@ sha2 = { version = "0.11.0-rc.3", optional = true }
6162
sha3 = { version = "0.11.0-rc.3", optional = true }
6263
sm2 = { version = "0.14.0-rc.0", optional = true }
6364
sm3 = { version = "0.5.0-rc.3", optional = true }
65+
sm4 = { version = "0.6.0-pre", optional = true }
6466
digest = { version = "0.11.0-rc.4", optional = true }
6567
signature = { version = "3.0.0-rc.5", features = [
6668
"alloc",
@@ -73,12 +75,13 @@ strum = { version = "0.26.3", optional = true }
7375
strum_macros = { version = "0.26.4", optional = true }
7476
paste = "1.0.14"
7577
getrandom = "0.3"
76-
rand = "0.9"
78+
rand = "0.10.0-rc.1"
7779

7880
[dev-dependencies]
7981
aes = "0.9.0-pre.2"
8082
env_logger = "0.11.5"
8183
hex-literal = "1"
84+
paste = "1.0.15"
8285
rsa = { version = "0.10.0-pre.3" }
8386
serde_json = "^1.0.108"
8487
sha2 = { version = "0.11.0-rc.2", features = ["oid"] }
@@ -117,6 +120,7 @@ rustcrypto = [
117120
rustcrypto-full = [
118121
"rustcrypto",
119122
"aes",
123+
"camellia",
120124
"p192",
121125
"p224",
122126
"p256",
@@ -128,6 +132,7 @@ rustcrypto-full = [
128132
"sha3",
129133
"sm2",
130134
"sm3",
135+
"sm4",
131136
]
132137

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

tss-esapi/src/structures/mod.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ pub use self::capability_data::CapabilityData;
2222
// The names section
2323
// //////////////////////////////////////////////////////
2424
mod names;
25+
#[cfg(feature = "rustcrypto")]
26+
#[cfg_attr(
27+
not(any(feature = "sha1", feature = "sha2", feature = "sha3", feature = "sm3",)),
28+
allow(unused)
29+
)]
30+
pub(crate) use names::name::make_name;
2531
pub use names::name::Name;
2632
// //////////////////////////////////////////////////////
2733
// 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: 18 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,20 @@ 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+
#[cfg_attr(
594+
not(any(feature = "sha1", feature = "sha2", feature = "sha3", feature = "sm3",)),
595+
allow(unused)
596+
)]
597+
macro_rules! make_name {
598+
($hash: ty) => {
599+
crate::structures::make_name::<$hash, _>(self)
600+
};
601+
}
602+
603+
crate::utils::match_name_hashing_algorithm!(self, make_name)
604+
}
605+
}

0 commit comments

Comments
 (0)