From 0ed26fb63c814458e9906a916fe3ce5ca961842f Mon Sep 17 00:00:00 2001 From: Pauli Date: Tue, 22 Sep 2020 09:26:23 +1000 Subject: [PATCH] drbg: gettable parameters for cipher/digest/mac type. Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/12931) --- providers/implementations/rands/drbg_ctr.c | 15 ++++++++++++++ providers/implementations/rands/drbg_hash.c | 11 +++++++++++ providers/implementations/rands/drbg_hmac.c | 22 +++++++++++++++++++++ 3 files changed, 48 insertions(+) diff --git a/providers/implementations/rands/drbg_ctr.c b/providers/implementations/rands/drbg_ctr.c index 609981b9e87..fdb3d46f1f5 100644 --- a/providers/implementations/rands/drbg_ctr.c +++ b/providers/implementations/rands/drbg_ctr.c @@ -631,6 +631,19 @@ static void drbg_ctr_free(void *vdrbg) static int drbg_ctr_get_ctx_params(void *vdrbg, OSSL_PARAM params[]) { PROV_DRBG *drbg = (PROV_DRBG *)vdrbg; + PROV_DRBG_CTR *ctr = (PROV_DRBG_CTR *)drbg->data; + OSSL_PARAM *p; + + p = OSSL_PARAM_locate(params, OSSL_DRBG_PARAM_USE_DF); + if (p != NULL && !OSSL_PARAM_set_int(p, ctr->use_df)) + return 0; + + p = OSSL_PARAM_locate(params, OSSL_DRBG_PARAM_CIPHER); + if (p != NULL) { + if (ctr->cipher_ctr == NULL + || !OSSL_PARAM_set_utf8_string(p, EVP_CIPHER_name(ctr->cipher_ctr))) + return 0; + } return drbg_get_ctx_params(drbg, params); } @@ -638,6 +651,8 @@ static int drbg_ctr_get_ctx_params(void *vdrbg, OSSL_PARAM params[]) static const OSSL_PARAM *drbg_ctr_gettable_ctx_params(ossl_unused void *provctx) { static const OSSL_PARAM known_gettable_ctx_params[] = { + OSSL_PARAM_utf8_string(OSSL_DRBG_PARAM_CIPHER, NULL, 0), + OSSL_PARAM_int(OSSL_DRBG_PARAM_USE_DF, NULL), OSSL_PARAM_DRBG_GETTABLE_CTX_COMMON, OSSL_PARAM_END }; diff --git a/providers/implementations/rands/drbg_hash.c b/providers/implementations/rands/drbg_hash.c index ca2f8bb0c6f..e5266dbb299 100644 --- a/providers/implementations/rands/drbg_hash.c +++ b/providers/implementations/rands/drbg_hash.c @@ -428,6 +428,16 @@ static void drbg_hash_free(void *vdrbg) static int drbg_hash_get_ctx_params(void *vdrbg, OSSL_PARAM params[]) { PROV_DRBG *drbg = (PROV_DRBG *)vdrbg; + PROV_DRBG_HASH *hash = (PROV_DRBG_HASH *)drbg->data; + const EVP_MD *md; + OSSL_PARAM *p; + + p = OSSL_PARAM_locate(params, OSSL_DRBG_PARAM_DIGEST); + if (p != NULL) { + md = ossl_prov_digest_md(&hash->digest); + if (md == NULL || !OSSL_PARAM_set_utf8_string(p, EVP_MD_name(md))) + return 0; + } return drbg_get_ctx_params(drbg, params); } @@ -435,6 +445,7 @@ static int drbg_hash_get_ctx_params(void *vdrbg, OSSL_PARAM params[]) static const OSSL_PARAM *drbg_hash_gettable_ctx_params(ossl_unused void *p_ctx) { static const OSSL_PARAM known_gettable_ctx_params[] = { + OSSL_PARAM_utf8_string(OSSL_DRBG_PARAM_DIGEST, NULL, 0), OSSL_PARAM_DRBG_GETTABLE_CTX_COMMON, OSSL_PARAM_END }; diff --git a/providers/implementations/rands/drbg_hmac.c b/providers/implementations/rands/drbg_hmac.c index fb232de519c..f7ac2926ac8 100644 --- a/providers/implementations/rands/drbg_hmac.c +++ b/providers/implementations/rands/drbg_hmac.c @@ -325,6 +325,26 @@ static void drbg_hmac_free(void *vdrbg) static int drbg_hmac_get_ctx_params(void *vdrbg, OSSL_PARAM params[]) { PROV_DRBG *drbg = (PROV_DRBG *)vdrbg; + PROV_DRBG_HMAC *hmac = (PROV_DRBG_HMAC *)drbg->data; + const char *name; + const EVP_MD *md; + OSSL_PARAM *p; + + p = OSSL_PARAM_locate(params, OSSL_DRBG_PARAM_MAC); + if (p != NULL) { + if (hmac->ctx == NULL) + return 0; + name = EVP_MAC_name(EVP_MAC_CTX_mac(hmac->ctx)); + if (!OSSL_PARAM_set_utf8_string(p, name)) + return 0; + } + + p = OSSL_PARAM_locate(params, OSSL_DRBG_PARAM_DIGEST); + if (p != NULL) { + md = ossl_prov_digest_md(&hmac->digest); + if (md == NULL || !OSSL_PARAM_set_utf8_string(p, EVP_MD_name(md))) + return 0; + } return drbg_get_ctx_params(drbg, params); } @@ -332,6 +352,8 @@ static int drbg_hmac_get_ctx_params(void *vdrbg, OSSL_PARAM params[]) static const OSSL_PARAM *drbg_hmac_gettable_ctx_params(ossl_unused void *p_ctx) { static const OSSL_PARAM known_gettable_ctx_params[] = { + OSSL_PARAM_utf8_string(OSSL_DRBG_PARAM_MAC, NULL, 0), + OSSL_PARAM_utf8_string(OSSL_DRBG_PARAM_DIGEST, NULL, 0), OSSL_PARAM_DRBG_GETTABLE_CTX_COMMON, OSSL_PARAM_END }; -- 2.47.2