From 3d214461bf78d1fdd9b1b69e0555428a3d65030a Mon Sep 17 00:00:00 2001 From: Richard Levitte Date: Tue, 16 Jul 2019 06:05:08 +0200 Subject: [PATCH] Rework the provider digest constructor to provide implementation get_params Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/9391) --- .../common/include/internal/core_mkdigest.h | 63 ++++++++++++------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/providers/common/include/internal/core_mkdigest.h b/providers/common/include/internal/core_mkdigest.h index 7225196d62..8a077aec47 100644 --- a/providers/common/include/internal/core_mkdigest.h +++ b/providers/common/include/internal/core_mkdigest.h @@ -11,6 +11,8 @@ # define OSSL_CORE_MKDIGEST_H # include +# include +# include # ifdef __cplusplus extern "C" { @@ -38,6 +40,24 @@ static void *name##_dupctx(void *ctx) \ return ret; \ } +# define OSSL_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags) \ +static OSSL_OP_digest_get_params_fn name##_get_params; \ +static int name##_get_params(OSSL_PARAM params[]) \ +{ \ + OSSL_PARAM *p = NULL; \ + \ + p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_BLOCK_SIZE); \ + if (p != NULL && !OSSL_PARAM_set_int(p, (blksize))) \ + return 0; \ + p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_SIZE); \ + if (p != NULL && !OSSL_PARAM_set_int(p, (dgstsize))) \ + return 0; \ + p = OSSL_PARAM_locate(params, OSSL_DIGEST_PARAM_FLAGS); \ + if (p != NULL && !OSSL_PARAM_set_ulong(p, (flags))) \ + return 0; \ + return 1; \ +} + # define OSSL_FUNC_DIGEST_SET_FINAL(name, dgstsize, fin) \ static OSSL_OP_digest_final_fn name##_wrapfinal; \ static int name##_wrapfinal(void *ctx, unsigned char *out, size_t *outl, size_t outsz) \ @@ -49,17 +69,7 @@ static int name##_wrapfinal(void *ctx, unsigned char *out, size_t *outl, size_t return 0; \ } -# define OSSL_FUNC_DIGEST_COMMON(name, blksize, dgstsize, init, upd) \ -static OSSL_OP_digest_block_size_fn name##_block_size; \ -static OSSL_OP_digest_size_fn name##_size; \ -static size_t name##_block_size(void) \ -{ \ - return blksize; \ -} \ -static size_t name##_size(void) \ -{ \ - return dgstsize; \ -} \ +# define OSSL_FUNC_DIGEST_COMMON(name, init, upd) \ const OSSL_DISPATCH name##_functions[] = { \ { OSSL_FUNC_DIGEST_NEWCTX, (void (*)(void))name##_newctx }, \ { OSSL_FUNC_DIGEST_INIT, (void (*)(void))init }, \ @@ -67,25 +77,32 @@ const OSSL_DISPATCH name##_functions[] = { \ { OSSL_FUNC_DIGEST_FINAL, (void (*)(void))name##_wrapfinal }, \ { OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))name##_freectx }, \ { OSSL_FUNC_DIGEST_DUPCTX, (void (*)(void))name##_dupctx }, \ - { OSSL_FUNC_DIGEST_SIZE, (void (*)(void))name##_size }, \ - { OSSL_FUNC_DIGEST_BLOCK_SIZE, (void (*)(void))name##_block_size }, - -# define OSSL_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, init, upd, fin) \ -OSSL_FUNC_DIGEST_ALLOC_METHODS(name, CTX) \ -OSSL_FUNC_DIGEST_SET_FINAL(name, dgstsize, fin) \ -OSSL_FUNC_DIGEST_COMMON(name, blksize, dgstsize, init, upd) + { OSSL_FUNC_DIGEST_GET_PARAMS, (void (*)(void))name##_get_params }, # define OSSL_FUNC_DIGEST_CONSTRUCT_END \ { 0, NULL } \ }; -# define OSSL_FUNC_DIGEST_CONSTRUCT(name, CTX, blksize, dgstsize, init, upd, fin) \ -OSSL_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, init, upd, fin) \ +# define OSSL_FUNC_DIGEST_CONSTRUCT_START(name, CTX, \ + blksize, dgstsize, flags, \ + init, upd, fin) \ +OSSL_FUNC_DIGEST_ALLOC_METHODS(name, CTX) \ +OSSL_FUNC_DIGEST_SET_FINAL(name, dgstsize, fin) \ +OSSL_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags) \ +OSSL_FUNC_DIGEST_COMMON(name, init, upd) + +# define OSSL_FUNC_DIGEST_CONSTRUCT(name, CTX, blksize, dgstsize, flags, \ + init, upd, fin) \ +OSSL_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \ + init, upd, fin) \ OSSL_FUNC_DIGEST_CONSTRUCT_END -# define OSSL_FUNC_DIGEST_CONSTRUCT_PARAMS(name, CTX, blksize, dgstsize, init, upd, fin, setparams) \ -OSSL_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, init, upd, fin) \ - { OSSL_FUNC_DIGEST_SET_PARAMS, (void (*)(void))setparams }, \ +# define OSSL_FUNC_DIGEST_CONSTRUCT_PARAMS(name, CTX, \ + blksize, dgstsize, flags, \ + init, upd, fin, setparams) \ +OSSL_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \ + init, upd, fin) \ + { OSSL_FUNC_DIGEST_CTX_SET_PARAMS, (void (*)(void))setparams }, \ OSSL_FUNC_DIGEST_CONSTRUCT_END # ifdef __cplusplus