crypto/bn/bntest.c:1595: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned32 by call to `BN_GF2m_mod_sqr`.
Showing all 15 steps of the trace


crypto/bn/bntest.c:1572:1: Parameter `ctx->stack.depth`
1570.   }
1571.   
1572. > int test_gf2m_mod_sqrt(BIO *bp, BN_CTX *ctx)
1573.   {
1574.       BIGNUM *a, *b[2], *c, *d, *e, *f;

crypto/bn/bntest.c:1594:13: Call
1592.           for (j = 0; j < 2; j++) {
1593.               BN_GF2m_mod(c, a, b[j]);
1594.               BN_GF2m_mod_sqrt(d, a, b[j], ctx);
                    ^
1595.               BN_GF2m_mod_sqr(e, d, b[j], ctx);
1596.   # if 0                          /* make test uses ouput in bc but bc can't

crypto/bn/bn_gf2m.c:1083:1: Parameter `ctx->stack.depth`
  1081.    * for best performance, use the BN_GF2m_mod_sqrt_arr function.
  1082.    */
  1083. > int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
  1084.   {
  1085.       int ret = 0;

crypto/bn/bntest.c:1595:13: Call
1593.               BN_GF2m_mod(c, a, b[j]);
1594.               BN_GF2m_mod_sqrt(d, a, b[j], ctx);
1595.               BN_GF2m_mod_sqr(e, d, b[j], ctx);
                    ^
1596.   # if 0                          /* make test uses ouput in bc but bc can't
1597.                                    * handle GF(2^m) arithmetic */

crypto/bn/bn_gf2m.c:605:1: Parameter `ctx->stack.depth`
  603.    * use the BN_GF2m_mod_sqr_arr function.
  604.    */
  605. > int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
  606.   {
  607.       int ret = 0;

crypto/bn/bn_gf2m.c:620:11: Call
  618.           goto err;
  619.       }
  620.       ret = BN_GF2m_mod_sqr_arr(r, a, arr, ctx);
                   ^
  621.       bn_check_top(r);
  622.    err:

crypto/bn/bn_gf2m.c:570:1: Parameter `ctx->stack.depth`
    568.   
    569.   /* Square a, reduce the result mod p, and store it in a.  r could be a. */
    570. > int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[],
    571.                           BN_CTX *ctx)
    572.   {

crypto/bn/bn_gf2m.c:577:5: Call
    575.   
    576.       bn_check_top(a);
    577.       BN_CTX_start(ctx);
               ^
    578.       if ((s = BN_CTX_get(ctx)) == NULL)
    579.           return 0;

crypto/bn/bn_ctx.c:253:1: Parameter `ctx->stack.depth`
      251.   }
      252.   
      253. > void BN_CTX_start(BN_CTX *ctx)
      254.   {
      255.       CTXDBG_ENTRY("BN_CTX_start", ctx);

crypto/bn/bn_gf2m.c:595:5: Call
    593.       ret = 1;
    594.    err:
    595.       BN_CTX_end(ctx);
               ^
    596.       return ret;
    597.   }

crypto/bn/bn_ctx.c:267:1: Parameter `ctx->stack.depth`
      265.   }
      266.   
      267. > void BN_CTX_end(BN_CTX *ctx)
      268.   {
      269.       CTXDBG_ENTRY("BN_CTX_end", ctx);

crypto/bn/bn_ctx.c:273:27: Call
      271.           ctx->err_stack--;
      272.       else {
      273.           unsigned int fp = BN_STACK_pop(&ctx->stack);
                                       ^
      274.           /* Does this stack frame have anything to release? */
      275.           if (fp < ctx->used)

crypto/bn/bn_ctx.c:351:1: <LHS trace>
349.   }
350.   
351. > static unsigned int BN_STACK_pop(BN_STACK *st)
352.   {
353.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:351:1: Parameter `st->depth`
        349.   }
        350.   
        351. > static unsigned int BN_STACK_pop(BN_STACK *st)
        352.   {
        353.       return st->indexes[--(st->depth)];

crypto/bn/bn_ctx.c:353:12: Binary operation: ([0, +oo] - 1):unsigned32 by call to `BN_GF2m_mod_sqr` 
        351.   static unsigned int BN_STACK_pop(BN_STACK *st)
        352.   {
        353.       return st->indexes[--(st->depth)];
                          ^
        354.   }
        355.   

static unsigned int BN_STACK_pop(BN_STACK *st)
{
    return st->indexes[--(st->depth)];
}
['int test_gf2m_mod_sqrt(BIO *bp, BN_CTX *ctx)\n{\n    BIGNUM *a, *b[2], *c, *d, *e, *f;\n    int i, j, ret = 0;\n    int p0[] = { 163, 7, 6, 3, 0, -1 };\n    int p1[] = { 193, 15, 0, -1 };\n    a = BN_new();\n    b[0] = BN_new();\n    b[1] = BN_new();\n    c = BN_new();\n    d = BN_new();\n    e = BN_new();\n    f = BN_new();\n    BN_GF2m_arr2poly(p0, b[0]);\n    BN_GF2m_arr2poly(p1, b[1]);\n    for (i = 0; i < num0; i++) {\n        BN_bntest_rand(a, 512, 0, 0);\n        for (j = 0; j < 2; j++) {\n            BN_GF2m_mod(c, a, b[j]);\n            BN_GF2m_mod_sqrt(d, a, b[j], ctx);\n            BN_GF2m_mod_sqr(e, d, b[j], ctx);\n# if 0\n            if (bp != NULL) {\n                if (!results) {\n                    BN_print(bp, d);\n                    BIO_puts(bp, " ^ 2 - ");\n                    BN_print(bp, a);\n                    BIO_puts(bp, "\\n");\n                }\n            }\n# endif\n            BN_GF2m_add(f, c, e);\n            if (!BN_is_zero(f)) {\n                fprintf(stderr, "GF(2^m) modular square root test failed!\\n");\n                goto err;\n            }\n        }\n    }\n    ret = 1;\n err:\n    BN_free(a);\n    BN_free(b[0]);\n    BN_free(b[1]);\n    BN_free(c);\n    BN_free(d);\n    BN_free(e);\n    BN_free(f);\n    return ret;\n}', 'int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)\n{\n    int ret = 0;\n    const int max = BN_num_bits(p) + 1;\n    int *arr = NULL;\n    bn_check_top(a);\n    bn_check_top(p);\n    if ((arr = (int *)OPENSSL_malloc(sizeof(int) * max)) == NULL)\n        goto err;\n    ret = BN_GF2m_poly2arr(p, arr, max);\n    if (!ret || ret > max) {\n        BNerr(BN_F_BN_GF2M_MOD_SQRT, BN_R_INVALID_LENGTH);\n        goto err;\n    }\n    ret = BN_GF2m_mod_sqrt_arr(r, a, arr, ctx);\n    bn_check_top(r);\n err:\n    if (arr)\n        OPENSSL_free(arr);\n    return ret;\n}', 'int BN_GF2m_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)\n{\n    int ret = 0;\n    const int max = BN_num_bits(p) + 1;\n    int *arr = NULL;\n    bn_check_top(a);\n    bn_check_top(p);\n    if ((arr = (int *)OPENSSL_malloc(sizeof(int) * max)) == NULL)\n        goto err;\n    ret = BN_GF2m_poly2arr(p, arr, max);\n    if (!ret || ret > max) {\n        BNerr(BN_F_BN_GF2M_MOD_SQR, BN_R_INVALID_LENGTH);\n        goto err;\n    }\n    ret = BN_GF2m_mod_sqr_arr(r, a, arr, ctx);\n    bn_check_top(r);\n err:\n    if (arr)\n        OPENSSL_free(arr);\n    return ret;\n}', 'int BN_GF2m_mod_sqr_arr(BIGNUM *r, const BIGNUM *a, const int p[],\n                        BN_CTX *ctx)\n{\n    int i, ret = 0;\n    BIGNUM *s;\n    bn_check_top(a);\n    BN_CTX_start(ctx);\n    if ((s = BN_CTX_get(ctx)) == NULL)\n        return 0;\n    if (!bn_wexpand(s, 2 * a->top))\n        goto err;\n    for (i = a->top - 1; i >= 0; i--) {\n        s->d[2 * i + 1] = SQR1(a->d[i]);\n        s->d[2 * i] = SQR0(a->d[i]);\n    }\n    s->top = 2 * a->top;\n    bn_correct_top(s);\n    if (!BN_GF2m_mod_arr(r, s, p))\n        goto err;\n    bn_check_top(r);\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return ret;\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}']