tool: only declare the static struct once in wrap_public_key()

and make sure to just set it once for both rsa and ec
This commit is contained in:
Klas Lindfors
2018-09-10 10:04:46 +02:00
parent 696894bc68
commit 228a04ad73
+4 -5
View File
@@ -163,20 +163,19 @@ int yk_ec_meth_sign(int type, const unsigned char *dgst, int dlen,
static int wrap_public_key(ykpiv_state *state, int algorithm, EVP_PKEY *public_key, static int wrap_public_key(ykpiv_state *state, int algorithm, EVP_PKEY *public_key,
int key) { int key) {
static struct internal_key int_key;
int_key.state = state;
int_key.algorithm = algorithm;
int_key.key = key;
if(YKPIV_IS_RSA(algorithm)) { if(YKPIV_IS_RSA(algorithm)) {
RSA_METHOD *meth = RSA_meth_dup(RSA_get_default_method()); RSA_METHOD *meth = RSA_meth_dup(RSA_get_default_method());
RSA *rsa = EVP_PKEY_get0_RSA(public_key); RSA *rsa = EVP_PKEY_get0_RSA(public_key);
static struct internal_key int_key;
int_key.state = state;
int_key.algorithm = algorithm;
int_key.key = key;
RSA_meth_set0_app_data(meth, &int_key); RSA_meth_set0_app_data(meth, &int_key);
RSA_meth_set_sign(meth, yk_rsa_meth_sign); RSA_meth_set_sign(meth, yk_rsa_meth_sign);
RSA_set_method(rsa, meth); RSA_set_method(rsa, meth);
} else { } else {
EC_KEY *ec = EVP_PKEY_get0_EC_KEY(public_key); EC_KEY *ec = EVP_PKEY_get0_EC_KEY(public_key);
EC_KEY_METHOD *meth = EC_KEY_METHOD_new(EC_KEY_get_method(ec)); EC_KEY_METHOD *meth = EC_KEY_METHOD_new(EC_KEY_get_method(ec));
struct internal_key int_key = {state, algorithm, key};
if (ec_key_ex_data_idx == -1) if (ec_key_ex_data_idx == -1)
ec_key_ex_data_idx = EC_KEY_get_ex_new_index(0, NULL, NULL, NULL, 0); ec_key_ex_data_idx = EC_KEY_get_ex_new_index(0, NULL, NULL, NULL, 0);
EC_KEY_set_ex_data(ec, ec_key_ex_data_idx, &int_key); EC_KEY_set_ex_data(ec, ec_key_ex_data_idx, &int_key);