crypto/rsa/rsa_sp800_56b_check.c:375: error: BUFFER_OVERRUN_L3
  Offset: [2, 15] (⇐ 1 + [1, 14]) Size: [0, 8388607] by call to `rsa_check_private_exponent`.
Showing all 31 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:372:14: Call
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)
374.             /* (Step 6): Check the private exponent d */

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:375:14: Call
373.             && (rsa_check_pminusq_diff(r, rsa->p, rsa->q, nbits) > 0)
374.             /* (Step 6): Check the private exponent d */
375.             && rsa_check_private_exponent(rsa, nbits, ctx)
                    ^
376.             /* 6.4.1.2.3 (Step 7): Check the CRT components */
377.             && rsa_check_crt_components(rsa, ctx);

crypto/rsa/rsa_sp800_56b_check.c:157:1: Parameter `rsa->e->top`
  155.    *     (Step 6b) 1 = (d*e) mod LCM(p–1, q–1)
  156.    */
  157. > int rsa_check_private_exponent(const RSA *rsa, int nbits, BN_CTX *ctx)
  158.   {
  159.       int ret;

crypto/rsa/rsa_sp800_56b_check.c:179:14: Call
  177.             && (BN_cmp(rsa->d, lcm) < 0)
  178.             /* (Step 6b) 1 = (e . d) mod LCM(p - 1, q - 1) */
  179.             && BN_mod_mul(r, rsa->e, rsa->d, lcm, ctx)
                      ^
  180.             && BN_is_one(r));
  181.   

crypto/bn/bn_mod.c:193:1: Parameter `a->top`
    191.   
    192.   /* slow but works */
    193. > int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,
    194.                  BN_CTX *ctx)
    195.   {

crypto/bn/bn_mod.c:207:14: Call
    205.           goto err;
    206.       if (a == b) {
    207.           if (!BN_sqr(t, a, ctx))
                        ^
    208.               goto err;
    209.       } else {

crypto/bn/bn_sqr.c:17:1: Parameter `*r->d`
      15.    * I've just gone over this and it is now %20 faster on x86 - eay - 27 Jun 96
      16.    */
      17. > int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
      18.   {
      19.       int ret = bn_sqr_fixed_top(r, a, ctx);

crypto/bn/bn_sqr.c:19:15: Call
      17.   int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
      18.   {
      19.       int ret = bn_sqr_fixed_top(r, a, ctx);
                          ^
      20.   
      21.       bn_correct_top(r);

crypto/bn/bn_sqr.c:27:1: Parameter `a->top`
        25.   }
        26.   
        27. > int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
        28.   {
        29.       int max, al;

crypto/bn/bn_sqr.c:35:5: Assignment
        33.       bn_check_top(a);
        34.   
        35.       al = a->top;
                  ^
        36.       if (al <= 0) {
        37.           r->top = 0;

crypto/bn/bn_sqr.c:70:13: Call
        68.           if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {
        69.               BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];
        70.               bn_sqr_normal(rr->d, a->d, al, t);
                          ^
        71.           } else {
        72.               int j, k;

crypto/bn/bn_sqr.c:109:1: <Offset trace>
107.   
108.   /* tmp must have 2*n words */
109. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
110.   {
111.       int i, j, max;

crypto/bn/bn_sqr.c:109:1: Parameter `n`
          107.   
          108.   /* tmp must have 2*n words */
          109. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
          110.   {
          111.       int i, j, max;

crypto/bn/bn_sqr.c:120:5: Assignment
          118.       rp[0] = rp[max - 1] = 0;
          119.       rp++;
          120.       j = n;
                     ^
          121.   
          122.       if (--j > 0) {

crypto/bn/bn_sqr.c:122:9: Assignment
          120.       j = n;
          121.   
          122.       if (--j > 0) {
                         ^
          123.           ap++;
          124.           rp[j] = bn_mul_words(rp, ap, j, ap[-1]);

crypto/bn/bn_sqr.c:109:1: <Length trace>
107.   
108.   /* tmp must have 2*n words */
109. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
110.   {
111.       int i, j, max;

crypto/bn/bn_sqr.c:109:1: Parameter `*r`
          107.   
          108.   /* tmp must have 2*n words */
          109. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
          110.   {
          111.       int i, j, max;

crypto/bn/bn_sqr.c:117:5: Assignment
          115.       max = n * 2;
          116.       ap = a;
          117.       rp = r;
                     ^
          118.       rp[0] = rp[max - 1] = 0;
          119.       rp++;

crypto/bn/bn_sqr.c:119:5: Assignment
          117.       rp = r;
          118.       rp[0] = rp[max - 1] = 0;
          119.       rp++;
                     ^
          120.       j = n;
          121.   

crypto/bn/bn_sqr.c:124:9: Array access: Offset: [2, 15] (⇐ 1 + [1, 14]) Size: [0, 8388607] by call to `rsa_check_private_exponent` 
          122.       if (--j > 0) {
          123.           ap++;
          124.           rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
                         ^
          125.           rp += 2;
          126.       }

void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
{
    int i, j, max;
    const BN_ULONG *ap;
    BN_ULONG *rp;
    max = n * 2;
    ap = a;
    rp = r;
    rp[0] = rp[max - 1] = 0;
    rp++;
    j = n;
    if (--j > 0) {
        ap++;
        rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
        rp += 2;
    }
    for (i = n - 2; i > 0; i--) {
        j--;
        ap++;
        rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);
        rp += 2;
    }
    bn_add_words(r, r, r, max);
    bn_sqr_words(tmp, a, n);
    bn_add_words(r, r, tmp, max);
}
['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 rsa_check_private_exponent(const RSA *rsa, int nbits, BN_CTX *ctx)\n{\n    int ret;\n    BIGNUM *r, *p1, *q1, *lcm, *p1q1, *gcd;\n    if (BN_num_bits(rsa->d) <= (nbits >> 1))\n        return 0;\n    BN_CTX_start(ctx);\n    r = BN_CTX_get(ctx);\n    p1 = BN_CTX_get(ctx);\n    q1 = BN_CTX_get(ctx);\n    lcm = BN_CTX_get(ctx);\n    p1q1 = BN_CTX_get(ctx);\n    gcd = BN_CTX_get(ctx);\n    ret = (gcd != NULL\n          && (rsa_get_lcm(ctx, rsa->p, rsa->q, lcm, gcd, p1, q1, p1q1) == 1)\n          && (BN_cmp(rsa->d, lcm) < 0)\n          && BN_mod_mul(r, rsa->e, rsa->d, lcm, ctx)\n          && BN_is_one(r));\n    BN_clear(p1);\n    BN_clear(q1);\n    BN_clear(lcm);\n    BN_clear(gcd);\n    BN_CTX_end(ctx);\n    return ret;\n}', 'int BN_mod_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, const BIGNUM *m,\n               BN_CTX *ctx)\n{\n    BIGNUM *t;\n    int ret = 0;\n    bn_check_top(a);\n    bn_check_top(b);\n    bn_check_top(m);\n    BN_CTX_start(ctx);\n    if ((t = BN_CTX_get(ctx)) == NULL)\n        goto err;\n    if (a == b) {\n        if (!BN_sqr(t, a, ctx))\n            goto err;\n    } else {\n        if (!BN_mul(t, a, b, ctx))\n            goto err;\n    }\n    if (!BN_nnmod(r, t, m, ctx))\n        goto err;\n    bn_check_top(r);\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return ret;\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n    int ret = bn_sqr_fixed_top(r, a, ctx);\n    bn_correct_top(r);\n    bn_check_top(r);\n    return ret;\n}', 'int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n    int max, al;\n    int ret = 0;\n    BIGNUM *tmp, *rr;\n    bn_check_top(a);\n    al = a->top;\n    if (al <= 0) {\n        r->top = 0;\n        r->neg = 0;\n        return 1;\n    }\n    BN_CTX_start(ctx);\n    rr = (a != r) ? r : BN_CTX_get(ctx);\n    tmp = BN_CTX_get(ctx);\n    if (rr == NULL || tmp == NULL)\n        goto err;\n    max = 2 * al;\n    if (bn_wexpand(rr, max) == NULL)\n        goto err;\n    if (al == 4) {\n#ifndef BN_SQR_COMBA\n        BN_ULONG t[8];\n        bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n        bn_sqr_comba4(rr->d, a->d);\n#endif\n    } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n        BN_ULONG t[16];\n        bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n        bn_sqr_comba8(rr->d, a->d);\n#endif\n    } else {\n#if defined(BN_RECURSION)\n        if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n            BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n            bn_sqr_normal(rr->d, a->d, al, t);\n        } else {\n            int j, k;\n            j = BN_num_bits_word((BN_ULONG)al);\n            j = 1 << (j - 1);\n            k = j + j;\n            if (al == j) {\n                if (bn_wexpand(tmp, k * 2) == NULL)\n                    goto err;\n                bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n            } else {\n                if (bn_wexpand(tmp, max) == NULL)\n                    goto err;\n                bn_sqr_normal(rr->d, a->d, al, tmp->d);\n            }\n        }\n#else\n        if (bn_wexpand(tmp, max) == NULL)\n            goto err;\n        bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n    }\n    rr->neg = 0;\n    rr->top = max;\n    rr->flags |= BN_FLG_FIXED_TOP;\n    if (r != rr && BN_copy(r, rr) == NULL)\n        goto err;\n    ret = 1;\n err:\n    bn_check_top(rr);\n    bn_check_top(tmp);\n    BN_CTX_end(ctx);\n    return ret;\n}', 'void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n    int i, j, max;\n    const BN_ULONG *ap;\n    BN_ULONG *rp;\n    max = n * 2;\n    ap = a;\n    rp = r;\n    rp[0] = rp[max - 1] = 0;\n    rp++;\n    j = n;\n    if (--j > 0) {\n        ap++;\n        rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n        rp += 2;\n    }\n    for (i = n - 2; i > 0; i--) {\n        j--;\n        ap++;\n        rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n        rp += 2;\n    }\n    bn_add_words(r, r, r, max);\n    bn_sqr_words(tmp, a, n);\n    bn_add_words(r, r, tmp, max);\n}']