crypto/ec/ec_ameth.c:657: error: BUFFER_OVERRUN_L3
  Offset: [1, +oo] Size: [0, 8388607] by call to `o2i_ECPublicKey`.
Showing all 36 steps of the trace


crypto/ec/ec_ameth.c:645:14: Call
643.           if (ecpeer == NULL)
644.               goto err;
645.           if (!EC_KEY_set_group(ecpeer, grp))
                    ^
646.               goto err;
647.       } else {

crypto/ec/ec_key.c:429:18: Call
  427.           return 0;
  428.       EC_GROUP_free(key->group);
  429.       key->group = EC_GROUP_dup(group);
                          ^
  430.       return (key->group == NULL) ? 0 : 1;
  431.   }

crypto/ec/ec_lib.c:242:10: Call
    240.       if ((t = EC_GROUP_new(a->meth)) == NULL)
    241.           return NULL;
    242.       if (!EC_GROUP_copy(t, a))
                    ^
    243.           goto err;
    244.   

crypto/ec/ec_lib.c:130:1: Parameter `dest->order->top`
      128.   }
      129.   
      130. > int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)
      131.   {
      132.       if (dest->meth->group_copy == 0) {

crypto/ec/ec_ameth.c:657:10: Call
655.       if (!p || !plen)
656.           goto err;
657.       if (!o2i_ECPublicKey(&ecpeer, &p, plen))
                ^
658.           goto err;
659.       pkpeer = EVP_PKEY_new();

crypto/ec/ec_asn1.c:1109:1: Parameter `(*a)->group->field->top`
  1107.   }
  1108.   
  1109. > EC_KEY *o2i_ECPublicKey(EC_KEY **a, const unsigned char **in, long len)
  1110.   {
  1111.       EC_KEY *ret = NULL;

crypto/ec/ec_asn1.c:1121:10: Call
  1119.       }
  1120.       ret = *a;
  1121.       if (!EC_KEY_oct2key(ret, *in, len, NULL)) {
                   ^
  1122.           ECerr(EC_F_O2I_ECPUBLICKEY, ERR_R_EC_LIB);
  1123.           return 0;

crypto/ec/ec_key.c:526:1: Parameter `key->group->field->top`
    524.   }
    525.   
    526. > int EC_KEY_oct2key(EC_KEY *key, const unsigned char *buf, size_t len,
    527.                      BN_CTX *ctx)
    528.   {

crypto/ec/ec_key.c:535:9: Call
    533.       if (key->pub_key == NULL)
    534.           return 0;
    535.       if (EC_POINT_oct2point(key->group, key->pub_key, buf, len, ctx) == 0)
                   ^
    536.           return 0;
    537.       /*

crypto/ec/ec_oct.c:113:1: Parameter `group->field->top`
      111.   }
      112.   
      113. > int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point,
      114.                          const unsigned char *buf, size_t len, BN_CTX *ctx)
      115.   {

crypto/ec/ec_oct.c:135:20: Call
      133.           }
      134.   #else
      135.               return ec_GF2m_simple_oct2point(group, point, buf, len, ctx);
                                ^
      136.   #endif
      137.       }

crypto/ec/ec2_oct.c:235:1: Parameter `group->field->top`
        233.    * simple implementation only uses affine coordinates.
        234.    */
        235. > int ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
        236.                                const unsigned char *buf, size_t len,
        237.                                BN_CTX *ctx)

crypto/ec/ec2_oct.c:304:14: Call
        302.   
        303.       if (form == POINT_CONVERSION_COMPRESSED) {
        304.           if (!EC_POINT_set_compressed_coordinates_GF2m
                            ^
        305.               (group, point, x, y_bit, ctx))
        306.               goto err;

crypto/ec/ec_oct.c:54:1: Parameter `group->field->top`
          52.   
          53.   #ifndef OPENSSL_NO_EC2M
          54. > int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group,
          55.                                                EC_POINT *point, const BIGNUM *x,
          56.                                                int y_bit, BN_CTX *ctx)

crypto/ec/ec_oct.c:71:20: Call
          69.       if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) {
          70.           if (group->meth->field_type == NID_X9_62_prime_field)
          71.               return ec_GFp_simple_set_compressed_coordinates(group, point, x,
                                   ^
          72.                                                               y_bit, ctx);
          73.           else

crypto/ec/ecp_oct.c:16:1: Parameter `group->field->top`
            14.   #include "ec_lcl.h"
            15.   
            16. > int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group,
            17.                                                EC_POINT *point,
            18.                                                const BIGNUM *x_, int y_bit,

crypto/ec/ecp_oct.c:51:10: Call
            49.   
            50.       /* tmp1 := x^3 */
            51.       if (!BN_nnmod(x, x_, group->field, ctx))
                           ^
            52.           goto err;
            53.       if (group->meth->field_decode == 0) {

crypto/bn/bn_mod.c:13:1: Parameter `d->top`
              11.   #include "bn_lcl.h"
              12.   
              13. > int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)
              14.   {
              15.       /*

crypto/bn/bn_mod.c:20:11: Call
              18.        */
              19.   
              20.       if (!(BN_mod(r, m, d, ctx)))
                              ^
              21.           return 0;
              22.       if (!r->neg)

crypto/bn/bn_div.c:137:1: Parameter `divisor->top`
                135.    * If 'dv' or 'rm' is NULL, the respective value is not returned.
                136.    */
                137. > int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,
                138.              BN_CTX *ctx)
                139.   {

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:102:1: Parameter `m->top`
              100.   }
              101.   
              102. > int BN_mod_sqr(BIGNUM *r, const BIGNUM *a, const BIGNUM *m, BN_CTX *ctx)
              103.   {
              104.       if (!BN_sqr(r, a, ctx))

crypto/bn/bn_mod.c:107:12: Call
              105.           return 0;
              106.       /* r->neg == 0,  thus we don't need BN_nnmod */
              107.       return BN_mod(r, r, m, ctx);
                                ^
              108.   }
              109.   

crypto/bn/bn_div.c:199:31: Call
                197.   
                198.       /* First we normalise the numbers */
                199.       norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);
                                                     ^
                200.       if (!(BN_lshift(sdiv, divisor, norm_shift)))
                201.           goto err;

crypto/bn/bn_lib.c:140:9: Assignment
                  138.   
                  139.       if (BN_is_zero(a))
                  140.           return 0;
                                 ^
                  141.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
                  142.   }

crypto/bn/bn_div.c:199:5: Assignment
                197.   
                198.       /* First we normalise the numbers */
                199.       norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);
                           ^
                200.       if (!(BN_lshift(sdiv, divisor, norm_shift)))
                201.           goto err;

crypto/bn/bn_div.c:200:11: Call
                198.       /* First we normalise the numbers */
                199.       norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);
                200.       if (!(BN_lshift(sdiv, divisor, norm_shift)))
                                 ^
                201.           goto err;
                202.       sdiv->neg = 0;

crypto/bn/bn_shift.c:83:1: <Offset trace>
81.   }
82.   
83. > int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
84.   {
85.       int i, nw, lb, rb;

crypto/bn/bn_shift.c:83:1: Parameter `n`
                  81.   }
                  82.   
                  83. > int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
                  84.   {
                  85.       int i, nw, lb, rb;

crypto/bn/bn_shift.c:97:5: Assignment
                  95.       }
                  96.   
                  97.       nw = n / BN_BITS2;
                             ^
                  98.       if (bn_wexpand(r, a->top + nw + 1) == NULL)
                  99.           return 0;

crypto/bn/bn_shift.c:83:1: <Length trace>
81.   }
82.   
83. > int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
84.   {
85.       int i, nw, lb, rb;

crypto/bn/bn_shift.c:83:1: Parameter `*r->d`
                  81.   }
                  82.   
                  83. > int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
                  84.   {
                  85.       int i, nw, lb, rb;

crypto/bn/bn_shift.c:98:9: Call
                  96.   
                  97.       nw = n / BN_BITS2;
                  98.       if (bn_wexpand(r, a->top + nw + 1) == NULL)
                                 ^
                  99.           return 0;
                  100.       r->neg = a->neg;

crypto/bn/bn_lib.c:941:1: Parameter `*a->d`
                    939.   }
                    940.   
                    941. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
                    942.   {
                    943.       return (words <= a->dmax) ? a : bn_expand2(a, words);

crypto/bn/bn_shift.c:104:5: Assignment
                  102.       rb = BN_BITS2 - lb;
                  103.       f = a->d;
                  104.       t = r->d;
                             ^
                  105.       t[a->top + nw] = 0;
                  106.       if (lb == 0)

crypto/bn/bn_shift.c:112:13: Array access: Offset: [1, +oo] Size: [0, 8388607] by call to `o2i_ECPublicKey` 
                  110.           for (i = a->top - 1; i >= 0; i--) {
                  111.               l = f[i];
                  112.               t[nw + i + 1] |= (l >> rb) & BN_MASK2;
                                     ^
                  113.               t[nw + i] = (l << lb) & BN_MASK2;
                  114.           }

int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)
{
    int i, nw, lb, rb;
    BN_ULONG *t, *f;
    BN_ULONG l;
    bn_check_top(r);
    bn_check_top(a);
    if (n < 0) {
        BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);
        return 0;
    }
    nw = n / BN_BITS2;
    if (bn_wexpand(r, a->top + nw + 1) == NULL)
        return 0;
    r->neg = a->neg;
    lb = n % BN_BITS2;
    rb = BN_BITS2 - lb;
    f = a->d;
    t = r->d;
    t[a->top + nw] = 0;
    if (lb == 0)
        for (i = a->top - 1; i >= 0; i--)
            t[nw + i] = f[i];
    else
        for (i = a->top - 1; i >= 0; i--) {
            l = f[i];
            t[nw + i + 1] |= (l >> rb) & BN_MASK2;
            t[nw + i] = (l << lb) & BN_MASK2;
        }
    memset(t, 0, sizeof(*t) * nw);
    r->top = a->top + nw + 1;
    bn_correct_top(r);
    bn_check_top(r);
    return 1;
}
['static int ecdh_cms_set_peerkey(EVP_PKEY_CTX *pctx,\n                                X509_ALGOR *alg, ASN1_BIT_STRING *pubkey)\n{\n    const ASN1_OBJECT *aoid;\n    int atype;\n    const void *aval;\n    int rv = 0;\n    EVP_PKEY *pkpeer = NULL;\n    EC_KEY *ecpeer = NULL;\n    const unsigned char *p;\n    int plen;\n    X509_ALGOR_get0(&aoid, &atype, &aval, alg);\n    if (OBJ_obj2nid(aoid) != NID_X9_62_id_ecPublicKey)\n        goto err;\n    if (atype == V_ASN1_UNDEF || atype == V_ASN1_NULL) {\n        const EC_GROUP *grp;\n        EVP_PKEY *pk;\n        pk = EVP_PKEY_CTX_get0_pkey(pctx);\n        if (!pk)\n            goto err;\n        grp = EC_KEY_get0_group(pk->pkey.ec);\n        ecpeer = EC_KEY_new();\n        if (ecpeer == NULL)\n            goto err;\n        if (!EC_KEY_set_group(ecpeer, grp))\n            goto err;\n    } else {\n        ecpeer = eckey_type2param(atype, aval);\n        if (!ecpeer)\n            goto err;\n    }\n    plen = ASN1_STRING_length(pubkey);\n    p = ASN1_STRING_get0_data(pubkey);\n    if (!p || !plen)\n        goto err;\n    if (!o2i_ECPublicKey(&ecpeer, &p, plen))\n        goto err;\n    pkpeer = EVP_PKEY_new();\n    if (pkpeer == NULL)\n        goto err;\n    EVP_PKEY_set1_EC_KEY(pkpeer, ecpeer);\n    if (EVP_PKEY_derive_set_peer(pctx, pkpeer) > 0)\n        rv = 1;\n err:\n    EC_KEY_free(ecpeer);\n    EVP_PKEY_free(pkpeer);\n    return rv;\n}', 'int EC_KEY_set_group(EC_KEY *key, const EC_GROUP *group)\n{\n    if (key->meth->set_group != NULL && key->meth->set_group(key, group) == 0)\n        return 0;\n    EC_GROUP_free(key->group);\n    key->group = EC_GROUP_dup(group);\n    return (key->group == NULL) ? 0 : 1;\n}', 'EC_GROUP *EC_GROUP_dup(const EC_GROUP *a)\n{\n    EC_GROUP *t = NULL;\n    int ok = 0;\n    if (a == NULL)\n        return NULL;\n    if ((t = EC_GROUP_new(a->meth)) == NULL)\n        return NULL;\n    if (!EC_GROUP_copy(t, a))\n        goto err;\n    ok = 1;\n err:\n    if (!ok) {\n        EC_GROUP_free(t);\n        return NULL;\n    }\n        return t;\n}', 'int EC_GROUP_copy(EC_GROUP *dest, const EC_GROUP *src)\n{\n    if (dest->meth->group_copy == 0) {\n        ECerr(EC_F_EC_GROUP_COPY, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n        return 0;\n    }\n    if (dest->meth != src->meth) {\n        ECerr(EC_F_EC_GROUP_COPY, EC_R_INCOMPATIBLE_OBJECTS);\n        return 0;\n    }\n    if (dest == src)\n        return 1;\n    dest->pre_comp_type = src->pre_comp_type;\n    switch (src->pre_comp_type) {\n    case PCT_none:\n        dest->pre_comp.ec = NULL;\n        break;\n    case PCT_nistz256:\n#ifdef ECP_NISTZ256_ASM\n        dest->pre_comp.nistz256 = EC_nistz256_pre_comp_dup(src->pre_comp.nistz256);\n#endif\n        break;\n#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128\n    case PCT_nistp224:\n        dest->pre_comp.nistp224 = EC_nistp224_pre_comp_dup(src->pre_comp.nistp224);\n        break;\n    case PCT_nistp256:\n        dest->pre_comp.nistp256 = EC_nistp256_pre_comp_dup(src->pre_comp.nistp256);\n        break;\n    case PCT_nistp521:\n        dest->pre_comp.nistp521 = EC_nistp521_pre_comp_dup(src->pre_comp.nistp521);\n        break;\n#else\n    case PCT_nistp224:\n    case PCT_nistp256:\n    case PCT_nistp521:\n        break;\n#endif\n    case PCT_ec:\n        dest->pre_comp.ec = EC_ec_pre_comp_dup(src->pre_comp.ec);\n        break;\n    }\n    if (src->mont_data != NULL) {\n        if (dest->mont_data == NULL) {\n            dest->mont_data = BN_MONT_CTX_new();\n            if (dest->mont_data == NULL)\n                return 0;\n        }\n        if (!BN_MONT_CTX_copy(dest->mont_data, src->mont_data))\n            return 0;\n    } else {\n        BN_MONT_CTX_free(dest->mont_data);\n        dest->mont_data = NULL;\n    }\n    if (src->generator != NULL) {\n        if (dest->generator == NULL) {\n            dest->generator = EC_POINT_new(dest);\n            if (dest->generator == NULL)\n                return 0;\n        }\n        if (!EC_POINT_copy(dest->generator, src->generator))\n            return 0;\n    } else {\n        EC_POINT_clear_free(dest->generator);\n        dest->generator = NULL;\n    }\n    if ((src->meth->flags & EC_FLAGS_CUSTOM_CURVE) == 0) {\n        if (!BN_copy(dest->order, src->order))\n            return 0;\n        if (!BN_copy(dest->cofactor, src->cofactor))\n            return 0;\n    }\n    dest->curve_name = src->curve_name;\n    dest->asn1_flag = src->asn1_flag;\n    dest->asn1_form = src->asn1_form;\n    if (src->seed) {\n        OPENSSL_free(dest->seed);\n        if ((dest->seed = OPENSSL_malloc(src->seed_len)) == NULL) {\n            ECerr(EC_F_EC_GROUP_COPY, ERR_R_MALLOC_FAILURE);\n            return 0;\n        }\n        if (!memcpy(dest->seed, src->seed, src->seed_len))\n            return 0;\n        dest->seed_len = src->seed_len;\n    } else {\n        OPENSSL_free(dest->seed);\n        dest->seed = NULL;\n        dest->seed_len = 0;\n    }\n    return dest->meth->group_copy(dest, src);\n}', 'EC_KEY *o2i_ECPublicKey(EC_KEY **a, const unsigned char **in, long len)\n{\n    EC_KEY *ret = NULL;\n    if (a == NULL || (*a) == NULL || (*a)->group == NULL) {\n        ECerr(EC_F_O2I_ECPUBLICKEY, ERR_R_PASSED_NULL_PARAMETER);\n        return 0;\n    }\n    ret = *a;\n    if (!EC_KEY_oct2key(ret, *in, len, NULL)) {\n        ECerr(EC_F_O2I_ECPUBLICKEY, ERR_R_EC_LIB);\n        return 0;\n    }\n    *in += len;\n    return ret;\n}', 'int EC_KEY_oct2key(EC_KEY *key, const unsigned char *buf, size_t len,\n                   BN_CTX *ctx)\n{\n    if (key == NULL || key->group == NULL)\n        return 0;\n    if (key->pub_key == NULL)\n        key->pub_key = EC_POINT_new(key->group);\n    if (key->pub_key == NULL)\n        return 0;\n    if (EC_POINT_oct2point(key->group, key->pub_key, buf, len, ctx) == 0)\n        return 0;\n    if ((key->group->meth->flags & EC_FLAGS_CUSTOM_CURVE) == 0)\n        key->conv_form = (point_conversion_form_t)(buf[0] & ~0x01);\n    return 1;\n}', 'int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point,\n                       const unsigned char *buf, size_t len, BN_CTX *ctx)\n{\n    if (group->meth->oct2point == 0\n        && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) {\n        ECerr(EC_F_EC_POINT_OCT2POINT, ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n        return 0;\n    }\n    if (group->meth != point->meth) {\n        ECerr(EC_F_EC_POINT_OCT2POINT, 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_oct2point(group, point, buf, len, ctx);\n        else\n#ifdef OPENSSL_NO_EC2M\n        {\n            ECerr(EC_F_EC_POINT_OCT2POINT, EC_R_GF2M_NOT_SUPPORTED);\n            return 0;\n        }\n#else\n            return ec_GF2m_simple_oct2point(group, point, buf, len, ctx);\n#endif\n    }\n    return group->meth->oct2point(group, point, buf, len, ctx);\n}', 'int ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point,\n                             const unsigned char *buf, size_t len,\n                             BN_CTX *ctx)\n{\n    point_conversion_form_t form;\n    int y_bit;\n    BN_CTX *new_ctx = NULL;\n    BIGNUM *x, *y, *yxi;\n    size_t field_len, enc_len;\n    int ret = 0;\n    if (len == 0) {\n        ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_BUFFER_TOO_SMALL);\n        return 0;\n    }\n    form = buf[0];\n    y_bit = form & 1;\n    form = form & ~1U;\n    if ((form != 0) && (form != POINT_CONVERSION_COMPRESSED)\n        && (form != POINT_CONVERSION_UNCOMPRESSED)\n        && (form != POINT_CONVERSION_HYBRID)) {\n        ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n        return 0;\n    }\n    if ((form == 0 || form == POINT_CONVERSION_UNCOMPRESSED) && y_bit) {\n        ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n        return 0;\n    }\n    if (form == 0) {\n        if (len != 1) {\n            ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n            return 0;\n        }\n        return EC_POINT_set_to_infinity(group, point);\n    }\n    field_len = (EC_GROUP_get_degree(group) + 7) / 8;\n    enc_len =\n        (form ==\n         POINT_CONVERSION_COMPRESSED) ? 1 + field_len : 1 + 2 * field_len;\n    if (len != enc_len) {\n        ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n        return 0;\n    }\n    if (ctx == NULL) {\n        ctx = new_ctx = BN_CTX_new();\n        if (ctx == NULL)\n            return 0;\n    }\n    BN_CTX_start(ctx);\n    x = BN_CTX_get(ctx);\n    y = BN_CTX_get(ctx);\n    yxi = BN_CTX_get(ctx);\n    if (yxi == NULL)\n        goto err;\n    if (!BN_bin2bn(buf + 1, field_len, x))\n        goto err;\n    if (BN_ucmp(x, group->field) >= 0) {\n        ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n        goto err;\n    }\n    if (form == POINT_CONVERSION_COMPRESSED) {\n        if (!EC_POINT_set_compressed_coordinates_GF2m\n            (group, point, x, y_bit, ctx))\n            goto err;\n    } else {\n        if (!BN_bin2bn(buf + 1 + field_len, field_len, y))\n            goto err;\n        if (BN_ucmp(y, group->field) >= 0) {\n            ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n            goto err;\n        }\n        if (form == POINT_CONVERSION_HYBRID) {\n            if (!group->meth->field_div(group, yxi, y, x, ctx))\n                goto err;\n            if (y_bit != BN_is_odd(yxi)) {\n                ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_INVALID_ENCODING);\n                goto err;\n            }\n        }\n        if (!EC_POINT_set_affine_coordinates_GF2m(group, point, x, y, ctx))\n            goto err;\n    }\n    ret = 1;\n err:\n    BN_CTX_end(ctx);\n    BN_CTX_free(new_ctx);\n    return ret;\n}', 'int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group,\n                                             EC_POINT *point, const BIGNUM *x,\n                                             int y_bit, BN_CTX *ctx)\n{\n    if (group->meth->point_set_compressed_coordinates == 0\n        && !(group->meth->flags & EC_FLAGS_DEFAULT_OCT)) {\n        ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M,\n              ERR_R_SHOULD_NOT_HAVE_BEEN_CALLED);\n        return 0;\n    }\n    if (group->meth != point->meth) {\n        ECerr(EC_F_EC_POINT_SET_COMPRESSED_COORDINATES_GF2M,\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            return ec_GF2m_simple_set_compressed_coordinates(group, point, x,\n                                                             y_bit, ctx);\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_GFp(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}', 'int BN_nnmod(BIGNUM *r, const BIGNUM *m, const BIGNUM *d, BN_CTX *ctx)\n{\n    if (!(BN_mod(r, m, d, ctx)))\n        return 0;\n    if (!r->neg)\n        return 1;\n    return (d->neg ? BN_sub : BN_add) (r, r, d);\n}', 'int BN_div(BIGNUM *dv, BIGNUM *rm, const BIGNUM *num, const BIGNUM *divisor,\n           BN_CTX *ctx)\n{\n    int norm_shift, i, loop;\n    BIGNUM *tmp, wnum, *snum, *sdiv, *res;\n    BN_ULONG *resp, *wnump;\n    BN_ULONG d0, d1;\n    int num_n, div_n;\n    int no_branch = 0;\n    if ((num->top > 0 && num->d[num->top - 1] == 0) ||\n        (divisor->top > 0 && divisor->d[divisor->top - 1] == 0)) {\n        BNerr(BN_F_BN_DIV, BN_R_NOT_INITIALIZED);\n        return 0;\n    }\n    bn_check_top(num);\n    bn_check_top(divisor);\n    if ((BN_get_flags(num, BN_FLG_CONSTTIME) != 0)\n        || (BN_get_flags(divisor, BN_FLG_CONSTTIME) != 0)) {\n        no_branch = 1;\n    }\n    bn_check_top(dv);\n    bn_check_top(rm);\n    if (BN_is_zero(divisor)) {\n        BNerr(BN_F_BN_DIV, BN_R_DIV_BY_ZERO);\n        return 0;\n    }\n    if (!no_branch && BN_ucmp(num, divisor) < 0) {\n        if (rm != NULL) {\n            if (BN_copy(rm, num) == NULL)\n                return 0;\n        }\n        if (dv != NULL)\n            BN_zero(dv);\n        return 1;\n    }\n    BN_CTX_start(ctx);\n    res = (dv == NULL) ? BN_CTX_get(ctx) : dv;\n    tmp = BN_CTX_get(ctx);\n    snum = BN_CTX_get(ctx);\n    sdiv = BN_CTX_get(ctx);\n    if (sdiv == NULL)\n        goto err;\n    norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);\n    if (!(BN_lshift(sdiv, divisor, norm_shift)))\n        goto err;\n    sdiv->neg = 0;\n    norm_shift += BN_BITS2;\n    if (!(BN_lshift(snum, num, norm_shift)))\n        goto err;\n    snum->neg = 0;\n    if (no_branch) {\n        if (snum->top <= sdiv->top + 1) {\n            if (bn_wexpand(snum, sdiv->top + 2) == NULL)\n                goto err;\n            for (i = snum->top; i < sdiv->top + 2; i++)\n                snum->d[i] = 0;\n            snum->top = sdiv->top + 2;\n        } else {\n            if (bn_wexpand(snum, snum->top + 1) == NULL)\n                goto err;\n            snum->d[snum->top] = 0;\n            snum->top++;\n        }\n    }\n    div_n = sdiv->top;\n    num_n = snum->top;\n    loop = num_n - div_n;\n    wnum.neg = 0;\n    wnum.d = &(snum->d[loop]);\n    wnum.top = div_n;\n    wnum.dmax = snum->dmax - loop;\n    d0 = sdiv->d[div_n - 1];\n    d1 = (div_n == 1) ? 0 : sdiv->d[div_n - 2];\n    wnump = &(snum->d[num_n - 1]);\n    if (!bn_wexpand(res, (loop + 1)))\n        goto err;\n    res->neg = (num->neg ^ divisor->neg);\n    res->top = loop - no_branch;\n    resp = &(res->d[loop - 1]);\n    if (!bn_wexpand(tmp, (div_n + 1)))\n        goto err;\n    if (!no_branch) {\n        if (BN_ucmp(&wnum, sdiv) >= 0) {\n            bn_clear_top2max(&wnum);\n            bn_sub_words(wnum.d, wnum.d, sdiv->d, div_n);\n            *resp = 1;\n        } else\n            res->top--;\n    }\n    resp++;\n    if (res->top == 0)\n        res->neg = 0;\n    else\n        resp--;\n    for (i = 0; i < loop - 1; i++, wnump--) {\n        BN_ULONG q, l0;\n# if defined(BN_DIV3W) && !defined(OPENSSL_NO_ASM)\n        BN_ULONG bn_div_3_words(BN_ULONG *, BN_ULONG, BN_ULONG);\n        q = bn_div_3_words(wnump, d1, d0);\n# else\n        BN_ULONG n0, n1, rem = 0;\n        n0 = wnump[0];\n        n1 = wnump[-1];\n        if (n0 == d0)\n            q = BN_MASK2;\n        else {\n#  ifdef BN_LLONG\n            BN_ULLONG t2;\n#   if defined(BN_LLONG) && defined(BN_DIV2W) && !defined(bn_div_words)\n            q = (BN_ULONG)(((((BN_ULLONG) n0) << BN_BITS2) | n1) / d0);\n#   else\n            q = bn_div_words(n0, n1, d0);\n#   endif\n#   ifndef REMAINDER_IS_ALREADY_CALCULATED\n            rem = (n1 - q * d0) & BN_MASK2;\n#   endif\n            t2 = (BN_ULLONG) d1 *q;\n            for (;;) {\n                if (t2 <= ((((BN_ULLONG) rem) << BN_BITS2) | wnump[-2]))\n                    break;\n                q--;\n                rem += d0;\n                if (rem < d0)\n                    break;\n                t2 -= d1;\n            }\n#  else\n            BN_ULONG t2l, t2h;\n            q = bn_div_words(n0, n1, d0);\n#   ifndef REMAINDER_IS_ALREADY_CALCULATED\n            rem = (n1 - q * d0) & BN_MASK2;\n#   endif\n#   if defined(BN_UMULT_LOHI)\n            BN_UMULT_LOHI(t2l, t2h, d1, q);\n#   elif defined(BN_UMULT_HIGH)\n            t2l = d1 * q;\n            t2h = BN_UMULT_HIGH(d1, q);\n#   else\n            {\n                BN_ULONG ql, qh;\n                t2l = LBITS(d1);\n                t2h = HBITS(d1);\n                ql = LBITS(q);\n                qh = HBITS(q);\n                mul64(t2l, t2h, ql, qh);\n            }\n#   endif\n            for (;;) {\n                if ((t2h < rem) || ((t2h == rem) && (t2l <= wnump[-2])))\n                    break;\n                q--;\n                rem += d0;\n                if (rem < d0)\n                    break;\n                if (t2l < d1)\n                    t2h--;\n                t2l -= d1;\n            }\n#  endif\n        }\n# endif\n        l0 = bn_mul_words(tmp->d, sdiv->d, div_n, q);\n        tmp->d[div_n] = l0;\n        wnum.d--;\n        if (bn_sub_words(wnum.d, wnum.d, tmp->d, div_n + 1)) {\n            q--;\n            if (bn_add_words(wnum.d, wnum.d, sdiv->d, div_n))\n                (*wnump)++;\n        }\n        resp--;\n        *resp = q;\n    }\n    bn_correct_top(snum);\n    if (rm != NULL) {\n        int neg = num->neg;\n        BN_rshift(rm, snum, norm_shift);\n        if (!BN_is_zero(rm))\n            rm->neg = neg;\n        bn_check_top(rm);\n    }\n    if (no_branch)\n        bn_correct_top(res);\n    BN_CTX_end(ctx);\n    return 1;\n err:\n    bn_check_top(rm);\n    BN_CTX_end(ctx);\n    return 0;\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_num_bits(const BIGNUM *a)\n{\n    int i = a->top - 1;\n    bn_check_top(a);\n    if (BN_is_zero(a))\n        return 0;\n    return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));\n}', 'int BN_lshift(BIGNUM *r, const BIGNUM *a, int n)\n{\n    int i, nw, lb, rb;\n    BN_ULONG *t, *f;\n    BN_ULONG l;\n    bn_check_top(r);\n    bn_check_top(a);\n    if (n < 0) {\n        BNerr(BN_F_BN_LSHIFT, BN_R_INVALID_SHIFT);\n        return 0;\n    }\n    nw = n / BN_BITS2;\n    if (bn_wexpand(r, a->top + nw + 1) == NULL)\n        return 0;\n    r->neg = a->neg;\n    lb = n % BN_BITS2;\n    rb = BN_BITS2 - lb;\n    f = a->d;\n    t = r->d;\n    t[a->top + nw] = 0;\n    if (lb == 0)\n        for (i = a->top - 1; i >= 0; i--)\n            t[nw + i] = f[i];\n    else\n        for (i = a->top - 1; i >= 0; i--) {\n            l = f[i];\n            t[nw + i + 1] |= (l >> rb) & BN_MASK2;\n            t[nw + i] = (l << lb) & BN_MASK2;\n        }\n    memset(t, 0, sizeof(*t) * nw);\n    r->top = a->top + nw + 1;\n    bn_correct_top(r);\n    bn_check_top(r);\n    return 1;\n}', 'BIGNUM *bn_wexpand(BIGNUM *a, int words)\n{\n    return (words <= a->dmax) ? a : bn_expand2(a, words);\n}']