[−][src]Struct ecdsa_fun::ECDSA
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]
NG: AddTag,
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]
&self,
verification_key: &Point<impl PointType, Public, NonZero>,
message: &[u8; 32],
signature: &Signature<impl Secrecy>
) -> bool
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]
NG: RefUnwindSafe,
impl<NG> Send for ECDSA<NG> where
NG: Send,
[src]
NG: Send,
impl<NG> Sync for ECDSA<NG> where
NG: Sync,
[src]
NG: Sync,
impl<NG> Unpin for ECDSA<NG> where
NG: Unpin,
[src]
NG: Unpin,
impl<NG> UnwindSafe for ECDSA<NG> where
NG: UnwindSafe,
[src]
NG: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Mark for T
[src]
#[must_use]pub fn mark<M>(self) -> <M as ChangeMark<T>>::Out where
M: ChangeMark<T>,
[src]
M: ChangeMark<T>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,