crypto/ec/ec_mult.c:298: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned64 by call to `BN_consttime_swap`.
Showing all 7 steps of the trace


crypto/ec/ec_mult.c:297:16: Call
295.   
296.       for (i = order_bits - 1; i >= 0; i--) {
297.           kbit = BN_is_bit_set(k, i) ^ pbit;
                      ^
298.           EC_POINT_CSWAP(kbit, r, s, group_top, Z_is_one);
299.           if (!EC_POINT_add(group, s, r, s, ctx))

crypto/bn/bn_lib.c:632:9: Assignment
  630.       bn_check_top(a);
  631.       if (n < 0)
  632.           return 0;
                 ^
  633.       i = n / BN_BITS2;
  634.       j = n % BN_BITS2;

crypto/ec/ec_mult.c:297:9: Assignment
295.   
296.       for (i = order_bits - 1; i >= 0; i--) {
297.           kbit = BN_is_bit_set(k, i) ^ pbit;
               ^
298.           EC_POINT_CSWAP(kbit, r, s, group_top, Z_is_one);
299.           if (!EC_POINT_add(group, s, r, s, ctx))

crypto/ec/ec_mult.c:298:9: Call
296.       for (i = order_bits - 1; i >= 0; i--) {
297.           kbit = BN_is_bit_set(k, i) ^ pbit;
298.           EC_POINT_CSWAP(kbit, r, s, group_top, Z_is_one);
               ^
299.           if (!EC_POINT_add(group, s, r, s, ctx))
300.               goto err;

crypto/bn/bn_lib.c:724:1: <LHS trace>
722.    * a and b cannot be the same number
723.    */
724. > void BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)
725.   {
726.       BN_ULONG t;

crypto/bn/bn_lib.c:724:1: Parameter `condition`
  722.    * a and b cannot be the same number
  723.    */
  724. > void BN_consttime_swap(BN_ULONG condition, BIGNUM *a, BIGNUM *b, int nwords)
  725.   {
  726.       BN_ULONG t;

crypto/bn/bn_lib.c:736:5: Binary operation: ([0, +oo] - 1):unsigned64 by call to `BN_consttime_swap` 
  734.       assert(sizeof(BN_ULONG) >= sizeof(int));
  735.   
  736.       condition = ((condition - 1) >> (BN_BITS2 - 1)) - 1;
             ^
  737.   
  738.       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) & condition & BN_FLG_CONSTTIME;
    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 ec_mul_consttime(const EC_GROUP *group, EC_POINT *r,\n                            const BIGNUM *scalar, const EC_POINT *point,\n                            BN_CTX *ctx)\n{\n    int i, order_bits, group_top, kbit, pbit, Z_is_one;\n    EC_POINT *s = NULL;\n    BIGNUM *k = NULL;\n    BIGNUM *lambda = NULL;\n    BN_CTX *new_ctx = NULL;\n    int ret = 0;\n    if (ctx == NULL && (ctx = new_ctx = BN_CTX_secure_new()) == NULL)\n        goto err;\n    if ((group->order == NULL) || (group->field == NULL))\n        goto err;\n    order_bits = BN_num_bits(group->order);\n    s = EC_POINT_new(group);\n    if (s == NULL)\n        goto err;\n    if (point == NULL) {\n        if (group->generator == NULL)\n            goto err;\n        if (!EC_POINT_copy(s, group->generator))\n            goto err;\n    } else {\n        if (!EC_POINT_copy(s, point))\n            goto err;\n    }\n    EC_POINT_BN_set_flags(s, BN_FLG_CONSTTIME);\n    BN_CTX_start(ctx);\n    lambda = BN_CTX_get(ctx);\n    k = BN_CTX_get(ctx);\n    if (k == NULL)\n        goto err;\n    group_top = bn_get_top(group->order);\n    if ((bn_wexpand(k, group_top + 1) == NULL)\n        || (bn_wexpand(lambda, group_top + 1) == NULL))\n        goto err;\n    if (!BN_copy(k, scalar))\n        goto err;\n    BN_set_flags(k, BN_FLG_CONSTTIME);\n    if ((BN_num_bits(k) > order_bits) || (BN_is_negative(k))) {\n        if (!BN_nnmod(k, k, group->order, ctx))\n            goto err;\n    }\n    if (!BN_add(lambda, k, group->order))\n        goto err;\n    BN_set_flags(lambda, BN_FLG_CONSTTIME);\n    if (!BN_add(k, lambda, group->order))\n        goto err;\n    kbit = BN_is_bit_set(lambda, order_bits);\n    BN_consttime_swap(kbit, k, lambda, group_top + 1);\n    group_top = bn_get_top(group->field);\n    if ((bn_wexpand(s->X, group_top) == NULL)\n        || (bn_wexpand(s->Y, group_top) == NULL)\n        || (bn_wexpand(s->Z, group_top) == NULL)\n        || (bn_wexpand(r->X, group_top) == NULL)\n        || (bn_wexpand(r->Y, group_top) == NULL)\n        || (bn_wexpand(r->Z, group_top) == NULL))\n        goto err;\n    if (!EC_POINT_copy(r, s))\n        goto err;\n    EC_POINT_BN_set_flags(r, BN_FLG_CONSTTIME);\n    if (!EC_POINT_dbl(group, s, s, ctx))\n        goto err;\n    pbit = 0;\n#define EC_POINT_CSWAP(c, a, b, w, t) do {         \\\n        BN_consttime_swap(c, (a)->X, (b)->X, w);   \\\n        BN_consttime_swap(c, (a)->Y, (b)->Y, w);   \\\n        BN_consttime_swap(c, (a)->Z, (b)->Z, w);   \\\n        t = ((a)->Z_is_one ^ (b)->Z_is_one) & (c); \\\n        (a)->Z_is_one ^= (t);                      \\\n        (b)->Z_is_one ^= (t);                      \\\n} while(0)\n    for (i = order_bits - 1; i >= 0; i--) {\n        kbit = BN_is_bit_set(k, i) ^ pbit;\n        EC_POINT_CSWAP(kbit, r, s, group_top, Z_is_one);\n        if (!EC_POINT_add(group, s, r, s, ctx))\n            goto err;\n        if (!EC_POINT_dbl(group, r, r, ctx))\n            goto err;\n        pbit ^= kbit;\n    }\n    EC_POINT_CSWAP(pbit, r, s, group_top, Z_is_one);\n#undef EC_POINT_CSWAP\n    ret = 1;\n err:\n    EC_POINT_free(s);\n    BN_CTX_end(ctx);\n    BN_CTX_free(new_ctx);\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) & condition & BN_FLG_CONSTTIME;\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}']