Skip to content

Add ability to create PKey from parameters #2439

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

huwcbjones
Copy link
Contributor

@huwcbjones huwcbjones commented Aug 6, 2025

Work towards #2047 by adding ability to create PKeys from OSSL params.

As such:

  1. Add wrappers around OSSL_PARAM_BLD and OSSL_PARAM to make it easier interacting with these APIs (as well as ensuring lifetimes/ownership is respected). As noted in pkey: add get bn & utf-8 param funcs #2436 (comment) it's not preferrable to expose these APIs publicly, so leave them as an internal module.
  2. Add the EVP_PKEY_fromdata* APIs to PkeyCtx.
  3. Use the ParamBuilder instead of manually constructing a list of params in KDF and PKEY_CTX.

For Rsa, this means that from_public_components would look like this

        #[cfg(ossl300)]
        {
            let params = ParamBuilder::new()
                .push_bignum(c"n", &n)?
                .push_bignum(c"e", &e)?
                .build()?;
            return pkey_from_params(Id::RSA, &params)?.rsa();
        }

        #[cfg(not(ossl300))]
        unsafe {
            let rsa = cvt_p(ffi::RSA_new())?;
            RSA_set0_key(rsa, n.as_ptr(), e.as_ptr(), ptr::null_mut());
            mem::forget((n, e));
            Ok(Rsa::from_ptr(rsa))
        }

@huwcbjones huwcbjones force-pushed the huw/evp-from-params branch 6 times, most recently from 33d55eb to 6ec4f5e Compare August 6, 2025 16:58
@huwcbjones huwcbjones marked this pull request as ready for review August 6, 2025 17:33
@huwcbjones huwcbjones force-pushed the huw/evp-from-params branch from 6ec4f5e to 46b04b2 Compare August 8, 2025 10:31
@huwcbjones huwcbjones force-pushed the huw/evp-from-params branch from c441853 to 086de70 Compare August 8, 2025 19:11
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.

1 participant