mirror of
https://github.com/openssl/openssl.git
synced 2025-01-18 13:44:20 +08:00
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)
This commit is contained in:
parent
408def8b30
commit
d7ec1dda2e
@ -12,9 +12,6 @@
|
|||||||
#include "prov/digestcommon.h"
|
#include "prov/digestcommon.h"
|
||||||
#include "prov/implementations.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)
|
int ossl_blake2s256_init(void *ctx)
|
||||||
{
|
{
|
||||||
BLAKE2S_PARAM P;
|
BLAKE2S_PARAM P;
|
||||||
|
@ -28,6 +28,7 @@
|
|||||||
* of the functions in the dispatch table are correct.
|
* 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;
|
||||||
|
static OSSL_FUNC_digest_init_fn keccak_init_params;
|
||||||
static OSSL_FUNC_digest_update_fn keccak_update;
|
static OSSL_FUNC_digest_update_fn keccak_update;
|
||||||
static OSSL_FUNC_digest_final_fn keccak_final;
|
static OSSL_FUNC_digest_final_fn keccak_final;
|
||||||
static OSSL_FUNC_digest_freectx_fn keccak_freectx;
|
static OSSL_FUNC_digest_freectx_fn keccak_freectx;
|
||||||
@ -49,7 +50,7 @@ static sha3_final_fn generic_sha3_final;
|
|||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
static int keccak_init(void *vctx)
|
static int keccak_init(void *vctx, ossl_unused const OSSL_PARAM params[])
|
||||||
{
|
{
|
||||||
if (!ossl_prov_is_running())
|
if (!ossl_prov_is_running())
|
||||||
return 0;
|
return 0;
|
||||||
@ -58,6 +59,12 @@ static int keccak_init(void *vctx)
|
|||||||
return 1;
|
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)
|
static int keccak_update(void *vctx, const unsigned char *inp, size_t len)
|
||||||
{
|
{
|
||||||
KECCAK1600_CTX *ctx = vctx;
|
KECCAK1600_CTX *ctx = vctx;
|
||||||
@ -225,7 +232,6 @@ static void *uname##_newctx(void *provctx) \
|
|||||||
PROV_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags) \
|
PROV_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags) \
|
||||||
const OSSL_DISPATCH ossl_##name##_functions[] = { \
|
const OSSL_DISPATCH ossl_##name##_functions[] = { \
|
||||||
{ OSSL_FUNC_DIGEST_NEWCTX, (void (*)(void))name##_newctx }, \
|
{ 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_UPDATE, (void (*)(void))keccak_update }, \
|
||||||
{ OSSL_FUNC_DIGEST_FINAL, (void (*)(void))keccak_final }, \
|
{ OSSL_FUNC_DIGEST_FINAL, (void (*)(void))keccak_final }, \
|
||||||
{ OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))keccak_freectx }, \
|
{ 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) \
|
#define PROV_FUNC_SHA3_DIGEST(name, bitlen, blksize, dgstsize, flags) \
|
||||||
PROV_FUNC_SHA3_DIGEST_COMMON(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
|
PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END
|
||||||
|
|
||||||
#define PROV_FUNC_SHAKE_DIGEST(name, bitlen, blksize, dgstsize, flags) \
|
#define PROV_FUNC_SHAKE_DIGEST(name, bitlen, blksize, dgstsize, flags) \
|
||||||
PROV_FUNC_SHA3_DIGEST_COMMON(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_SET_CTX_PARAMS, (void (*)(void))shake_set_ctx_params }, \
|
||||||
{ OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS, \
|
{ OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS, \
|
||||||
(void (*)(void))shake_settable_ctx_params }, \
|
(void (*)(void))shake_settable_ctx_params }, \
|
||||||
|
@ -36,7 +36,7 @@ static int name##_get_params(OSSL_PARAM params[]) \
|
|||||||
(void (*)(void))ossl_digest_default_gettable_params }
|
(void (*)(void))ossl_digest_default_gettable_params }
|
||||||
|
|
||||||
# define PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START( \
|
# 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_newctx_fn name##_newctx; \
|
||||||
static OSSL_FUNC_digest_freectx_fn name##_freectx; \
|
static OSSL_FUNC_digest_freectx_fn name##_freectx; \
|
||||||
static OSSL_FUNC_digest_dupctx_fn name##_dupctx; \
|
static OSSL_FUNC_digest_dupctx_fn name##_dupctx; \
|
||||||
@ -58,11 +58,6 @@ static void *name##_dupctx(void *ctx) \
|
|||||||
*ret = *in; \
|
*ret = *in; \
|
||||||
return ret; \
|
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 OSSL_FUNC_digest_final_fn name##_internal_final; \
|
||||||
static int name##_internal_final(void *ctx, unsigned char *out, size_t *outl, \
|
static int name##_internal_final(void *ctx, unsigned char *out, size_t *outl, \
|
||||||
size_t outsz) \
|
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) \
|
PROV_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags) \
|
||||||
const OSSL_DISPATCH ossl_##name##_functions[] = { \
|
const OSSL_DISPATCH ossl_##name##_functions[] = { \
|
||||||
{ OSSL_FUNC_DIGEST_NEWCTX, (void (*)(void))name##_newctx }, \
|
{ 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_UPDATE, (void (*)(void))upd }, \
|
||||||
{ OSSL_FUNC_DIGEST_FINAL, (void (*)(void))name##_internal_final }, \
|
{ OSSL_FUNC_DIGEST_FINAL, (void (*)(void))name##_internal_final }, \
|
||||||
{ OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))name##_freectx }, \
|
{ OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))name##_freectx }, \
|
||||||
@ -89,17 +83,32 @@ const OSSL_DISPATCH ossl_##name##_functions[] = { \
|
|||||||
|
|
||||||
# define IMPLEMENT_digest_functions( \
|
# define IMPLEMENT_digest_functions( \
|
||||||
name, CTX, blksize, dgstsize, flags, init, upd, fin) \
|
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, \
|
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
|
PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END
|
||||||
|
|
||||||
# define IMPLEMENT_digest_functions_with_settable_ctx( \
|
# define IMPLEMENT_digest_functions_with_settable_ctx( \
|
||||||
name, CTX, blksize, dgstsize, flags, init, upd, fin, \
|
name, CTX, blksize, dgstsize, flags, init, upd, fin, \
|
||||||
settable_ctx_params, set_ctx_params) \
|
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, \
|
PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \
|
||||||
init, upd, fin), \
|
upd, fin), \
|
||||||
{ OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS, (void (*)(void))settable_ctx_params }, \
|
{ OSSL_FUNC_DIGEST_INIT, (void (*)(void))name##_internal_init }, \
|
||||||
{ OSSL_FUNC_DIGEST_SET_CTX_PARAMS, (void (*)(void))set_ctx_params }, \
|
{ 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
|
PROV_DISPATCH_FUNC_DIGEST_CONSTRUCT_END
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user