1PROVIDER-DIGEST(7ossl)              OpenSSL             PROVIDER-DIGEST(7ossl)
2
3
4

NAME

6       provider-digest - The digest library <-> provider functions
7

SYNOPSIS

9        #include <openssl/core_dispatch.h>
10        #include <openssl/core_names.h>
11
12        /*
13         * Digests support the following function signatures in OSSL_DISPATCH arrays.
14         * (The function signatures are not actual functions).
15         */
16
17        /* Context management */
18        void *OSSL_FUNC_digest_newctx(void *provctx);
19        void OSSL_FUNC_digest_freectx(void *dctx);
20        void *OSSL_FUNC_digest_dupctx(void *dctx);
21
22        /* Digest generation */
23        int OSSL_FUNC_digest_init(void *dctx, const OSSL_PARAM params[]);
24        int OSSL_FUNC_digest_update(void *dctx, const unsigned char *in, size_t inl);
25        int OSSL_FUNC_digest_final(void *dctx, unsigned char *out, size_t *outl,
26                                   size_t outsz);
27        int OSSL_FUNC_digest_digest(void *provctx, const unsigned char *in, size_t inl,
28                                    unsigned char *out, size_t *outl, size_t outsz);
29
30        /* Digest parameter descriptors */
31        const OSSL_PARAM *OSSL_FUNC_digest_gettable_params(void *provctx);
32
33        /* Digest operation parameter descriptors */
34        const OSSL_PARAM *OSSL_FUNC_digest_gettable_ctx_params(void *dctx,
35                                                               void *provctx);
36        const OSSL_PARAM *OSSL_FUNC_digest_settable_ctx_params(void *dctx,
37                                                               void *provctx);
38
39        /* Digest parameters */
40        int OSSL_FUNC_digest_get_params(OSSL_PARAM params[]);
41
42        /* Digest operation parameters */
43        int OSSL_FUNC_digest_set_ctx_params(void *dctx, const OSSL_PARAM params[]);
44        int OSSL_FUNC_digest_get_ctx_params(void *dctx, OSSL_PARAM params[]);
45

DESCRIPTION

47       This documentation is primarily aimed at provider authors. See
48       provider(7) for further information.
49
50       The DIGEST operation enables providers to implement digest algorithms
51       and make them available to applications via the API functions
52       EVP_DigestInit_ex(3), EVP_DigestUpdate(3) and EVP_DigestFinal(3) (and
53       other related functions).
54
55       All "functions" mentioned here are passed as function pointers between
56       libcrypto and the provider in OSSL_DISPATCH arrays via OSSL_ALGORITHM
57       arrays that are returned by the provider's provider_query_operation()
58       function (see "Provider Functions" in provider-base(7)).
59
60       All these "functions" have a corresponding function type definition
61       named OSSL_FUNC_{name}_fn, and a helper function to retrieve the
62       function pointer from an OSSL_DISPATCH element named OSSL_FUNC_{name}.
63       For example, the "function" OSSL_FUNC_digest_newctx() has these:
64
65        typedef void *(OSSL_FUNC_digest_newctx_fn)(void *provctx);
66        static ossl_inline OSSL_FUNC_digest_newctx_fn
67            OSSL_FUNC_digest_newctx(const OSSL_DISPATCH *opf);
68
69       OSSL_DISPATCH arrays are indexed by numbers that are provided as macros
70       in openssl-core_dispatch.h(7), as follows:
71
72        OSSL_FUNC_digest_newctx               OSSL_FUNC_DIGEST_NEWCTX
73        OSSL_FUNC_digest_freectx              OSSL_FUNC_DIGEST_FREECTX
74        OSSL_FUNC_digest_dupctx               OSSL_FUNC_DIGEST_DUPCTX
75
76        OSSL_FUNC_digest_init                 OSSL_FUNC_DIGEST_INIT
77        OSSL_FUNC_digest_update               OSSL_FUNC_DIGEST_UPDATE
78        OSSL_FUNC_digest_final                OSSL_FUNC_DIGEST_FINAL
79        OSSL_FUNC_digest_digest               OSSL_FUNC_DIGEST_DIGEST
80
81        OSSL_FUNC_digest_get_params           OSSL_FUNC_DIGEST_GET_PARAMS
82        OSSL_FUNC_digest_get_ctx_params       OSSL_FUNC_DIGEST_GET_CTX_PARAMS
83        OSSL_FUNC_digest_set_ctx_params       OSSL_FUNC_DIGEST_SET_CTX_PARAMS
84
85        OSSL_FUNC_digest_gettable_params      OSSL_FUNC_DIGEST_GETTABLE_PARAMS
86        OSSL_FUNC_digest_gettable_ctx_params  OSSL_FUNC_DIGEST_GETTABLE_CTX_PARAMS
87        OSSL_FUNC_digest_settable_ctx_params  OSSL_FUNC_DIGEST_SETTABLE_CTX_PARAMS
88
89       A digest algorithm implementation may not implement all of these
90       functions.  In order to be usable all or none of
91       OSSL_FUNC_digest_newctx, OSSL_FUNC_digest_freectx,
92       OSSL_FUNC_digest_init, OSSL_FUNC_digest_update and
93       OSSL_FUNC_digest_final should be implemented.  All other functions are
94       optional.
95
96   Context Management Functions
97       OSSL_FUNC_digest_newctx() should create and return a pointer to a
98       provider side structure for holding context information during a digest
99       operation.  A pointer to this context will be passed back in a number
100       of the other digest operation function calls.  The parameter provctx is
101       the provider context generated during provider initialisation (see
102       provider(7)).
103
104       OSSL_FUNC_digest_freectx() is passed a pointer to the provider side
105       digest context in the dctx parameter.  This function should free any
106       resources associated with that context.
107
108       OSSL_FUNC_digest_dupctx() should duplicate the provider side digest
109       context in the dctx parameter and return the duplicate copy.
110
111   Digest Generation Functions
112       OSSL_FUNC_digest_init() initialises a digest operation given a newly
113       created provider side digest context in the dctx parameter.  The
114       params, if not NULL, should be set on the context in a manner similar
115       to using OSSL_FUNC_digest_set_ctx_params().
116
117       OSSL_FUNC_digest_update() is called to supply data to be digested as
118       part of a previously initialised digest operation.  The dctx parameter
119       contains a pointer to a previously initialised provider side context.
120       OSSL_FUNC_digest_update() should digest inl bytes of data at the
121       location pointed to by in.  OSSL_FUNC_digest_update() may be called
122       multiple times for a single digest operation.
123
124       OSSL_FUNC_digest_final() generates a digest started through previous
125       OSSL_FUNC_digest_init() and OSSL_FUNC_digest_update() calls.  The dctx
126       parameter contains a pointer to the provider side context.  The digest
127       should be written to *out and the length of the digest to *outl.  The
128       digest should not exceed outsz bytes.
129
130       OSSL_FUNC_digest_digest() is a "oneshot" digest function.  No provider
131       side digest context is used.  Instead the provider context that was
132       created during provider initialisation is passed in the provctx
133       parameter (see provider(7)).  inl bytes at in should be digested and
134       the result should be stored at out. The length of the digest should be
135       stored in *outl which should not exceed outsz bytes.
136
137   Digest Parameters
138       See OSSL_PARAM(3) for further details on the parameters structure used
139       by these functions.
140
141       OSSL_FUNC_digest_get_params() gets details of the algorithm
142       implementation and stores them in params.
143
144       OSSL_FUNC_digest_set_ctx_params() sets digest operation parameters for
145       the provider side digest context dctx to params.  Any parameter
146       settings are additional to any that were previously set.  Passing NULL
147       for params should return true.
148
149       OSSL_FUNC_digest_get_ctx_params() gets digest operation details details
150       from the given provider side digest context dctx and stores them in
151       params.  Passing NULL for params should return true.
152
153       OSSL_FUNC_digest_gettable_params() returns a constant OSSL_PARAM array
154       containing descriptors of the parameters that
155       OSSL_FUNC_digest_get_params() can handle.
156
157       OSSL_FUNC_digest_gettable_ctx_params() and
158       OSSL_FUNC_digest_settable_ctx_params() both return constant OSSL_PARAM
159       arrays as descriptors of the parameters that
160       OSSL_FUNC_digest_get_ctx_params() and OSSL_FUNC_digest_set_ctx_params()
161       can handle, respectively.  The array is based on the current state of
162       the provider side context if dctx is not NULL and on the provider side
163       algorithm provctx otherwise.
164
165       Parameters currently recognised by built-in digests with this function
166       are as follows. Not all parameters are relevant to, or are understood
167       by all digests:
168
169       "blocksize" (OSSL_DIGEST_PARAM_BLOCK_SIZE) <unsigned integer>
170           The digest block size.  The length of the "blocksize" parameter
171           should not exceed that of a size_t.
172
173       "size" (OSSL_DIGEST_PARAM_SIZE) <unsigned integer>
174           The digest output size.  The length of the "size" parameter should
175           not exceed that of a size_t.
176
177       "flags" (OSSL_DIGEST_PARAM_FLAGS) <unsigned integer>
178           Diverse flags that describe exceptional behaviour for the digest:
179
180           EVP_MD_FLAG_ONESHOT
181               This digest method can only handle one block of input.
182
183           EVP_MD_FLAG_XOF
184               This digest method is an extensible-output function (XOF) and
185               supports setting the OSSL_DIGEST_PARAM_XOFLEN parameter.
186
187           EVP_MD_FLAG_DIGALGID_NULL
188               When setting up a DigestAlgorithmIdentifier, this flag will
189               have the parameter set to NULL by default.  Use this for
190               PKCS#1.  Note: if combined with EVP_MD_FLAG_DIGALGID_ABSENT,
191               the latter will override.
192
193           EVP_MD_FLAG_DIGALGID_ABSENT
194               When setting up a DigestAlgorithmIdentifier, this flag will
195               have the parameter be left absent by default.  Note: if
196               combined with EVP_MD_FLAG_DIGALGID_NULL, the latter will be
197               overridden.
198
199           EVP_MD_FLAG_DIGALGID_CUSTOM
200               Custom DigestAlgorithmIdentifier handling via ctrl, with
201               EVP_MD_FLAG_DIGALGID_ABSENT as default.  Note: if combined with
202               EVP_MD_FLAG_DIGALGID_NULL, the latter will be overridden.
203               Currently unused.
204
205           The length of the "flags" parameter should equal that of an
206           unsigned long int.
207
208   Digest Context Parameters
209       OSSL_FUNC_digest_set_ctx_params() sets digest parameters associated
210       with the given provider side digest context dctx to params.  Any
211       parameter settings are additional to any that were previously set.  See
212       OSSL_PARAM(3) for further details on the parameters structure.
213
214       OSSL_FUNC_digest_get_ctx_params() gets details of currently set
215       parameters values associated with the give provider side digest context
216       dctx and stores them in params.  See OSSL_PARAM(3) for further details
217       on the parameters structure.
218

RETURN VALUES

220       OSSL_FUNC_digest_newctx() and OSSL_FUNC_digest_dupctx() should return
221       the newly created provider side digest context, or NULL on failure.
222
223       OSSL_FUNC_digest_init(), OSSL_FUNC_digest_update(),
224       OSSL_FUNC_digest_final(), OSSL_FUNC_digest_digest(),
225       OSSL_FUNC_digest_set_params() and OSSL_FUNC_digest_get_params() should
226       return 1 for success or 0 on error.
227
228       OSSL_FUNC_digest_size() should return the digest size.
229
230       OSSL_FUNC_digest_block_size() should return the block size of the
231       underlying digest algorithm.
232

BUGS

234       The EVP_Q_digest(), EVP_Digest() and EVP_DigestFinal_ex() API calls do
235       not expect the digest size to be larger than EVP_MAX_MD_SIZE. Any
236       algorithm which produces larger digests is unusable with those API
237       calls.
238

SEE ALSO

240       provider(7), OSSL_PROVIDER-FIPS(7), OSSL_PROVIDER-default(7),
241       OSSL_PROVIDER-legacy(7), EVP_MD-common(7), EVP_MD-BLAKE2(7),
242       EVP_MD-MD2(7), EVP_MD-MD4(7), EVP_MD-MD5(7), EVP_MD-MD5-SHA1(7),
243       EVP_MD-MDC2(7), EVP_MD-RIPEMD160(7), EVP_MD-SHA1(7), EVP_MD-SHA2(7),
244       EVP_MD-SHA3(7), EVP_MD-SHAKE(7), EVP_MD-SM3(7), EVP_MD-WHIRLPOOL(7),
245       life_cycle-digest(7), EVP_DigestInit(3)
246

HISTORY

248       The provider DIGEST interface was introduced in OpenSSL 3.0.
249
251       Copyright 2019-2022 The OpenSSL Project Authors. All Rights Reserved.
252
253       Licensed under the Apache License 2.0 (the "License").  You may not use
254       this file except in compliance with the License.  You can obtain a copy
255       in the file LICENSE in the source distribution or at
256       <https://www.openssl.org/source/license.html>.
257
258
259
2603.0.5                             2022-11-01            PROVIDER-DIGEST(7ossl)
Impressum