diff options
author | Richard Levitte <levitte@openssl.org> | 2019-07-16 06:05:08 +0200 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2019-08-12 13:35:18 +0200 |
commit | 3d214461bf78d1fdd9b1b69e0555428a3d65030a (patch) | |
tree | 5e7d8c94819ac806a2479af30b4994c2e18b339a /providers | |
parent | 6a3b7c6887346d37c5771fc1fa755a59add44d0b (diff) |
Rework the provider digest constructor to provide implementation get_params
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/9391)
Diffstat (limited to 'providers')
-rw-r--r-- | providers/common/include/internal/core_mkdigest.h | 63 |
1 files 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 <openssl/core_numbers.h> +# include <openssl/core_names.h> +# include <openssl/params.h> # 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 |