Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- EVP_PKEY *create_pkey_rsa(const TPM2B_PUBLIC_KEY_RSA *const rsa_unqiue, const uint32_t exponent)
- {
- EVP_PKEY_CTX *ctx = NULL;
- EVP_PKEY *rsa_key = NULL;
- BIGNUM *value_n = NULL, *value_e = NULL;
- OSSL_PARAM *key_params = NULL;
- OSSL_PARAM_BLD *param_builder = NULL;
- ctx = EVP_PKEY_CTX_new_from_name(NULL, "RSA", NULL);
- value_n = BN_bin2bn(rsa_unqiue->buffer, rsa_unqiue->size, NULL);
- value_e = uint32_to_bn(exponent ? exponent : 65537);
- param_builder = OSSL_PARAM_BLD_new();
- OSSL_PARAM_BLD_push_BN(param_builder, "n", value_n);
- OSSL_PARAM_BLD_push_BN(param_builder, "e", value_e);
- OSSL_PARAM_BLD_push_BN(param_builder, "d", NULL);
- key_params = OSSL_PARAM_BLD_to_param(param_builder);
- if (!(EVP_PKEY_fromdata_init(ctx) && EVP_PKEY_fromdata(ctx, &rsa_key, EVP_PKEY_KEYPAIR, key_params))) {
- /* Error handling */
- }
- /* Do clean-up here !!! */
- return rsa_key;
- }
Advertisement
Add Comment
Please, Sign In to add comment