* in the file LICENSE in the source distribution or at
* https://www.openssl.org/source/license.html
*/
+{-
+use OpenSSL::paramnames qw(produce_param_decoder);
+-}
#include <string.h>
#include <openssl/core_names.h>
#include <openssl/params.h>
#include <openssl/err.h>
#include <openssl/proverr.h>
+#include "internal/cryptlib.h"
#include "internal/numbers.h"
#include "internal/sha3.h"
#include "prov/digestcommon.h"
return ret;
}
+{- produce_param_decoder('shake_get_ctx_params',
+ (['DIGEST_PARAM_XOFLEN', 'xoflen', 'size_t'],
+ ['DIGEST_PARAM_SIZE', 'size', 'size_t'],
+ )); -}
+
static const OSSL_PARAM *shake_gettable_ctx_params(ossl_unused void *ctx,
ossl_unused void *provctx)
{
- static const OSSL_PARAM known_shake_gettable_ctx_params[] = {
- {OSSL_DIGEST_PARAM_XOFLEN, OSSL_PARAM_UNSIGNED_INTEGER, NULL, 0, 0},
- {OSSL_DIGEST_PARAM_SIZE, OSSL_PARAM_UNSIGNED_INTEGER, NULL, 0, 0},
- OSSL_PARAM_END
- };
- return known_shake_gettable_ctx_params;
+ return shake_get_ctx_params_list;
}
static int shake_get_ctx_params(void *vctx, OSSL_PARAM params[])
{
- OSSL_PARAM *p;
+ struct shake_get_ctx_params_st p;
KECCAK1600_CTX *ctx = (KECCAK1600_CTX *)vctx;
- if (ctx == NULL)
+ if (ctx == NULL || !shake_get_ctx_params_decoder(params, &p))
return 0;
- if (ossl_param_is_empty(params))
- return 1;
- p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_XOFLEN);
- if (p != NULL && !OSSL_PARAM_set_size_t(p, ctx->md_size)) {
+ if (p.xoflen != NULL && !OSSL_PARAM_set_size_t(p.xoflen, ctx->md_size)) {
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
return 0;
}
- /* Size is an alias of xoflen */
- p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_SIZE);
- if (p != NULL && !OSSL_PARAM_set_size_t(p, ctx->md_size)) {
+ /* Size is an alias of xoflen but separate them for compatibility */
+ if (p.size != NULL && !OSSL_PARAM_set_size_t(p.size, ctx->md_size)) {
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
return 0;
}
return 1;
}
+{- produce_param_decoder('shake_set_ctx_params',
+ (['DIGEST_PARAM_XOFLEN', 'xoflen', 'size_t'],
+ ['DIGEST_PARAM_SIZE', 'xoflen', 'size_t'],
+ )); -}
+
static const OSSL_PARAM *shake_settable_ctx_params(ossl_unused void *ctx,
ossl_unused void *provctx)
{
- static const OSSL_PARAM known_shake_settable_ctx_params[] = {
- {OSSL_DIGEST_PARAM_XOFLEN, OSSL_PARAM_UNSIGNED_INTEGER, NULL, 0, 0},
- {OSSL_DIGEST_PARAM_SIZE, OSSL_PARAM_UNSIGNED_INTEGER, NULL, 0, 0},
- OSSL_PARAM_END
- };
-
- return known_shake_settable_ctx_params;
+ return shake_set_ctx_params_list;
}
static int shake_set_ctx_params(void *vctx, const OSSL_PARAM params[])
{
- const OSSL_PARAM *p;
+ struct shake_set_ctx_params_st p;
KECCAK1600_CTX *ctx = (KECCAK1600_CTX *)vctx;
- if (ossl_unlikely(ctx == NULL))
+ if (ossl_unlikely(ctx == NULL || !shake_set_ctx_params_decoder(params, &p)))
return 0;
- if (ossl_param_is_empty(params))
- return 1;
-
- p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_XOFLEN);
- if (ossl_unlikely(p == NULL))
- p = OSSL_PARAM_locate_const(params, OSSL_DIGEST_PARAM_SIZE);
- if (ossl_unlikely(p != NULL && !OSSL_PARAM_get_size_t(p, &ctx->md_size))) {
+ if (ossl_unlikely(p.xoflen != NULL
+ && !OSSL_PARAM_get_size_t(p.xoflen, &ctx->md_size))) {
ERR_raise(ERR_LIB_PROV, PROV_R_FAILED_TO_GET_PARAMETER);
return 0;
}