digest.h
Go to the documentation of this file.
1 /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
2  * All rights reserved.
3  *
4  * This package is an SSL implementation written
5  * by Eric Young (eay@cryptsoft.com).
6  * The implementation was written so as to conform with Netscapes SSL.
7  *
8  * This library is free for commercial and non-commercial use as long as
9  * the following conditions are aheared to. The following conditions
10  * apply to all code found in this distribution, be it the RC4, RSA,
11  * lhash, DES, etc., code; not just the SSL code. The SSL documentation
12  * included with this distribution is covered by the same copyright terms
13  * except that the holder is Tim Hudson (tjh@cryptsoft.com).
14  *
15  * Copyright remains Eric Young's, and as such any Copyright notices in
16  * the code are not to be removed.
17  * If this package is used in a product, Eric Young should be given attribution
18  * as the author of the parts of the library used.
19  * This can be in the form of a textual message at program startup or
20  * in documentation (online or textual) provided with the package.
21  *
22  * Redistribution and use in source and binary forms, with or without
23  * modification, are permitted provided that the following conditions
24  * are met:
25  * 1. Redistributions of source code must retain the copyright
26  * notice, this list of conditions and the following disclaimer.
27  * 2. Redistributions in binary form must reproduce the above copyright
28  * notice, this list of conditions and the following disclaimer in the
29  * documentation and/or other materials provided with the distribution.
30  * 3. All advertising materials mentioning features or use of this software
31  * must display the following acknowledgement:
32  * "This product includes cryptographic software written by
33  * Eric Young (eay@cryptsoft.com)"
34  * The word 'cryptographic' can be left out if the rouines from the library
35  * being used are not cryptographic related :-).
36  * 4. If you include any Windows specific code (or a derivative thereof) from
37  * the apps directory (application code) you must include an acknowledgement:
38  * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
39  *
40  * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
41  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
44  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  *
52  * The licence and distribution terms for any publically available version or
53  * derivative of this code cannot be changed. i.e. this code cannot simply be
54  * copied and put under another distribution licence
55  * [including the GNU Public Licence.] */
56 
57 #ifndef OPENSSL_HEADER_DIGEST_H
58 #define OPENSSL_HEADER_DIGEST_H
59 
60 #include <openssl/base.h>
61 
62 #if defined(__cplusplus)
63 extern "C" {
64 #endif
65 
66 
67 // Digest functions.
68 //
69 // An EVP_MD abstracts the details of a specific hash function allowing code to
70 // deal with the concept of a "hash function" without needing to know exactly
71 // which hash function it is.
72 
73 
74 // Hash algorithms.
75 //
76 // The following functions return |EVP_MD| objects that implement the named hash
77 // function.
78 
79 OPENSSL_EXPORT const EVP_MD *EVP_md4(void);
80 OPENSSL_EXPORT const EVP_MD *EVP_md5(void);
81 OPENSSL_EXPORT const EVP_MD *EVP_sha1(void);
82 OPENSSL_EXPORT const EVP_MD *EVP_sha224(void);
83 OPENSSL_EXPORT const EVP_MD *EVP_sha256(void);
84 OPENSSL_EXPORT const EVP_MD *EVP_sha384(void);
85 OPENSSL_EXPORT const EVP_MD *EVP_sha512(void);
88 
89 // EVP_md5_sha1 is a TLS-specific |EVP_MD| which computes the concatenation of
90 // MD5 and SHA-1, as used in TLS 1.1 and below.
92 
93 // EVP_get_digestbynid returns an |EVP_MD| for the given NID, or NULL if no
94 // such digest is known.
96 
97 // EVP_get_digestbyobj returns an |EVP_MD| for the given |ASN1_OBJECT|, or NULL
98 // if no such digest is known.
100 
101 
102 // Digest contexts.
103 //
104 // An EVP_MD_CTX represents the state of a specific digest operation in
105 // progress.
106 
107 // EVP_MD_CTX_init initialises an, already allocated, |EVP_MD_CTX|. This is the
108 // same as setting the structure to zero.
110 
111 // EVP_MD_CTX_new allocates and initialises a fresh |EVP_MD_CTX| and returns
112 // it, or NULL on allocation failure. The caller must use |EVP_MD_CTX_free| to
113 // release the resulting object.
115 
116 // EVP_MD_CTX_cleanup frees any resources owned by |ctx| and resets it to a
117 // freshly initialised state. It does not free |ctx| itself. It returns one.
119 
120 // EVP_MD_CTX_free calls |EVP_MD_CTX_cleanup| and then frees |ctx| itself.
122 
123 // EVP_MD_CTX_copy_ex sets |out|, which must already be initialised, to be a
124 // copy of |in|. It returns one on success and zero on allocation failure.
126 
127 // EVP_MD_CTX_move sets |out|, which must already be initialised, to the hash
128 // state in |in|. |in| is mutated and left in an empty state.
130 
131 // EVP_MD_CTX_reset calls |EVP_MD_CTX_cleanup| followed by |EVP_MD_CTX_init|. It
132 // returns one.
134 
135 
136 // Digest operations.
137 
138 // EVP_DigestInit_ex configures |ctx|, which must already have been
139 // initialised, for a fresh hashing operation using |type|. It returns one on
140 // success and zero on allocation failure.
142  ENGINE *engine);
143 
144 // EVP_DigestInit acts like |EVP_DigestInit_ex| except that |ctx| is
145 // initialised before use.
147 
148 // EVP_DigestUpdate hashes |len| bytes from |data| into the hashing operation
149 // in |ctx|. It returns one.
151  size_t len);
152 
153 // EVP_MAX_MD_SIZE is the largest digest size supported, in bytes.
154 // Functions that output a digest generally require the buffer have
155 // at least this much space.
156 #define EVP_MAX_MD_SIZE 64 // SHA-512 is the longest so far.
157 
158 // EVP_MAX_MD_BLOCK_SIZE is the largest digest block size supported, in
159 // bytes.
160 #define EVP_MAX_MD_BLOCK_SIZE 128 // SHA-512 is the longest so far.
161 
162 // EVP_DigestFinal_ex finishes the digest in |ctx| and writes the output to
163 // |md_out|. |EVP_MD_CTX_size| bytes are written, which is at most
164 // |EVP_MAX_MD_SIZE|. If |out_size| is not NULL then |*out_size| is set to the
165 // number of bytes written. It returns one. After this call, the hash cannot be
166 // updated or finished again until |EVP_DigestInit_ex| is called to start
167 // another hashing operation.
169  unsigned int *out_size);
170 
171 // EVP_DigestFinal acts like |EVP_DigestFinal_ex| except that
172 // |EVP_MD_CTX_cleanup| is called on |ctx| before returning.
174  unsigned int *out_size);
175 
176 // EVP_Digest performs a complete hashing operation in one call. It hashes |len|
177 // bytes from |data| and writes the digest to |md_out|. |EVP_MD_CTX_size| bytes
178 // are written, which is at most |EVP_MAX_MD_SIZE|. If |out_size| is not NULL
179 // then |*out_size| is set to the number of bytes written. It returns one on
180 // success and zero otherwise.
181 OPENSSL_EXPORT int EVP_Digest(const void *data, size_t len, uint8_t *md_out,
182  unsigned int *md_out_size, const EVP_MD *type,
183  ENGINE *impl);
184 
185 
186 // Digest function accessors.
187 //
188 // These functions allow code to learn details about an abstract hash
189 // function.
190 
191 // EVP_MD_type returns a NID identifying |md|. (For example, |NID_sha256|.)
192 OPENSSL_EXPORT int EVP_MD_type(const EVP_MD *md);
193 
194 // EVP_MD_flags returns the flags for |md|, which is a set of |EVP_MD_FLAG_*|
195 // values, ORed together.
197 
198 // EVP_MD_size returns the digest size of |md|, in bytes.
199 OPENSSL_EXPORT size_t EVP_MD_size(const EVP_MD *md);
200 
201 // EVP_MD_block_size returns the native block-size of |md|, in bytes.
203 
204 // EVP_MD_FLAG_PKEY_DIGEST indicates that the digest function is used with a
205 // specific public key in order to verify signatures. (For example,
206 // EVP_dss1.)
207 #define EVP_MD_FLAG_PKEY_DIGEST 1
208 
209 // EVP_MD_FLAG_DIGALGID_ABSENT indicates that the parameter type in an X.509
210 // DigestAlgorithmIdentifier representing this digest function should be
211 // undefined rather than NULL.
212 #define EVP_MD_FLAG_DIGALGID_ABSENT 2
213 
214 // EVP_MD_FLAG_XOF indicates that the digest is an extensible-output function
215 // (XOF). This flag is defined for compatibility and will never be set in any
216 // |EVP_MD| in BoringSSL.
217 #define EVP_MD_FLAG_XOF 4
218 
219 
220 // Digest operation accessors.
221 
222 // EVP_MD_CTX_md returns the underlying digest function, or NULL if one has not
223 // been set.
225 
226 // EVP_MD_CTX_size returns the digest size of |ctx|, in bytes. It
227 // will crash if a digest hasn't been set on |ctx|.
229 
230 // EVP_MD_CTX_block_size returns the block size of the digest function used by
231 // |ctx|, in bytes. It will crash if a digest hasn't been set on |ctx|.
233 
234 // EVP_MD_CTX_type returns a NID describing the digest function used by |ctx|.
235 // (For example, |NID_sha256|.) It will crash if a digest hasn't been set on
236 // |ctx|.
238 
239 
240 // ASN.1 functions.
241 //
242 // These functions allow code to parse and serialize AlgorithmIdentifiers for
243 // hash functions.
244 
245 // EVP_parse_digest_algorithm parses an AlgorithmIdentifier structure containing
246 // a hash function OID (for example, 2.16.840.1.101.3.4.2.1 is SHA-256) and
247 // advances |cbs|. The parameters field may either be omitted or a NULL. It
248 // returns the digest function or NULL on error.
250 
251 // EVP_marshal_digest_algorithm marshals |md| as an AlgorithmIdentifier
252 // structure and appends the result to |cbb|. It returns one on success and zero
253 // on error.
255 
256 
257 // Deprecated functions.
258 
259 // EVP_MD_CTX_copy sets |out|, which must /not/ be initialised, to be a copy of
260 // |in|. It returns one on success and zero on error.
262 
263 // EVP_add_digest does nothing and returns one. It exists only for
264 // compatibility with OpenSSL.
265 OPENSSL_EXPORT int EVP_add_digest(const EVP_MD *digest);
266 
267 // EVP_get_digestbyname returns an |EVP_MD| given a human readable name in
268 // |name|, or NULL if the name is unknown.
269 OPENSSL_EXPORT const EVP_MD *EVP_get_digestbyname(const char *);
270 
271 // EVP_dss1 returns the value of EVP_sha1(). This was provided by OpenSSL to
272 // specifiy the original DSA signatures, which were fixed to use SHA-1. Note,
273 // however, that attempting to sign or verify DSA signatures with the EVP
274 // interface will always fail.
275 OPENSSL_EXPORT const EVP_MD *EVP_dss1(void);
276 
277 // EVP_MD_CTX_create calls |EVP_MD_CTX_new|.
279 
280 // EVP_MD_CTX_destroy calls |EVP_MD_CTX_free|.
282 
283 // EVP_DigestFinalXOF returns zero and adds an error to the error queue.
284 // BoringSSL does not support any XOF digests.
286  size_t len);
287 
288 // EVP_MD_meth_get_flags calls |EVP_MD_flags|.
290 
291 // EVP_MD_CTX_set_flags does nothing.
293 
294 // EVP_MD_CTX_FLAG_NON_FIPS_ALLOW is meaningless. In OpenSSL it permits non-FIPS
295 // algorithms in FIPS mode. But BoringSSL FIPS mode doesn't prohibit algorithms
296 // (it's up the the caller to use the FIPS module in a fashion compliant with
297 // their needs). Thus this exists only to allow code to compile.
298 #define EVP_MD_CTX_FLAG_NON_FIPS_ALLOW 0
299 
300 // EVP_MD_nid calls |EVP_MD_type|.
301 OPENSSL_EXPORT int EVP_MD_nid(const EVP_MD *md);
302 
303 
304 struct evp_md_pctx_ops;
305 
307  // digest is the underlying digest function, or NULL if not set.
308  const EVP_MD *digest;
309  // md_data points to a block of memory that contains the hash-specific
310  // context.
311  void *md_data;
312 
313  // pctx is an opaque (at this layer) pointer to additional context that
314  // EVP_PKEY functions may store in this object.
316 
317  // pctx_ops, if not NULL, points to a vtable that contains functions to
318  // manipulate |pctx|.
319  const struct evp_md_pctx_ops *pctx_ops;
320 } /* EVP_MD_CTX */;
321 
322 
323 #if defined(__cplusplus)
324 } // extern C
325 
326 #if !defined(BORINGSSL_NO_CXX)
327 extern "C++" {
328 
330 
332 
333 using ScopedEVP_MD_CTX =
334  internal::StackAllocatedMovable<EVP_MD_CTX, int, EVP_MD_CTX_init,
336 
338 
339 } // extern C++
340 #endif
341 
342 #endif
343 
344 #define DIGEST_R_INPUT_NOT_INITIALIZED 100
345 #define DIGEST_R_DECODE_ERROR 101
346 #define DIGEST_R_UNKNOWN_HASH 102
347 
348 #endif // OPENSSL_HEADER_DIGEST_H
EVP_MD_meth_get_flags
OPENSSL_EXPORT uint32_t EVP_MD_meth_get_flags(const EVP_MD *md)
Definition: digest.c:125
EVP_MD_type
OPENSSL_EXPORT int EVP_MD_type(const EVP_MD *md)
Definition: digest.c:69
obj
OPENSSL_EXPORT const ASN1_OBJECT * obj
Definition: x509.h:1671
EVP_md5_sha1
const OPENSSL_EXPORT EVP_MD * EVP_md5_sha1(void)
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
EVP_MD_block_size
OPENSSL_EXPORT size_t EVP_MD_block_size(const EVP_MD *md)
Definition: digest.c:77
EVP_sha512
const OPENSSL_EXPORT EVP_MD * EVP_sha512(void)
cbs_st
Definition: bytestring.h:39
EVP_get_digestbyname
const OPENSSL_EXPORT EVP_MD * EVP_get_digestbyname(const char *)
Definition: digest_extra.c:234
ctx
Definition: benchmark-async.c:30
EVP_DigestFinal_ex
OPENSSL_EXPORT int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, uint8_t *md_out, unsigned int *out_size)
Definition: digest.c:230
EVP_MD_CTX_destroy
OPENSSL_EXPORT void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx)
Definition: digest.c:118
env_md_st
Definition: third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/internal.h:67
EVP_sha384
const OPENSSL_EXPORT EVP_MD * EVP_sha384(void)
EVP_MD_CTX_block_size
OPENSSL_EXPORT size_t EVP_MD_CTX_block_size(const EVP_MD_CTX *ctx)
Definition: digest.c:272
EVP_MD_CTX_move
OPENSSL_EXPORT void EVP_MD_CTX_move(EVP_MD_CTX *out, EVP_MD_CTX *in)
Definition: digest.c:182
EVP_MD_CTX_new
OPENSSL_EXPORT EVP_MD_CTX * EVP_MD_CTX_new(void)
Definition: digest.c:84
EVP_add_digest
OPENSSL_EXPORT int EVP_add_digest(const EVP_MD *digest)
Definition: digest.c:280
EVP_Digest
OPENSSL_EXPORT int EVP_Digest(const void *data, size_t len, uint8_t *md_out, unsigned int *md_out_size, const EVP_MD *type, ENGINE *impl)
Definition: digest.c:246
EVP_get_digestbynid
const OPENSSL_EXPORT EVP_MD * EVP_get_digestbynid(int nid)
Definition: digest_extra.c:108
EVP_get_digestbyobj
const OPENSSL_EXPORT EVP_MD * EVP_get_digestbyobj(const ASN1_OBJECT *obj)
Definition: digest_extra.c:156
cbs
const CBS * cbs
Definition: third_party/boringssl-with-bazel/src/crypto/trust_token/internal.h:107
EVP_sha256
const OPENSSL_EXPORT EVP_MD * EVP_sha256(void)
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
base.h
EVP_MD_CTX_set_flags
OPENSSL_EXPORT void EVP_MD_CTX_set_flags(EVP_MD_CTX *ctx, int flags)
Definition: digest.c:127
EVP_MD_CTX_md
const OPENSSL_EXPORT EVP_MD * EVP_MD_CTX_md(const EVP_MD_CTX *ctx)
Definition: digest.c:261
env_md_ctx_st
Definition: digest.h:306
asn1_object_st
Definition: third_party/boringssl-with-bazel/src/crypto/asn1/internal.h:102
EVP_MD_CTX_cleanup
OPENSSL_EXPORT int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx)
Definition: digest.c:96
uint32_t
unsigned int uint32_t
Definition: stdint-msvc2008.h:80
EVP_dss1
const OPENSSL_EXPORT EVP_MD * EVP_dss1(void)
Definition: dss1.c:18
in
const char * in
Definition: third_party/abseil-cpp/absl/strings/internal/str_format/parser_test.cc:391
EVP_DigestUpdate
OPENSSL_EXPORT int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, size_t len)
Definition: digest.c:225
evp_pkey_ctx_st
Definition: third_party/boringssl-with-bazel/src/crypto/evp/internal.h:182
xds_interop_client.int
int
Definition: xds_interop_client.py:113
EVP_MD_size
OPENSSL_EXPORT size_t EVP_MD_size(const EVP_MD *md)
Definition: digest.c:75
EVP_parse_digest_algorithm
const OPENSSL_EXPORT EVP_MD * EVP_parse_digest_algorithm(CBS *cbs)
Definition: digest_extra.c:168
evp_md_pctx_ops
Definition: third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/internal.h:97
EVP_MD_CTX_size
OPENSSL_EXPORT size_t EVP_MD_CTX_size(const EVP_MD_CTX *ctx)
Definition: digest.c:268
EVP_MD_CTX_free
OPENSSL_EXPORT void EVP_MD_CTX_free(EVP_MD_CTX *ctx)
Definition: digest.c:109
BSSL_NAMESPACE_END
#define BSSL_NAMESPACE_END
Definition: base.h:480
EVP_MD_CTX_reset
OPENSSL_EXPORT int EVP_MD_CTX_reset(EVP_MD_CTX *ctx)
Definition: digest.c:194
EVP_MD_CTX_copy_ex
OPENSSL_EXPORT int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in)
Definition: digest.c:129
EVP_MD_flags
OPENSSL_EXPORT uint32_t EVP_MD_flags(const EVP_MD *md)
Definition: digest.c:73
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
EVP_DigestInit_ex
OPENSSL_EXPORT int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, ENGINE *engine)
Definition: digest.c:200
EVP_MD_CTX_type
OPENSSL_EXPORT int EVP_MD_CTX_type(const EVP_MD_CTX *ctx)
Definition: digest.c:276
EVP_marshal_digest_algorithm
OPENSSL_EXPORT int EVP_marshal_digest_algorithm(CBB *cbb, const EVP_MD *md)
Definition: digest_extra.c:199
nid
int nid
Definition: cipher_extra.c:71
env_md_ctx_st::pctx_ops
const struct evp_md_pctx_ops * pctx_ops
Definition: digest.h:319
absl::out_size
char int out_size
Definition: abseil-cpp/absl/synchronization/mutex.h:1048
benchmark.md
md
Definition: benchmark.py:86
BSSL_NAMESPACE_BEGIN
Definition: trust_token_test.cc:45
absl::flags_internal
Definition: abseil-cpp/absl/flags/commandlineflag.h:40
env_md_ctx_st::pctx
EVP_PKEY_CTX * pctx
Definition: digest.h:315
EVP_DigestFinalXOF
OPENSSL_EXPORT int EVP_DigestFinalXOF(EVP_MD_CTX *ctx, uint8_t *out, size_t len)
Definition: digest.c:120
OPENSSL_EXPORT
#define OPENSSL_EXPORT
Definition: base.h:222
BORINGSSL_MAKE_DELETER
#define BORINGSSL_MAKE_DELETER(type, deleter)
Definition: base.h:506
EVP_sha1
const OPENSSL_EXPORT EVP_MD * EVP_sha1(void)
EVP_DigestInit
OPENSSL_EXPORT int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type)
Definition: digest.c:220
EVP_MD_nid
OPENSSL_EXPORT int EVP_MD_nid(const EVP_MD *md)
Definition: digest.c:71
EVP_DigestFinal
OPENSSL_EXPORT int EVP_DigestFinal(EVP_MD_CTX *ctx, uint8_t *md_out, unsigned int *out_size)
Definition: digest.c:240
engine_st
Definition: engine.c:29
EVP_MD_CTX
struct env_md_ctx_st EVP_MD_CTX
Definition: base.h:402
env_md_ctx_st::md_data
void * md_data
Definition: digest.h:311
EVP_MD_CTX_create
OPENSSL_EXPORT EVP_MD_CTX * EVP_MD_CTX_create(void)
Definition: digest.c:94
EVP_MD_CTX_init
OPENSSL_EXPORT void EVP_MD_CTX_init(EVP_MD_CTX *ctx)
Definition: digest.c:80
EVP_md4
const OPENSSL_EXPORT EVP_MD * EVP_md4(void)
asyncio_get_stats.type
type
Definition: asyncio_get_stats.py:37
len
int len
Definition: abseil-cpp/absl/base/internal/low_level_alloc_test.cc:46
EVP_md5
const OPENSSL_EXPORT EVP_MD * EVP_md5(void)
EVP_sha512_256
const OPENSSL_EXPORT EVP_MD * EVP_sha512_256(void)
EVP_MD_CTX_copy
OPENSSL_EXPORT int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in)
Definition: digest.c:189
EVP_sha224
const OPENSSL_EXPORT EVP_MD * EVP_sha224(void)
EVP_blake2b256
const OPENSSL_EXPORT EVP_MD * EVP_blake2b256(void)
Definition: digest_extra.c:268
env_md_ctx_st::digest
const EVP_MD * digest
Definition: digest.h:308
cbb_st
Definition: bytestring.h:375


grpc
Author(s):
autogenerated on Thu Mar 13 2025 02:59:12