Skip to content

Commit ef81f09

Browse files
committed
[WIP] Convert signature to ecdsa::Signature
Signed-off-by: Arthur Gautier <[email protected]>
1 parent 412d14a commit ef81f09

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

tss-esapi/Cargo.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ regex = "1.3.9"
2828
zeroize = { version = "1.5.7", features = ["zeroize_derive"] }
2929
tss-esapi-sys = { path = "../tss-esapi-sys", version = "0.5.0" }
3030
x509-cert = { version = "0.2.0", optional = true }
31+
ecdsa = { version = "0.16.9", optional = true }
3132
elliptic-curve = { version = "0.13.8", optional = true, features = ["alloc", "pkcs8"] }
3233
p192 = { version = "0.13.0", optional = true }
3334
p224 = { version = "0.13.2", optional = true }
@@ -58,5 +59,5 @@ semver = "1.0.7"
5859
[features]
5960
default = ["abstraction"]
6061
generate-bindings = ["tss-esapi-sys/generate-bindings"]
61-
abstraction = ["elliptic-curve", "rsa", "x509-cert", "p192", "p224", "p256", "p384", "p521", "sha1", "sha2", "sha3", "sm2", "sm3"]
62+
abstraction = ["ecdsa", "elliptic-curve", "rsa", "x509-cert", "p192", "p224", "p256", "p384", "p521", "sha1", "sha2", "sha3", "sm2", "sm3"]
6263
integration-tests = ["strum", "strum_macros"]

tss-esapi/src/abstraction/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ pub mod public;
1010
pub mod transient;
1111

1212
mod hashing;
13+
mod signatures;
1314
pub use hashing::AssociatedHashingAlgorithm;
1415

1516
use std::convert::TryFrom;
+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2024 Contributors to the Parsec project.
2+
// SPDX-License-Identifier: Apache-2.0
3+
4+
use crate::{structures::EccSignature, Error, Result, WrapperErrorKind};
5+
6+
use std::convert::TryFrom;
7+
8+
use ecdsa::SignatureSize;
9+
use elliptic_curve::{
10+
generic_array::{typenum::Unsigned, ArrayLength},
11+
FieldBytes, FieldBytesSize, PrimeCurve,
12+
};
13+
14+
impl<C> TryFrom<EccSignature> for ecdsa::Signature<C>
15+
where
16+
C: PrimeCurve,
17+
SignatureSize<C>: ArrayLength<u8>,
18+
{
19+
type Error = Error;
20+
21+
fn try_from(signature: EccSignature) -> Result<Self> {
22+
let r = signature.signature_r().as_slice();
23+
let s = signature.signature_s().as_slice();
24+
25+
if r.len() != FieldBytesSize::<C>::USIZE {
26+
return Err(Error::local_error(WrapperErrorKind::InvalidParam));
27+
}
28+
if s.len() != FieldBytesSize::<C>::USIZE {
29+
return Err(Error::local_error(WrapperErrorKind::InvalidParam));
30+
}
31+
32+
let signature = ecdsa::Signature::from_scalars(
33+
FieldBytes::<C>::from_slice(r).clone(),
34+
FieldBytes::<C>::from_slice(s).clone(),
35+
)
36+
.map_err(|_| Error::local_error(WrapperErrorKind::InvalidParam))?;
37+
Ok(signature)
38+
}
39+
}
40+
41+
// TODO(baloo): impl TryFrom<RsaSignature> for rsa::pkcs1v15::Signature
42+
// TODO(baloo): impl TryFrom<RsaSignature> for rsa::pss::Signature

0 commit comments

Comments
 (0)