crypto/rsa/rsa_sp800_56b_gen.c:220: error: BUFFER_OVERRUN_L3
  Offset: [32, +oo] Size: [0, 8388607] by call to `BN_mul`.
Showing all 12 steps of the trace


crypto/rsa/rsa_sp800_56b_gen.c:180:1: Parameter `rsa->n->d`
178.    *           1 = success.
179.    */
180. > int rsa_sp800_56b_derive_params_from_pq(RSA *rsa, int nbits,
181.                                           const BIGNUM *e, BN_CTX *ctx)
182.   {

crypto/rsa/rsa_sp800_56b_gen.c:220:28: Call
218.       if (rsa->n == NULL)
219.           rsa->n = BN_new();
220.       if (rsa->n == NULL || !BN_mul(rsa->n, rsa->p, rsa->q, ctx))
                                  ^
221.           goto err;
222.   

crypto/bn/bn_mul.c:497:1: Parameter `*r->d`
  495.   #endif                          /* BN_RECURSION */
  496.   
  497. > int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
  498.   {
  499.       int ret = bn_mul_fixed_top(r, a, b, ctx);

crypto/bn/bn_mul.c:499:15: Call
  497.   int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
  498.   {
  499.       int ret = bn_mul_fixed_top(r, a, b, ctx);
                       ^
  500.   
  501.       bn_correct_top(r);

crypto/bn/bn_mul.c:507:1: Parameter `a->top`
    505.   }
    506.   
    507. > int bn_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
    508.   {
    509.       int ret = 0;

crypto/bn/bn_mul.c:524:5: Assignment
    522.       bn_check_top(r);
    523.   
    524.       al = a->top;
               ^
    525.       bl = b->top;
    526.   

crypto/bn/bn_mul.c:595:17: Call
    593.                   if (bn_wexpand(rr, k * 2) == NULL)
    594.                       goto err;
    595.                   bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);
                           ^
    596.               }
    597.               rr->top = top;

crypto/bn/bn_mul.c:175:1: <Offset trace>
173.    */
174.   /* dnX may not be positive, but n2/2+dnX has to be */
175. > void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
176.                         int dna, int dnb, BN_ULONG *t)
177.   {

crypto/bn/bn_mul.c:175:1: Parameter `n2`
      173.    */
      174.   /* dnX may not be positive, but n2/2+dnX has to be */
      175. > void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
      176.                         int dna, int dnb, BN_ULONG *t)
      177.   {

crypto/bn/bn_mul.c:175:1: <Length trace>
173.    */
174.   /* dnX may not be positive, but n2/2+dnX has to be */
175. > void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
176.                         int dna, int dnb, BN_ULONG *t)
177.   {

crypto/bn/bn_mul.c:175:1: Parameter `*t`
      173.    */
      174.   /* dnX may not be positive, but n2/2+dnX has to be */
      175. > void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
      176.                         int dna, int dnb, BN_ULONG *t)
      177.   {

crypto/bn/bn_mul.c:266:9: Array access: Offset: [32, +oo] Size: [0, 8388607] by call to `BN_mul` 
      264.   # endif                         /* BN_MUL_COMBA */
      265.       {
      266.           p = &(t[n2 * 2]);
                     ^
      267.           if (!zero)
      268.               bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);

void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,
                      int dna, int dnb, BN_ULONG *t)
{
    int n = n2 / 2, c1, c2;
    int tna = n + dna, tnb = n + dnb;
    unsigned int neg, zero;
    BN_ULONG ln, lo, *p;
# ifdef BN_MUL_COMBA
#  if 0
    if (n2 == 4) {
        bn_mul_comba4(r, a, b);
        return;
    }
#  endif
    if (n2 == 8 && dna == 0 && dnb == 0) {
        bn_mul_comba8(r, a, b);
        return;
    }
# endif
    if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) {
        bn_mul_normal(r, a, n2 + dna, b, n2 + dnb);
        if ((dna + dnb) < 0)
            memset(&r[2 * n2 + dna + dnb], 0,
                   sizeof(BN_ULONG) * -(dna + dnb));
        return;
    }
    c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);
    c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);
    zero = neg = 0;
    switch (c1 * 3 + c2) {
    case -4:
        bn_sub_part_words(t, &(a[n]), a, tna, tna - n);
        bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);
        break;
    case -3:
        zero = 1;
        break;
    case -2:
        bn_sub_part_words(t, &(a[n]), a, tna, tna - n);
        bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);
        neg = 1;
        break;
    case -1:
    case 0:
    case 1:
        zero = 1;
        break;
    case 2:
        bn_sub_part_words(t, a, &(a[n]), tna, n - tna);
        bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);
        neg = 1;
        break;
    case 3:
        zero = 1;
        break;
    case 4:
        bn_sub_part_words(t, a, &(a[n]), tna, n - tna);
        bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);
        break;
    }
# ifdef BN_MUL_COMBA
    if (n == 4 && dna == 0 && dnb == 0) {
        if (!zero)
            bn_mul_comba4(&(t[n2]), t, &(t[n]));
        else
            memset(&t[n2], 0, sizeof(*t) * 8);
        bn_mul_comba4(r, a, b);
        bn_mul_comba4(&(r[n2]), &(a[n]), &(b[n]));
    } else if (n == 8 && dna == 0 && dnb == 0) {
        if (!zero)
            bn_mul_comba8(&(t[n2]), t, &(t[n]));
        else
            memset(&t[n2], 0, sizeof(*t) * 16);
        bn_mul_comba8(r, a, b);
        bn_mul_comba8(&(r[n2]), &(a[n]), &(b[n]));
    } else
# endif
    {
        p = &(t[n2 * 2]);
        if (!zero)
            bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);
        else
            memset(&t[n2], 0, sizeof(*t) * n2);
        bn_mul_recursive(r, a, b, n, 0, 0, p);
        bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]), n, dna, dnb, p);
    }
    c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));
    if (neg) {
        c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));
    } else {
        c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));
    }
    c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));
    if (c1) {
        p = &(r[n + n2]);
        lo = *p;
        ln = (lo + c1) & BN_MASK2;
        *p = ln;
        if (ln < (BN_ULONG)c1) {
            do {
                p++;
                lo = *p;
                ln = (lo + 1) & BN_MASK2;
                *p = ln;
            } while (ln == 0);
        }
    }
}
['int rsa_sp800_56b_derive_params_from_pq(RSA *rsa, int nbits,\n                                        const BIGNUM *e, BN_CTX *ctx)\n{\n    int ret = -1;\n    BIGNUM *p1, *q1, *lcm, *p1q1, *gcd;\n    BN_CTX_start(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    if (gcd == NULL)\n        goto err;\n    if (rsa_get_lcm(ctx, rsa->p, rsa->q, lcm, gcd, p1, q1, p1q1) != 1)\n        goto err;\n    BN_free(rsa->e);\n    rsa->e = BN_dup(e);\n    if (rsa->e == NULL)\n        goto err;\n    BN_clear_free(rsa->d);\n    rsa->d = BN_secure_new();\n    if (rsa->d == NULL || BN_mod_inverse(rsa->d, e, lcm, ctx) == NULL)\n        goto err;\n    if (BN_num_bits(rsa->d) <= (nbits >> 1)) {\n        ret = 0;\n        goto err;\n    }\n    if (rsa->n == NULL)\n        rsa->n = BN_new();\n    if (rsa->n == NULL || !BN_mul(rsa->n, rsa->p, rsa->q, ctx))\n        goto err;\n    if (rsa->dmp1 == NULL)\n        rsa->dmp1 = BN_new();\n    if (rsa->dmp1 == NULL || !BN_mod(rsa->dmp1, rsa->d, p1, ctx))\n        goto err;\n    if (rsa->dmq1 == NULL)\n        rsa->dmq1 = BN_secure_new();\n    if (rsa->dmq1 == NULL || !BN_mod(rsa->dmq1, rsa->d, q1, ctx))\n        goto err;\n    BN_free(rsa->iqmp);\n    rsa->iqmp = BN_secure_new();\n    if (rsa->iqmp == NULL\n            || BN_mod_inverse(rsa->iqmp, rsa->q, rsa->p, ctx) == NULL)\n        goto err;\n    ret = 1;\nerr:\n    if (ret != 1) {\n        BN_free(rsa->e);\n        rsa->e = NULL;\n        BN_free(rsa->d);\n        rsa->d = NULL;\n        BN_free(rsa->n);\n        rsa->n = NULL;\n        BN_free(rsa->iqmp);\n        rsa->iqmp = NULL;\n        BN_free(rsa->dmq1);\n        rsa->dmq1 = NULL;\n        BN_free(rsa->dmp1);\n        rsa->dmp1 = NULL;\n    }\n    BN_clear(p1);\n    BN_clear(q1);\n    BN_clear(lcm);\n    BN_clear(p1q1);\n    BN_clear(gcd);\n    BN_CTX_end(ctx);\n    return ret;\n}', 'int BN_mul(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n    int ret = bn_mul_fixed_top(r, a, b, ctx);\n    bn_correct_top(r);\n    bn_check_top(r);\n    return ret;\n}', 'int bn_mul_fixed_top(BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)\n{\n    int ret = 0;\n    int top, al, bl;\n    BIGNUM *rr;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n    int i;\n#endif\n#ifdef BN_RECURSION\n    BIGNUM *t = NULL;\n    int j = 0, k;\n#endif\n    bn_check_top(a);\n    bn_check_top(b);\n    bn_check_top(r);\n    al = a->top;\n    bl = b->top;\n    if ((al == 0) || (bl == 0)) {\n        BN_zero(r);\n        return 1;\n    }\n    top = al + bl;\n    BN_CTX_start(ctx);\n    if ((r == a) || (r == b)) {\n        if ((rr = BN_CTX_get(ctx)) == NULL)\n            goto err;\n    } else\n        rr = r;\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n    i = al - bl;\n#endif\n#ifdef BN_MUL_COMBA\n    if (i == 0) {\n# if 0\n        if (al == 4) {\n            if (bn_wexpand(rr, 8) == NULL)\n                goto err;\n            rr->top = 8;\n            bn_mul_comba4(rr->d, a->d, b->d);\n            goto end;\n        }\n# endif\n        if (al == 8) {\n            if (bn_wexpand(rr, 16) == NULL)\n                goto err;\n            rr->top = 16;\n            bn_mul_comba8(rr->d, a->d, b->d);\n            goto end;\n        }\n    }\n#endif\n#ifdef BN_RECURSION\n    if ((al >= BN_MULL_SIZE_NORMAL) && (bl >= BN_MULL_SIZE_NORMAL)) {\n        if (i >= -1 && i <= 1) {\n            if (i >= 0) {\n                j = BN_num_bits_word((BN_ULONG)al);\n            }\n            if (i == -1) {\n                j = BN_num_bits_word((BN_ULONG)bl);\n            }\n            j = 1 << (j - 1);\n            assert(j <= al || j <= bl);\n            k = j + j;\n            t = BN_CTX_get(ctx);\n            if (t == NULL)\n                goto err;\n            if (al > j || bl > j) {\n                if (bn_wexpand(t, k * 4) == NULL)\n                    goto err;\n                if (bn_wexpand(rr, k * 4) == NULL)\n                    goto err;\n                bn_mul_part_recursive(rr->d, a->d, b->d,\n                                      j, al - j, bl - j, t->d);\n            } else {\n                if (bn_wexpand(t, k * 2) == NULL)\n                    goto err;\n                if (bn_wexpand(rr, k * 2) == NULL)\n                    goto err;\n                bn_mul_recursive(rr->d, a->d, b->d, j, al - j, bl - j, t->d);\n            }\n            rr->top = top;\n            goto end;\n        }\n    }\n#endif\n    if (bn_wexpand(rr, top) == NULL)\n        goto err;\n    rr->top = top;\n    bn_mul_normal(rr->d, a->d, al, b->d, bl);\n#if defined(BN_MUL_COMBA) || defined(BN_RECURSION)\n end:\n#endif\n    rr->neg = a->neg ^ b->neg;\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(r);\n    BN_CTX_end(ctx);\n    return ret;\n}', 'void bn_mul_recursive(BN_ULONG *r, BN_ULONG *a, BN_ULONG *b, int n2,\n                      int dna, int dnb, BN_ULONG *t)\n{\n    int n = n2 / 2, c1, c2;\n    int tna = n + dna, tnb = n + dnb;\n    unsigned int neg, zero;\n    BN_ULONG ln, lo, *p;\n# ifdef BN_MUL_COMBA\n#  if 0\n    if (n2 == 4) {\n        bn_mul_comba4(r, a, b);\n        return;\n    }\n#  endif\n    if (n2 == 8 && dna == 0 && dnb == 0) {\n        bn_mul_comba8(r, a, b);\n        return;\n    }\n# endif\n    if (n2 < BN_MUL_RECURSIVE_SIZE_NORMAL) {\n        bn_mul_normal(r, a, n2 + dna, b, n2 + dnb);\n        if ((dna + dnb) < 0)\n            memset(&r[2 * n2 + dna + dnb], 0,\n                   sizeof(BN_ULONG) * -(dna + dnb));\n        return;\n    }\n    c1 = bn_cmp_part_words(a, &(a[n]), tna, n - tna);\n    c2 = bn_cmp_part_words(&(b[n]), b, tnb, tnb - n);\n    zero = neg = 0;\n    switch (c1 * 3 + c2) {\n    case -4:\n        bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n        bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n        break;\n    case -3:\n        zero = 1;\n        break;\n    case -2:\n        bn_sub_part_words(t, &(a[n]), a, tna, tna - n);\n        bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n        neg = 1;\n        break;\n    case -1:\n    case 0:\n    case 1:\n        zero = 1;\n        break;\n    case 2:\n        bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n        bn_sub_part_words(&(t[n]), b, &(b[n]), tnb, n - tnb);\n        neg = 1;\n        break;\n    case 3:\n        zero = 1;\n        break;\n    case 4:\n        bn_sub_part_words(t, a, &(a[n]), tna, n - tna);\n        bn_sub_part_words(&(t[n]), &(b[n]), b, tnb, tnb - n);\n        break;\n    }\n# ifdef BN_MUL_COMBA\n    if (n == 4 && dna == 0 && dnb == 0) {\n        if (!zero)\n            bn_mul_comba4(&(t[n2]), t, &(t[n]));\n        else\n            memset(&t[n2], 0, sizeof(*t) * 8);\n        bn_mul_comba4(r, a, b);\n        bn_mul_comba4(&(r[n2]), &(a[n]), &(b[n]));\n    } else if (n == 8 && dna == 0 && dnb == 0) {\n        if (!zero)\n            bn_mul_comba8(&(t[n2]), t, &(t[n]));\n        else\n            memset(&t[n2], 0, sizeof(*t) * 16);\n        bn_mul_comba8(r, a, b);\n        bn_mul_comba8(&(r[n2]), &(a[n]), &(b[n]));\n    } else\n# endif\n    {\n        p = &(t[n2 * 2]);\n        if (!zero)\n            bn_mul_recursive(&(t[n2]), t, &(t[n]), n, 0, 0, p);\n        else\n            memset(&t[n2], 0, sizeof(*t) * n2);\n        bn_mul_recursive(r, a, b, n, 0, 0, p);\n        bn_mul_recursive(&(r[n2]), &(a[n]), &(b[n]), n, dna, dnb, p);\n    }\n    c1 = (int)(bn_add_words(t, r, &(r[n2]), n2));\n    if (neg) {\n        c1 -= (int)(bn_sub_words(&(t[n2]), t, &(t[n2]), n2));\n    } else {\n        c1 += (int)(bn_add_words(&(t[n2]), &(t[n2]), t, n2));\n    }\n    c1 += (int)(bn_add_words(&(r[n]), &(r[n]), &(t[n2]), n2));\n    if (c1) {\n        p = &(r[n + n2]);\n        lo = *p;\n        ln = (lo + c1) & BN_MASK2;\n        *p = ln;\n        if (ln < (BN_ULONG)c1) {\n            do {\n                p++;\n                lo = *p;\n                ln = (lo + 1) & BN_MASK2;\n                *p = ln;\n            } while (ln == 0);\n        }\n    }\n}']