test/ectest.c:204: error: BUFFER_OVERRUN_L3
  Offset: [16, +oo] (⇐ 1 + [15, +oo]) Size: [0, 8388607] by call to `EC_POINT_set_compressed_coordinates`.
Showing all 27 steps of the trace


test/ectest.c:165:13: Call
163.           || !TEST_ptr(a = BN_new())
164.           || !TEST_ptr(b = BN_new())
165.           || !TEST_true(BN_hex2bn(&p, "17"))
                   ^
166.           || !TEST_true(BN_hex2bn(&a, "1"))
167.           || !TEST_true(BN_hex2bn(&b, "1"))

crypto/bn/bn_conv.c:126:1: Parameter `(*bn)->top`
  124.   #endif
  125.   
  126. > int BN_hex2bn(BIGNUM **bn, const char *a)
  127.   {
  128.       BIGNUM *ret = NULL;

test/ectest.c:204:13: Call
202.           || !TEST_ptr(yplusone = BN_new())
203.           || !TEST_true(BN_hex2bn(&x, "D"))
204.           || !TEST_true(EC_POINT_set_compressed_coordinates(group, Q, x, 1, ctx)))
                   ^
205.           goto err;
206.   

crypto/ec/ec_oct.c:18:1: Parameter `x->top`
  16.   #include "ec_lcl.h"
  17.   
  18. > int EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point,
  19.                                           const BIGNUM *x, int y_bit, BN_CTX *ctx)
  20.   {

crypto/ec/ec_oct.c:34:20: Call
  32.       if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) {
  33.           if (group->meth->field_type == NID_X9_62_prime_field)
  34.               return ec_GFp_simple_set_compressed_coordinates(group, point, x,
                           ^
  35.                                                               y_bit, ctx);
  36.           else

crypto/ec/ecp_oct.c:37:12: Call
    35.   
    36.       BN_CTX_start(ctx);
    37.       tmp1 = BN_CTX_get(ctx);
                     ^
    38.       tmp2 = BN_CTX_get(ctx);
    39.       x = BN_CTX_get(ctx);

crypto/bn/bn_ctx.c:238:5: Call
      236.       }
      237.       /* OK, make sure the returned bignum is "zero" */
      238.       BN_zero(ret);
                 ^
      239.       /* clear BN_FLG_CONSTTIME if leaked from previous frames */
      240.       ret->flags &= (~BN_FLG_CONSTTIME);

crypto/bn/bn_lib.c:361:1: Parameter `*a->d`
        359.   }
        360.   
        361. > int BN_set_word(BIGNUM *a, BN_ULONG w)
        362.   {
        363.       bn_check_top(a);

crypto/bn/bn_lib.c:364:9: Call
        362.   {
        363.       bn_check_top(a);
        364.       if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)
                       ^
        365.           return 0;
        366.       a->neg = 0;

crypto/bn/bn_lcl.h:660:1: Parameter `*a->d`
          658.                            const BIGNUM *add, const BIGNUM *rem, BN_CTX *ctx);
          659.   
          660. > static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)
          661.   {
          662.       if (bits > (INT_MAX - BN_BITS2 + 1))

crypto/ec/ecp_oct.c:60:14: Call
    58.               goto err;
    59.       } else {
    60.           if (!BN_mod_sqr(tmp2, x_, group->field, ctx))
                       ^
    61.               goto err;
    62.           if (!BN_mod_mul(tmp1, tmp2, x_, group->field, ctx))

crypto/bn/bn_mod.c:222:1: Parameter `*r->d`
      220.   }
      221.   
      222. > int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
      223.   {
      224.       if (!BN_sqr(r, a, ctx))

crypto/bn/bn_mod.c:224:10: Call
      222.   int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
      223.   {
      224.       if (!BN_sqr(r, a, ctx))
                      ^
      225.           return 0;
      226.       /* r->neg == 0,  thus we don't need BN_nnmod */

crypto/bn/bn_sqr.c:17:1: Parameter `*r->d`
        15.    * I've just gone over this and it is now %20 faster on x86 - eay - 27 Jun 96
        16.    */
        17. > int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
        18.   {
        19.       int ret = bn_sqr_fixed_top(r, a, ctx);

crypto/bn/bn_sqr.c:19:15: Call
        17.   int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
        18.   {
        19.       int ret = bn_sqr_fixed_top(r, a, ctx);
                            ^
        20.   
        21.       bn_correct_top(r);

crypto/bn/bn_sqr.c:27:1: Parameter `a->top`
          25.   }
          26.   
          27. > int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)
          28.   {
          29.       int max, al;

crypto/bn/bn_sqr.c:35:5: Assignment
          33.       bn_check_top(a);
          34.   
          35.       al = a->top;
                    ^
          36.       if (al <= 0) {
          37.           r->top = 0;

crypto/bn/bn_sqr.c:84:17: Call
          82.                   if (bn_wexpand(tmp, max) == NULL)
          83.                       goto err;
          84.                   bn_sqr_normal(rr->d, a->d, al, tmp->d);
                                ^
          85.               }
          86.           }

crypto/bn/bn_sqr.c:109:1: <Offset trace>
107.   
108.   /* tmp must have 2*n words */
109. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
110.   {
111.       int i, j, max;

crypto/bn/bn_sqr.c:109:1: Parameter `n`
            107.   
            108.   /* tmp must have 2*n words */
            109. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
            110.   {
            111.       int i, j, max;

crypto/bn/bn_sqr.c:120:5: Assignment
            118.       rp[0] = rp[max - 1] = 0;
            119.       rp++;
            120.       j = n;
                       ^
            121.   
            122.       if (--j > 0) {

crypto/bn/bn_sqr.c:122:9: Assignment
            120.       j = n;
            121.   
            122.       if (--j > 0) {
                           ^
            123.           ap++;
            124.           rp[j] = bn_mul_words(rp, ap, j, ap[-1]);

crypto/bn/bn_sqr.c:109:1: <Length trace>
107.   
108.   /* tmp must have 2*n words */
109. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
110.   {
111.       int i, j, max;

crypto/bn/bn_sqr.c:109:1: Parameter `*r`
            107.   
            108.   /* tmp must have 2*n words */
            109. > void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
            110.   {
            111.       int i, j, max;

crypto/bn/bn_sqr.c:117:5: Assignment
            115.       max = n * 2;
            116.       ap = a;
            117.       rp = r;
                       ^
            118.       rp[0] = rp[max - 1] = 0;
            119.       rp++;

crypto/bn/bn_sqr.c:119:5: Assignment
            117.       rp = r;
            118.       rp[0] = rp[max - 1] = 0;
            119.       rp++;
                       ^
            120.       j = n;
            121.   

crypto/bn/bn_sqr.c:124:9: Array access: Offset: [16, +oo] (⇐ 1 + [15, +oo]) Size: [0, 8388607] by call to `EC_POINT_set_compressed_coordinates` 
            122.       if (--j > 0) {
            123.           ap++;
            124.           rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
                           ^
            125.           rp += 2;
            126.       }

void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)
{
    int i, j, max;
    const BN_ULONG *ap;
    BN_ULONG *rp;
    max = n * 2;
    ap = a;
    rp = r;
    rp[0] = rp[max - 1] = 0;
    rp++;
    j = n;
    if (--j > 0) {
        ap++;
        rp[j] = bn_mul_words(rp, ap, j, ap[-1]);
        rp += 2;
    }
    for (i = n - 2; i > 0; i--) {
        j--;
        ap++;
        rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);
        rp += 2;
    }
    bn_add_words(r, r, r, max);
    bn_sqr_words(tmp, a, n);
    bn_add_words(r, r, tmp, max);
}
['static int prime_field_tests(void)\n{\n    BN_CTX *ctx = NULL;\n    BIGNUM *p = NULL, *a = NULL, *b = NULL, *scalar3 = NULL;\n    EC_GROUP *group = NULL, *tmp = NULL;\n    EC_GROUP *P_160 = NULL, *P_192 = NULL, *P_224 = NULL,\n             *P_256 = NULL, *P_384 = NULL, *P_521 = NULL;\n    EC_POINT *P = NULL, *Q = NULL, *R = NULL;\n    BIGNUM *x = NULL, *y = NULL, *z = NULL, *yplusone = NULL;\n    const EC_POINT *points[4];\n    const BIGNUM *scalars[4];\n    unsigned char buf[100];\n    size_t len, r = 0;\n    int k;\n    if (!TEST_ptr(ctx = BN_CTX_new())\n        || !TEST_ptr(p = BN_new())\n        || !TEST_ptr(a = BN_new())\n        || !TEST_ptr(b = BN_new())\n        || !TEST_true(BN_hex2bn(&p, "17"))\n        || !TEST_true(BN_hex2bn(&a, "1"))\n        || !TEST_true(BN_hex2bn(&b, "1"))\n        || !TEST_ptr(group = EC_GROUP_new(EC_GFp_mont_method()))\n        || !TEST_true(EC_GROUP_set_curve(group, p, a, b, ctx))\n        || !TEST_ptr(tmp = EC_GROUP_new(EC_GROUP_method_of(group)))\n        || !TEST_true(EC_GROUP_copy(tmp, group)))\n        goto err;\n    EC_GROUP_free(group);\n    group = tmp;\n    tmp = NULL;\n    if (!TEST_true(EC_GROUP_get_curve(group, p, a, b, ctx)))\n        goto err;\n    TEST_info("Curve defined by Weierstrass equation");\n    TEST_note("     y^2 = x^3 + a*x + b (mod p)");\n    test_output_bignum("a", a);\n    test_output_bignum("b", b);\n    test_output_bignum("p", p);\n    buf[0] = 0;\n    if (!TEST_ptr(P = EC_POINT_new(group))\n        || !TEST_ptr(Q = EC_POINT_new(group))\n        || !TEST_ptr(R = EC_POINT_new(group))\n        || !TEST_true(EC_POINT_set_to_infinity(group, P))\n        || !TEST_true(EC_POINT_is_at_infinity(group, P))\n        || !TEST_true(EC_POINT_oct2point(group, Q, buf, 1, ctx))\n        || !TEST_true(EC_POINT_add(group, P, P, Q, ctx))\n        || !TEST_true(EC_POINT_is_at_infinity(group, P))\n        || !TEST_ptr(x = BN_new())\n        || !TEST_ptr(y = BN_new())\n        || !TEST_ptr(z = BN_new())\n        || !TEST_ptr(yplusone = BN_new())\n        || !TEST_true(BN_hex2bn(&x, "D"))\n        || !TEST_true(EC_POINT_set_compressed_coordinates(group, Q, x, 1, ctx)))\n        goto err;\n    if (!TEST_int_gt(EC_POINT_is_on_curve(group, Q, ctx), 0)) {\n        if (!TEST_true(EC_POINT_get_affine_coordinates(group, Q, x, y, ctx)))\n            goto err;\n        TEST_info("Point is not on curve");\n        test_output_bignum("x", x);\n        test_output_bignum("y", y);\n        goto err;\n    }\n    TEST_note("A cyclic subgroup:");\n    k = 100;\n    do {\n        if (!TEST_int_ne(k--, 0))\n            goto err;\n        if (EC_POINT_is_at_infinity(group, P)) {\n            TEST_note("     point at infinity");\n        } else {\n            if (!TEST_true(EC_POINT_get_affine_coordinates(group, P, x, y,\n                                                           ctx)))\n                goto err;\n            test_output_bignum("x", x);\n            test_output_bignum("y", y);\n        }\n        if (!TEST_true(EC_POINT_copy(R, P))\n            || !TEST_true(EC_POINT_add(group, P, P, Q, ctx)))\n            goto err;\n    } while (!EC_POINT_is_at_infinity(group, P));\n    if (!TEST_true(EC_POINT_add(group, P, Q, R, ctx))\n        || !TEST_true(EC_POINT_is_at_infinity(group, P)))\n        goto err;\n    len =\n        EC_POINT_point2oct(group, Q, POINT_CONVERSION_COMPRESSED, buf,\n                           sizeof(buf), ctx);\n    if (!TEST_size_t_ne(len, 0)\n        || !TEST_true(EC_POINT_oct2point(group, P, buf, len, ctx))\n        || !TEST_int_eq(0, EC_POINT_cmp(group, P, Q, ctx)))\n        goto err;\n    test_output_memory("Generator as octet string, compressed form:",\n                       buf, len);\n    len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_UNCOMPRESSED,\n                             buf, sizeof(buf), ctx);\n    if (!TEST_size_t_ne(len, 0)\n        || !TEST_true(EC_POINT_oct2point(group, P, buf, len, ctx))\n        || !TEST_int_eq(0, EC_POINT_cmp(group, P, Q, ctx)))\n        goto err;\n    test_output_memory("Generator as octet string, uncompressed form:",\n                       buf, len);\n    len = EC_POINT_point2oct(group, Q, POINT_CONVERSION_HYBRID,\n                             buf, sizeof(buf), ctx);\n    if (!TEST_size_t_ne(len, 0)\n        || !TEST_true(EC_POINT_oct2point(group, P, buf, len, ctx))\n        || !TEST_int_eq(0, EC_POINT_cmp(group, P, Q, ctx)))\n        goto err;\n    test_output_memory("Generator as octet string, hybrid form:",\n                       buf, len);\n    if (!TEST_true(EC_POINT_get_Jprojective_coordinates_GFp(group, R, x, y, z,\n                                                            ctx)))\n        goto err;\n    TEST_info("A representation of the inverse of that generator in");\n    TEST_note("Jacobian projective coordinates");\n    test_output_bignum("x", x);\n    test_output_bignum("y", y);\n    test_output_bignum("z", z);\n    if (!TEST_true(EC_POINT_invert(group, P, ctx))\n        || !TEST_int_eq(0, EC_POINT_cmp(group, P, R, ctx))\n        || !TEST_true(BN_hex2bn(&p,                         "FFFFFFFF"\n                                    "FFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFF"))\n        || !TEST_int_eq(1, BN_is_prime_ex(p, BN_prime_checks, ctx, NULL))\n        || !TEST_true(BN_hex2bn(&a,                         "FFFFFFFF"\n                                    "FFFFFFFFFFFFFFFFFFFFFFFF7FFFFFFC"))\n        || !TEST_true(BN_hex2bn(&b,                         "1C97BEFC"\n                                    "54BD7A8B65ACF89F81D4D4ADC565FA45"))\n        || !TEST_true(EC_GROUP_set_curve(group, p, a, b, ctx))\n        || !TEST_true(BN_hex2bn(&x,                         "4A96B568"\n                                    "8EF573284664698968C38BB913CBFC82"))\n        || !TEST_true(BN_hex2bn(&y,                         "23a62855"\n                                    "3168947d59dcc912042351377ac5fb32"))\n        || !TEST_true(BN_add(yplusone, y, BN_value_one()))\n        || !TEST_false(EC_POINT_set_affine_coordinates(group, P, x, yplusone,\n                                                       ctx))\n        || !TEST_true(EC_POINT_set_affine_coordinates(group, P, x, y, ctx))\n        || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)\n        || !TEST_true(BN_hex2bn(&z,                       "0100000000"\n                                    "000000000001F4C8F927AED3CA752257"))\n        || !TEST_true(EC_GROUP_set_generator(group, P, z, BN_value_one()))\n        || !TEST_true(EC_POINT_get_affine_coordinates(group, P, x, y, ctx)))\n        goto err;\n    TEST_info("SEC2 curve secp160r1 -- Generator");\n    test_output_bignum("x", x);\n    test_output_bignum("y", y);\n    if (!TEST_true(BN_hex2bn(&z,                         "23a62855"\n                                 "3168947d59dcc912042351377ac5fb32"))\n        || !TEST_BN_eq(y, z)\n        || !TEST_int_eq(EC_GROUP_get_degree(group), 160)\n        || !group_order_tests(group)\n        || !TEST_ptr(P_160 = EC_GROUP_new(EC_GROUP_method_of(group)))\n        || !TEST_true(EC_GROUP_copy(P_160, group))\n        || !TEST_true(BN_hex2bn(&p,                 "FFFFFFFFFFFFFFFF"\n                                    "FFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFF"))\n        || !TEST_int_eq(1, BN_is_prime_ex(p, BN_prime_checks, ctx, NULL))\n        || !TEST_true(BN_hex2bn(&a,                 "FFFFFFFFFFFFFFFF"\n                                    "FFFFFFFFFFFFFFFEFFFFFFFFFFFFFFFC"))\n        || !TEST_true(BN_hex2bn(&b,                 "64210519E59C80E7"\n                                    "0FA7E9AB72243049FEB8DEECC146B9B1"))\n        || !TEST_true(EC_GROUP_set_curve(group, p, a, b, ctx))\n        || !TEST_true(BN_hex2bn(&x,                 "188DA80EB03090F6"\n                                    "7CBF20EB43A18800F4FF0AFD82FF1012"))\n        || !TEST_true(EC_POINT_set_compressed_coordinates(group, P, x, 1, ctx))\n        || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)\n        || !TEST_true(BN_hex2bn(&z,                 "FFFFFFFFFFFFFFFF"\n                                    "FFFFFFFF99DEF836146BC9B1B4D22831"))\n        || !TEST_true(EC_GROUP_set_generator(group, P, z, BN_value_one()))\n        || !TEST_true(EC_POINT_get_affine_coordinates(group, P, x, y, ctx)))\n        goto err;\n    TEST_info("NIST curve P-192 -- Generator");\n    test_output_bignum("x", x);\n    test_output_bignum("y", y);\n    if (!TEST_true(BN_hex2bn(&z,                 "07192B95FFC8DA78"\n                                 "631011ED6B24CDD573F977A11E794811"))\n        || !TEST_BN_eq(y, z)\n        || !TEST_true(BN_add(yplusone, y, BN_value_one()))\n        || !TEST_false(EC_POINT_set_affine_coordinates(group, P, x, yplusone,\n                                                       ctx))\n        || !TEST_int_eq(EC_GROUP_get_degree(group), 192)\n        || !group_order_tests(group)\n        || !TEST_ptr(P_192 = EC_GROUP_new(EC_GROUP_method_of(group)))\n        || !TEST_true(EC_GROUP_copy(P_192, group))\n        || !TEST_true(BN_hex2bn(&p,         "FFFFFFFFFFFFFFFFFFFFFFFF"\n                                    "FFFFFFFF000000000000000000000001"))\n        || !TEST_int_eq(1, BN_is_prime_ex(p, BN_prime_checks, ctx, NULL))\n        || !TEST_true(BN_hex2bn(&a,         "FFFFFFFFFFFFFFFFFFFFFFFF"\n                                    "FFFFFFFEFFFFFFFFFFFFFFFFFFFFFFFE"))\n        || !TEST_true(BN_hex2bn(&b,         "B4050A850C04B3ABF5413256"\n                                    "5044B0B7D7BFD8BA270B39432355FFB4"))\n        || !TEST_true(EC_GROUP_set_curve(group, p, a, b, ctx))\n        || !TEST_true(BN_hex2bn(&x,         "B70E0CBD6BB4BF7F321390B9"\n                                    "4A03C1D356C21122343280D6115C1D21"))\n        || !TEST_true(EC_POINT_set_compressed_coordinates(group, P, x, 0, ctx))\n        || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)\n        || !TEST_true(BN_hex2bn(&z,         "FFFFFFFFFFFFFFFFFFFFFFFF"\n                                    "FFFF16A2E0B8F03E13DD29455C5C2A3D"))\n        || !TEST_true(EC_GROUP_set_generator(group, P, z, BN_value_one()))\n        || !TEST_true(EC_POINT_get_affine_coordinates(group, P, x, y, ctx)))\n        goto err;\n    TEST_info("NIST curve P-224 -- Generator");\n    test_output_bignum("x", x);\n    test_output_bignum("y", y);\n    if (!TEST_true(BN_hex2bn(&z,         "BD376388B5F723FB4C22DFE6"\n                                 "CD4375A05A07476444D5819985007E34"))\n        || !TEST_BN_eq(y, z)\n        || !TEST_true(BN_add(yplusone, y, BN_value_one()))\n        || !TEST_false(EC_POINT_set_affine_coordinates(group, P, x, yplusone,\n                                                       ctx))\n        || !TEST_int_eq(EC_GROUP_get_degree(group), 224)\n        || !group_order_tests(group)\n        || !TEST_ptr(P_224 = EC_GROUP_new(EC_GROUP_method_of(group)))\n        || !TEST_true(EC_GROUP_copy(P_224, group))\n        || !TEST_true(BN_hex2bn(&p, "FFFFFFFF000000010000000000000000"\n                                    "00000000FFFFFFFFFFFFFFFFFFFFFFFF"))\n        || !TEST_int_eq(1, BN_is_prime_ex(p, BN_prime_checks, ctx, NULL))\n        || !TEST_true(BN_hex2bn(&a, "FFFFFFFF000000010000000000000000"\n                                    "00000000FFFFFFFFFFFFFFFFFFFFFFFC"))\n        || !TEST_true(BN_hex2bn(&b, "5AC635D8AA3A93E7B3EBBD55769886BC"\n                                    "651D06B0CC53B0F63BCE3C3E27D2604B"))\n        || !TEST_true(EC_GROUP_set_curve(group, p, a, b, ctx))\n        || !TEST_true(BN_hex2bn(&x, "6B17D1F2E12C4247F8BCE6E563A440F2"\n                                    "77037D812DEB33A0F4A13945D898C296"))\n        || !TEST_true(EC_POINT_set_compressed_coordinates(group, P, x, 1, ctx))\n        || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)\n        || !TEST_true(BN_hex2bn(&z, "FFFFFFFF00000000FFFFFFFFFFFFFFFF"\n                                    "BCE6FAADA7179E84F3B9CAC2FC632551"))\n        || !TEST_true(EC_GROUP_set_generator(group, P, z, BN_value_one()))\n        || !TEST_true(EC_POINT_get_affine_coordinates(group, P, x, y, ctx)))\n        goto err;\n    TEST_info("NIST curve P-256 -- Generator");\n    test_output_bignum("x", x);\n    test_output_bignum("y", y);\n    if (!TEST_true(BN_hex2bn(&z, "4FE342E2FE1A7F9B8EE7EB4A7C0F9E16"\n                                 "2BCE33576B315ECECBB6406837BF51F5"))\n        || !TEST_BN_eq(y, z)\n        || !TEST_true(BN_add(yplusone, y, BN_value_one()))\n        || !TEST_false(EC_POINT_set_affine_coordinates(group, P, x, yplusone,\n                                                       ctx))\n        || !TEST_int_eq(EC_GROUP_get_degree(group), 256)\n        || !group_order_tests(group)\n        || !TEST_ptr(P_256 = EC_GROUP_new(EC_GROUP_method_of(group)))\n        || !TEST_true(EC_GROUP_copy(P_256, group))\n        || !TEST_true(BN_hex2bn(&p, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n                                    "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"\n                                    "FFFFFFFF0000000000000000FFFFFFFF"))\n        || !TEST_int_eq(1, BN_is_prime_ex(p, BN_prime_checks, ctx, NULL))\n        || !TEST_true(BN_hex2bn(&a, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n                                    "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFE"\n                                    "FFFFFFFF0000000000000000FFFFFFFC"))\n        || !TEST_true(BN_hex2bn(&b, "B3312FA7E23EE7E4988E056BE3F82D19"\n                                    "181D9C6EFE8141120314088F5013875A"\n                                    "C656398D8A2ED19D2A85C8EDD3EC2AEF"))\n        || !TEST_true(EC_GROUP_set_curve(group, p, a, b, ctx))\n        || !TEST_true(BN_hex2bn(&x, "AA87CA22BE8B05378EB1C71EF320AD74"\n                                    "6E1D3B628BA79B9859F741E082542A38"\n                                    "5502F25DBF55296C3A545E3872760AB7"))\n        || !TEST_true(EC_POINT_set_compressed_coordinates(group, P, x, 1, ctx))\n        || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)\n        || !TEST_true(BN_hex2bn(&z, "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n                                    "FFFFFFFFFFFFFFFFC7634D81F4372DDF"\n                                    "581A0DB248B0A77AECEC196ACCC52973"))\n        || !TEST_true(EC_GROUP_set_generator(group, P, z, BN_value_one()))\n        || !TEST_true(EC_POINT_get_affine_coordinates(group, P, x, y, ctx)))\n        goto err;\n    TEST_info("NIST curve P-384 -- Generator");\n    test_output_bignum("x", x);\n    test_output_bignum("y", y);\n    if (!TEST_true(BN_hex2bn(&z, "3617DE4A96262C6F5D9E98BF9292DC29"\n                                 "F8F41DBD289A147CE9DA3113B5F0B8C0"\n                                 "0A60B1CE1D7E819D7A431D7C90EA0E5F"))\n        || !TEST_BN_eq(y, z)\n        || !TEST_true(BN_add(yplusone, y, BN_value_one()))\n        || !TEST_false(EC_POINT_set_affine_coordinates(group, P, x, yplusone,\n                                                       ctx))\n        || !TEST_int_eq(EC_GROUP_get_degree(group), 384)\n        || !group_order_tests(group)\n        || !TEST_ptr(P_384 = EC_GROUP_new(EC_GROUP_method_of(group)))\n        || !TEST_true(EC_GROUP_copy(P_384, group))\n        || !TEST_true(BN_hex2bn(&p,                              "1FF"\n                                    "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n                                    "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n                                    "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n                                    "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"))\n        || !TEST_int_eq(1, BN_is_prime_ex(p, BN_prime_checks, ctx, NULL))\n        || !TEST_true(BN_hex2bn(&a,                              "1FF"\n                                    "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n                                    "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n                                    "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n                                    "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFC"))\n        || !TEST_true(BN_hex2bn(&b,                              "051"\n                                    "953EB9618E1C9A1F929A21A0B68540EE"\n                                    "A2DA725B99B315F3B8B489918EF109E1"\n                                    "56193951EC7E937B1652C0BD3BB1BF07"\n                                    "3573DF883D2C34F1EF451FD46B503F00"))\n        || !TEST_true(EC_GROUP_set_curve(group, p, a, b, ctx))\n        || !TEST_true(BN_hex2bn(&x,                               "C6"\n                                    "858E06B70404E9CD9E3ECB662395B442"\n                                    "9C648139053FB521F828AF606B4D3DBA"\n                                    "A14B5E77EFE75928FE1DC127A2FFA8DE"\n                                    "3348B3C1856A429BF97E7E31C2E5BD66"))\n        || !TEST_true(EC_POINT_set_compressed_coordinates(group, P, x, 0, ctx))\n        || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)\n        || !TEST_true(BN_hex2bn(&z,                              "1FF"\n                                    "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF"\n                                    "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFA"\n                                    "51868783BF2F966B7FCC0148F709A5D0"\n                                    "3BB5C9B8899C47AEBB6FB71E91386409"))\n        || !TEST_true(EC_GROUP_set_generator(group, P, z, BN_value_one()))\n        || !TEST_true(EC_POINT_get_affine_coordinates(group, P, x, y, ctx)))\n        goto err;\n    TEST_info("NIST curve P-521 -- Generator");\n    test_output_bignum("x", x);\n    test_output_bignum("y", y);\n    if (!TEST_true(BN_hex2bn(&z,                              "118"\n                                 "39296A789A3BC0045C8A5FB42C7D1BD9"\n                                 "98F54449579B446817AFBD17273E662C"\n                                 "97EE72995EF42640C550B9013FAD0761"\n                                 "353C7086A272C24088BE94769FD16650"))\n        || !TEST_BN_eq(y, z)\n        || !TEST_true(BN_add(yplusone, y, BN_value_one()))\n        || !TEST_false(EC_POINT_set_affine_coordinates(group, P, x, yplusone,\n                                                       ctx))\n        || !TEST_int_eq(EC_GROUP_get_degree(group), 521)\n        || !group_order_tests(group)\n        || !TEST_ptr(P_521 = EC_GROUP_new(EC_GROUP_method_of(group)))\n        || !TEST_true(EC_GROUP_copy(P_521, group))\n        || !TEST_true(EC_POINT_set_affine_coordinates(group, P, x, y, ctx))\n        || !TEST_true(EC_POINT_copy(Q, P))\n        || !TEST_false(EC_POINT_is_at_infinity(group, Q))\n        || !TEST_true(EC_POINT_dbl(group, P, P, ctx))\n        || !TEST_int_gt(EC_POINT_is_on_curve(group, P, ctx), 0)\n        || !TEST_true(EC_POINT_invert(group, Q, ctx))\n        || !TEST_true(EC_POINT_add(group, R, P, Q, ctx))\n        || !TEST_true(EC_POINT_add(group, R, R, Q, ctx))\n        || !TEST_true(EC_POINT_is_at_infinity(group, R))\n        || !TEST_false(EC_POINT_is_at_infinity(group, Q)))\n        goto err;\n    points[0] = Q;\n    points[1] = Q;\n    points[2] = Q;\n    points[3] = Q;\n    if (!TEST_true(EC_GROUP_get_order(group, z, ctx))\n        || !TEST_true(BN_add(y, z, BN_value_one()))\n        || !TEST_BN_even(y)\n        || !TEST_true(BN_rshift1(y, y)))\n        goto err;\n    scalars[0] = y;\n    scalars[1] = y;\n    TEST_note("combined multiplication ...");\n    if (!TEST_true(EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx))\n        || !TEST_true(EC_POINTs_mul(group, R, z, 2, points, scalars, ctx))\n        || !TEST_int_eq(0, EC_POINT_cmp(group, P, R, ctx))\n        || !TEST_int_eq(0, EC_POINT_cmp(group, R, Q, ctx))\n        || !TEST_true(BN_rand(y, BN_num_bits(y), 0, 0))\n        || !TEST_true(BN_add(z, z, y)))\n        goto err;\n    BN_set_negative(z, 1);\n    scalars[0] = y;\n    scalars[1] = z;\n    if (!TEST_true(EC_POINTs_mul(group, P, NULL, 2, points, scalars, ctx))\n        || !TEST_true(EC_POINT_is_at_infinity(group, P))\n        || !TEST_true(BN_rand(x, BN_num_bits(y) - 1, 0, 0))\n        || !TEST_true(BN_add(z, x, y)))\n        goto err;\n    BN_set_negative(z, 1);\n    scalars[0] = x;\n    scalars[1] = y;\n    scalars[2] = z;\n    if (!TEST_ptr(scalar3 = BN_new()))\n        goto err;\n    BN_zero(scalar3);\n    scalars[3] = scalar3;\n    if (!TEST_true(EC_POINTs_mul(group, P, NULL, 4, points, scalars, ctx))\n        || !TEST_true(EC_POINT_is_at_infinity(group, P)))\n        goto err;\n    TEST_note(" ok\\n");\n    r = 1;\nerr:\n    BN_CTX_free(ctx);\n    BN_free(p);\n    BN_free(a);\n    BN_free(b);\n    EC_GROUP_free(group);\n    EC_GROUP_free(tmp);\n    EC_POINT_free(P);\n    EC_POINT_free(Q);\n    EC_POINT_free(R);\n    BN_free(x);\n    BN_free(y);\n    BN_free(z);\n    BN_free(yplusone);\n    BN_free(scalar3);\n    EC_GROUP_free(P_160);\n    EC_GROUP_free(P_192);\n    EC_GROUP_free(P_224);\n    EC_GROUP_free(P_256);\n    EC_GROUP_free(P_384);\n    EC_GROUP_free(P_521);\n    return r;\n}', "int BN_hex2bn(BIGNUM **bn, const char *a)\n{\n    BIGNUM *ret = NULL;\n    BN_ULONG l = 0;\n    int neg = 0, h, m, i, j, k, c;\n    int num;\n    if (a == NULL || *a == '\\0')\n        return 0;\n    if (*a == '-') {\n        neg = 1;\n        a++;\n    }\n    for (i = 0; i <= INT_MAX / 4 && ossl_isxdigit(a[i]); i++)\n        continue;\n    if (i == 0 || i > INT_MAX / 4)\n        goto err;\n    num = i + neg;\n    if (bn == NULL)\n        return num;\n    if (*bn == NULL) {\n        if ((ret = BN_new()) == NULL)\n            return 0;\n    } else {\n        ret = *bn;\n        BN_zero(ret);\n    }\n    if (bn_expand(ret, i * 4) == NULL)\n        goto err;\n    j = i;\n    m = 0;\n    h = 0;\n    while (j > 0) {\n        m = (BN_BYTES * 2 <= j) ? BN_BYTES * 2 : j;\n        l = 0;\n        for (;;) {\n            c = a[j - m];\n            k = OPENSSL_hexchar2int(c);\n            if (k < 0)\n                k = 0;\n            l = (l << 4) | k;\n            if (--m <= 0) {\n                ret->d[h++] = l;\n                break;\n            }\n        }\n        j -= BN_BYTES * 2;\n    }\n    ret->top = h;\n    bn_correct_top(ret);\n    *bn = ret;\n    bn_check_top(ret);\n    if (ret->top != 0)\n        ret->neg = neg;\n    return num;\n err:\n    if (*bn == NULL)\n        BN_free(ret);\n    return 0;\n}", 'int EC_POINT_set_compressed_coordinates(const EC_GROUP *group, EC_POINT *point,\n                                        const BIGNUM *x, int y_bit, BN_CTX *ctx)\n{\n    if (group->meth->point_set_compressed_coordinates == NULL\n        && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) {\n        ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES,\n              ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n        return 0;\n    }\n    if (!ec_point_is_compat(point, group)) {\n        ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES,\n              EC_R_INCOMPATIBLE_OBJECTS);\n        return 0;\n    }\n    if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) {\n        if (group->meth->field_type == NID_X9_62_prime_field)\n            return ec_GFp_simple_set_compressed_coordinates(group, point, x,\n                                                            y_bit, ctx);\n        else\n#ifdef OPENSSL_NO_EC2M\n        {\n            ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES,\n                  EC_R_GF2M_NOT_SUPPORTED);\n            return 0;\n        }\n#else\n            return ec_GF2m_simple_set_compressed_coordinates(group, point, x,\n                                                             y_bit, ctx);\n#endif\n    }\n    return group->meth->point_set_compressed_coordinates(group, point, x,\n                                                         y_bit, ctx);\n}', 'int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group,\n                                             EC_POINT *point,\n                                             const BIGNUM *x_, int y_bit,\n                                             BN_CTX *ctx)\n{\n    BN_CTX *new_ctx = NULL;\n    BIGNUM *tmp1, *tmp2, *x, *y;\n    int ret = 0;\n    ERR_clear_error();\n    if (ctx == NULL) {\n        ctx = new_ctx = BN_CTX_new();\n        if (ctx == NULL)\n            return 0;\n    }\n    y_bit = (y_bit != 0);\n    BN_CTX_start(ctx);\n    tmp1 = BN_CTX_get(ctx);\n    tmp2 = BN_CTX_get(ctx);\n    x = BN_CTX_get(ctx);\n    y = BN_CTX_get(ctx);\n    if (y == NULL)\n        goto err;\n    if (!BN_nnmod(x, x_, group->field, ctx))\n        goto err;\n    if (group->meth->field_decode == 0) {\n        if (!group->meth->field_sqr(group, tmp2, x_, ctx))\n            goto err;\n        if (!group->meth->field_mul(group, tmp1, tmp2, x_, ctx))\n            goto err;\n    } else {\n        if (!BN_mod_sqr(tmp2, x_, group->field, ctx))\n            goto err;\n        if (!BN_mod_mul(tmp1, tmp2, x_, group->field, ctx))\n            goto err;\n    }\n    if (group->a_is_minus3) {\n        if (!BN_mod_lshift1_quick(tmp2, x, group->field))\n            goto err;\n        if (!BN_mod_add_quick(tmp2, tmp2, x, group->field))\n            goto err;\n        if (!BN_mod_sub_quick(tmp1, tmp1, tmp2, group->field))\n            goto err;\n    } else {\n        if (group->meth->field_decode) {\n            if (!group->meth->field_decode(group, tmp2, group->a, ctx))\n                goto err;\n            if (!BN_mod_mul(tmp2, tmp2, x, group->field, ctx))\n                goto err;\n        } else {\n            if (!group->meth->field_mul(group, tmp2, group->a, x, ctx))\n                goto err;\n        }\n        if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))\n            goto err;\n    }\n    if (group->meth->field_decode) {\n        if (!group->meth->field_decode(group, tmp2, group->b, ctx))\n            goto err;\n        if (!BN_mod_add_quick(tmp1, tmp1, tmp2, group->field))\n            goto err;\n    } else {\n        if (!BN_mod_add_quick(tmp1, tmp1, group->b, group->field))\n            goto err;\n    }\n    if (!BN_mod_sqrt(y, tmp1, group->field, ctx)) {\n        unsigned long err = ERR_peek_last_error();\n        if (ERR_GET_LIB(err) == ERR_LIB_BN\n            && ERR_GET_REASON(err) == BN_R_NOT_A_SQUARE) {\n            ERR_clear_error();\n            ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n                  EC_R_INVALID_COMPRESSED_POINT);\n        } else\n            ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n                  ERR_R_BN_LIB);\n        goto err;\n    }\n    if (y_bit != BN_is_odd(y)) {\n        if (BN_is_zero(y)) {\n            int kron;\n            kron = BN_kronecker(x, group->field, ctx);\n            if (kron == -2)\n                goto err;\n            if (kron == 1)\n                ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n                      EC_R_INVALID_COMPRESSION_BIT);\n            else\n                ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n                      EC_R_INVALID_COMPRESSED_POINT);\n            goto err;\n        }\n        if (!BN_usub(y, group->field, y))\n            goto err;\n    }\n    if (y_bit != BN_is_odd(y)) {\n        ECerr(EC_F_EC_GFP_SIMPLE_SET_COMPRESSED_COORDINATES,\n              ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    if (!EC_POINT_set_affine_coordinates(group, point, x, y, ctx))\n        goto err;\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    BN_CTX_free(new_ctx);\n    return ret;\n}', 'BIGNUM *BN_CTX_get(BN_CTX *ctx)\n{\n    BIGNUM *ret;\n    CTXDBG("ENTER BN_CTX_get()", ctx);\n    if (ctx->err_stack || ctx->too_many)\n        return NULL;\n    if ((ret = BN_POOL_get(&ctx->pool, ctx->flags)) == NULL) {\n        ctx->too_many = 1;\n        BNerr(BN_F_BN_CTX_GET, BN_R_TOO_MANY_TEMPORARY_VARIABLES);\n        return NULL;\n    }\n    BN_zero(ret);\n    ret->flags &= (~BN_FLG_CONSTTIME);\n    ctx->used++;\n    CTXDBG("LEAVE BN_CTX_get()", ctx);\n    return ret;\n}', 'int BN_set_word(BIGNUM *a, BN_ULONG w)\n{\n    bn_check_top(a);\n    if (bn_expand(a, (int)sizeof(BN_ULONG) * 8) == NULL)\n        return 0;\n    a->neg = 0;\n    a->d[0] = w;\n    a->top = (w ? 1 : 0);\n    a->flags &= ~BN_FLG_FIXED_TOP;\n    bn_check_top(a);\n    return 1;\n}', 'static ossl_inline BIGNUM *bn_expand(BIGNUM *a, int bits)\n{\n    if (bits > (INT_MAX - BN_BITS2 + 1))\n        return NULL;\n    if (((bits+BN_BITS2-1)/BN_BITS2) <= (a)->dmax)\n        return a;\n    return bn_expand2((a),(bits+BN_BITS2-1)/BN_BITS2);\n}', 'int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)\n{\n    if (!BN_sqr(r, a, ctx))\n        return 0;\n    return BN_mod(r, r, m, ctx);\n}', 'int BN_sqr(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n    int ret = bn_sqr_fixed_top(r, a, ctx);\n    bn_correct_top(r);\n    bn_check_top(r);\n    return ret;\n}', 'int bn_sqr_fixed_top(BIGNUM *r, const BIGNUM *a, BN_CTX *ctx)\n{\n    int max, al;\n    int ret = 0;\n    BIGNUM *tmp, *rr;\n    bn_check_top(a);\n    al = a->top;\n    if (al <= 0) {\n        r->top = 0;\n        r->neg = 0;\n        return 1;\n    }\n    BN_CTX_start(ctx);\n    rr = (a != r) ? r : BN_CTX_get(ctx);\n    tmp = BN_CTX_get(ctx);\n    if (rr == NULL || tmp == NULL)\n        goto err;\n    max = 2 * al;\n    if (bn_wexpand(rr, max) == NULL)\n        goto err;\n    if (al == 4) {\n#ifndef BN_SQR_COMBA\n        BN_ULONG t[8];\n        bn_sqr_normal(rr->d, a->d, 4, t);\n#else\n        bn_sqr_comba4(rr->d, a->d);\n#endif\n    } else if (al == 8) {\n#ifndef BN_SQR_COMBA\n        BN_ULONG t[16];\n        bn_sqr_normal(rr->d, a->d, 8, t);\n#else\n        bn_sqr_comba8(rr->d, a->d);\n#endif\n    } else {\n#if defined(BN_RECURSION)\n        if (al < BN_SQR_RECURSIVE_SIZE_NORMAL) {\n            BN_ULONG t[BN_SQR_RECURSIVE_SIZE_NORMAL * 2];\n            bn_sqr_normal(rr->d, a->d, al, t);\n        } else {\n            int j, k;\n            j = BN_num_bits_word((BN_ULONG)al);\n            j = 1 << (j - 1);\n            k = j + j;\n            if (al == j) {\n                if (bn_wexpand(tmp, k * 2) == NULL)\n                    goto err;\n                bn_sqr_recursive(rr->d, a->d, al, tmp->d);\n            } else {\n                if (bn_wexpand(tmp, max) == NULL)\n                    goto err;\n                bn_sqr_normal(rr->d, a->d, al, tmp->d);\n            }\n        }\n#else\n        if (bn_wexpand(tmp, max) == NULL)\n            goto err;\n        bn_sqr_normal(rr->d, a->d, al, tmp->d);\n#endif\n    }\n    rr->neg = 0;\n    rr->top = max;\n    rr->flags |= BN_FLG_FIXED_TOP;\n    if (r != rr && BN_copy(r, rr) == NULL)\n        goto err;\n    ret = 1;\n err:\n    bn_check_top(rr);\n    bn_check_top(tmp);\n    BN_CTX_end(ctx);\n    return ret;\n}', 'void bn_sqr_normal(BN_ULONG *r, const BN_ULONG *a, int n, BN_ULONG *tmp)\n{\n    int i, j, max;\n    const BN_ULONG *ap;\n    BN_ULONG *rp;\n    max = n * 2;\n    ap = a;\n    rp = r;\n    rp[0] = rp[max - 1] = 0;\n    rp++;\n    j = n;\n    if (--j > 0) {\n        ap++;\n        rp[j] = bn_mul_words(rp, ap, j, ap[-1]);\n        rp += 2;\n    }\n    for (i = n - 2; i > 0; i--) {\n        j--;\n        ap++;\n        rp[j] = bn_mul_add_words(rp, ap, j, ap[-1]);\n        rp += 2;\n    }\n    bn_add_words(r, r, r, max);\n    bn_sqr_words(tmp, a, n);\n    bn_add_words(r, r, tmp, max);\n}']