use crate::{crypto::Agreement, rng::CryptoRng};
type P256Ty = cfg_select! {
feature = "crypto-ring" => crate::crypto::EcdhP256Ring,
feature = "crypto-graviola" => crate::crypto::EcdhP256Graviola,
feature = "crypto-alr" => crate::crypto::EcdhP256Alr,
feature = "crypto-ruco" => crate::crypto::EcdhP256Ruco,
_ => crate::crypto::AgreementDummy::<[u8; 65], [u8; 32]>
};
type P384Ty = cfg_select! {
feature = "crypto-ring" => crate::crypto::EcdhP384Ring,
feature = "crypto-graviola" => crate::crypto::EcdhP384Graviola,
feature = "crypto-alr" => crate::crypto::EcdhP384Alr,
feature = "crypto-ruco" => crate::crypto::EcdhP384Ruco,
_ => crate::crypto::AgreementDummy::<[u8; 97], [u8; 48]>
};
type X25519Ty = cfg_select! {
feature = "crypto-ring" => crate::crypto::X25519Ring,
feature = "crypto-graviola" => crate::crypto::X25519Graviola,
feature = "crypto-alr" => crate::crypto::X25519Alr,
feature = "crypto-ruco" => crate::crypto::X25519Ruco,
_ => crate::crypto::AgreementDummy::<[u8; 32], [u8; 32]>
};
#[derive(Debug)]
pub struct EcdhP256Global(P256Ty);
impl Agreement for EcdhP256Global {
type PublicKey = <P256Ty as Agreement>::PublicKey;
type SharedSecret = <P256Ty as Agreement>::SharedSecret;
#[inline]
fn generate<RNG>(rng: &mut RNG) -> crate::Result<Self>
where
RNG: CryptoRng,
{
Ok(Self(P256Ty::generate(rng)?))
}
#[inline]
fn diffie_hellman(self, other_participant_pk: &[u8]) -> crate::Result<Self::SharedSecret> {
self.0.diffie_hellman(other_participant_pk)
}
#[inline]
fn public_key(&self) -> crate::Result<Self::PublicKey> {
self.0.public_key()
}
}
#[derive(Debug)]
pub struct EcdhP384Global(P384Ty);
impl Agreement for EcdhP384Global {
type PublicKey = <P384Ty as Agreement>::PublicKey;
type SharedSecret = <P384Ty as Agreement>::SharedSecret;
#[inline]
fn generate<RNG>(rng: &mut RNG) -> crate::Result<Self>
where
RNG: CryptoRng,
{
Ok(Self(P384Ty::generate(rng)?))
}
#[inline]
fn diffie_hellman(self, other_participant_pk: &[u8]) -> crate::Result<Self::SharedSecret> {
self.0.diffie_hellman(other_participant_pk)
}
#[inline]
fn public_key(&self) -> crate::Result<Self::PublicKey> {
self.0.public_key()
}
}
#[derive(Debug)]
pub struct X25519Global(X25519Ty);
impl Agreement for X25519Global {
type PublicKey = <X25519Ty as Agreement>::PublicKey;
type SharedSecret = <X25519Ty as Agreement>::SharedSecret;
#[inline]
fn generate<RNG>(rng: &mut RNG) -> crate::Result<Self>
where
RNG: CryptoRng,
{
Ok(Self(X25519Ty::generate(rng)?))
}
#[inline]
fn diffie_hellman(self, other_participant_pk: &[u8]) -> crate::Result<Self::SharedSecret> {
self.0.diffie_hellman(other_participant_pk)
}
#[inline]
fn public_key(&self) -> crate::Result<Self::PublicKey> {
self.0.public_key()
}
}