test/bntest.c:1556: error: BUFFER_OVERRUN_L3
  Offset: [1, +oo] Size: [0, 8388607] by call to `BN_GF2m_mod_sqrt`.
Showing all 14 steps of the trace


test/bntest.c:1555:13: Call
1553.           BN_bntest_rand(a, 512, 0, 0);
1554.           for (j = 0; j < 2; j++) {
1555.               BN_GF2m_mod(c, a, b[j]);
                    ^
1556.               BN_GF2m_mod_sqrt(d, a, b[j], ctx);
1557.               BN_GF2m_mod_sqr(e, d, b[j], ctx);

crypto/bn/bn_gf2m.c:469:1: Parameter `r->top`
  467.    * BN_GF2m_mod_arr function.
  468.    */
  469. > int BN_GF2m_mod(BIGNUM *r, const BIGNUM *a, const BIGNUM *p)
  470.   {
  471.       int ret = 0;

test/bntest.c:1556:13: Call
1554.           for (j = 0; j < 2; j++) {
1555.               BN_GF2m_mod(c, a, b[j]);
1556.               BN_GF2m_mod_sqrt(d, a, b[j], ctx);
                    ^
1557.               BN_GF2m_mod_sqr(e, d, b[j], ctx);
1558.               BN_GF2m_add(f, c, e);

crypto/bn/bn_gf2m.c:1087:1: Parameter `*a->d`
  1085.    * for best performance, use the BN_GF2m_mod_sqrt_arr function.
  1086.    */
  1087. > int BN_GF2m_mod_sqrt(BIGNUM *r, const BIGNUM *a, const BIGNUM *p, BN_CTX *ctx)
  1088.   {
  1089.       int ret = 0;

crypto/bn/bn_gf2m.c:1101:11: Call
  1099.           goto err;
  1100.       }
  1101.       ret = BN_GF2m_mod_sqrt_arr(r, a, arr, ctx);
                    ^
  1102.       bn_check_top(r);
  1103.    err:

crypto/bn/bn_gf2m.c:1053:1: Parameter `*a->d`
    1051.    * r could be a. Uses exponentiation as in algorithm A.4.1 from IEEE P1363.
    1052.    */
    1053. > int BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a, const int p[],
    1054.                            BN_CTX *ctx)
    1055.   {

crypto/bn/bn_gf2m.c:1073:11: Call
    1071.       if (!BN_set_bit(u, p[0] - 1))
    1072.           goto err;
    1073.       ret = BN_GF2m_mod_exp_arr(r, a, u, p, ctx);
                      ^
    1074.       bn_check_top(r);
    1075.   

crypto/bn/bn_gf2m.c:980:1: Parameter `*a->d`
      978.    * P1363.
      979.    */
      980. > int BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
      981.                           const int p[], BN_CTX *ctx)
      982.   {

crypto/bn/bn_gf2m.c:1007:18: Call
      1005.               goto err;
      1006.           if (BN_is_bit_set(b, i)) {
      1007.               if (!BN_GF2m_mod_mul_arr(u, u, a, p, ctx))
                               ^
      1008.                   goto err;
      1009.           }

crypto/bn/bn_gf2m.c:489:1: <Offset trace>
487.    * the result in r.  r could be a or b; a could be b.
488.    */
489. > int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
490.                           const int p[], BN_CTX *ctx)
491.   {

crypto/bn/bn_gf2m.c:489:1: Parameter `b->top`
        487.    * the result in r.  r could be a or b; a could be b.
        488.    */
        489. > int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
        490.                           const int p[], BN_CTX *ctx)
        491.   {

crypto/bn/bn_gf2m.c:489:1: <Length trace>
487.    * the result in r.  r could be a or b; a could be b.
488.    */
489. > int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
490.                           const int p[], BN_CTX *ctx)
491.   {

crypto/bn/bn_gf2m.c:489:1: Parameter `*b->d`
        487.    * the result in r.  r could be a or b; a could be b.
        488.    */
        489. > int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
        490.                           const int p[], BN_CTX *ctx)
        491.   {

crypto/bn/bn_gf2m.c:517:40: Array access: Offset: [1, +oo] Size: [0, 8388607] by call to `BN_GF2m_mod_sqrt` 
        515.       for (j = 0; j < b->top; j += 2) {
        516.           y0 = b->d[j];
        517.           y1 = ((j + 1) == b->top) ? 0 : b->d[j + 1];
                                                      ^
        518.           for (i = 0; i < a->top; i += 2) {
        519.               x0 = a->d[i];

int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,
                        const int p[], BN_CTX *ctx)
{
    int zlen, i, j, k, ret = 0;
    BIGNUM *s;
    BN_ULONG x1, x0, y1, y0, zz[4];
    bn_check_top(a);
    bn_check_top(b);
    if (a == b) {
        return BN_GF2m_mod_sqr_arr(r, a, p, ctx);
    }
    BN_CTX_start(ctx);
    if ((s = BN_CTX_get(ctx)) == NULL)
        goto err;
    zlen = a->top + b->top + 4;
    if (!bn_wexpand(s, zlen))
        goto err;
    s->top = zlen;
    for (i = 0; i < zlen; i++)
        s->d[i] = 0;
    for (j = 0; j < b->top; j += 2) {
        y0 = b->d[j];
        y1 = ((j + 1) == b->top) ? 0 : b->d[j + 1];
        for (i = 0; i < a->top; i += 2) {
            x0 = a->d[i];
            x1 = ((i + 1) == a->top) ? 0 : a->d[i + 1];
            bn_GF2m_mul_2x2(zz, x1, x0, y1, y0);
            for (k = 0; k < 4; k++)
                s->d[i + j + k] ^= zz[k];
        }
    }
    bn_correct_top(s);
    if (BN_GF2m_mod_arr(r, s, p))
        ret = 1;
    bn_check_top(r);
 err:
    BN_CTX_end(ctx);
    return ret;
}
['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            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(BIGNUM *r, const BIGNUM *a, const BIGNUM *p)\n{\n    int ret = 0;\n    int arr[6];\n    bn_check_top(a);\n    bn_check_top(p);\n    ret = BN_GF2m_poly2arr(p, arr, OSSL_NELEM(arr));\n    if (!ret || ret > (int)OSSL_NELEM(arr)) {\n        BNerr(BN_F_BN_GF2M_MOD, BN_R_INVALID_LENGTH);\n        return 0;\n    }\n    ret = BN_GF2m_mod_arr(r, a, arr);\n    bn_check_top(r);\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 = OPENSSL_malloc(sizeof(*arr) * 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    OPENSSL_free(arr);\n    return ret;\n}', 'int BN_GF2m_mod_sqrt_arr(BIGNUM *r, const BIGNUM *a, const int p[],\n                         BN_CTX *ctx)\n{\n    int ret = 0;\n    BIGNUM *u;\n    bn_check_top(a);\n    if (!p[0]) {\n        BN_zero(r);\n        return 1;\n    }\n    BN_CTX_start(ctx);\n    if ((u = BN_CTX_get(ctx)) == NULL)\n        goto err;\n    if (!BN_set_bit(u, p[0] - 1))\n        goto err;\n    ret = BN_GF2m_mod_exp_arr(r, a, u, p, ctx);\n    bn_check_top(r);\n err:\n    BN_CTX_end(ctx);\n    return ret;\n}', 'int BN_GF2m_mod_exp_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n                        const int p[], BN_CTX *ctx)\n{\n    int ret = 0, i, n;\n    BIGNUM *u;\n    bn_check_top(a);\n    bn_check_top(b);\n    if (BN_is_zero(b))\n        return (BN_one(r));\n    if (BN_abs_is_word(b, 1))\n        return (BN_copy(r, a) != NULL);\n    BN_CTX_start(ctx);\n    if ((u = BN_CTX_get(ctx)) == NULL)\n        goto err;\n    if (!BN_GF2m_mod_arr(u, a, p))\n        goto err;\n    n = BN_num_bits(b) - 1;\n    for (i = n - 1; i >= 0; i--) {\n        if (!BN_GF2m_mod_sqr_arr(u, u, p, ctx))\n            goto err;\n        if (BN_is_bit_set(b, i)) {\n            if (!BN_GF2m_mod_mul_arr(u, u, a, p, ctx))\n                goto err;\n        }\n    }\n    if (!BN_copy(r, u))\n        goto err;\n    bn_check_top(r);\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    return ret;\n}', 'int BN_GF2m_mod_mul_arr(BIGNUM *r, const BIGNUM *a, const BIGNUM *b,\n                        const int p[], BN_CTX *ctx)\n{\n    int zlen, i, j, k, ret = 0;\n    BIGNUM *s;\n    BN_ULONG x1, x0, y1, y0, zz[4];\n    bn_check_top(a);\n    bn_check_top(b);\n    if (a == b) {\n        return BN_GF2m_mod_sqr_arr(r, a, p, ctx);\n    }\n    BN_CTX_start(ctx);\n    if ((s = BN_CTX_get(ctx)) == NULL)\n        goto err;\n    zlen = a->top + b->top + 4;\n    if (!bn_wexpand(s, zlen))\n        goto err;\n    s->top = zlen;\n    for (i = 0; i < zlen; i++)\n        s->d[i] = 0;\n    for (j = 0; j < b->top; j += 2) {\n        y0 = b->d[j];\n        y1 = ((j + 1) == b->top) ? 0 : b->d[j + 1];\n        for (i = 0; i < a->top; i += 2) {\n            x0 = a->d[i];\n            x1 = ((i + 1) == a->top) ? 0 : a->d[i + 1];\n            bn_GF2m_mul_2x2(zz, x1, x0, y1, y0);\n            for (k = 0; k < 4; k++)\n                s->d[i + j + k] ^= zz[k];\n        }\n    }\n    bn_correct_top(s);\n    if (BN_GF2m_mod_arr(r, s, p))\n        ret = 1;\n    bn_check_top(r);\n err:\n    BN_CTX_end(ctx);\n    return ret;\n}']