Skip to content

Commit 1ee2dae

Browse files
committed
formatting
1 parent 53d5313 commit 1ee2dae

File tree

2 files changed

+64
-71
lines changed

2 files changed

+64
-71
lines changed

ecdsa/src/impl_signature_trait.rs

Lines changed: 61 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -8,69 +8,73 @@ pub mod signers {
88
const SIGNING_KEY_LEN: usize = 32;
99

1010
macro_rules! impl_signature_trait {
11-
($digest_alg_name:ident, $alias:ident, $sign_fn:ident, $verify_fn:ident) => {
12-
#[allow(non_camel_case_types)]
13-
#[doc = concat!("A signer using [`libcrux_sha2::", stringify!($digest_alg_name),"`].")]
14-
pub type $alias = Signer<libcrux_sha2::$digest_alg_name>;
11+
(
12+
$digest_alg_name:ident,
13+
$alias:ident,
14+
$sign_fn:ident,
15+
$verify_fn:ident
16+
) => {
17+
#[allow(non_camel_case_types)]
18+
#[doc = concat!("A signer using [`libcrux_sha2::", stringify!($digest_alg_name),"`].")]
19+
pub type $alias = Signer<libcrux_sha2::$digest_alg_name>;
1520

16-
/// The [`arrayref`](libcrux_traits::signature::arrayref) version of the Sign trait.
17-
impl arrayref::Sign<SIGNING_KEY_LEN, SIG_LEN> for $alias {
18-
/// The nonce needed for signing.
19-
type SignAux<'a> = &'a Nonce;
20-
type SigningKey<'a, const LEN: usize> = &'a [u8; SIGNING_KEY_LEN];
21-
/// Sign a payload using a provided signing key and `nonce`.
22-
#[inline(always)]
23-
fn sign(
24-
payload: &[u8],
25-
signing_key: &[u8; SIGNING_KEY_LEN],
26-
signature: &mut [u8; SIG_LEN],
27-
nonce: &Nonce,
28-
) -> Result<(), arrayref::SignError> {
29-
let result = libcrux_p256::$sign_fn(
30-
signature,
31-
payload.len().try_into().map_err(|_| arrayref::SignError::InvalidPayloadLength)?,
32-
payload,
33-
signing_key,
34-
&nonce.0,
35-
);
36-
if !result {
37-
return Err(arrayref::SignError::LibraryError);
21+
/// The [`arrayref`](libcrux_traits::signature::arrayref) version of the Sign trait.
22+
impl arrayref::Sign<SIGNING_KEY_LEN, SIG_LEN> for $alias {
23+
/// The nonce needed for signing.
24+
type SignAux<'a> = &'a Nonce;
25+
type SigningKey<'a, const LEN: usize> = &'a [u8; SIGNING_KEY_LEN];
26+
/// Sign a payload using a provided signing key and `nonce`.
27+
#[inline(always)]
28+
fn sign(
29+
payload: &[u8],
30+
signing_key: &[u8; SIGNING_KEY_LEN],
31+
signature: &mut [u8; SIG_LEN],
32+
nonce: &Nonce,
33+
) -> Result<(), arrayref::SignError> {
34+
let result = libcrux_p256::$sign_fn(
35+
signature,
36+
payload.len().try_into().map_err(|_| arrayref::SignError::InvalidPayloadLength)?,
37+
payload,
38+
signing_key,
39+
&nonce.0,
40+
);
41+
if !result {
42+
return Err(arrayref::SignError::LibraryError);
43+
}
44+
Ok(())
3845
}
39-
Ok(())
4046
}
41-
}
42-
43-
/// The [`arrayref`](libcrux_traits::signature::arrayref) version of the Verify trait.
44-
impl arrayref::Verify<VERIFICATION_KEY_LEN, SIG_LEN> for $alias {
45-
/// No auxiliary information is required for verification.
46-
type VerifyAux<'a> = ();
47-
#[inline(always)]
48-
/// Verify a signature using a provided verification key.
49-
fn verify(
50-
payload: &[u8],
51-
verification_key: &[u8; VERIFICATION_KEY_LEN],
52-
signature: &[u8; SIG_LEN],
53-
_aux: (),
54-
) -> Result<(), arrayref::VerifyError> {
5547

56-
let result = libcrux_p256::$verify_fn(
57-
payload.len().try_into().map_err(|_| arrayref::VerifyError::InvalidPayloadLength)?,
58-
payload,
59-
verification_key,
60-
<&[u8; 32]>::try_from(&signature[0..32]).unwrap(),
61-
<&[u8; 32]>::try_from(&signature[32..]).unwrap(),
62-
);
63-
if !result {
64-
return Err(arrayref::VerifyError::LibraryError);
48+
/// The [`arrayref`](libcrux_traits::signature::arrayref) version of the Verify trait.
49+
impl arrayref::Verify<VERIFICATION_KEY_LEN, SIG_LEN> for $alias {
50+
/// No auxiliary information is required for verification.
51+
type VerifyAux<'a> = ();
52+
#[inline(always)]
53+
/// Verify a signature using a provided verification key.
54+
fn verify(
55+
payload: &[u8],
56+
verification_key: &[u8; VERIFICATION_KEY_LEN],
57+
signature: &[u8; SIG_LEN],
58+
_aux: (),
59+
) -> Result<(), arrayref::VerifyError> {
60+
let result = libcrux_p256::$verify_fn(
61+
payload.len().try_into().map_err(|_| arrayref::VerifyError::InvalidPayloadLength)?,
62+
payload,
63+
verification_key,
64+
<&[u8; 32]>::try_from(&signature[0..32]).unwrap(),
65+
<&[u8; 32]>::try_from(&signature[32..]).unwrap(),
66+
);
67+
if !result {
68+
return Err(arrayref::VerifyError::LibraryError);
69+
}
70+
Ok(())
6571
}
66-
Ok(())
6772
}
68-
}
69-
libcrux_traits::impl_signature_slice_trait!($alias => SIGNING_KEY_LEN, SIG_LEN, &Nonce, nonce, &'a [u8; SIGNING_KEY_LEN]);
70-
libcrux_traits::impl_verify_slice_trait!($alias => VERIFICATION_KEY_LEN, SIG_LEN, (), _aux);
71-
// TODO: owned and secrets traits not appearing in docs
72-
};
73-
}
73+
libcrux_traits::impl_signature_slice_trait!($alias => SIGNING_KEY_LEN, SIG_LEN, &Nonce, nonce, &'a [u8; SIGNING_KEY_LEN]);
74+
libcrux_traits::impl_verify_slice_trait!($alias => VERIFICATION_KEY_LEN, SIG_LEN, (), _aux);
75+
// TODO: owned and secrets traits not appearing in docs
76+
};
77+
}
7478

7579
pub mod p256 {
7680
//! [`libcrux_traits::signature`] APIs for p256.

rsa/src/impl_signature_trait.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ macro_rules! impl_signature_trait {
1616

1717
/// The [`arrayref`](libcrux_traits::signature::arrayref) version of the Sign trait.
1818
impl arrayref::Sign<$bytes, $bytes> for $alias {
19-
2019
/// The salt, provided as a `&'a [u8]`.
2120
type SignAux<'a> = &'a [u8];
2221
type SigningKey<'a, const LEN: usize> = &'a generic_keys::PrivateKey<LEN, u8>;
@@ -37,7 +36,6 @@ macro_rules! impl_signature_trait {
3736
.map_err(|e| match e {
3837
crate::Error::MessageTooLarge => arrayref::SignError::InvalidPayloadLength,
3938
_ => arrayref::SignError::LibraryError,
40-
4139
})
4240
}
4341
}
@@ -60,18 +58,18 @@ macro_rules! impl_signature_trait {
6058
signature,
6159
)
6260
.map_err(|e| match e {
63-
crate::Error::InvalidSignatureLength => arrayref::VerifyError::InvalidSignatureBufferLength,
61+
crate::Error::InvalidSignatureLength => {
62+
arrayref::VerifyError::InvalidSignatureBufferLength
63+
}
6464
crate::Error::MessageTooLarge => arrayref::VerifyError::InvalidPayloadLength,
6565
_ => arrayref::VerifyError::LibraryError,
66-
6766
})
6867
}
6968
}
7069

7170
// manual implementation of sign slice trait
7271
/// The [`slice`](libcrux_traits::signature::slice) version of the Sign trait.
7372
impl slice::Sign for $alias {
74-
7573
/// The salt, provided as a `&'a [u8]`.
7674
type SignAux<'a> = &'a [u8];
7775
type SigningKey<'a> = generic_keys::VarLenPrivateKey<'a, u8>;
@@ -83,7 +81,6 @@ macro_rules! impl_signature_trait {
8381
salt: &[u8],
8482
) -> Result<(), slice::SignError> {
8583
sign_varlen(
86-
8784
crate::DigestAlgorithm::$digest_alg,
8885
&signing_key,
8986
payload,
@@ -93,8 +90,6 @@ macro_rules! impl_signature_trait {
9390
.map_err(|e| match e {
9491
crate::Error::MessageTooLarge => slice::SignError::InvalidPayloadLength,
9592
_ => slice::SignError::LibraryError,
96-
97-
9893
})
9994
}
10095
}
@@ -111,23 +106,17 @@ macro_rules! impl_signature_trait {
111106
payload: &[u8],
112107
signing_key: &generic_keys::PrivateKey<$bytes, U8>,
113108
salt: &[u8],
114-
115109
) -> Result<[u8; $bytes], secrets::SignError> {
116-
117110
use libcrux_secrets::DeclassifyRef;
118111

119112
<Self as owned::Sign<_, _>>::sign(payload, signing_key.declassify_ref(), salt)
120-
121113
}
122-
123114
}
124115

125-
126116
libcrux_traits::impl_verify_slice_trait!($alias => $bytes, $bytes, u32, salt_len);
127117

128118
// TODO: owned trait not appearing in docs
129119

130-
131120
};
132121
}
133122

0 commit comments

Comments
 (0)