Skip to content

Commit

Permalink
bn/bn_gf2m.c: avoid infinite loop wich malformed ECParamters.
Browse files Browse the repository at this point in the history
CVE-2015-1788

Reviewed-by: Matt Caswell <matt@openssl.org>
  • Loading branch information
Andy Polyakov committed Jun 11, 2015
1 parent 59302b6 commit 4924b37
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions crypto/bn/bn_gf2m.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,9 +691,10 @@ int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
}
# else
{
int i, ubits = BN_num_bits(u), vbits = BN_num_bits(v), /* v is copy
* of p */
top = p->top;
int i;
int ubits = BN_num_bits(u);
int vbits = BN_num_bits(v); /* v is copy of p */
int top = p->top;
BN_ULONG *udp, *bdp, *vdp, *cdp;

bn_wexpand(u, top);
Expand Down Expand Up @@ -737,8 +738,12 @@ int BN_GF2m_mod_inv(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
ubits--;
}

if (ubits <= BN_BITS2 && udp[0] == 1)
break;
if (ubits <= BN_BITS2) {
if (udp[0] == 0) /* poly was reducible */
goto err;
if (udp[0] == 1)
break;
}

if (ubits < vbits) {
i = ubits;
Expand Down

0 comments on commit 4924b37

Please sign in to comment.