pub struct Signature<C: PrimeCurve> where
SignatureSize<C>: ArrayLength<u8>, { /* private fields */ }
Expand description
ECDSA signature (fixed-size). Generic over elliptic curve types.
Serialized as fixed-sized big endian scalar values with no added 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 DER-encoded signatures also supported via the
Signature::from_der
and Signature::to_der
methods.
serde
support
When the serde
feature of this crate is enabled, it provides support for
serializing and deserializing ECDSA signatures using the Serialize
and
Deserialize
traits.
The serialization uses a 64-byte fixed encoding when used with binary formats, and a hexadecimal encoding when used with text formats.
Implementations
sourceimpl<C> Signature<C> where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Signature<C> where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
sourcepub fn from_der(bytes: &[u8]) -> Result<Self> where
MaxSize<C>: ArrayLength<u8>,
<FieldSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
Available on crate feature der
only.
pub fn from_der(bytes: &[u8]) -> Result<Self> where
MaxSize<C>: ArrayLength<u8>,
<FieldSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
der
only.Parse a signature from ASN.1 DER
sourcepub fn from_scalars(
r: impl Into<FieldBytes<C>>,
s: impl Into<FieldBytes<C>>
) -> Result<Self>
pub fn from_scalars(
r: impl Into<FieldBytes<C>>,
s: impl Into<FieldBytes<C>>
) -> Result<Self>
Create a Signature
from the serialized r
and s
scalar values
which comprise the signature.
sourcepub fn split_bytes(&self) -> (FieldBytes<C>, FieldBytes<C>)
pub fn split_bytes(&self) -> (FieldBytes<C>, FieldBytes<C>)
Split the signature into its r
and s
components, represented as bytes.
sourceimpl<C> Signature<C> where
C: PrimeCurve + ScalarArithmetic,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Signature<C> where
C: PrimeCurve + ScalarArithmetic,
SignatureSize<C>: ArrayLength<u8>,
sourcepub fn r(&self) -> NonZeroScalar<C>
Available on crate feature arithmetic
only.
pub fn r(&self) -> NonZeroScalar<C>
arithmetic
only.Get the r
component of this signature
sourcepub fn s(&self) -> NonZeroScalar<C>
Available on crate feature arithmetic
only.
pub fn s(&self) -> NonZeroScalar<C>
arithmetic
only.Get the s
component of this signature
sourcepub fn split_scalars(&self) -> (NonZeroScalar<C>, NonZeroScalar<C>)
Available on crate feature arithmetic
only.
pub fn split_scalars(&self) -> (NonZeroScalar<C>, NonZeroScalar<C>)
arithmetic
only.Split the signature into its r
and s
scalars.
sourcepub fn normalize_s(&self) -> Option<Self>
Available on crate feature arithmetic
only.
pub fn normalize_s(&self) -> Option<Self>
arithmetic
only.Normalize signature into “low S” form as described in BIP 0062: Dealing with Malleability.
Trait Implementations
sourceimpl<C> AsRef<[u8]> for Signature<C> where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
impl<C> AsRef<[u8]> for Signature<C> where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
sourceimpl<C: Clone + PrimeCurve> Clone for Signature<C> where
SignatureSize<C>: ArrayLength<u8>,
impl<C: Clone + PrimeCurve> Clone for Signature<C> where
SignatureSize<C>: ArrayLength<u8>,
sourceimpl<C> Debug for Signature<C> where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Debug for Signature<C> where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
sourceimpl<'de, C> Deserialize<'de> for Signature<C> where
C: PrimeCurve + ScalarArithmetic,
SignatureSize<C>: ArrayLength<u8>,
Available on crate features arithmetic
and serde
only.
impl<'de, C> Deserialize<'de> for Signature<C> where
C: PrimeCurve + ScalarArithmetic,
SignatureSize<C>: ArrayLength<u8>,
arithmetic
and serde
only.sourcefn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where
D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<C, D> DigestSigner<D, Signature<C>> for SigningKey<C> where
C: PrimeCurve + ProjectiveArithmetic,
C::UInt: for<'a> From<&'a Scalar<C>>,
D: CoreProxy + Digest + FixedOutput<OutputSize = FieldSize<C>>,
D::Core: BlockSizeUser + BufferKindUser<BufferKind = Eager> + Clone + Default + FixedOutputCore + HashMarker + OutputSizeUser<OutputSize = D::OutputSize>,
<D::Core as BlockSizeUser>::BlockSize: IsLess<U256>,
Le<<D::Core as BlockSizeUser>::BlockSize, U256>: NonZero,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
impl<C, D> DigestSigner<D, Signature<C>> for SigningKey<C> where
C: PrimeCurve + ProjectiveArithmetic,
C::UInt: for<'a> From<&'a Scalar<C>>,
D: CoreProxy + Digest + FixedOutput<OutputSize = FieldSize<C>>,
D::Core: BlockSizeUser + BufferKindUser<BufferKind = Eager> + Clone + Default + FixedOutputCore + HashMarker + OutputSizeUser<OutputSize = D::OutputSize>,
<D::Core as BlockSizeUser>::BlockSize: IsLess<U256>,
Le<<D::Core as BlockSizeUser>::BlockSize, U256>: NonZero,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
sourcefn try_sign_digest(&self, msg_digest: D) -> Result<Signature<C>>
fn try_sign_digest(&self, msg_digest: D) -> Result<Signature<C>>
Sign message digest using a deterministic ephemeral scalar (k
)
computed using the algorithm described in RFC6979 § 3.2.
sourcefn sign_digest(&self, digest: D) -> S
fn sign_digest(&self, digest: D) -> S
sourceimpl<C, D> DigestVerifier<D, Signature<C>> for VerifyingKey<C> where
C: PrimeCurve + ProjectiveArithmetic,
D: Digest + FixedOutput<OutputSize = FieldSize<C>>,
AffinePoint<C>: VerifyPrimitive<C>,
Scalar<C>: Reduce<C::UInt>,
SignatureSize<C>: ArrayLength<u8>,
impl<C, D> DigestVerifier<D, Signature<C>> for VerifyingKey<C> where
C: PrimeCurve + ProjectiveArithmetic,
D: Digest + FixedOutput<OutputSize = FieldSize<C>>,
AffinePoint<C>: VerifyPrimitive<C>,
Scalar<C>: Reduce<C::UInt>,
SignatureSize<C>: ArrayLength<u8>,
sourceimpl<C> Display for Signature<C> where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Display for Signature<C> where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
sourceimpl<C> FromStr for Signature<C> where
C: PrimeCurve + ScalarArithmetic,
SignatureSize<C>: ArrayLength<u8>,
Available on crate feature arithmetic
only.
impl<C> FromStr for Signature<C> where
C: PrimeCurve + ScalarArithmetic,
SignatureSize<C>: ArrayLength<u8>,
arithmetic
only.sourceimpl<C> LowerHex for Signature<C> where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
impl<C> LowerHex for Signature<C> where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
sourceimpl<C: PartialEq + PrimeCurve> PartialEq<Signature<C>> for Signature<C> where
SignatureSize<C>: ArrayLength<u8>,
impl<C: PartialEq + PrimeCurve> PartialEq<Signature<C>> for Signature<C> where
SignatureSize<C>: ArrayLength<u8>,
sourceimpl<C> PrehashSignature for Signature<C> where
C: DigestPrimitive,
<FieldSize<C> as Add>::Output: ArrayLength<u8>,
Available on crate feature hazmat
only.
impl<C> PrehashSignature for Signature<C> where
C: DigestPrimitive,
<FieldSize<C> as Add>::Output: ArrayLength<u8>,
hazmat
only.type Digest = <C as DigestPrimitive>::Digest
type Digest = <C as DigestPrimitive>::Digest
Preferred Digest
algorithm to use when computing this signature type.
sourceimpl<C, D> RandomizedDigestSigner<D, Signature<C>> for SigningKey<C> where
C: PrimeCurve + ProjectiveArithmetic,
C::UInt: for<'a> From<&'a Scalar<C>>,
D: CoreProxy + Digest + FixedOutput<OutputSize = FieldSize<C>>,
D::Core: BlockSizeUser + BufferKindUser<BufferKind = Eager> + Clone + Default + FixedOutputCore + HashMarker + OutputSizeUser<OutputSize = D::OutputSize>,
<D::Core as BlockSizeUser>::BlockSize: IsLess<U256>,
Le<<D::Core as BlockSizeUser>::BlockSize, U256>: NonZero,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
impl<C, D> RandomizedDigestSigner<D, Signature<C>> for SigningKey<C> where
C: PrimeCurve + ProjectiveArithmetic,
C::UInt: for<'a> From<&'a Scalar<C>>,
D: CoreProxy + Digest + FixedOutput<OutputSize = FieldSize<C>>,
D::Core: BlockSizeUser + BufferKindUser<BufferKind = Eager> + Clone + Default + FixedOutputCore + HashMarker + OutputSizeUser<OutputSize = D::OutputSize>,
<D::Core as BlockSizeUser>::BlockSize: IsLess<U256>,
Le<<D::Core as BlockSizeUser>::BlockSize, U256>: NonZero,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
sourcefn try_sign_digest_with_rng(
&self,
rng: impl CryptoRng + RngCore,
msg: D
) -> Result<Signature<C>>
fn try_sign_digest_with_rng(
&self,
rng: impl CryptoRng + RngCore,
msg: D
) -> Result<Signature<C>>
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.
sourcefn sign_digest_with_rng(&self, rng: impl CryptoRng + RngCore, digest: D) -> S
fn sign_digest_with_rng(&self, rng: impl CryptoRng + RngCore, digest: D) -> S
Sign the given prehashed message Digest
, returning a signature. Read more
sourceimpl<C> RandomizedSigner<Signature<C>> for SigningKey<C> where
Self: RandomizedDigestSigner<C::Digest, Signature<C>>,
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
impl<C> RandomizedSigner<Signature<C>> for SigningKey<C> where
Self: RandomizedDigestSigner<C::Digest, Signature<C>>,
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
sourceimpl<C> Serialize for Signature<C> where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
Available on crate feature serde
only.
impl<C> Serialize for Signature<C> where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
serde
only.sourceimpl<C> Signature for Signature<C> where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Signature for Signature<C> where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
sourceimpl<C> Signer<Signature<C>> for SigningKey<C> where
Self: DigestSigner<C::Digest, Signature<C>>,
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Signer<Signature<C>> for SigningKey<C> where
Self: DigestSigner<C::Digest, Signature<C>>,
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + Reduce<C::UInt> + SignPrimitive<C>,
SignatureSize<C>: ArrayLength<u8>,
sourceimpl<C> TryFrom<&'_ [u8]> for Signature<C> where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
impl<C> TryFrom<&'_ [u8]> for Signature<C> where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
sourceimpl<C> TryFrom<Signature<C>> for Signature<C> where
C: PrimeCurve,
MaxSize<C>: ArrayLength<u8>,
<FieldSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
Available on crate feature der
only.
impl<C> TryFrom<Signature<C>> for Signature<C> where
C: PrimeCurve,
MaxSize<C>: ArrayLength<u8>,
<FieldSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,
der
only.sourceimpl<C> UpperHex for Signature<C> where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
impl<C> UpperHex for Signature<C> where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
sourceimpl<C> Verifier<Signature<C>> for VerifyingKey<C> where
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
C::Digest: Digest + FixedOutput<OutputSize = FieldSize<C>>,
AffinePoint<C>: VerifyPrimitive<C>,
Scalar<C>: Reduce<C::UInt>,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Verifier<Signature<C>> for VerifyingKey<C> where
C: PrimeCurve + ProjectiveArithmetic + DigestPrimitive,
C::Digest: Digest + FixedOutput<OutputSize = FieldSize<C>>,
AffinePoint<C>: VerifyPrimitive<C>,
Scalar<C>: Reduce<C::UInt>,
SignatureSize<C>: ArrayLength<u8>,
impl<C> Copy for Signature<C> where
C: PrimeCurve,
SignatureSize<C>: ArrayLength<u8>,
<SignatureSize<C> as ArrayLength<u8>>::ArrayType: Copy,
impl<C: Eq + PrimeCurve> Eq for Signature<C> where
SignatureSize<C>: ArrayLength<u8>,
impl<C: PrimeCurve> StructuralEq for Signature<C> where
SignatureSize<C>: ArrayLength<u8>,
impl<C: PrimeCurve> StructuralPartialEq for Signature<C> where
SignatureSize<C>: ArrayLength<u8>,
Auto Trait Implementations
impl<C> RefUnwindSafe for Signature<C> where
<<<<C as Curve>::UInt as ArrayEncoding>::ByteSize as Add<<<C as Curve>::UInt as ArrayEncoding>::ByteSize>>::Output as ArrayLength<u8>>::ArrayType: RefUnwindSafe,
impl<C> Send for Signature<C>
impl<C> Sync for Signature<C>
impl<C> Unpin for Signature<C> where
<<<<C as Curve>::UInt as ArrayEncoding>::ByteSize as Add<<<C as Curve>::UInt as ArrayEncoding>::ByteSize>>::Output as ArrayLength<u8>>::ArrayType: Unpin,
impl<C> UnwindSafe for Signature<C> where
<<<<C as Curve>::UInt as ArrayEncoding>::ByteSize as Add<<<C as Curve>::UInt as ArrayEncoding>::ByteSize>>::Output as ArrayLength<u8>>::ArrayType: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more