hcrypto: fix off-by-one set-bit counting

This commit is contained in:
Nicolas Williams
2019-07-05 13:02:24 -05:00
parent 51aed5d820
commit 8bc5d5af10
2 changed files with 2 additions and 2 deletions

View File

@@ -237,7 +237,7 @@ BN_is_bit_set(const BIGNUM *bn, int bit)
heim_integer *hi = (heim_integer *)bn;
unsigned char *p = hi->data;
if ((bit / 8) > hi->length || hi->length == 0)
if ((bit / 8) >= hi->length || hi->length == 0)
return 0;
return p[hi->length - 1 - (bit / 8)] & is_set[bit % 8];

View File

@@ -305,7 +305,7 @@ DH_check_pubkey(const DH *dh, const BIGNUM *pub_key, int *codes)
unsigned i, n = BN_num_bits(pub_key);
unsigned bits = 0;
for (i = 0; i <= n; i++)
for (i = 0; i < n; i++)
if (BN_is_bit_set(pub_key, i))
bits++;