From: Richard Levitte Date: Tue, 16 Jul 2019 03:59:50 +0000 (+0200) Subject: Make more use of OSSL_PARAM for digests X-Git-Tag: openssl-3.0.0-alpha1~1630 X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=2893111fc624b33f59ab78ac7333740adac6d00d;p=oweals%2Fopenssl.git Make more use of OSSL_PARAM for digests A lot of the different numbers associated with digests are really algorithm parameters. block size, digest length, that sort of thing. Reviewed-by: Matt Caswell (Merged from https://github.com/openssl/openssl/pull/9391) --- diff --git a/crypto/include/internal/evp_int.h b/crypto/include/internal/evp_int.h index 9d878987bc..cdb5aab87c 100644 --- a/crypto/include/internal/evp_int.h +++ b/crypto/include/internal/evp_int.h @@ -212,10 +212,9 @@ struct evp_md_st { OSSL_OP_digest_digest_fn *digest; OSSL_OP_digest_freectx_fn *freectx; OSSL_OP_digest_dupctx_fn *dupctx; - OSSL_OP_digest_size_fn *size; - OSSL_OP_digest_block_size_fn *dblock_size; - OSSL_OP_digest_set_params_fn *set_params; OSSL_OP_digest_get_params_fn *get_params; + OSSL_OP_digest_ctx_set_params_fn *ctx_set_params; + OSSL_OP_digest_ctx_get_params_fn *ctx_get_params; } /* EVP_MD */ ; diff --git a/doc/man7/provider-digest.pod b/doc/man7/provider-digest.pod index f6c3286528..08428428fa 100644 --- a/doc/man7/provider-digest.pod +++ b/doc/man7/provider-digest.pod @@ -31,10 +31,11 @@ provider-digest - The digest library E-E provider functions unsigned char *out, size_t *outl, size_t outsz); /* Digest parameters */ - size_t OP_digest_size(void); - size_t OP_digest_block_size(void); - int OP_digest_set_params(void *dctx, const OSSL_PARAM params[]); - int OP_digest_get_params(void *dctx, OSSL_PARAM params[]); + int OP_digest_get_params(OSSL_PARAM params[]); + + /* Digest context parameters */ + int OP_digest_ctx_set_params(void *dctx, const OSSL_PARAM params[]); + int OP_digest_ctx_get_params(void *dctx, OSSL_PARAM params[]); =head1 DESCRIPTION @@ -129,18 +130,72 @@ exceed B bytes. =head2 Digest Parameters -OP_digest_size() should return the size of the digest. +OP_digest_get_params() gets details of the algorithm implementation +and stores them in B. +See L for further details on the parameters structure. + +Parameters currently recognised by built-in digests with this function +are as follows. Not all parametes are relevant to, or are understood +by all digests: + +=over 4 + +=item B (int) + +The digest block size. + +=item B (int) + +The digest output size. + +=item B (unsigned long) + +Diverse flags that describe exceptional behaviour for the digest: + +=over 4 + +=item B + +This digest method can only handle one block of input. + +=item B + +This digest method is an extensible-output function (XOF) and supports +setting the B parameter. + +=item B + +When setting up a DigestAlgorithmIdentifier, this flag will have the +parameter set to NULL by default. Use this for PKCS#1. I + +=item B + +When setting up a DigestAlgorithmIdentifier, this flag will have the +parameter be left absent by default. I + +=item B + +Custom DigestAlgorithmIdentifier handling via ctrl, with +B as default. I +Currently unused. + +=back + +=back -OP_digest_block_size() should return the size of the block size of the -underlying digest algorithm. +=head2 Digest Context Parameters -OP_digest_set_params() set digest parameters associated with the given provider -side digest context B to B. +OP_digest_ctx_set_params() sets digest parameters associated with the +given provider side digest context B to B. Any parameter settings are additional to any that were previously set. See L for further details on the parameters structure. -OP_digest_get_params() gets details of currently set parameters values associated -with the give provider side digest context B and stores them in B. +OP_digest_ctx_get_params() gets details of currently set parameters +values associated with the give provider side digest context B +and stores them in B. See L for further details on the parameters structure. Parameters currently recognised by built-in digests are as follows. Not all diff --git a/include/openssl/core_names.h b/include/openssl/core_names.h index d1ba624d65..bf57d15d38 100644 --- a/include/openssl/core_names.h +++ b/include/openssl/core_names.h @@ -55,6 +55,9 @@ extern "C" { #define OSSL_DIGEST_PARAM_SSL3_MS "ssl3-ms" #define OSSL_DIGEST_PARAM_PAD_TYPE "pad_type" #define OSSL_DIGEST_PARAM_MICALG "micalg" +#define OSSL_DIGEST_PARAM_BLOCK_SIZE "blocksize" /* OSSL_PARAM_INTEGER */ +#define OSSL_DIGEST_PARAM_SIZE "size" /* OSSL_PARAM_INTEGER */ +#define OSSL_DIGEST_PARAM_FLAGS "flags" /* OSSL_PARAM_UNSIGNED_INTEGER */ /* PKEY parameters */ /* Diffie-Hellman Parameters */ diff --git a/include/openssl/core_numbers.h b/include/openssl/core_numbers.h index f4c4a61ada..e4d3f5d60f 100644 --- a/include/openssl/core_numbers.h +++ b/include/openssl/core_numbers.h @@ -136,19 +136,18 @@ OSSL_CORE_MAKE_FUNC(const OSSL_ITEM *,provider_get_reason_strings, /* Digests */ -# define OSSL_OP_DIGEST 1 - -# define OSSL_FUNC_DIGEST_NEWCTX 1 -# define OSSL_FUNC_DIGEST_INIT 2 -# define OSSL_FUNC_DIGEST_UPDATE 3 -# define OSSL_FUNC_DIGEST_FINAL 4 -# define OSSL_FUNC_DIGEST_DIGEST 5 -# define OSSL_FUNC_DIGEST_FREECTX 6 -# define OSSL_FUNC_DIGEST_DUPCTX 7 -# define OSSL_FUNC_DIGEST_SIZE 8 -# define OSSL_FUNC_DIGEST_BLOCK_SIZE 9 -# define OSSL_FUNC_DIGEST_SET_PARAMS 10 -# define OSSL_FUNC_DIGEST_GET_PARAMS 11 +# define OSSL_OP_DIGEST 1 + +# define OSSL_FUNC_DIGEST_NEWCTX 1 +# define OSSL_FUNC_DIGEST_INIT 2 +# define OSSL_FUNC_DIGEST_UPDATE 3 +# define OSSL_FUNC_DIGEST_FINAL 4 +# define OSSL_FUNC_DIGEST_DIGEST 5 +# define OSSL_FUNC_DIGEST_FREECTX 6 +# define OSSL_FUNC_DIGEST_DUPCTX 7 +# define OSSL_FUNC_DIGEST_GET_PARAMS 8 +# define OSSL_FUNC_DIGEST_CTX_SET_PARAMS 9 +# define OSSL_FUNC_DIGEST_CTX_GET_PARAMS 10 OSSL_CORE_MAKE_FUNC(void *, OP_digest_newctx, (void *provctx)) OSSL_CORE_MAKE_FUNC(int, OP_digest_init, (void *dctx)) @@ -164,12 +163,11 @@ OSSL_CORE_MAKE_FUNC(int, OP_digest_digest, OSSL_CORE_MAKE_FUNC(void, OP_digest_freectx, (void *dctx)) OSSL_CORE_MAKE_FUNC(void *, OP_digest_dupctx, (void *dctx)) -OSSL_CORE_MAKE_FUNC(size_t, OP_digest_size, (void)) -OSSL_CORE_MAKE_FUNC(size_t, OP_digest_block_size, (void)) -OSSL_CORE_MAKE_FUNC(int, OP_digest_set_params, - (void *dctx, const OSSL_PARAM params[])) -OSSL_CORE_MAKE_FUNC(int, OP_digest_get_params, - (void *dctx, OSSL_PARAM params[])) +OSSL_CORE_MAKE_FUNC(int, OP_digest_get_params, (OSSL_PARAM params[])) +OSSL_CORE_MAKE_FUNC(int, OP_digest_ctx_set_params, + (void *vctx, const OSSL_PARAM params[])) +OSSL_CORE_MAKE_FUNC(int, OP_digest_ctx_get_params, + (void *vctx, OSSL_PARAM params[])) /* Symmetric Ciphers */