diff options
author | Shane Lontis <shane.lontis@oracle.com> | 2020-10-15 13:39:02 +1000 |
---|---|---|
committer | Tomas Mraz <tomas@openssl.org> | 2021-01-26 15:22:13 +0100 |
commit | 98dbf2c1c8143c0cc6dd05be7950d90bc6792064 (patch) | |
tree | 80e18bd238e8f64b4b207846e8322b4ecfdb1592 /crypto | |
parent | 5764c3522c417fc775a78df4529e7a6f93379de8 (diff) |
Add functions to set values into an EVP_PKEY
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Tomas Mraz <tomas@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13139)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/evp/p_lib.c | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/crypto/evp/p_lib.c b/crypto/evp/p_lib.c index f82e42c7e3..f43f5488d0 100644 --- a/crypto/evp/p_lib.c +++ b/crypto/evp/p_lib.c @@ -2138,3 +2138,107 @@ int EVP_PKEY_get_size_t_param(const EVP_PKEY *pkey, const char *key_name, return 0; return 1; } + +int EVP_PKEY_set_int_param(EVP_PKEY *pkey, const char *key_name, int in) +{ + OSSL_PARAM params[2]; + + if (pkey == NULL + || pkey->keymgmt == NULL + || pkey->keydata == NULL + || key_name == NULL) + return 0; + + params[0] = OSSL_PARAM_construct_int(key_name, &in); + params[1] = OSSL_PARAM_construct_end(); + return evp_keymgmt_set_params(pkey->keymgmt, pkey->keydata, params); +} + +int EVP_PKEY_set_size_t_param(EVP_PKEY *pkey, const char *key_name, size_t in) +{ + OSSL_PARAM params[2]; + + if (pkey == NULL + || pkey->keymgmt == NULL + || pkey->keydata == NULL + || key_name == NULL) + return 0; + + params[0] = OSSL_PARAM_construct_size_t(key_name, &in); + params[1] = OSSL_PARAM_construct_end(); + return evp_keymgmt_set_params(pkey->keymgmt, pkey->keydata, params); +} + +int EVP_PKEY_set_bn_param(EVP_PKEY *pkey, const char *key_name, BIGNUM *bn) +{ + OSSL_PARAM params[2]; + unsigned char buffer[2048]; + int bsize = 0; + + if (pkey == NULL + || pkey->keymgmt == NULL + || pkey->keydata == NULL + || key_name == NULL + || bn == NULL) + return 0; + + bsize = BN_num_bytes(bn); + if (!ossl_assert(bsize <= (int)sizeof(buffer))) + return 0; + + if (BN_bn2nativepad(bn, buffer, bsize) < 0) + return 0; + params[0] = OSSL_PARAM_construct_BN(key_name, buffer, bsize); + params[1] = OSSL_PARAM_construct_end(); + return evp_keymgmt_set_params(pkey->keymgmt, pkey->keydata, params); +} + +int EVP_PKEY_set_utf8_string_param(EVP_PKEY *pkey, const char *key_name, + char *str) +{ + OSSL_PARAM params[2]; + + if (pkey == NULL + || pkey->keymgmt == NULL + || pkey->keydata == NULL + || key_name == NULL) + return 0; + + params[0] = OSSL_PARAM_construct_utf8_string(key_name, str, 0); + params[1] = OSSL_PARAM_construct_end(); + return evp_keymgmt_set_params(pkey->keymgmt, pkey->keydata, params); +} + +int EVP_PKEY_set_octet_string_param(EVP_PKEY *pkey, const char *key_name, + unsigned char *buf, size_t bsize) +{ + OSSL_PARAM params[2]; + + if (pkey == NULL + || pkey->keymgmt == NULL + || pkey->keydata == NULL + || key_name == NULL) + return 0; + + params[0] = OSSL_PARAM_construct_octet_string(key_name, buf, bsize); + params[1] = OSSL_PARAM_construct_end(); + return evp_keymgmt_set_params(pkey->keymgmt, pkey->keydata, params); +} + +const OSSL_PARAM *EVP_PKEY_settable_params(EVP_PKEY *pkey) +{ + if (pkey == NULL + || pkey->keymgmt == NULL + || pkey->keydata == NULL) + return 0; + return EVP_KEYMGMT_settable_params(pkey->keymgmt); +} + +int EVP_PKEY_set_params(EVP_PKEY *pkey, OSSL_PARAM params[]) +{ + if (pkey == NULL + || pkey->keymgmt == NULL + || pkey->keydata == NULL) + return 0; + return evp_keymgmt_set_params(pkey->keymgmt, pkey->keydata, params); +} |