summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/lib/libcrypto/evp/m_sha1.c82
1 files changed, 54 insertions, 28 deletions
diff --git a/src/lib/libcrypto/evp/m_sha1.c b/src/lib/libcrypto/evp/m_sha1.c
index 16aab86292..92d8c30a8c 100644
--- a/src/lib/libcrypto/evp/m_sha1.c
+++ b/src/lib/libcrypto/evp/m_sha1.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: m_sha1.c,v 1.21 2023/04/09 15:40:09 jsing Exp $ */ 1/* $OpenBSD: m_sha1.c,v 1.22 2023/04/09 15:47:41 jsing Exp $ */
2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
3 * All rights reserved. 3 * All rights reserved.
4 * 4 *
@@ -119,25 +119,20 @@ sha224_init(EVP_MD_CTX *ctx)
119} 119}
120 120
121static int 121static int
122sha256_init(EVP_MD_CTX *ctx) 122sha224_update(EVP_MD_CTX *ctx, const void *data, size_t count)
123{
124 return SHA256_Init(ctx->md_data);
125}
126/*
127 * Even though there're separate SHA224_[Update|Final], we call
128 * SHA256 functions even in SHA224 context. This is what happens
129 * there anyway, so we can spare few CPU cycles:-)
130 */
131static int
132sha256_update(EVP_MD_CTX *ctx, const void *data, size_t count)
133{ 123{
124 /*
125 * Even though there're separate SHA224_[Update|Final], we call
126 * SHA256 functions even in SHA224 context. This is what happens
127 * there anyway, so we can spare few CPU cycles:-)
128 */
134 return SHA256_Update(ctx->md_data, data, count); 129 return SHA256_Update(ctx->md_data, data, count);
135} 130}
136 131
137static int 132static int
138sha256_final(EVP_MD_CTX *ctx, unsigned char *md) 133sha224_final(EVP_MD_CTX *ctx, unsigned char *md)
139{ 134{
140 return SHA256_Final(md, ctx->md_data); 135 return SHA224_Final(md, ctx->md_data);
141} 136}
142 137
143static const EVP_MD sha224_md = { 138static const EVP_MD sha224_md = {
@@ -146,8 +141,8 @@ static const EVP_MD sha224_md = {
146 .md_size = SHA224_DIGEST_LENGTH, 141 .md_size = SHA224_DIGEST_LENGTH,
147 .flags = EVP_MD_FLAG_DIGALGID_ABSENT, 142 .flags = EVP_MD_FLAG_DIGALGID_ABSENT,
148 .init = sha224_init, 143 .init = sha224_init,
149 .update = sha256_update, 144 .update = sha224_update,
150 .final = sha256_final, 145 .final = sha224_final,
151 .copy = NULL, 146 .copy = NULL,
152 .cleanup = NULL, 147 .cleanup = NULL,
153 .block_size = SHA256_CBLOCK, 148 .block_size = SHA256_CBLOCK,
@@ -157,7 +152,25 @@ static const EVP_MD sha224_md = {
157const EVP_MD * 152const EVP_MD *
158EVP_sha224(void) 153EVP_sha224(void)
159{ 154{
160 return (&sha224_md); 155 return &sha224_md;
156}
157
158static int
159sha256_init(EVP_MD_CTX *ctx)
160{
161 return SHA256_Init(ctx->md_data);
162}
163
164static int
165sha256_update(EVP_MD_CTX *ctx, const void *data, size_t count)
166{
167 return SHA256_Update(ctx->md_data, data, count);
168}
169
170static int
171sha256_final(EVP_MD_CTX *ctx, unsigned char *md)
172{
173 return SHA256_Final(md, ctx->md_data);
161} 174}
162 175
163static const EVP_MD sha256_md = { 176static const EVP_MD sha256_md = {
@@ -189,21 +202,16 @@ sha384_init(EVP_MD_CTX *ctx)
189} 202}
190 203
191static int 204static int
192sha512_init(EVP_MD_CTX *ctx) 205sha384_update(EVP_MD_CTX *ctx, const void *data, size_t count)
193{
194 return SHA512_Init(ctx->md_data);
195}
196/* See comment in SHA224/256 section */
197static int
198sha512_update(EVP_MD_CTX *ctx, const void *data, size_t count)
199{ 206{
207 /* See comment in SHA224/256 section */
200 return SHA512_Update(ctx->md_data, data, count); 208 return SHA512_Update(ctx->md_data, data, count);
201} 209}
202 210
203static int 211static int
204sha512_final(EVP_MD_CTX *ctx, unsigned char *md) 212sha384_final(EVP_MD_CTX *ctx, unsigned char *md)
205{ 213{
206 return SHA512_Final(md, ctx->md_data); 214 return SHA384_Final(md, ctx->md_data);
207} 215}
208 216
209static const EVP_MD sha384_md = { 217static const EVP_MD sha384_md = {
@@ -212,8 +220,8 @@ static const EVP_MD sha384_md = {
212 .md_size = SHA384_DIGEST_LENGTH, 220 .md_size = SHA384_DIGEST_LENGTH,
213 .flags = EVP_MD_FLAG_DIGALGID_ABSENT, 221 .flags = EVP_MD_FLAG_DIGALGID_ABSENT,
214 .init = sha384_init, 222 .init = sha384_init,
215 .update = sha512_update, 223 .update = sha384_update,
216 .final = sha512_final, 224 .final = sha384_final,
217 .copy = NULL, 225 .copy = NULL,
218 .cleanup = NULL, 226 .cleanup = NULL,
219 .block_size = SHA512_CBLOCK, 227 .block_size = SHA512_CBLOCK,
@@ -226,6 +234,24 @@ EVP_sha384(void)
226 return &sha384_md; 234 return &sha384_md;
227} 235}
228 236
237static int
238sha512_init(EVP_MD_CTX *ctx)
239{
240 return SHA512_Init(ctx->md_data);
241}
242
243static int
244sha512_update(EVP_MD_CTX *ctx, const void *data, size_t count)
245{
246 return SHA512_Update(ctx->md_data, data, count);
247}
248
249static int
250sha512_final(EVP_MD_CTX *ctx, unsigned char *md)
251{
252 return SHA512_Final(md, ctx->md_data);
253}
254
229static const EVP_MD sha512_md = { 255static const EVP_MD sha512_md = {
230 .type = NID_sha512, 256 .type = NID_sha512,
231 .pkey_type = NID_sha512WithRSAEncryption, 257 .pkey_type = NID_sha512WithRSAEncryption,