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: 3e35a6e7a1b0 ("Use side-channel secured mpz_powm_sec of libgmp 5, if available")
}
break;
}
- if (!e.ptr || !n.ptr)
+ if (!e.len || !n.len || (n.ptr[n.len-1] & 0x01) == 0)
{
return NULL;
}
this->k = (mpz_sizeinbase(this->n, 2) + 7) / BITS_PER_BYTE;
+ if (!mpz_sgn(this->e))
+ {
+ destroy(this);
+ return NULL;
+ }
return &this->public;
}