pub struct Signature<C: EcdsaCurve> { /* private fields */ }Expand description
ECDSA signature (fixed-size, a.k.a. IEEE P1363). 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
Both r and s MUST be non-zero.
For example, in a curve with a 256-bit modulus like NIST P-256 or secp256k1, r and s are
both 32-bytes and serialized as big endian, 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 hexadecimal encoding when used with “human readable” text formats, and a binary encoding otherwise.
Implementations§
Source§impl<C> Signature<C>where
C: EcdsaCurve,
impl<C> Signature<C>where
C: EcdsaCurve,
Sourcepub fn from_bytes(bytes: &SignatureBytes<C>) -> Result<Self>
pub fn from_bytes(bytes: &SignatureBytes<C>) -> Result<Self>
Parse a signature from fixed-width bytes, i.e. 2 * the size of FieldBytes for a
particular curve.
§Errors
If the r and/or s component of the signature is out-of-range when interpreted as a big
endian integer.
Sourcepub fn from_slice(slice: &[u8]) -> Result<Self>
pub fn from_slice(slice: &[u8]) -> Result<Self>
Parse a signature from a byte slice.
§Errors
Returns Error in the event the signature is not the expected size, i.e. 2 * the size of
FieldBytes for a particular curve.
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>
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.
Sourcepub fn to_bytes(&self) -> SignatureBytes<C>
pub fn to_bytes(&self) -> SignatureBytes<C>
Serialize this signature as bytes.
Source§impl<C> Signature<C>where
C: EcdsaCurve + CurveArithmetic,
impl<C> Signature<C>where
C: EcdsaCurve + CurveArithmetic,
Sourcepub fn r(&self) -> NonZeroScalar<C>
Available on crate feature algorithm only.
pub fn r(&self) -> NonZeroScalar<C>
algorithm only.Get the r component of this signature
Sourcepub fn s(&self) -> NonZeroScalar<C>
Available on crate feature algorithm only.
pub fn s(&self) -> NonZeroScalar<C>
algorithm only.Get the s component of this signature
Sourcepub fn split_scalars(&self) -> (NonZeroScalar<C>, NonZeroScalar<C>)
Available on crate feature algorithm only.
pub fn split_scalars(&self) -> (NonZeroScalar<C>, NonZeroScalar<C>)
algorithm only.Split the signature into its r and s scalars.
Sourcepub fn normalize_s(&self) -> Self
Available on crate feature algorithm only.
pub fn normalize_s(&self) -> Self
algorithm only.Normalize signature into “low S” form described in BIP 0062: Dealing with Malleability.
Trait Implementations§
Source§impl<C> AssociatedAlgorithmIdentifier for Signature<C>where
C: EcdsaCurve,
Self: AssociatedOid,
Available on crate feature pkcs8 only.ECDSA AlgorithmIdentifier which identifies the digest used by default
with the Signer and Verifier traits.
impl<C> AssociatedAlgorithmIdentifier for Signature<C>where
C: EcdsaCurve,
Self: AssociatedOid,
pkcs8 only.ECDSA AlgorithmIdentifier which identifies the digest used by default
with the Signer and Verifier traits.
Source§const ALGORITHM_IDENTIFIER: AlgorithmIdentifierRef<'static>
const ALGORITHM_IDENTIFIER: AlgorithmIdentifierRef<'static>
AlgorithmIdentifier for this structure.Source§impl<C> AssociatedOid for Signature<C>
Available on crate feature digest only.ECDSA ObjectIdentifier which identifies the digest used by default with the Signer and
Verifier traits.
impl<C> AssociatedOid for Signature<C>
digest only.ECDSA ObjectIdentifier which identifies the digest used by default with the Signer and
Verifier traits.
To support non-default digest algorithms, use the SignatureWithOid type instead.
Source§const OID: ObjectIdentifier
const OID: ObjectIdentifier
impl<C: Copy + EcdsaCurve> Copy for Signature<C>
Source§impl<C> Debug for Signature<C>where
C: EcdsaCurve,
impl<C> Debug for Signature<C>where
C: EcdsaCurve,
Source§impl<'de, C> Deserialize<'de> for Signature<C>where
C: EcdsaCurve,
Available on crate feature serde only.
impl<'de, C> Deserialize<'de> for Signature<C>where
C: EcdsaCurve,
serde only.Source§fn 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>,
Source§impl<C, D> DigestSigner<D, Signature<C>> for SigningKey<C>where
C: EcdsaCurve + CurveArithmetic + DigestAlgorithm,
D: Digest + FixedOutput,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
Available on crate feature algorithm only.Sign message digest using a deterministic ephemeral scalar (k)
computed using the algorithm described in RFC6979 § 3.2.
impl<C, D> DigestSigner<D, Signature<C>> for SigningKey<C>where
C: EcdsaCurve + CurveArithmetic + DigestAlgorithm,
D: Digest + FixedOutput,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
algorithm only.Sign message digest using a deterministic ephemeral scalar (k)
computed using the algorithm described in RFC6979 § 3.2.
Source§impl<C, D> DigestVerifier<D, Signature<C>> for VerifyingKey<C>
Available on crate feature algorithm only.
impl<C, D> DigestVerifier<D, Signature<C>> for VerifyingKey<C>
algorithm only.Source§impl<C> Display for Signature<C>where
C: EcdsaCurve,
impl<C> Display for Signature<C>where
C: EcdsaCurve,
impl<C: Eq + EcdsaCurve> Eq for Signature<C>
Source§impl<C> From<Signature<C>> for Signature<C>where
C: EcdsaCurve,
MaxSize<C>: ArraySize,
<FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArraySize,
Available on crate feature der only.
impl<C> From<Signature<C>> for Signature<C>where
C: EcdsaCurve,
MaxSize<C>: ArraySize,
<FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArraySize,
der only.Source§impl<C> From<Signature<C>> for SignatureBytes<C>where
C: EcdsaCurve,
impl<C> From<Signature<C>> for SignatureBytes<C>where
C: EcdsaCurve,
Source§fn from(signature: Signature<C>) -> SignatureBytes<C>
fn from(signature: Signature<C>) -> SignatureBytes<C>
Source§impl<C> From<SignatureWithOid<C>> for Signature<C>where
C: EcdsaCurve,
Available on crate feature digest only.
impl<C> From<SignatureWithOid<C>> for Signature<C>where
C: EcdsaCurve,
digest only.Source§fn from(sig: SignatureWithOid<C>) -> Signature<C>
fn from(sig: SignatureWithOid<C>) -> Signature<C>
Source§impl<C> FromStr for Signature<C>where
C: EcdsaCurve + CurveArithmetic,
Available on crate feature algorithm only.
impl<C> FromStr for Signature<C>where
C: EcdsaCurve + CurveArithmetic,
algorithm only.Source§impl<C> Hash for Signature<C>where
C: EcdsaCurve,
impl<C> Hash for Signature<C>where
C: EcdsaCurve,
Source§impl<C> LowerHex for Signature<C>where
C: EcdsaCurve,
impl<C> LowerHex for Signature<C>where
C: EcdsaCurve,
Source§impl<C> MultipartSigner<Signature<C>> for SigningKey<C>where
C: EcdsaCurve + CurveArithmetic + DigestAlgorithm,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
Available on crate feature algorithm only.
impl<C> MultipartSigner<Signature<C>> for SigningKey<C>where
C: EcdsaCurve + CurveArithmetic + DigestAlgorithm,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
algorithm only.Source§fn try_multipart_sign(&self, msg: &[&[u8]]) -> Result<Signature<C>, Error>
fn try_multipart_sign(&self, msg: &[&[u8]]) -> Result<Signature<C>, Error>
Signer::try_sign() but the message is provided in non-contiguous byte
slices. Read moreSource§fn multipart_sign(&self, msg: &[&[u8]]) -> S
fn multipart_sign(&self, msg: &[&[u8]]) -> S
Signer::sign() but the message is provided in non-contiguous byte slices.Source§impl<C> MultipartVerifier<Signature<C>> for VerifyingKey<C>
Available on crate feature algorithm only.
impl<C> MultipartVerifier<Signature<C>> for VerifyingKey<C>
algorithm only.Source§fn multipart_verify(
&self,
msg: &[&[u8]],
signature: &Signature<C>,
) -> Result<()>
fn multipart_verify( &self, msg: &[&[u8]], signature: &Signature<C>, ) -> Result<()>
Verifier::verify() but the message is provided in non-contiguous byte
slices. Read moreSource§impl<C: PartialEq + EcdsaCurve> PartialEq for Signature<C>
impl<C: PartialEq + EcdsaCurve> PartialEq for Signature<C>
Source§impl<C> PrehashSigner<Signature<C>> for SigningKey<C>where
C: EcdsaCurve + CurveArithmetic + DigestAlgorithm,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
Available on crate feature algorithm only.Sign message prehash using a deterministic ephemeral scalar (k) computed using the algorithm
described in RFC6979 § 3.2.
impl<C> PrehashSigner<Signature<C>> for SigningKey<C>where
C: EcdsaCurve + CurveArithmetic + DigestAlgorithm,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
algorithm only.Sign message prehash using a deterministic ephemeral scalar (k) computed using the algorithm
described in RFC6979 § 3.2.
Source§impl<C> PrehashVerifier<Signature<C>> for VerifyingKey<C>where
C: EcdsaCurve + CurveArithmetic,
Available on crate feature algorithm only.
impl<C> PrehashVerifier<Signature<C>> for VerifyingKey<C>where
C: EcdsaCurve + CurveArithmetic,
algorithm only.Source§impl<C, D> RandomizedDigestSigner<D, Signature<C>> for SigningKey<C>where
C: EcdsaCurve + CurveArithmetic + DigestAlgorithm,
D: Digest + FixedOutput,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
Available on crate feature algorithm only.
impl<C, D> RandomizedDigestSigner<D, Signature<C>> for SigningKey<C>where
C: EcdsaCurve + CurveArithmetic + DigestAlgorithm,
D: Digest + FixedOutput,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
algorithm only.Source§impl<C> RandomizedMultipartSigner<Signature<C>> for SigningKey<C>where
Self: RandomizedDigestSigner<C::Digest, Signature<C>>,
C: EcdsaCurve + CurveArithmetic + DigestAlgorithm,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
Available on crate feature algorithm only.
impl<C> RandomizedMultipartSigner<Signature<C>> for SigningKey<C>where
Self: RandomizedDigestSigner<C::Digest, Signature<C>>,
C: EcdsaCurve + CurveArithmetic + DigestAlgorithm,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
algorithm only.Source§fn try_multipart_sign_with_rng<R: TryCryptoRng + ?Sized>(
&self,
rng: &mut R,
msg: &[&[u8]],
) -> Result<Signature<C>>
fn try_multipart_sign_with_rng<R: TryCryptoRng + ?Sized>( &self, rng: &mut R, msg: &[&[u8]], ) -> Result<Signature<C>>
RandomizedSigner::try_sign_with_rng() but the message is provided in
non-contiguous byte slices. Read moreSource§fn multipart_sign_with_rng<R>(&self, rng: &mut R, msg: &[&[u8]]) -> S
fn multipart_sign_with_rng<R>(&self, rng: &mut R, msg: &[&[u8]]) -> S
RandomizedSigner::sign_with_rng() but the message is provided in
non-contiguous byte slices.Source§impl<C> RandomizedPrehashSigner<Signature<C>> for SigningKey<C>where
C: EcdsaCurve + CurveArithmetic + DigestAlgorithm,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
Available on crate feature algorithm only.
impl<C> RandomizedPrehashSigner<Signature<C>> for SigningKey<C>where
C: EcdsaCurve + CurveArithmetic + DigestAlgorithm,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
algorithm only.Source§fn sign_prehash_with_rng<R: TryCryptoRng + ?Sized>(
&self,
rng: &mut R,
prehash: &[u8],
) -> Result<Signature<C>>
fn sign_prehash_with_rng<R: TryCryptoRng + ?Sized>( &self, rng: &mut R, prehash: &[u8], ) -> Result<Signature<C>>
Source§impl<C> RandomizedSigner<Signature<C>> for SigningKey<C>where
Self: RandomizedDigestSigner<C::Digest, Signature<C>>,
C: EcdsaCurve + CurveArithmetic + DigestAlgorithm,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
Available on crate feature algorithm only.
impl<C> RandomizedSigner<Signature<C>> for SigningKey<C>where
Self: RandomizedDigestSigner<C::Digest, Signature<C>>,
C: EcdsaCurve + CurveArithmetic + DigestAlgorithm,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
algorithm only.Source§fn try_sign_with_rng<R: TryCryptoRng + ?Sized>(
&self,
rng: &mut R,
msg: &[u8],
) -> Result<Signature<C>>
fn try_sign_with_rng<R: TryCryptoRng + ?Sized>( &self, rng: &mut R, msg: &[u8], ) -> Result<Signature<C>>
Source§impl<C> Serialize for Signature<C>where
C: EcdsaCurve,
Available on crate feature serde only.
impl<C> Serialize for Signature<C>where
C: EcdsaCurve,
serde only.Source§impl<C> SignatureEncoding for Signature<C>where
C: EcdsaCurve,
impl<C> SignatureEncoding for Signature<C>where
C: EcdsaCurve,
Source§type Repr = Array<u8, <<C as Curve>::FieldBytesSize as Add>::Output>
type Repr = Array<u8, <<C as Curve>::FieldBytesSize as Add>::Output>
Source§fn to_vec(&self) -> Vec<u8> ⓘ
fn to_vec(&self) -> Vec<u8> ⓘ
alloc only.Source§fn encoded_len(&self) -> usize
fn encoded_len(&self) -> usize
Source§impl<C> Signer<Signature<C>> for SigningKey<C>where
C: EcdsaCurve + CurveArithmetic + DigestAlgorithm,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
Available on crate feature algorithm only.Sign message using a deterministic ephemeral scalar (k)
computed using the algorithm described in RFC6979 § 3.2.
impl<C> Signer<Signature<C>> for SigningKey<C>where
C: EcdsaCurve + CurveArithmetic + DigestAlgorithm,
Scalar<C>: Invert<Output = CtOption<Scalar<C>>>,
algorithm only.Sign message using a deterministic ephemeral scalar (k)
computed using the algorithm described in RFC6979 § 3.2.
impl<C: PartialEq + EcdsaCurve> StructuralPartialEq for Signature<C>
Source§impl<C> TryFrom<Signature<C>> for Signature<C>where
C: EcdsaCurve,
MaxSize<C>: ArraySize,
<FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArraySize,
Available on crate feature der only.
impl<C> TryFrom<Signature<C>> for Signature<C>where
C: EcdsaCurve,
MaxSize<C>: ArraySize,
<FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArraySize,
der only.Source§impl<C> UpperHex for Signature<C>where
C: EcdsaCurve,
impl<C> UpperHex for Signature<C>where
C: EcdsaCurve,
Source§impl<C> Verifier<Signature<C>> for VerifyingKey<C>
Available on crate feature algorithm only.
impl<C> Verifier<Signature<C>> for VerifyingKey<C>
algorithm only.Auto Trait Implementations§
impl<C> Freeze for Signature<C>
impl<C> RefUnwindSafe for Signature<C>
impl<C> Send for Signature<C>
impl<C> Sync for Signature<C>
impl<C> Unpin for Signature<C>
impl<C> UnsafeUnpin for Signature<C>
impl<C> UnwindSafe for Signature<C>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> DynAssociatedAlgorithmIdentifier for Twhere
T: AssociatedAlgorithmIdentifier,
impl<T> DynAssociatedAlgorithmIdentifier for Twhere
T: AssociatedAlgorithmIdentifier,
Source§fn algorithm_identifier(&self) -> Result<AlgorithmIdentifier<Any>, Error>
fn algorithm_identifier(&self) -> Result<AlgorithmIdentifier<Any>, Error>
AlgorithmIdentifier for this structure. Read more