VerifyingKey

Enum VerifyingKey 

Source
pub enum VerifyingKey {
    Ed25519(Box<VerifyingKey>),
    MlDsa44((Box<MLDSAVerificationKey<libcrux_ml_dsa::::ml_dsa_generic::ml_dsa_44::MLDSA44VerificationKey::{constant#0}>>, Hash)),
    MlDsa65((Box<MLDSAVerificationKey<libcrux_ml_dsa::::ml_dsa_generic::ml_dsa_65::MLDSA65VerificationKey::{constant#0}>>, Hash)),
    MlDsa87((Box<MLDSAVerificationKey<libcrux_ml_dsa::::ml_dsa_generic::ml_dsa_87::MLDSA87VerificationKey::{constant#0}>>, Hash)),
}
Expand description

Public key for signature verification supporting multiple algorithms.

This enum provides a unified interface for verifying signatures across different cryptographic algorithms, supporting both classical and post-quantum schemes.

§Algorithm Selection

  • Ed25519: Use for legacy compatibility and smaller key sizes
  • ML-DSA-44: Use for TLS certificates requiring post-quantum security
  • ML-DSA-65: Use for message signatures with strong post-quantum security
  • ML-DSA-87: Use for high-security applications requiring maximum protection

§Examples

use zoe_wire_protocol::{VerifyingKey, SigningKey, KeyPair};
use rand::rngs::OsRng;

// Generate a keypair
let keypair = KeyPair::generate(&mut OsRng);
let verifying_key = keypair.public_key();

// Sign and verify a message
let message = b"Hello, world!";
let signature = keypair.sign(message);
let is_valid = verifying_key.verify(message, &signature)?;
assert!(is_valid);

Variants§

§

Ed25519(Box<VerifyingKey>)

Ed25519 public key (32 bytes)

§

MlDsa44((Box<MLDSAVerificationKey<libcrux_ml_dsa::::ml_dsa_generic::ml_dsa_44::MLDSA44VerificationKey::{constant#0}>>, Hash))

ML-DSA-44 public key (1,312 bytes) - for TLS certificates

§

MlDsa65((Box<MLDSAVerificationKey<libcrux_ml_dsa::::ml_dsa_generic::ml_dsa_65::MLDSA65VerificationKey::{constant#0}>>, Hash))

ML-DSA-65 public key (1,952 bytes) - for message signatures

§

MlDsa87((Box<MLDSAVerificationKey<libcrux_ml_dsa::::ml_dsa_generic::ml_dsa_87::MLDSA87VerificationKey::{constant#0}>>, Hash))

ML-DSA-87 public key (2,592 bytes) - for high security

Implementations§

Source§

impl VerifyingKey

flutter_rust_bridge:opaque

Source

pub fn algorithm(&self) -> Algorithm

Get the algorithm for this key type

Source

pub fn verify( &self, message: &[u8], signature: &Signature, ) -> Result<(), VerifyError>

Verify a signature against a message using the appropriate algorithm.

This method automatically matches the signature type with the key type and returns Ok(false) if they don’t match (rather than an error).

§Arguments
  • message - The message bytes that were signed
  • signature - The signature to verify
§Returns
  • Ok(true) - Signature is valid for this key and message
  • Ok(false) - Signature is invalid or key/signature types don’t match
  • Err(_) - Verification error (malformed signature, etc.)
§Examples
use zoe_wire_protocol::{KeyPair, VerifyingKey, SigningKey};
use rand::rngs::OsRng;

let keypair = KeyPair::generate_ed25519(&mut OsRng);
let message = b"Hello, world!";
let signature = keypair.sign(message);
let verifying_key = keypair.public_key();

let is_valid = verifying_key.verify(message, &signature)?;
assert!(is_valid);
Source

pub fn encode(&self) -> Vec<u8>

Encode the VerifyingKey to bytes for serialization.

This method serializes the key using postcard format for efficient storage and transmission. The resulting bytes can be deserialized back to a VerifyingKey using postcard::from_bytes().

§Returns

A Vec<u8> containing the serialized key data.

§Examples
use zoe_wire_protocol::{KeyPair, VerifyingKey};
use rand::rngs::OsRng;

let keypair = KeyPair::generate_ed25519(&mut OsRng);
let verifying_key = keypair.public_key();

// Serialize the key
let key_bytes = verifying_key.encode();

// Deserialize it back
let restored_key: VerifyingKey = postcard::from_bytes(&key_bytes).unwrap();
assert_eq!(&verifying_key, &restored_key);
Source

pub fn id(&self) -> KeyId

Source

pub fn to_bytes(&self) -> Result<Vec<u8>, Error>

Source

pub fn from_hex(hex: String) -> Result<VerifyingKey, String>

Source

pub fn to_pem(&self) -> Result<String, VerifyingKeyError>

Export the VerifyingKey to PEM format.

This method serializes the key using postcard format and then encodes it as a PEM block with the label “ZOE PUBLIC KEY”. This provides a standardized text format that’s compatible with many cryptographic tools and libraries.

§Returns

A Result<String, VerifyingKeyError> containing the PEM-encoded key or an error.

§Examples
use zoe_wire_protocol::{KeyPair, VerifyingKey};
use rand::rngs::OsRng;

let keypair = KeyPair::generate_ed25519(&mut OsRng);
let verifying_key = keypair.public_key();
let pem_string = verifying_key.to_pem().unwrap();
println!("Public key PEM:\n{}", pem_string);
Source

pub fn from_pem(pem_string: &str) -> Result<VerifyingKey, VerifyingKeyError>

Import a VerifyingKey from PEM format.

This method parses a PEM-encoded string and deserializes it back to a VerifyingKey. The PEM block should have the label “ZOE PUBLIC KEY”.

§Arguments
  • pem_string - A string containing the PEM-encoded public key
§Returns

A Result<VerifyingKey, VerifyingKeyError> containing the decoded key or an error.

§Examples
use zoe_wire_protocol::{KeyPair, VerifyingKey};
use rand::rngs::OsRng;

let original_keypair = KeyPair::generate_ed25519(&mut OsRng);
let original_key = original_keypair.public_key();
let pem_string = original_key.to_pem().unwrap();

let restored_key = VerifyingKey::from_pem(&pem_string).unwrap();
assert_eq!(original_key.encode(), restored_key.encode());

Trait Implementations§

Source§

impl Clone for VerifyingKey

Source§

fn clone(&self) -> VerifyingKey

Returns a duplicate 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 Debug for VerifyingKey

Source§

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

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

impl<'de> Deserialize<'de> for VerifyingKey

Source§

fn deserialize<__D>( __deserializer: __D, ) -> Result<VerifyingKey, <__D as Deserializer<'de>>::Error>
where __D: Deserializer<'de>,

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

impl Display for VerifyingKey

Source§

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

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

impl From<&KeyPair> for VerifyingKey

Source§

fn from(val: &KeyPair) -> VerifyingKey

Converts to this type from the input type.
Source§

impl From<MLDSAVerificationKey<libcrux_ml_dsa::::ml_dsa_generic::ml_dsa_44::MLDSA44VerificationKey::{constant#0}>> for VerifyingKey

Source§

fn from( key: MLDSAVerificationKey<libcrux_ml_dsa::::ml_dsa_generic::ml_dsa_44::MLDSA44VerificationKey::{constant#0}>, ) -> VerifyingKey

Converts to this type from the input type.
Source§

impl From<MLDSAVerificationKey<libcrux_ml_dsa::::ml_dsa_generic::ml_dsa_65::MLDSA65VerificationKey::{constant#0}>> for VerifyingKey

Source§

fn from( key: MLDSAVerificationKey<libcrux_ml_dsa::::ml_dsa_generic::ml_dsa_65::MLDSA65VerificationKey::{constant#0}>, ) -> VerifyingKey

Converts to this type from the input type.
Source§

impl From<MLDSAVerificationKey<libcrux_ml_dsa::::ml_dsa_generic::ml_dsa_87::MLDSA87VerificationKey::{constant#0}>> for VerifyingKey

Source§

fn from( key: MLDSAVerificationKey<libcrux_ml_dsa::::ml_dsa_generic::ml_dsa_87::MLDSA87VerificationKey::{constant#0}>, ) -> VerifyingKey

Converts to this type from the input type.
Source§

impl Hash for VerifyingKey

Source§

fn hash<H>(&self, state: &mut H)
where H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for VerifyingKey

Source§

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

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

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

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

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

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

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

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

impl PartialEq for VerifyingKey

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for VerifyingKey

Source§

fn partial_cmp(&self, other: &VerifyingKey) -> 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

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

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

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Serialize for VerifyingKey

Source§

fn serialize<__S>( &self, __serializer: __S, ) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>
where __S: Serializer,

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

impl TryFrom<&[u8]> for VerifyingKey

Source§

type Error = Error

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

fn try_from( value: &[u8], ) -> Result<VerifyingKey, <VerifyingKey as TryFrom<&[u8]>>::Error>

Performs the conversion.
Source§

impl Eq for VerifyingKey

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<'a, T, E> AsTaggedExplicit<'a, E> for T
where T: 'a,

§

fn explicit(self, class: Class, tag: u32) -> TaggedParser<'a, Explicit, Self, E>

§

impl<'a, T, E> AsTaggedImplicit<'a, E> for T
where T: 'a,

§

fn implicit( self, class: Class, constructed: bool, tag: u32, ) -> TaggedParser<'a, Implicit, Self, E>

Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
§

impl<T> Classify for T

§

type Classified = T

§

fn classify(self) -> T

§

impl<T> Classify for T

§

type Classified = T

§

fn classify(self) -> T

Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<Q, K> Comparable<K> for Q
where Q: Ord + ?Sized, K: Borrow<Q> + ?Sized,

§

fn compare(&self, key: &K) -> Ordering

Compare self to key and return their ordering.
§

impl<T> CompatExt for T

§

fn compat(self) -> Compat<T>

Applies the [Compat] adapter by value. Read more
§

fn compat_ref(&self) -> Compat<&T>

Applies the [Compat] adapter by shared reference. Read more
§

fn compat_mut(&mut self) -> Compat<&mut T>

Applies the [Compat] adapter by mutable reference. Read more
§

impl<T> Declassify for T

§

type Declassified = T

§

fn declassify(self) -> T

§

impl<T> Declassify for T

§

type Declassified = T

§

fn declassify(self) -> T

Source§

impl<T> DynClone for T
where T: Clone,

§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

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

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.

§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
§

impl<T> ToStringFallible for T
where T: Display,

§

fn try_to_string(&self) -> Result<String, TryReserveError>

ToString::to_string, but without panic on OOM.

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<T> DartSafe for T

Source§

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

§

impl<T> ErasedDestructor for T
where T: 'static,

§

impl<T> RpcMessage for T
where T: Debug + Serialize + DeserializeOwned + Send + Sync + Unpin + 'static,

§

impl<T> RpcMessage for T
where T: Debug + Serialize + DeserializeOwned + Send + Sync + Unpin + 'static,

§

impl<T> TaskRetFutTrait for T
where T: Send,