Skip to content

Commit 2f14766

Browse files
committed
bump rustcrypto dependencies to pre-release
Signed-off-by: Arthur Gautier <[email protected]>
1 parent cca3717 commit 2f14766

File tree

7 files changed

+102
-86
lines changed

7 files changed

+102
-86
lines changed

Cargo.toml

+7
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
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+
10+
rsa = { git = "https://github.com/RustCrypto/RSA.git" }

tss-esapi/Cargo.toml

+20-19
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,23 @@ 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-
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}
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+
pkcs8 = { version = "0.11.0-rc.1", optional = true }
46+
rsa = { version = "0.10.0-pre.3", optional = true }
47+
sha1 = { version = "0.11.0-pre.4", optional = true }
48+
sha2 = { version = "0.11.0-pre.4", optional = true }
49+
sha3 = { version = "0.11.0-pre.4", optional = true }
50+
sm2 = { version = "0.14.0-pre", optional = true }
51+
sm3 = { version = "0.5.0-pre.4", optional = true }
52+
digest = { version = "0.11.0-pre.9", optional = true }
53+
signature = { version = "2.3.0-pre.4", features = ["std"], optional = true}
5454
cfg-if = "1.0.0"
5555
strum = { version = "0.26.3", optional = true }
5656
strum_macros = { version = "0.26.4", optional = true }
@@ -60,14 +60,14 @@ getrandom = "0.2.11"
6060
[dev-dependencies]
6161
env_logger = "0.11.5"
6262
serde_json = "^1.0.108"
63-
sha2 = { version = "0.10.8", features = ["oid"] }
63+
sha2 = { version = "0.11.0-pre.4", features = ["oid"] }
6464
tss-esapi = { path = ".", features = [
6565
"integration-tests",
6666
"serde",
6767
"abstraction",
6868
"rustcrypto-full",
6969
] }
70-
x509-cert = { version = "0.2.0", features = ["builder"] }
70+
x509-cert = { version = "0.3.0-pre.0", features = ["builder"] }
7171

7272
[build-dependencies]
7373
semver = "1.0.7"
@@ -80,3 +80,4 @@ integration-tests = ["strum", "strum_macros"]
8080

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

tss-esapi/src/abstraction/public.rs

+24-20
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
};
@@ -18,7 +18,7 @@ use x509_cert::spki::SubjectPublicKeyInfoOwned;
1818
#[cfg(feature = "rsa")]
1919
use {
2020
crate::structures::RsaExponent,
21-
rsa::{BigUint, RsaPublicKey},
21+
rsa::{BoxedUint, RsaPublicKey},
2222
};
2323

2424
#[cfg(any(
@@ -57,15 +57,13 @@ where
5757
let x = unique.x().as_bytes();
5858
let y = unique.y().as_bytes();
5959

60-
if x.len() != FieldBytesSize::<C>::USIZE {
61-
return Err(Error::local_error(WrapperErrorKind::InvalidParam));
62-
}
63-
if y.len() != FieldBytesSize::<C>::USIZE {
64-
return Err(Error::local_error(WrapperErrorKind::InvalidParam));
65-
}
66-
67-
let encoded_point =
68-
EncodedPoint::<C>::from_affine_coordinates(x.into(), y.into(), false);
60+
let encoded_point = EncodedPoint::<C>::from_affine_coordinates(
61+
x.try_into()
62+
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?,
63+
y.try_into()
64+
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?,
65+
false,
66+
);
6967
let public_key = PublicKey::<C>::try_from(&encoded_point)
7068
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?;
7169

@@ -86,10 +84,11 @@ impl TryFrom<&Public> for RsaPublicKey {
8684
unique, parameters, ..
8785
} => {
8886
let exponent = match parameters.exponent() {
89-
RsaExponent::ZERO_EXPONENT => BigUint::from(RSA_DEFAULT_EXP),
90-
_ => BigUint::from(parameters.exponent().value()),
87+
RsaExponent::ZERO_EXPONENT => BoxedUint::from(RSA_DEFAULT_EXP),
88+
_ => BoxedUint::from(parameters.exponent().value()),
9189
};
92-
let modulus = BigUint::from_bytes_be(unique.as_bytes());
90+
let modulus = BoxedUint::from_be_slice(unique.as_bytes(), 8192)
91+
.map_err(|_| Error::local_error(WrapperErrorKind::WrongParamSize))?;
9392

9493
let public_key = RsaPublicKey::new(modulus, exponent)
9594
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?;
@@ -173,17 +172,21 @@ where
173172
let x = x.as_slice();
174173
let y = y.as_slice();
175174

176-
// TODO: When elliptic_curve bumps to 0.14, we can use the TryFrom implementation instead
177-
// of checking lengths manually
178175
if x.len() != FieldBytesSize::<C>::USIZE {
179176
return Err(Error::local_error(WrapperErrorKind::InvalidParam));
180177
}
181178
if y.len() != FieldBytesSize::<C>::USIZE {
182179
return Err(Error::local_error(WrapperErrorKind::InvalidParam));
183180
}
184181

185-
let encoded_point =
186-
EncodedPoint::<C>::from_affine_coordinates(x.into(), y.into(), false);
182+
let encoded_point = EncodedPoint::<C>::from_affine_coordinates(
183+
x.try_into()
184+
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?,
185+
y.try_into()
186+
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?,
187+
false,
188+
);
189+
187190
let public_key = PublicKey::<C>::try_from(&encoded_point)
188191
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?;
189192

@@ -201,8 +204,9 @@ impl TryFrom<&TpmPublicKey> for RsaPublicKey {
201204
fn try_from(value: &TpmPublicKey) -> Result<Self, Self::Error> {
202205
match value {
203206
TpmPublicKey::Rsa(modulus) => {
204-
let exponent = BigUint::from(RSA_DEFAULT_EXP);
205-
let modulus = BigUint::from_bytes_be(modulus.as_slice());
207+
let exponent = BoxedUint::from(RSA_DEFAULT_EXP);
208+
let modulus = BoxedUint::from_be_slice(modulus.as_slice(), 8192)
209+
.map_err(|_| Error::local_error(WrapperErrorKind::WrongParamSize))?;
206210

207211
let public_key = RsaPublicKey::new(modulus, exponent)
208212
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?;

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/signer.rs

+35-35
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ use std::{convert::TryFrom, ops::Add, sync::Mutex};
2424
use digest::{Digest, FixedOutput, Output};
2525
use ecdsa::{
2626
der::{MaxOverhead, MaxSize, Signature as DerSignature},
27-
hazmat::{DigestPrimitive, SignPrimitive},
28-
Signature, SignatureSize, VerifyingKey,
27+
hazmat::DigestPrimitive,
28+
EcdsaCurve, Signature, SignatureSize, VerifyingKey,
2929
};
3030
use elliptic_curve::{
31-
generic_array::ArrayLength,
31+
array::ArraySize,
3232
ops::Invert,
3333
sec1::{FromEncodedPoint, ModulusSize, ToEncodedPoint},
3434
subtle::CtOption,
@@ -139,15 +139,15 @@ impl TpmSigner
139139
#[derive(Debug)]
140140
pub struct EcSigner<C, Ctx>
141141
where
142-
C: PrimeCurve + CurveArithmetic,
142+
C: PrimeCurve + CurveArithmetic + EcdsaCurve,
143143
{
144144
context: Ctx,
145145
verifying_key: VerifyingKey<C>,
146146
}
147147

148148
impl<C, Ctx> EcSigner<C, Ctx>
149149
where
150-
C: PrimeCurve + CurveArithmetic,
150+
C: PrimeCurve + CurveArithmetic + EcdsaCurve,
151151
C: AssociatedTpmCurve,
152152
FieldBytesSize<C>: ModulusSize,
153153
AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>,
@@ -179,14 +179,14 @@ where
179179

180180
impl<C, Ctx> EcSigner<C, Ctx>
181181
where
182-
C: PrimeCurve + CurveArithmetic,
182+
C: PrimeCurve + CurveArithmetic + EcdsaCurve,
183183
C: AssociatedTpmCurve,
184184
{
185185
/// Key parameters for this curve, selected digest is the one selected by DigestPrimitive
186186
pub fn key_params_default() -> KeyParams
187187
where
188188
C: DigestPrimitive,
189-
<C as DigestPrimitive>::Digest: FixedOutput<OutputSize = FieldBytesSize<C>>,
189+
<C as DigestPrimitive>::Digest: FixedOutput,
190190
<C as DigestPrimitive>::Digest: AssociatedHashingAlgorithm,
191191
{
192192
Self::key_params::<<C as DigestPrimitive>::Digest>()
@@ -199,7 +199,7 @@ where
199199
/// The hashing algorithm `D` is the digest that will be used for signatures (SHA-256, SHA3-256, ...).
200200
pub fn key_params<D>() -> KeyParams
201201
where
202-
D: FixedOutput<OutputSize = FieldBytesSize<C>>,
202+
D: FixedOutput,
203203
D: AssociatedHashingAlgorithm,
204204
{
205205
KeyParams::Ecc {
@@ -212,9 +212,9 @@ where
212212

213213
impl<C, Ctx> AsRef<VerifyingKey<C>> for EcSigner<C, Ctx>
214214
where
215-
C: PrimeCurve + CurveArithmetic,
216-
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
217-
SignatureSize<C>: ArrayLength<u8>,
215+
C: PrimeCurve + CurveArithmetic + EcdsaCurve,
216+
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
217+
SignatureSize<C>: ArraySize,
218218
{
219219
fn as_ref(&self) -> &VerifyingKey<C> {
220220
&self.verifying_key
@@ -223,21 +223,21 @@ where
223223

224224
impl<C, Ctx> KeypairRef for EcSigner<C, Ctx>
225225
where
226-
C: PrimeCurve + CurveArithmetic,
227-
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
228-
SignatureSize<C>: ArrayLength<u8>,
226+
C: PrimeCurve + CurveArithmetic + EcdsaCurve,
227+
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
228+
SignatureSize<C>: ArraySize,
229229
{
230230
type VerifyingKey = VerifyingKey<C>;
231231
}
232232

233233
impl<C, Ctx, D> DigestSigner<D, Signature<C>> for EcSigner<C, Ctx>
234234
where
235-
C: PrimeCurve + CurveArithmetic,
235+
C: PrimeCurve + CurveArithmetic + EcdsaCurve,
236236
C: AssociatedTpmCurve,
237-
D: Digest + FixedOutput<OutputSize = FieldBytesSize<C>>,
237+
D: Digest + FixedOutput,
238238
D: AssociatedHashingAlgorithm,
239-
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
240-
SignatureSize<C>: ArrayLength<u8>,
239+
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
240+
SignatureSize<C>: ArraySize,
241241
TpmDigest: From<Output<D>>,
242242
Ctx: TpmSigner,
243243
{
@@ -261,16 +261,16 @@ where
261261

262262
impl<C, Ctx, D> DigestSigner<D, DerSignature<C>> for EcSigner<C, Ctx>
263263
where
264-
C: PrimeCurve + CurveArithmetic,
264+
C: PrimeCurve + CurveArithmetic + EcdsaCurve,
265265
C: AssociatedTpmCurve,
266-
D: Digest + FixedOutput<OutputSize = FieldBytesSize<C>>,
266+
D: Digest + FixedOutput,
267267
D: AssociatedHashingAlgorithm,
268-
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
269-
SignatureSize<C>: ArrayLength<u8>,
268+
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
269+
SignatureSize<C>: ArraySize,
270270
TpmDigest: From<Output<D>>,
271271

272-
MaxSize<C>: ArrayLength<u8>,
273-
<FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
272+
MaxSize<C>: ArraySize,
273+
<FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArraySize,
274274

275275
Ctx: TpmSigner,
276276
{
@@ -282,11 +282,11 @@ where
282282

283283
impl<C, Ctx> Signer<Signature<C>> for EcSigner<C, Ctx>
284284
where
285-
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
285+
C: PrimeCurve + CurveArithmetic + EcdsaCurve + DigestPrimitive,
286286
C: AssociatedTpmCurve,
287287
<C as DigestPrimitive>::Digest: AssociatedHashingAlgorithm,
288-
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
289-
SignatureSize<C>: ArrayLength<u8>,
288+
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
289+
SignatureSize<C>: ArraySize,
290290
TpmDigest: From<Output<<C as DigestPrimitive>::Digest>>,
291291

292292
Ctx: TpmSigner,
@@ -298,15 +298,15 @@ where
298298

299299
impl<C, Ctx> Signer<DerSignature<C>> for EcSigner<C, Ctx>
300300
where
301-
C: PrimeCurve + CurveArithmetic + DigestPrimitive,
301+
C: PrimeCurve + CurveArithmetic + EcdsaCurve + DigestPrimitive,
302302
C: AssociatedTpmCurve,
303303
<C as DigestPrimitive>::Digest: AssociatedHashingAlgorithm,
304-
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
305-
SignatureSize<C>: ArrayLength<u8>,
304+
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
305+
SignatureSize<C>: ArraySize,
306306
TpmDigest: From<Output<<C as DigestPrimitive>::Digest>>,
307307

308-
MaxSize<C>: ArrayLength<u8>,
309-
<FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
308+
MaxSize<C>: ArraySize,
309+
<FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArraySize,
310310

311311
Ctx: TpmSigner,
312312
{
@@ -317,9 +317,9 @@ where
317317

318318
impl<C, Ctx> SignatureAlgorithmIdentifier for EcSigner<C, Ctx>
319319
where
320-
C: PrimeCurve + CurveArithmetic,
321-
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>,
322-
SignatureSize<C>: ArrayLength<u8>,
320+
C: PrimeCurve + CurveArithmetic + EcdsaCurve,
321+
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
322+
SignatureSize<C>: ArraySize,
323323
Signature<C>: AssociatedAlgorithmIdentifier<Params = AnyRef<'static>>,
324324
{
325325
type Params = AnyRef<'static>;

0 commit comments

Comments
 (0)