Api

Trait Api 

Source
pub trait Api<const N: usize>: Support<bool> + Send {
    const PRIVATE: Layout;
    const PUBLIC: Layout;
    const WRAPPED: usize;

    // Required methods
    fn generate(private: &mut [u8]) -> Result<(), Error>;
    fn public(private: &[u8], public: &mut [u8]) -> Result<(), Error>;
    fn sign(
        private: &[u8],
        digest: &[u8; N],
        r: &mut [u8; N],
        s: &mut [u8; N],
    ) -> Result<(), Error>;
    fn verify(
        public: &[u8],
        digest: &[u8; N],
        r: &[u8; N],
        s: &[u8; N],
    ) -> Result<bool, Error>;
    fn drop_private(private: &mut [u8]) -> Result<(), Error>;
    fn export_private(private: &[u8], wrapped: &mut [u8]) -> Result<(), Error>;
    fn import_private(wrapped: &[u8], private: &mut [u8]) -> Result<(), Error>;
    fn export_public(
        public: &[u8],
        x: &mut [u8; N],
        y: &mut [u8; N],
    ) -> Result<(), Error>;
    fn import_public(
        x: &[u8; N],
        y: &[u8; N],
        public: &mut [u8],
    ) -> Result<(), Error>;
}
Available on crate features internal-api-crypto and internal-api-crypto-ecdsa only.
Expand description

ECDSA interface.

Required Associated Constants§

Source

const PRIVATE: Layout

Layout of a private key.

This may use more than N bytes in case blinding or checksum are used. This may also require stricter alignment than one byte.

Source

const PUBLIC: Layout

Layout of a public key.

This may be bigger than 2 * N in case checksum is used. This may also require stricter alignment than one byte.

Source

const WRAPPED: usize

Length in bytes of a wrapped private key.

This may be greater than N in case blinding is used.

Required Methods§

Source

fn generate(private: &mut [u8]) -> Result<(), Error>

Generates a private key.

Source

fn public(private: &[u8], public: &mut [u8]) -> Result<(), Error>

Returns the public key of a private key.

Source

fn sign( private: &[u8], digest: &[u8; N], r: &mut [u8; N], s: &mut [u8; N], ) -> Result<(), Error>

Signs a digest.

The signature components r and s are in big-endian.

Source

fn verify( public: &[u8], digest: &[u8; N], r: &[u8; N], s: &[u8; N], ) -> Result<bool, Error>

Verifies a signature.

The signature components r and s are in big-endian.

Source

fn drop_private(private: &mut [u8]) -> Result<(), Error>

Drops a private key.

This may zeroize the storage for example. Implementations should not rely on this for memory leaks. This is only security relevant.

Source

fn export_private(private: &[u8], wrapped: &mut [u8]) -> Result<(), Error>

Exports a private key.

The wrapped key must be Self::WRAPPED bytes long. Users cannot assume that the wrapped key is the scalar representing the private key.

Source

fn import_private(wrapped: &[u8], private: &mut [u8]) -> Result<(), Error>

Imports a private key.

The wrapped key must be Self::WRAPPED bytes long.

Source

fn export_public( public: &[u8], x: &mut [u8; N], y: &mut [u8; N], ) -> Result<(), Error>

Exports a public key.

The coordinates x and y are in big-endian.

Source

fn import_public( x: &[u8; N], y: &[u8; N], public: &mut [u8], ) -> Result<(), Error>

Imports a public key.

The coordinates x and y are in big-endian.

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§