Skip to content

Commit 06ceec2

Browse files
committed
bump rustcrypto dependencies to pre-release
1 parent e21adf0 commit 06ceec2

File tree

7 files changed

+91
-78
lines changed

7 files changed

+91
-78
lines changed

Cargo.toml

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
11
[workspace]
22
resolver = "2"
33
members = ["tss-esapi", "tss-esapi-sys"]
4+
5+
[patch.crates-io]
6+
p192 = { git = "https://github.com/RustCrypto/elliptic-curves.git" }
7+
p224 = { git = "https://github.com/RustCrypto/elliptic-curves.git" }
8+
sm2 = { git = "https://github.com/RustCrypto/elliptic-curves.git" }
9+

tss-esapi/Cargo.toml

+19-18
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,22 @@ hostname-validator = "1.1.0"
3434
regex = "1.3.9"
3535
zeroize = { version = "1.5.7", features = ["zeroize_derive"] }
3636
tss-esapi-sys = { path = "../tss-esapi-sys", version = "0.5.0" }
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-
rsa = { version = "0.9", optional = true }
46-
sha1 = { version = "0.10.6", optional = true }
47-
sha2 = { version = "0.10.8", optional = true }
48-
sha3 = { version = "0.10.8", optional = true }
49-
sm2 = { version = "0.13.3", optional = true }
50-
sm3 = { version = "0.4.2", optional = true }
51-
digest = "0.10.7"
52-
signature = { version = "2.2.0", features = ["std"], optional = true}
37+
x509-cert = { version = "0.3.0-pre.0", optional = true }
38+
ecdsa = { version = "0.17.0-pre.9", features = ["der", "hazmat", "arithmetic", "verifying"], optional = true }
39+
elliptic-curve = { version = "0.14.0-rc.1", optional = true, features = ["alloc", "pkcs8"] }
40+
p192 = { version = "0.14.0-pre", optional = true }
41+
p224 = { version = "0.14.0-pre", optional = true }
42+
p256 = { version = "0.14.0-pre.2", optional = true }
43+
p384 = { version = "0.14.0-pre.2", optional = true }
44+
p521 = { version = "0.14.0-pre.2", optional = true }
45+
rsa = { version = "0.10.0-pre.3", optional = true }
46+
sha1 = { version = "0.11.0-pre.4", optional = true }
47+
sha2 = { version = "0.11.0-pre.4", optional = true }
48+
sha3 = { version = "0.11.0-pre.4", optional = true }
49+
sm2 = { version = "0.14.0-pre", optional = true }
50+
sm3 = { version = "0.5.0-pre.4", optional = true }
51+
digest = "0.11.0-pre.9"
52+
signature = { version = "2.3.0-pre.4", features = ["std"], optional = true}
5353
cfg-if = "1.0.0"
5454
strum = { version = "0.26.3", optional = true }
5555
strum_macros = { version = "0.26.4", optional = true }
@@ -59,14 +59,14 @@ getrandom = "0.2.11"
5959
[dev-dependencies]
6060
env_logger = "0.11.5"
6161
serde_json = "^1.0.108"
62-
sha2 = { version = "0.10.8", features = ["oid"] }
62+
sha2 = { version = "0.11.0-pre.4", features = ["oid"] }
6363
tss-esapi = { path = ".", features = [
6464
"integration-tests",
6565
"serde",
6666
"abstraction",
6767
"rustcrypto-full",
6868
] }
69-
x509-cert = { version = "0.2.0", features = ["builder"] }
69+
x509-cert = { version = "0.3.0-pre.0", features = ["builder"] }
7070

7171
[build-dependencies]
7272
semver = "1.0.7"
@@ -79,3 +79,4 @@ integration-tests = ["strum", "strum_macros"]
7979

8080
rustcrypto = ["ecdsa", "elliptic-curve", "signature", "x509-cert"]
8181
rustcrypto-full = ["rustcrypto", "p192", "p224", "p256", "p384", "p521", "rsa", "sha1", "sha2", "sha3", "sm2", "sm3"]
82+

tss-esapi/src/abstraction/public.rs

+16-14
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{Error, WrapperErrorKind};
88

99
use core::convert::TryFrom;
1010
use elliptic_curve::{
11-
generic_array::typenum::Unsigned,
11+
array::typenum::Unsigned,
1212
sec1::{EncodedPoint, FromEncodedPoint, ModulusSize, ToEncodedPoint},
1313
AffinePoint, CurveArithmetic, FieldBytesSize, PublicKey,
1414
};
@@ -46,15 +46,13 @@ where
4646
let x = unique.x().as_bytes();
4747
let y = unique.y().as_bytes();
4848

49-
if x.len() != FieldBytesSize::<C>::USIZE {
50-
return Err(Error::local_error(WrapperErrorKind::InvalidParam));
51-
}
52-
if y.len() != FieldBytesSize::<C>::USIZE {
53-
return Err(Error::local_error(WrapperErrorKind::InvalidParam));
54-
}
55-
56-
let encoded_point =
57-
EncodedPoint::<C>::from_affine_coordinates(x.into(), y.into(), false);
49+
let encoded_point = EncodedPoint::<C>::from_affine_coordinates(
50+
x.try_into()
51+
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?,
52+
y.try_into()
53+
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?,
54+
false,
55+
);
5856
let public_key = PublicKey::<C>::try_from(&encoded_point)
5957
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?;
6058

@@ -162,17 +160,21 @@ where
162160
let x = x.as_slice();
163161
let y = y.as_slice();
164162

165-
// TODO: When elliptic_curve bumps to 0.14, we can use the TryFrom implementation instead
166-
// of checking lengths manually
167163
if x.len() != FieldBytesSize::<C>::USIZE {
168164
return Err(Error::local_error(WrapperErrorKind::InvalidParam));
169165
}
170166
if y.len() != FieldBytesSize::<C>::USIZE {
171167
return Err(Error::local_error(WrapperErrorKind::InvalidParam));
172168
}
173169

174-
let encoded_point =
175-
EncodedPoint::<C>::from_affine_coordinates(x.into(), y.into(), false);
170+
let encoded_point = EncodedPoint::<C>::from_affine_coordinates(
171+
x.try_into()
172+
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?,
173+
y.try_into()
174+
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?,
175+
false,
176+
);
177+
176178
let public_key = PublicKey::<C>::try_from(&encoded_point)
177179
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?;
178180

tss-esapi/src/abstraction/signatures.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ use crate::{structures::EccSignature, Error, Result, WrapperErrorKind};
55

66
use std::convert::TryFrom;
77

8-
use ecdsa::SignatureSize;
8+
use ecdsa::{EcdsaCurve, SignatureSize};
99
use elliptic_curve::{
10-
generic_array::{typenum::Unsigned, ArrayLength},
10+
array::{typenum::Unsigned, ArraySize},
1111
FieldBytes, FieldBytesSize, PrimeCurve,
1212
};
1313

@@ -16,8 +16,8 @@ use crate::structures::Signature;
1616

1717
impl<C> TryFrom<EccSignature> for ecdsa::Signature<C>
1818
where
19-
C: PrimeCurve,
20-
SignatureSize<C>: ArrayLength<u8>,
19+
C: PrimeCurve + EcdsaCurve,
20+
SignatureSize<C>: ArraySize,
2121
{
2222
type Error = Error;
2323

@@ -33,8 +33,12 @@ where
3333
}
3434

3535
let signature = ecdsa::Signature::from_scalars(
36-
FieldBytes::<C>::from_slice(r).clone(),
37-
FieldBytes::<C>::from_slice(s).clone(),
36+
FieldBytes::<C>::try_from(r)
37+
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?
38+
.clone(),
39+
FieldBytes::<C>::try_from(s)
40+
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?
41+
.clone(),
3842
)
3943
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?;
4044
Ok(signature)

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

+34-34
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ use std::{convert::TryFrom, ops::Add, sync::Mutex};
2121
use digest::{Digest, FixedOutput, Output};
2222
use ecdsa::{
2323
der::{MaxOverhead, MaxSize, Signature as DerSignature},
24-
hazmat::{DigestPrimitive, SignPrimitive},
25-
Signature, SignatureSize, VerifyingKey,
24+
hazmat::DigestPrimitive,
25+
EcdsaCurve, Signature, SignatureSize, VerifyingKey,
2626
};
2727
use elliptic_curve::{
28-
generic_array::ArrayLength,
28+
array::ArraySize,
2929
ops::Invert,
3030
sec1::{FromEncodedPoint, ModulusSize, ToEncodedPoint},
3131
subtle::CtOption,
@@ -70,7 +70,7 @@ use x509_cert::{
7070
#[derive(Debug)]
7171
pub struct EcSigner<'ctx, C>
7272
where
73-
C: PrimeCurve + CurveArithmetic,
73+
C: PrimeCurve + CurveArithmetic + EcdsaCurve,
7474
{
7575
context: Mutex<&'ctx mut TransientKeyContext>,
7676
key_material: KeyMaterial,
@@ -80,7 +80,7 @@ where
8080

8181
impl<'ctx, C> EcSigner<'ctx, C>
8282
where
83-
C: PrimeCurve + CurveArithmetic,
83+
C: PrimeCurve + CurveArithmetic + EcdsaCurve,
8484
C: AssociatedTpmCurve,
8585
FieldBytesSize<C>: ModulusSize,
8686
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
@@ -106,7 +106,7 @@ where
106106

107107
impl<C> EcSigner<'_, C>
108108
where
109-
C: PrimeCurve + CurveArithmetic,
109+
C: PrimeCurve + CurveArithmetic + EcdsaCurve,
110110
C: AssociatedTpmCurve,
111111
{
112112
/// Key parameters for this curve, selected digest is the one selected by DigestPrimitive
@@ -126,7 +126,7 @@ where
126126
/// The hashing algorithm `D` is the digest that will be used for signatures (SHA-256, SHA3-256, ...).
127127
pub fn key_params<D>() -> KeyParams
128128
where
129-
D: FixedOutput<OutputSize = FieldBytesSize<C>>,
129+
D: FixedOutput,
130130
D: AssociatedHashingAlgorithm,
131131
{
132132
KeyParams::Ecc {
@@ -139,9 +139,9 @@ where
139139

140140
impl<C> AsRef<VerifyingKey<C>> for EcSigner<'_, C>
141141
where
142-
C: PrimeCurve + CurveArithmetic,
143-
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
144-
SignatureSize<C>: ArrayLength<u8>,
142+
C: PrimeCurve + CurveArithmetic + EcdsaCurve,
143+
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
144+
SignatureSize<C>: ArraySize,
145145
{
146146
fn as_ref(&self) -> &VerifyingKey<C> {
147147
&self.verifying_key
@@ -150,21 +150,21 @@ where
150150

151151
impl<C> KeypairRef for EcSigner<'_, C>
152152
where
153-
C: PrimeCurve + CurveArithmetic,
154-
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
155-
SignatureSize<C>: ArrayLength<u8>,
153+
C: PrimeCurve + CurveArithmetic + EcdsaCurve,
154+
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
155+
SignatureSize<C>: ArraySize,
156156
{
157157
type VerifyingKey = VerifyingKey<C>;
158158
}
159159

160160
impl<C, D> DigestSigner<D, Signature<C>> for EcSigner<'_, C>
161161
where
162-
C: PrimeCurve + CurveArithmetic,
162+
C: PrimeCurve + CurveArithmetic + EcdsaCurve,
163163
C: AssociatedTpmCurve,
164-
D: Digest + FixedOutput<OutputSize = FieldBytesSize<C>>,
164+
D: Digest + FixedOutput,
165165
D: AssociatedHashingAlgorithm,
166-
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
167-
SignatureSize<C>: ArrayLength<u8>,
166+
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
167+
SignatureSize<C>: ArraySize,
168168
TpmDigest: From<Output<D>>,
169169
{
170170
fn try_sign_digest(&self, digest: D) -> Result<Signature<C>, SigError> {
@@ -195,16 +195,16 @@ where
195195

196196
impl<C, D> DigestSigner<D, DerSignature<C>> for EcSigner<'_, C>
197197
where
198-
C: PrimeCurve + CurveArithmetic,
198+
C: PrimeCurve + CurveArithmetic + EcdsaCurve,
199199
C: AssociatedTpmCurve,
200-
D: Digest + FixedOutput<OutputSize = FieldBytesSize<C>>,
200+
D: Digest + FixedOutput,
201201
D: AssociatedHashingAlgorithm,
202-
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
203-
SignatureSize<C>: ArrayLength<u8>,
202+
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
203+
SignatureSize<C>: ArraySize,
204204
TpmDigest: From<Output<D>>,
205205

206-
MaxSize<C>: ArrayLength<u8>,
207-
<FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
206+
MaxSize<C>: ArraySize,
207+
<FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArraySize,
208208
{
209209
fn try_sign_digest(&self, digest: D) -> Result<DerSignature<C>, SigError> {
210210
let signature: Signature<_> = self.try_sign_digest(digest)?;
@@ -214,11 +214,11 @@ where
214214

215215
impl<C> Signer<Signature<C>> for EcSigner<'_, C>
216216
where
217-
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
217+
C: PrimeCurve + CurveArithmetic + EcdsaCurve + DigestPrimitive,
218218
C: AssociatedTpmCurve,
219219
<C as DigestPrimitive>::Digest: AssociatedHashingAlgorithm,
220-
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
221-
SignatureSize<C>: ArrayLength<u8>,
220+
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
221+
SignatureSize<C>: ArraySize,
222222
TpmDigest: From<Output<<C as DigestPrimitive>::Digest>>,
223223
{
224224
fn try_sign(&self, msg: &[u8]) -> Result<Signature<C>, SigError> {
@@ -228,15 +228,15 @@ where
228228

229229
impl<C> Signer<DerSignature<C>> for EcSigner<'_, C>
230230
where
231-
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
231+
C: PrimeCurve + CurveArithmetic + EcdsaCurve + DigestPrimitive,
232232
C: AssociatedTpmCurve,
233233
<C as DigestPrimitive>::Digest: AssociatedHashingAlgorithm,
234-
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
235-
SignatureSize<C>: ArrayLength<u8>,
234+
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
235+
SignatureSize<C>: ArraySize,
236236
TpmDigest: From<Output<<C as DigestPrimitive>::Digest>>,
237237

238-
MaxSize<C>: ArrayLength<u8>,
239-
<FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
238+
MaxSize<C>: ArraySize,
239+
<FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArraySize,
240240
{
241241
fn try_sign(&self, msg: &[u8]) -> Result<DerSignature<C>, SigError> {
242242
self.try_sign_digest(C::Digest::new_with_prefix(msg))
@@ -245,9 +245,9 @@ where
245245

246246
impl<C> SignatureAlgorithmIdentifier for EcSigner<'_, C>
247247
where
248-
C: PrimeCurve + CurveArithmetic,
249-
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
250-
SignatureSize<C>: ArrayLength<u8>,
248+
C: PrimeCurve + CurveArithmetic + EcdsaCurve,
249+
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
250+
SignatureSize<C>: ArraySize,
251251
Signature<C>: AssociatedAlgorithmIdentifier<Params = AnyRef<'static>>,
252252
{
253253
type Params = AnyRef<'static>;

tss-esapi/src/structures/buffers.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -124,8 +124,8 @@ pub mod data {
124124
pub mod digest {
125125
use crate::tss2_esys::TPMU_HA;
126126
use digest::{
127+
array::Array,
127128
consts::{U20, U32, U48, U64},
128-
generic_array::GenericArray,
129129
typenum::Unsigned,
130130
};
131131
use std::mem::size_of;
@@ -229,13 +229,13 @@ pub mod digest {
229229

230230
macro_rules! impl_from_digest {
231231
($($size:ty),+) => {
232-
$(impl From<GenericArray<u8, $size>> for Digest {
233-
fn from(value: GenericArray<u8, $size>) -> Self {
232+
$(impl From<Array<u8, $size>> for Digest {
233+
fn from(value: Array<u8, $size>) -> Self {
234234
Digest(value.as_slice().to_vec().into())
235235
}
236236
}
237237

238-
impl TryFrom<Digest> for GenericArray<u8, $size> {
238+
impl TryFrom<Digest> for Array<u8, $size> {
239239
type Error = Error;
240240

241241
fn try_from(value: Digest) -> Result<Self> {

tss-esapi/tests/integration_tests/abstraction_tests/transient_key_context_tests.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -901,10 +901,10 @@ fn sign_csr() {
901901

902902
let subject = Name::from_str("CN=tpm.example").expect("Parse common name");
903903
let signer = EcSigner::<NistP256>::new(&mut ctx, tpm_km, None).expect("Create a signer");
904-
let builder = RequestBuilder::new(subject, &signer).expect("Create certificate request");
904+
let builder = RequestBuilder::new(subject).expect("Create certificate request");
905905

906906
let cert_req = builder
907-
.build::<p256::ecdsa::DerSignature>()
907+
.build::<_, p256::ecdsa::DerSignature>(&signer)
908908
.expect("Sign a CSR");
909909

910910
println!(

0 commit comments

Comments
 (0)