Skip to content

Commit

Permalink
ecdsa: bump der dependency to v0.3 (#267)
Browse files Browse the repository at this point in the history
  • Loading branch information
tarcieri authored Mar 26, 2021
1 parent f0e3871 commit 6bbe347
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 27 deletions.
16 changes: 4 additions & 12 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion ecdsa/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ categories = ["cryptography", "no-std"]
keywords = ["crypto", "ecc", "nist", "secp256k1", "signature"]

[dependencies]
der = { version = "0.2", optional = true, features = ["big-uint"] }
der = { version = "0.3", optional = true, features = ["big-uint"] }
elliptic-curve = { version = "0.9", default-features = false }
hmac = { version = "0.10", optional = true, default-features = false }
signature = { version = ">= 1.3.0, < 1.4.0", default-features = false, features = ["rand-preview"] }
Expand Down
21 changes: 10 additions & 11 deletions ecdsa/src/der.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
//! Support for ECDSA signatures encoded as ASN.1 DER.
pub use der::BigUIntSize;

use crate::{
generic_array::{ArrayLength, GenericArray},
generic_array::{typenum::NonZero, ArrayLength, GenericArray},
Error,
};
use core::{
Expand Down Expand Up @@ -52,7 +50,7 @@ const ENCODING_ERR_MSG: &str = "DER encoding error";
pub struct Signature<C>
where
C: Curve,
C::FieldSize: Add + ArrayLength<u8> + BigUIntSize,
C::FieldSize: Add + ArrayLength<u8> + NonZero,
MaxSize<C>: ArrayLength<u8>,
<C::FieldSize as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
{
Expand All @@ -69,7 +67,7 @@ where
impl<C> signature::Signature for Signature<C>
where
C: Curve,
C::FieldSize: Add + ArrayLength<u8> + BigUIntSize,
C::FieldSize: Add + ArrayLength<u8> + NonZero,
MaxSize<C>: ArrayLength<u8>,
<C::FieldSize as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
{
Expand All @@ -83,7 +81,7 @@ where
impl<C> Signature<C>
where
C: Curve,
C::FieldSize: Add + ArrayLength<u8> + BigUIntSize,
C::FieldSize: Add + ArrayLength<u8> + NonZero,
MaxSize<C>: ArrayLength<u8>,
<C::FieldSize as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
{
Expand Down Expand Up @@ -111,7 +109,8 @@ where
let mut bytes = SignatureBytes::<C>::default();
let mut encoder = der::Encoder::new(&mut bytes);

encoder.sequence(&[&r, &s]).expect(ENCODING_ERR_MSG);
encoder.message(&[&r, &s]).expect(ENCODING_ERR_MSG);

encoder
.finish()
.expect(ENCODING_ERR_MSG)
Expand All @@ -133,7 +132,7 @@ where
impl<C> AsRef<[u8]> for Signature<C>
where
C: Curve,
C::FieldSize: Add + ArrayLength<u8> + BigUIntSize,
C::FieldSize: Add + ArrayLength<u8> + NonZero,
MaxSize<C>: ArrayLength<u8>,
<C::FieldSize as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
{
Expand All @@ -145,7 +144,7 @@ where
impl<C> fmt::Debug for Signature<C>
where
C: Curve,
C::FieldSize: Add + ArrayLength<u8> + BigUIntSize,
C::FieldSize: Add + ArrayLength<u8> + NonZero,
MaxSize<C>: ArrayLength<u8>,
<C::FieldSize as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
{
Expand All @@ -160,7 +159,7 @@ where
impl<C> TryFrom<&[u8]> for Signature<C>
where
C: Curve,
C::FieldSize: Add + ArrayLength<u8> + BigUIntSize,
C::FieldSize: Add + ArrayLength<u8> + NonZero,
MaxSize<C>: ArrayLength<u8>,
<C::FieldSize as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
{
Expand Down Expand Up @@ -208,7 +207,7 @@ fn find_scalar_range(outer: &[u8], inner: &[u8]) -> Result<Range<usize>, Error>
impl<C> signature::PrehashSignature for Signature<C>
where
C: Curve + crate::hazmat::DigestPrimitive,
C::FieldSize: Add + ArrayLength<u8> + BigUIntSize,
C::FieldSize: Add + ArrayLength<u8> + NonZero,
MaxSize<C>: ArrayLength<u8>,
<C::FieldSize as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
{
Expand Down
9 changes: 6 additions & 3 deletions ecdsa/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@ use generic_array::{sequence::Concat, typenum::Unsigned, ArrayLength, GenericArr
#[cfg(feature = "arithmetic")]
use elliptic_curve::{ff::PrimeField, NonZeroScalar, ProjectiveArithmetic, Scalar};

#[cfg(feature = "der")]
use generic_array::typenum::NonZero;

/// Size of a fixed sized signature for the given elliptic curve.
pub type SignatureSize<C> = <<C as elliptic_curve::Curve>::FieldSize as Add>::Output;

Expand Down Expand Up @@ -159,7 +162,7 @@ where
#[cfg_attr(docsrs, doc(cfg(feature = "der")))]
pub fn from_der(bytes: &[u8]) -> Result<Self, Error>
where
C::FieldSize: Add + ArrayLength<u8> + der::BigUIntSize,
C::FieldSize: Add + ArrayLength<u8> + NonZero,
der::MaxSize<C>: ArrayLength<u8>,
<C::FieldSize as Add>::Output: Add<der::MaxOverhead> + ArrayLength<u8>,
{
Expand All @@ -171,7 +174,7 @@ where
#[cfg_attr(docsrs, doc(cfg(feature = "der")))]
pub fn to_der(&self) -> der::Signature<C>
where
C::FieldSize: Add + ArrayLength<u8> + der::BigUIntSize,
C::FieldSize: Add + ArrayLength<u8> + NonZero,
der::MaxSize<C>: ArrayLength<u8>,
<C::FieldSize as Add>::Output: Add<der::MaxOverhead> + ArrayLength<u8>,
{
Expand Down Expand Up @@ -293,7 +296,7 @@ where
impl<C> TryFrom<der::Signature<C>> for Signature<C>
where
C: Curve + CheckSignatureBytes,
C::FieldSize: Add + ArrayLength<u8> + der::BigUIntSize,
C::FieldSize: Add + ArrayLength<u8> + NonZero,
der::MaxSize<C>: ArrayLength<u8>,
<C::FieldSize as Add>::Output: Add<der::MaxOverhead> + ArrayLength<u8>,
{
Expand Down

0 comments on commit 6bbe347

Please sign in to comment.