crypto/ec/ecp_nistz256.c:625: error: BUFFER_OVERRUN_L3
  Offset: 0 Size: [0, 8388607] by call to `BN_nnmod`.
Showing all 17 steps of the trace


crypto/ec/ecp_nistz256.c:623:24: Call
621.               BIGNUM *mod;
622.   
623.               if ((mod = BN_CTX_get(ctx)) == NULL)
                              ^
624.                   goto err;
625.               if (!BN_nnmod(mod, scalar[i], group->order, ctx)) {

crypto/bn/bn_ctx.c:229:5: Call
  227.       }
  228.       /* OK, make sure the returned bignum is "zero" */
  229.       BN_zero(ret);
             ^
  230.       ctx->used++;
  231.       CTXDBG_RET(ctx, ret);

crypto/bn/bn_lib.c:463:1: Parameter `*a->d`
    461.   }
    462.   
    463. > int BN_set_word(BIGNUM *a, BN_ULONG w)
    464.   {
    465.       bn_check_top(a);

crypto/bn/bn_lib.c:466:9: Call
    464.   {
    465.       bn_check_top(a);
    466.       if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
                   ^
    467.           return (0);
    468.       a->neg = 0;

crypto/bn/bn_lcl.h:676:1: Parameter `*a->d`
      674.   int bn_probable_prime_dh_coprime(BIGNUM *rnd, int bits, BN_CTX *ctx);
      675.   
      676. > static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)
      677.   {
      678.       if (bits > (INT_MAX - BN_BITS2 + 1))

crypto/ec/ecp_nistz256.c:625:18: Call
623.               if ((mod = BN_CTX_get(ctx)) == NULL)
624.                   goto err;
625.               if (!BN_nnmod(mod, scalar[i], group->order, ctx)) {
                        ^
626.                   ECerr(EC_F_ECP_NISTZ256_WINDOWED_MUL, ERR_R_BN_LIB);
627.                   goto err;

crypto/bn/bn_mod.c:13:1: Parameter `*r->d`
  11.   #include "bn_lcl.h"
  12.   
  13. > int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
  14.   {
  15.       /*

crypto/bn/bn_mod.c:20:11: Call
  18.        */
  19.   
  20.       if (!(BN_mod(r, m, d, ctx)))
                  ^
  21.           return 0;
  22.       if (!r->neg)

crypto/bn/bn_div.c:140:1: Parameter `*rm->d`
    138.    * If 'dv' or 'rm' is NULL, the respective value is not returned.
    139.    */
    140. > int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
    141.              BN_CTX *ctx)
    142.   {

crypto/bn/bn_div.c:409:9: Call
    407.            */
    408.           int neg = num->neg;
    409.           BN_rshift(rm, snum, norm_shift);
                   ^
    410.           if (!BN_is_zero(rm))
    411.               rm->neg = neg;

crypto/bn/bn_shift.c:120:1: Parameter `*r->d`
      118.   }
      119.   
      120. > int BN_rshift(BIGNUM *r, const BIGNUM *a, int n)
      121.   {
      122.       int i, j, nw, lb, rb;

crypto/bn/bn_shift.c:138:9: Call
      136.       lb = BN_BITS2 - rb;
      137.       if (nw >= a->top || a->top == 0) {
      138.           BN_zero(r);
                     ^
      139.           return (1);
      140.       }

crypto/bn/bn_lib.c:463:1: <Length trace>
461.   }
462.   
463. > int BN_set_word(BIGNUM *a, BN_ULONG w)
464.   {
465.       bn_check_top(a);

crypto/bn/bn_lib.c:463:1: Parameter `*a->d`
        461.   }
        462.   
        463. > int BN_set_word(BIGNUM *a, BN_ULONG w)
        464.   {
        465.       bn_check_top(a);

crypto/bn/bn_lib.c:466:9: Call
        464.   {
        465.       bn_check_top(a);
        466.       if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
                       ^
        467.           return (0);
        468.       a->neg = 0;

crypto/bn/bn_lcl.h:676:1: Parameter `*a->d`
          674.   int bn_probable_prime_dh_coprime(BIGNUM *rnd, int bits, BN_CTX *ctx);
          675.   
          676. > static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)
          677.   {
          678.       if (bits > (INT_MAX - BN_BITS2 + 1))

crypto/bn/bn_lib.c:469:5: Array access: Offset: 0 Size: [0, 8388607] by call to `BN_nnmod` 
        467.           return (0);
        468.       a->neg = 0;
        469.       a->d[0] = w;
                   ^
        470.       a->top = (w ? 1 : 0);
        471.       bn_check_top(a);

int BN_set_word(BIGNUM *a, BN_ULONG w)
{
    bn_check_top(a);
    if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
        return (0);
    a->neg = 0;
    a->d[0] = w;
    a->top = (w ? 1 : 0);
    bn_check_top(a);
    return (1);
}
['static int ecp_nistz256_windowed_mul(const EC_GROUP *group,\n                                            P256_POINT *r,\n                                            const BIGNUM **scalar,\n                                            const EC_POINT **point,\n                                            size_t num, BN_CTX *ctx)\n{\n    size_t i;\n    int j, ret = 0;\n    unsigned int idx;\n    unsigned char (*p_str)[33] = NULL;\n    const unsigned int window_size = 5;\n    const unsigned int mask = (1 << (window_size + 1)) - 1;\n    unsigned int wvalue;\n    P256_POINT *temp;\n    const BIGNUM **scalars = NULL;\n    P256_POINT (*table)[16] = NULL;\n    void *table_storage = NULL;\n    if ((num * 16 + 6) > OPENSSL_MALLOC_MAX_NELEMS(P256_POINT)\n        || (table_storage =\n            OPENSSL_malloc((num * 16 + 5) * sizeof(P256_POINT) + 64)) == NULL\n        || (p_str =\n            OPENSSL_malloc(num * 33 * sizeof(unsigned char))) == NULL\n        || (scalars = OPENSSL_malloc(num * sizeof(BIGNUM *))) == NULL) {\n        ECerr(EC_F_ECP_NISTZ256_WINDOWED_MUL, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    table = (void *)ALIGNPTR(table_storage, 64);\n    temp = (P256_POINT *)(table + num);\n    for (i = 0; i < num; i++) {\n        P256_POINT *row = table[i];\n        if ((BN_num_bits(scalar[i]) > 256) || BN_is_negative(scalar[i])) {\n            BIGNUM *mod;\n            if ((mod = BN_CTX_get(ctx)) == NULL)\n                goto err;\n            if (!BN_nnmod(mod, scalar[i], group->order, ctx)) {\n                ECerr(EC_F_ECP_NISTZ256_WINDOWED_MUL, ERR_R_BN_LIB);\n                goto err;\n            }\n            scalars[i] = mod;\n        } else\n            scalars[i] = scalar[i];\n        for (j = 0; j < bn_get_top(scalars[i]) * BN_BYTES; j += BN_BYTES) {\n            BN_ULONG d = bn_get_words(scalars[i])[j / BN_BYTES];\n            p_str[i][j + 0] = (unsigned char)d;\n            p_str[i][j + 1] = (unsigned char)(d >> 8);\n            p_str[i][j + 2] = (unsigned char)(d >> 16);\n            p_str[i][j + 3] = (unsigned char)(d >>= 24);\n            if (BN_BYTES == 8) {\n                d >>= 8;\n                p_str[i][j + 4] = (unsigned char)d;\n                p_str[i][j + 5] = (unsigned char)(d >> 8);\n                p_str[i][j + 6] = (unsigned char)(d >> 16);\n                p_str[i][j + 7] = (unsigned char)(d >> 24);\n            }\n        }\n        for (; j < 33; j++)\n            p_str[i][j] = 0;\n        if (!ecp_nistz256_bignum_to_field_elem(temp[0].X, point[i]->X)\n            || !ecp_nistz256_bignum_to_field_elem(temp[0].Y, point[i]->Y)\n            || !ecp_nistz256_bignum_to_field_elem(temp[0].Z, point[i]->Z)) {\n            ECerr(EC_F_ECP_NISTZ256_WINDOWED_MUL,\n                  EC_R_COORDINATES_OUT_OF_RANGE);\n            goto err;\n        }\n        ecp_nistz256_scatter_w5  (row, &temp[0], 1);\n        ecp_nistz256_point_double(&temp[1], &temp[0]);\n        ecp_nistz256_scatter_w5  (row, &temp[1], 2);\n        ecp_nistz256_point_add   (&temp[2], &temp[1], &temp[0]);\n        ecp_nistz256_scatter_w5  (row, &temp[2], 3);\n        ecp_nistz256_point_double(&temp[1], &temp[1]);\n        ecp_nistz256_scatter_w5  (row, &temp[1], 4);\n        ecp_nistz256_point_double(&temp[2], &temp[2]);\n        ecp_nistz256_scatter_w5  (row, &temp[2], 6);\n        ecp_nistz256_point_add   (&temp[3], &temp[1], &temp[0]);\n        ecp_nistz256_scatter_w5  (row, &temp[3], 5);\n        ecp_nistz256_point_add   (&temp[4], &temp[2], &temp[0]);\n        ecp_nistz256_scatter_w5  (row, &temp[4], 7);\n        ecp_nistz256_point_double(&temp[1], &temp[1]);\n        ecp_nistz256_scatter_w5  (row, &temp[1], 8);\n        ecp_nistz256_point_double(&temp[2], &temp[2]);\n        ecp_nistz256_scatter_w5  (row, &temp[2], 12);\n        ecp_nistz256_point_double(&temp[3], &temp[3]);\n        ecp_nistz256_scatter_w5  (row, &temp[3], 10);\n        ecp_nistz256_point_double(&temp[4], &temp[4]);\n        ecp_nistz256_scatter_w5  (row, &temp[4], 14);\n        ecp_nistz256_point_add   (&temp[2], &temp[2], &temp[0]);\n        ecp_nistz256_scatter_w5  (row, &temp[2], 13);\n        ecp_nistz256_point_add   (&temp[3], &temp[3], &temp[0]);\n        ecp_nistz256_scatter_w5  (row, &temp[3], 11);\n        ecp_nistz256_point_add   (&temp[4], &temp[4], &temp[0]);\n        ecp_nistz256_scatter_w5  (row, &temp[4], 15);\n        ecp_nistz256_point_add   (&temp[2], &temp[1], &temp[0]);\n        ecp_nistz256_scatter_w5  (row, &temp[2], 9);\n        ecp_nistz256_point_double(&temp[1], &temp[1]);\n        ecp_nistz256_scatter_w5  (row, &temp[1], 16);\n    }\n    idx = 255;\n    wvalue = p_str[0][(idx - 1) / 8];\n    wvalue = (wvalue >> ((idx - 1) % 8)) & mask;\n    ecp_nistz256_gather_w5(&temp[0], table[0], _booth_recode_w5(wvalue) >> 1);\n    memcpy(r, &temp[0], sizeof(temp[0]));\n    while (idx >= 5) {\n        for (i = (idx == 255 ? 1 : 0); i < num; i++) {\n            unsigned int off = (idx - 1) / 8;\n            wvalue = p_str[i][off] | p_str[i][off + 1] << 8;\n            wvalue = (wvalue >> ((idx - 1) % 8)) & mask;\n            wvalue = _booth_recode_w5(wvalue);\n            ecp_nistz256_gather_w5(&temp[0], table[i], wvalue >> 1);\n            ecp_nistz256_neg(temp[1].Y, temp[0].Y);\n            copy_conditional(temp[0].Y, temp[1].Y, (wvalue & 1));\n            ecp_nistz256_point_add(r, r, &temp[0]);\n        }\n        idx -= window_size;\n        ecp_nistz256_point_double(r, r);\n        ecp_nistz256_point_double(r, r);\n        ecp_nistz256_point_double(r, r);\n        ecp_nistz256_point_double(r, r);\n        ecp_nistz256_point_double(r, r);\n    }\n    for (i = 0; i < num; i++) {\n        wvalue = p_str[i][0];\n        wvalue = (wvalue << 1) & mask;\n        wvalue = _booth_recode_w5(wvalue);\n        ecp_nistz256_gather_w5(&temp[0], table[i], wvalue >> 1);\n        ecp_nistz256_neg(temp[1].Y, temp[0].Y);\n        copy_conditional(temp[0].Y, temp[1].Y, wvalue & 1);\n        ecp_nistz256_point_add(r, r, &temp[0]);\n    }\n    ret = 1;\n err:\n    OPENSSL_free(table_storage);\n    OPENSSL_free(p_str);\n    OPENSSL_free(scalars);\n    return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n    BIGNUM *ret;\n    CTXDBG_ENTRY("BN_CTX_get", ctx);\n    if (ctx->err_stack || ctx->too_many)\n        return NULL;\n    if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n        ctx->too_many = 1;\n        BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n        return NULL;\n    }\n    BN_zero(ret);\n    ctx->used++;\n    CTXDBG_RET(ctx, ret);\n    return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n    bn_check_top(a);\n    if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n        return (0);\n    a->neg = 0;\n    a->d[0] = w;\n    a->top = (w ? 1 : 0);\n    bn_check_top(a);\n    return (1);\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n    if (bits > (INT_MAX - BN_BITS2 + 1))\n        return NULL;\n    if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n        return a;\n    return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n    if (!(BN_mod(r, m, d, ctx)))\n        return 0;\n    if (!r->neg)\n        return 1;\n    return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n           BN_CTX *ctx)\n{\n    int norm_shift, i, loop;\n    BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n    BN_ULONG *resp, *wnump;\n    BN_ULONG d0, d1;\n    int num_n, div_n;\n    int no_branch = 0;\n    if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n        (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n        BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n        return 0;\n    }\n    bn_check_top(num);\n    bn_check_top(divisor);\n    if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n        || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n        no_branch = 1;\n    }\n    bn_check_top(dv);\n    bn_check_top(rm);\n    if (BN_is_zero(divisor)) {\n        BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n        return (0);\n    }\n    if (!no_branch && BN_ucmp(num, divisor) < 0) {\n        if (rm != NULL) {\n            if (BN_copy(rm, num) == NULL)\n                return (0);\n        }\n        if (dv != NULL)\n            BN_zero(dv);\n        return (1);\n    }\n    BN_CTX_start(ctx);\n    tmp = BN_CTX_get(ctx);\n    snum = BN_CTX_get(ctx);\n    sdiv = BN_CTX_get(ctx);\n    if (dv == NULL)\n        res = BN_CTX_get(ctx);\n    else\n        res = dv;\n    if (sdiv == NULL || res == NULL || tmp == NULL || snum == NULL)\n        goto err;\n    norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n    if (!(BN_lshift(sdiv, divisor, norm_shift)))\n        goto err;\n    sdiv->neg = 0;\n    norm_shift += BN_BITS2;\n    if (!(BN_lshift(snum, num, norm_shift)))\n        goto err;\n    snum->neg = 0;\n    if (no_branch) {\n        if (snum->top <= sdiv->top + 1) {\n            if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n                goto err;\n            for (i = snum->top; i < sdiv->top + 2; i++)\n                snum->d[i] = 0;\n            snum->top = sdiv->top + 2;\n        } else {\n            if (bn_wexpand(snum, snum->top + 1) == NULL)\n                goto err;\n            snum->d[snum->top] = 0;\n            snum->top++;\n        }\n    }\n    div_n = sdiv->top;\n    num_n = snum->top;\n    loop = num_n - div_n;\n    wnum.neg = 0;\n    wnum.d = &(snum->d[loop]);\n    wnum.top = div_n;\n    wnum.dmax = snum->dmax - loop;\n    d0 = sdiv->d[div_n - 1];\n    d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n    wnump = &(snum->d[num_n - 1]);\n    res->neg = (num->neg ^ divisor->neg);\n    if (!bn_wexpand(res, (loop + 1)))\n        goto err;\n    res->top = loop - no_branch;\n    resp = &(res->d[loop - 1]);\n    if (!bn_wexpand(tmp, (div_n + 1)))\n        goto err;\n    if (!no_branch) {\n        if (BN_ucmp(&wnum, sdiv) >= 0) {\n            bn_clear_top2max(&wnum);\n            bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n            *resp = 1;\n        } else\n            res->top--;\n    }\n    resp++;\n    if (res->top == 0)\n        res->neg = 0;\n    else\n        resp--;\n    for (i = 0; i < loop - 1; i++, wnump--) {\n        BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n        BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n        q = bn_div_3_words(wnump, d1, d0);\n# else\n        BN_ULONG n0, n1, rem = 0;\n        n0 = wnump[0];\n        n1 = wnump[-1];\n        if (n0 == d0)\n            q = BN_MASK2;\n        else {\n#  ifdef BN_LLONG\n            BN_ULLONG t2;\n#   if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n            q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n#   else\n            q = bn_div_words(n0, n1, d0);\n#   endif\n#   ifndef REMAINDER_IS_ALREADY_CALCULATED\n            rem = (n1 - q * d0) & BN_MASK2;\n#   endif\n            t2 = (BN_ULLONG) d1 *q;\n            for (;;) {\n                if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n                    break;\n                q--;\n                rem += d0;\n                if (rem < d0)\n                    break;\n                t2 -= d1;\n            }\n#  else\n            BN_ULONG t2l, t2h;\n            q = bn_div_words(n0, n1, d0);\n#   ifndef REMAINDER_IS_ALREADY_CALCULATED\n            rem = (n1 - q * d0) & BN_MASK2;\n#   endif\n#   if defined(BN_UMULT_LOHI)\n            BN_UMULT_LOHI(t2l, t2h, d1, q);\n#   elif defined(BN_UMULT_HIGH)\n            t2l = d1 * q;\n            t2h = BN_UMULT_HIGH(d1, q);\n#   else\n            {\n                BN_ULONG ql, qh;\n                t2l = LBITS(d1);\n                t2h = HBITS(d1);\n                ql = LBITS(q);\n                qh = HBITS(q);\n                mul64(t2l, t2h, ql, qh);\n            }\n#   endif\n            for (;;) {\n                if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n                    break;\n                q--;\n                rem += d0;\n                if (rem < d0)\n                    break;\n                if (t2l < d1)\n                    t2h--;\n                t2l -= d1;\n            }\n#  endif\n        }\n# endif\n        l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n        tmp->d[div_n] = l0;\n        wnum.d--;\n        if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n            q--;\n            if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n                (*wnump)++;\n        }\n        resp--;\n        *resp = q;\n    }\n    bn_correct_top(snum);\n    if (rm != NULL) {\n        int neg = num->neg;\n        BN_rshift(rm, snum, norm_shift);\n        if (!BN_is_zero(rm))\n            rm->neg = neg;\n        bn_check_top(rm);\n    }\n    if (no_branch)\n        bn_correct_top(res);\n    BN_CTX_end(ctx);\n    return (1);\n err:\n    bn_check_top(rm);\n    BN_CTX_end(ctx);\n    return (0);\n}', 'int BN_rshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n    int i, j, nw, lb, rb;\n    BN_ULONG *t, *f;\n    BN_ULONG l, tmp;\n    bn_check_top(r);\n    bn_check_top(a);\n    if (n < 0) {\n        BNerr(BN_F_BN_RSHIFT, BN_R_INVALID_SHIFT);\n        return 0;\n    }\n    nw = n / BN_BITS2;\n    rb = n % BN_BITS2;\n    lb = BN_BITS2 - rb;\n    if (nw >= a->top || a->top == 0) {\n        BN_zero(r);\n        return (1);\n    }\n    i = (BN_num_bits(a) - n + (BN_BITS2 - 1)) / BN_BITS2;\n    if (r != a) {\n        r->neg = a->neg;\n        if (bn_wexpand(r, i) == NULL)\n            return (0);\n    } else {\n        if (n == 0)\n            return 1;\n    }\n    f = &(a->d[nw]);\n    t = r->d;\n    j = a->top - nw;\n    r->top = i;\n    if (rb == 0) {\n        for (i = j; i != 0; i--)\n            *(t++) = *(f++);\n    } else {\n        l = *(f++);\n        for (i = j - 1; i != 0; i--) {\n            tmp = (l >> rb) & BN_MASK2;\n            l = *(f++);\n            *(t++) = (tmp | (l << lb)) & BN_MASK2;\n        }\n        if ((l = (l >> rb) & BN_MASK2))\n            *(t) = l;\n    }\n    bn_check_top(r);\n    return (1);\n}']