crypto/ec/ecp_nistz256.c:619: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned32 by call to `BN_nnmod`.
Showing all 13 steps of the trace


crypto/ec/ecp_nistz256.c:579:8: Parameter `ctx->stack.depth`
577.   
578.   /* r = sum(scalar[i]*point[i]) */
579.   __owur static int ecp_nistz256_windowed_mul(const EC_GROUP *group,
              ^
580.                                               P256_POINT *r,
581.                                               const BIGNUM **scalar,

crypto/ec/ecp_nistz256.c:619:18: Call
617.               if ((mod = BN_CTX_get(ctx)) == NULL)
618.                   goto err;
619.               if (!BN_nnmod(mod, scalar[i], group->order, ctx)) {
                        ^
620.                   ECerr(EC_F_ECP_NISTZ256_WINDOWED_MUL, ERR_R_BN_LIB);
621.                   goto err;

crypto/bn/bn_mod.c:13:1: Parameter `ctx->stack.depth`
  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:188:1: Parameter `ctx->stack.depth`
    186.    * If 'dv' or 'rm' is NULL, the respective value is not returned.
    187.    */
    188. > int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
    189.              BN_CTX *ctx)
    190.   {

crypto/bn/bn_div.c:241:5: Call
    239.       }
    240.   
    241.       BN_CTX_start(ctx);
               ^
    242.       res = (dv == NULL) ? BN_CTX_get(ctx) : dv;
    243.       tmp = BN_CTX_get(ctx);

crypto/bn/bn_ctx.c:181:1: Parameter `ctx->stack.depth`
      179.   }
      180.   
      181. > void BN_CTX_start(BN_CTX *ctx)
      182.   {
      183.       CTXDBG_ENTRY("BN_CTX_start", ctx);

crypto/bn/bn_div.c:463:5: Call
    461.       if (no_branch)
    462.           bn_correct_top(res);
    463.       BN_CTX_end(ctx);
               ^
    464.       return 1;
    465.    err:

crypto/bn/bn_ctx.c:195:1: Parameter `ctx->stack.depth`
      193.   }
      194.   
      195. > void BN_CTX_end(BN_CTX *ctx)
      196.   {
      197.       CTXDBG_ENTRY("BN_CTX_end", ctx);

crypto/bn/bn_ctx.c:201:27: Call
      199.           ctx->err_stack--;
      200.       else {
      201.           unsigned int fp = BN_STACK_pop(&ctx->stack);
                                       ^
      202.           /* Does this stack frame have anything to release? */
      203.           if (fp < ctx->used)

crypto/bn/bn_ctx.c:274:1: <LHS trace>
272.   }
273.   
274. > static unsigned int BN_STACK_pop(BN_STACK *st)
275.   {
276.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:274:1: Parameter `st->depth`
        272.   }
        273.   
        274. > static unsigned int BN_STACK_pop(BN_STACK *st)
        275.   {
        276.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:276:12: Binary operation: ([0, +oo] - 1):unsigned32 by call to `BN_nnmod` 
        274.   static unsigned int BN_STACK_pop(BN_STACK *st)
        275.   {
        276.       return st->indexes[--(st->depth)];
                          ^
        277.   }
        278.   

static unsigned int BN_STACK_pop(BN_STACK *st)
{
    return st->indexes[--(st->depth)];
}
['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}', '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, j, 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    res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n    tmp = BN_CTX_get(ctx);\n    snum = BN_CTX_get(ctx);\n    sdiv = BN_CTX_get(ctx);\n    if (sdiv == 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.flags = BN_FLG_STATIC_DATA;\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    if (!bn_wexpand(res, (loop + 1)))\n        goto err;\n    res->neg = (num->neg ^ divisor->neg);\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)\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        l0 = bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1);\n        q -= l0;\n        for (l0 = 0 - l0, j = 0; j < div_n; j++)\n            tmp->d[j] = sdiv->d[j] & l0;\n        l0 = bn_add_words(wnum.d, wnum.d, tmp->d, div_n);\n        (*wnump) += l0;\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}', 'void BN_CTX_start(BN_CTX *ctx)\n{\n    CTXDBG_ENTRY("BN_CTX_start", ctx);\n    if (ctx->err_stack || ctx->too_many)\n        ctx->err_stack++;\n    else if (!BN_STACK_push(&ctx->stack, ctx->used)) {\n        BNerr(BN_F_BN_CTX_START, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n        ctx->err_stack++;\n    }\n    CTXDBG_EXIT(ctx);\n}', 'void BN_CTX_end(BN_CTX *ctx)\n{\n    CTXDBG_ENTRY("BN_CTX_end", ctx);\n    if (ctx->err_stack)\n        ctx->err_stack--;\n    else {\n        unsigned int fp = BN_STACK_pop(&ctx->stack);\n        if (fp < ctx->used)\n            BN_POOL_release(&ctx->pool, ctx->used - fp);\n        ctx->used = fp;\n        ctx->too_many = 0;\n    }\n    CTXDBG_EXIT(ctx);\n}', 'static unsigned int BN_STACK_pop(BN_STACK *st)\n{\n    return st->indexes[--(st->depth)];\n}']