Skip to main content

SignatureScheme

Enum SignatureScheme 

Source
pub enum SignatureScheme {
    Schnorr,
    Ecdsa,
    Ed25519,
    MLDSA44,
    MLDSA65,
    MLDSA87,
    SshEd25519,
    SshDsa,
    SshEcdsaP256,
    SshEcdsaP384,
}
Expand description

Supported digital signature schemes.

This enum represents the various signature schemes supported in this crate, including elliptic curve schemes (ECDSA, Schnorr), Edwards curve schemes (Ed25519), post-quantum schemes (ML-DSA), and SSH-specific algorithms.

§Examples

use bc_components::SignatureScheme;

// Use the default signature scheme (Schnorr)
let scheme = SignatureScheme::default();
let (private_key, public_key) = scheme.keypair();
// Create a key pair using a specific signature scheme
let (mldsa_private, mldsa_public) = SignatureScheme::MLDSA65.keypair();

Variants§

§

Schnorr

BIP-340 Schnorr signature scheme, used in Bitcoin Taproot (default)

§

Ecdsa

ECDSA signature scheme using the secp256k1 curve

§

Ed25519

Ed25519 signature scheme (RFC 8032)

§

MLDSA44

ML-DSA44 post-quantum signature scheme (NIST level 2)

§

MLDSA65

ML-DSA65 post-quantum signature scheme (NIST level 3)

§

MLDSA87

ML-DSA87 post-quantum signature scheme (NIST level 5)

§

SshEd25519

Ed25519 signature scheme for SSH

§

SshDsa

DSA signature scheme for SSH

§

SshEcdsaP256

ECDSA signature scheme with NIST P-256 curve for SSH

§

SshEcdsaP384

ECDSA signature scheme with NIST P-384 curve for SSH

Implementations§

Source§

impl SignatureScheme

Source

pub fn keypair(&self) -> (SigningPrivateKey, SigningPublicKey)

Creates a new key pair for the signature scheme using the system’s secure random number generator.

This is a convenience method that calls keypair_opt with an empty comment.

§Returns

A tuple containing a signing private key and its corresponding public key.

§Examples
use bc_components::SignatureScheme;

// Generate a Schnorr key pair
let (private_key, public_key) = SignatureScheme::Schnorr.keypair();

// Use the default scheme (also Schnorr)
let (default_private, default_public) =
    SignatureScheme::default().keypair();
Source

pub fn keypair_opt( &self, comment: impl Into<String>, ) -> (SigningPrivateKey, SigningPublicKey)

Creates a new key pair for the signature scheme with an optional comment.

The comment is only used for SSH keys and is ignored for other schemes.

§Arguments
  • comment - A string comment to include with SSH keys
§Returns

A tuple containing a signing private key and its corresponding public key.

§Examples
use bc_components::SignatureScheme;

// Generate an SSH Ed25519 key pair with a comment
let (ssh_private, ssh_public) =
    SignatureScheme::SshEd25519.keypair_opt("user@example.com");
Source

pub fn keypair_using( &self, _rng: &mut impl RandomNumberGenerator, comment: impl Into<String>, ) -> Result<(SigningPrivateKey, SigningPublicKey)>

Creates a key pair for the signature scheme using a provided random number generator.

This allows for deterministic key generation when using a seeded RNG. Note that not all signature schemes support deterministic generation.

§Arguments
  • rng - A mutable reference to a random number generator
  • comment - A string comment to include with SSH keys
§Returns

A Result containing a tuple of signing private key and public key, or an error if the signature scheme doesn’t support deterministic generation.

§Examples
use bc_components::SignatureScheme;
use bc_rand::SecureRandomNumberGenerator;

let mut rng = SecureRandomNumberGenerator;

// Generate an ECDSA key pair with a specific RNG
let result = SignatureScheme::Ecdsa.keypair_using(&mut rng, "");
assert!(result.is_ok());

Trait Implementations§

Source§

impl Clone for SignatureScheme

Source§

fn clone(&self) -> SignatureScheme

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SignatureScheme

Source§

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

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

impl Default for SignatureScheme

Source§

fn default() -> SignatureScheme

Returns the “default value” for a type. Read more
Source§

impl Eq for SignatureScheme

Source§

impl Hash for SignatureScheme

Source§

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

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 PartialEq for SignatureScheme

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 StructuralPartialEq for SignatureScheme

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
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
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
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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.

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, 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.
Source§

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

Source§

fn vzip(self) -> V