ECSignature

Trait ECSignature 

Source
pub trait ECSignature {
    type r: AsRef<[u8]>;
    type s: AsRef<[u8]>;
    type sbytes: AsRef<[u8]>;

    // Required methods
    fn generate_keypair(&mut self, seed: [u8; 32]);
    fn sign(&self, data: &[u8]) -> Result<Self::sbytes>;
    fn verify(&self, data: &[u8], signature: &[u8]) -> Result<bool>;
    fn r(s: Self::sbytes) -> Self::r;
    fn s(s: Self::sbytes) -> Self::s;
}
Expand description

A trait to implement ECDSA signatures for any curve type.

As RustCrypto is yet to support (i.e. no Projective arithmetic yet) curves P384, p521 or Brainpool I put together my own affine-point arithemtic impls leveraging types SecretKey, PublicKey, EncodedPoint from the elliptic-curve crate.

For now - all methods in this trait return byte-arrays (this is just a stop-gap solution)

Required Associated Types§

Source

type r: AsRef<[u8]>

Type r represents the r component of an ECDSA signature.

Source

type s: AsRef<[u8]>

Type s represents the s component of an ECDSA signature.

Source

type sbytes: AsRef<[u8]>

A type to hold the raw-signature i.e. r + s in bytes.

Required Methods§

Source

fn generate_keypair(&mut self, seed: [u8; 32])

Generate a ECDSA keypair.

  • This function borrows SigningKey and VerifyingKey types from the p256 impl to compute ECDSASHA256 Signatures

For other impls, we use a mix of SecretKey, PublicKey, EncodedPoint types. borrowed from the elliptic-curve crate.

Source

fn sign(&self, data: &[u8]) -> Result<Self::sbytes>

Function to sign messages of arbitrary length.

  • Returns the signature as byte-array or an Error.

Note - we use affine point arithmetic of ECDSA calculation for curves other than p256

Source

fn verify(&self, data: &[u8], signature: &[u8]) -> Result<bool>

Function to verify a signature.

  • Returns a bool is successful or an Error.

Note - we use affine point arithmetic of ECDSA calculation for curves other than p256

Source

fn r(s: Self::sbytes) -> Self::r

The raw r component of a signature in bytes

Source

fn s(s: Self::sbytes) -> Self::s

The raw s component of a signature in bytes

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§