Skip to content

Commit bf87537

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

File tree

7 files changed

+92
-79
lines changed

7 files changed

+92
-79
lines changed

Cargo.toml

Lines changed: 6 additions & 0 deletions
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

Lines changed: 20 additions & 19 deletions
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 = "0.10.7"
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 = "0.11.0-pre.9"
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 = ["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

Lines changed: 16 additions & 14 deletions
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
};
@@ -60,15 +60,13 @@ where
6060
let x = unique.x().as_bytes();
6161
let y = unique.y().as_bytes();
6262

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

@@ -176,17 +174,21 @@ where
176174
let x = x.as_slice();
177175
let y = y.as_slice();
178176

179-
// TODO: When elliptic_curve bumps to 0.14, we can use the TryFrom implementation instead
180-
// of checking lengths manually
181177
if x.len() != FieldBytesSize::<C>::USIZE {
182178
return Err(Error::local_error(WrapperErrorKind::InvalidParam));
183179
}
184180
if y.len() != FieldBytesSize::<C>::USIZE {
185181
return Err(Error::local_error(WrapperErrorKind::InvalidParam));
186182
}
187183

188-
let encoded_point =
189-
EncodedPoint::<C>::from_affine_coordinates(x.into(), y.into(), false);
184+
let encoded_point = EncodedPoint::<C>::from_affine_coordinates(
185+
x.try_into()
186+
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?,
187+
y.try_into()
188+
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?,
189+
false,
190+
);
191+
190192
let public_key = PublicKey::<C>::try_from(&encoded_point)
191193
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?;
192194

tss-esapi/src/abstraction/signatures.rs

Lines changed: 10 additions & 6 deletions
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

Lines changed: 34 additions & 34 deletions
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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 2 additions & 2 deletions
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)