Add {get,set}table_params() functions for provider digests

Reviewed-by: Matt Caswell <matt@openssl.org>
Reviewed-by: Shane Lontis <shane.lontis@oracle.com>
(Merged from https://github.com/openssl/openssl/pull/9576)
This commit is contained in:
Richard Levitte 2019-08-12 15:03:24 +02:00
parent ad623ec0cb
commit ec02412b54
5 changed files with 97 additions and 15 deletions

View file

@ -19,6 +19,17 @@
#include "internal/sha.h"
static OSSL_OP_digest_ctx_set_params_fn sha1_set_params;
static OSSL_OP_digest_settable_ctx_params_fn sha1_settable_params;
static const OSSL_PARAM known_sha1_ctx_params[] = {
{OSSL_DIGEST_PARAM_SSL3_MS, OSSL_PARAM_OCTET_STRING, NULL, 0, 0},
OSSL_PARAM_END
};
static const OSSL_PARAM *sha1_settable_params(void)
{
return known_sha1_ctx_params;
}
/* Special set_params method for SSL3 */
static int sha1_set_params(void *vctx, const OSSL_PARAM params[])
@ -39,7 +50,7 @@ OSSL_FUNC_DIGEST_CONSTRUCT_PARAMS(sha1, SHA_CTX,
SHA_CBLOCK, SHA_DIGEST_LENGTH,
EVP_MD_FLAG_DIGALGID_ABSENT,
SHA1_Init, SHA1_Update, SHA1_Final,
sha1_set_params)
sha1_settable_params, sha1_set_params)
OSSL_FUNC_DIGEST_CONSTRUCT(sha224, SHA256_CTX,
SHA256_CBLOCK, SHA224_DIGEST_LENGTH,

View file

@ -26,7 +26,8 @@ static OSSL_OP_digest_update_fn keccak_update;
static OSSL_OP_digest_final_fn keccak_final;
static OSSL_OP_digest_freectx_fn keccak_freectx;
static OSSL_OP_digest_dupctx_fn keccak_dupctx;
static OSSL_OP_digest_ctx_set_params_fn shake_set_params;
static OSSL_OP_digest_ctx_set_params_fn shake_ctx_set_params;
static OSSL_OP_digest_settable_ctx_params_fn shake_settable_ctx_params;
static sha3_absorb_fn generic_sha3_absorb;
static sha3_final_fn generic_sha3_final;
@ -203,8 +204,21 @@ static void *uname##_newctx(void *provctx) \
}
#define OSSL_FUNC_SHA3_DIGEST(name, bitlen, blksize, dgstsize, flags, \
stparams) \
stparamtypes, stparams) \
static OSSL_OP_digest_get_params_fn name##_get_params; \
static OSSL_OP_digest_gettable_params_fn name##_gettable_params; \
static const OSSL_PARAM known_##name##_gettable_params[] = { \
{OSSL_DIGEST_PARAM_BLOCK_SIZE, OSSL_PARAM_INTEGER, \
NULL, sizeof(int), 0}, \
{OSSL_DIGEST_PARAM_SIZE, OSSL_PARAM_INTEGER, NULL, sizeof(int), 0}, \
{OSSL_DIGEST_PARAM_FLAGS, OSSL_PARAM_INTEGER, \
NULL, sizeof(unsigned long), 0}, \
OSSL_PARAM_END \
}; \
static const OSSL_PARAM *name##_gettable_params(void) \
{ \
return known_##name##_gettable_params; \
} \
static int name##_get_params(OSSL_PARAM params[]) \
{ \
OSSL_PARAM *p = NULL; \
@ -228,7 +242,11 @@ const OSSL_DISPATCH name##_functions[] = { \
{ OSSL_FUNC_DIGEST_FREECTX, (void (*)(void))keccak_freectx }, \
{ OSSL_FUNC_DIGEST_DUPCTX, (void (*)(void))keccak_dupctx }, \
{ OSSL_FUNC_DIGEST_GET_PARAMS, (void (*)(void))name##_get_params }, \
{ OSSL_FUNC_DIGEST_GETTABLE_PARAMS, \
(void (*)(void))name##_gettable_params }, \
{ OSSL_FUNC_DIGEST_CTX_SET_PARAMS, (void (*)(void))stparams }, \
{ OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS, \
(void (*)(void))stparamtypes }, \
OSSL_FUNC_DIGEST_CONSTRUCT_END
static void keccak_freectx(void *vctx)
@ -247,7 +265,17 @@ static void *keccak_dupctx(void *ctx)
return ret;
}
static int shake_set_params(void *vctx, const OSSL_PARAM params[])
static const OSSL_PARAM known_shake_settable_ctx_params[] = {
{OSSL_DIGEST_PARAM_SSL3_MS, OSSL_PARAM_OCTET_STRING, NULL, 0, 0},
OSSL_PARAM_END
};
static const OSSL_PARAM *shake_settable_ctx_params(void)
{
return known_shake_settable_ctx_params;
}
static int shake_ctx_set_params(void *vctx, const OSSL_PARAM params[])
{
const OSSL_PARAM *p;
KECCAK1600_CTX *ctx = (KECCAK1600_CTX *)vctx;
@ -265,18 +293,20 @@ static int shake_set_params(void *vctx, const OSSL_PARAM params[])
SHA3_newctx(sha3, SHA3_##bitlen, sha3_##bitlen, bitlen, '\x06') \
OSSL_FUNC_SHA3_DIGEST(sha3_##bitlen, bitlen, \
SHA3_BLOCKSIZE(bitlen), SHA3_MDSIZE(bitlen), \
EVP_MD_FLAG_DIGALGID_ABSENT, NULL)
EVP_MD_FLAG_DIGALGID_ABSENT, NULL, NULL)
#define SHAKE(bitlen) \
SHA3_newctx(shake, SHAKE_##bitlen, shake_##bitlen, bitlen, '\x1f') \
OSSL_FUNC_SHA3_DIGEST(shake_##bitlen, bitlen, \
SHA3_BLOCKSIZE(bitlen), SHA3_MDSIZE(bitlen), \
EVP_MD_FLAG_XOF, shake_set_params)
EVP_MD_FLAG_XOF, \
shake_settable_ctx_params, shake_ctx_set_params)
#define KMAC(bitlen) \
KMAC_newctx(keccak_kmac_##bitlen, bitlen, '\x04') \
OSSL_FUNC_SHA3_DIGEST(keccak_kmac_##bitlen, bitlen, \
SHA3_BLOCKSIZE(bitlen), KMAC_MDSIZE(bitlen), \
EVP_MD_FLAG_XOF, shake_set_params)
EVP_MD_FLAG_XOF, \
shake_settable_ctx_params, shake_ctx_set_params)
SHA3(224)
SHA3(256)

View file

@ -42,6 +42,19 @@ static void *name##_dupctx(void *ctx) \
# define OSSL_FUNC_DIGEST_GET_PARAM(name, blksize, dgstsize, flags) \
static OSSL_OP_digest_get_params_fn name##_get_params; \
static OSSL_OP_digest_gettable_params_fn name##_gettable_params; \
static const OSSL_PARAM known_##name##_gettable_params[] = { \
{OSSL_DIGEST_PARAM_BLOCK_SIZE, OSSL_PARAM_INTEGER, \
NULL, sizeof(int), 0}, \
{OSSL_DIGEST_PARAM_SIZE, OSSL_PARAM_INTEGER, NULL, sizeof(int), 0}, \
{OSSL_DIGEST_PARAM_FLAGS, OSSL_PARAM_INTEGER, \
NULL, sizeof(unsigned long), 0}, \
OSSL_PARAM_END \
}; \
static const OSSL_PARAM *name##_gettable_params(void) \
{ \
return known_##name##_gettable_params; \
} \
static int name##_get_params(OSSL_PARAM params[]) \
{ \
OSSL_PARAM *p = NULL; \
@ -77,7 +90,9 @@ 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_GET_PARAMS, (void (*)(void))name##_get_params },
{ OSSL_FUNC_DIGEST_GET_PARAMS, (void (*)(void))name##_get_params }, \
{ OSSL_FUNC_DIGEST_GETTABLE_PARAMS, \
(void (*)(void))name##_gettable_params },
# define OSSL_FUNC_DIGEST_CONSTRUCT_END \
{ 0, NULL } \
@ -99,9 +114,12 @@ OSSL_FUNC_DIGEST_CONSTRUCT_END
# define OSSL_FUNC_DIGEST_CONSTRUCT_PARAMS(name, CTX, \
blksize, dgstsize, flags, \
init, upd, fin, setparams) \
init, upd, fin, \
setparamtypes, setparams) \
OSSL_FUNC_DIGEST_CONSTRUCT_START(name, CTX, blksize, dgstsize, flags, \
init, upd, fin) \
{ OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS, \
(void (*)(void))setparamtypes }, \
{ OSSL_FUNC_DIGEST_CTX_SET_PARAMS, (void (*)(void))setparams }, \
OSSL_FUNC_DIGEST_CONSTRUCT_END

View file

@ -17,10 +17,21 @@
#include "internal/md5_sha1.h"
#include "internal/provider_algs.h"
static OSSL_OP_digest_ctx_set_params_fn md5_sha1_set_params;
static OSSL_OP_digest_ctx_set_params_fn md5_sha1_ctx_set_params;
static OSSL_OP_digest_settable_ctx_params_fn md5_sha1_settable_ctx_params;
static const OSSL_PARAM known_md5_sha1_settable_ctx_params[] = {
{OSSL_DIGEST_PARAM_SSL3_MS, OSSL_PARAM_OCTET_STRING, NULL, 0, 0},
OSSL_PARAM_END
};
static const OSSL_PARAM *md5_sha1_settable_ctx_params(void)
{
return known_md5_sha1_settable_ctx_params;
}
/* Special set_params method for SSL3 */
static int md5_sha1_set_params(void *vctx, const OSSL_PARAM params[])
static int md5_sha1_ctx_set_params(void *vctx, const OSSL_PARAM params[])
{
const OSSL_PARAM *p;
MD5_SHA1_CTX *ctx = (MD5_SHA1_CTX *)vctx;
@ -37,4 +48,5 @@ static int md5_sha1_set_params(void *vctx, const OSSL_PARAM params[])
OSSL_FUNC_DIGEST_CONSTRUCT_PARAMS(md5_sha1, MD5_SHA1_CTX,
MD5_SHA1_CBLOCK, MD5_SHA1_DIGEST_LENGTH, 0,
md5_sha1_init, md5_sha1_update, md5_sha1_final,
md5_sha1_set_params)
md5_sha1_settable_ctx_params,
md5_sha1_ctx_set_params)

View file

@ -15,9 +15,20 @@
#include "internal/core_mkdigest.h"
#include "internal/provider_algs.h"
static OSSL_OP_digest_ctx_set_params_fn mdc2_set_params;
static OSSL_OP_digest_ctx_set_params_fn mdc2_ctx_set_params;
static OSSL_OP_digest_settable_ctx_params_fn mdc2_settable_ctx_params;
static int mdc2_set_params(void *vctx, const OSSL_PARAM params[])
static const OSSL_PARAM known_mdc2_settable_ctx_params[] = {
{OSSL_DIGEST_PARAM_PAD_TYPE, OSSL_PARAM_INTEGER, NULL, sizeof(int), 0},
OSSL_PARAM_END
};
static const OSSL_PARAM *mdc2_settable_ctx_params(void)
{
return known_mdc2_settable_ctx_params;
}
static int mdc2_ctx_set_params(void *vctx, const OSSL_PARAM params[])
{
const OSSL_PARAM *p;
MDC2_CTX *ctx = (MDC2_CTX *)vctx;
@ -34,4 +45,4 @@ static int mdc2_set_params(void *vctx, const OSSL_PARAM params[])
OSSL_FUNC_DIGEST_CONSTRUCT_PARAMS(mdc2, MDC2_CTX,
MDC2_BLOCK, MDC2_DIGEST_LENGTH, 0,
MDC2_Init, MDC2_Update, MDC2_Final,
mdc2_set_params)
mdc2_settable_ctx_params, mdc2_ctx_set_params)