Coverage Report

Created: 2024-11-21 07:03

/src/boringssl/crypto/fipsmodule/digest/digests.c.inc
Line
Count
Source
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/nid.h>
63
64
#include "internal.h"
65
#include "../delocate.h"
66
#include "../../internal.h"
67
68
#if defined(NDEBUG)
69
#define CHECK(x) (void) (x)
70
#else
71
#define CHECK(x) assert(x)
72
#endif
73
74
75
16.6k
static void sha1_init(EVP_MD_CTX *ctx) {
76
16.6k
  BCM_sha1_init(ctx->md_data);
77
16.6k
}
78
79
35.8k
static void sha1_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
80
35.8k
  BCM_sha1_update(ctx->md_data, data, count);
81
35.8k
}
82
83
19.4k
static void sha1_final(EVP_MD_CTX *ctx, uint8_t *md) {
84
19.4k
  BCM_sha1_final(md, ctx->md_data);
85
19.4k
}
86
87
2
DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha1) {
88
2
  out->type = NID_sha1;
89
2
  out->md_size = BCM_SHA_DIGEST_LENGTH;
90
2
  out->flags = 0;
91
2
  out->init = sha1_init;
92
2
  out->update = sha1_update;
93
2
  out->final = sha1_final;
94
2
  out->block_size = 64;
95
2
  out->ctx_size = sizeof(SHA_CTX);
96
2
}
97
98
99
234
static void sha224_init(EVP_MD_CTX *ctx) {
100
234
  BCM_sha224_init(ctx->md_data);
101
234
}
102
103
11.8k
static void sha224_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
104
11.8k
  BCM_sha224_update(ctx->md_data, data, count);
105
11.8k
}
106
107
2.27k
static void sha224_final(EVP_MD_CTX *ctx, uint8_t *md) {
108
2.27k
  BCM_sha224_final(md, ctx->md_data);
109
2.27k
}
110
111
2
DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha224) {
112
2
  out->type = NID_sha224;
113
2
  out->md_size = BCM_SHA224_DIGEST_LENGTH;
114
2
  out->flags = 0;
115
2
  out->init = sha224_init;
116
2
  out->update = sha224_update;
117
2
  out->final = sha224_final;
118
2
  out->block_size = 64;
119
2
  out->ctx_size = sizeof(SHA256_CTX);
120
2
}
121
122
123
779
static void sha256_init(EVP_MD_CTX *ctx) {
124
779
  BCM_sha256_init(ctx->md_data);
125
779
}
126
127
30.6k
static void sha256_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
128
30.6k
  BCM_sha256_update(ctx->md_data, data, count);
129
30.6k
}
130
131
12.4k
static void sha256_final(EVP_MD_CTX *ctx, uint8_t *md) {
132
12.4k
  BCM_sha256_final(md, ctx->md_data);
133
12.4k
}
134
135
2
DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha256) {
136
2
  out->type = NID_sha256;
137
2
  out->md_size = BCM_SHA256_DIGEST_LENGTH;
138
2
  out->flags = 0;
139
2
  out->init = sha256_init;
140
2
  out->update = sha256_update;
141
2
  out->final = sha256_final;
142
2
  out->block_size = 64;
143
2
  out->ctx_size = sizeof(SHA256_CTX);
144
2
}
145
146
147
277
static void sha384_init(EVP_MD_CTX *ctx) {
148
277
  BCM_sha384_init(ctx->md_data);
149
277
}
150
151
7.65k
static void sha384_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
152
7.65k
  BCM_sha384_update(ctx->md_data, data, count);
153
7.65k
}
154
155
2.13k
static void sha384_final(EVP_MD_CTX *ctx, uint8_t *md) {
156
2.13k
  BCM_sha384_final(md, ctx->md_data);
157
2.13k
}
158
159
2
DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha384) {
160
2
  out->type = NID_sha384;
161
2
  out->md_size = BCM_SHA384_DIGEST_LENGTH;
162
2
  out->flags = 0;
163
2
  out->init = sha384_init;
164
2
  out->update = sha384_update;
165
2
  out->final = sha384_final;
166
2
  out->block_size = 128;
167
2
  out->ctx_size = sizeof(SHA512_CTX);
168
2
}
169
170
171
345
static void sha512_init(EVP_MD_CTX *ctx) {
172
345
  BCM_sha512_init(ctx->md_data);
173
345
}
174
175
18.9k
static void sha512_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
176
18.9k
  BCM_sha512_update(ctx->md_data, data, count);
177
18.9k
}
178
179
2.66k
static void sha512_final(EVP_MD_CTX *ctx, uint8_t *md) {
180
2.66k
  BCM_sha512_final(md, ctx->md_data);
181
2.66k
}
182
183
2
DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha512) {
184
2
  out->type = NID_sha512;
185
2
  out->md_size = BCM_SHA512_DIGEST_LENGTH;
186
2
  out->flags = 0;
187
2
  out->init = sha512_init;
188
2
  out->update = sha512_update;
189
2
  out->final = sha512_final;
190
2
  out->block_size = 128;
191
2
  out->ctx_size = sizeof(SHA512_CTX);
192
2
}
193
194
195
77
static void sha512_256_init(EVP_MD_CTX *ctx) {
196
77
  BCM_sha512_256_init(ctx->md_data);
197
77
}
198
199
7.42k
static void sha512_256_update(EVP_MD_CTX *ctx, const void *data, size_t count) {
200
7.42k
  BCM_sha512_256_update(ctx->md_data, data, count);
201
7.42k
}
202
203
821
static void sha512_256_final(EVP_MD_CTX *ctx, uint8_t *md) {
204
821
  BCM_sha512_256_final(md, ctx->md_data);
205
821
}
206
207
2
DEFINE_METHOD_FUNCTION(EVP_MD, EVP_sha512_256) {
208
2
  out->type = NID_sha512_256;
209
2
  out->md_size = BCM_SHA512_256_DIGEST_LENGTH;
210
2
  out->flags = 0;
211
2
  out->init = sha512_256_init;
212
2
  out->update = sha512_256_update;
213
2
  out->final = sha512_256_final;
214
2
  out->block_size = 128;
215
2
  out->ctx_size = sizeof(SHA512_CTX);
216
2
}
217
218
#undef CHECK