From 9d04f83410ac052aecf7a3031ad20f5237c02014 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Thu, 30 Apr 2015 14:16:07 +0100 Subject: [PATCH] Add DSA digest length checks. Reviewed-by: Ben Laurie --- crypto/dsa/dsa_pmeth.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/crypto/dsa/dsa_pmeth.c b/crypto/dsa/dsa_pmeth.c index 594583ffc8..1adab4f8ec 100644 --- a/crypto/dsa/dsa_pmeth.c +++ b/crypto/dsa/dsa_pmeth.c @@ -125,10 +125,15 @@ static int pkey_dsa_sign(EVP_PKEY_CTX *ctx, unsigned char *sig, DSA_PKEY_CTX *dctx = ctx->data; DSA *dsa = ctx->pkey->pkey.dsa; - if (dctx->md) + if (dctx->md) { + if (tbslen != (size_t)EVP_MD_size(dctx->md)) + return 0; type = EVP_MD_type(dctx->md); - else + } else { + if (tbslen != SHA_DIGEST_LENGTH) + return 0; type = NID_sha1; + } ret = DSA_sign(type, tbs, tbslen, sig, &sltmp, dsa); @@ -146,10 +151,15 @@ static int pkey_dsa_verify(EVP_PKEY_CTX *ctx, DSA_PKEY_CTX *dctx = ctx->data; DSA *dsa = ctx->pkey->pkey.dsa; - if (dctx->md) + if (dctx->md) { + if (tbslen != (size_t)EVP_MD_size(dctx->md)) + return 0; type = EVP_MD_type(dctx->md); - else + } else { + if (tbslen != SHA_DIGEST_LENGTH) + return 0; type = NID_sha1; + } ret = DSA_verify(type, tbs, tbslen, sig, siglen, dsa); -- 2.25.1