Skip to content

Add DHKEM support and test cases#1069

Merged
rhenium merged 1 commit into
ruby:masterfrom
sylph01:test-dhkem
Jun 24, 2026
Merged

Add DHKEM support and test cases#1069
rhenium merged 1 commit into
ruby:masterfrom
sylph01:test-dhkem

Conversation

@sylph01

@sylph01 sylph01 commented Jun 23, 2026

Copy link
Copy Markdown
Contributor

Follow-up to #1062:

  • Added test cases for EVP_KEM-EC / EVP_KEM-X25519 / EVP_KEM-X448 (RFC 9180 Section 4.1 — DH-Based KEM)
  • Added a parameter helper for OpenSSL 3.2-3.4 so EC/X25519/X448 DHKEM works on those versions
    • On OpenSSL 3.2-3.4, DHKEM on EC/ECX keys need the operation (DHKEM) to be explicitly selected, so this adds a helper to the implementation to fill the operation parameter

Note: I left out EVP_KEM-RSA intentionally. RSA keys have a different mode of operation (RSASVE), and on OpenSSL 3.2-3.4, this needs to be explicitly set to perform RSASVE (just like DHKEM needed an explicit parameter). If there is need for this I will add it separately or in the same pull request.

Comment thread ext/openssl/ossl_pkey.c Outdated
* X25519, X448 and EC keys only support the RFC 9180 DH-Based KEM (DHKEM).
* OpenSSL 3.2-3.4 require the operation to be selected explicitly via
* OSSL_KEM_PARAM_OPERATION before encapsulate/decapsulate; without it the
* operation fails with "invalid mode". OpenSSL 3.5 defaults to DHKEM. Build

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

OpenSSL 3.3 is EOL already and 3.4 will reach EOL in 4 months: https://openssl-library.org/policies/releasestrat/index.html

To me, this looks like more of a bug fix. Fortunately, the usual suspects (Ubuntu and RHEL) appear to have skipped these versions, so I wonder if anyone would actually benefit from this workaround?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

If that's the case, I might just opt to remove the options helper altogether. That fix is b7d163e, and with this, the patch only includes changes to the test.

@rhenium

rhenium commented Jun 23, 2026

Copy link
Copy Markdown
Member

I'm leaning towards not merging the default values for OSSL_KEM_PARAM_OPERATION_DHKEM. The tests seem like a good addition and passed without the change on my computer.

FWIW, I've been exploring if we could expose OSSL_PARAM from EVP_PKEY_CTX to Ruby in a generic way. I haven't had time to finish it, but a WIP branch is here: https://github.com/rhenium/ruby-openssl/commits/ky/pkey-ctx/

@rhenium

rhenium commented Jun 24, 2026

Copy link
Copy Markdown
Member

Could you squash commits?

@sylph01

sylph01 commented Jun 24, 2026

Copy link
Copy Markdown
Contributor Author

squashed @ dfc45d3

@rhenium rhenium left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@rhenium rhenium merged commit 9627df5 into ruby:master Jun 24, 2026
46 of 47 checks passed
@sylph01 sylph01 deleted the test-dhkem branch June 24, 2026 10:09
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