openssl icon indicating copy to clipboard operation
openssl copied to clipboard

ML-KEM digest fetching

Open beldmit opened this issue 6 months ago • 7 comments

I came across that fetching parameters are ignored when creating ML-KEM public key from data. I want to fetch supplementary digests with particular properties.

EVP_KEYMGMT object for ML-KEM supports OSSL_PKEY_PARAM_PROPERTIES only for key generation, not for fetching.

EVP_PKEY_fromdata calls evp_keymgmt_util_fromdata implemented as

https://github.com/openssl/openssl/blob/f426dd1311eecd12f24190c94f56eb85e62aaa27/crypto/evp/keymgmt_lib.c#L319-L331

Fetching of supplementary digests (SHAKE, SHA3) happens when we call evp_keymgmt_newdata (ossl_ml_kem_key_new callback) and parameters are processed only in evp_keymgmt_import.

Can we improve this situation?

beldmit avatar Jun 02 '25 17:06 beldmit

Note: for the FIPS provider this is irrelevant since the fetch can only come from it's internal library context. For the default provider, this is an issue.

paulidale avatar Jun 02 '25 21:06 paulidale

Can anyone please give a clue how can it be implemented? I think the preferred way is to try fetching the digests from the same provider we have the EVP_KEYMGMT respecting the properties and then fallback if we failed

beldmit avatar Jun 06 '25 08:06 beldmit

Perhaps ml_kem_import could be augmented to refetch the digests in the event that a properties param has been provided?

mattcaswell avatar Jun 11 '25 13:06 mattcaswell

I think the digests are fetched earlier...

beldmit avatar Jun 11 '25 14:06 beldmit

From a quick check, it seems that the property query could be set on the decoder between it being created and the key imported. The key isn't actually created until ossl_ml_kem_d2i_PUBKEY gets called. Key creation triggers the digest fetches. There doesn't, however, appear to be any way to get the current provider inside this routine to force fetching from it rather than honouring the property query string.

It would be possible to add a ?provider="xxx" in the caller but it's the usual messing around with property query strings.

paulidale avatar Jun 11 '25 21:06 paulidale

I think the digests are fetched earlier...

They are. But they're not used until later. Hence my suggestion to "refetch" them on import.

mattcaswell avatar Jun 12 '25 08:06 mattcaswell

Yes, this opens a way forward

beldmit avatar Jun 12 '25 08:06 beldmit

I assume it is not just this algorithm

slontis avatar Jul 02 '25 23:07 slontis

@slontis Yes - but but from the FIPS perspective this one is of the most interest

beldmit avatar Jul 03 '25 20:07 beldmit