crypto/rsa/rsa_sp800_56b_check.c:371: error: BUFFER_OVERRUN_L3
  Offset added: [8, +oo] Size: [0, 536870848] by call to `rsa_check_prime_factor`.
Showing all 20 steps of the trace


crypto/rsa/rsa_sp800_56b_check.c:316:1: Parameter `rsa->e->top`
314.    *     6.4.1.3.3 "rsakpv2 - crt"
315.    */
316. > int rsa_sp800_56b_check_keypair(const RSA *rsa, const BIGNUM *efixed,
317.                                   int strength, int nbits)
318.   {

crypto/rsa/rsa_sp800_56b_check.c:344:10: Call
342.       }
343.       /* (Step 1.c): e is odd integer 65537 <= e < 2^256 */
344.       if (!rsa_check_public_exponent(rsa->e)) {
                ^
345.           /* exponent out of range */
346.           RSAerr(RSA_F_RSA_SP800_56B_CHECK_KEYPAIR,

crypto/rsa/rsa_sp800_56b_check.c:191:1: Parameter `e->top`
  189.   
  190.   /* Check exponent is odd, and has a bitlen ranging from [17..256] */
  191. > int rsa_check_public_exponent(const BIGNUM *e)
  192.   {
  193.       int bitlen = BN_num_bits(e);

crypto/rsa/rsa_sp800_56b_check.c:193:18: Call
  191.   int rsa_check_public_exponent(const BIGNUM *e)
  192.   {
  193.       int bitlen = BN_num_bits(e);
                          ^
  194.   
  195.       return (BN_is_odd(e) &&  bitlen > 16 && bitlen < 257);

crypto/bn/bn_lib.c:140:9: Call
    138.       bn_check_top(a);
    139.   
    140.       if (BN_is_zero(a))
                   ^
    141.           return 0;
    142.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));

crypto/bn/bn_lib.c:864:1: Parameter `a->top`
      862.   }
      863.   
      864. > int BN_is_zero(const BIGNUM *a)
      865.   {
      866.       return a->top == 0;

crypto/rsa/rsa_sp800_56b_check.c:195:13: Call
  193.       int bitlen = BN_num_bits(e);
  194.   
  195.       return (BN_is_odd(e) &&  bitlen > 16 && bitlen < 257);
                     ^
  196.   }
  197.   

crypto/bn/bn_lib.c:879:1: Parameter `a->top`
    877.   }
    878.   
    879. > int BN_is_odd(const BIGNUM *a)
    880.   {
    881.       return (a->top > 0) && (a->d[0] & 1);

crypto/rsa/rsa_sp800_56b_check.c:371:11: Call
369.   
370.       /* (Step 5): check prime factors p & q */
371.       ret = rsa_check_prime_factor(rsa->p, rsa->e, nbits, ctx)
                 ^
372.             && rsa_check_prime_factor(rsa->q, rsa->e, nbits, ctx)
373.             && (rsa_check_pminusq_diff(r, rsa->p, rsa->q, nbits) > 0)

crypto/rsa/rsa_sp800_56b_check.c:124:1: Parameter `e->top`
  122.    * See SP800-5bBr1 6.4.1.2.3 Step 5 (a to d) & (e to h).
  123.    */
  124. > int rsa_check_prime_factor(BIGNUM *p, BIGNUM *e, int nbits, BN_CTX *ctx)
  125.   {
  126.       int checks = bn_rsa_fips186_4_prime_MR_min_checks(nbits);

crypto/rsa/rsa_sp800_56b_check.c:143:14: Call
  141.             && (BN_copy(p1, p) != NULL)
  142.             && BN_sub_word(p1, 1)
  143.             && BN_gcd(gcd, p1, e, ctx)
                      ^
  144.             && BN_is_one(gcd);
  145.   

crypto/bn/bn_gcd.c:15:1: Parameter `in_b->top`
    13.   static BIGNUM *euclid(BIGNUM *a, BIGNUM *b);
    14.   
    15. > int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx)
    16.   {
    17.       BIGNUM *a, *b, *t;

crypto/bn/bn_gcd.c:31:9: Call
    29.       if (BN_copy(a, in_a) == NULL)
    30.           goto err;
    31.       if (BN_copy(b, in_b) == NULL)
                  ^
    32.           goto err;
    33.       a->neg = 0;

crypto/bn/bn_lib.c:281:1: <Offset trace>
279.   }
280.   
281. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
282.   {
283.       bn_check_top(b);

crypto/bn/bn_lib.c:281:1: Parameter `b->top`
      279.   }
      280.   
      281. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
      282.   {
      283.       bn_check_top(b);

crypto/bn/bn_lib.c:281:1: <Length trace>
279.   }
280.   
281. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
282.   {
283.       bn_check_top(b);

crypto/bn/bn_lib.c:281:1: Parameter `*a->d`
      279.   }
      280.   
      281. > BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
      282.   {
      283.       bn_check_top(b);

crypto/bn/bn_lib.c:287:9: Call
      285.       if (a == b)
      286.           return a;
      287.       if (bn_wexpand(a, b->top) == NULL)
                     ^
      288.           return NULL;
      289.   

crypto/bn/bn_lib.c:960:1: Parameter `*a->d`
        958.   }
        959.   
        960. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
        961.   {
        962.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_lib.c:291:9: Array access: Offset added: [8, +oo] Size: [0, 536870848] by call to `rsa_check_prime_factor` 
      289.   
      290.       if (b->top > 0)
      291.           memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
                     ^
      292.   
      293.       a->neg = b->neg;

BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)
{
    bn_check_top(b);
    if (a == b)
        return a;
    if (bn_wexpand(a, b->top) == NULL)
        return NULL;
    if (b->top > 0)
        memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);
    a->neg = b->neg;
    a->top = b->top;
    a->flags |= b->flags & BN_FLG_FIXED_TOP;
    bn_check_top(a);
    return a;
}
['int rsa_sp800_56b_check_keypair(const RSA *rsa, const BIGNUM *efixed,\n                                int strength, int nbits)\n{\n    int ret = 0;\n    BN_CTX *ctx = NULL;\n    BIGNUM *r = NULL;\n    if (rsa->p == NULL\n            || rsa->q == NULL\n            || rsa->e == NULL\n            || rsa->d == NULL\n            || rsa->n == NULL) {\n        RSAerr(RSA_F_RSA_SP800_56B_CHECK_KEYPAIR, RSA_R_INVALID_REQUEST);\n        return 0;\n    }\n    if (!rsa_sp800_56b_validate_strength(nbits, strength))\n        return 0;\n    if (efixed != NULL) {\n        if (BN_cmp(efixed, rsa->e) != 0) {\n            RSAerr(RSA_F_RSA_SP800_56B_CHECK_KEYPAIR, RSA_R_INVALID_REQUEST);\n            return 0;\n        }\n    }\n    if (!rsa_check_public_exponent(rsa->e)) {\n        RSAerr(RSA_F_RSA_SP800_56B_CHECK_KEYPAIR,\n               RSA_R_PUB_EXPONENT_OUT_OF_RANGE);\n        return 0;\n    }\n    if (nbits != BN_num_bits(rsa->n)) {\n        RSAerr(RSA_F_RSA_SP800_56B_CHECK_KEYPAIR, RSA_R_INVALID_KEYPAIR);\n        return 0;\n    }\n    ctx = BN_CTX_new();\n    if (ctx == NULL)\n        return 0;\n    BN_CTX_start(ctx);\n    r = BN_CTX_get(ctx);\n    if (r == NULL || !BN_mul(r, rsa->p, rsa->q, ctx))\n        goto err;\n    if (BN_cmp(rsa->n, r) != 0) {\n        RSAerr(RSA_F_RSA_SP800_56B_CHECK_KEYPAIR, RSA_R_INVALID_REQUEST);\n        goto err;\n    }\n    ret = rsa_check_prime_factor(rsa->p, rsa->e, nbits, ctx)\n          && rsa_check_prime_factor(rsa->q, rsa->e, nbits, ctx)\n          && (rsa_check_pminusq_diff(r, rsa->p, rsa->q, nbits) > 0)\n          && rsa_check_private_exponent(rsa, nbits, ctx)\n          && rsa_check_crt_components(rsa, ctx);\n    if (ret != 1)\n        RSAerr(RSA_F_RSA_SP800_56B_CHECK_KEYPAIR, RSA_R_INVALID_KEYPAIR);\nerr:\n    BN_clear(r);\n    BN_CTX_end(ctx);\n    BN_CTX_free(ctx);\n    return ret;\n}', 'int rsa_check_public_exponent(const BIGNUM *e)\n{\n    int bitlen = BN_num_bits(e);\n    return (BN_is_odd(e) &&  bitlen > 16 && bitlen < 257);\n}', 'int BN_num_bits(const BIGNUM *a)\n{\n    int i = a->top - 1;\n    bn_check_top(a);\n    if (BN_is_zero(a))\n        return 0;\n    return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));\n}', 'int BN_is_zero(const BIGNUM *a)\n{\n    return a->top == 0;\n}', 'int BN_is_odd(const BIGNUM *a)\n{\n    return (a->top > 0) && (a->d[0] & 1);\n}', 'int rsa_check_prime_factor(BIGNUM *p, BIGNUM *e, int nbits, BN_CTX *ctx)\n{\n    int checks = bn_rsa_fips186_4_prime_MR_min_checks(nbits);\n    int ret = 0;\n    BIGNUM *p1 = NULL, *gcd = NULL;\n    if (BN_is_prime_fasttest_ex(p, checks, ctx, 1, NULL) != 1\n            || rsa_check_prime_factor_range(p, nbits, ctx) != 1)\n        return 0;\n    BN_CTX_start(ctx);\n    p1 = BN_CTX_get(ctx);\n    gcd = BN_CTX_get(ctx);\n    ret = (gcd != NULL)\n          && (BN_copy(p1, p) != NULL)\n          && BN_sub_word(p1, 1)\n          && BN_gcd(gcd, p1, e, ctx)\n          && BN_is_one(gcd);\n    BN_clear(p1);\n    BN_CTX_end(ctx);\n    return ret;\n}', 'int BN_gcd(BIGNUM *r, const BIGNUM *in_a, const BIGNUM *in_b, BN_CTX *ctx)\n{\n    BIGNUM *a, *b, *t;\n    int ret = 0;\n    bn_check_top(in_a);\n    bn_check_top(in_b);\n    BN_CTX_start(ctx);\n    a = BN_CTX_get(ctx);\n    b = BN_CTX_get(ctx);\n    if (b == NULL)\n        goto err;\n    if (BN_copy(a, in_a) == NULL)\n        goto err;\n    if (BN_copy(b, in_b) == NULL)\n        goto err;\n    a->neg = 0;\n    b->neg = 0;\n    if (BN_cmp(a, b) < 0) {\n        t = a;\n        a = b;\n        b = t;\n    }\n    t = euclid(a, b);\n    if (t == NULL)\n        goto err;\n    if (BN_copy(r, t) == NULL)\n        goto err;\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    bn_check_top(r);\n    return ret;\n}', 'BIGNUM *BN_copy(BIGNUM *a, const BIGNUM *b)\n{\n    bn_check_top(b);\n    if (a == b)\n        return a;\n    if (bn_wexpand(a, b->top) == NULL)\n        return NULL;\n    if (b->top > 0)\n        memcpy(a->d, b->d, sizeof(b->d[0]) * b->top);\n    a->neg = b->neg;\n    a->top = b->top;\n    a->flags |= b->flags & BN_FLG_FIXED_TOP;\n    bn_check_top(a);\n    return a;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']