Document the provider DIGEST operation
[oweals/openssl.git] / doc / man7 / provider-digest.pod
1 =pod
2
3 =head1 NAME
4
5 provider-digest - The digest library E<lt>-E<gt> provider functions
6
7 =head1 SYNOPSIS
8
9 =for comment multiple includes
10
11  #include <openssl/core_numbers.h>
12  #include <openssl/core_names.h>
13
14  /*
15   * None of these are actual functions, but are displayed like this for
16   * the function signatures for functions that are offered as function
17   * pointers in OSSL_DISPATCH arrays.
18   */
19
20  /* Context management */
21  void *OP_digest_newctx(void *provctx);
22  void OP_digest_freectx(void *dctx);
23  void *OP_digest_dupctx(void *dctx);
24
25  /* Digest generation */
26  int OP_digest_init(void *dctx);
27  int OP_digest_update(void *dctx, const unsigned char *in, size_t inl);
28  int OP_digest_final(void *dctx, unsigned char *out, size_t *outl,
29                      size_t outsz);
30  int OP_digest_digest(void *provctx, const unsigned char *in, size_t inl,
31                       unsigned char *out, size_t *outl, size_t outsz);
32
33  /* Digest parameters */
34  size_t OP_digest_size(void);
35  size_t OP_digest_block_size(void);
36  int OP_digest_set_params(void *dctx, const OSSL_PARAM params[]);
37  int OP_digest_get_params(void *dctx, OSSL_PARAM params[]);
38
39 =head1 DESCRIPTION
40
41 This documentation is primarily aimed at provider authors. See L<provider(7)>
42 for further information.
43
44 The DIGEST operation enables providers to implement digest algorithms and make
45 them available to applications via the API functions L<EVP_DigestInit_ex(3)>,
46 L<EVP_DigestUpdate(3)> and L<EVP_DigestFinal(3)> (and other related functions).
47
48 All "functions" mentioned here are passed as function pointers between
49 F<libcrypto> and the provider in B<OSSL_DISPATCH> arrays via
50 B<OSSL_ALGORITHM> arrays that are returned by the provider's
51 provider_query_operation() function
52 (see L<provider-base(7)/Provider Functions>).
53
54 All these "functions" have a corresponding function type definition
55 named B<OSSL_{name}_fn>, and a helper function to retrieve the
56 function pointer from an B<OSSL_DISPATCH> element named
57 B<OSSL_get_{name}>.
58 For example, the "function" OP_digest_newctx() has these:
59
60  typedef void *(OSSL_OP_digest_newctx_fn)(void *provctx);
61  static ossl_inline OSSL_OP_digest_newctx_fn
62      OSSL_get_OP_digest_newctx(const OSSL_DISPATCH *opf);
63
64 B<OSSL_DISPATCH> arrays are indexed by numbers that are provided as
65 macros in L<openssl-core_numbers.h(7)>, as follows:
66
67  OP_digest_newctx        OSSL_FUNC_DIGEST_NEWCTX
68  OP_digest_freectx       OSSL_FUNC_DIGEST_FREECTX
69  OP_digest_dupctx        OSSL_FUNC_DIGEST_DUPCTX
70
71  OP_digest_init          OSSL_FUNC_DIGEST_INIT
72  OP_digest_update        OSSL_FUNC_DIGEST_UPDATE
73  OP_digest_final         OSSL_FUNC_DIGEST_FINAL
74  OP_digest_digest        OSSL_FUNC_DIGEST_DIGEST
75
76  OP_digest_size          OSSL_FUNC_DIGEST_SIZE
77  OP_digest_block_size    OSSL_FUNC_DIGEST_BLOCK_SIZE
78  OP_digest_set_params    OSSL_FUNC_DIGEST_SET_PARAMS
79  OP_digest_get_params    OSSL_FUNC_DIGEST_GET_PARAMS
80
81 A digest algorithm implementation may not implement all of these functions.
82 In order to be useable all or none of OP_digest_newctx, OP_digest_freectx,
83 OP_digest_init, OP_digest_update and OP_digest_final should be implemented.
84 All other functions are optional.
85
86 =head2 Context Management Functions
87
88 OP_digest_newctx() should create and return a pointer to a provider side
89 structure for holding context information during a digest operation.
90 A pointer to this context will be passed back in a number of the other digest
91 operation function calls.
92 The paramater B<provctx> is the provider context generated during provider
93 initialisation (see L<provider(3)>).
94
95 OP_digest_freectx() is passed a pointer to the provider side digest context in
96 the B<dctx> parameter.
97 This function should free any resources associated with that context.
98
99 OP_digest_dupctx() should duplicate the provider side digest context in the
100 B<dctx> parameter and return the duplicate copy.
101
102 =head2 Digest Generation Functions
103
104 OP_digest_init() initialises a digest operation given a newly created
105 provider side digest context in the B<dctx> paramter.
106
107 OP_digest_update() is called to supply data to be digested as part of a
108 previously initialised digest operation.
109 The B<dctx> parameter contains a pointer to a previously initialised provider
110 side context.
111 OP_digest_update() should digest B<inl> bytes of data at the location pointed to
112 by B<in>.
113 OP_digest_update() may be called multiple times for a single digest operation.
114
115 OP_digest_final() generates a digest started through previous OP_digest_init()
116 and OP_digest_update() calls.
117 The B<dctx> parameter contains a pointer to the provider side context.
118 The digest should be written to B<*out> and the length of the digest to
119 B<*outl>.
120 The digest should not exceed B<outsz> bytes.
121
122 OP_digest_digest() is a "oneshot" digest function.
123 No provider side digest context is used.
124 Instead the provider context that was created during provider initialisation is
125 passed in the B<provctx> parameter (see L<provider(3)>).
126 B<inl> bytes at B<in> should be digested and the result should be stored at
127 B<out>. The length of the digest should be stored in B<*outl> which should not
128 exceed B<outsz> bytes.
129
130 =head2 Digest Parameters
131
132 OP_digest_size() should return the size of the digest.
133
134 OP_digest_block_size() should return the size of the block size of the
135 underlying digest algorithm.
136
137 OP_digest_set_params() set digest parameters associated with the given provider
138 side digest context B<dctx> to B<params>.
139 Any parameter settings are additional to any that were previously set.
140 See L<OSSL_PARAM(3)> for further details on the parameters structure.
141
142 OP_digest_get_params() gets details of currently set parameters values associated
143 with the give provider side digest context B<dctx> and stores them in B<params>.
144 See L<OSSL_PARAM(3)> for further details on the parameters structure.
145
146 Parameters currently recognised by built-in digests are as follows. Not all
147 parametes are relevant to, or are understood by all digests:
148
149 =over 4
150
151 =item B<OSSL_DIGEST_PARAM_XOFLEN> (size_t)
152
153 Sets the digest length for extendable output functions.
154
155 =item B<OSSL_DIGEST_PARAM_SSL3_MS> (octet string)
156
157 This parameter is set by libssl in order to calculate a signature hash for an
158 SSLv3 CertificateVerify message as per RFC6101.
159 It is only set after all handshake messages have already been digested via
160 OP_digest_update() calls.
161 The parameter provides the master secret value to be added to the digest.
162 The digest implementation should calculate the complete digest as per RFC6101
163 section 5.6.8.
164 The next call after setting this parameter will be OP_digest_final().
165 This is only relevant for implementations of SHA1 or MD5_SHA1.
166
167 =item B<OSSL_DIGEST_PARAM_PAD_TYPE> (int)
168
169 Sets the pad type to be used.
170 The only built-in digest that uses this is MDC2.
171 Normally the final MDC2 block is padded with 0s.
172 If the pad type is set to 2 then the final block is padded with 0x80 followed by
173 0s.
174
175 =item B<OSSL_DIGEST_PARAM_MICALG> (utf8 string)
176
177 Gets the digest Message Integrity Check algorithm string.
178 This is used when creating S/MIME multipart/signed messages, as specified in
179 RFC 5751.
180
181 =back
182
183 =head1 RETURN VALUES
184
185 OP_digest_newctx() and OP_digest_dupctx() should return the newly created
186 provider side digest context, or NULL on failure.
187
188 OP_digest_init(), OP_digest_update(), OP_digest_final(), OP_digest_digest(),
189 OP_digest_set_params() and OP_digest_get_params() should return 1 for success or
190 0 on error.
191
192 OP_digest_size() should return the digest size.
193
194 OP_digest_block_size() should return the block size of the underlying digest
195 algorithm.
196
197 =head1 SEE ALSO
198
199 L<provider(7)>
200
201 =head1 HISTORY
202
203 The provider DIGEST interface was introduced in OpenSSL 3.0.
204
205 =head1 COPYRIGHT
206
207 Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
208
209 Licensed under the Apache License 2.0 (the "License").  You may not use
210 this file except in compliance with the License.  You can obtain a copy
211 in the file LICENSE in the source distribution or at
212 L<https://www.openssl.org/source/license.html>.
213
214 =cut