Skip to content

Commit d8cc2cd

Browse files
committed
rework feature set
This allows to bring the rustcrypto "base" and then limit the support to only the type of keys or hash you need Signed-off-by: Arthur Gautier <[email protected]>
1 parent 697f280 commit d8cc2cd

File tree

5 files changed

+38
-23
lines changed

5 files changed

+38
-23
lines changed

tss-esapi/Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ regex = "1.3.9"
3434
zeroize = { version = "1.5.7", features = ["zeroize_derive"] }
3535
tss-esapi-sys = { path = "../tss-esapi-sys", version = "0.5.0" }
3636
x509-cert = { version = "0.2.0", optional = true }
37-
ecdsa = { version = "0.16.9", optional = true }
37+
ecdsa = { version = "0.16.9", features = ["der", "hazmat", "arithmetic", "verifying"], optional = true }
3838
elliptic-curve = { version = "0.13.8", optional = true, features = ["alloc", "pkcs8"] }
3939
p192 = { version = "0.13.0", optional = true }
4040
p224 = { version = "0.13.2", optional = true }
@@ -63,6 +63,7 @@ tss-esapi = { path = ".", features = [
6363
"integration-tests",
6464
"serde",
6565
"abstraction",
66+
"rustcrypto-full",
6667
] }
6768
x509-cert = { version = "0.2.0", features = ["builder"] }
6869

@@ -72,5 +73,7 @@ semver = "1.0.7"
7273
[features]
7374
default = ["abstraction"]
7475
generate-bindings = ["tss-esapi-sys/generate-bindings"]
75-
abstraction = ["ecdsa", "elliptic-curve", "signature", "rsa", "x509-cert", "p192", "p224", "p256", "p384", "p521", "sha1", "sha2", "sha3", "sm2", "sm3"]
76+
abstraction = ["rustcrypto"]
7677
integration-tests = ["strum", "strum_macros"]
78+
rustcrypto = ["ecdsa", "elliptic-curve", "signature", "x509-cert"]
79+
rustcrypto-full = ["rustcrypto", "p192", "p224", "p256", "p384", "p521", "rsa", "sha1", "sha2", "sha3", "sm2", "sm3"]

tss-esapi/src/abstraction/hashing.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,42 @@ pub trait AssociatedHashingAlgorithm {
99
const TPM_DIGEST: HashingAlgorithm;
1010
}
1111

12-
#[cfg(feature = "sha1")]
12+
#[cfg(all(feature = "rustcrypto", feature = "sha1"))]
1313
impl AssociatedHashingAlgorithm for sha1::Sha1 {
1414
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha1;
1515
}
1616

17-
#[cfg(feature = "sha2")]
17+
#[cfg(all(feature = "rustcrypto", feature = "sha2"))]
1818
impl AssociatedHashingAlgorithm for sha2::Sha256 {
1919
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha256;
2020
}
2121

22-
#[cfg(feature = "sha2")]
22+
#[cfg(all(feature = "rustcrypto", feature = "sha2"))]
2323
impl AssociatedHashingAlgorithm for sha2::Sha384 {
2424
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha384;
2525
}
2626

27-
#[cfg(feature = "sha2")]
27+
#[cfg(all(feature = "rustcrypto", feature = "sha2"))]
2828
impl AssociatedHashingAlgorithm for sha2::Sha512 {
2929
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha512;
3030
}
3131

32-
#[cfg(feature = "sm3")]
32+
#[cfg(all(feature = "rustcrypto", feature = "sm3"))]
3333
impl AssociatedHashingAlgorithm for sm3::Sm3 {
3434
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sm3_256;
3535
}
3636

37-
#[cfg(feature = "sha3")]
37+
#[cfg(all(feature = "rustcrypto", feature = "sha3"))]
3838
impl AssociatedHashingAlgorithm for sha3::Sha3_256 {
3939
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_256;
4040
}
4141

42-
#[cfg(feature = "sha3")]
42+
#[cfg(all(feature = "rustcrypto", feature = "sha3"))]
4343
impl AssociatedHashingAlgorithm for sha3::Sha3_384 {
4444
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_384;
4545
}
4646

47-
#[cfg(feature = "sha3")]
47+
#[cfg(all(feature = "rustcrypto", feature = "sha3"))]
4848
impl AssociatedHashingAlgorithm for sha3::Sha3_512 {
4949
const TPM_DIGEST: HashingAlgorithm = HashingAlgorithm::Sha3_512;
5050
}

tss-esapi/src/abstraction/public.rs

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ use elliptic_curve::{
1818
FieldBytesSize,
1919
PublicKey,
2020
};
21-
use rsa::{pkcs8::EncodePublicKey, BigUint, RsaPublicKey};
21+
22+
#[cfg(feature = "rustcrypto")]
2223
use x509_cert::spki::SubjectPublicKeyInfoOwned;
2324

25+
#[cfg(all(feature = "rustcrypto", feature = "rsa"))]
26+
use rsa::{pkcs8::EncodePublicKey, BigUint, RsaPublicKey};
27+
2428
/// Default exponent for RSA keys.
2529
// Also known as 0x10001
2630
const RSA_DEFAULT_EXP: u64 = 65537;
@@ -66,6 +70,7 @@ where
6670
}
6771
}
6872

73+
#[cfg(all(feature = "rustcrypto", feature = "rsa"))]
6974
impl TryFrom<&Public> for RsaPublicKey {
7075
type Error = Error;
7176

@@ -127,17 +132,17 @@ impl TryFrom<&Public> for SubjectPublicKeyInfoOwned {
127132
};
128133
}
129134

130-
#[cfg(feature = "p192")]
135+
#[cfg(all(feature = "rustcrypto", feature = "p192"))]
131136
read_key!(EccCurve::NistP192, p192::NistP192);
132-
#[cfg(feature = "p224")]
137+
#[cfg(all(feature = "rustcrypto", feature = "p224"))]
133138
read_key!(EccCurve::NistP224, p224::NistP224);
134-
#[cfg(feature = "p256")]
139+
#[cfg(all(feature = "rustcrypto", feature = "p256"))]
135140
read_key!(EccCurve::NistP256, p256::NistP256);
136-
#[cfg(feature = "p384")]
141+
#[cfg(all(feature = "rustcrypto", feature = "p384"))]
137142
read_key!(EccCurve::NistP384, p384::NistP384);
138-
#[cfg(feature = "p521")]
143+
#[cfg(all(feature = "rustcrypto", feature = "p521"))]
139144
read_key!(EccCurve::NistP521, p521::NistP521);
140-
#[cfg(feature = "sm2")]
145+
#[cfg(all(feature = "rustcrypto", feature = "sm2"))]
141146
read_key!(EccCurve::Sm2P256, sm2::Sm2);
142147

143148
Err(Error::local_error(WrapperErrorKind::UnsupportedParam))
@@ -182,6 +187,7 @@ where
182187
}
183188
}
184189

190+
#[cfg(all(feature = "rustcrypto", feature = "rsa"))]
185191
impl TryFrom<&TpmPublicKey> for RsaPublicKey {
186192
type Error = Error;
187193

@@ -207,32 +213,32 @@ pub trait AssociatedTpmCurve {
207213
const TPM_CURVE: EccCurve;
208214
}
209215

210-
#[cfg(feature = "p192")]
216+
#[cfg(all(feature = "rustcrypto", feature = "p192"))]
211217
impl AssociatedTpmCurve for p192::NistP192 {
212218
const TPM_CURVE: EccCurve = EccCurve::NistP192;
213219
}
214220

215-
#[cfg(feature = "p224")]
221+
#[cfg(all(feature = "rustcrypto", feature = "p224"))]
216222
impl AssociatedTpmCurve for p224::NistP224 {
217223
const TPM_CURVE: EccCurve = EccCurve::NistP224;
218224
}
219225

220-
#[cfg(feature = "p256")]
226+
#[cfg(all(feature = "rustcrypto", feature = "p256"))]
221227
impl AssociatedTpmCurve for p256::NistP256 {
222228
const TPM_CURVE: EccCurve = EccCurve::NistP256;
223229
}
224230

225-
#[cfg(feature = "p384")]
231+
#[cfg(all(feature = "rustcrypto", feature = "p384"))]
226232
impl AssociatedTpmCurve for p384::NistP384 {
227233
const TPM_CURVE: EccCurve = EccCurve::NistP384;
228234
}
229235

230-
#[cfg(feature = "p521")]
236+
#[cfg(all(feature = "rustcrypto", feature = "p521"))]
231237
impl AssociatedTpmCurve for p521::NistP521 {
232238
const TPM_CURVE: EccCurve = EccCurve::NistP521;
233239
}
234240

235-
#[cfg(feature = "sm2")]
241+
#[cfg(all(feature = "rustcrypto", feature = "sm2"))]
236242
impl AssociatedTpmCurve for sm2::Sm2 {
237243
const TPM_CURVE: EccCurve = EccCurve::Sm2P256;
238244
}

tss-esapi/src/abstraction/signatures.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ where
4343

4444
// Note: this does not implement `TryFrom<RsaSignature>` because `RsaSignature` does not carry the
4545
// information whether the signatures was generated using PKCS#1v1.5 or PSS.
46+
#[cfg(all(feature = "rustcrypto", feature = "rsa"))]
4647
impl TryFrom<Signature> for rsa::pkcs1v15::Signature {
4748
type Error = Error;
4849

@@ -58,6 +59,7 @@ impl TryFrom<Signature> for rsa::pkcs1v15::Signature {
5859

5960
// Note: this does not implement `TryFrom<RsaSignature>` because `RsaSignature` does not carry the
6061
// information whether the signatures was generated using PKCS#1v1.5 or PSS.
62+
#[cfg(all(feature = "rustcrypto", feature = "rsa"))]
6163
impl TryFrom<Signature> for rsa::pss::Signature {
6264
type Error = Error;
6365

tss-esapi/src/abstraction/transient/mod.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,13 @@ use std::convert::{AsMut, AsRef, TryFrom, TryInto};
3434
use zeroize::Zeroize;
3535

3636
mod key_attestation;
37+
38+
#[cfg(feature = "rustcrypto")]
3739
mod signer;
3840

3941
pub use key_attestation::MakeCredParams;
42+
43+
#[cfg(feature = "rustcrypto")]
4044
pub use signer::EcSigner;
4145

4246
/// Parameters for the kinds of keys supported by the context

0 commit comments

Comments
 (0)