Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 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. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 72 | |
| 73 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 74 | // Hash algorithms. |
| 75 | // |
| 76 | // The following functions return |EVP_MD| objects that implement the named hash |
| 77 | // function. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 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); |
| 86 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 87 | // EVP_md5_sha1 is a TLS-specific |EVP_MD| which computes the concatenation of |
| 88 | // MD5 and SHA-1, as used in TLS 1.1 and below. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 89 | OPENSSL_EXPORT const EVP_MD *EVP_md5_sha1(void); |
| 90 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 91 | // EVP_get_digestbynid returns an |EVP_MD| for the given NID, or NULL if no |
| 92 | // such digest is known. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 93 | OPENSSL_EXPORT const EVP_MD *EVP_get_digestbynid(int nid); |
| 94 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 95 | // EVP_get_digestbyobj returns an |EVP_MD| for the given |ASN1_OBJECT|, or NULL |
| 96 | // if no such digest is known. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 97 | OPENSSL_EXPORT const EVP_MD *EVP_get_digestbyobj(const ASN1_OBJECT *obj); |
| 98 | |
| 99 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 100 | // Digest contexts. |
| 101 | // |
| 102 | // An EVP_MD_CTX represents the state of a specific digest operation in |
| 103 | // progress. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 104 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 105 | // EVP_MD_CTX_init initialises an, already allocated, |EVP_MD_CTX|. This is the |
| 106 | // same as setting the structure to zero. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 107 | OPENSSL_EXPORT void EVP_MD_CTX_init(EVP_MD_CTX *ctx); |
| 108 | |
Robert Sloan | 4562e9d | 2017-10-02 10:26:51 -0700 | [diff] [blame] | 109 | // EVP_MD_CTX_new allocates and initialises a fresh |EVP_MD_CTX| and returns |
| 110 | // it, or NULL on allocation failure. The caller must use |EVP_MD_CTX_free| to |
| 111 | // release the resulting object. |
| 112 | OPENSSL_EXPORT EVP_MD_CTX *EVP_MD_CTX_new(void); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 113 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 114 | // EVP_MD_CTX_cleanup frees any resources owned by |ctx| and resets it to a |
| 115 | // freshly initialised state. It does not free |ctx| itself. It returns one. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 116 | OPENSSL_EXPORT int EVP_MD_CTX_cleanup(EVP_MD_CTX *ctx); |
| 117 | |
Robert Sloan | 4562e9d | 2017-10-02 10:26:51 -0700 | [diff] [blame] | 118 | // EVP_MD_CTX_free calls |EVP_MD_CTX_cleanup| and then frees |ctx| itself. |
| 119 | OPENSSL_EXPORT void EVP_MD_CTX_free(EVP_MD_CTX *ctx); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 120 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 121 | // EVP_MD_CTX_copy_ex sets |out|, which must already be initialised, to be a |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 122 | // copy of |in|. It returns one on success and zero on allocation failure. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 123 | OPENSSL_EXPORT int EVP_MD_CTX_copy_ex(EVP_MD_CTX *out, const EVP_MD_CTX *in); |
| 124 | |
Adam Vartanian | bfcf3a7 | 2018-08-10 14:55:24 +0100 | [diff] [blame] | 125 | // EVP_MD_CTX_reset calls |EVP_MD_CTX_cleanup| followed by |EVP_MD_CTX_init|. It |
| 126 | // returns one. |
| 127 | OPENSSL_EXPORT int EVP_MD_CTX_reset(EVP_MD_CTX *ctx); |
Robert Sloan | 4562e9d | 2017-10-02 10:26:51 -0700 | [diff] [blame] | 128 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 129 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 130 | // Digest operations. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 131 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 132 | // EVP_DigestInit_ex configures |ctx|, which must already have been |
| 133 | // initialised, for a fresh hashing operation using |type|. It returns one on |
Robert Sloan | d9e572d | 2018-08-27 12:27:00 -0700 | [diff] [blame] | 134 | // success and zero on allocation failure. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 135 | OPENSSL_EXPORT int EVP_DigestInit_ex(EVP_MD_CTX *ctx, const EVP_MD *type, |
| 136 | ENGINE *engine); |
| 137 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 138 | // EVP_DigestInit acts like |EVP_DigestInit_ex| except that |ctx| is |
| 139 | // initialised before use. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 140 | OPENSSL_EXPORT int EVP_DigestInit(EVP_MD_CTX *ctx, const EVP_MD *type); |
| 141 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 142 | // EVP_DigestUpdate hashes |len| bytes from |data| into the hashing operation |
| 143 | // in |ctx|. It returns one. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 144 | OPENSSL_EXPORT int EVP_DigestUpdate(EVP_MD_CTX *ctx, const void *data, |
| 145 | size_t len); |
| 146 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 147 | // EVP_MAX_MD_SIZE is the largest digest size supported, in bytes. |
| 148 | // Functions that output a digest generally require the buffer have |
| 149 | // at least this much space. |
| 150 | #define EVP_MAX_MD_SIZE 64 // SHA-512 is the longest so far. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 151 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 152 | // EVP_MAX_MD_BLOCK_SIZE is the largest digest block size supported, in |
| 153 | // bytes. |
| 154 | #define EVP_MAX_MD_BLOCK_SIZE 128 // SHA-512 is the longest so far. |
David Benjamin | 4969cc9 | 2016-04-22 15:02:23 -0400 | [diff] [blame] | 155 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 156 | // EVP_DigestFinal_ex finishes the digest in |ctx| and writes the output to |
| 157 | // |md_out|. |EVP_MD_CTX_size| bytes are written, which is at most |
| 158 | // |EVP_MAX_MD_SIZE|. If |out_size| is not NULL then |*out_size| is set to the |
| 159 | // number of bytes written. It returns one. After this call, the hash cannot be |
| 160 | // updated or finished again until |EVP_DigestInit_ex| is called to start |
| 161 | // another hashing operation. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 162 | OPENSSL_EXPORT int EVP_DigestFinal_ex(EVP_MD_CTX *ctx, uint8_t *md_out, |
| 163 | unsigned int *out_size); |
| 164 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 165 | // EVP_DigestFinal acts like |EVP_DigestFinal_ex| except that |
| 166 | // |EVP_MD_CTX_cleanup| is called on |ctx| before returning. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 167 | OPENSSL_EXPORT int EVP_DigestFinal(EVP_MD_CTX *ctx, uint8_t *md_out, |
| 168 | unsigned int *out_size); |
| 169 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 170 | // EVP_Digest performs a complete hashing operation in one call. It hashes |len| |
| 171 | // bytes from |data| and writes the digest to |md_out|. |EVP_MD_CTX_size| bytes |
| 172 | // are written, which is at most |EVP_MAX_MD_SIZE|. If |out_size| is not NULL |
| 173 | // then |*out_size| is set to the number of bytes written. It returns one on |
| 174 | // success and zero otherwise. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 175 | OPENSSL_EXPORT int EVP_Digest(const void *data, size_t len, uint8_t *md_out, |
| 176 | unsigned int *md_out_size, const EVP_MD *type, |
| 177 | ENGINE *impl); |
| 178 | |
| 179 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 180 | // Digest function accessors. |
| 181 | // |
| 182 | // These functions allow code to learn details about an abstract hash |
| 183 | // function. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 184 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 185 | // EVP_MD_type returns a NID identifying |md|. (For example, |NID_sha256|.) |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 186 | OPENSSL_EXPORT int EVP_MD_type(const EVP_MD *md); |
| 187 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 188 | // EVP_MD_flags returns the flags for |md|, which is a set of |EVP_MD_FLAG_*| |
| 189 | // values, ORed together. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 190 | OPENSSL_EXPORT uint32_t EVP_MD_flags(const EVP_MD *md); |
| 191 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 192 | // EVP_MD_size returns the digest size of |md|, in bytes. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 193 | OPENSSL_EXPORT size_t EVP_MD_size(const EVP_MD *md); |
| 194 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 195 | // EVP_MD_block_size returns the native block-size of |md|, in bytes. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 196 | OPENSSL_EXPORT size_t EVP_MD_block_size(const EVP_MD *md); |
| 197 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 198 | // EVP_MD_FLAG_PKEY_DIGEST indicates the the digest function is used with a |
| 199 | // specific public key in order to verify signatures. (For example, |
| 200 | // EVP_dss1.) |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 201 | #define EVP_MD_FLAG_PKEY_DIGEST 1 |
| 202 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 203 | // EVP_MD_FLAG_DIGALGID_ABSENT indicates that the parameter type in an X.509 |
| 204 | // DigestAlgorithmIdentifier representing this digest function should be |
| 205 | // undefined rather than NULL. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 206 | #define EVP_MD_FLAG_DIGALGID_ABSENT 2 |
| 207 | |
| 208 | |
Robert Sloan | 4562e9d | 2017-10-02 10:26:51 -0700 | [diff] [blame] | 209 | // Digest operation accessors. |
| 210 | |
| 211 | // EVP_MD_CTX_md returns the underlying digest function, or NULL if one has not |
| 212 | // been set. |
| 213 | OPENSSL_EXPORT const EVP_MD *EVP_MD_CTX_md(const EVP_MD_CTX *ctx); |
| 214 | |
| 215 | // EVP_MD_CTX_size returns the digest size of |ctx|, in bytes. It |
| 216 | // will crash if a digest hasn't been set on |ctx|. |
| 217 | OPENSSL_EXPORT size_t EVP_MD_CTX_size(const EVP_MD_CTX *ctx); |
| 218 | |
| 219 | // EVP_MD_CTX_block_size returns the block size of the digest function used by |
| 220 | // |ctx|, in bytes. It will crash if a digest hasn't been set on |ctx|. |
| 221 | OPENSSL_EXPORT size_t EVP_MD_CTX_block_size(const EVP_MD_CTX *ctx); |
| 222 | |
| 223 | // EVP_MD_CTX_type returns a NID describing the digest function used by |ctx|. |
| 224 | // (For example, |NID_sha256|.) It will crash if a digest hasn't been set on |
| 225 | // |ctx|. |
| 226 | OPENSSL_EXPORT int EVP_MD_CTX_type(const EVP_MD_CTX *ctx); |
| 227 | |
| 228 | |
| 229 | // ASN.1 functions. |
| 230 | // |
| 231 | // These functions allow code to parse and serialize AlgorithmIdentifiers for |
| 232 | // hash functions. |
| 233 | |
| 234 | // EVP_parse_digest_algorithm parses an AlgorithmIdentifier structure containing |
| 235 | // a hash function OID (for example, 2.16.840.1.101.3.4.2.1 is SHA-256) and |
| 236 | // advances |cbs|. The parameters field may either be omitted or a NULL. It |
| 237 | // returns the digest function or NULL on error. |
| 238 | OPENSSL_EXPORT const EVP_MD *EVP_parse_digest_algorithm(CBS *cbs); |
| 239 | |
| 240 | // EVP_marshal_digest_algorithm marshals |md| as an AlgorithmIdentifier |
| 241 | // structure and appends the result to |cbb|. It returns one on success and zero |
| 242 | // on error. |
| 243 | OPENSSL_EXPORT int EVP_marshal_digest_algorithm(CBB *cbb, const EVP_MD *md); |
| 244 | |
| 245 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 246 | // Deprecated functions. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 247 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 248 | // EVP_MD_CTX_copy sets |out|, which must /not/ be initialised, to be a copy of |
| 249 | // |in|. It returns one on success and zero on error. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 250 | OPENSSL_EXPORT int EVP_MD_CTX_copy(EVP_MD_CTX *out, const EVP_MD_CTX *in); |
| 251 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 252 | // EVP_add_digest does nothing and returns one. It exists only for |
| 253 | // compatibility with OpenSSL. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 254 | OPENSSL_EXPORT int EVP_add_digest(const EVP_MD *digest); |
| 255 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 256 | // EVP_get_digestbyname returns an |EVP_MD| given a human readable name in |
| 257 | // |name|, or NULL if the name is unknown. |
Adam Langley | f4e4272 | 2015-06-04 17:45:09 -0700 | [diff] [blame] | 258 | OPENSSL_EXPORT const EVP_MD *EVP_get_digestbyname(const char *); |
| 259 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 260 | // EVP_dss1 returns the value of EVP_sha1(). This was provided by OpenSSL to |
| 261 | // specifiy the original DSA signatures, which were fixed to use SHA-1. Note, |
| 262 | // however, that attempting to sign or verify DSA signatures with the EVP |
| 263 | // interface will always fail. |
David Benjamin | d316cba | 2016-06-02 16:17:39 -0400 | [diff] [blame] | 264 | OPENSSL_EXPORT const EVP_MD *EVP_dss1(void); |
| 265 | |
Robert Sloan | 4562e9d | 2017-10-02 10:26:51 -0700 | [diff] [blame] | 266 | // EVP_MD_CTX_create calls |EVP_MD_CTX_new|. |
| 267 | OPENSSL_EXPORT EVP_MD_CTX *EVP_MD_CTX_create(void); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 268 | |
Robert Sloan | 4562e9d | 2017-10-02 10:26:51 -0700 | [diff] [blame] | 269 | // EVP_MD_CTX_destroy calls |EVP_MD_CTX_free|. |
| 270 | OPENSSL_EXPORT void EVP_MD_CTX_destroy(EVP_MD_CTX *ctx); |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 271 | |
Pete Bentley | 0c61efe | 2019-08-13 09:32:23 +0100 | [diff] [blame^] | 272 | // EVP_DigestFinalXOF returns zero and adds an error to the error queue. |
| 273 | // BoringSSL does not support any XOF digests. |
| 274 | OPENSSL_EXPORT int EVP_DigestFinalXOF(EVP_MD_CTX *ctx, uint8_t *out, |
| 275 | size_t len); |
| 276 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 277 | |
| 278 | struct evp_md_pctx_ops; |
| 279 | |
| 280 | struct env_md_ctx_st { |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 281 | // digest is the underlying digest function, or NULL if not set. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 282 | const EVP_MD *digest; |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 283 | // md_data points to a block of memory that contains the hash-specific |
| 284 | // context. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 285 | void *md_data; |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 286 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 287 | // pctx is an opaque (at this layer) pointer to additional context that |
| 288 | // EVP_PKEY functions may store in this object. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 289 | EVP_PKEY_CTX *pctx; |
| 290 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 291 | // pctx_ops, if not NULL, points to a vtable that contains functions to |
| 292 | // manipulate |pctx|. |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 293 | const struct evp_md_pctx_ops *pctx_ops; |
| 294 | } /* EVP_MD_CTX */; |
| 295 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 296 | |
| 297 | #if defined(__cplusplus) |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 298 | } // extern C |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 299 | |
| 300 | #if !defined(BORINGSSL_NO_CXX) |
| 301 | extern "C++" { |
| 302 | |
Robert Sloan | 726e9d1 | 2018-09-11 11:45:04 -0700 | [diff] [blame] | 303 | BSSL_NAMESPACE_BEGIN |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 304 | |
Robert Sloan | 4562e9d | 2017-10-02 10:26:51 -0700 | [diff] [blame] | 305 | BORINGSSL_MAKE_DELETER(EVP_MD_CTX, EVP_MD_CTX_free) |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 306 | |
| 307 | using ScopedEVP_MD_CTX = |
| 308 | internal::StackAllocated<EVP_MD_CTX, int, EVP_MD_CTX_init, |
| 309 | EVP_MD_CTX_cleanup>; |
| 310 | |
Robert Sloan | 726e9d1 | 2018-09-11 11:45:04 -0700 | [diff] [blame] | 311 | BSSL_NAMESPACE_END |
David Benjamin | f0c4a6c | 2016-08-11 13:26:41 -0400 | [diff] [blame] | 312 | |
| 313 | } // extern C++ |
| 314 | #endif |
| 315 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 316 | #endif |
| 317 | |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 318 | #define DIGEST_R_INPUT_NOT_INITIALIZED 100 |
Robert Sloan | 6d0d00e | 2017-03-27 07:13:07 -0700 | [diff] [blame] | 319 | #define DIGEST_R_DECODE_ERROR 101 |
| 320 | #define DIGEST_R_UNKNOWN_HASH 102 |
Adam Langley | d9e397b | 2015-01-22 14:27:53 -0800 | [diff] [blame] | 321 | |
Robert Sloan | 8f860b1 | 2017-08-28 07:37:06 -0700 | [diff] [blame] | 322 | #endif // OPENSSL_HEADER_DIGEST_H |