pub struct Signature<C: Curve + CheckSignatureBytes> where
SignatureSize<C>: ArrayLength<u8>, { /* private fields */ }
Expand description
ECDSA signatures (fixed-size).
Generic over elliptic curve types.
These signatures are serialized as fixed-sized big endian scalar values with no additional framing:
r
: field element size for the given curve, big-endians
: field element size for the given curve, big-endian
For example, in a curve with a 256-bit modulus like NIST P-256 or
secp256k1, r
and s
will both be 32-bytes, resulting in a signature
with a total of 64-bytes.
ASN.1 is also supported via the Signature::from_asn1
and
Signature::to_asn1
methods.
Implementations
pub fn from_scalars(
r: impl Into<FieldBytes<C>>,
s: impl Into<FieldBytes<C>>
) -> Result<Self, Error>
pub fn from_scalars(
r: impl Into<FieldBytes<C>>,
s: impl Into<FieldBytes<C>>
) -> Result<Self, Error>
Create a Signature
from the serialized r
and s
scalar values
which comprise the signature.
Parse a signature from ASN.1 DER
pub fn to_asn1(&self) -> Signature<C> where
C::FieldSize: Add + ArrayLength<u8>,
MaxSize<C>: ArrayLength<u8>,
<C::FieldSize as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
pub fn to_asn1(&self) -> Signature<C> where
C::FieldSize: Add + ArrayLength<u8>,
MaxSize<C>: ArrayLength<u8>,
<C::FieldSize as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
Serialize this signature as ASN.1 DER
impl<C> Signature<C> where
C: Curve + ProjectiveArithmetic,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
<Scalar<C> as PrimeField>::Repr: From<Scalar<C>> + for<'a> From<&'a Scalar<C>>,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Signature<C> where
C: Curve + ProjectiveArithmetic,
Scalar<C>: PrimeField<Repr = FieldBytes<C>>,
<Scalar<C> as PrimeField>::Repr: From<Scalar<C>> + for<'a> From<&'a Scalar<C>>,
SignatureSize<C>: ArrayLength<u8>,
Get the r
component of this signature
Get the s
component of this signature
Normalize signature into “low S” form as described in BIP 0062: Dealing with Malleability.
Trait Implementations
impl<C> AsRef<[u8]> for Signature<C> where
C: Curve + CheckSignatureBytes,
SignatureSize<C>: ArrayLength<u8>,
impl<C> AsRef<[u8]> for Signature<C> where
C: Curve + CheckSignatureBytes,
SignatureSize<C>: ArrayLength<u8>,
impl<C: Clone + Curve + CheckSignatureBytes> Clone for Signature<C> where
SignatureSize<C>: ArrayLength<u8>,
impl<C: Clone + Curve + CheckSignatureBytes> Clone for Signature<C> where
SignatureSize<C>: ArrayLength<u8>,
impl<C> Debug for Signature<C> where
C: Curve + CheckSignatureBytes,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Debug for Signature<C> where
C: Curve + CheckSignatureBytes,
SignatureSize<C>: ArrayLength<u8>,
impl<C, D> DigestSigner<D, Signature<C>> for SigningKey<C> where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>> + FromDigest<C> + Invert<Output = Scalar<C>> + SignPrimitive<C> + Zeroize,
D: FixedOutput<OutputSize = C::FieldSize> + BlockInput + Clone + Default + Reset + Update,
SignatureSize<C>: ArrayLength<u8>,
impl<C, D> DigestSigner<D, Signature<C>> for SigningKey<C> where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>> + FromDigest<C> + Invert<Output = Scalar<C>> + SignPrimitive<C> + Zeroize,
D: FixedOutput<OutputSize = C::FieldSize> + BlockInput + Clone + Default + Reset + Update,
SignatureSize<C>: ArrayLength<u8>,
Sign message prehash using a deterministic ephemeral scalar (k
)
computed using the algorithm described in RFC 6979 (Section 3.2):
https://tools.ietf.org/html/rfc6979#section-3
Sign the given prehashed message Digest
, returning a signature. Read more
impl<C, D> DigestVerifier<D, Signature<C>> for VerifyingKey<C> where
C: Curve + ProjectiveArithmetic,
D: Digest<OutputSize = C::FieldSize>,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>> + FromDigest<C>,
AffinePoint<C>: Copy + Clone + Debug + VerifyPrimitive<C>,
ProjectivePoint<C>: From<AffinePoint<C>>,
SignatureSize<C>: ArrayLength<u8>,
impl<C, D> DigestVerifier<D, Signature<C>> for VerifyingKey<C> where
C: Curve + ProjectiveArithmetic,
D: Digest<OutputSize = C::FieldSize>,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>> + FromDigest<C>,
AffinePoint<C>: Copy + Clone + Debug + VerifyPrimitive<C>,
ProjectivePoint<C>: From<AffinePoint<C>>,
SignatureSize<C>: ArrayLength<u8>,
impl<C: PartialEq + Curve + CheckSignatureBytes> PartialEq<Signature<C>> for Signature<C> where
SignatureSize<C>: ArrayLength<u8>,
impl<C: PartialEq + Curve + CheckSignatureBytes> PartialEq<Signature<C>> for Signature<C> where
SignatureSize<C>: ArrayLength<u8>,
impl<C> PrehashSignature for Signature<C> where
C: DigestPrimitive + CheckSignatureBytes,
<C::FieldSize as Add>::Output: ArrayLength<u8>,
impl<C> PrehashSignature for Signature<C> where
C: DigestPrimitive + CheckSignatureBytes,
<C::FieldSize as Add>::Output: ArrayLength<u8>,
impl<C, D> RandomizedDigestSigner<D, Signature<C>> for SigningKey<C> where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>> + FromDigest<C> + Invert<Output = Scalar<C>> + SignPrimitive<C> + Zeroize,
D: FixedOutput<OutputSize = C::FieldSize> + BlockInput + Clone + Default + Reset + Update,
SignatureSize<C>: ArrayLength<u8>,
impl<C, D> RandomizedDigestSigner<D, Signature<C>> for SigningKey<C> where
C: Curve + ProjectiveArithmetic,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>> + FromDigest<C> + Invert<Output = Scalar<C>> + SignPrimitive<C> + Zeroize,
D: FixedOutput<OutputSize = C::FieldSize> + BlockInput + Clone + Default + Reset + Update,
SignatureSize<C>: ArrayLength<u8>,
Sign message prehash using an ephemeral scalar (k
) derived according
to a variant of RFC 6979 (Section 3.6) which supplies additional
entropy from an RNG.
Sign the given prehashed message Digest
, returning a signature. Read more
impl<C> RandomizedSigner<Signature<C>> for SigningKey<C> where
C: Curve + ProjectiveArithmetic + DigestPrimitive,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>> + FromDigest<C> + Invert<Output = Scalar<C>> + SignPrimitive<C> + Zeroize,
SignatureSize<C>: ArrayLength<u8>,
Self: RandomizedDigestSigner<C::Digest, Signature<C>>,
impl<C> RandomizedSigner<Signature<C>> for SigningKey<C> where
C: Curve + ProjectiveArithmetic + DigestPrimitive,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>> + FromDigest<C> + Invert<Output = Scalar<C>> + SignPrimitive<C> + Zeroize,
SignatureSize<C>: ArrayLength<u8>,
Self: RandomizedDigestSigner<C::Digest, Signature<C>>,
Attempt to sign the given message, returning a digital signature on success, or an error if something went wrong. Read more
impl<C> Signature for Signature<C> where
C: Curve + CheckSignatureBytes,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Signature for Signature<C> where
C: Curve + CheckSignatureBytes,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Signer<Signature<C>> for SigningKey<C> where
C: Curve + ProjectiveArithmetic + DigestPrimitive,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>> + FromDigest<C> + Invert<Output = Scalar<C>> + SignPrimitive<C> + Zeroize,
SignatureSize<C>: ArrayLength<u8>,
Self: DigestSigner<C::Digest, Signature<C>>,
impl<C> Signer<Signature<C>> for SigningKey<C> where
C: Curve + ProjectiveArithmetic + DigestPrimitive,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>> + FromDigest<C> + Invert<Output = Scalar<C>> + SignPrimitive<C> + Zeroize,
SignatureSize<C>: ArrayLength<u8>,
Self: DigestSigner<C::Digest, Signature<C>>,
impl<C> TryFrom<&'_ [u8]> for Signature<C> where
C: Curve + CheckSignatureBytes,
SignatureSize<C>: ArrayLength<u8>,
impl<C> TryFrom<&'_ [u8]> for Signature<C> where
C: Curve + CheckSignatureBytes,
SignatureSize<C>: ArrayLength<u8>,
impl<C> TryFrom<Signature<C>> for Signature<C> where
C: Curve + CheckSignatureBytes,
C::FieldSize: Add + ArrayLength<u8>,
MaxSize<C>: ArrayLength<u8>,
<C::FieldSize as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
impl<C> TryFrom<Signature<C>> for Signature<C> where
C: Curve + CheckSignatureBytes,
C::FieldSize: Add + ArrayLength<u8>,
MaxSize<C>: ArrayLength<u8>,
<C::FieldSize as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
impl<C> Verifier<Signature<C>> for VerifyingKey<C> where
C: Curve + ProjectiveArithmetic + DigestPrimitive,
C::Digest: Digest<OutputSize = C::FieldSize>,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>> + FromDigest<C>,
AffinePoint<C>: Copy + Clone + Debug + VerifyPrimitive<C>,
ProjectivePoint<C>: From<AffinePoint<C>>,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Verifier<Signature<C>> for VerifyingKey<C> where
C: Curve + ProjectiveArithmetic + DigestPrimitive,
C::Digest: Digest<OutputSize = C::FieldSize>,
FieldBytes<C>: From<Scalar<C>> + for<'r> From<&'r Scalar<C>>,
Scalar<C>: PrimeField<Repr = FieldBytes<C>> + FromDigest<C>,
AffinePoint<C>: Copy + Clone + Debug + VerifyPrimitive<C>,
ProjectivePoint<C>: From<AffinePoint<C>>,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Copy for Signature<C> where
C: Curve + CheckSignatureBytes,
SignatureSize<C>: ArrayLength<u8>,
<SignatureSize<C> as ArrayLength<u8>>::ArrayType: Copy,
impl<C: Eq + Curve + CheckSignatureBytes> Eq for Signature<C> where
SignatureSize<C>: ArrayLength<u8>,
impl<C: Curve + CheckSignatureBytes> StructuralEq for Signature<C> where
SignatureSize<C>: ArrayLength<u8>,
impl<C: Curve + CheckSignatureBytes> StructuralPartialEq for Signature<C> where
SignatureSize<C>: ArrayLength<u8>,
Auto Trait Implementations
impl<C> RefUnwindSafe for Signature<C> where
<<<C as Curve>::FieldSize as Add<<C as Curve>::FieldSize>>::Output as ArrayLength<u8>>::ArrayType: RefUnwindSafe,
impl<C> Unpin for Signature<C> where
<<<C as Curve>::FieldSize as Add<<C as Curve>::FieldSize>>::Output as ArrayLength<u8>>::ArrayType: Unpin,
impl<C> UnwindSafe for Signature<C> where
<<<C as Curve>::FieldSize as Add<<C as Curve>::FieldSize>>::Output as ArrayLength<u8>>::ArrayType: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Causes self
to use its Binary
implementation when Debug
-formatted.
Causes self
to use its Display
implementation when
Debug
-formatted. Read more
Causes self
to use its LowerExp
implementation when
Debug
-formatted. Read more
Causes self
to use its LowerHex
implementation when
Debug
-formatted. Read more
Causes self
to use its Octal
implementation when Debug
-formatted.
Causes self
to use its Pointer
implementation when
Debug
-formatted. Read more
Causes self
to use its UpperExp
implementation when
Debug
-formatted. Read more
Causes self
to use its UpperHex
implementation when
Debug
-formatted. Read more
fn pipe_as_ref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: AsRef<T>,
T: 'a,
R: 'a,
fn pipe_as_ref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: AsRef<T>,
T: 'a,
R: 'a,
Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more
fn pipe_borrow<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Borrow<T>,
T: 'a,
R: 'a,
fn pipe_borrow<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Borrow<T>,
T: 'a,
R: 'a,
Pipes a trait borrow into a function that cannot normally be called in suffix position. Read more
fn pipe_deref<'a, R>(&'a self, func: impl FnOnce(&'a Self::Target) -> R) -> R where
Self: Deref,
R: 'a,
fn pipe_deref<'a, R>(&'a self, func: impl FnOnce(&'a Self::Target) -> R) -> R where
Self: Deref,
R: 'a,
Pipes a dereference into a function that cannot normally be called in suffix position. Read more
Pipes a reference into a function that cannot ordinarily be called in suffix position. Read more
Provides immutable access to the reference for inspection.
Calls tap_ref
in debug builds, and does nothing in release builds.
Provides mutable access to the reference for modification.
Calls tap_ref_mut
in debug builds, and does nothing in release builds.
Provides immutable access to the borrow for inspection. Read more
Calls tap_borrow
in debug builds, and does nothing in release builds.
fn tap_borrow_mut<F, R>(self, func: F) -> Self where
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
fn tap_borrow_mut<F, R>(self, func: F) -> Self where
Self: BorrowMut<T>,
F: FnOnce(&mut T) -> R,
Provides mutable access to the borrow for modification.
Immutably dereferences self
for inspection.
fn tap_deref_dbg<F, R>(self, func: F) -> Self where
Self: Deref,
F: FnOnce(&Self::Target) -> R,
fn tap_deref_dbg<F, R>(self, func: F) -> Self where
Self: Deref,
F: FnOnce(&Self::Target) -> R,
Calls tap_deref
in debug builds, and does nothing in release builds.
fn tap_deref_mut<F, R>(self, func: F) -> Self where
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
fn tap_deref_mut<F, R>(self, func: F) -> Self where
Self: DerefMut,
F: FnOnce(&mut Self::Target) -> R,
Mutably dereferences self
for modification.