EVP_PKEY_generate() #24011
Unanswered
shaikhus12122864
asked this question in
Q&A
EVP_PKEY_generate()
#24011
Replies: 2 comments 4 replies
-
You can use the mappings specified in #23506 (comment) to get the CRT parameters of a given RSA private key. #include <openssl/evp.h>
#include <openssl/core_names.h>
#include <openssl/rsa.h>
#define RSA_KEY_SIZE 2048
void print_parameter(const EVP_PKEY *pkey, const char *key_name) {
BIGNUM *param = NULL;
char *str = NULL;
if (EVP_PKEY_get_bn_param(pkey, key_name, ¶m)) {
str = BN_bn2dec(param);
fprintf(stdout, "%s: %s\n", key_name, str);
OPENSSL_free(str);
BN_free(param);
}
else {
fprintf(stderr, "Failed to fetch %s\n", key_name);
}
}
int main() {
EVP_PKEY *pkey = NULL;
pkey = EVP_RSA_gen(RSA_KEY_SIZE);
if (pkey == NULL) {
fprintf(stderr, "Failed to generate RSA key\n");
return 1;
}
print_parameter(pkey, OSSL_PKEY_PARAM_RSA_N);
print_parameter(pkey, OSSL_PKEY_PARAM_RSA_FACTOR1);
print_parameter(pkey, OSSL_PKEY_PARAM_RSA_FACTOR2);
print_parameter(pkey, OSSL_PKEY_PARAM_RSA_D);
print_parameter(pkey, OSSL_PKEY_PARAM_RSA_EXPONENT1);
print_parameter(pkey, OSSL_PKEY_PARAM_RSA_EXPONENT2);
print_parameter(pkey, OSSL_PKEY_PARAM_RSA_COEFFICIENT1);
EVP_PKEY_free(pkey);
return 0;
} |
Beta Was this translation helpful? Give feedback.
2 replies
-
Do you need calculating CRT parameters for an existing key data which has only p, q and d? Or is this just asking about how to retrieve CRT parameters from an RSA EVP_PKEY generated by OpenSSL? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Is there any function in openssl to calculate CRT parameters for RSA private key
Beta Was this translation helpful? Give feedback.
All reactions