Struct ecdsa::VerifyingKey

source ·
pub struct VerifyingKey<C>where
    C: PrimeCurve + CurveArithmetic,{ /* private fields */ }
Available on crate feature verifying only.
Expand description

ECDSA public key used for verifying signatures. Generic over prime order elliptic curves (e.g. NIST P-curves)

Requires an elliptic_curve::CurveArithmetic impl on the curve, and a VerifyPrimitive impl on its associated AffinePoint type.

Usage

The signature crate defines the following traits which are the primary API for verifying:

  • Verifier: verify a message against a provided key and signature
  • DigestVerifier: verify a message Digest against a provided key and signature
  • PrehashVerifier: verify the low-level raw output bytes of a message digest

See the p256 crate for examples of using this type with a concrete elliptic curve.

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 leverages the encoding used by the PublicKey type, which is a binary-oriented ASN.1 DER encoding.

Implementations§

source§

impl<C> VerifyingKey<C>where C: PrimeCurve + CurveArithmetic, AffinePoint<C>: DecompressPoint<C> + FromEncodedPoint<C> + ToEncodedPoint<C> + VerifyPrimitive<C>, FieldBytesSize<C>: ModulusSize, SignatureSize<C>: ArrayLength<u8>,

source

pub fn recover_from_msg( msg: &[u8], signature: &Signature<C>, recovery_id: RecoveryId ) -> Result<Self>where C: DigestPrimitive,

Recover a VerifyingKey from the given message, signature, and RecoveryId.

The message is first hashed using this curve’s DigestPrimitive.

source

pub fn recover_from_digest<D>( msg_digest: D, signature: &Signature<C>, recovery_id: RecoveryId ) -> Result<Self>where D: Digest,

Recover a VerifyingKey from the given message Digest, signature, and RecoveryId.

source

pub fn recover_from_prehash( prehash: &[u8], signature: &Signature<C>, recovery_id: RecoveryId ) -> Result<Self>

Recover a VerifyingKey from the given prehash of a message, the signature over that prehashed message, and a RecoveryId.

source§

impl<C> VerifyingKey<C>where C: PrimeCurve + CurveArithmetic, AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>, FieldBytesSize<C>: ModulusSize,

source

pub fn from_sec1_bytes(bytes: &[u8]) -> Result<Self>

Initialize VerifyingKey from a SEC1-encoded public key.

source

pub fn from_affine(affine: AffinePoint<C>) -> Result<Self>

Initialize VerifyingKey from an affine point.

Returns an Error if the given affine point is the additive identity (a.k.a. point at infinity).

source

pub fn from_encoded_point(public_key: &EncodedPoint<C>) -> Result<Self>

Initialize VerifyingKey from an EncodedPoint.

source

pub fn to_encoded_point(&self, compress: bool) -> EncodedPoint<C>

Serialize this VerifyingKey as a SEC1 EncodedPoint, optionally applying point compression.

source

pub fn to_sec1_bytes(&self) -> Box<[u8]>where C: PointCompression,

Available on crate feature alloc only.

Convert this VerifyingKey into the Elliptic-Curve-Point-to-Octet-String encoding described in SEC 1: Elliptic Curve Cryptography (Version 2.0) section 2.3.3 (page 10).

http://www.secg.org/sec1-v2.pdf

source

pub fn as_affine(&self) -> &AffinePoint<C>

Borrow the inner AffinePoint for this public key.

Trait Implementations§

source§

impl<C> AsRef<<C as CurveArithmetic>::AffinePoint> for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic, AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>, FieldBytesSize<C>: ModulusSize,

source§

fn as_ref(&self) -> &AffinePoint<C>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<C> AsRef<VerifyingKey<C>> for SigningKey<C>where C: PrimeCurve + CurveArithmetic, Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>, SignatureSize<C>: ArrayLength<u8>,

Available on crate feature signing only.
source§

fn as_ref(&self) -> &VerifyingKey<C>

Converts this type into a shared reference of the (usually inferred) input type.
source§

impl<C> AssociatedAlgorithmIdentifier for VerifyingKey<C>where C: AssociatedOid + CurveArithmetic + PrimeCurve, AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>, FieldBytesSize<C>: ModulusSize,

Available on crate feature pkcs8 only.
§

type Params = ObjectIdentifier

Algorithm parameters.
source§

const ALGORITHM_IDENTIFIER: AlgorithmIdentifier<ObjectIdentifier> = PublicKey<C>::ALGORITHM_IDENTIFIER

AlgorithmIdentifier for this structure.
source§

impl<C> Clone for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic + Clone,

source§

fn clone(&self) -> VerifyingKey<C>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<C> Debug for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic + Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de, C> Deserialize<'de> for VerifyingKey<C>where C: PrimeCurve + AssociatedOid + CurveArithmetic + PointCompression, AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>, FieldBytesSize<C>: ModulusSize,

Available on crate features pem and serde only.
source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<C, D> DigestVerifier<D, Signature<C>> for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic, D: Digest + FixedOutput<OutputSize = FieldBytesSize<C>>, AffinePoint<C>: VerifyPrimitive<C>, SignatureSize<C>: ArrayLength<u8>, MaxSize<C>: ArrayLength<u8>, <FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,

Available on crate feature der only.
source§

fn verify_digest(&self, msg_digest: D, signature: &Signature<C>) -> Result<()>

Verify the signature against the given Digest output.
source§

impl<C, D> DigestVerifier<D, Signature<C>> for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic, D: Digest + FixedOutput<OutputSize = FieldBytesSize<C>>, AffinePoint<C>: VerifyPrimitive<C>, SignatureSize<C>: ArrayLength<u8>,

source§

fn verify_digest(&self, msg_digest: D, signature: &Signature<C>) -> Result<()>

Verify the signature against the given Digest output.
source§

impl<C> EncodePublicKey for VerifyingKey<C>where C: PrimeCurve + AssociatedOid + CurveArithmetic + PointCompression, AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>, FieldBytesSize<C>: ModulusSize,

Available on crate feature pem only.
source§

fn to_public_key_der(&self) -> Result<Document>

Serialize a Document containing a SPKI-encoded public key.
§

fn to_public_key_pem(&self, line_ending: LineEnding) -> Result<String, Error>

Serialize this public key as PEM-encoded SPKI with the given [LineEnding].
§

fn write_public_key_der_file(&self, path: impl AsRef<Path>) -> Result<(), Error>

Available on crate feature std only.
Write ASN.1 DER-encoded public key to the given path
§

fn write_public_key_pem_file( &self, path: impl AsRef<Path>, line_ending: LineEnding ) -> Result<(), Error>

Available on crate feature std only.
Write ASN.1 DER-encoded public key to the given path
source§

impl<C> From<&PublicKey<C>> for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic,

source§

fn from(public_key: &PublicKey<C>) -> VerifyingKey<C>

Converts to this type from the input type.
source§

impl<C> From<&SigningKey<C>> for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic, Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>, SignatureSize<C>: ArrayLength<u8>,

Available on crate feature signing only.
source§

fn from(signing_key: &SigningKey<C>) -> VerifyingKey<C>

Converts to this type from the input type.
source§

impl<C> From<&VerifyingKey<C>> for CompressedPoint<C>where C: PrimeCurve + CurveArithmetic + PointCompression, AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>, FieldBytesSize<C>: ModulusSize,

source§

fn from(verifying_key: &VerifyingKey<C>) -> CompressedPoint<C>

Converts to this type from the input type.
source§

impl<C> From<&VerifyingKey<C>> for EncodedPoint<C>where C: PrimeCurve + CurveArithmetic + PointCompression, AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>, FieldBytesSize<C>: ModulusSize,

source§

fn from(verifying_key: &VerifyingKey<C>) -> EncodedPoint<C>

Converts to this type from the input type.
source§

impl<C> From<&VerifyingKey<C>> for PublicKey<C>where C: PrimeCurve + CurveArithmetic,

source§

fn from(verifying_key: &VerifyingKey<C>) -> PublicKey<C>

Converts to this type from the input type.
source§

impl<C> From<PublicKey<C>> for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic,

source§

fn from(public_key: PublicKey<C>) -> VerifyingKey<C>

Converts to this type from the input type.
source§

impl<C> From<SigningKey<C>> for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic, Scalar<C>: Invert<Output = CtOption<Scalar<C>>> + SignPrimitive<C>, SignatureSize<C>: ArrayLength<u8>,

Available on crate feature signing only.
source§

fn from(signing_key: SigningKey<C>) -> VerifyingKey<C>

Converts to this type from the input type.
source§

impl<C> From<VerifyingKey<C>> for CompressedPoint<C>where C: PrimeCurve + CurveArithmetic + PointCompression, AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>, FieldBytesSize<C>: ModulusSize,

source§

fn from(verifying_key: VerifyingKey<C>) -> CompressedPoint<C>

Converts to this type from the input type.
source§

impl<C> From<VerifyingKey<C>> for EncodedPoint<C>where C: PrimeCurve + CurveArithmetic + PointCompression, AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>, FieldBytesSize<C>: ModulusSize,

source§

fn from(verifying_key: VerifyingKey<C>) -> EncodedPoint<C>

Converts to this type from the input type.
source§

impl<C> From<VerifyingKey<C>> for PublicKey<C>where C: PrimeCurve + CurveArithmetic,

source§

fn from(verifying_key: VerifyingKey<C>) -> PublicKey<C>

Converts to this type from the input type.
source§

impl<C> FromStr for VerifyingKey<C>where C: PrimeCurve + AssociatedOid + CurveArithmetic + PointCompression, AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>, FieldBytesSize<C>: ModulusSize,

Available on crate feature pem only.
§

type Err = Error

The associated error which can be returned from parsing.
source§

fn from_str(s: &str) -> Result<Self>

Parses a string s to return a value of this type. Read more
source§

impl<C> Ord for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic, AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>, FieldBytesSize<C>: ModulusSize,

source§

fn cmp(&self, other: &Self) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Selfwhere Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Selfwhere Self: Sized + PartialOrd<Self>,

Restrict a value to a certain interval. Read more
source§

impl<C> PartialEq<VerifyingKey<C>> for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic,

source§

fn eq(&self, other: &Self) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<C> PartialOrd<VerifyingKey<C>> for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic, AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>, FieldBytesSize<C>: ModulusSize,

source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl<C> PrehashVerifier<Signature<C>> for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic + DigestPrimitive, AffinePoint<C>: VerifyPrimitive<C>, SignatureSize<C>: ArrayLength<u8>, MaxSize<C>: ArrayLength<u8>, <FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,

Available on crate feature der only.
source§

fn verify_prehash(&self, prehash: &[u8], signature: &Signature<C>) -> Result<()>

Use Self to verify that the provided signature for a given message prehash is authentic. Read more
source§

impl<C> PrehashVerifier<Signature<C>> for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic, AffinePoint<C>: VerifyPrimitive<C>, SignatureSize<C>: ArrayLength<u8>,

source§

fn verify_prehash(&self, prehash: &[u8], signature: &Signature<C>) -> Result<()>

Use Self to verify that the provided signature for a given message prehash is authentic. Read more
source§

impl<C> Serialize for VerifyingKey<C>where C: PrimeCurve + AssociatedOid + CurveArithmetic + PointCompression, AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>, FieldBytesSize<C>: ModulusSize,

Available on crate features pem and serde only.
source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl<C> SignatureAlgorithmIdentifier for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic, AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>, FieldBytesSize<C>: ModulusSize, Signature<C>: AssociatedAlgorithmIdentifier<Params = AnyRef<'static>>,

Available on crate feature pkcs8 only.
§

type Params = AnyRef<'static>

Algorithm parameters.
source§

const SIGNATURE_ALGORITHM_IDENTIFIER: AlgorithmIdentifier<Self::Params> = Signature<C>::ALGORITHM_IDENTIFIER

AlgorithmIdentifier for the corresponding singature system.
source§

impl<C> TryFrom<&[u8]> for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic, AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>, FieldBytesSize<C>: ModulusSize,

§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(bytes: &[u8]) -> Result<Self>

Performs the conversion.
source§

impl<C> TryFrom<SubjectPublicKeyInfo<AnyRef<'_>, BitStringRef<'_>>> for VerifyingKey<C>where C: PrimeCurve + AssociatedOid + CurveArithmetic + PointCompression, AffinePoint<C>: FromEncodedPoint<C> + ToEncodedPoint<C>, FieldBytesSize<C>: ModulusSize,

Available on crate feature pkcs8 only.
§

type Error = Error

The type returned in the event of a conversion error.
source§

fn try_from(spki: SubjectPublicKeyInfoRef<'_>) -> Result<Self>

Performs the conversion.
source§

impl<C> Verifier<Signature<C>> for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic + DigestPrimitive, AffinePoint<C>: VerifyPrimitive<C>, SignatureSize<C>: ArrayLength<u8>,

source§

fn verify(&self, msg: &[u8], signature: &Signature<C>) -> Result<()>

Use Self to verify that the provided signature for a given message bytestring is authentic. Read more
source§

impl<C> Verifier<Signature<C>> for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic + DigestPrimitive, AffinePoint<C>: VerifyPrimitive<C>, SignatureSize<C>: ArrayLength<u8>, MaxSize<C>: ArrayLength<u8>, <FieldBytesSize<C> as Add>::Output: Add<MaxOverhead> + ArrayLength<u8>,

Available on crate feature der only.
source§

fn verify(&self, msg: &[u8], signature: &Signature<C>) -> Result<()>

Use Self to verify that the provided signature for a given message bytestring is authentic. Read more
source§

impl<C> Verifier<SignatureWithOid<C>> for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic + DigestPrimitive, AffinePoint<C>: VerifyPrimitive<C>, SignatureSize<C>: ArrayLength<u8>,

Available on crate feature sha2 only.
source§

fn verify(&self, msg: &[u8], sig: &SignatureWithOid<C>) -> Result<()>

Use Self to verify that the provided signature for a given message bytestring is authentic. Read more
source§

impl<C> Copy for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic,

source§

impl<C> Eq for VerifyingKey<C>where C: PrimeCurve + CurveArithmetic,

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

const: unstable · source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> DecodePublicKey for Twhere T: for<'a> TryFrom<SubjectPublicKeyInfo<AnyRef<'a>, BitStringRef<'a>>, Error = Error>,

§

fn from_public_key_der(bytes: &[u8]) -> Result<T, Error>

Deserialize object from ASN.1 DER-encoded [SubjectPublicKeyInfo] (binary format).
§

fn from_public_key_pem(s: &str) -> Result<Self, Error>

Available on crate feature pem only.
Deserialize PEM-encoded [SubjectPublicKeyInfo]. Read more
§

fn read_public_key_der_file(path: impl AsRef<Path>) -> Result<Self, Error>

Available on crate feature std only.
Load public key object from an ASN.1 DER-encoded file on the local filesystem (binary format).
§

fn read_public_key_pem_file(path: impl AsRef<Path>) -> Result<Self, Error>

Available on crate features pem and std only.
Load public key object from a PEM-encoded file on the local filesystem.
§

impl<T> DynAssociatedAlgorithmIdentifier for Twhere T: AssociatedAlgorithmIdentifier,

§

fn algorithm_identifier(&self) -> Result<AlgorithmIdentifier<Any>, Error>

AlgorithmIdentifier for this structure.
§

impl<T> DynSignatureAlgorithmIdentifier for Twhere T: SignatureAlgorithmIdentifier,

§

fn signature_algorithm_identifier( &self ) -> Result<AlgorithmIdentifier<Any>, Error>

AlgorithmIdentifier for the corresponding singature system.
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

const: unstable · source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same<T> for T

§

type Output = T

Should always be Self
source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
const: unstable · source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,