BN_num_bits() returns 0 when passed NULL and a negative value on
internal error. The OpenSSL wrappers stored the result in a size_t,
so a 0 return falsely satisfied the bit-length check and a negative
return wrapped to a huge value. Capture the int return, reject
non-positive values, then compare against the limit.
isc_ossl_wrap_rsa_key_bits_leq(EVP_PKEY *pkey, size_t limit) {
const RSA *rsa;
const BIGNUM *ce;
- size_t bits = SIZE_MAX;
REQUIRE(pkey != NULL);
ce = NULL;
RSA_get0_key(rsa, NULL, &ce, NULL);
if (ce != NULL) {
- bits = BN_num_bits(ce);
+ int bits = BN_num_bits(ce);
+
+ return bits > 0 && (size_t)bits <= limit;
}
}
- return bits <= limit;
+ return false;
}
isc_result_t
bool
isc_ossl_wrap_rsa_key_bits_leq(EVP_PKEY *pkey, size_t limit) {
- size_t bits = SIZE_MAX;
BIGNUM *e = NULL;
if (EVP_PKEY_get_bn_param(pkey, OSSL_PKEY_PARAM_RSA_E, &e) == 1) {
- bits = BN_num_bits(e);
+ int bits = BN_num_bits(e);
BN_free(e);
+
+ return bits > 0 && (size_t)bits <= limit;
}
- return bits <= limit;
+ return false;
}
isc_result_t