From ab56952b58f9f357bcfe369a5eb97a4b5cd6f948 Mon Sep 17 00:00:00 2001 From: "Dr. David von Oheimb" Date: Sat, 2 Dec 2023 18:04:44 +0100 Subject: [PATCH] EVP: add missing *_get/settable_params() error queue entries and error result documentation --- crypto/encode_decode/decoder_err.c | 6 +++++- crypto/encode_decode/decoder_meth.c | 4 +++- crypto/encode_decode/encoder_err.c | 6 +++++- crypto/encode_decode/encoder_meth.c | 2 ++ crypto/err/openssl.txt | 9 +++++++++ crypto/evp/asymcipher.c | 8 ++++++-- crypto/evp/digest.c | 5 +++++ crypto/evp/evp_enc.c | 14 +++++++++++--- crypto/evp/evp_err.c | 10 ++++++++++ crypto/evp/evp_rand.c | 20 +++++++++++++++----- crypto/evp/exchange.c | 8 ++++++-- crypto/evp/kem.c | 8 ++++++-- crypto/evp/mac_meth.c | 22 +++++++++++++++++----- crypto/evp/pmeth_lib.c | 2 ++ crypto/evp/signature.c | 8 ++++++-- doc/man3/EVP_EncryptInit.pod | 6 +++--- doc/man3/EVP_MAC.pod | 5 +++++ doc/man3/EVP_PKEY_CTX_set_params.pod | 6 +++--- doc/man3/EVP_PKEY_settable_params.pod | 4 +++- doc/man3/EVP_RAND.pod | 2 +- doc/man3/OSSL_DECODER.pod | 2 +- doc/man3/OSSL_ENCODER.pod | 2 +- include/openssl/decodererr.h | 4 +++- include/openssl/encodererr.h | 4 +++- include/openssl/evperr.h | 5 +++++ 25 files changed, 136 insertions(+), 36 deletions(-) diff --git a/crypto/encode_decode/decoder_err.c b/crypto/encode_decode/decoder_err.c index 88324a1d50788..15722ea078712 100644 --- a/crypto/encode_decode/decoder_err.c +++ b/crypto/encode_decode/decoder_err.c @@ -1,6 +1,6 @@ /* * Generated by util/mkerr.pl DO NOT EDIT - * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -19,8 +19,12 @@ static const ERR_STRING_DATA OSSL_DECODER_str_reasons[] = { "could not decode object"}, {ERR_PACK(ERR_LIB_OSSL_DECODER, 0, OSSL_DECODER_R_DECODER_NOT_FOUND), "decoder not found"}, + {ERR_PACK(ERR_LIB_OSSL_DECODER, 0, OSSL_DECODER_R_MISSING_GETTABLE_PARAMS), + "missing gettable params"}, {ERR_PACK(ERR_LIB_OSSL_DECODER, 0, OSSL_DECODER_R_MISSING_GET_PARAMS), "missing get params"}, + {ERR_PACK(ERR_LIB_OSSL_DECODER, 0, OSSL_DECODER_R_MISSING_SETTABLE_CTX_PARAMS), + "missing settable ctx params"}, {0, NULL} }; diff --git a/crypto/encode_decode/decoder_meth.c b/crypto/encode_decode/decoder_meth.c index 2e70e8aa37949..66fe3c53333cb 100644 --- a/crypto/encode_decode/decoder_meth.c +++ b/crypto/encode_decode/decoder_meth.c @@ -588,7 +588,8 @@ OSSL_DECODER_gettable_params(OSSL_DECODER *decoder) return decoder->gettable_params(provctx); } - return NULL; + ERR_raise(ERR_LIB_OSSL_DECODER, OSSL_DECODER_R_MISSING_GETTABLE_PARAMS); + return NULL; } int OSSL_DECODER_get_params(OSSL_DECODER *decoder, OSSL_PARAM params[]) @@ -606,6 +607,7 @@ OSSL_DECODER_settable_ctx_params(OSSL_DECODER *decoder) return decoder->settable_ctx_params(provctx); } + ERR_raise(ERR_LIB_OSSL_DECODER, OSSL_DECODER_R_MISSING_SETTABLE_CTX_PARAMS); return NULL; } diff --git a/crypto/encode_decode/encoder_err.c b/crypto/encode_decode/encoder_err.c index a904e87ef2e7c..8f9e906fd4d40 100644 --- a/crypto/encode_decode/encoder_err.c +++ b/crypto/encode_decode/encoder_err.c @@ -1,6 +1,6 @@ /* * Generated by util/mkerr.pl DO NOT EDIT - * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -19,8 +19,12 @@ static const ERR_STRING_DATA OSSL_ENCODER_str_reasons[] = { "encoder not found"}, {ERR_PACK(ERR_LIB_OSSL_ENCODER, 0, OSSL_ENCODER_R_INCORRECT_PROPERTY_QUERY), "incorrect property query"}, + {ERR_PACK(ERR_LIB_OSSL_ENCODER, 0, OSSL_ENCODER_R_MISSING_GETTABLE_PARAMS), + "missing gettable params"}, {ERR_PACK(ERR_LIB_OSSL_ENCODER, 0, OSSL_ENCODER_R_MISSING_GET_PARAMS), "missing get params"}, + {ERR_PACK(ERR_LIB_OSSL_ENCODER, 0, OSSL_ENCODER_R_MISSING_SETTABLE_CTX_PARAMS), + "missing settable ctx params"}, {0, NULL} }; diff --git a/crypto/encode_decode/encoder_meth.c b/crypto/encode_decode/encoder_meth.c index adf34bbb9f1b4..13e8782eeef1d 100644 --- a/crypto/encode_decode/encoder_meth.c +++ b/crypto/encode_decode/encoder_meth.c @@ -579,6 +579,7 @@ OSSL_ENCODER_gettable_params(OSSL_ENCODER *encoder) return encoder->gettable_params(provctx); } + ERR_raise(ERR_LIB_OSSL_ENCODER, OSSL_ENCODER_R_MISSING_GETTABLE_PARAMS); return NULL; } @@ -596,6 +597,7 @@ const OSSL_PARAM *OSSL_ENCODER_settable_ctx_params(OSSL_ENCODER *encoder) return encoder->settable_ctx_params(provctx); } + ERR_raise(ERR_LIB_OSSL_ENCODER, OSSL_ENCODER_R_MISSING_SETTABLE_CTX_PARAMS); return NULL; } diff --git a/crypto/err/openssl.txt b/crypto/err/openssl.txt index 5f60bd52d2d46..9907615f06a4e 100644 --- a/crypto/err/openssl.txt +++ b/crypto/err/openssl.txt @@ -749,7 +749,12 @@ EVP_R_LOCKING_NOT_SUPPORTED:213:locking not supported EVP_R_MEMORY_LIMIT_EXCEEDED:172:memory limit exceeded EVP_R_MESSAGE_DIGEST_IS_NULL:159:message digest is null EVP_R_METHOD_NOT_SUPPORTED:144:method not supported +EVP_R_MISSING_GETTABLE_CTX_PARAMS:226:missing gettable ctx params +EVP_R_MISSING_GETTABLE_PARAMS:229:missing gettable params +EVP_R_MISSING_GET_CTX_PARAMS:230:missing get ctx params EVP_R_MISSING_PARAMETERS:103:missing parameters +EVP_R_MISSING_SETTABLE_CTX_PARAMS:228:missing settable ctx params +EVP_R_MISSING_SET_CTX_PARAMS:231:missing set ctx params EVP_R_NOT_ABLE_TO_COPY_CTX:190:not able to copy ctx EVP_R_NOT_XOF_OR_INVALID_LENGTH:178:not XOF or invalid length EVP_R_NO_CIPHER_SET:131:no cipher set @@ -868,10 +873,14 @@ OCSP_R_UNKNOWN_NID:120:unknown nid OCSP_R_UNSUPPORTED_REQUESTORNAME_TYPE:129:unsupported requestorname type OSSL_DECODER_R_COULD_NOT_DECODE_OBJECT:101:could not decode object OSSL_DECODER_R_DECODER_NOT_FOUND:102:decoder not found +OSSL_DECODER_R_MISSING_GETTABLE_PARAMS:103:missing gettable params OSSL_DECODER_R_MISSING_GET_PARAMS:100:missing get params +OSSL_DECODER_R_MISSING_SETTABLE_CTX_PARAMS:104:missing settable ctx params OSSL_ENCODER_R_ENCODER_NOT_FOUND:101:encoder not found OSSL_ENCODER_R_INCORRECT_PROPERTY_QUERY:100:incorrect property query +OSSL_ENCODER_R_MISSING_GETTABLE_PARAMS:103:missing gettable params OSSL_ENCODER_R_MISSING_GET_PARAMS:102:missing get params +OSSL_ENCODER_R_MISSING_SETTABLE_CTX_PARAMS:104:missing settable ctx params OSSL_STORE_R_AMBIGUOUS_CONTENT_TYPE:107:ambiguous content type OSSL_STORE_R_BAD_PASSWORD_READ:115:bad password read OSSL_STORE_R_ERROR_VERIFYING_PKCS12_MAC:113:error verifying pkcs12 mac diff --git a/crypto/evp/asymcipher.c b/crypto/evp/asymcipher.c index d22ab2a01a16d..53f600bce8df5 100644 --- a/crypto/evp/asymcipher.c +++ b/crypto/evp/asymcipher.c @@ -546,8 +546,10 @@ const OSSL_PARAM *EVP_ASYM_CIPHER_gettable_ctx_params(const EVP_ASYM_CIPHER *cip { void *provctx; - if (cip == NULL || cip->gettable_ctx_params == NULL) + if (cip == NULL || cip->gettable_ctx_params == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_GETTABLE_CTX_PARAMS); return NULL; + } provctx = ossl_provider_ctx(EVP_ASYM_CIPHER_get0_provider(cip)); return cip->gettable_ctx_params(NULL, provctx); @@ -557,8 +559,10 @@ const OSSL_PARAM *EVP_ASYM_CIPHER_settable_ctx_params(const EVP_ASYM_CIPHER *cip { void *provctx; - if (cip == NULL || cip->settable_ctx_params == NULL) + if (cip == NULL || cip->settable_ctx_params == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_SETTABLE_CTX_PARAMS); return NULL; + } provctx = ossl_provider_ctx(EVP_ASYM_CIPHER_get0_provider(cip)); return cip->settable_ctx_params(NULL, provctx); diff --git a/crypto/evp/digest.c b/crypto/evp/digest.c index ab670a8f49cb6..acbe0abf55b2a 100644 --- a/crypto/evp/digest.c +++ b/crypto/evp/digest.c @@ -765,6 +765,7 @@ const OSSL_PARAM *EVP_MD_gettable_params(const EVP_MD *digest) if (digest != NULL && digest->gettable_params != NULL) return digest->gettable_params( ossl_provider_ctx(EVP_MD_get0_provider(digest))); + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_GETTABLE_PARAMS); return NULL; } @@ -795,6 +796,7 @@ const OSSL_PARAM *EVP_MD_settable_ctx_params(const EVP_MD *md) provctx = ossl_provider_ctx(EVP_MD_get0_provider(md)); return md->settable_ctx_params(NULL, provctx); } + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_SETTABLE_CTX_PARAMS); return NULL; } @@ -821,6 +823,7 @@ const OSSL_PARAM *EVP_MD_CTX_settable_params(EVP_MD_CTX *ctx) return ctx->digest->settable_ctx_params(ctx->algctx, alg); } + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_SETTABLE_CTX_PARAMS); return NULL; } @@ -851,6 +854,7 @@ const OSSL_PARAM *EVP_MD_gettable_ctx_params(const EVP_MD *md) provctx = ossl_provider_ctx(EVP_MD_get0_provider(md)); return md->gettable_ctx_params(NULL, provctx); } + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_GETTABLE_CTX_PARAMS); return NULL; } @@ -876,6 +880,7 @@ const OSSL_PARAM *EVP_MD_CTX_gettable_params(EVP_MD_CTX *ctx) provctx = ossl_provider_ctx(EVP_MD_get0_provider(ctx->digest)); return ctx->digest->gettable_ctx_params(ctx->algctx, provctx); } + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_GETTABLE_CTX_PARAMS); return NULL; } diff --git a/crypto/evp/evp_enc.c b/crypto/evp/evp_enc.c index a19952971271e..38d4a6a4e8bf5 100644 --- a/crypto/evp/evp_enc.c +++ b/crypto/evp/evp_enc.c @@ -1353,7 +1353,8 @@ int EVP_CIPHER_CTX_set_params(EVP_CIPHER_CTX *ctx, const OSSL_PARAM params[]) int EVP_CIPHER_CTX_get_params(EVP_CIPHER_CTX *ctx, OSSL_PARAM params[]) { - if (ctx->cipher != NULL && ctx->cipher->get_ctx_params != NULL) + if (ctx != NULL && ctx->cipher != NULL + && ctx->cipher->get_ctx_params != NULL) return ctx->cipher->get_ctx_params(ctx->algctx, params); return 0; } @@ -1363,6 +1364,7 @@ const OSSL_PARAM *EVP_CIPHER_gettable_params(const EVP_CIPHER *cipher) if (cipher != NULL && cipher->gettable_params != NULL) return cipher->gettable_params( ossl_provider_ctx(EVP_CIPHER_get0_provider(cipher))); + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_GETTABLE_PARAMS); return NULL; } @@ -1374,6 +1376,7 @@ const OSSL_PARAM *EVP_CIPHER_settable_ctx_params(const EVP_CIPHER *cipher) provctx = ossl_provider_ctx(EVP_CIPHER_get0_provider(cipher)); return cipher->settable_ctx_params(NULL, provctx); } + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_SETTABLE_CTX_PARAMS); return NULL; } @@ -1385,6 +1388,7 @@ const OSSL_PARAM *EVP_CIPHER_gettable_ctx_params(const EVP_CIPHER *cipher) provctx = ossl_provider_ctx(EVP_CIPHER_get0_provider(cipher)); return cipher->gettable_ctx_params(NULL, provctx); } + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_GETTABLE_CTX_PARAMS); return NULL; } @@ -1392,10 +1396,12 @@ const OSSL_PARAM *EVP_CIPHER_CTX_settable_params(EVP_CIPHER_CTX *cctx) { void *alg; - if (cctx != NULL && cctx->cipher->settable_ctx_params != NULL) { + if (cctx != NULL && cctx->cipher != NULL + && cctx->cipher->settable_ctx_params != NULL) { alg = ossl_provider_ctx(EVP_CIPHER_get0_provider(cctx->cipher)); return cctx->cipher->settable_ctx_params(cctx->algctx, alg); } + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_SETTABLE_CTX_PARAMS); return NULL; } @@ -1403,10 +1409,12 @@ const OSSL_PARAM *EVP_CIPHER_CTX_gettable_params(EVP_CIPHER_CTX *cctx) { void *provctx; - if (cctx != NULL && cctx->cipher->gettable_ctx_params != NULL) { + if (cctx != NULL && cctx->cipher != NULL + && cctx->cipher->gettable_ctx_params != NULL) { provctx = ossl_provider_ctx(EVP_CIPHER_get0_provider(cctx->cipher)); return cctx->cipher->gettable_ctx_params(cctx->algctx, provctx); } + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_GETTABLE_CTX_PARAMS); return NULL; } diff --git a/crypto/evp/evp_err.c b/crypto/evp/evp_err.c index 42dd7e400972e..12034810f950c 100644 --- a/crypto/evp/evp_err.c +++ b/crypto/evp/evp_err.c @@ -111,7 +111,17 @@ static const ERR_STRING_DATA EVP_str_reasons[] = { "message digest is null"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_METHOD_NOT_SUPPORTED), "method not supported"}, + {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_MISSING_GETTABLE_CTX_PARAMS), + "missing gettable ctx params"}, + {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_MISSING_GETTABLE_PARAMS), + "missing gettable params"}, + {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_MISSING_GET_CTX_PARAMS), + "missing get ctx params"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_MISSING_PARAMETERS), "missing parameters"}, + {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_MISSING_SETTABLE_CTX_PARAMS), + "missing settable ctx params"}, + {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_MISSING_SET_CTX_PARAMS), + "missing set ctx params"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_NOT_ABLE_TO_COPY_CTX), "not able to copy ctx"}, {ERR_PACK(ERR_LIB_EVP, 0, EVP_R_NOT_XOF_OR_INVALID_LENGTH), diff --git a/crypto/evp/evp_rand.c b/crypto/evp/evp_rand.c index 50334042a9cca..c10186477fc0d 100644 --- a/crypto/evp/evp_rand.c +++ b/crypto/evp/evp_rand.c @@ -445,8 +445,10 @@ int EVP_RAND_CTX_set_params(EVP_RAND_CTX *ctx, const OSSL_PARAM params[]) const OSSL_PARAM *EVP_RAND_gettable_params(const EVP_RAND *rand) { - if (rand->gettable_params == NULL) + if (rand->gettable_params == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_GETTABLE_PARAMS); return NULL; + } return rand->gettable_params(ossl_provider_ctx(EVP_RAND_get0_provider(rand))); } @@ -454,8 +456,10 @@ const OSSL_PARAM *EVP_RAND_gettable_ctx_params(const EVP_RAND *rand) { void *provctx; - if (rand->gettable_ctx_params == NULL) + if (rand->gettable_ctx_params == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_GETTABLE_CTX_PARAMS); return NULL; + } provctx = ossl_provider_ctx(EVP_RAND_get0_provider(rand)); return rand->gettable_ctx_params(NULL, provctx); } @@ -464,8 +468,10 @@ const OSSL_PARAM *EVP_RAND_settable_ctx_params(const EVP_RAND *rand) { void *provctx; - if (rand->settable_ctx_params == NULL) + if (rand->settable_ctx_params == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_SETTABLE_CTX_PARAMS); return NULL; + } provctx = ossl_provider_ctx(EVP_RAND_get0_provider(rand)); return rand->settable_ctx_params(NULL, provctx); } @@ -474,8 +480,10 @@ const OSSL_PARAM *EVP_RAND_CTX_gettable_params(EVP_RAND_CTX *ctx) { void *provctx; - if (ctx->meth->gettable_ctx_params == NULL) + if (ctx->meth->gettable_ctx_params == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_GETTABLE_CTX_PARAMS); return NULL; + } provctx = ossl_provider_ctx(EVP_RAND_get0_provider(ctx->meth)); return ctx->meth->gettable_ctx_params(ctx->algctx, provctx); } @@ -484,8 +492,10 @@ const OSSL_PARAM *EVP_RAND_CTX_settable_params(EVP_RAND_CTX *ctx) { void *provctx; - if (ctx->meth->settable_ctx_params == NULL) + if (ctx->meth->settable_ctx_params == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_SETTABLE_CTX_PARAMS); return NULL; + } provctx = ossl_provider_ctx(EVP_RAND_get0_provider(ctx->meth)); return ctx->meth->settable_ctx_params(ctx->algctx, provctx); } diff --git a/crypto/evp/exchange.c b/crypto/evp/exchange.c index d9eed1cea5be2..89f2f745889fe 100644 --- a/crypto/evp/exchange.c +++ b/crypto/evp/exchange.c @@ -580,8 +580,10 @@ const OSSL_PARAM *EVP_KEYEXCH_gettable_ctx_params(const EVP_KEYEXCH *keyexch) { void *provctx; - if (keyexch == NULL || keyexch->gettable_ctx_params == NULL) + if (keyexch == NULL || keyexch->gettable_ctx_params == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_GETTABLE_CTX_PARAMS); return NULL; + } provctx = ossl_provider_ctx(EVP_KEYEXCH_get0_provider(keyexch)); return keyexch->gettable_ctx_params(NULL, provctx); @@ -591,8 +593,10 @@ const OSSL_PARAM *EVP_KEYEXCH_settable_ctx_params(const EVP_KEYEXCH *keyexch) { void *provctx; - if (keyexch == NULL || keyexch->settable_ctx_params == NULL) + if (keyexch == NULL || keyexch->settable_ctx_params == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_SETTABLE_CTX_PARAMS); return NULL; + } provctx = ossl_provider_ctx(EVP_KEYEXCH_get0_provider(keyexch)); return keyexch->settable_ctx_params(NULL, provctx); } diff --git a/crypto/evp/kem.c b/crypto/evp/kem.c index f96012ccf01ed..d4bfca9865232 100644 --- a/crypto/evp/kem.c +++ b/crypto/evp/kem.c @@ -509,8 +509,10 @@ const OSSL_PARAM *EVP_KEM_gettable_ctx_params(const EVP_KEM *kem) { void *provctx; - if (kem == NULL || kem->gettable_ctx_params == NULL) + if (kem == NULL || kem->gettable_ctx_params == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_GETTABLE_CTX_PARAMS); return NULL; + } provctx = ossl_provider_ctx(EVP_KEM_get0_provider(kem)); return kem->gettable_ctx_params(NULL, provctx); @@ -520,8 +522,10 @@ const OSSL_PARAM *EVP_KEM_settable_ctx_params(const EVP_KEM *kem) { void *provctx; - if (kem == NULL || kem->settable_ctx_params == NULL) + if (kem == NULL || kem->settable_ctx_params == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_SETTABLE_CTX_PARAMS); return NULL; + } provctx = ossl_provider_ctx(EVP_KEM_get0_provider(kem)); return kem->settable_ctx_params(NULL, provctx); diff --git a/crypto/evp/mac_meth.c b/crypto/evp/mac_meth.c index a3e7a0220850d..1ce921fea47b2 100644 --- a/crypto/evp/mac_meth.c +++ b/crypto/evp/mac_meth.c @@ -188,8 +188,10 @@ const OSSL_PROVIDER *EVP_MAC_get0_provider(const EVP_MAC *mac) const OSSL_PARAM *EVP_MAC_gettable_params(const EVP_MAC *mac) { - if (mac->gettable_params == NULL) + if (mac == NULL || mac->gettable_params == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_GETTABLE_PARAMS); return NULL; + } return mac->gettable_params(ossl_provider_ctx(EVP_MAC_get0_provider(mac))); } @@ -197,8 +199,10 @@ const OSSL_PARAM *EVP_MAC_gettable_ctx_params(const EVP_MAC *mac) { void *alg; - if (mac->gettable_ctx_params == NULL) + if (mac == NULL || mac->gettable_ctx_params == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_GETTABLE_CTX_PARAMS); return NULL; + } alg = ossl_provider_ctx(EVP_MAC_get0_provider(mac)); return mac->gettable_ctx_params(NULL, alg); } @@ -207,8 +211,10 @@ const OSSL_PARAM *EVP_MAC_settable_ctx_params(const EVP_MAC *mac) { void *alg; - if (mac->settable_ctx_params == NULL) + if (mac == NULL || mac->settable_ctx_params == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_SETTABLE_CTX_PARAMS); return NULL; + } alg = ossl_provider_ctx(EVP_MAC_get0_provider(mac)); return mac->settable_ctx_params(NULL, alg); } @@ -217,8 +223,11 @@ const OSSL_PARAM *EVP_MAC_CTX_gettable_params(EVP_MAC_CTX *ctx) { void *alg; - if (ctx->meth->gettable_ctx_params == NULL) + if (ctx == NULL || ctx->meth == NULL + || ctx->meth->gettable_ctx_params == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_GETTABLE_CTX_PARAMS); return NULL; + } alg = ossl_provider_ctx(EVP_MAC_get0_provider(ctx->meth)); return ctx->meth->gettable_ctx_params(ctx->algctx, alg); } @@ -227,8 +236,11 @@ const OSSL_PARAM *EVP_MAC_CTX_settable_params(EVP_MAC_CTX *ctx) { void *alg; - if (ctx->meth->settable_ctx_params == NULL) + if (ctx == NULL || ctx->meth == NULL + || ctx->meth->settable_ctx_params == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_SETTABLE_CTX_PARAMS); return NULL; + } alg = ossl_provider_ctx(EVP_MAC_get0_provider(ctx->meth)); return ctx->meth->settable_ctx_params(ctx->algctx, alg); } diff --git a/crypto/evp/pmeth_lib.c b/crypto/evp/pmeth_lib.c index 268b1617e3799..f4ec7aaf231cc 100644 --- a/crypto/evp/pmeth_lib.c +++ b/crypto/evp/pmeth_lib.c @@ -719,6 +719,7 @@ int EVP_PKEY_CTX_set_params(EVP_PKEY_CTX *ctx, const OSSL_PARAM *params) return evp_pkey_ctx_set_params_to_ctrl(ctx, params); #endif } + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_SET_CTX_PARAMS); return 0; } @@ -757,6 +758,7 @@ int EVP_PKEY_CTX_get_params(EVP_PKEY_CTX *ctx, OSSL_PARAM *params) return evp_pkey_ctx_get_params_to_ctrl(ctx, params); #endif } + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_GET_CTX_PARAMS); return 0; } diff --git a/crypto/evp/signature.c b/crypto/evp/signature.c index 379b344f0da68..3ffc8bbc253a6 100644 --- a/crypto/evp/signature.c +++ b/crypto/evp/signature.c @@ -369,8 +369,10 @@ const OSSL_PARAM *EVP_SIGNATURE_gettable_ctx_params(const EVP_SIGNATURE *sig) { void *provctx; - if (sig == NULL || sig->gettable_ctx_params == NULL) + if (sig == NULL || sig->gettable_ctx_params == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_GETTABLE_CTX_PARAMS); return NULL; + } provctx = ossl_provider_ctx(EVP_SIGNATURE_get0_provider(sig)); return sig->gettable_ctx_params(NULL, provctx); @@ -380,8 +382,10 @@ const OSSL_PARAM *EVP_SIGNATURE_settable_ctx_params(const EVP_SIGNATURE *sig) { void *provctx; - if (sig == NULL || sig->settable_ctx_params == NULL) + if (sig == NULL || sig->settable_ctx_params == NULL) { + ERR_raise(ERR_LIB_EVP, EVP_R_MISSING_SETTABLE_CTX_PARAMS); return NULL; + } provctx = ossl_provider_ctx(EVP_SIGNATURE_get0_provider(sig)); return sig->settable_ctx_params(NULL, provctx); diff --git a/doc/man3/EVP_EncryptInit.pod b/doc/man3/EVP_EncryptInit.pod index a04e6d102f1ad..6846f3d2c0010 100644 --- a/doc/man3/EVP_EncryptInit.pod +++ b/doc/man3/EVP_EncryptInit.pod @@ -331,12 +331,12 @@ See L below for more information. =item EVP_CIPHER_gettable_params() Get a constant L array that describes the retrievable parameters -that can be used with EVP_CIPHER_get_params(). +that can be used with EVP_CIPHER_get_params(), or NULL on error. =item EVP_CIPHER_gettable_ctx_params() and EVP_CIPHER_CTX_gettable_params() Get a constant L array that describes the retrievable parameters -that can be used with EVP_CIPHER_CTX_get_params(). +that can be used with EVP_CIPHER_CTX_get_params(), or NULL on error. EVP_CIPHER_gettable_ctx_params() returns the parameters that can be retrieved from the algorithm, whereas EVP_CIPHER_CTX_gettable_params() returns the parameters that can be retrieved in the context's current state. @@ -344,7 +344,7 @@ parameters that can be retrieved in the context's current state. =item EVP_CIPHER_settable_ctx_params() and EVP_CIPHER_CTX_settable_params() Get a constant L array that describes the settable parameters -that can be used with EVP_CIPHER_CTX_set_params(). +that can be used with EVP_CIPHER_CTX_set_params(), or NULL on error. EVP_CIPHER_settable_ctx_params() returns the parameters that can be set from the algorithm, whereas EVP_CIPHER_CTX_settable_params() returns the parameters that can be set in the context's current state. diff --git a/doc/man3/EVP_MAC.pod b/doc/man3/EVP_MAC.pod index 56ac92a486728..b8254d952136e 100644 --- a/doc/man3/EVP_MAC.pod +++ b/doc/man3/EVP_MAC.pod @@ -383,6 +383,11 @@ If it isn't set, a call to EVP_MAC_init() will set it. EVP_MAC_do_all_provided() returns nothing at all. +EVP_MAC_gettable_params(), EVP_MAC_gettable_params(), +EVP_MAC_gettable_ctx_params(), EVP_MAC_CTX_gettable_params(), +EVP_MAC_settable_ctx_params(), EVP_MAC_CTX_settable_params() +return a constant L array or NULL on error. + =head1 EXAMPLES #include diff --git a/doc/man3/EVP_PKEY_CTX_set_params.pod b/doc/man3/EVP_PKEY_CTX_set_params.pod index c02151654c3a6..f1a823583161f 100644 --- a/doc/man3/EVP_PKEY_CTX_set_params.pod +++ b/doc/man3/EVP_PKEY_CTX_set_params.pod @@ -59,9 +59,9 @@ L =head1 RETURN VALUES EVP_PKEY_CTX_set_params() returns 1 for success or 0 otherwise. -EVP_PKEY_CTX_settable_params() returns an OSSL_PARAM array on success or NULL on -error. -It may also return NULL if there are no settable parameters available. +EVP_PKEY_CTX_gettable_params() and EVP_PKEY_CTX_settable_params() +return a constant L array on success or NULL on error. +It may also return NULL if there are no get/settable parameters available. All other functions and macros described on this page return a positive value for success and 0 or a negative value for failure. In particular a return value diff --git a/doc/man3/EVP_PKEY_settable_params.pod b/doc/man3/EVP_PKEY_settable_params.pod index 6760818cda799..8d9026eb8bace 100644 --- a/doc/man3/EVP_PKEY_settable_params.pod +++ b/doc/man3/EVP_PKEY_settable_params.pod @@ -55,7 +55,9 @@ These functions only work for Bs that contain a provider side key. =head1 RETURN VALUES -EVP_PKEY_settable_params() returns NULL on error or if it is not supported, +EVP_PKEY_gettable_params() and EVP_PKEY_settable_params() +return a constant L array on success or NULL on error, +which may mean that the operation is not supported. All other methods return 1 if a value was successfully set, or 0 if there was an error. diff --git a/doc/man3/EVP_RAND.pod b/doc/man3/EVP_RAND.pod index 0c79c57b81ef8..a2deb469bd82b 100644 --- a/doc/man3/EVP_RAND.pod +++ b/doc/man3/EVP_RAND.pod @@ -385,7 +385,7 @@ EVP_RAND_get_strength() returns the strength of the random number generator in bits. EVP_RAND_gettable_params(), EVP_RAND_gettable_ctx_params() and -EVP_RAND_settable_ctx_params() return an array of OSSL_PARAMs. +EVP_RAND_settable_ctx_params() return an array of OSSL_PARAMs or NULL on error. EVP_RAND_verify_zeroization() returns 1 if the internal DRBG state is currently zeroed, and 0 if not. diff --git a/doc/man3/OSSL_DECODER.pod b/doc/man3/OSSL_DECODER.pod index c58ebf462c71a..01c69ec147cfb 100644 --- a/doc/man3/OSSL_DECODER.pod +++ b/doc/man3/OSSL_DECODER.pod @@ -86,7 +86,7 @@ I, and for each of the implementations, calls I with the implementation method and I as arguments. OSSL_DECODER_gettable_params() returns an L -array of parameter descriptors. +array of parameter descriptors, NULL on error.. OSSL_DECODER_get_params() attempts to get parameters specified with an L array I. Parameters that the diff --git a/doc/man3/OSSL_ENCODER.pod b/doc/man3/OSSL_ENCODER.pod index d7271547287e1..6692a49de285a 100644 --- a/doc/man3/OSSL_ENCODER.pod +++ b/doc/man3/OSSL_ENCODER.pod @@ -86,7 +86,7 @@ I, and for each of the implementations, calls I with the implementation method and I as arguments. OSSL_ENCODER_gettable_params() returns an L -array of parameter descriptors. +array of parameter descriptors, NULL on error. OSSL_ENCODER_get_params() attempts to get parameters specified with an L array I. Parameters that the diff --git a/include/openssl/decodererr.h b/include/openssl/decodererr.h index 4212a38bca2ad..a2cfe6469399d 100644 --- a/include/openssl/decodererr.h +++ b/include/openssl/decodererr.h @@ -1,6 +1,6 @@ /* * Generated by util/mkerr.pl DO NOT EDIT - * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -23,6 +23,8 @@ */ # define OSSL_DECODER_R_COULD_NOT_DECODE_OBJECT 101 # define OSSL_DECODER_R_DECODER_NOT_FOUND 102 +# define OSSL_DECODER_R_MISSING_GETTABLE_PARAMS 103 # define OSSL_DECODER_R_MISSING_GET_PARAMS 100 +# define OSSL_DECODER_R_MISSING_SETTABLE_CTX_PARAMS 104 #endif diff --git a/include/openssl/encodererr.h b/include/openssl/encodererr.h index 5e318b145370a..f9eead9b36ef6 100644 --- a/include/openssl/encodererr.h +++ b/include/openssl/encodererr.h @@ -1,6 +1,6 @@ /* * Generated by util/mkerr.pl DO NOT EDIT - * Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved. + * Copyright 1995-2023 The OpenSSL Project Authors. All Rights Reserved. * * Licensed under the Apache License 2.0 (the "License"). You may not use * this file except in compliance with the License. You can obtain a copy @@ -23,6 +23,8 @@ */ # define OSSL_ENCODER_R_ENCODER_NOT_FOUND 101 # define OSSL_ENCODER_R_INCORRECT_PROPERTY_QUERY 100 +# define OSSL_ENCODER_R_MISSING_GETTABLE_PARAMS 103 # define OSSL_ENCODER_R_MISSING_GET_PARAMS 102 +# define OSSL_ENCODER_R_MISSING_SETTABLE_CTX_PARAMS 104 #endif diff --git a/include/openssl/evperr.h b/include/openssl/evperr.h index 11f3faa459ed0..c58d05c994c17 100644 --- a/include/openssl/evperr.h +++ b/include/openssl/evperr.h @@ -79,7 +79,12 @@ # define EVP_R_MEMORY_LIMIT_EXCEEDED 172 # define EVP_R_MESSAGE_DIGEST_IS_NULL 159 # define EVP_R_METHOD_NOT_SUPPORTED 144 +# define EVP_R_MISSING_GETTABLE_CTX_PARAMS 226 +# define EVP_R_MISSING_GETTABLE_PARAMS 229 +# define EVP_R_MISSING_GET_CTX_PARAMS 230 # define EVP_R_MISSING_PARAMETERS 103 +# define EVP_R_MISSING_SETTABLE_CTX_PARAMS 228 +# define EVP_R_MISSING_SET_CTX_PARAMS 231 # define EVP_R_NOT_ABLE_TO_COPY_CTX 190 # define EVP_R_NOT_XOF_OR_INVALID_LENGTH 178 # define EVP_R_NO_CIPHER_SET 131