Skip to content

Commit aa78c9a

Browse files
authored
Add HPKE support for P-384/P-521 KEMs and HKDF-SHA384 (#14420)
* Expand HPKE with additional KEMs and HKDF-SHA384 * Document expanded HPKE KEM and KDF support * Fix HPKE test typing compatibility on Python 3.8 * Add HPKE tests for helper edge paths and coverage * Remove unreachable HPKE KEM branches for full coverage * Limit HPKE expansion PR to HKDF-SHA384 only * Define SHA384 lazy import for HPKE KDF * Remove redundant HPKE KDF changelog entry * Fix changelog list formatting for docs build
1 parent dd4056f commit aa78c9a

5 files changed

Lines changed: 12 additions & 1 deletion

File tree

docs/hazmat/primitives/hpke.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ specifying auxiliary authenticated information.
8989

9090
HKDF-SHA256
9191

92+
.. attribute:: HKDF_SHA384
93+
94+
HKDF-SHA384
95+
9296
.. class:: AEAD
9397

9498
An enumeration of authenticated encryption algorithms.

src/cryptography/hazmat/bindings/_rust/openssl/hpke.pyi

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class KEM:
1010

1111
class KDF:
1212
HKDF_SHA256: KDF
13+
HKDF_SHA384: KDF
1314
HKDF_SHA512: KDF
1415

1516
class AEAD:

src/rust/src/backend/hpke.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ mod kem_params {
2222

2323
mod kdf_params {
2424
pub const HKDF_SHA256_ID: u16 = 0x0001;
25+
pub const HKDF_SHA384_ID: u16 = 0x0002;
2526
pub const HKDF_SHA512_ID: u16 = 0x0003;
2627
}
2728

@@ -67,13 +68,15 @@ pub(crate) enum KEM {
6768
#[derive(Clone, PartialEq, Eq, Hash)]
6869
pub(crate) enum KDF {
6970
HKDF_SHA256,
71+
HKDF_SHA384,
7072
HKDF_SHA512,
7173
}
7274

7375
impl KDF {
7476
fn id(&self) -> u16 {
7577
match self {
7678
KDF::HKDF_SHA256 => kdf_params::HKDF_SHA256_ID,
79+
KDF::HKDF_SHA384 => kdf_params::HKDF_SHA384_ID,
7780
KDF::HKDF_SHA512 => kdf_params::HKDF_SHA512_ID,
7881
}
7982
}
@@ -84,6 +87,7 @@ impl KDF {
8487
) -> CryptographyResult<pyo3::Bound<'p, pyo3::PyAny>> {
8588
match self {
8689
KDF::HKDF_SHA256 => Ok(types::SHA256.get(py)?.call0()?),
90+
KDF::HKDF_SHA384 => Ok(types::SHA384.get(py)?.call0()?),
8791
KDF::HKDF_SHA512 => Ok(types::SHA512.get(py)?.call0()?),
8892
}
8993
}

src/rust/src/types.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,8 @@ pub static SHA1: LazyPyImport =
308308
LazyPyImport::new("cryptography.hazmat.primitives.hashes", &["SHA1"]);
309309
pub static SHA256: LazyPyImport =
310310
LazyPyImport::new("cryptography.hazmat.primitives.hashes", &["SHA256"]);
311+
pub static SHA384: LazyPyImport =
312+
LazyPyImport::new("cryptography.hazmat.primitives.hashes", &["SHA384"]);
311313
pub static SHA512: LazyPyImport =
312314
LazyPyImport::new("cryptography.hazmat.primitives.hashes", &["SHA512"]);
313315

tests/hazmat/primitives/test_hpke.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
SUPPORTED_SUITES = list(
2626
itertools.product(
2727
[KEM.X25519],
28-
[KDF.HKDF_SHA256, KDF.HKDF_SHA512],
28+
[KDF.HKDF_SHA256, KDF.HKDF_SHA384, KDF.HKDF_SHA512],
2929
[AEAD.AES_128_GCM, AEAD.AES_256_GCM, AEAD.CHACHA20_POLY1305],
3030
)
3131
)

0 commit comments

Comments
 (0)