summaryrefslogtreecommitdiffstats
path: root/crypto
diff options
context:
space:
mode:
authorBernd Edlinger <bernd.edlinger@hotmail.de>2019-09-06 23:38:49 +0200
committerBernd Edlinger <bernd.edlinger@hotmail.de>2019-09-09 14:43:57 +0200
commitfeeb7ecd2f272e1c195e51cefc0d6b0199fef1d0 (patch)
tree55d374b46d9a18051f2243f8944d20568c9cd490 /crypto
parentUniform TEST_*() check usage in test/ectest.c (diff)
downloadopenssl-feeb7ecd2f272e1c195e51cefc0d6b0199fef1d0.tar.xz
openssl-feeb7ecd2f272e1c195e51cefc0d6b0199fef1d0.zip
Check the DH modulus bit length
The check was missing in DH_check and DH_check_params. [extended tests] Reviewed-by: Paul Dale <paul.dale@oracle.com> (Merged from https://github.com/openssl/openssl/pull/9796)
Diffstat (limited to 'crypto')
-rw-r--r--crypto/dh/dh_check.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/crypto/dh/dh_check.c b/crypto/dh/dh_check.c
index aff7e37181..373110d263 100644
--- a/crypto/dh/dh_check.c
+++ b/crypto/dh/dh_check.c
@@ -31,6 +31,10 @@ int DH_check_params_ex(const DH *dh)
DHerr(DH_F_DH_CHECK_PARAMS_EX, DH_R_CHECK_P_NOT_PRIME);
if ((errflags & DH_NOT_SUITABLE_GENERATOR) != 0)
DHerr(DH_F_DH_CHECK_PARAMS_EX, DH_R_NOT_SUITABLE_GENERATOR);
+ if ((errflags & DH_MODULUS_TOO_SMALL) != 0)
+ DHerr(DH_F_DH_CHECK_PARAMS_EX, DH_R_MODULUS_TOO_SMALL);
+ if ((errflags & DH_MODULUS_TOO_LARGE) != 0)
+ DHerr(DH_F_DH_CHECK_PARAMS_EX, DH_R_MODULUS_TOO_LARGE);
return errflags == 0;
}
@@ -58,6 +62,10 @@ int DH_check_params(const DH *dh, int *ret)
goto err;
if (BN_cmp(dh->g, tmp) >= 0)
*ret |= DH_NOT_SUITABLE_GENERATOR;
+ if (BN_num_bits(dh->p) < DH_MIN_MODULUS_BITS)
+ *ret |= DH_MODULUS_TOO_SMALL;
+ if (BN_num_bits(dh->p) > OPENSSL_DH_MAX_MODULUS_BITS)
+ *ret |= DH_MODULUS_TOO_LARGE;
ok = 1;
err:
@@ -91,6 +99,10 @@ int DH_check_ex(const DH *dh)
DHerr(DH_F_DH_CHECK_EX, DH_R_CHECK_P_NOT_PRIME);
if ((errflags & DH_CHECK_P_NOT_SAFE_PRIME) != 0)
DHerr(DH_F_DH_CHECK_EX, DH_R_CHECK_P_NOT_SAFE_PRIME);
+ if ((errflags & DH_MODULUS_TOO_SMALL) != 0)
+ DHerr(DH_F_DH_CHECK_EX, DH_R_MODULUS_TOO_SMALL);
+ if ((errflags & DH_MODULUS_TOO_LARGE) != 0)
+ DHerr(DH_F_DH_CHECK_EX, DH_R_MODULUS_TOO_LARGE);
return errflags == 0;
}