[][src]Struct ecdsa_fun::ECDSA

pub struct ECDSA<NG> {
    pub nonce_gen: NG,
    pub enforce_low_s: bool,
}

An instance of the ECDSA signature scheme.

Fields

nonce_gen: NG

An instance of NonceGen to produce nonces.

enforce_low_s: bool

enforce_low_s: Whether the verify algorithm should enforce that the s component of the signature is low (see BIP-146).

Implementations

impl ECDSA<()>[src]

pub fn verify_only() -> Self[src]

Creates an ECDSA instance that cannot be used to sign messages but can verify signatures.

impl<NG> ECDSA<NG>[src]

pub fn new(nonce_gen: NG) -> Self where
    NG: AddTag
[src]

Creates a ECDSA instance.

The caller chooses how nonces are generated by providing a NonceGen.

Example

use ecdsa_fun::{nonce, ECDSA};
use rand::rngs::ThreadRng;
use sha2::Sha256;
let nonce_gen = nonce::Synthetic::<Sha256, nonce::GlobalRng<ThreadRng>>::default();
let ecdsa = ECDSA::new(nonce_gen);

pub fn enforce_low_s(self) -> Self[src]

Transforms the ECDSA instance into one which enforces the BIP-146 low s constraint when verifying (it is always low s when signing).

*** DO NOT USE THIS IF VERIFYING BITCOIN TRANSACTIONS FROM THE CHAIN***: BIP-146 is only enforced for transaction relay so you can still have valid high s signatures. This is especially true if you are using the ECDSA adaptor scheme.

impl<NG> ECDSA<NG>[src]

pub fn verification_key_for(&self, secret_key: &Scalar) -> Point[src]

Get the corresponding verification key for a secret key

Example

use ecdsa_fun::{fun::Scalar, ECDSA};
let ecdsa = ECDSA::verify_only();
let secret_key = Scalar::random(&mut rand::thread_rng());
let verification_key = ecdsa.verification_key_for(&secret_key);

#[must_use]pub fn verify(
    &self,
    verification_key: &Point<impl PointType, Public, NonZero>,
    message: &[u8; 32],
    signature: &Signature<impl Secrecy>
) -> bool
[src]

Verify an ECDSA signature.

impl<NG: NonceGen> ECDSA<NG>[src]

pub fn sign(&self, secret_key: &Scalar, message_hash: &[u8; 32]) -> Signature[src]

Deterministically produce a ECDSA signature on a message hash.

Examples

use ecdsa_fun::{
    fun::{digest::Digest, g, marker::*, Scalar, G},
    nonce, ECDSA,
};
use rand::rngs::ThreadRng;
use sha2::Sha256;
let secret_key = Scalar::random(&mut rand::thread_rng());
let nonce_gen = nonce::Synthetic::<Sha256, nonce::GlobalRng<ThreadRng>>::default();
let ecdsa = ECDSA::new(nonce_gen);
let verification_key = ecdsa.verification_key_for(&secret_key);
let message_hash = {
    let message = b"Attack at dawn";
    let mut message_hash = [0u8; 32];
    let hash = Sha256::default().chain(message);
    message_hash.copy_from_slice(hash.finalize().as_ref());
    message_hash
};
let signature = ecdsa.sign(&secret_key, &message_hash);
assert!(ecdsa.verify(&verification_key, &message_hash, &signature));

Trait Implementations

impl<NG: Clone> Clone for ECDSA<NG>[src]

impl<NG: Debug> Debug for ECDSA<NG>[src]

impl<NG: Default> Default for ECDSA<NG>[src]

Auto Trait Implementations

impl<NG> RefUnwindSafe for ECDSA<NG> where
    NG: RefUnwindSafe
[src]

impl<NG> Send for ECDSA<NG> where
    NG: Send
[src]

impl<NG> Sync for ECDSA<NG> where
    NG: Sync
[src]

impl<NG> Unpin for ECDSA<NG> where
    NG: Unpin
[src]

impl<NG> UnwindSafe for ECDSA<NG> where
    NG: UnwindSafe
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Mark for T[src]

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

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