Skip to content

Commit ca66ca7

Browse files
authored
ed448-goldilocks: don't rename signature crate (#1259)
Uses the original crate name and re-exports it under `ed448_goldilocks::sign::signature`
1 parent 33eac24 commit ca66ca7

File tree

6 files changed

+66
-66
lines changed

6 files changed

+66
-66
lines changed

ed448-goldilocks/Cargo.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,23 @@ This crate also includes signing and verifying of Ed448 signatures.
1616
"""
1717

1818
[dependencies]
19-
crypto_signature = { version = "3.0.0-rc.0", default-features = false, features = ["digest", "rand_core"], optional = true, package = "signature" }
2019
elliptic-curve = { version = "0.14.0-rc.6", features = ["arithmetic", "hash2curve", "pkcs8"] }
21-
ed448 = { version = "=0.5.0-pre.0", default-features = false, optional = true }
2220
rand_core = { version = "0.9", default-features = false }
23-
serdect = { version = "0.3.0", optional = true }
2421
sha3 = { version = "0.11.0-rc.0", default-features = false }
2522
subtle = { version = "2.6", default-features = false }
2623

24+
# optional dependencies
25+
ed448 = { version = "=0.5.0-pre.0", optional = true, default-features = false }
26+
serdect = { version = "0.3.0", optional = true }
27+
signature = { version = "3.0.0-rc.0", optional = true, default-features = false, features = ["digest", "rand_core"] }
28+
2729
[features]
2830
default = ["std", "signing", "pkcs8"]
29-
alloc = ["crypto_signature/alloc", "ed448?/alloc", "elliptic-curve/alloc", "serdect/alloc"]
31+
alloc = ["ed448?/alloc", "elliptic-curve/alloc", "serdect?/alloc", "signature?/alloc"]
3032
std = ["alloc"]
3133
bits = ["elliptic-curve/bits"]
3234
pkcs8 = ["ed448?/pkcs8", "elliptic-curve/pkcs8"]
33-
signing = ["dep:crypto_signature", "ed448"]
35+
signing = ["dep:ed448", "dep:signature"]
3436
serde = ["dep:serdect", "ed448?/serde_bytes"]
3537

3638
[dev-dependencies]

ed448-goldilocks/src/sign.rs

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,19 +75,21 @@
7575
mod context;
7676
mod error;
7777
mod expanded;
78-
mod signature;
7978
mod signing_key;
8079
mod verifying_key;
8180

8281
pub use context::*;
83-
pub use crypto_signature;
82+
pub use ed448::Signature;
8483
#[cfg(feature = "pkcs8")]
8584
pub use elliptic_curve::pkcs8;
8685
pub use error::*;
87-
pub use signature::*;
86+
pub use signature;
8887
pub use signing_key::*;
8988
pub use verifying_key::*;
9089

90+
use crate::{CompressedEdwardsY, EdwardsPoint, Scalar};
91+
use elliptic_curve::array::Array;
92+
9193
/// Length of a secret key in bytes
9294
pub const SECRET_KEY_LENGTH: usize = 57;
9395

@@ -111,3 +113,37 @@ pub const ALGORITHM_ID: pkcs8::AlgorithmIdentifierRef<'static> = pkcs8::Algorith
111113
oid: ALGORITHM_OID,
112114
parameters: None,
113115
};
116+
117+
impl From<InnerSignature> for Signature {
118+
fn from(inner: InnerSignature) -> Self {
119+
let mut s = [0u8; SECRET_KEY_LENGTH];
120+
s.copy_from_slice(&inner.s.to_bytes_rfc_8032());
121+
Self::from_components(inner.r.compress(), s)
122+
}
123+
}
124+
125+
impl TryFrom<&Signature> for InnerSignature {
126+
type Error = SigningError;
127+
128+
fn try_from(signature: &Signature) -> Result<Self, Self::Error> {
129+
let s_bytes: &Array<u8, _> = (signature.s_bytes()).into();
130+
let s = Option::from(Scalar::from_canonical_bytes(s_bytes))
131+
.ok_or(SigningError::InvalidSignatureSComponent)?;
132+
let r = Option::from(CompressedEdwardsY::from(*signature.r_bytes()).decompress())
133+
.ok_or(SigningError::InvalidSignatureRComponent)?;
134+
Ok(Self { r, s })
135+
}
136+
}
137+
138+
pub(crate) struct InnerSignature {
139+
pub(crate) r: EdwardsPoint,
140+
pub(crate) s: Scalar,
141+
}
142+
143+
impl TryFrom<Signature> for InnerSignature {
144+
type Error = SigningError;
145+
146+
fn try_from(signature: Signature) -> Result<Self, Self::Error> {
147+
Self::try_from(&signature)
148+
}
149+
}

ed448-goldilocks/src/sign/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,14 @@ impl Display for SigningError {
4141

4242
impl Error for SigningError {}
4343

44-
impl From<SigningError> for crypto_signature::Error {
44+
impl From<SigningError> for signature::Error {
4545
#[cfg(feature = "alloc")]
4646
fn from(err: SigningError) -> Self {
47-
crypto_signature::Error::from_source(err)
47+
signature::Error::from_source(err)
4848
}
4949

5050
#[cfg(not(feature = "alloc"))]
5151
fn from(_err: SigningError) -> Self {
52-
crypto_signature::Error::new()
52+
signature::Error::new()
5353
}
5454
}

ed448-goldilocks/src/sign/signature.rs

Lines changed: 0 additions & 38 deletions
This file was deleted.

ed448-goldilocks/src/sign/signing_key.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@
44
use crate::sign::expanded::ExpandedSecretKey;
55
use crate::*;
66
use core::fmt::{self, Debug, Formatter};
7-
use crypto_signature::Error;
87
use elliptic_curve::zeroize::{Zeroize, ZeroizeOnDrop};
98
use rand_core::CryptoRng;
109
use sha3::digest::{
1110
Digest, ExtendableOutput, FixedOutput, FixedOutputReset, HashMarker, Update, XofReader,
1211
consts::U64, crypto_common::BlockSizeUser, typenum::IsEqual,
1312
};
13+
use signature::Error;
1414
use subtle::{Choice, ConstantTimeEq};
1515

1616
#[cfg(feature = "pkcs8")]
@@ -212,7 +212,7 @@ impl TryFrom<Box<[u8]>> for SigningKey {
212212
}
213213
}
214214

215-
impl<D> crypto_signature::DigestSigner<D, Signature> for SigningKey
215+
impl<D> signature::DigestSigner<D, Signature> for SigningKey
216216
where
217217
D: Digest,
218218
{
@@ -224,21 +224,21 @@ where
224224
}
225225
}
226226

227-
impl crypto_signature::hazmat::PrehashSigner<Signature> for SigningKey {
227+
impl signature::hazmat::PrehashSigner<Signature> for SigningKey {
228228
fn sign_prehash(&self, prehash: &[u8]) -> Result<Signature, Error> {
229229
let sig = self.secret.sign_prehashed(&[], prehash)?;
230230
Ok(sig.into())
231231
}
232232
}
233233

234-
impl crypto_signature::Signer<Signature> for SigningKey {
234+
impl signature::Signer<Signature> for SigningKey {
235235
fn try_sign(&self, msg: &[u8]) -> Result<Signature, Error> {
236236
let sig = self.secret.sign_raw(msg)?;
237237
Ok(sig.into())
238238
}
239239
}
240240

241-
impl<D> crypto_signature::DigestSigner<D, Signature> for Context<'_, '_, SigningKey>
241+
impl<D> signature::DigestSigner<D, Signature> for Context<'_, '_, SigningKey>
242242
where
243243
D: Digest,
244244
{
@@ -253,34 +253,34 @@ where
253253
}
254254
}
255255

256-
impl crypto_signature::hazmat::PrehashSigner<Signature> for Context<'_, '_, SigningKey> {
256+
impl signature::hazmat::PrehashSigner<Signature> for Context<'_, '_, SigningKey> {
257257
fn sign_prehash(&self, prehash: &[u8]) -> Result<Signature, Error> {
258258
let sig = self.key.secret.sign_prehashed(self.value, prehash)?;
259259
Ok(sig.into())
260260
}
261261
}
262262

263-
impl crypto_signature::Signer<Signature> for Context<'_, '_, SigningKey> {
263+
impl signature::Signer<Signature> for Context<'_, '_, SigningKey> {
264264
fn try_sign(&self, msg: &[u8]) -> Result<Signature, Error> {
265265
let sig = self.key.secret.sign_ctx(self.value, msg)?;
266266
Ok(sig.into())
267267
}
268268
}
269269

270-
impl<D> crypto_signature::DigestVerifier<D, Signature> for SigningKey
270+
impl<D> signature::DigestVerifier<D, Signature> for SigningKey
271271
where
272272
D: Digest,
273273
{
274274
fn verify_digest(&self, msg: D, signature: &Signature) -> Result<(), Error> {
275-
<VerifyingKey as crypto_signature::DigestVerifier<D, Signature>>::verify_digest(
275+
<VerifyingKey as signature::DigestVerifier<D, Signature>>::verify_digest(
276276
&self.secret.public_key,
277277
msg,
278278
signature,
279279
)
280280
}
281281
}
282282

283-
impl crypto_signature::Verifier<Signature> for SigningKey {
283+
impl signature::Verifier<Signature> for SigningKey {
284284
fn verify(&self, msg: &[u8], signature: &Signature) -> Result<(), Error> {
285285
self.secret.public_key.verify_raw(signature, msg)
286286
}
@@ -474,7 +474,7 @@ impl SigningKey {
474474
}
475475

476476
/// Create a signing context that can be used for Ed448ph with
477-
/// [`crypto_signature::DigestSigner`]
477+
/// [`signature::DigestSigner`]
478478
pub fn with_context<'k, 'v>(&'k self, context: &'v [u8]) -> Context<'k, 'v, Self> {
479479
Context {
480480
key: self,

ed448-goldilocks/src/sign/verifying_key.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ use core::{
1818
fmt::{self, Debug, Formatter},
1919
hash::{Hash, Hasher},
2020
};
21-
use crypto_signature::Error;
2221
use elliptic_curve::Group;
2322
use sha3::{
2423
Shake256,
2524
digest::{Digest, ExtendableOutput, Update, XofReader},
2625
};
26+
use signature::Error;
2727

2828
/// Ed448 public key as defined in [RFC8032 § 5.2.5]
2929
#[derive(Copy, Clone, Default, Eq)]
@@ -56,13 +56,13 @@ impl PartialEq for VerifyingKey {
5656
}
5757
}
5858

59-
impl crypto_signature::Verifier<Signature> for VerifyingKey {
59+
impl signature::Verifier<Signature> for VerifyingKey {
6060
fn verify(&self, msg: &[u8], signature: &Signature) -> Result<(), Error> {
6161
self.verify_raw(signature, msg)
6262
}
6363
}
6464

65-
impl<D> crypto_signature::DigestVerifier<D, Signature> for VerifyingKey
65+
impl<D> signature::DigestVerifier<D, Signature> for VerifyingKey
6666
where
6767
D: Digest,
6868
{
@@ -73,13 +73,13 @@ where
7373
}
7474
}
7575

76-
impl crypto_signature::Verifier<Signature> for Context<'_, '_, VerifyingKey> {
76+
impl signature::Verifier<Signature> for Context<'_, '_, VerifyingKey> {
7777
fn verify(&self, msg: &[u8], signature: &Signature) -> Result<(), Error> {
7878
self.key.verify_ctx(signature, self.value, msg)
7979
}
8080
}
8181

82-
impl<D> crypto_signature::DigestVerifier<D, Signature> for Context<'_, '_, VerifyingKey>
82+
impl<D> signature::DigestVerifier<D, Signature> for Context<'_, '_, VerifyingKey>
8383
where
8484
D: Digest,
8585
{
@@ -186,7 +186,7 @@ impl VerifyingKey {
186186
Ok(Self { compressed, point })
187187
}
188188

189-
/// Create a context for this verifying key that can be used with [`crypto_signature::DigestVerifier`].
189+
/// Create a context for this verifying key that can be used with [`signature::DigestVerifier`].
190190
pub fn with_context<'k, 'v>(&'k self, context: &'v [u8]) -> Context<'k, 'v, Self> {
191191
Context {
192192
key: self,

0 commit comments

Comments
 (0)