digests.c
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 #include <openssl/digest.h>
58 
59 #include <assert.h>
60 #include <string.h>
61 
62 #include <openssl/md4.h>
63 #include <openssl/md5.h>
64 #include <openssl/nid.h>
65 #include <openssl/sha.h>
66 
67 #include "internal.h"
68 #include "../delocate.h"
69 #include "../../internal.h"
70 
71 #if defined(NDEBUG)
72 #define CHECK(x) (void) (x)
73 #else
74 #define CHECK(x) assert(x)
75 #endif
76 
77 
78 static void md4_init(EVP_MD_CTX *ctx) {
79  CHECK(MD4_Init(ctx->md_data));
80 }
81 
82 static void md4_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
83  CHECK(MD4_Update(ctx->md_data, data, count));
84 }
85 
86 static void md4_final(EVP_MD_CTX *ctx, uint8_t *out) {
87  CHECK(MD4_Final(out, ctx->md_data));
88 }
89 
91  out->type = NID_md4;
92  out->md_size = MD4_DIGEST_LENGTH;
93  out->flags = 0;
94  out->init = md4_init;
95  out->update = md4_update;
96  out->final = md4_final;
97  out->block_size = 64;
98  out->ctx_size = sizeof(MD4_CTX);
99 }
100 
101 
102 static void md5_init(EVP_MD_CTX *ctx) {
103  CHECK(MD5_Init(ctx->md_data));
104 }
105 
106 static void md5_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
107  CHECK(MD5_Update(ctx->md_data, data, count));
108 }
109 
110 static void md5_final(EVP_MD_CTX *ctx, uint8_t *out) {
111  CHECK(MD5_Final(out, ctx->md_data));
112 }
113 
115  out->type = NID_md5;
116  out->md_size = MD5_DIGEST_LENGTH;
117  out->flags = 0;
118  out->init = md5_init;
119  out->update = md5_update;
120  out->final = md5_final;
121  out->block_size = 64;
122  out->ctx_size = sizeof(MD5_CTX);
123 }
124 
125 
126 static void sha1_init(EVP_MD_CTX *ctx) {
127  CHECK(SHA1_Init(ctx->md_data));
128 }
129 
130 static void sha1_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
131  CHECK(SHA1_Update(ctx->md_data, data, count));
132 }
133 
134 static void sha1_final(EVP_MD_CTX *ctx, uint8_t *md) {
135  CHECK(SHA1_Final(md, ctx->md_data));
136 }
137 
139  out->type = NID_sha1;
140  out->md_size = SHA_DIGEST_LENGTH;
141  out->flags = 0;
142  out->init = sha1_init;
143  out->update = sha1_update;
144  out->final = sha1_final;
145  out->block_size = 64;
146  out->ctx_size = sizeof(SHA_CTX);
147 }
148 
149 
150 static void sha224_init(EVP_MD_CTX *ctx) {
151  CHECK(SHA224_Init(ctx->md_data));
152 }
153 
154 static void sha224_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
155  CHECK(SHA224_Update(ctx->md_data, data, count));
156 }
157 
159  CHECK(SHA224_Final(md, ctx->md_data));
160 }
161 
163  out->type = NID_sha224;
164  out->md_size = SHA224_DIGEST_LENGTH;
165  out->flags = 0;
166  out->init = sha224_init;
167  out->update = sha224_update;
168  out->final = sha224_final;
169  out->block_size = 64;
170  out->ctx_size = sizeof(SHA256_CTX);
171 }
172 
173 
174 static void sha256_init(EVP_MD_CTX *ctx) {
175  CHECK(SHA256_Init(ctx->md_data));
176 }
177 
178 static void sha256_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
179  CHECK(SHA256_Update(ctx->md_data, data, count));
180 }
181 
183  CHECK(SHA256_Final(md, ctx->md_data));
184 }
185 
187  out->type = NID_sha256;
188  out->md_size = SHA256_DIGEST_LENGTH;
189  out->flags = 0;
190  out->init = sha256_init;
191  out->update = sha256_update;
192  out->final = sha256_final;
193  out->block_size = 64;
194  out->ctx_size = sizeof(SHA256_CTX);
195 }
196 
197 
198 static void sha384_init(EVP_MD_CTX *ctx) {
199  CHECK(SHA384_Init(ctx->md_data));
200 }
201 
202 static void sha384_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
203  CHECK(SHA384_Update(ctx->md_data, data, count));
204 }
205 
207  CHECK(SHA384_Final(md, ctx->md_data));
208 }
209 
211  out->type = NID_sha384;
212  out->md_size = SHA384_DIGEST_LENGTH;
213  out->flags = 0;
214  out->init = sha384_init;
215  out->update = sha384_update;
216  out->final = sha384_final;
217  out->block_size = 128;
218  out->ctx_size = sizeof(SHA512_CTX);
219 }
220 
221 
222 static void sha512_init(EVP_MD_CTX *ctx) {
223  CHECK(SHA512_Init(ctx->md_data));
224 }
225 
226 static void sha512_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
227  CHECK(SHA512_Update(ctx->md_data, data, count));
228 }
229 
231  CHECK(SHA512_Final(md, ctx->md_data));
232 }
233 
235  out->type = NID_sha512;
236  out->md_size = SHA512_DIGEST_LENGTH;
237  out->flags = 0;
238  out->init = sha512_init;
239  out->update = sha512_update;
240  out->final = sha512_final;
241  out->block_size = 128;
242  out->ctx_size = sizeof(SHA512_CTX);
243 }
244 
245 
247  CHECK(SHA512_256_Init(ctx->md_data));
248 }
249 
250 static void sha512_256_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
251  CHECK(SHA512_256_Update(ctx->md_data, data, count));
252 }
253 
255  CHECK(SHA512_256_Final(md, ctx->md_data));
256 }
257 
259  out->type = NID_sha512_256;
260  out->md_size = SHA512_256_DIGEST_LENGTH;
261  out->flags = 0;
262  out->init = sha512_256_init;
263  out->update = sha512_256_update;
264  out->final = sha512_256_final;
265  out->block_size = 128;
266  out->ctx_size = sizeof(SHA512_CTX);
267 }
268 
269 
270 typedef struct {
273 } MD5_SHA1_CTX;
274 
275 static void md5_sha1_init(EVP_MD_CTX *md_ctx) {
276  MD5_SHA1_CTX *ctx = md_ctx->md_data;
277  CHECK(MD5_Init(&ctx->md5) && SHA1_Init(&ctx->sha1));
278 }
279 
280 static void md5_sha1_update(EVP_MD_CTX *md_ctx, const void *data,
281  size_t count) {
282  MD5_SHA1_CTX *ctx = md_ctx->md_data;
283  CHECK(MD5_Update(&ctx->md5, data, count) &&
284  SHA1_Update(&ctx->sha1, data, count));
285 }
286 
287 static void md5_sha1_final(EVP_MD_CTX *md_ctx, uint8_t *out) {
288  MD5_SHA1_CTX *ctx = md_ctx->md_data;
289  CHECK(MD5_Final(out, &ctx->md5) &&
290  SHA1_Final(out + MD5_DIGEST_LENGTH, &ctx->sha1));
291 }
292 
294  out->type = NID_md5_sha1;
296  out->flags = 0;
297  out->init = md5_sha1_init;
298  out->update = md5_sha1_update;
299  out->final = md5_sha1_final;
300  out->block_size = 64;
301  out->ctx_size = sizeof(MD5_SHA1_CTX);
302 }
303 
304 #undef CHECK
md5_update
static void md5_update(EVP_MD_CTX *ctx, const void *data, size_t count)
Definition: digests.c:106
MD4_Final
#define MD4_Final
Definition: boringssl_prefix_symbols.h:1807
NID_md5_sha1
#define NID_md5_sha1
Definition: nid.h:603
SHA1_Update
#define SHA1_Update
Definition: boringssl_prefix_symbols.h:2149
NID_md4
#define NID_md4
Definition: nid.h:1254
EVP_md5_sha1
const OPENSSL_EXPORT EVP_MD * EVP_md5_sha1(void)
md5_init
static void md5_init(EVP_MD_CTX *ctx)
Definition: digests.c:102
gen_build_yaml.out
dictionary out
Definition: src/benchmark/gen_build_yaml.py:24
sha512_256_final
static void sha512_256_final(EVP_MD_CTX *ctx, uint8_t *md)
Definition: digests.c:254
DEFINE_METHOD_FUNCTION
DEFINE_METHOD_FUNCTION(EVP_MD, EVP_md4)
Definition: digests.c:90
MD4_CTX
struct md4_state_st MD4_CTX
Definition: base.h:418
EVP_sha512
const OPENSSL_EXPORT EVP_MD * EVP_sha512(void)
ctx
Definition: benchmark-async.c:30
SHA1_Final
#define SHA1_Final
Definition: boringssl_prefix_symbols.h:2146
MD5_SHA1_CTX::sha1
SHA_CTX sha1
Definition: digests.c:272
MD5_SHA1_CTX
Definition: digests.c:270
env_md_st
Definition: third_party/boringssl-with-bazel/src/crypto/fipsmodule/digest/internal.h:67
md4_final
static void md4_final(EVP_MD_CTX *ctx, uint8_t *out)
Definition: digests.c:86
EVP_sha384
const OPENSSL_EXPORT EVP_MD * EVP_sha384(void)
sha256_init
static void sha256_init(EVP_MD_CTX *ctx)
Definition: digests.c:174
SHA256_CTX
struct sha256_state_st SHA256_CTX
Definition: base.h:429
SHA224_Update
#define SHA224_Update
Definition: boringssl_prefix_symbols.h:2153
string.h
MD4_DIGEST_LENGTH
#define MD4_DIGEST_LENGTH
Definition: md4.h:73
SHA384_Final
#define SHA384_Final
Definition: boringssl_prefix_symbols.h:2161
SHA1_Init
#define SHA1_Init
Definition: boringssl_prefix_symbols.h:2147
md5_state_st
Definition: md5.h:97
SHA512_Update
#define SHA512_Update
Definition: boringssl_prefix_symbols.h:2172
sha224_final
static void sha224_final(EVP_MD_CTX *ctx, uint8_t *md)
Definition: digests.c:158
sha256_final
static void sha256_final(EVP_MD_CTX *ctx, uint8_t *md)
Definition: digests.c:182
sha384_init
static void sha384_init(EVP_MD_CTX *ctx)
Definition: digests.c:198
sha512_init
static void sha512_init(EVP_MD_CTX *ctx)
Definition: digests.c:222
NID_sha384
#define NID_sha384
Definition: nid.h:2998
EVP_sha256
const OPENSSL_EXPORT EVP_MD * EVP_sha256(void)
uint8_t
unsigned char uint8_t
Definition: stdint-msvc2008.h:78
md5_sha1_update
static void md5_sha1_update(EVP_MD_CTX *md_ctx, const void *data, size_t count)
Definition: digests.c:280
SHA512_Init
#define SHA512_Init
Definition: boringssl_prefix_symbols.h:2170
env_md_ctx_st
Definition: digest.h:306
md5_final
static void md5_final(EVP_MD_CTX *ctx, uint8_t *out)
Definition: digests.c:110
SHA384_Init
#define SHA384_Init
Definition: boringssl_prefix_symbols.h:2162
SHA384_DIGEST_LENGTH
#define SHA384_DIGEST_LENGTH
Definition: sha.h:203
MD5_Init
#define MD5_Init
Definition: boringssl_prefix_symbols.h:1813
MD5_SHA1_CTX::md5
MD5_CTX md5
Definition: digests.c:271
NID_sha256
#define NID_sha256
Definition: nid.h:2993
md5_sha1_init
static void md5_sha1_init(EVP_MD_CTX *md_ctx)
Definition: digests.c:275
sha_state_st
Definition: sha.h:99
sha512_final
static void sha512_final(EVP_MD_CTX *ctx, uint8_t *md)
Definition: digests.c:230
sha224_init
static void sha224_init(EVP_MD_CTX *ctx)
Definition: digests.c:150
MD4_Update
#define MD4_Update
Definition: boringssl_prefix_symbols.h:1810
SHA512_Final
#define SHA512_Final
Definition: boringssl_prefix_symbols.h:2169
SHA512_256_Update
#define SHA512_256_Update
Definition: boringssl_prefix_symbols.h:2168
NID_sha512_256
#define NID_sha512_256
Definition: nid.h:4251
sha.h
sha1_final
static void sha1_final(EVP_MD_CTX *ctx, uint8_t *md)
Definition: digests.c:134
sha384_final
static void sha384_final(EVP_MD_CTX *ctx, uint8_t *md)
Definition: digests.c:206
sha256_update
static void sha256_update(EVP_MD_CTX *ctx, const void *data, size_t count)
Definition: digests.c:178
MD5_Update
#define MD5_Update
Definition: boringssl_prefix_symbols.h:1815
SHA512_256_DIGEST_LENGTH
#define SHA512_256_DIGEST_LENGTH
Definition: sha.h:268
SHA224_Init
#define SHA224_Init
Definition: boringssl_prefix_symbols.h:2152
SHA512_DIGEST_LENGTH
#define SHA512_DIGEST_LENGTH
Definition: sha.h:230
data
char data[kBufferLength]
Definition: abseil-cpp/absl/strings/internal/str_format/float_conversion.cc:1006
NID_md5
#define NID_md5
Definition: nid.h:105
NID_sha1
#define NID_sha1
Definition: nid.h:372
sha1_init
static void sha1_init(EVP_MD_CTX *ctx)
Definition: digests.c:126
NID_sha512
#define NID_sha512
Definition: nid.h:3003
sha384_update
static void sha384_update(EVP_MD_CTX *ctx, const void *data, size_t count)
Definition: digests.c:202
SHA512_CTX
struct sha512_state_st SHA512_CTX
Definition: base.h:430
md4_init
static void md4_init(EVP_MD_CTX *ctx)
Definition: digests.c:78
SHA224_Final
#define SHA224_Final
Definition: boringssl_prefix_symbols.h:2151
NID_sha224
#define NID_sha224
Definition: nid.h:3008
MD5_CTX
struct md5_state_st MD5_CTX
Definition: base.h:419
benchmark.md
md
Definition: benchmark.py:86
md4_update
static void md4_update(EVP_MD_CTX *ctx, const void *data, size_t count)
Definition: digests.c:82
nid.h
digest.h
SHA224_DIGEST_LENGTH
#define SHA224_DIGEST_LENGTH
Definition: sha.h:128
sha512_update
static void sha512_update(EVP_MD_CTX *ctx, const void *data, size_t count)
Definition: digests.c:226
md4.h
count
int * count
Definition: bloaty/third_party/googletest/googlemock/test/gmock_stress_test.cc:96
md5.h
CHECK
#define CHECK(x)
Definition: digests.c:74
SHA256_Init
#define SHA256_Init
Definition: boringssl_prefix_symbols.h:2156
MD5_Final
#define MD5_Final
Definition: boringssl_prefix_symbols.h:1812
sha512_256_init
static void sha512_256_init(EVP_MD_CTX *ctx)
Definition: digests.c:246
SHA256_DIGEST_LENGTH
#define SHA256_DIGEST_LENGTH
Definition: sha.h:155
MD5_DIGEST_LENGTH
#define MD5_DIGEST_LENGTH
Definition: md5.h:74
sha1_update
static void sha1_update(EVP_MD_CTX *ctx, const void *data, size_t count)
Definition: digests.c:130
sha512_256_update
static void sha512_256_update(EVP_MD_CTX *ctx, const void *data, size_t count)
Definition: digests.c:250
EVP_sha1
const OPENSSL_EXPORT EVP_MD * EVP_sha1(void)
SHA_DIGEST_LENGTH
#define SHA_DIGEST_LENGTH
Definition: sha.h:74
SHA384_Update
#define SHA384_Update
Definition: boringssl_prefix_symbols.h:2163
md5_sha1_final
static void md5_sha1_final(EVP_MD_CTX *md_ctx, uint8_t *out)
Definition: digests.c:287
env_md_ctx_st::md_data
void * md_data
Definition: digest.h:311
EVP_md4
const OPENSSL_EXPORT EVP_MD * EVP_md4(void)
EVP_md5
const OPENSSL_EXPORT EVP_MD * EVP_md5(void)
SHA_CTX
struct sha_state_st SHA_CTX
Definition: base.h:431
internal.h
MD4_Init
#define MD4_Init
Definition: boringssl_prefix_symbols.h:1808
SHA256_Final
#define SHA256_Final
Definition: boringssl_prefix_symbols.h:2155
EVP_sha512_256
const OPENSSL_EXPORT EVP_MD * EVP_sha512_256(void)
SHA512_256_Init
#define SHA512_256_Init
Definition: boringssl_prefix_symbols.h:2167
SHA512_256_Final
#define SHA512_256_Final
Definition: boringssl_prefix_symbols.h:2166
EVP_sha224
const OPENSSL_EXPORT EVP_MD * EVP_sha224(void)
sha224_update
static void sha224_update(EVP_MD_CTX *ctx, const void *data, size_t count)
Definition: digests.c:154
SHA256_Update
#define SHA256_Update
Definition: boringssl_prefix_symbols.h:2159


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