Guest User

Untitled

a guest
Apr 30th, 2024
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. EVP_PKEY *create_pkey_rsa(const TPM2B_PUBLIC_KEY_RSA *const rsa_unqiue, const uint32_t exponent)
  2. {
  3.     EVP_PKEY_CTX *ctx = NULL;
  4.     EVP_PKEY *rsa_key = NULL;
  5.     BIGNUM *value_n = NULL, *value_e = NULL;
  6.     OSSL_PARAM *key_params = NULL;
  7.     OSSL_PARAM_BLD *param_builder = NULL;
  8.  
  9.     ctx = EVP_PKEY_CTX_new_from_name(NULL, "RSA", NULL);
  10.  
  11.     value_n = BN_bin2bn(rsa_unqiue->buffer, rsa_unqiue->size, NULL);
  12.     value_e = uint32_to_bn(exponent ? exponent : 65537);
  13.  
  14.     param_builder = OSSL_PARAM_BLD_new();
  15.  
  16.     OSSL_PARAM_BLD_push_BN(param_builder, "n", value_n);
  17.     OSSL_PARAM_BLD_push_BN(param_builder, "e", value_e);
  18.     OSSL_PARAM_BLD_push_BN(param_builder, "d", NULL);
  19.  
  20.     key_params = OSSL_PARAM_BLD_to_param(param_builder);
  21.     if (!(EVP_PKEY_fromdata_init(ctx) && EVP_PKEY_fromdata(ctx, &rsa_key, EVP_PKEY_KEYPAIR, key_params))) {
  22.         /* Error handling */
  23.     }
  24.  
  25.     /* Do clean-up here !!! */
  26.  
  27.     return rsa_key;
  28. }
Advertisement
Add Comment
Please, Sign In to add comment