gmp: Make sure the modulus is odd and the exponent not zero
Unlike mpz_powm() its secure replacement mpz_powm_sec() has the additional
requirement that the exponent must be > 0 and the modulus has to be odd.
Otherwise, it will crash with a floating-point exception.
Fixes: CVE-2017-9022
Fixes: 3e35a6e7a1 ("Use side-channel secured mpz_powm_sec of libgmp 5, if available")
This commit is contained in:
committed by
Andreas Steffen
parent
89f05ed5a9
commit
6681d98d18
@@ -475,7 +475,7 @@ gmp_rsa_public_key_t *gmp_rsa_public_key_load(key_type_t type, va_list args)
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!e.ptr || !n.ptr)
|
||||
if (!e.len || !n.len || (n.ptr[n.len-1] & 0x01) == 0)
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
@@ -506,5 +506,10 @@ gmp_rsa_public_key_t *gmp_rsa_public_key_load(key_type_t type, va_list args)
|
||||
|
||||
this->k = (mpz_sizeinbase(this->n, 2) + 7) / BITS_PER_BYTE;
|
||||
|
||||
if (!mpz_sgn(this->e))
|
||||
{
|
||||
destroy(this);
|
||||
return NULL;
|
||||
}
|
||||
return &this->public;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user