[−][src]Module k256::ecdsa
This is supported on
feature="ecdsa-core"
only.Elliptic Curve Digital Signature Algorithm (ECDSA).
This module contains support for computing and verifying ECDSA signatures. To use it, you will need to enable one of the two following Cargo features:
ecdsa-core
: provides only theSignature
type (which represents an ECDSA/secp256k1 signature). Does not require thearithmetic
feature. This is useful for 3rd-party crates which wish to use theSignature
type for interoperability purposes (particularly in conjunction with thesignature::Signer
trait. Example use cases for this include other software implementations of ECDSA/secp256k1 and wrappers for cloud KMS services or hardware devices (HSM or crypto hardware wallet).ecdsa
: provides theSignature
,Signer
, andVerifier
types which natively implement ECDSA/secp256k1 signing and verification.
Signing/Verification Example
This example requires the ecdsa
Cargo feature is enabled:
use k256::{ ecdsa::{Signer, Signature, signature::RandomizedSigner}, elliptic_curve::{Generate}, SecretKey, }; use rand_core::OsRng; // requires 'getrandom' feature // Signing let secret_key = SecretKey::generate(&mut OsRng); let signer = Signer::new(&secret_key).expect("secret key invalid"); let message = b"ECDSA proves knowledge of a secret number in the context of a single message"; // Note: the signature type must be annotated or otherwise inferrable as // `Signer` has many impls of the `RandomizedSigner` trait (for both // regular and recoverable signature types). let signature: Signature = signer.sign_with_rng(&mut OsRng, message); // Verification use k256::{PublicKey, ecdsa::{Verifier, signature::Verifier as _}}; let public_key = PublicKey::from_secret_key(&secret_key, true).expect("secret key invalid"); let verifier = Verifier::new(&public_key).expect("public key invalid"); assert!(verifier.verify(message, &signature).is_ok());
Re-exports
pub use ecdsa_core::signature; |
Modules
recoverable | feature="ecdsa-core" Ethereum-style "recoverable signatures". |
Structs
Error | feature="ecdsa-core" Signature errors. |
Signer | feature="ecdsa-core" and feature="ecdsa" ECDSA/secp256k1 signer |
Verifier | feature="ecdsa-core" and feature="ecdsa" ECDSA/secp256k1 verifier |
Type Definitions
Signature | feature="ecdsa-core" ECDSA/secp256k1 signature (fixed-size) |