From 928626d6ced675a3fc768a3d643b6f57246a5dc3 Mon Sep 17 00:00:00 2001 From: Jared Crawford Date: Mon, 13 Jan 2025 16:29:04 -0500 Subject: [PATCH] Abstract core KEM functionality out of DHKEM 2/2 This change was missed in the initial port of #1664. Without this change, customers cannot provide a non-DH KEM --- .../org/bouncycastle/crypto/hpke/HPKE.java | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/core/src/main/java/org/bouncycastle/crypto/hpke/HPKE.java b/core/src/main/java/org/bouncycastle/crypto/hpke/HPKE.java index 64f63c708a..430e280dcd 100644 --- a/core/src/main/java/org/bouncycastle/crypto/hpke/HPKE.java +++ b/core/src/main/java/org/bouncycastle/crypto/hpke/HPKE.java @@ -70,6 +70,25 @@ public HPKE(byte mode, short kemId, short kdfId, short aeadId) } + public HPKE(byte mode, short kemId, short kdfId, short aeadId, KEM kem, int encSize) + { + this.mode = mode; + this.kemId = kemId; + this.kdfId = kdfId; + this.aeadId = aeadId; + this.hkdf = new HKDF(kdfId); + this.kem = kem; + if (aeadId == aead_AES_GCM128) + { + Nk = 16; + } + else + { + Nk = 32; + } + this.encSize = encSize; + } + public int getEncSize() { return kem.getEncryptionSize();