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


crypto/ec/ec_ameth.c:193:13: Call
191.       X509_ALGOR_get0(NULL, &ptype, &pval, palg);
192.   
193.       eckey = eckey_type2param(ptype, pval);
                   ^
194.   
195.       if (!eckey)

crypto/ec/ec_ameth.c:115:17: Call
  113.               goto ecerr;
  114.           }
  115.           group = EC_GROUP_new_by_curve_name(OBJ_obj2nid(poid));
                         ^
  116.           if (group == NULL)
  117.               goto ecerr;

crypto/ec/ec_curve.c:3096:19: Call
    3094.       for (i = 0; i < curve_list_length; i++)
    3095.           if (curve_list[i].nid == nid) {
    3096.               ret = ec_group_new_from_data(curve_list[i]);
                              ^
    3097.               break;
    3098.           }

crypto/ec/ec_curve.c:3009:14: Call
      3007.       params += seed_len;         /* skip seed */
      3008.   
      3009.       if ((p = BN_bin2bn(params + 0 * param_len, param_len, NULL)) == NULL
                           ^
      3010.           || (a = BN_bin2bn(params + 1 * param_len, param_len, NULL)) == NULL
      3011.           || (b = BN_bin2bn(params + 2 * param_len, param_len, NULL)) == NULL) {

crypto/bn/bn_lib.c:475:1: Parameter `ret->top`
        473.   }
        474.   
        475. > BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)
        476.   {
        477.       unsigned int i, m;

crypto/ec/ec_ameth.c:199:10: Call
197.   
198.       /* We have parameters now set private key */
199.       if (!d2i_ECPrivateKey(&eckey, &p, pklen)) {
                ^
200.           ECerr(EC_F_ECKEY_PRIV_DECODE, EC_R_DECODE_ERROR);
201.           goto ecerr;

crypto/ec/ec_asn1.c:918:1: Parameter `(*a)->group->field->top`
  916.   /* some EC_KEY functions */
  917.   
  918. > EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
  919.   {
  920.       EC_KEY *ret = NULL;

crypto/ec/ec_asn1.c:972:14: Call
  970.           pub_oct = ASN1_STRING_data(priv_key->publicKey);
  971.           pub_oct_len = ASN1_STRING_length(priv_key->publicKey);
  972.           if (!EC_KEY_oct2key(ret, pub_oct, pub_oct_len, NULL)) {
                      ^
  973.               ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);
  974.               goto err;

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:118:1: Parameter `group->field->top`
      116.   }
      117.   
      118. > int EC_POINT_oct2point(const EC_GROUP *group, EC_POINT *point,
      119.                          const unsigned char *buf, size_t len, BN_CTX *ctx)
      120.   {

crypto/ec/ec_oct.c:140:20: Call
      138.           }
      139.   #else
      140.               return ec_GF2m_simple_oct2point(group, point, buf, len, ctx);
                                ^
      141.   #endif
      142.       }

crypto/ec/ec2_oct.c:249:1: Parameter `group->field->top`
        247.    * simple implementation only uses affine coordinates.
        248.    */
        249. > int ec_GF2m_simple_oct2point(const EC_GROUP *group, EC_POINT *point,
        250.                                const unsigned char *buf, size_t len,
        251.                                BN_CTX *ctx)

crypto/ec/ec2_oct.c:318:14: Call
        316.   
        317.       if (form == POINT_CONVERSION_COMPRESSED) {
        318.           if (!EC_POINT_set_compressed_coordinates_GF2m
                            ^
        319.               (group, point, x, y_bit, ctx))
        320.               goto err;

crypto/ec/ec_oct.c:59:1: Parameter `group->field->top`
          57.   
          58.   #ifndef OPENSSL_NO_EC2M
          59. > int EC_POINT_set_compressed_coordinates_GF2m(const EC_GROUP *group,
          60.                                                EC_POINT *point, const BIGNUM *x,
          61.                                                int y_bit, BN_CTX *ctx)

crypto/ec/ec_oct.c:76:20: Call
          74.       if (group->meth->flags & EC_FLAGS_DEFAULT_OCT) {
          75.           if (group->meth->field_type == NID_X9_62_prime_field)
          76.               return ec_GFp_simple_set_compressed_coordinates(group, point, x,
                                   ^
          77.                                                               y_bit, ctx);
          78.           else

crypto/ec/ecp_oct.c:21:1: Parameter `group->field->top`
            19.   #include "ec_lcl.h"
            20.   
            21. > int ec_GFp_simple_set_compressed_coordinates(const EC_GROUP *group,
            22.                                                EC_POINT *point,
            23.                                                const BIGNUM *x_, int y_bit,

crypto/ec/ecp_oct.c:56:10: Call
            54.   
            55.       /* tmp1 := x^3 */
            56.       if (!BN_nnmod(x, x_, group->field, ctx))
                           ^
            57.           goto err;
            58.       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:205:31: Call
                203.   
                204.       /* First we normalise the numbers */
                205.       norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);
                                                     ^
                206.       if (!(BN_lshift(sdiv, divisor, norm_shift)))
                207.           goto err;

crypto/bn/bn_lib.c:167:9: Assignment
                  165.   
                  166.       if (BN_is_zero(a))
                  167.           return 0;
                                 ^
                  168.       return ((i * BN_BITS2) + BN_num_bits_word(a->d[i]));
                  169.   }

crypto/bn/bn_div.c:205:5: Assignment
                203.   
                204.       /* First we normalise the numbers */
                205.       norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);
                           ^
                206.       if (!(BN_lshift(sdiv, divisor, norm_shift)))
                207.           goto err;

crypto/bn/bn_div.c:206:11: Call
                204.       /* First we normalise the numbers */
                205.       norm_shift = BN_BITS2 - ((BN_num_bits(divisor)) % BN_BITS2);
                206.       if (!(BN_lshift(sdiv, divisor, norm_shift)))
                                 ^
                207.           goto err;
                208.       sdiv->neg = 0;

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

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

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

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

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

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

crypto/bn/bn_lib.c:1014:1: Parameter `*a->d`
                    1012.   }
                    1013.   
                    1014. > BIGNUM *bn_wexpand(BIGNUM *a, int words)
                    1015.   {
                    1016.       return (words <= a->dmax) ? a : bn_expand2(a, words);

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

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

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;
    }
    r->neg = a->neg;
    nw = n / BN_BITS2;
    if (bn_wexpand(r, a->top + nw + 1) == NULL)
        return (0);
    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 eckey_priv_decode(EVP_PKEY *pkey, PKCS8_PRIV_KEY_INFO *p8)\n{\n    const unsigned char *p = NULL;\n    void *pval;\n    int ptype, pklen;\n    EC_KEY *eckey = NULL;\n    X509_ALGOR *palg;\n    if (!PKCS8_pkey_get0(NULL, &p, &pklen, &palg, p8))\n        return 0;\n    X509_ALGOR_get0(NULL, &ptype, &pval, palg);\n    eckey = eckey_type2param(ptype, pval);\n    if (!eckey)\n        goto ecliberr;\n    if (!d2i_ECPrivateKey(&eckey, &p, pklen)) {\n        ECerr(EC_F_ECKEY_PRIV_DECODE, EC_R_DECODE_ERROR);\n        goto ecerr;\n    }\n    EVP_PKEY_assign_EC_KEY(pkey, eckey);\n    return 1;\n ecliberr:\n    ECerr(EC_F_ECKEY_PRIV_DECODE, ERR_R_EC_LIB);\n ecerr:\n    EC_KEY_free(eckey);\n    return 0;\n}', 'static EC_KEY *eckey_type2param(int ptype, void *pval)\n{\n    EC_KEY *eckey = NULL;\n    if (ptype == V_ASN1_SEQUENCE) {\n        ASN1_STRING *pstr = pval;\n        const unsigned char *pm = NULL;\n        int pmlen;\n        pm = pstr->data;\n        pmlen = pstr->length;\n        if ((eckey = d2i_ECParameters(NULL, &pm, pmlen)) == NULL) {\n            ECerr(EC_F_ECKEY_TYPE2PARAM, EC_R_DECODE_ERROR);\n            goto ecerr;\n        }\n    } else if (ptype == V_ASN1_OBJECT) {\n        ASN1_OBJECT *poid = pval;\n        EC_GROUP *group;\n        if ((eckey = EC_KEY_new()) == NULL) {\n            ECerr(EC_F_ECKEY_TYPE2PARAM, ERR_R_MALLOC_FAILURE);\n            goto ecerr;\n        }\n        group = EC_GROUP_new_by_curve_name(OBJ_obj2nid(poid));\n        if (group == NULL)\n            goto ecerr;\n        EC_GROUP_set_asn1_flag(group, OPENSSL_EC_NAMED_CURVE);\n        if (EC_KEY_set_group(eckey, group) == 0)\n            goto ecerr;\n        EC_GROUP_free(group);\n    } else {\n        ECerr(EC_F_ECKEY_TYPE2PARAM, EC_R_DECODE_ERROR);\n        goto ecerr;\n    }\n    return eckey;\n ecerr:\n    EC_KEY_free(eckey);\n    return NULL;\n}', 'EC_GROUP *EC_GROUP_new_by_curve_name(int nid)\n{\n    size_t i;\n    EC_GROUP *ret = NULL;\n    if (nid <= 0)\n        return NULL;\n    for (i = 0; i < curve_list_length; i++)\n        if (curve_list[i].nid == nid) {\n            ret = ec_group_new_from_data(curve_list[i]);\n            break;\n        }\n    if (ret == NULL) {\n        ECerr(EC_F_EC_GROUP_NEW_BY_CURVE_NAME, EC_R_UNKNOWN_GROUP);\n        return NULL;\n    }\n    EC_GROUP_set_curve_name(ret, nid);\n    return ret;\n}', 'static EC_GROUP *ec_group_new_from_data(const ec_list_element curve)\n{\n    EC_GROUP *group = NULL;\n    EC_POINT *P = NULL;\n    BN_CTX *ctx = NULL;\n    BIGNUM *p = NULL, *a = NULL, *b = NULL, *x = NULL, *y = NULL, *order =\n        NULL;\n    int ok = 0;\n    int seed_len, param_len;\n    const EC_METHOD *meth;\n    const EC_CURVE_DATA *data;\n    const unsigned char *params;\n    if (curve.data == NULL)\n        return EC_GROUP_new(curve.meth != NULL ? curve.meth() : NULL);\n    if ((ctx = BN_CTX_new()) == NULL) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    data = curve.data;\n    seed_len = data->seed_len;\n    param_len = data->param_len;\n    params = (const unsigned char *)(data + 1);\n    params += seed_len;\n    if ((p = BN_bin2bn(params + 0 * param_len, param_len, NULL)) == NULL\n        || (a = BN_bin2bn(params + 1 * param_len, param_len, NULL)) == NULL\n        || (b = BN_bin2bn(params + 2 * param_len, param_len, NULL)) == NULL) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB);\n        goto err;\n    }\n    if (curve.meth != 0) {\n        meth = curve.meth();\n        if (((group = EC_GROUP_new(meth)) == NULL) ||\n            (!(group->meth->group_set_curve(group, p, a, b, ctx)))) {\n            ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n            goto err;\n        }\n    } else if (data->field_type == NID_X9_62_prime_field) {\n        if ((group = EC_GROUP_new_curve_GFp(p, a, b, ctx)) == NULL) {\n            ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n            goto err;\n        }\n    }\n#ifndef OPENSSL_NO_EC2M\n    else {\n        if ((group = EC_GROUP_new_curve_GF2m(p, a, b, ctx)) == NULL) {\n            ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n            goto err;\n        }\n    }\n#endif\n    if ((P = EC_POINT_new(group)) == NULL) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n        goto err;\n    }\n    if ((x = BN_bin2bn(params + 3 * param_len, param_len, NULL)) == NULL\n        || (y = BN_bin2bn(params + 4 * param_len, param_len, NULL)) == NULL) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB);\n        goto err;\n    }\n    if (!EC_POINT_set_affine_coordinates_GFp(group, P, x, y, ctx)) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n        goto err;\n    }\n    if ((order = BN_bin2bn(params + 5 * param_len, param_len, NULL)) == NULL\n        || !BN_set_word(x, (BN_ULONG)data->cofactor)) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_BN_LIB);\n        goto err;\n    }\n    if (!EC_GROUP_set_generator(group, P, order, x)) {\n        ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n        goto err;\n    }\n    if (seed_len) {\n        if (!EC_GROUP_set_seed(group, params - seed_len, seed_len)) {\n            ECerr(EC_F_EC_GROUP_NEW_FROM_DATA, ERR_R_EC_LIB);\n            goto err;\n        }\n    }\n    ok = 1;\n err:\n    if (!ok) {\n        EC_GROUP_free(group);\n        group = NULL;\n    }\n    EC_POINT_free(P);\n    BN_CTX_free(ctx);\n    BN_free(p);\n    BN_free(a);\n    BN_free(b);\n    BN_free(order);\n    BN_free(x);\n    BN_free(y);\n    return group;\n}', 'BIGNUM *BN_bin2bn(const unsigned char *s, int len, BIGNUM *ret)\n{\n    unsigned int i, m;\n    unsigned int n;\n    BN_ULONG l;\n    BIGNUM *bn = NULL;\n    if (ret == NULL)\n        ret = bn = BN_new();\n    if (ret == NULL)\n        return (NULL);\n    bn_check_top(ret);\n    for ( ; len > 0 && *s == 0; s++, len--)\n        continue;\n    n = len;\n    if (n == 0) {\n        ret->top = 0;\n        return (ret);\n    }\n    i = ((n - 1) / BN_BYTES) + 1;\n    m = ((n - 1) % (BN_BYTES));\n    if (bn_wexpand(ret, (int)i) == NULL) {\n        BN_free(bn);\n        return NULL;\n    }\n    ret->top = i;\n    ret->neg = 0;\n    l = 0;\n    while (n--) {\n        l = (l << 8L) | *(s++);\n        if (m-- == 0) {\n            ret->d[--i] = l;\n            l = 0;\n            m = BN_BYTES - 1;\n        }\n    }\n    bn_correct_top(ret);\n    return (ret);\n}', 'EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)\n{\n    EC_KEY *ret = NULL;\n    EC_PRIVATEKEY *priv_key = NULL;\n    const unsigned char *p = *in;\n    if ((priv_key = d2i_EC_PRIVATEKEY(NULL, &p, len)) == NULL) {\n        ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);\n        return NULL;\n    }\n    if (a == NULL || *a == NULL) {\n        if ((ret = EC_KEY_new()) == NULL) {\n            ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);\n            goto err;\n        }\n    } else\n        ret = *a;\n    if (priv_key->parameters) {\n        EC_GROUP_clear_free(ret->group);\n        ret->group = EC_GROUP_new_from_ecpkparameters(priv_key->parameters);\n    }\n    if (ret->group == NULL) {\n        ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);\n        goto err;\n    }\n    ret->version = priv_key->version;\n    if (priv_key->privateKey) {\n        ASN1_OCTET_STRING *pkey = priv_key->privateKey;\n        if (EC_KEY_oct2priv(ret, ASN1_STRING_data(pkey),\n                            ASN1_STRING_length(pkey)) == 0)\n            goto err;\n    } else {\n        ECerr(EC_F_D2I_ECPRIVATEKEY, EC_R_MISSING_PRIVATE_KEY);\n        goto err;\n    }\n    EC_POINT_clear_free(ret->pub_key);\n    ret->pub_key = EC_POINT_new(ret->group);\n    if (ret->pub_key == NULL) {\n        ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);\n        goto err;\n    }\n    if (priv_key->publicKey) {\n        const unsigned char *pub_oct;\n        int pub_oct_len;\n        pub_oct = ASN1_STRING_data(priv_key->publicKey);\n        pub_oct_len = ASN1_STRING_length(priv_key->publicKey);\n        if (!EC_KEY_oct2key(ret, pub_oct, pub_oct_len, NULL)) {\n            ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);\n            goto err;\n        }\n    } else {\n        if (ret->group->meth->keygenpub == NULL\n            || ret->group->meth->keygenpub(ret) == 0)\n                goto err;\n        ret->enc_flag |= EC_PKEY_NO_PUBKEY;\n    }\n    if (a)\n        *a = ret;\n    EC_PRIVATEKEY_free(priv_key);\n    *in = p;\n    return (ret);\n err:\n    if (a == NULL || *a != ret)\n        EC_KEY_free(ret);\n    EC_PRIVATEKEY_free(priv_key);\n    return NULL;\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    if (EC_POINT_is_on_curve(group, point, ctx) <= 0) {\n        ECerr(EC_F_EC_GF2M_SIMPLE_OCT2POINT, EC_R_POINT_IS_NOT_ON_CURVE);\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    tmp = BN_CTX_get(ctx);\n    snum = BN_CTX_get(ctx);\n    sdiv = BN_CTX_get(ctx);\n    if (dv == NULL)\n        res = BN_CTX_get(ctx);\n    else\n        res = dv;\n    if (sdiv == NULL || res == NULL || tmp == NULL || snum == 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    res->neg = (num->neg ^ divisor->neg);\n    if (!bn_wexpand(res, (loop + 1)))\n        goto err;\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_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    r->neg = a->neg;\n    nw = n / BN_BITS2;\n    if (bn_wexpand(r, a->top + nw + 1) == NULL)\n        return (0);\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}']