crypto/dsa/dsa_ossl.c:252: error: INTEGER_OVERFLOW_L2
  ([0, 1] - 1):unsigned64 by call to `BN_consttime_swap`.
Showing all 6 steps of the trace


crypto/dsa/dsa_ossl.c:252:23: Call
250.           goto err;
251.   
252.       BN_consttime_swap(BN_is_bit_set(l, q_bits), k, l, q_words + 2);
                             ^
253.   
254.       if ((dsa)->meth->bn_mod_exp != NULL) {

crypto/bn/bn_lib.c:655:9: Assignment
  653.       bn_check_top(a);
  654.       if (n < 0)
  655.           return 0;
                 ^
  656.       i = n / BN_BITS2;
  657.       j = n % BN_BITS2;

crypto/dsa/dsa_ossl.c:252:5: Call
250.           goto err;
251.   
252.       BN_consttime_swap(BN_is_bit_set(l, q_bits), k, l, q_words + 2);
           ^
253.   
254.       if ((dsa)->meth->bn_mod_exp != NULL) {

crypto/bn/bn_lib.c:747:1: <LHS trace>
745.    * a and b cannot be the same number
746.    */
747. > void BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)
748.   {
749.       BN_ULONG t;

crypto/bn/bn_lib.c:747:1: Parameter `condition`
  745.    * a and b cannot be the same number
  746.    */
  747. > void BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)
  748.   {
  749.       BN_ULONG t;

crypto/bn/bn_lib.c:759:5: Binary operation: ([0, 1] - 1):unsigned64 by call to `BN_consttime_swap` 
  757.       assert(sizeof(BN_ULONG) >= sizeof(int));
  758.   
  759.       condition = ((condition - 1) >> (BN_BITS2 - 1)) - 1;
             ^
  760.   
  761.       t = (a->top ^ b->top) & condition;

void BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)
{
    BN_ULONG t;
    int i;
    bn_wcheck_size(a, nwords);
    bn_wcheck_size(b, nwords);
    assert(a != b);
    assert((condition & (condition - 1)) == 0);
    assert(sizeof(BN_ULONG) >= sizeof(int));
    condition = ((condition - 1) >> (BN_BITS2 - 1)) - 1;
    t = (a->top ^ b->top) & condition;
    a->top ^= t;
    b->top ^= t;
    t = (a->neg ^ b->neg) & condition;
    a->neg ^= t;
    b->neg ^= t;
    t = ((a->flags ^ b->flags) & BN_FLG_CONSTTIME) & condition;
    a->flags ^= t;
    b->flags ^= t;
#define BN_CONSTTIME_SWAP(ind) \
        do { \
                t = (a->d[ind] ^ b->d[ind]) & condition; \
                a->d[ind] ^= t; \
                b->d[ind] ^= t; \
        } while (0)
    switch (nwords) {
    default:
        for (i = 10; i < nwords; i++)
            BN_CONSTTIME_SWAP(i);
    case 10:
        BN_CONSTTIME_SWAP(9);
    case 9:
        BN_CONSTTIME_SWAP(8);
    case 8:
        BN_CONSTTIME_SWAP(7);
    case 7:
        BN_CONSTTIME_SWAP(6);
    case 6:
        BN_CONSTTIME_SWAP(5);
    case 5:
        BN_CONSTTIME_SWAP(4);
    case 4:
        BN_CONSTTIME_SWAP(3);
    case 3:
        BN_CONSTTIME_SWAP(2);
    case 2:
        BN_CONSTTIME_SWAP(1);
    case 1:
        BN_CONSTTIME_SWAP(0);
    }
#undef BN_CONSTTIME_SWAP
}
['static int dsa_sign_setup(DSA *dsa, BN_CTX *ctx_in,\n                          BIGNUM **kinvp, BIGNUM **rp,\n                          const unsigned char *dgst, int dlen)\n{\n    BN_CTX *ctx = NULL;\n    BIGNUM *k, *kinv = NULL, *r = *rp;\n    BIGNUM *l;\n    int ret = 0;\n    int q_bits, q_words;\n    if (!dsa->p || !dsa->q || !dsa->g) {\n        DSAerr(DSA_F_DSA_SIGN_SETUP, DSA_R_MISSING_PARAMETERS);\n        return 0;\n    }\n    k = BN_new();\n    l = BN_new();\n    if (k == NULL || l == NULL)\n        goto err;\n    if (ctx_in == NULL) {\n        if ((ctx = BN_CTX_new()) == NULL)\n            goto err;\n    } else\n        ctx = ctx_in;\n    q_bits = BN_num_bits(dsa->q);\n    q_words = bn_get_top(dsa->q);\n    if (!bn_wexpand(k, q_words + 2)\n        || !bn_wexpand(l, q_words + 2))\n        goto err;\n    do {\n        if (dgst != NULL) {\n            if (!BN_generate_dsa_nonce(k, dsa->q, dsa->priv_key, dgst,\n                                       dlen, ctx))\n                goto err;\n        } else if (!BN_priv_rand_range(k, dsa->q))\n            goto err;\n    } while (BN_is_zero(k));\n    BN_set_flags(k, BN_FLG_CONSTTIME);\n    if (dsa->flags & DSA_FLAG_CACHE_MONT_P) {\n        if (!BN_MONT_CTX_set_locked(&dsa->method_mont_p,\n                                    dsa->lock, dsa->p, ctx))\n            goto err;\n    }\n    if (!BN_add(l, k, dsa->q)\n        || !BN_add(k, l, dsa->q))\n        goto err;\n    BN_consttime_swap(BN_is_bit_set(l, q_bits), k, l, q_words + 2);\n    if ((dsa)->meth->bn_mod_exp != NULL) {\n            if (!dsa->meth->bn_mod_exp(dsa, r, dsa->g, k, dsa->p, ctx,\n                                       dsa->method_mont_p))\n                goto err;\n    } else {\n            if (!BN_mod_exp_mont(r, dsa->g, k, dsa->p, ctx, dsa->method_mont_p))\n                goto err;\n    }\n    if (!BN_mod(r, r, dsa->q, ctx))\n        goto err;\n    if ((kinv = dsa_mod_inverse_fermat(k, dsa->q, ctx)) == NULL)\n        goto err;\n    BN_clear_free(*kinvp);\n    *kinvp = kinv;\n    kinv = NULL;\n    ret = 1;\n err:\n    if (!ret)\n        DSAerr(DSA_F_DSA_SIGN_SETUP, ERR_R_BN_LIB);\n    if (ctx != ctx_in)\n        BN_CTX_free(ctx);\n    BN_clear_free(k);\n    BN_clear_free(l);\n    return ret;\n}', 'int BN_is_bit_set(const BIGNUM *a, int n)\n{\n    int i, j;\n    bn_check_top(a);\n    if (n < 0)\n        return 0;\n    i = n / BN_BITS2;\n    j = n % BN_BITS2;\n    if (a->top <= i)\n        return 0;\n    return (int)(((a->d[i]) >> j) & ((BN_ULONG)1));\n}', 'void BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)\n{\n    BN_ULONG t;\n    int i;\n    bn_wcheck_size(a, nwords);\n    bn_wcheck_size(b, nwords);\n    assert(a != b);\n    assert((condition & (condition - 1)) == 0);\n    assert(sizeof(BN_ULONG) >= sizeof(int));\n    condition = ((condition - 1) >> (BN_BITS2 - 1)) - 1;\n    t = (a->top ^ b->top) & condition;\n    a->top ^= t;\n    b->top ^= t;\n    t = (a->neg ^ b->neg) & condition;\n    a->neg ^= t;\n    b->neg ^= t;\n    t = ((a->flags ^ b->flags) & BN_FLG_CONSTTIME) & condition;\n    a->flags ^= t;\n    b->flags ^= t;\n#define BN_CONSTTIME_SWAP(ind) \\\n        do { \\\n                t = (a->d[ind] ^ b->d[ind]) & condition; \\\n                a->d[ind] ^= t; \\\n                b->d[ind] ^= t; \\\n        } while (0)\n    switch (nwords) {\n    default:\n        for (i = 10; i < nwords; i++)\n            BN_CONSTTIME_SWAP(i);\n    case 10:\n        BN_CONSTTIME_SWAP(9);\n    case 9:\n        BN_CONSTTIME_SWAP(8);\n    case 8:\n        BN_CONSTTIME_SWAP(7);\n    case 7:\n        BN_CONSTTIME_SWAP(6);\n    case 6:\n        BN_CONSTTIME_SWAP(5);\n    case 5:\n        BN_CONSTTIME_SWAP(4);\n    case 4:\n        BN_CONSTTIME_SWAP(3);\n    case 3:\n        BN_CONSTTIME_SWAP(2);\n    case 2:\n        BN_CONSTTIME_SWAP(1);\n    case 1:\n        BN_CONSTTIME_SWAP(0);\n    }\n#undef BN_CONSTTIME_SWAP\n}']