diff options
author | Pauli <ppzgs1@gmail.com> | 2021-03-02 22:42:41 +1000 |
---|---|---|
committer | Pauli <ppzgs1@gmail.com> | 2021-03-12 08:27:11 +1000 |
commit | d7ec1dda2ec543153a7a1602aa8421849d33f9b5 (patch) | |
tree | ec65ad16e3aeaaba818b8abbfd55a118d5a1cd28 /providers | |
parent | 408def8b30756469c1b657b9271832f7c1bdce12 (diff) |
prov: support param argument to digest init calls
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/14383)
Diffstat (limited to 'providers')
-rw-r--r-- | providers/implementations/digests/blake2_prov.c | 3 | ||||
-rw-r--r-- | providers/implementations/digests/sha3_prov.c | 12 | ||||
-rw-r--r-- | providers/implementations/include/prov/digestcommon.h | 31 |
3 files changed, 30 insertions, 16 deletions
diff --git a/providers/implementations/digests/blake2_prov.c b/providers/implementations/digests/blake2_prov.c index 74ff44e6b7..25342eedb8 100644 --- a/providers/implementations/digests/blake2_prov.c +++ b/providers/implementations/digests/blake2_prov.c @@ -12,9 +12,6 @@ #include "prov/digestcommon.h" #include "prov/implementations.h" -OSSL_FUNC_digest_init_fn ossl_blake2s256_init; -OSSL_FUNC_digest_init_fn ossl_blake2b512_init; - int ossl_blake2s256_init(void *ctx) { BLAKE2S_PARAM P; diff --git a/providers/implementations/digests/sha3_prov.c b/providers/implementations/digests/sha3_prov.c index c8c5df41ed..0db6f86be8 100644 --- a/providers/implementations/digests/sha3_prov.c +++ b/providers/implementations/digests/sha3_prov.c @@ -28,6 +28,7 @@ * of the functions in the dispatch table are correct. */ static OSSL_FUNC_digest_init_fn keccak_init; +static OSSL_FUNC_digest_init_fn keccak_init_params; static OSSL_FUNC_digest_update_fn keccak_update; static OSSL_FUNC_digest_final_fn keccak_final; static OSSL_FUNC_digest_freectx_fn keccak_freectx; @@ -49,7 +50,7 @@ static sha3_final_fn generic_sha3_final; #endif -static int keccak_init(void *vctx) +static int keccak_init(void *vctx, ossl_unused const OSSL_PARAM params[]) { if (!ossl_prov_is_running()) return 0; @@ -58,6 +59,12 @@ static int keccak_init(void *vctx) return 1; } +static int keccak_init_params(void *vctx, const OSSL_PARAM params[]) +{ + return keccak_init(vctx, NULL) + && shake_set_ctx_params(vctx, params); +} + static int keccak_update(void *vctx, const unsigned char *inp, size_t len) { KECCAK1600_CTX *ctx = vctx; @@ -225,7 +232,6 @@ static void *uname##_newctx(void *provctx) \ PROV_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags) \ const OSSL_DISPATCH ossl_##name##_functions[] = { \ { OSSL_FUNC_DIGEST_NEWCTX, (void (*)(void))name##_newctx }, \ - { OSSL_FUNC_DIGEST_INIT, (void (*)(void))keccak_init }, \ { OSSL_FUNC_DIGEST_UPDATE, (void (*)(void))keccak_update }, \ { OSSL_FUNC_DIGEST_FINAL, (void (*)(void))keccak_final }, \ { OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))keccak_freectx }, \ @@ -234,10 +240,12 @@ const OSSL_DISPATCH ossl_##name##_functions[] = { \ #define PROV_FUNC_SHA3_DIGEST(name, bitlen, blksize, dgstsize, flags) \ PROV_FUNC_SHA3_DIGEST_COMMON(name, bitlen, blksize, dgstsize, flags), \ + { OSSL_FUNC_DIGEST_INIT, (void (*)(void))keccak_init }, \ PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END #define PROV_FUNC_SHAKE_DIGEST(name, bitlen, blksize, dgstsize, flags) \ PROV_FUNC_SHA3_DIGEST_COMMON(name, bitlen, blksize, dgstsize, flags), \ + { OSSL_FUNC_DIGEST_INIT, (void (*)(void))keccak_init_params }, \ { OSSL_FUNC_DIGEST_SET_CTX_PARAMS, (void (*)(void))shake_set_ctx_params }, \ { OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS, \ (void (*)(void))shake_settable_ctx_params }, \ diff --git a/providers/implementations/include/prov/digestcommon.h b/providers/implementations/include/prov/digestcommon.h index 638fe3d4a4..b0ed83648d 100644 --- a/providers/implementations/include/prov/digestcommon.h +++ b/providers/implementations/include/prov/digestcommon.h @@ -36,7 +36,7 @@ static int name##_get_params(OSSL_PARAM params[]) \ (void (*)(void))ossl_digest_default_gettable_params } # define PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START( \ - name, CTX, blksize, dgstsize, flags, init, upd, fin) \ + name, CTX, blksize, dgstsize, flags, upd, fin) \ static OSSL_FUNC_digest_newctx_fn name##_newctx; \ static OSSL_FUNC_digest_freectx_fn name##_freectx; \ static OSSL_FUNC_digest_dupctx_fn name##_dupctx; \ @@ -58,11 +58,6 @@ static void *name##_dupctx(void *ctx) \ *ret = *in; \ return ret; \ } \ -static OSSL_FUNC_digest_init_fn name##_internal_init; \ -static int name##_internal_init(void *ctx) \ -{ \ - return ossl_prov_is_running() ? init(ctx) : 0; \ -} \ static OSSL_FUNC_digest_final_fn name##_internal_final; \ static int name##_internal_final(void *ctx, unsigned char *out, size_t *outl, \ size_t outsz) \ @@ -76,7 +71,6 @@ static int name##_internal_final(void *ctx, unsigned char *out, size_t *outl, \ PROV_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags) \ const OSSL_DISPATCH ossl_##name##_functions[] = { \ { OSSL_FUNC_DIGEST_NEWCTX, (void (*)(void))name##_newctx }, \ - { OSSL_FUNC_DIGEST_INIT, (void (*)(void))name##_internal_init }, \ { OSSL_FUNC_DIGEST_UPDATE, (void (*)(void))upd }, \ { OSSL_FUNC_DIGEST_FINAL, (void (*)(void))name##_internal_final }, \ { OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))name##_freectx }, \ @@ -89,17 +83,32 @@ const OSSL_DISPATCH ossl_##name##_functions[] = { \ # define IMPLEMENT_digest_functions( \ name, CTX, blksize, dgstsize, flags, init, upd, fin) \ +static OSSL_FUNC_digest_init_fn name##_internal_init; \ +static int name##_internal_init(void *ctx, \ + ossl_unused const OSSL_PARAM params[]) \ +{ \ + return ossl_prov_is_running() && init(ctx); \ +} \ PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \ - init, upd, fin), \ + upd, fin), \ + { OSSL_FUNC_DIGEST_INIT, (void (*)(void))name##_internal_init }, \ PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END # define IMPLEMENT_digest_functions_with_settable_ctx( \ name, CTX, blksize, dgstsize, flags, init, upd, fin, \ settable_ctx_params, set_ctx_params) \ +static OSSL_FUNC_digest_init_fn name##_internal_init; \ +static int name##_internal_init(void *ctx, const OSSL_PARAM params[]) \ +{ \ + return ossl_prov_is_running() \ + && init(ctx) \ + && set_ctx_params(ctx, params); \ +} \ PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \ - init, upd, fin), \ -{ OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS, (void (*)(void))settable_ctx_params }, \ -{ OSSL_FUNC_DIGEST_SET_CTX_PARAMS, (void (*)(void))set_ctx_params }, \ + upd, fin), \ + { OSSL_FUNC_DIGEST_INIT, (void (*)(void))name##_internal_init }, \ + { OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS, (void (*)(void))settable_ctx_params }, \ + { OSSL_FUNC_DIGEST_SET_CTX_PARAMS, (void (*)(void))set_ctx_params }, \ PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END |