diff options
author | Richard Levitte <levitte@openssl.org> | 2019-08-12 14:56:18 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2019-08-15 10:49:56 +0200 |
commit | ae3ff60e7bea6fb7510b5c0c2b9599d8430cf001 (patch) | |
tree | a6cef6a574ebeac091b9bdb57ba6aff5c257becf /crypto | |
parent | aee6e29f0e88df18ebc21dbcf9d4d5794d7511e0 (diff) |
Add missing EVP param utility functions
These functions were missing for a completes API:
EVP_MD_get_params(), EVP_CIPHER_get_params(), EVP_CIPHER_CTX_set_params(),
and EVP_CIPHER_CTX_get_params
Additionally, we also add all the corresponding parameter descriptor
returning functions, along the correspoding provider dispatches:
EVP_MD_gettable_params(), EVP_MD_CTX_settable_params(),
EVP_MD_CTX_gettable_params(), EVP_CIPHER_gettable_params(),
EVP_CIPHER_CTX_settable_params(), and EVP_CIPHER_CTX_gettable_params()
Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9576)
Diffstat (limited to 'crypto')
-rw-r--r-- | crypto/evp/digest.c | 42 | ||||
-rw-r--r-- | crypto/evp/evp_enc.c | 59 | ||||
-rw-r--r-- | crypto/include/internal/evp_int.h | 6 |
3 files changed, 107 insertions, 0 deletions
diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index afcd73609b..46d5c17e2f 100644 --- a/crypto/evp/digest.c +++ b/crypto/evp/digest.c @@ -524,6 +524,20 @@ int EVP_Digest(const void *data, size_t count, return ret; } +int EVP_MD_get_params(const EVP_MD *digest, OSSL_PARAM params[]) +{ + if (digest != NULL && digest->get_params != NULL) + return digest->get_params(params); + return 0; +} + +const OSSL_PARAM *EVP_MD_gettable_params(const EVP_MD *digest) +{ + if (digest != NULL && digest->gettable_params != NULL) + return digest->gettable_params(); + return NULL; +} + int EVP_MD_CTX_set_params(EVP_MD_CTX *ctx, const OSSL_PARAM params[]) { if (ctx->digest != NULL && ctx->digest->ctx_set_params != NULL) @@ -531,6 +545,13 @@ int EVP_MD_CTX_set_params(EVP_MD_CTX *ctx, const OSSL_PARAM params[]) return 0; } +const OSSL_PARAM *EVP_MD_CTX_settable_params(const EVP_MD *digest) +{ + if (digest != NULL && digest->settable_ctx_params != NULL) + return digest->settable_ctx_params(); + return NULL; +} + int EVP_MD_CTX_get_params(EVP_MD_CTX *ctx, OSSL_PARAM params[]) { if (ctx->digest != NULL && ctx->digest->get_params != NULL) @@ -538,6 +559,13 @@ int EVP_MD_CTX_get_params(EVP_MD_CTX *ctx, OSSL_PARAM params[]) return 0; } +const OSSL_PARAM *EVP_MD_CTX_gettable_params(const EVP_MD *digest) +{ + if (digest != NULL && digest->gettable_ctx_params != NULL) + return digest->gettable_ctx_params(); + return NULL; +} + /* TODO(3.0): Remove legacy code below - only used by engines & DigestSign */ int EVP_MD_CTX_ctrl(EVP_MD_CTX *ctx, int cmd, int p1, void *p2) { @@ -655,6 +683,20 @@ static void *evp_md_from_dispatch(const char *name, const OSSL_DISPATCH *fns, if (md->ctx_get_params == NULL) md->ctx_get_params = OSSL_get_OP_digest_ctx_get_params(fns); break; + case OSSL_FUNC_DIGEST_GETTABLE_PARAMS: + if (md->gettable_params == NULL) + md->gettable_params = OSSL_get_OP_digest_gettable_params(fns); + break; + case OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS: + if (md->settable_ctx_params == NULL) + md->settable_ctx_params = + OSSL_get_OP_digest_settable_ctx_params(fns); + break; + case OSSL_FUNC_DIGEST_GETTABLE_CTX_PARAMS: + if (md->gettable_ctx_params == NULL) + md->gettable_ctx_params = + OSSL_get_OP_digest_gettable_ctx_params(fns); + break; } } if ((fncnt != 0 && fncnt != 5) diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c index 31e15a63c2..9e0c01aff9 100644 --- a/crypto/evp/evp_enc.c +++ b/crypto/evp/evp_enc.c @@ -1051,6 +1051,48 @@ legacy: return ret; } +int EVP_CIPHER_get_params(EVP_CIPHER *cipher, OSSL_PARAM params[]) +{ + if (cipher != NULL && cipher->get_params != NULL) + return cipher->get_params(params); + return 0; +} + +int EVP_CIPHER_CTX_set_params(EVP_CIPHER_CTX *ctx, const OSSL_PARAM params[]) +{ + if (ctx->cipher != NULL && ctx->cipher->ctx_set_params != NULL) + return ctx->cipher->ctx_set_params(ctx->provctx, params); + return 0; +} + +int EVP_CIPHER_CTX_get_params(EVP_CIPHER_CTX *ctx, OSSL_PARAM params[]) +{ + if (ctx->cipher != NULL && ctx->cipher->ctx_get_params != NULL) + return ctx->cipher->ctx_get_params(ctx->provctx, params); + return 0; +} + +const OSSL_PARAM *EVP_CIPHER_gettable_params(const EVP_CIPHER *cipher) +{ + if (cipher != NULL && cipher->gettable_params != NULL) + return cipher->gettable_params(); + return NULL; +} + +const OSSL_PARAM *EVP_CIPHER_CTX_settable_params(const EVP_CIPHER *cipher) +{ + if (cipher != NULL && cipher->settable_ctx_params != NULL) + return cipher->settable_ctx_params(); + return NULL; +} + +const OSSL_PARAM *EVP_CIPHER_CTX_gettable_params(const EVP_CIPHER *cipher) +{ + if (cipher != NULL && cipher->gettable_ctx_params != NULL) + return cipher->gettable_ctx_params(); + return NULL; +} + #if !defined(FIPS_MODE) /* TODO(3.0): No support for RAND yet in the FIPS module */ int EVP_CIPHER_CTX_rand_key(EVP_CIPHER_CTX *ctx, unsigned char *key) @@ -1212,6 +1254,23 @@ static void *evp_cipher_from_dispatch(const char *name, break; cipher->ctx_set_params = OSSL_get_OP_cipher_ctx_set_params(fns); break; + case OSSL_FUNC_CIPHER_GETTABLE_PARAMS: + if (cipher->gettable_params != NULL) + break; + cipher->gettable_params = OSSL_get_OP_cipher_gettable_params(fns); + break; + case OSSL_FUNC_CIPHER_GETTABLE_CTX_PARAMS: + if (cipher->gettable_ctx_params != NULL) + break; + cipher->gettable_ctx_params = + OSSL_get_OP_cipher_gettable_ctx_params(fns); + break; + case OSSL_FUNC_CIPHER_SETTABLE_CTX_PARAMS: + if (cipher->settable_ctx_params != NULL) + break; + cipher->settable_ctx_params = + OSSL_get_OP_cipher_settable_ctx_params(fns); + break; } } if ((fnciphcnt != 0 && fnciphcnt != 3 && fnciphcnt != 4) diff --git a/crypto/include/internal/evp_int.h b/crypto/include/internal/evp_int.h index cdb5aab87c..ce9b9b8f51 100644 --- a/crypto/include/internal/evp_int.h +++ b/crypto/include/internal/evp_int.h @@ -215,6 +215,9 @@ struct evp_md_st { OSSL_OP_digest_get_params_fn *get_params; OSSL_OP_digest_ctx_set_params_fn *ctx_set_params; OSSL_OP_digest_ctx_get_params_fn *ctx_get_params; + OSSL_OP_digest_gettable_params_fn *gettable_params; + OSSL_OP_digest_settable_ctx_params_fn *settable_ctx_params; + OSSL_OP_digest_gettable_ctx_params_fn *gettable_ctx_params; } /* EVP_MD */ ; @@ -266,6 +269,9 @@ struct evp_cipher_st { OSSL_OP_cipher_get_params_fn *get_params; OSSL_OP_cipher_ctx_get_params_fn *ctx_get_params; OSSL_OP_cipher_ctx_set_params_fn *ctx_set_params; + OSSL_OP_cipher_gettable_params_fn *gettable_params; + OSSL_OP_cipher_gettable_ctx_params_fn *gettable_ctx_params; + OSSL_OP_cipher_settable_ctx_params_fn *settable_ctx_params; } /* EVP_CIPHER */ ; /* Macros to code block cipher wrappers */ |