rozbb / rust-hpke

An implementation of the HPKE hybrid encryption standard (RFC 9180)
Other
62 stars 31 forks source link

default implementation for kem::gen_keypair #26

Closed BoOTheFurious closed 2 years ago

BoOTheFurious commented 2 years ago

Hello, In the kem trait, the function gen_keypair is usually derived from derive_keypair. Thus a default implementation will ease the implementation of the kem trait.

    fn gen_keypair<R: rand::CryptoRng + rand::RngCore>(
        csprng: &mut R,
    ) -> (Self::PrivateKey, Self::PublicKey) {
        // Make some keying material that's the size of a private key
        let mut ikm: GenericArray<u8, <Self::PrivateKey as hpke::Serializable>::OutputSize> =
            GenericArray::default();
        // Fill it with randomness
        csprng.fill_bytes(&mut ikm);
        // Run derive_keypair using the KEM's KDF
        Self::derive_keypair(&ikm)
    }

(I can make a PR if it is easier for you)

Regards,

rozbb commented 2 years ago

Another good catch. Will fix

rozbb commented 2 years ago

Fixed in #27