diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libcrypto/evp/m_sha1.c | 82 |
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 | ||
| 121 | static int | 121 | static int |
| 122 | sha256_init(EVP_MD_CTX *ctx) | 122 | sha224_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 | */ | ||
| 131 | static int | ||
| 132 | sha256_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 | ||
| 137 | static int | 132 | static int |
| 138 | sha256_final(EVP_MD_CTX *ctx, unsigned char *md) | 133 | sha224_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 | ||
| 143 | static const EVP_MD sha224_md = { | 138 | static 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 = { | |||
| 157 | const EVP_MD * | 152 | const EVP_MD * |
| 158 | EVP_sha224(void) | 153 | EVP_sha224(void) |
| 159 | { | 154 | { |
| 160 | return (&sha224_md); | 155 | return &sha224_md; |
| 156 | } | ||
| 157 | |||
| 158 | static int | ||
| 159 | sha256_init(EVP_MD_CTX *ctx) | ||
| 160 | { | ||
| 161 | return SHA256_Init(ctx->md_data); | ||
| 162 | } | ||
| 163 | |||
| 164 | static int | ||
| 165 | sha256_update(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
| 166 | { | ||
| 167 | return SHA256_Update(ctx->md_data, data, count); | ||
| 168 | } | ||
| 169 | |||
| 170 | static int | ||
| 171 | sha256_final(EVP_MD_CTX *ctx, unsigned char *md) | ||
| 172 | { | ||
| 173 | return SHA256_Final(md, ctx->md_data); | ||
| 161 | } | 174 | } |
| 162 | 175 | ||
| 163 | static const EVP_MD sha256_md = { | 176 | static const EVP_MD sha256_md = { |
| @@ -189,21 +202,16 @@ sha384_init(EVP_MD_CTX *ctx) | |||
| 189 | } | 202 | } |
| 190 | 203 | ||
| 191 | static int | 204 | static int |
| 192 | sha512_init(EVP_MD_CTX *ctx) | 205 | sha384_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 */ | ||
| 197 | static int | ||
| 198 | sha512_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 | ||
| 203 | static int | 211 | static int |
| 204 | sha512_final(EVP_MD_CTX *ctx, unsigned char *md) | 212 | sha384_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 | ||
| 209 | static const EVP_MD sha384_md = { | 217 | static 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 | ||
| 237 | static int | ||
| 238 | sha512_init(EVP_MD_CTX *ctx) | ||
| 239 | { | ||
| 240 | return SHA512_Init(ctx->md_data); | ||
| 241 | } | ||
| 242 | |||
| 243 | static int | ||
| 244 | sha512_update(EVP_MD_CTX *ctx, const void *data, size_t count) | ||
| 245 | { | ||
| 246 | return SHA512_Update(ctx->md_data, data, count); | ||
| 247 | } | ||
| 248 | |||
| 249 | static int | ||
| 250 | sha512_final(EVP_MD_CTX *ctx, unsigned char *md) | ||
| 251 | { | ||
| 252 | return SHA512_Final(md, ctx->md_data); | ||
| 253 | } | ||
| 254 | |||
| 229 | static const EVP_MD sha512_md = { | 255 | static const EVP_MD sha512_md = { |
| 230 | .type = NID_sha512, | 256 | .type = NID_sha512, |
| 231 | .pkey_type = NID_sha512WithRSAEncryption, | 257 | .pkey_type = NID_sha512WithRSAEncryption, |
