Skip to content

Commit cca3717

Browse files
authored
Merge pull request #537 from baloo/baloo/rust-crypto/signer-interface
adds a `signature::Signer` interface
2 parents b25394f + 2cc63f4 commit cca3717

File tree

12 files changed

+1299
-151
lines changed

12 files changed

+1299
-151
lines changed

tss-esapi/Cargo.toml

+25-6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ required-features = ["abstraction"]
2222
[dependencies]
2323
bitfield = "0.17.0"
2424
serde = { version = "1.0.115", features = [
25+
"alloc",
2526
"derive",
2627
], optional = true, default-features = false }
2728
malloced = "1.3.1"
@@ -33,9 +34,23 @@ hostname-validator = "1.1.0"
3334
regex = "1.3.9"
3435
zeroize = { version = "1.5.7", features = ["zeroize_derive"] }
3536
tss-esapi-sys = { path = "../tss-esapi-sys", version = "0.5.0" }
36-
oid = { version = "0.2.1", optional = true }
37-
picky-asn1 = { version = "0.9.0", optional = true }
38-
picky-asn1-x509 = { version = "0.13.0", optional = true }
37+
x509-cert = { version = "0.2.0", optional = true }
38+
ecdsa = { version = "0.16.9", features = ["der", "hazmat", "arithmetic", "verifying"], optional = true }
39+
elliptic-curve = { version = "0.13.8", optional = true, features = ["alloc", "pkcs8"] }
40+
p192 = { version = "0.13.0", optional = true }
41+
p224 = { version = "0.13.2", optional = true }
42+
p256 = { version = "0.13.2", optional = true }
43+
p384 = { version = "0.13.0", optional = true }
44+
p521 = { version = "0.13.3", optional = true }
45+
pkcs8 = { version = "0.10.2", optional = true }
46+
rsa = { version = "0.9", optional = true }
47+
sha1 = { version = "0.10.6", optional = true }
48+
sha2 = { version = "0.10.8", optional = true }
49+
sha3 = { version = "0.10.8", optional = true }
50+
sm2 = { version = "0.13.3", optional = true }
51+
sm3 = { version = "0.4.2", optional = true }
52+
digest = { version = "0.10.7", optional = true }
53+
signature = { version = "2.2.0", features = ["std"], optional = true}
3954
cfg-if = "1.0.0"
4055
strum = { version = "0.26.3", optional = true }
4156
strum_macros = { version = "0.26.4", optional = true }
@@ -44,20 +59,24 @@ getrandom = "0.2.11"
4459

4560
[dev-dependencies]
4661
env_logger = "0.11.5"
47-
sha2 = "0.10.1"
4862
serde_json = "^1.0.108"
63+
sha2 = { version = "0.10.8", features = ["oid"] }
4964
tss-esapi = { path = ".", features = [
5065
"integration-tests",
5166
"serde",
5267
"abstraction",
68+
"rustcrypto-full",
5369
] }
54-
70+
x509-cert = { version = "0.2.0", features = ["builder"] }
5571

5672
[build-dependencies]
5773
semver = "1.0.7"
5874

5975
[features]
6076
default = ["abstraction"]
6177
generate-bindings = ["tss-esapi-sys/generate-bindings"]
62-
abstraction = ["oid", "picky-asn1", "picky-asn1-x509"]
78+
abstraction = ["rustcrypto"]
6379
integration-tests = ["strum", "strum_macros"]
80+
81+
rustcrypto = ["digest", "ecdsa", "elliptic-curve", "pkcs8", "signature", "x509-cert"]
82+
rustcrypto-full = ["rustcrypto", "p192", "p224", "p256", "p384", "p521", "rsa", "sha1", "sha2", "sha3", "sm2", "sm3"]

tss-esapi/README.md

+3
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,9 @@ The crate currently offers the following features:
2828
on top of the basic Rust-native ESAPI API provided by the crate. This feature
2929
can be turned off to reduce the number of dependencies built.
3030
* `serde` - enable serde `Serialize`/`Deserialize` traits for types.
31+
* `rustcrypto-full` (disabled by default) - provides conversion from all
32+
supported elliptic curves, rsa or hashes.
33+
Support for individual hash, rsa or curves can be pulled individually.
3134

3235
## Cross compiling
3336

tss-esapi/src/abstraction/hashing.rs

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

tss-esapi/src/abstraction/mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,14 @@ pub mod pcr;
99
pub mod public;
1010
pub mod transient;
1111

12+
mod hashing;
13+
mod signatures;
14+
mod signer;
15+
pub use hashing::AssociatedHashingAlgorithm;
16+
pub use signer::EcSigner;
17+
#[cfg(feature = "rsa")]
18+
pub use signer::{RsaPkcsSigner, RsaPssSigner};
19+
1220
use std::convert::TryFrom;
1321

1422
use crate::{

0 commit comments

Comments
 (0)