Skip to content

Commit 71573dc

Browse files
davidbenBoringssl LUCI CQ
authored and
Boringssl LUCI CQ
committed
Clean up ECDSA EVP_PKEY_CTRL_MD validation.
We have no EVP_MDs with type NID_ecdsa_with_SHA1 (that's a remnant of the old signature algorithm EVP_MDs). Also there's no sense in calling EVP_MD_type or performing the cast five times. Change-Id: I7ea60d80059420b01341accbadf9854b4c3fd1b8 Reviewed-on: https://boringssl-review.googlesource.com/c/boringssl/+/52685 Reviewed-by: Adam Langley <[email protected]> Commit-Queue: David Benjamin <[email protected]>
1 parent 118a892 commit 71573dc

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

crypto/evp/p_ec.c

+8-8
Original file line numberDiff line numberDiff line change
@@ -179,18 +179,18 @@ static int pkey_ec_ctrl(EVP_PKEY_CTX *ctx, int type, int p1, void *p2) {
179179
EC_PKEY_CTX *dctx = ctx->data;
180180

181181
switch (type) {
182-
case EVP_PKEY_CTRL_MD:
183-
if (EVP_MD_type((const EVP_MD *)p2) != NID_sha1 &&
184-
EVP_MD_type((const EVP_MD *)p2) != NID_ecdsa_with_SHA1 &&
185-
EVP_MD_type((const EVP_MD *)p2) != NID_sha224 &&
186-
EVP_MD_type((const EVP_MD *)p2) != NID_sha256 &&
187-
EVP_MD_type((const EVP_MD *)p2) != NID_sha384 &&
188-
EVP_MD_type((const EVP_MD *)p2) != NID_sha512) {
182+
case EVP_PKEY_CTRL_MD: {
183+
const EVP_MD *md = p2;
184+
int md_type = EVP_MD_type(md);
185+
if (md_type != NID_sha1 && md_type != NID_sha224 &&
186+
md_type != NID_sha256 && md_type != NID_sha384 &&
187+
md_type != NID_sha512) {
189188
OPENSSL_PUT_ERROR(EVP, EVP_R_INVALID_DIGEST_TYPE);
190189
return 0;
191190
}
192-
dctx->md = p2;
191+
dctx->md = md;
193192
return 1;
193+
}
194194

195195
case EVP_PKEY_CTRL_GET_MD:
196196
*(const EVP_MD **)p2 = dctx->md;

0 commit comments

Comments
 (0)