#include "dst_parse.h"
#include "openssl_shim.h"
-#define OPENSSLRSA_MAX_MODULUS_BITS 4096
-#define OPENSSLRSA_MIN_MODULUS_BITS 512
+constexpr int rsa_max_modulus_bits = 4096;
+constexpr int rsa_min_modulus_bits = 512;
+constexpr unsigned int rsa_max_modulus_bytes = (rsa_max_modulus_bits + 7) / 8;
+constexpr unsigned int rsa_max_exponent_bytes = 5; /* 2^32 + 1 */
static BIGNUM *rsa_exponent_min = NULL;
static BIGNUM *rsa_exponent_max = NULL;
evp_md_ctx = dctx->ctxdata.evp_md_ctx;
pkey = key->keydata.pkeypair.pub;
- if (!isc_ossl_wrap_rsa_modulus_bits_in_range(
- pkey, OPENSSLRSA_MIN_MODULUS_BITS,
- OPENSSLRSA_MAX_MODULUS_BITS) ||
+ if (!isc_ossl_wrap_rsa_modulus_bits_in_range(pkey, rsa_min_modulus_bits,
+ rsa_max_modulus_bits) ||
!isc_ossl_wrap_rsa_exponent_is_allowed(pkey))
{
return DST_R_VERIFYFAILURE;
if (r.length < e_bytes) {
CLEANUP(DST_R_INVALIDPUBLICKEY);
}
+ if (e_bytes > rsa_max_exponent_bytes ||
+ r.length - e_bytes > rsa_max_modulus_bytes)
+ {
+ CLEANUP(ISC_R_RANGE);
+ }
c.e = BN_bin2bn(r.base, e_bytes, NULL);
isc_region_consume(&r, e_bytes);
c.n = BN_bin2bn(r.base, r.length, NULL);
if (c.e == NULL || c.n == NULL) {
CLEANUP(ISC_R_NOMEMORY);
}
- if (BN_num_bits(c.n) < OPENSSLRSA_MIN_MODULUS_BITS ||
- BN_num_bits(c.n) > OPENSSLRSA_MAX_MODULUS_BITS)
+ if (BN_num_bits(c.n) < rsa_min_modulus_bits ||
+ BN_num_bits(c.n) > rsa_max_modulus_bits)
{
CLEANUP(ISC_R_RANGE);
}
if (c.n == NULL || c.e == NULL) {
CLEANUP(DST_R_INVALIDPRIVATEKEY);
}
- if (BN_num_bits(c.n) < OPENSSLRSA_MIN_MODULUS_BITS ||
- BN_num_bits(c.n) > OPENSSLRSA_MAX_MODULUS_BITS)
+ if (BN_num_bits(c.n) < rsa_min_modulus_bits ||
+ BN_num_bits(c.n) > rsa_max_modulus_bits)
{
CLEANUP(ISC_R_RANGE);
}
CLEANUP(ISC_R_RANGE);
}
if (!isc_ossl_wrap_rsa_modulus_bits_in_range(
- pubpkey, OPENSSLRSA_MIN_MODULUS_BITS,
- OPENSSLRSA_MAX_MODULUS_BITS))
+ pubpkey, rsa_min_modulus_bits, rsa_max_modulus_bits))
{
CLEANUP(ISC_R_RANGE);
}