Skip to content

Commit

Permalink
Add utility function ossl_param_is_empty()
Browse files Browse the repository at this point in the history
Changed all provider implementations that have a set_ctx_params()
to call this function instead of just testing (params == NULL).This
detects the case wherean OSSL_PARAM array contains just a terminator
entry.

Reviewed-by: Richard Levitte <[email protected]>
Reviewed-by: Tom Cosgrove <[email protected]>
Reviewed-by: Tomas Mraz <[email protected]>
(Merged from openssl#25499)
  • Loading branch information
slontis authored and t8m committed Oct 9, 2024
1 parent 187952d commit f5981c9
Show file tree
Hide file tree
Showing 62 changed files with 113 additions and 99 deletions.
5 changes: 5 additions & 0 deletions providers/common/include/prov/providercommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ void ossl_set_error_state(const char *type);

/* Return true if the module is in a usable condition */
int ossl_prov_is_running(void);

static ossl_inline int ossl_param_is_empty(const OSSL_PARAM params[])
{
return params == NULL || params->key == NULL;
}
5 changes: 3 additions & 2 deletions providers/common/provider_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# include <openssl/engine.h>
# include "crypto/evp.h"
#endif
#include "prov/providercommon.h"
#include "prov/provider_util.h"

void ossl_prov_cipher_reset(PROV_CIPHER *pc)
Expand Down Expand Up @@ -94,7 +95,7 @@ int ossl_prov_cipher_load_from_params(PROV_CIPHER *pc,
const OSSL_PARAM *p;
const char *propquery;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

if (!load_common(params, &propquery, &pc->engine))
Expand Down Expand Up @@ -179,7 +180,7 @@ int ossl_prov_digest_load_from_params(PROV_DIGEST *pd,
const OSSL_PARAM *p;
const char *propquery;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

if (!load_common(params, &propquery, &pd->engine))
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/asymciphers/rsa_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,7 +466,7 @@ static int rsa_set_ctx_params(void *vprsactx, const OSSL_PARAM params[])

if (prsactx == NULL)
return 0;
if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

if (!OSSL_FIPS_IND_SET_CTX_PARAM(prsactx, OSSL_FIPS_IND_SETTABLE0, params,
Expand Down
3 changes: 2 additions & 1 deletion providers/implementations/asymciphers/sm2_enc.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "crypto/sm2.h"
#include "prov/provider_ctx.h"
#include "prov/implementations.h"
#include "prov/providercommon.h"
#include "prov/provider_util.h"

static OSSL_FUNC_asym_cipher_newctx_fn sm2_newctx;
Expand Down Expand Up @@ -190,7 +191,7 @@ static int sm2_set_ctx_params(void *vpsm2ctx, const OSSL_PARAM params[])

if (psm2ctx == NULL)
return 0;
if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

if (!ossl_prov_digest_load_from_params(&psm2ctx->md, params,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ static int aes_set_ctx_params(void *vctx, const OSSL_PARAM params[])
EVP_CTRL_TLS1_1_MULTIBLOCK_PARAM mb_param;
# endif

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_AEAD_MAC_KEY);
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/ciphers/cipher_aes_gcm_siv.c
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ static int ossl_aes_gcm_siv_set_ctx_params(void *vctx, const OSSL_PARAM params[]
const OSSL_PARAM *p;
unsigned int speed = 0;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_AEAD_TAG);
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/ciphers/cipher_aes_ocb.c
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ static int aes_ocb_set_ctx_params(void *vctx, const OSSL_PARAM params[])
const OSSL_PARAM *p;
size_t sz;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_AEAD_TAG);
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/ciphers/cipher_aes_siv.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ static int aes_siv_set_ctx_params(void *vctx, const OSSL_PARAM params[])
const OSSL_PARAM *p;
unsigned int speed = 0;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_AEAD_TAG);
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/ciphers/cipher_aes_wrp.c
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ static int aes_wrap_set_ctx_params(void *vctx, const OSSL_PARAM params[])
const OSSL_PARAM *p;
size_t keylen = 0;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_KEYLEN);
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/ciphers/cipher_aes_xts.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ static int aes_xts_set_ctx_params(void *vctx, const OSSL_PARAM params[])
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
const OSSL_PARAM *p;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_KEYLEN);
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/ciphers/cipher_chacha20.c
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ static int chacha20_set_ctx_params(void *vctx, const OSSL_PARAM params[])
const OSSL_PARAM *p;
size_t len;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_KEYLEN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ static int chacha20_poly1305_set_ctx_params(void *vctx,
PROV_CIPHER_HW_CHACHA20_POLY1305 *hw =
(PROV_CIPHER_HW_CHACHA20_POLY1305 *)ctx->base.hw;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_KEYLEN);
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/ciphers/cipher_rc2.c
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ static int rc2_set_ctx_params(void *vctx, const OSSL_PARAM params[])
PROV_RC2_CTX *ctx = (PROV_RC2_CTX *)vctx;
const OSSL_PARAM *p;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

if (!ossl_cipher_var_keylen_set_ctx_params(vctx, params))
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/ciphers/cipher_rc4_hmac_md5.c
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ static int rc4_hmac_md5_set_ctx_params(void *vctx, const OSSL_PARAM params[])
const OSSL_PARAM *p;
size_t sz;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_KEYLEN);
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/ciphers/cipher_rc5.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ static int rc5_set_ctx_params(void *vctx, const OSSL_PARAM params[])
PROV_RC5_CTX *ctx = (PROV_RC5_CTX *)vctx;
const OSSL_PARAM *p;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

if (!ossl_cipher_var_keylen_set_ctx_params(vctx, params))
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/ciphers/cipher_sm4_xts.c
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ static int sm4_xts_set_ctx_params(void *vxctx, const OSSL_PARAM params[])
PROV_SM4_XTS_CTX *xctx = (PROV_SM4_XTS_CTX *)vxctx;
const OSSL_PARAM *p;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

/*-
Expand Down
4 changes: 2 additions & 2 deletions providers/implementations/ciphers/ciphercommon.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ int ossl_cipher_var_keylen_set_ctx_params(void *vctx, const OSSL_PARAM params[])
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
const OSSL_PARAM *p;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

if (!ossl_cipher_generic_set_ctx_params(vctx, params))
Expand Down Expand Up @@ -625,7 +625,7 @@ int ossl_cipher_generic_set_ctx_params(void *vctx, const OSSL_PARAM params[])
PROV_CIPHER_CTX *ctx = (PROV_CIPHER_CTX *)vctx;
const OSSL_PARAM *p;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_PADDING);
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/ciphers/ciphercommon_ccm.c
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ int ossl_ccm_set_ctx_params(void *vctx, const OSSL_PARAM params[])
const OSSL_PARAM *p;
size_t sz;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

p = OSSL_PARAM_locate_const(params, OSSL_CIPHER_PARAM_AEAD_TAG);
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/ciphers/ciphercommon_gcm.c
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ int ossl_gcm_set_ctx_params(void *vctx, const OSSL_PARAM params[])
void *vp;
int type;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

for (p = params; p->key != NULL; p++) {
Expand Down
4 changes: 2 additions & 2 deletions providers/implementations/digests/blake2_prov.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ int ossl_blake##variant##_get_ctx_params(void *vctx, OSSL_PARAM params[]) \
\
if (ctx == NULL) \
return 0; \
if (params == NULL) \
if (ossl_param_is_empty(params)) \
return 1; \
\
p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_SIZE); \
Expand All @@ -65,7 +65,7 @@ int ossl_blake##variant##_set_ctx_params(void *vctx, const OSSL_PARAM params[])
\
if (ctx == NULL) \
return 0; \
if (params == NULL) \
if (ossl_param_is_empty(params)) \
return 1; \
\
p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_SIZE); \
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/digests/md5_sha1_prov.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static int md5_sha1_set_ctx_params(void *vctx, const OSSL_PARAM params[])

if (ctx == NULL)
return 0;
if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_SSL3_MS);
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/digests/mdc2_prov.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ static int mdc2_set_ctx_params(void *vctx, const OSSL_PARAM params[])

if (ctx == NULL)
return 0;
if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_PAD_TYPE);
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/digests/sha2_prov.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ static int sha1_set_ctx_params(void *vctx, const OSSL_PARAM params[])

if (ctx == NULL)
return 0;
if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_SSL3_MS);
Expand Down
4 changes: 2 additions & 2 deletions providers/implementations/digests/sha3_prov.c
Original file line number Diff line number Diff line change
Expand Up @@ -589,7 +589,7 @@ static int shake_get_ctx_params(void *vctx, OSSL_PARAM params[])

if (ctx == NULL)
return 0;
if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_XOFLEN);
Expand Down Expand Up @@ -625,7 +625,7 @@ static int shake_set_ctx_params(void *vctx, const OSSL_PARAM params[])

if (ctx == NULL)
return 0;
if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_XOFLEN);
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/exchange/dh_exch.c
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ static int dh_set_ctx_params(void *vpdhctx, const OSSL_PARAM params[])

if (pdhctx == NULL)
return 0;
if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

if (!OSSL_FIPS_IND_SET_CTX_PARAM(pdhctx, OSSL_FIPS_IND_SETTABLE0, params,
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/exchange/ecdh_exch.c
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ int ecdh_set_ctx_params(void *vpecdhctx, const OSSL_PARAM params[])

if (pectx == NULL)
return 0;
if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

if (!OSSL_FIPS_IND_SET_CTX_PARAM(pectx, OSSL_FIPS_IND_SETTABLE0, params,
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/kdfs/argon2.c
Original file line number Diff line number Diff line change
Expand Up @@ -1394,7 +1394,7 @@ static int kdf_argon2_set_ctx_params(void *vctx, const OSSL_PARAM params[])
KDF_ARGON2 *ctx;
uint32_t u32_value;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

ctx = (KDF_ARGON2 *) vctx;
Expand Down
12 changes: 6 additions & 6 deletions providers/implementations/kdfs/hkdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ static int hkdf_common_set_ctx_params(KDF_HKDF *ctx, const OSSL_PARAM params[])
const OSSL_PARAM *p;
int n;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

if (OSSL_PARAM_locate_const(params, OSSL_ALG_PARAM_DIGEST) != NULL) {
Expand Down Expand Up @@ -323,7 +323,7 @@ static int kdf_hkdf_set_ctx_params(void *vctx, const OSSL_PARAM params[])
{
KDF_HKDF *ctx = vctx;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

if (!OSSL_FIPS_IND_SET_CTX_PARAM(ctx, OSSL_FIPS_IND_SETTABLE0, params,
Expand Down Expand Up @@ -363,7 +363,7 @@ static int hkdf_common_get_ctx_params(KDF_HKDF *ctx, OSSL_PARAM params[])
{
OSSL_PARAM *p;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

if ((p = OSSL_PARAM_locate(params, OSSL_KDF_PARAM_SIZE)) != NULL) {
Expand All @@ -389,7 +389,7 @@ static int kdf_hkdf_get_ctx_params(void *vctx, OSSL_PARAM params[])
{
KDF_HKDF *ctx = (KDF_HKDF *)vctx;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

if (!hkdf_common_get_ctx_params(ctx, params))
Expand Down Expand Up @@ -841,7 +841,7 @@ static int kdf_tls1_3_set_ctx_params(void *vctx, const OSSL_PARAM params[])
const OSSL_PARAM *p;
KDF_HKDF *ctx = vctx;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

if (!OSSL_FIPS_IND_SET_CTX_PARAM(ctx, OSSL_FIPS_IND_SETTABLE0, params,
Expand Down Expand Up @@ -917,7 +917,7 @@ static int kdf_tls1_3_get_ctx_params(void *vctx, OSSL_PARAM params[])
{
KDF_HKDF *ctx = (KDF_HKDF *)vctx;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

if (!hkdf_common_get_ctx_params(ctx, params))
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/kdfs/hmacdrbg_kdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ static int hmac_drbg_kdf_set_ctx_params(void *vctx,
size_t size = 0;
int md_size;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

p = OSSL_PARAM_locate_const(params, OSSL_KDF_PARAM_HMACDRBG_ENTROPY);
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/kdfs/kbkdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@ static int kbkdf_set_ctx_params(void *vctx, const OSSL_PARAM params[])
OSSL_LIB_CTX *libctx = PROV_LIBCTX_OF(ctx->provctx);
const OSSL_PARAM *p;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

if (!OSSL_FIPS_IND_SET_CTX_PARAM(ctx, OSSL_FIPS_IND_SETTABLE0, params,
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/kdfs/krb5kdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ static int krb5kdf_set_ctx_params(void *vctx, const OSSL_PARAM params[])
KRB5KDF_CTX *ctx = vctx;
OSSL_LIB_CTX *provctx = PROV_LIBCTX_OF(ctx->provctx);

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

if (!ossl_prov_cipher_load_from_params(&ctx->cipher, params, provctx))
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/kdfs/pbkdf2.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ static int kdf_pbkdf2_set_ctx_params(void *vctx, const OSSL_PARAM params[])
uint64_t iter, min_iter;
const EVP_MD *md;

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

if (OSSL_PARAM_locate_const(params, OSSL_ALG_PARAM_DIGEST) != NULL) {
Expand Down
2 changes: 1 addition & 1 deletion providers/implementations/kdfs/pkcs12kdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ static int kdf_pkcs12_set_ctx_params(void *vctx, const OSSL_PARAM params[])
KDF_PKCS12 *ctx = vctx;
OSSL_LIB_CTX *provctx = PROV_LIBCTX_OF(ctx->provctx);

if (params == NULL)
if (ossl_param_is_empty(params))
return 1;

if (!ossl_prov_digest_load_from_params(&ctx->digest, params, provctx))
Expand Down
Loading

0 comments on commit f5981c9

Please sign in to comment.