crypto/ec/ec_ameth.c:249: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned64 by call to `d2i_ECPrivateKey`.
Showing all 10 steps of the trace


crypto/ec/ec_ameth.c:249:10: Call
247.   
248.       /* We have parameters now set private key */
249.       if (!d2i_ECPrivateKey(&eckey, &p, pklen)) {
                ^
250.           ECerr(EC_F_ECKEY_PRIV_DECODE, EC_R_DECODE_ERROR);
251.           goto ecerr;

crypto/ec/ec_asn1.c:989:1: Parameter `(*a)->group->pre_comp.ec->w`
  987.   /* some EC_KEY functions */
  988.   
  989. > EC_KEY *d2i_ECPrivateKey(EC_KEY **a, const unsigned char **in, long len)
  990.   {
  991.       EC_KEY *ret = NULL;

crypto/ec/ec_asn1.c:1067:14: Call
  1065.           }
  1066.       } else {
  1067.           if (!EC_POINT_mul
                       ^
  1068.               (ret->group, ret->pub_key, ret->priv_key, NULL, NULL, NULL)) {
  1069.               ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);

crypto/ec/ec_lib.c:914:1: Parameter `group->pre_comp.ec->w`
    912.   }
    913.   
    914. > int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,
    915.                    const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)
    916.   {

crypto/ec/ec_lib.c:925:12: Call
    923.       scalars[0] = p_scalar;
    924.   
    925.       return EC_POINTs_mul(group, r, g_scalar,
                      ^
    926.                            (point != NULL
    927.                             && p_scalar != NULL), points, scalars, ctx);

crypto/ec/ec_lib.c:903:1: Parameter `group->pre_comp.ec->w`
      901.    */
      902.   
      903. > int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
      904.                     size_t num, const EC_POINT *points[],
      905.                     const BIGNUM *scalars[], BN_CTX *ctx)

crypto/ec/ec_lib.c:909:16: Call
      907.       if (group->meth->mul == 0)
      908.           /* use default */
      909.           return ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);
                            ^
      910.   
      911.       return group->meth->mul(group, r, scalar, num, points, scalars, ctx);

crypto/ec/ec_mult.c:154:1: <LHS trace>
152.    * in the addition if scalar != NULL
153.    */
154. > int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
155.                   size_t num, const EC_POINT *points[], const BIGNUM *scalars[],
156.                   BN_CTX *ctx)

crypto/ec/ec_mult.c:154:1: Parameter `group->pre_comp.ec->w`
        152.    * in the addition if scalar != NULL
        153.    */
        154. > int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
        155.                   size_t num, const EC_POINT *points[], const BIGNUM *scalars[],
        156.                   BN_CTX *ctx)

crypto/ec/ec_mult.c:232:13: Binary operation: ([0, +oo] - 1):unsigned64 by call to `d2i_ECPrivateKey` 
        230.                   numblocks = pre_comp->numblocks;
        231.   
        232.               pre_points_per_block = (size_t)1 << (pre_comp->w - 1);
                           ^
        233.   
        234.               /* check that pre_comp looks sane */

int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
                size_t num, const EC_POINT *points[], const BIGNUM *scalars[],
                BN_CTX *ctx)
{
    BN_CTX *new_ctx = NULL;
    const EC_POINT *generator = NULL;
    EC_POINT *tmp = NULL;
    size_t totalnum;
    size_t blocksize = 0, numblocks = 0;
    size_t pre_points_per_block = 0;
    size_t i, j;
    int k;
    int r_is_inverted = 0;
    int r_is_at_infinity = 1;
    size_t *wsize = NULL;
    signed char **wNAF = NULL;
    size_t *wNAF_len = NULL;
    size_t max_len = 0;
    size_t num_val;
    EC_POINT **val = NULL;
    EC_POINT **v;
    EC_POINT ***val_sub = NULL;
    const EC_PRE_COMP *pre_comp = NULL;
    int num_scalar = 0;
    int ret = 0;
    if (group->meth != r->meth) {
        ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS);
        return 0;
    }
    if ((scalar == NULL) && (num == 0)) {
        return EC_POINT_set_to_infinity(group, r);
    }
    for (i = 0; i < num; i++) {
        if (group->meth != points[i]->meth) {
            ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS);
            return 0;
        }
    }
    if (ctx == NULL) {
        ctx = new_ctx = BN_CTX_new();
        if (ctx == NULL)
            goto err;
    }
    if (scalar != NULL) {
        generator = EC_GROUP_get0_generator(group);
        if (generator == NULL) {
            ECerr(EC_F_EC_WNAF_MUL, EC_R_UNDEFINED_GENERATOR);
            goto err;
        }
        pre_comp = group->pre_comp.ec;
        if (pre_comp && pre_comp->numblocks
            && (EC_POINT_cmp(group, generator, pre_comp->points[0], ctx) ==
                0)) {
            blocksize = pre_comp->blocksize;
            numblocks = (BN_num_bits(scalar) / blocksize) + 1;
            if (numblocks > pre_comp->numblocks)
                numblocks = pre_comp->numblocks;
            pre_points_per_block = (size_t)1 << (pre_comp->w - 1);
            if (pre_comp->num != (pre_comp->numblocks * pre_points_per_block)) {
                ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
                goto err;
            }
        } else {
            pre_comp = NULL;
            numblocks = 1;
            num_scalar = 1;
        }
    }
    totalnum = num + numblocks;
    wsize = OPENSSL_malloc(totalnum * sizeof wsize[0]);
    wNAF_len = OPENSSL_malloc(totalnum * sizeof wNAF_len[0]);
    wNAF = OPENSSL_malloc((totalnum + 1) * sizeof wNAF[0]);
    val_sub = OPENSSL_malloc(totalnum * sizeof val_sub[0]);
    if (wNAF != NULL)
        wNAF[0] = NULL;
    if (wsize == NULL || wNAF_len == NULL || wNAF == NULL || val_sub == NULL) {
        ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);
        goto err;
    }
    num_val = 0;
    for (i = 0; i < num + num_scalar; i++) {
        size_t bits;
        bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar);
        wsize[i] = EC_window_bits_for_scalar_size(bits);
        num_val += (size_t)1 << (wsize[i] - 1);
        wNAF[i + 1] = NULL;
        wNAF[i] =
            bn_compute_wNAF((i < num ? scalars[i] : scalar), wsize[i],
                            &wNAF_len[i]);
        if (wNAF[i] == NULL)
            goto err;
        if (wNAF_len[i] > max_len)
            max_len = wNAF_len[i];
    }
    if (numblocks) {
        if (pre_comp == NULL) {
            if (num_scalar != 1) {
                ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
                goto err;
            }
        } else {
            signed char *tmp_wNAF = NULL;
            size_t tmp_len = 0;
            if (num_scalar != 0) {
                ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
                goto err;
            }
            wsize[num] = pre_comp->w;
            tmp_wNAF = bn_compute_wNAF(scalar, wsize[num], &tmp_len);
            if (!tmp_wNAF)
                goto err;
            if (tmp_len <= max_len) {
                numblocks = 1;
                totalnum = num + 1;
                wNAF[num] = tmp_wNAF;
                wNAF[num + 1] = NULL;
                wNAF_len[num] = tmp_len;
                if (tmp_len > max_len)
                    max_len = tmp_len;
                val_sub[num] = pre_comp->points;
            } else {
                signed char *pp;
                EC_POINT **tmp_points;
                if (tmp_len < numblocks * blocksize) {
                    numblocks = (tmp_len + blocksize - 1) / blocksize;
                    if (numblocks > pre_comp->numblocks) {
                        ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
                        goto err;
                    }
                    totalnum = num + numblocks;
                }
                pp = tmp_wNAF;
                tmp_points = pre_comp->points;
                for (i = num; i < totalnum; i++) {
                    if (i < totalnum - 1) {
                        wNAF_len[i] = blocksize;
                        if (tmp_len < blocksize) {
                            ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
                            goto err;
                        }
                        tmp_len -= blocksize;
                    } else
                        wNAF_len[i] = tmp_len;
                    wNAF[i + 1] = NULL;
                    wNAF[i] = OPENSSL_malloc(wNAF_len[i]);
                    if (wNAF[i] == NULL) {
                        ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);
                        OPENSSL_free(tmp_wNAF);
                        goto err;
                    }
                    memcpy(wNAF[i], pp, wNAF_len[i]);
                    if (wNAF_len[i] > max_len)
                        max_len = wNAF_len[i];
                    if (*tmp_points == NULL) {
                        ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
                        OPENSSL_free(tmp_wNAF);
                        goto err;
                    }
                    val_sub[i] = tmp_points;
                    tmp_points += pre_points_per_block;
                    pp += blocksize;
                }
                OPENSSL_free(tmp_wNAF);
            }
        }
    }
    val = OPENSSL_malloc((num_val + 1) * sizeof val[0]);
    if (val == NULL) {
        ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);
        goto err;
    }
    val[num_val] = NULL;
    v = val;
    for (i = 0; i < num + num_scalar; i++) {
        val_sub[i] = v;
        for (j = 0; j < ((size_t)1 << (wsize[i] - 1)); j++) {
            *v = EC_POINT_new(group);
            if (*v == NULL)
                goto err;
            v++;
        }
    }
    if (!(v == val + num_val)) {
        ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);
        goto err;
    }
    if ((tmp = EC_POINT_new(group)) == NULL)
        goto err;
    for (i = 0; i < num + num_scalar; i++) {
        if (i < num) {
            if (!EC_POINT_copy(val_sub[i][0], points[i]))
                goto err;
        } else {
            if (!EC_POINT_copy(val_sub[i][0], generator))
                goto err;
        }
        if (wsize[i] > 1) {
            if (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx))
                goto err;
            for (j = 1; j < ((size_t)1 << (wsize[i] - 1)); j++) {
                if (!EC_POINT_add
                    (group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx))
                    goto err;
            }
        }
    }
    if (!EC_POINTs_make_affine(group, num_val, val, ctx))
        goto err;
    r_is_at_infinity = 1;
    for (k = max_len - 1; k >= 0; k--) {
        if (!r_is_at_infinity) {
            if (!EC_POINT_dbl(group, r, r, ctx))
                goto err;
        }
        for (i = 0; i < totalnum; i++) {
            if (wNAF_len[i] > (size_t)k) {
                int digit = wNAF[i][k];
                int is_neg;
                if (digit) {
                    is_neg = digit < 0;
                    if (is_neg)
                        digit = -digit;
                    if (is_neg != r_is_inverted) {
                        if (!r_is_at_infinity) {
                            if (!EC_POINT_invert(group, r, ctx))
                                goto err;
                        }
                        r_is_inverted = !r_is_inverted;
                    }
                    if (r_is_at_infinity) {
                        if (!EC_POINT_copy(r, val_sub[i][digit >> 1]))
                            goto err;
                        r_is_at_infinity = 0;
                    } else {
                        if (!EC_POINT_add
                            (group, r, r, val_sub[i][digit >> 1], ctx))
                            goto err;
                    }
                }
            }
        }
    }
    if (r_is_at_infinity) {
        if (!EC_POINT_set_to_infinity(group, r))
            goto err;
    } else {
        if (r_is_inverted)
            if (!EC_POINT_invert(group, r, ctx))
                goto err;
    }
    ret = 1;
 err:
    BN_CTX_free(new_ctx);
    EC_POINT_free(tmp);
    OPENSSL_free(wsize);
    OPENSSL_free(wNAF_len);
    if (wNAF != NULL) {
        signed char **w;
        for (w = wNAF; *w != NULL; w++)
            OPENSSL_free(*w);
        OPENSSL_free(wNAF);
    }
    if (val != NULL) {
        for (v = val; *v != NULL; v++)
            EC_POINT_clear_free(*v);
        OPENSSL_free(val);
    }
    OPENSSL_free(val_sub);
    return ret;
}
['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    if (EC_KEY_get0_public_key(eckey) == NULL) {\n        const BIGNUM *priv_key;\n        const EC_GROUP *group;\n        EC_POINT *pub_key;\n        group = EC_KEY_get0_group(eckey);\n        pub_key = EC_POINT_new(group);\n        if (pub_key == NULL) {\n            ECerr(EC_F_ECKEY_PRIV_DECODE, ERR_R_EC_LIB);\n            goto ecliberr;\n        }\n        if (!EC_POINT_copy(pub_key, EC_GROUP_get0_generator(group))) {\n            EC_POINT_free(pub_key);\n            ECerr(EC_F_ECKEY_PRIV_DECODE, ERR_R_EC_LIB);\n            goto ecliberr;\n        }\n        priv_key = EC_KEY_get0_private_key(eckey);\n        if (!EC_POINT_mul(group, pub_key, priv_key, NULL, NULL, NULL)) {\n            EC_POINT_free(pub_key);\n            ECerr(EC_F_ECKEY_PRIV_DECODE, ERR_R_EC_LIB);\n            goto ecliberr;\n        }\n        if (EC_KEY_set_public_key(eckey, pub_key) == 0) {\n            EC_POINT_free(pub_key);\n            ECerr(EC_F_ECKEY_PRIV_DECODE, ERR_R_EC_LIB);\n            goto ecliberr;\n        }\n        EC_POINT_free(pub_key);\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}', '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_asn1_pkparameters2group(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        if (ret->priv_key == NULL)\n            ret->priv_key = BN_secure_new();\n        if (ret->priv_key == NULL) {\n            ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_MALLOC_FAILURE);\n            goto err;\n        }\n        ret->priv_key = BN_bin2bn(ASN1_STRING_data(priv_key->privateKey),\n                                  ASN1_STRING_length(priv_key->privateKey),\n                                  ret->priv_key);\n        if (ret->priv_key == NULL) {\n            ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_BN_LIB);\n            goto err;\n        }\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 (pub_oct_len <= 0) {\n            ECerr(EC_F_D2I_ECPRIVATEKEY, EC_R_BUFFER_TOO_SMALL);\n            goto err;\n        }\n        ret->conv_form = (point_conversion_form_t) (pub_oct[0] & ~0x01);\n        if (!EC_POINT_oct2point(ret->group, ret->pub_key,\n                                pub_oct, (size_t)(pub_oct_len), NULL)) {\n            ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);\n            goto err;\n        }\n    } else {\n        if (!EC_POINT_mul\n            (ret->group, ret->pub_key, ret->priv_key, NULL, NULL, NULL)) {\n            ECerr(EC_F_D2I_ECPRIVATEKEY, ERR_R_EC_LIB);\n            goto err;\n        }\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_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,\n                 const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)\n{\n    const EC_POINT *points[1];\n    const BIGNUM *scalars[1];\n    points[0] = point;\n    scalars[0] = p_scalar;\n    return EC_POINTs_mul(group, r, g_scalar,\n                         (point != NULL\n                          && p_scalar != NULL), points, scalars, ctx);\n}', 'int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n                  size_t num, const EC_POINT *points[],\n                  const BIGNUM *scalars[], BN_CTX *ctx)\n{\n    if (group->meth->mul == 0)\n        return ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);\n    return group->meth->mul(group, r, scalar, num, points, scalars, ctx);\n}', 'int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n                size_t num, const EC_POINT *points[], const BIGNUM *scalars[],\n                BN_CTX *ctx)\n{\n    BN_CTX *new_ctx = NULL;\n    const EC_POINT *generator = NULL;\n    EC_POINT *tmp = NULL;\n    size_t totalnum;\n    size_t blocksize = 0, numblocks = 0;\n    size_t pre_points_per_block = 0;\n    size_t i, j;\n    int k;\n    int r_is_inverted = 0;\n    int r_is_at_infinity = 1;\n    size_t *wsize = NULL;\n    signed char **wNAF = NULL;\n    size_t *wNAF_len = NULL;\n    size_t max_len = 0;\n    size_t num_val;\n    EC_POINT **val = NULL;\n    EC_POINT **v;\n    EC_POINT ***val_sub = NULL;\n    const EC_PRE_COMP *pre_comp = NULL;\n    int num_scalar = 0;\n    int ret = 0;\n    if (group->meth != r->meth) {\n        ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n        return 0;\n    }\n    if ((scalar == NULL) && (num == 0)) {\n        return EC_POINT_set_to_infinity(group, r);\n    }\n    for (i = 0; i < num; i++) {\n        if (group->meth != points[i]->meth) {\n            ECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n            return 0;\n        }\n    }\n    if (ctx == NULL) {\n        ctx = new_ctx = BN_CTX_new();\n        if (ctx == NULL)\n            goto err;\n    }\n    if (scalar != NULL) {\n        generator = EC_GROUP_get0_generator(group);\n        if (generator == NULL) {\n            ECerr(EC_F_EC_WNAF_MUL, EC_R_UNDEFINED_GENERATOR);\n            goto err;\n        }\n        pre_comp = group->pre_comp.ec;\n        if (pre_comp && pre_comp->numblocks\n            && (EC_POINT_cmp(group, generator, pre_comp->points[0], ctx) ==\n                0)) {\n            blocksize = pre_comp->blocksize;\n            numblocks = (BN_num_bits(scalar) / blocksize) + 1;\n            if (numblocks > pre_comp->numblocks)\n                numblocks = pre_comp->numblocks;\n            pre_points_per_block = (size_t)1 << (pre_comp->w - 1);\n            if (pre_comp->num != (pre_comp->numblocks * pre_points_per_block)) {\n                ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n                goto err;\n            }\n        } else {\n            pre_comp = NULL;\n            numblocks = 1;\n            num_scalar = 1;\n        }\n    }\n    totalnum = num + numblocks;\n    wsize = OPENSSL_malloc(totalnum * sizeof wsize[0]);\n    wNAF_len = OPENSSL_malloc(totalnum * sizeof wNAF_len[0]);\n    wNAF = OPENSSL_malloc((totalnum + 1) * sizeof wNAF[0]);\n    val_sub = OPENSSL_malloc(totalnum * sizeof val_sub[0]);\n    if (wNAF != NULL)\n        wNAF[0] = NULL;\n    if (wsize == NULL || wNAF_len == NULL || wNAF == NULL || val_sub == NULL) {\n        ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    num_val = 0;\n    for (i = 0; i < num + num_scalar; i++) {\n        size_t bits;\n        bits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar);\n        wsize[i] = EC_window_bits_for_scalar_size(bits);\n        num_val += (size_t)1 << (wsize[i] - 1);\n        wNAF[i + 1] = NULL;\n        wNAF[i] =\n            bn_compute_wNAF((i < num ? scalars[i] : scalar), wsize[i],\n                            &wNAF_len[i]);\n        if (wNAF[i] == NULL)\n            goto err;\n        if (wNAF_len[i] > max_len)\n            max_len = wNAF_len[i];\n    }\n    if (numblocks) {\n        if (pre_comp == NULL) {\n            if (num_scalar != 1) {\n                ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n                goto err;\n            }\n        } else {\n            signed char *tmp_wNAF = NULL;\n            size_t tmp_len = 0;\n            if (num_scalar != 0) {\n                ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n                goto err;\n            }\n            wsize[num] = pre_comp->w;\n            tmp_wNAF = bn_compute_wNAF(scalar, wsize[num], &tmp_len);\n            if (!tmp_wNAF)\n                goto err;\n            if (tmp_len <= max_len) {\n                numblocks = 1;\n                totalnum = num + 1;\n                wNAF[num] = tmp_wNAF;\n                wNAF[num + 1] = NULL;\n                wNAF_len[num] = tmp_len;\n                if (tmp_len > max_len)\n                    max_len = tmp_len;\n                val_sub[num] = pre_comp->points;\n            } else {\n                signed char *pp;\n                EC_POINT **tmp_points;\n                if (tmp_len < numblocks * blocksize) {\n                    numblocks = (tmp_len + blocksize - 1) / blocksize;\n                    if (numblocks > pre_comp->numblocks) {\n                        ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n                        goto err;\n                    }\n                    totalnum = num + numblocks;\n                }\n                pp = tmp_wNAF;\n                tmp_points = pre_comp->points;\n                for (i = num; i < totalnum; i++) {\n                    if (i < totalnum - 1) {\n                        wNAF_len[i] = blocksize;\n                        if (tmp_len < blocksize) {\n                            ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n                            goto err;\n                        }\n                        tmp_len -= blocksize;\n                    } else\n                        wNAF_len[i] = tmp_len;\n                    wNAF[i + 1] = NULL;\n                    wNAF[i] = OPENSSL_malloc(wNAF_len[i]);\n                    if (wNAF[i] == NULL) {\n                        ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n                        OPENSSL_free(tmp_wNAF);\n                        goto err;\n                    }\n                    memcpy(wNAF[i], pp, wNAF_len[i]);\n                    if (wNAF_len[i] > max_len)\n                        max_len = wNAF_len[i];\n                    if (*tmp_points == NULL) {\n                        ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n                        OPENSSL_free(tmp_wNAF);\n                        goto err;\n                    }\n                    val_sub[i] = tmp_points;\n                    tmp_points += pre_points_per_block;\n                    pp += blocksize;\n                }\n                OPENSSL_free(tmp_wNAF);\n            }\n        }\n    }\n    val = OPENSSL_malloc((num_val + 1) * sizeof val[0]);\n    if (val == NULL) {\n        ECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n        goto err;\n    }\n    val[num_val] = NULL;\n    v = val;\n    for (i = 0; i < num + num_scalar; i++) {\n        val_sub[i] = v;\n        for (j = 0; j < ((size_t)1 << (wsize[i] - 1)); j++) {\n            *v = EC_POINT_new(group);\n            if (*v == NULL)\n                goto err;\n            v++;\n        }\n    }\n    if (!(v == val + num_val)) {\n        ECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n        goto err;\n    }\n    if ((tmp = EC_POINT_new(group)) == NULL)\n        goto err;\n    for (i = 0; i < num + num_scalar; i++) {\n        if (i < num) {\n            if (!EC_POINT_copy(val_sub[i][0], points[i]))\n                goto err;\n        } else {\n            if (!EC_POINT_copy(val_sub[i][0], generator))\n                goto err;\n        }\n        if (wsize[i] > 1) {\n            if (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx))\n                goto err;\n            for (j = 1; j < ((size_t)1 << (wsize[i] - 1)); j++) {\n                if (!EC_POINT_add\n                    (group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx))\n                    goto err;\n            }\n        }\n    }\n    if (!EC_POINTs_make_affine(group, num_val, val, ctx))\n        goto err;\n    r_is_at_infinity = 1;\n    for (k = max_len - 1; k >= 0; k--) {\n        if (!r_is_at_infinity) {\n            if (!EC_POINT_dbl(group, r, r, ctx))\n                goto err;\n        }\n        for (i = 0; i < totalnum; i++) {\n            if (wNAF_len[i] > (size_t)k) {\n                int digit = wNAF[i][k];\n                int is_neg;\n                if (digit) {\n                    is_neg = digit < 0;\n                    if (is_neg)\n                        digit = -digit;\n                    if (is_neg != r_is_inverted) {\n                        if (!r_is_at_infinity) {\n                            if (!EC_POINT_invert(group, r, ctx))\n                                goto err;\n                        }\n                        r_is_inverted = !r_is_inverted;\n                    }\n                    if (r_is_at_infinity) {\n                        if (!EC_POINT_copy(r, val_sub[i][digit >> 1]))\n                            goto err;\n                        r_is_at_infinity = 0;\n                    } else {\n                        if (!EC_POINT_add\n                            (group, r, r, val_sub[i][digit >> 1], ctx))\n                            goto err;\n                    }\n                }\n            }\n        }\n    }\n    if (r_is_at_infinity) {\n        if (!EC_POINT_set_to_infinity(group, r))\n            goto err;\n    } else {\n        if (r_is_inverted)\n            if (!EC_POINT_invert(group, r, ctx))\n                goto err;\n    }\n    ret = 1;\n err:\n    BN_CTX_free(new_ctx);\n    EC_POINT_free(tmp);\n    OPENSSL_free(wsize);\n    OPENSSL_free(wNAF_len);\n    if (wNAF != NULL) {\n        signed char **w;\n        for (w = wNAF; *w != NULL; w++)\n            OPENSSL_free(*w);\n        OPENSSL_free(wNAF);\n    }\n    if (val != NULL) {\n        for (v = val; *v != NULL; v++)\n            EC_POINT_clear_free(*v);\n        OPENSSL_free(val);\n    }\n    OPENSSL_free(val_sub);\n    return ret;\n}']