#[doc(inline)]
pub use rand_core::CryptoRng;
pub trait CryptoConfig {
type PrkError;
type Hasher: CryptoSha256TranscriptProcessor;
type X25519: CryptoX25519Processor;
fn ecdhe_x25519<R: CryptoRng>(_: &mut R) -> Self::X25519;
fn hasher_sha256() -> Self::Hasher;
fn sign_p256_init(_key: &[u8]) -> Option<impl CryptoSignerP256Processor>;
fn aead_chaha20poly1305(_key: &[u8; 32]) -> impl CryptoChaCha20Poly1305Processor;
fn hkdf_sha256_from_prk(
_prk: &[u8],
) -> Result<impl CryptoSha256HkdfGenProcessor, Self::PrkError>;
fn hkdf_sha256_init() -> impl CryptoSha256HkdfExtractProcessor;
fn hmac_sha384_init_with_key(_key: &[u8; 48]) -> impl CryptoSha384HmacProcessor;
fn hmac_sha256_init_with_key(_key: &[u8; 32]) -> impl CryptoSha256HmacProcessor;
fn sha256_init() -> impl CryptoSha256TranscriptProcessor;
fn sha384_init() -> impl CryptoSha384TranscriptProcessor;
fn x25519_init<R: CryptoRng>(&mut self, _: &mut R) -> impl CryptoX25519Processor;
}
pub trait CryptoSignerP256Processor {
#[must_use]
fn sign_p256(&self, _content: &[u8], _output: &mut [u8]) -> Option<usize>;
}
pub trait CryptoSha256HmacProcessor {
fn hmac_sha256_update(&mut self, _content: &[u8]) -> ();
fn hmac_sha256_fork(&self) -> Self;
fn hmac_sha256_finalize(self) -> [u8; 32];
}
pub trait CryptoSha384HmacProcessor {
fn hmac_sha384_update(&mut self, _content: &[u8]) -> ();
fn hmac_sha384_fork(&self) -> Self;
fn hmac_sha384_finalize(self) -> [u8; 48];
}
pub trait CryptoSha256HkdfExtractProcessor {
fn hkdf_sha256_extract(
&self,
_salt: Option<&[u8]>,
_ikm: &[u8],
) -> ([u8; 32], impl CryptoSha256HkdfGenProcessor);
}
pub trait CryptoSha256HkdfGenProcessor {
type Error;
fn hkdf_sha256_expand(&self, _info: &[u8], _okm: &mut [u8]) -> Result<(), Self::Error>;
}
pub trait CryptoX25519Processor {
fn x25519_public_key(&self) -> [u8; 32];
fn x25519_shared_secret(self, _pub_key: &[u8; 32]) -> [u8; 32];
}
pub trait CryptoSha256TranscriptProcessor {
fn sha256_update(&mut self, _: &[u8]) -> ();
fn sha256_fork(&self) -> Self;
fn sha256_finalize(self) -> [u8; 32];
}
pub trait CryptoSha384TranscriptProcessor {
fn sha384_update(&mut self, _: &[u8]) -> ();
fn sha384_finalize(self) -> [u8; 48];
}
#[derive(Debug)]
pub enum AeadError {
Opaque,
}
pub trait CryptoChaCha20Poly1305Processor {
fn encrypt_in_place(
&self,
_nonce: &[u8; 12],
_additional_data: &[u8],
_to_encrypt: &mut [u8],
) -> Result<[u8; 16], AeadError>;
fn decrypt_in_place(
&self,
_nonce: &[u8; 12],
_additional_data: &[u8],
_to_decrypt: &mut [u8],
_tag: &[u8; 16],
) -> Result<(), AeadError>;
}