Check input length to pkey_rsa_verify()
authorDr. Stephen Henson <steve@openssl.org>
Thu, 8 Dec 2016 12:16:02 +0000 (12:16 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Sat, 10 Dec 2016 02:53:52 +0000 (02:53 +0000)
Reviewed-by: Rich Salz <rsalz@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/2065)
(cherry picked from commit 71bbc79b7d3b1195a7a7dd5f547d52ddce32d6f0)

Conflicts:
crypto/rsa/rsa_err.c
include/openssl/rsa.h

crypto/rsa/rsa_pmeth.c

index 94db87a0637d1fff7400c3caff850429dc8fffb9..ac583bf60b0181e0013b3b204da6b2965ed4031b 100644 (file)
@@ -373,6 +373,10 @@ static int pkey_rsa_verify(EVP_PKEY_CTX *ctx,
         if (rctx->pad_mode == RSA_PKCS1_PADDING)
             return RSA_verify(EVP_MD_type(rctx->md), tbs, tbslen,
                               sig, siglen, rsa);
+        if (tbslen != (size_t)EVP_MD_size(rctx->md)) {
+            RSAerr(RSA_F_PKEY_RSA_VERIFY, RSA_R_INVALID_DIGEST_LENGTH);
+            return -1;
+        }
         if (rctx->pad_mode == RSA_X931_PADDING) {
             if (pkey_rsa_verifyrecover(ctx, NULL, &rslen, sig, siglen) <= 0)
                 return 0;