Skip to main content

CryptoProvider

Trait CryptoProvider 

Source
pub trait CryptoProvider:
    Clone
    + Send
    + Sync {
    type Hasher: Clone + Unpin;
    type AeadKey: Unpin;

Show 18 methods // Required methods fn cipher_suites() -> &'static [CipherSuite]; fn signature_schemes() -> &'static [SignatureScheme]; fn key_exchange_groups() -> &'static [KeyExchangeGroup]; fn secure_random(&self, buf: &mut [u8]); fn new_hash(&self, suite: CipherSuite) -> Self::Hasher; fn hash_update(&self, state: &mut Self::Hasher, data: &[u8]); fn hash_finalize(&self, state: Self::Hasher) -> Result<Hash, Error>; fn hmac( &self, suite: CipherSuite, key: &Hash, data: &[u8], ) -> Result<Hash, Error>; fn hkdf_extract( &self, suite: CipherSuite, salt: &Hash, ikm: &[u8], ) -> Result<Hash, Error>; fn hkdf_expand_label( &self, out: &mut [u8], suite: CipherSuite, secret: &Hash, label: &[u8], context: &[u8], ) -> Result<(), Error>; fn new_aead_key(&self, suite: CipherSuite, key: &[u8]) -> Self::AeadKey; fn aead_encrypt( &self, key: &Self::AeadKey, nonce: &[u8], aad: &[u8], data: &mut [u8], plaintext_len: usize, ) -> Result<usize, Error>; fn aead_decrypt( &self, key: &Self::AeadKey, nonce: &[u8], aad: &[u8], data: &mut [u8], ) -> Result<usize, Error>; fn key_exchange_generate_keypair( &self, group: KeyExchangeGroup, ) -> Result<(KeyExchangeSecretKey, KeyExchangePublicKey), Error>; fn key_exchange( &self, secret: &KeyExchangeSecretKey, peer_public: &[u8], ) -> Result<Vec<u8, KEY_EXCHANGE_SHARED_SECRET_MAX_SIZE>, Error>; fn sign( &self, scheme: SignatureScheme, secret_key: &[u8], data: &[u8], ) -> Result<Vec<u8, SIGNATURE_MAX_SIZE>, Error>; fn verify( &self, scheme: SignatureScheme, public_key: &[u8], data: &[u8], signature: &[u8], ) -> Result<(), Error>; // Provided method fn hash(&self, suite: CipherSuite, data: &[u8]) -> Result<Hash, Error> { ... }
}

Required Associated Types§

Source

type Hasher: Clone + Unpin

Opaque incremental hash state, must be Clone for transcript checkpointing.

Source

type AeadKey: Unpin

A distinct type is used to avoid computation for ench encrypt / decrypt operation for some ciphers (e.g. AES key expanding)

Required Methods§

Source

fn cipher_suites() -> &'static [CipherSuite]

Source

fn signature_schemes() -> &'static [SignatureScheme]

Source

fn key_exchange_groups() -> &'static [KeyExchangeGroup]

Source

fn secure_random(&self, buf: &mut [u8])

Source

fn new_hash(&self, suite: CipherSuite) -> Self::Hasher

Create a new incremental hash state for the given suite.

Source

fn hash_update(&self, state: &mut Self::Hasher, data: &[u8])

Absorb data into the hash state.

Source

fn hash_finalize(&self, state: Self::Hasher) -> Result<Hash, Error>

Finalize the hash and write the digest into out. Consumes the state.

Source

fn hmac( &self, suite: CipherSuite, key: &Hash, data: &[u8], ) -> Result<Hash, Error>

Source

fn hkdf_extract( &self, suite: CipherSuite, salt: &Hash, ikm: &[u8], ) -> Result<Hash, Error>

Source

fn hkdf_expand_label( &self, out: &mut [u8], suite: CipherSuite, secret: &Hash, label: &[u8], context: &[u8], ) -> Result<(), Error>

Source

fn new_aead_key(&self, suite: CipherSuite, key: &[u8]) -> Self::AeadKey

Source

fn aead_encrypt( &self, key: &Self::AeadKey, nonce: &[u8], aad: &[u8], data: &mut [u8], plaintext_len: usize, ) -> Result<usize, Error>

Source

fn aead_decrypt( &self, key: &Self::AeadKey, nonce: &[u8], aad: &[u8], data: &mut [u8], ) -> Result<usize, Error>

Source

fn key_exchange_generate_keypair( &self, group: KeyExchangeGroup, ) -> Result<(KeyExchangeSecretKey, KeyExchangePublicKey), Error>

Source

fn key_exchange( &self, secret: &KeyExchangeSecretKey, peer_public: &[u8], ) -> Result<Vec<u8, KEY_EXCHANGE_SHARED_SECRET_MAX_SIZE>, Error>

Source

fn sign( &self, scheme: SignatureScheme, secret_key: &[u8], data: &[u8], ) -> Result<Vec<u8, SIGNATURE_MAX_SIZE>, Error>

Source

fn verify( &self, scheme: SignatureScheme, public_key: &[u8], data: &[u8], signature: &[u8], ) -> Result<(), Error>

Provided Methods§

Source

fn hash(&self, suite: CipherSuite, data: &[u8]) -> Result<Hash, Error>

One-shot hash (default implementation uses the incremental API).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§