Skip to content

Fix: Improved support for combinations of HPKE algos#9999

Draft
sebastian-carpenter wants to merge 4 commits intowolfSSL:masterfrom
sebastian-carpenter:hpke-fix
Draft

Fix: Improved support for combinations of HPKE algos#9999
sebastian-carpenter wants to merge 4 commits intowolfSSL:masterfrom
sebastian-carpenter:hpke-fix

Conversation

@sebastian-carpenter
Copy link
Contributor

Description

hpke used wrong kdf/kem digest:

HPKE code incorrectly used the KDF digest length for the KEM. Per RFC 9180:

The KDF used in DHKEM can be equal to or different from the KDF used in the remainder of HPKE, depending on the chosen variant. Implementations MUST make sure to use the constants (Nh) and function calls (LabeledExtract and LabeledExpand) of the appropriate KDF when implementing DHKEM.

Basically, the KDF used does not need to match the KEM's. So I reworked the code to keep track of both the KEM and KDF digests. LabeledExtractAndExpand is the KEM route so that uses the KEM digest now. And the wc_HpkeKeyScheduleBase is the KDF route so that uses the KDF digest.

move hpke-eque code out of tls:

There were several areas in tls and ech with duplicated code related to hpke, or code that should be broken out into hpke. Fixed this issue by creating new WOLFSSL_LOCAL functions. Because of these functions I was able to remove the global array we had for hpke before.

Restricted the kem, kdf, and aead fields of the hpke struct from word32 to word16. The RFC only uses two bytes for these values (and so do we in the ECH code) so I made them smaller.

refactor openssl-ech workflow + add suite testing:

Broke openssl-ech.yml into a script. Mainly this was to streamline testing ciphersuites in the workflow. But it is very nice for locally testing ech interop too.

Also updated examples/server/server.c to support different ech ciphersuite through --ech-suite. The parsing for this is pretty optimistic.

Testing

Added tests to check all algorithm combinations for ECH (this may be extreme?). This comes out to 24 combinations each doing a full handshake.

Added tests to wolfcrypt for a bigger and smaller KDF compared to the KEM.

Interop testing with OpenSSL using a weird hpke suite.

Checklist

  • [ X] added tests
  • updated/added doxygen
  • updated appropriate READMEs
  • Updated manual and documentation

@sebastian-carpenter sebastian-carpenter self-assigned this Mar 17, 2026
Copilot AI review requested due to automatic review settings March 17, 2026 23:12
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes HPKE algorithm combination handling (separating KEM vs KDF digest usage) and refactors ECH/HPKE integration to reduce duplication, while expanding CI and API tests for suite permutations.

Changes:

  • Correct HPKE digest selection by tracking and using separate KEM and KDF digests.
  • Replace global “supported algos” arrays with internal support/query helpers used by TLS/ECH code.
  • Add/extend tests and CI interop scripting to exercise multiple HPKE/ECH suite combinations.

Reviewed changes

Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
wolfssl/wolfcrypt/hpke.h Updates Hpke fields and exposes internal helpers for TLS/ECH to query HPKE support/details.
wolfcrypt/src/hpke.c Implements split KEM/KDF digest handling and adds support/helper functions for ECH/TLS.
src/tls13.c Switches ECH cipher-suite support checks to new HPKE helper functions.
src/tls.c Uses centralized KEM enc length helper; tightens cleanup on TLSX push failure and free paths.
src/ssl_ech.c Uses centralized KEM enc length helper when building ECHConfig output; adjusts config generation defaults.
wolfcrypt/test/test.c Adds HPKE tests for mismatched KEM/KDF digest combinations.
tests/api.c Adds TLS 1.3 ECH tests iterating through supported (KEM,KDF,AEAD) combinations and verifying negotiated IDs.
examples/server/server.c Adds --ech-suite parsing to generate ECH configs with specific HPKE suite IDs.
.github/workflows/openssl-ech.yml Refactors OpenSSL ECH workflow to use a script and tests “default” + “weird” suites.
.github/scripts/openssl-ech.sh New helper script to run OpenSSL↔wolfSSL ECH interop in both directions with optional suite selection.
Comments suppressed due to low confidence (1)

tests/api.c:1

  • test_wolfSSL_Tls13_ECH_all_algos_ex() returns EXPECT_RESULT(), but the loop asserts it equals WOLFSSL_SUCCESS. In this test file, helper tests typically compare against TEST_SUCCESS / TEST_FAIL semantics rather than wolfSSL API return codes, so this assertion is very likely wrong and may fail even when the EXPECTs pass. Update the expected value to match the return convention of EXPECT_RESULT() (typically TEST_SUCCESS), or change _ex() to return WOLFSSL_SUCCESS/WOLFSSL_FAILURE consistently if that’s the intended convention for this specific test.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment on lines +1254 to +1278
WOLFSSL_LOCAL int wc_HpkeKemIsSupported(word16 kemId)
{
switch (kemId) {
#if defined(HAVE_ECC)
#if defined(WOLFSSL_SHA224) || !defined(NO_SHA256)
case DHKEM_P256_HKDF_SHA256:
#endif
#ifdef WOLFSSL_SHA384
case DHKEM_P384_HKDF_SHA384:
#endif
#if defined(WOLFSSL_SHA384) || defined(WOLFSSL_SHA512)
case DHKEM_P521_HKDF_SHA512:
#endif
#endif /* HAVE_ECC */
#if defined(HAVE_CURVE25519) && \
(defined(WOLFSSL_SHA224) || !defined(NO_SHA256))
case DHKEM_X25519_HKDF_SHA256:
#endif
return 1;

case DHKEM_X448_HKDF_SHA512:
default:
return 0;
}
}
Comment on lines +6 to +7
cat "$TMP_LOG"
rm -f "$TMP_LOG"
int ret = 0;
word16 encLen = DHKEM_X25519_ENC_LEN;
WOLFSSL_EchConfig* newConfig;
word16 encLen = sizeof(newConfig->receiverPubkey);
Comment on lines 131 to +135

WOLFSSL_LOCAL word16 wc_HpkeKemGetEncLen(word16 kemId);
WOLFSSL_LOCAL int wc_HpkeKemIsSupported(word16 kemId);
WOLFSSL_LOCAL int wc_HpkeKdfIsSupported(word16 kdfId);
WOLFSSL_LOCAL int wc_HpkeAeadIsSupported(word16 aeadId);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants