diff --git a/Cargo.toml b/Cargo.toml index 3e0fcc16923..7917d341a84 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,8 +24,10 @@ kdf-all = ["kdf-sha256", "kdf-sha384", "kdf-sha512"] kdf-sha256 = [] kdf-sha384 = [] kdf-sha512 = [] -kem-all = ["kem-dh-p256-hkdf-sha256", "kem-x25519-hkdf-sha256"] +kem-all = ["kem-dh-p256-hkdf-sha256", "kem-dh-p384-hkdf-sha384", "kem-dh-p521-hkdf-sha512", "kem-x25519-hkdf-sha256"] kem-dh-p256-hkdf-sha256 = ["hpke/p256"] +kem-dh-p384-hkdf-sha384 = ["hpke/p384"] +kem-dh-p521-hkdf-sha512 = ["hpke/p521"] kem-x25519-hkdf-sha256 = ["hpke/x25519"] [dependencies] diff --git a/README.md b/README.md index 981d0454575..251dc7c0e5f 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,8 @@ from rust, even when opting out of `algo-all`. * *kdf-all*: Enables `kdf-sha256`, `kdf-sha384`, `kdf-sha512` algorithm features. Enabled by default. -* *kem-all*: Enables both `kem-dh-p256-hkdf-sha256` and +* *kem-all*: Enables `kem-dh-p256-hkdf-sha256`, + `kem-dh-p384-hkdf-sha384`, `kem-dh-p521-hkdf-sha512`, and `kem-x25519-hkdf-sha256` algorithm features. Enabled by default. * *serde*: enables derived serde serialization and deserialization for diff --git a/src/kem.rs b/src/kem.rs index a63ff564136..5cd2201ec43 100644 --- a/src/kem.rs +++ b/src/kem.rs @@ -7,7 +7,7 @@ use wasm_bindgen::prelude::*; /** Kem represents an asymmetric key encapsulation mechanism, as per -[RFC9180§7.1][section-7.1]. Currently only two of options listed in +[RFC9180§7.1][section-7.1]. Currently only four of the options listed in the hpke draft are available. [section-7.1]: https://www.rfc-editor.org/rfc/rfc9180.html#section-7.1 @@ -27,6 +27,14 @@ pub enum Kem { #[cfg(feature = "kem-dh-p256-hkdf-sha256")] DhP256HkdfSha256 = 16, + /// DHKEM(P-384, HKDF-SHA384) [NISTCurves](https://doi.org/10.6028/nist.fips.186-4) + #[cfg(feature = "kem-dh-p384-hkdf-sha384")] + DhP384HkdfSha384 = 17, + + /// DHKEM(P-521, HKDF-SHA512) [NISTCurves](https://doi.org/10.6028/nist.fips.186-4) + #[cfg(feature = "kem-dh-p521-hkdf-sha512")] + DhP521HkdfSha512 = 18, + /// DHKEM(X25519, HKDF-SHA256) [RFC7748](https://www.rfc-editor.org/info/rfc7748) #[cfg(feature = "kem-x25519-hkdf-sha256")] X25519HkdfSha256 = 32, @@ -41,6 +49,14 @@ impl FromStr for Kem { "p256sha256" | "dhkemp256hkdfsha256" | "p256hkdfsha256" | "dhkem(p256, hkdfsha256)" => { Ok(Self::DhP256HkdfSha256) } + #[cfg(feature = "kem-dh-p384-hkdf-sha384")] + "p384sha384" | "dhkemp384hkdfsha384" | "p384hkdfsha384" | "dhkem(p384, hkdfsha384)" => { + Ok(Self::DhP384HkdfSha384) + } + #[cfg(feature = "kem-dh-p521-hkdf-sha512")] + "p521sha512" | "dhkemp521hkdfsha512" | "p521hkdfsha512" | "dhkem(p521, hkdfsha512)" => { + Ok(Self::DhP521HkdfSha512) + } #[cfg(feature = "kem-x25519-hkdf-sha256")] "x25519sha256" | "dhkemx25519hkdfsha256" @@ -63,6 +79,10 @@ impl Kem { pub const KEM_ALL: &[Kem] = &[ #[cfg(feature = "kem-dh-p256-hkdf-sha256")] Kem::DhP256HkdfSha256, + #[cfg(feature = "kem-dh-p384-hkdf-sha384")] + Kem::DhP384HkdfSha384, + #[cfg(feature = "kem-dh-p521-hkdf-sha512")] + Kem::DhP521HkdfSha512, #[cfg(feature = "kem-x25519-hkdf-sha256")] Kem::X25519HkdfSha256, ]; diff --git a/src/keypair.rs b/src/keypair.rs index d42c8460585..ac73c357086 100644 --- a/src/keypair.rs +++ b/src/keypair.rs @@ -40,6 +40,12 @@ pub fn gen_keypair(kem: Kem) -> Keypair { #[cfg(feature = "kem-dh-p256-hkdf-sha256")] Kem::DhP256HkdfSha256 => gen_kp::(), + #[cfg(feature = "kem-dh-p384-hkdf-sha384")] + Kem::DhP384HkdfSha384 => gen_kp::(), + + #[cfg(feature = "kem-dh-p521-hkdf-sha512")] + Kem::DhP521HkdfSha512 => gen_kp::(), + #[cfg(feature = "kem-x25519-hkdf-sha256")] Kem::X25519HkdfSha256 => gen_kp::(), } diff --git a/src/macros.rs b/src/macros.rs index 75dd1fc442a..cd89a551e6e 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -33,6 +33,10 @@ macro_rules! match_algo { match $kem { #[cfg(feature = "kem-dh-p256-hkdf-sha256")] $crate::Kem::DhP256HkdfSha256 => $fn::<$aead, $kdf, hpke::kem::DhP256HkdfSha256>, + #[cfg(feature = "kem-dh-p384-hkdf-sha384")] + $crate::Kem::DhP384HkdfSha384 => $fn::<$aead, $kdf, hpke::kem::DhP384HkdfSha384>, + #[cfg(feature = "kem-dh-p521-hkdf-sha512")] + $crate::Kem::DhP521HkdfSha512 => $fn::<$aead, $kdf, hpke::kem::DhP521HkdfSha512>, #[cfg(feature = "kem-x25519-hkdf-sha256")] $crate::Kem::X25519HkdfSha256 => $fn::<$aead, $kdf, hpke::kem::X25519HkdfSha256>, }