Skip to content

Commit 3996b36

Browse files
committed
Convert signature to ecdsa::Signature
Signed-off-by: Arthur Gautier <[email protected]>
1 parent 562ad61 commit 3996b36

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

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)