crypto/ecdsa/ecdsatest.c:374: error: INTEGER_OVERFLOW_L2
  ([0, +oo] - 1):unsigned64 by call to `EC_KEY_check_key`.
Showing all 16 steps of the trace


crypto/ecdsa/ecdsatest.c:365:8: Call
363.   			goto builtin_err;
364.   		EC_GROUP_free(group);
365.   		if (!EC_KEY_generate_key(wrong_eckey))
              ^
366.   			{
367.   			BIO_printf(out, " failed\n");

crypto/ec/ec_key.c:233:1: Parameter `eckey->priv_key->top`
  231.   	}
  232.   
  233. > int EC_KEY_generate_key(EC_KEY *eckey)
  234.   	{	
  235.   	int	ok = 0;

crypto/ecdsa/ecdsatest.c:374:8: Call
372.   		(void)BIO_flush(out);
373.   		/* check key */
374.   		if (!EC_KEY_check_key(eckey))
              ^
375.   			{
376.   			BIO_printf(out, " failed\n");

crypto/ec/ec_key.c:295:1: Parameter `eckey->priv_key->top`
  293.   	}
  294.   
  295. > int EC_KEY_check_key(const EC_KEY *eckey)
  296.   	{
  297.   	int	ok   = 0;

crypto/ec/ec_key.c:341:7: Call
  339.   	if (eckey->priv_key)
  340.   		{
  341.   		if (BN_cmp(eckey->priv_key, order) >= 0)
               ^
  342.   			{
  343.   			ECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_WRONG_ORDER);

crypto/bn/bn_lib.c:678:1: Parameter `a->top`
    676.   	}
    677.   
    678. > int BN_cmp(const BIGNUM *a, const BIGNUM *b)
    679.   	{
    680.   	int i;

crypto/ec/ec_key.c:346:8: Call
  344.   			goto err;
  345.   			}
  346.   		if (!EC_POINT_mul(eckey->group, point, eckey->priv_key,
                ^
  347.   			NULL, NULL, ctx))
  348.   			{

crypto/ec/ec_lib.c:1128:1: Parameter `g_scalar->top`
    1126.   	}
    1127.   
    1128. > int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,
    1129.   	const EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)
    1130.   	{

crypto/ec/ec_lib.c:1139:9: Call
    1137.   	scalars[0] = p_scalar;
    1138.   
    1139.   	return EC_POINTs_mul(group, r, g_scalar, (point != NULL && p_scalar != NULL), points, scalars, ctx);
                    ^
    1140.   	}
    1141.   

crypto/ec/ec_lib.c:1118:1: Parameter `scalar->top`
      1116.    */
      1117.   
      1118. > int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
      1119.   	size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)
      1120.   	{

crypto/ec/ec_lib.c:1123:10: Call
      1121.   	if (group->meth->mul == 0)
      1122.   		/* use default */
      1123.   		return ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);
                       ^
      1124.   
      1125.   	return group->meth->mul(group, r, scalar, num, points, scalars, ctx);

crypto/ec/ec_mult.c:344:1: Parameter `scalar->top`
        342.    * in the addition if scalar != NULL
        343.    */
        344. > int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,
        345.   	size_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)
        346.   	{

crypto/ec/ec_mult.c:416:17: Call
        414.   			/* determine maximum number of blocks that wNAF splitting may yield
        415.   			 * (NB: maximum wNAF length is bit length plus one) */
        416.   			numblocks = (BN_num_bits(scalar) / blocksize) + 1;
                               ^
        417.   
        418.   			/* we cannot use more blocks than we have precomputation for */

crypto/bn/bn_lib.c:248:1: <LHS trace>
246.   	}
247.   
248. > int BN_num_bits(const BIGNUM *a)
249.   	{
250.   	int i = a->top - 1;

crypto/bn/bn_lib.c:248:1: Parameter `a->top`
          246.   	}
          247.   
          248. > int BN_num_bits(const BIGNUM *a)
          249.   	{
          250.   	int i = a->top - 1;

crypto/bn/bn_lib.c:250:2: Binary operation: ([0, +oo] - 1):unsigned64 by call to `EC_KEY_check_key` 
          248.   int BN_num_bits(const BIGNUM *a)
          249.   	{
          250.   	int i = a->top - 1;
                  ^
          251.   	bn_check_top(a);
          252.   

int BN_num_bits(const BIGNUM *a)
	{
	int i = a->top - 1;
	bn_check_top(a);
	if (BN_is_zero(a)) return 0;
	return ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));
	}
['int test_builtin(BIO *out)\n\t{\n\tEC_builtin_curve *curves = NULL;\n\tsize_t\t\tcrv_len = 0, n = 0;\n\tEC_KEY\t\t*eckey = NULL, *wrong_eckey = NULL;\n\tEC_GROUP\t*group;\n\tunsigned char\tdigest[20], wrong_digest[20];\n\tunsigned char\t*signature = NULL;\n\tunsigned int\tsig_len;\n\tint\t\tnid, ret =  0;\n\tif (!RAND_pseudo_bytes(digest, 20) ||\n\t    !RAND_pseudo_bytes(wrong_digest, 20))\n\t\t{\n\t\tBIO_printf(out, "ERROR: unable to get random data\\n");\n\t\tgoto builtin_err;\n\t\t}\n\tBIO_printf(out, "\\ntesting ECDSA_sign() and ECDSA_verify() "\n\t\t"with some internal curves:\\n");\n\tcrv_len = EC_get_builtin_curves(NULL, 0);\n\tcurves = OPENSSL_malloc(sizeof(EC_builtin_curve) * crv_len);\n\tif (curves == NULL)\n\t\t{\n\t\tBIO_printf(out, "malloc error\\n");\n\t\tgoto builtin_err;\n\t\t}\n\tif (!EC_get_builtin_curves(curves, crv_len))\n\t\t{\n\t\tBIO_printf(out, "unable to get internal curves\\n");\n\t\tgoto builtin_err;\n\t\t}\n\tfor (n = 0; n < crv_len; n++)\n\t\t{\n\t\tunsigned char dirt, offset;\n\t\tnid = curves[n].nid;\n\t\tif (nid == NID_ipsec4)\n\t\t\tcontinue;\n\t\tif ((eckey = EC_KEY_new()) == NULL)\n\t\t\tgoto builtin_err;\n\t\tgroup = EC_GROUP_new_by_curve_name(nid);\n\t\tif (group == NULL)\n\t\t\tgoto builtin_err;\n\t\tif (EC_KEY_set_group(eckey, group) == 0)\n\t\t\tgoto builtin_err;\n\t\tEC_GROUP_free(group);\n\t\tif (EC_GROUP_get_degree(EC_KEY_get0_group(eckey)) < 160)\n\t\t\t{\n\t\t\tEC_KEY_free(eckey);\n\t\t\teckey = NULL;\n\t\t\tcontinue;\n\t\t\t}\n\t\tBIO_printf(out, "%s: ", OBJ_nid2sn(nid));\n\t\tif (!EC_KEY_generate_key(eckey))\n\t\t\t{\n\t\t\tBIO_printf(out, " failed\\n");\n\t\t\tgoto builtin_err;\n\t\t\t}\n\t\tif ((wrong_eckey = EC_KEY_new()) == NULL)\n\t\t\tgoto builtin_err;\n\t\tgroup = EC_GROUP_new_by_curve_name(nid);\n\t\tif (group == NULL)\n\t\t\tgoto builtin_err;\n\t\tif (EC_KEY_set_group(wrong_eckey, group) == 0)\n\t\t\tgoto builtin_err;\n\t\tEC_GROUP_free(group);\n\t\tif (!EC_KEY_generate_key(wrong_eckey))\n\t\t\t{\n\t\t\tBIO_printf(out, " failed\\n");\n\t\t\tgoto builtin_err;\n\t\t\t}\n\t\tBIO_printf(out, ".");\n\t\t(void)BIO_flush(out);\n\t\tif (!EC_KEY_check_key(eckey))\n\t\t\t{\n\t\t\tBIO_printf(out, " failed\\n");\n\t\t\tgoto builtin_err;\n\t\t\t}\n\t\tBIO_printf(out, ".");\n\t\t(void)BIO_flush(out);\n\t\tsig_len = ECDSA_size(eckey);\n\t\tif ((signature = OPENSSL_malloc(sig_len)) == NULL)\n\t\t\tgoto builtin_err;\n                if (!ECDSA_sign(0, digest, 20, signature, &sig_len, eckey))\n\t\t\t{\n\t\t\tBIO_printf(out, " failed\\n");\n\t\t\tgoto builtin_err;\n\t\t\t}\n\t\tBIO_printf(out, ".");\n\t\t(void)BIO_flush(out);\n\t\tif (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) != 1)\n\t\t\t{\n\t\t\tBIO_printf(out, " failed\\n");\n\t\t\tgoto builtin_err;\n\t\t\t}\n\t\tBIO_printf(out, ".");\n\t\t(void)BIO_flush(out);\n\t\tif (ECDSA_verify(0, digest, 20, signature, sig_len,\n\t\t\twrong_eckey) == 1)\n\t\t\t{\n\t\t\tBIO_printf(out, " failed\\n");\n\t\t\tgoto builtin_err;\n\t\t\t}\n\t\tBIO_printf(out, ".");\n\t\t(void)BIO_flush(out);\n\t\tif (ECDSA_verify(0, wrong_digest, 20, signature, sig_len,\n\t\t\teckey) == 1)\n\t\t\t{\n\t\t\tBIO_printf(out, " failed\\n");\n\t\t\tgoto builtin_err;\n\t\t\t}\n\t\tBIO_printf(out, ".");\n\t\t(void)BIO_flush(out);\n\t\toffset = signature[10] % sig_len;\n\t\tdirt   = signature[11];\n\t\tsignature[offset] ^= dirt ? dirt : 1;\n\t\tif (ECDSA_verify(0, digest, 20, signature, sig_len, eckey) == 1)\n\t\t\t{\n\t\t\tBIO_printf(out, " failed\\n");\n\t\t\tgoto builtin_err;\n\t\t\t}\n\t\tBIO_printf(out, ".");\n\t\t(void)BIO_flush(out);\n\t\tBIO_printf(out, " ok\\n");\n\t\tOPENSSL_free(signature);\n\t\tsignature = NULL;\n\t\tEC_KEY_free(eckey);\n\t\teckey = NULL;\n\t\tEC_KEY_free(wrong_eckey);\n\t\twrong_eckey = NULL;\n\t\t}\n\tret = 1;\nbuiltin_err:\n\tif (eckey)\n\t\tEC_KEY_free(eckey);\n\tif (wrong_eckey)\n\t\tEC_KEY_free(wrong_eckey);\n\tif (signature)\n\t\tOPENSSL_free(signature);\n\tif (curves)\n\t\tOPENSSL_free(curves);\n\treturn ret;\n\t}', 'int EC_KEY_generate_key(EC_KEY *eckey)\n\t{\n\tint\tok = 0;\n\tBN_CTX\t*ctx = NULL;\n\tBIGNUM\t*priv_key = NULL, *order = NULL;\n\tEC_POINT *pub_key = NULL;\n\tif (!eckey || !eckey->group)\n\t\t{\n\t\tECerr(EC_F_EC_KEY_GENERATE_KEY, ERR_R_PASSED_NULL_PARAMETER);\n\t\treturn 0;\n\t\t}\n\tif ((order = BN_new()) == NULL) goto err;\n\tif ((ctx = BN_CTX_new()) == NULL) goto err;\n\tif (eckey->priv_key == NULL)\n\t\t{\n\t\tpriv_key = BN_new();\n\t\tif (priv_key == NULL)\n\t\t\tgoto err;\n\t\t}\n\telse\n\t\tpriv_key = eckey->priv_key;\n\tif (!EC_GROUP_get_order(eckey->group, order, ctx))\n\t\tgoto err;\n\tdo\n\t\tif (!BN_rand_range(priv_key, order))\n\t\t\tgoto err;\n\twhile (BN_is_zero(priv_key));\n\tif (eckey->pub_key == NULL)\n\t\t{\n\t\tpub_key = EC_POINT_new(eckey->group);\n\t\tif (pub_key == NULL)\n\t\t\tgoto err;\n\t\t}\n\telse\n\t\tpub_key = eckey->pub_key;\n\tif (!EC_POINT_mul(eckey->group, pub_key, priv_key, NULL, NULL, ctx))\n\t\tgoto err;\n\teckey->priv_key = priv_key;\n\teckey->pub_key  = pub_key;\n\tok=1;\nerr:\n\tif (order)\n\t\tBN_free(order);\n\tif (pub_key  != NULL && eckey->pub_key  == NULL)\n\t\tEC_POINT_free(pub_key);\n\tif (priv_key != NULL && eckey->priv_key == NULL)\n\t\tBN_free(priv_key);\n\tif (ctx != NULL)\n\t\tBN_CTX_free(ctx);\n\treturn(ok);\n\t}', 'int EC_KEY_check_key(const EC_KEY *eckey)\n\t{\n\tint\tok   = 0;\n\tBN_CTX\t*ctx = NULL;\n\tconst BIGNUM\t*order  = NULL;\n\tEC_POINT *point = NULL;\n\tif (!eckey || !eckey->group || !eckey->pub_key)\n\t\t{\n\t\tECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_PASSED_NULL_PARAMETER);\n\t\treturn 0;\n\t\t}\n\tif ((ctx = BN_CTX_new()) == NULL)\n\t\tgoto err;\n\tif ((point = EC_POINT_new(eckey->group)) == NULL)\n\t\tgoto err;\n\tif (!EC_POINT_is_on_curve(eckey->group, eckey->pub_key, ctx))\n\t\t{\n\t\tECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_POINT_IS_NOT_ON_CURVE);\n\t\tgoto err;\n\t\t}\n\torder = &eckey->group->order;\n\tif (BN_is_zero(order))\n\t\t{\n\t\tECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_INVALID_GROUP_ORDER);\n\t\tgoto err;\n\t\t}\n\tif (!EC_POINT_mul(eckey->group, point, NULL, eckey->pub_key, order, ctx))\n\t\t{\n\t\tECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_EC_LIB);\n\t\tgoto err;\n\t\t}\n\tif (!EC_POINT_is_at_infinity(eckey->group, point))\n\t\t{\n\t\tECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_WRONG_ORDER);\n\t\tgoto err;\n\t\t}\n\tif (eckey->priv_key)\n\t\t{\n\t\tif (BN_cmp(eckey->priv_key, order) >= 0)\n\t\t\t{\n\t\t\tECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_WRONG_ORDER);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (!EC_POINT_mul(eckey->group, point, eckey->priv_key,\n\t\t\tNULL, NULL, ctx))\n\t\t\t{\n\t\t\tECerr(EC_F_EC_KEY_CHECK_KEY, ERR_R_EC_LIB);\n\t\t\tgoto err;\n\t\t\t}\n\t\tif (EC_POINT_cmp(eckey->group, point, eckey->pub_key,\n\t\t\tctx) != 0)\n\t\t\t{\n\t\t\tECerr(EC_F_EC_KEY_CHECK_KEY, EC_R_INVALID_PRIVATE_KEY);\n\t\t\tgoto err;\n\t\t\t}\n\t\t}\n\tok = 1;\nerr:\n\tif (ctx   != NULL)\n\t\tBN_CTX_free(ctx);\n\tif (point != NULL)\n\t\tEC_POINT_free(point);\n\treturn(ok);\n\t}', 'int BN_cmp(const BIGNUM *a, const BIGNUM *b)\n\t{\n\tint i;\n\tint gt,lt;\n\tBN_ULONG t1,t2;\n\tif ((a == NULL) || (b == NULL))\n\t\t{\n\t\tif (a != NULL)\n\t\t\treturn(-1);\n\t\telse if (b != NULL)\n\t\t\treturn(1);\n\t\telse\n\t\t\treturn(0);\n\t\t}\n\tbn_check_top(a);\n\tbn_check_top(b);\n\tif (a->neg != b->neg)\n\t\t{\n\t\tif (a->neg)\n\t\t\treturn(-1);\n\t\telse\treturn(1);\n\t\t}\n\tif (a->neg == 0)\n\t\t{ gt=1; lt= -1; }\n\telse\t{ gt= -1; lt=1; }\n\tif (a->top > b->top) return(gt);\n\tif (a->top < b->top) return(lt);\n\tfor (i=a->top-1; i>=0; i--)\n\t\t{\n\t\tt1=a->d[i];\n\t\tt2=b->d[i];\n\t\tif (t1 > t2) return(gt);\n\t\tif (t1 < t2) return(lt);\n\t\t}\n\treturn(0);\n\t}', 'int EC_POINT_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *g_scalar,\n\tconst EC_POINT *point, const BIGNUM *p_scalar, BN_CTX *ctx)\n\t{\n\tconst EC_POINT *points[1];\n\tconst BIGNUM *scalars[1];\n\tpoints[0] = point;\n\tscalars[0] = p_scalar;\n\treturn EC_POINTs_mul(group, r, g_scalar, (point != NULL && p_scalar != NULL), points, scalars, ctx);\n\t}', 'int EC_POINTs_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n\tsize_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)\n\t{\n\tif (group->meth->mul == 0)\n\t\treturn ec_wNAF_mul(group, r, scalar, num, points, scalars, ctx);\n\treturn group->meth->mul(group, r, scalar, num, points, scalars, ctx);\n\t}', 'int ec_wNAF_mul(const EC_GROUP *group, EC_POINT *r, const BIGNUM *scalar,\n\tsize_t num, const EC_POINT *points[], const BIGNUM *scalars[], BN_CTX *ctx)\n\t{\n\tBN_CTX *new_ctx = NULL;\n\tconst EC_POINT *generator = NULL;\n\tEC_POINT *tmp = NULL;\n\tsize_t totalnum;\n\tsize_t blocksize = 0, numblocks = 0;\n\tsize_t pre_points_per_block = 0;\n\tsize_t i, j;\n\tint k;\n\tint r_is_inverted = 0;\n\tint r_is_at_infinity = 1;\n\tsize_t *wsize = NULL;\n\tsigned char **wNAF = NULL;\n\tsize_t *wNAF_len = NULL;\n\tsize_t max_len = 0;\n\tsize_t num_val;\n\tEC_POINT **val = NULL;\n\tEC_POINT **v;\n\tEC_POINT ***val_sub = NULL;\n\tconst EC_PRE_COMP *pre_comp = NULL;\n\tint num_scalar = 0;\n\tint ret = 0;\n\tif (group->meth != r->meth)\n\t\t{\n\t\tECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n\t\treturn 0;\n\t\t}\n\tif ((scalar == NULL) && (num == 0))\n\t\t{\n\t\treturn EC_POINT_set_to_infinity(group, r);\n\t\t}\n\tfor (i = 0; i < num; i++)\n\t\t{\n\t\tif (group->meth != points[i]->meth)\n\t\t\t{\n\t\t\tECerr(EC_F_EC_WNAF_MUL, EC_R_INCOMPATIBLE_OBJECTS);\n\t\t\treturn 0;\n\t\t\t}\n\t\t}\n\tif (ctx == NULL)\n\t\t{\n\t\tctx = new_ctx = BN_CTX_new();\n\t\tif (ctx == NULL)\n\t\t\tgoto err;\n\t\t}\n\tif (scalar != NULL)\n\t\t{\n\t\tgenerator = EC_GROUP_get0_generator(group);\n\t\tif (generator == NULL)\n\t\t\t{\n\t\t\tECerr(EC_F_EC_WNAF_MUL, EC_R_UNDEFINED_GENERATOR);\n\t\t\tgoto err;\n\t\t\t}\n\t\tpre_comp = EC_EX_DATA_get_data(group->extra_data, ec_pre_comp_dup, ec_pre_comp_free, ec_pre_comp_clear_free);\n\t\tif (pre_comp && pre_comp->numblocks && (EC_POINT_cmp(group, generator, pre_comp->points[0], ctx) == 0))\n\t\t\t{\n\t\t\tblocksize = pre_comp->blocksize;\n\t\t\tnumblocks = (BN_num_bits(scalar) / blocksize) + 1;\n\t\t\tif (numblocks > pre_comp->numblocks)\n\t\t\t\tnumblocks = pre_comp->numblocks;\n\t\t\tpre_points_per_block = 1u << (pre_comp->w - 1);\n\t\t\tif (pre_comp->num != (pre_comp->numblocks * pre_points_per_block))\n\t\t\t\t{\n\t\t\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tpre_comp = NULL;\n\t\t\tnumblocks = 1;\n\t\t\tnum_scalar = 1;\n\t\t\t}\n\t\t}\n\ttotalnum = num + numblocks;\n\twsize    = OPENSSL_malloc(totalnum * sizeof wsize[0]);\n\twNAF_len = OPENSSL_malloc(totalnum * sizeof wNAF_len[0]);\n\twNAF     = OPENSSL_malloc((totalnum + 1) * sizeof wNAF[0]);\n\tval_sub  = OPENSSL_malloc(totalnum * sizeof val_sub[0]);\n\tif (!wsize || !wNAF_len || !wNAF || !val_sub)\n\t\t{\n\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\twNAF[0] = NULL;\n\tnum_val = 0;\n\tfor (i = 0; i < num + num_scalar; i++)\n\t\t{\n\t\tsize_t bits;\n\t\tbits = i < num ? BN_num_bits(scalars[i]) : BN_num_bits(scalar);\n\t\twsize[i] = EC_window_bits_for_scalar_size(bits);\n\t\tnum_val += 1u << (wsize[i] - 1);\n\t\twNAF[i + 1] = NULL;\n\t\twNAF[i] = compute_wNAF((i < num ? scalars[i] : scalar), wsize[i], &wNAF_len[i]);\n\t\tif (wNAF[i] == NULL)\n\t\t\tgoto err;\n\t\tif (wNAF_len[i] > max_len)\n\t\t\tmax_len = wNAF_len[i];\n\t\t}\n\tif (numblocks)\n\t\t{\n\t\tif (pre_comp == NULL)\n\t\t\t{\n\t\t\tif (num_scalar != 1)\n\t\t\t\t{\n\t\t\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tsigned char *tmp_wNAF = NULL;\n\t\t\tsize_t tmp_len = 0;\n\t\t\tif (num_scalar != 0)\n\t\t\t\t{\n\t\t\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n\t\t\t\tgoto err;\n\t\t\t\t}\n\t\t\twsize[num] = pre_comp->w;\n\t\t\ttmp_wNAF = compute_wNAF(scalar, wsize[num], &tmp_len);\n\t\t\tif (!tmp_wNAF)\n\t\t\t\tgoto err;\n\t\t\tif (tmp_len <= max_len)\n\t\t\t\t{\n\t\t\t\tnumblocks = 1;\n\t\t\t\ttotalnum = num + 1;\n\t\t\t\twNAF[num] = tmp_wNAF;\n\t\t\t\twNAF[num + 1] = NULL;\n\t\t\t\twNAF_len[num] = tmp_len;\n\t\t\t\tif (tmp_len > max_len)\n\t\t\t\t\tmax_len = tmp_len;\n\t\t\t\tval_sub[num] = pre_comp->points;\n\t\t\t\t}\n\t\t\telse\n\t\t\t\t{\n\t\t\t\tsigned char *pp;\n\t\t\t\tEC_POINT **tmp_points;\n\t\t\t\tif (tmp_len < numblocks * blocksize)\n\t\t\t\t\t{\n\t\t\t\t\tnumblocks = (tmp_len + blocksize - 1) / blocksize;\n\t\t\t\t\tif (numblocks > pre_comp->numblocks)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n\t\t\t\t\t\tgoto err;\n\t\t\t\t\t\t}\n\t\t\t\t\ttotalnum = num + numblocks;\n\t\t\t\t\t}\n\t\t\t\tpp = tmp_wNAF;\n\t\t\t\ttmp_points = pre_comp->points;\n\t\t\t\tfor (i = num; i < totalnum; i++)\n\t\t\t\t\t{\n\t\t\t\t\tif (i < totalnum - 1)\n\t\t\t\t\t\t{\n\t\t\t\t\t\twNAF_len[i] = blocksize;\n\t\t\t\t\t\tif (tmp_len < blocksize)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n\t\t\t\t\t\t\tgoto err;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\ttmp_len -= blocksize;\n\t\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\twNAF_len[i] = tmp_len;\n\t\t\t\t\twNAF[i + 1] = NULL;\n\t\t\t\t\twNAF[i] = OPENSSL_malloc(wNAF_len[i]);\n\t\t\t\t\tif (wNAF[i] == NULL)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n\t\t\t\t\t\tOPENSSL_free(tmp_wNAF);\n\t\t\t\t\t\tgoto err;\n\t\t\t\t\t\t}\n\t\t\t\t\tmemcpy(wNAF[i], pp, wNAF_len[i]);\n\t\t\t\t\tif (wNAF_len[i] > max_len)\n\t\t\t\t\t\tmax_len = wNAF_len[i];\n\t\t\t\t\tif (*tmp_points == NULL)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n\t\t\t\t\t\tOPENSSL_free(tmp_wNAF);\n\t\t\t\t\t\tgoto err;\n\t\t\t\t\t\t}\n\t\t\t\t\tval_sub[i] = tmp_points;\n\t\t\t\t\ttmp_points += pre_points_per_block;\n\t\t\t\t\tpp += blocksize;\n\t\t\t\t\t}\n\t\t\t\tOPENSSL_free(tmp_wNAF);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tval = OPENSSL_malloc((num_val + 1) * sizeof val[0]);\n\tif (val == NULL)\n\t\t{\n\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_MALLOC_FAILURE);\n\t\tgoto err;\n\t\t}\n\tval[num_val] = NULL;\n\tv = val;\n\tfor (i = 0; i < num + num_scalar; i++)\n\t\t{\n\t\tval_sub[i] = v;\n\t\tfor (j = 0; j < (1u << (wsize[i] - 1)); j++)\n\t\t\t{\n\t\t\t*v = EC_POINT_new(group);\n\t\t\tif (*v == NULL) goto err;\n\t\t\tv++;\n\t\t\t}\n\t\t}\n\tif (!(v == val + num_val))\n\t\t{\n\t\tECerr(EC_F_EC_WNAF_MUL, ERR_R_INTERNAL_ERROR);\n\t\tgoto err;\n\t\t}\n\tif (!(tmp = EC_POINT_new(group)))\n\t\tgoto err;\n\tfor (i = 0; i < num + num_scalar; i++)\n\t\t{\n\t\tif (i < num)\n\t\t\t{\n\t\t\tif (!EC_POINT_copy(val_sub[i][0], points[i])) goto err;\n\t\t\t}\n\t\telse\n\t\t\t{\n\t\t\tif (!EC_POINT_copy(val_sub[i][0], generator)) goto err;\n\t\t\t}\n\t\tif (wsize[i] > 1)\n\t\t\t{\n\t\t\tif (!EC_POINT_dbl(group, tmp, val_sub[i][0], ctx)) goto err;\n\t\t\tfor (j = 1; j < (1u << (wsize[i] - 1)); j++)\n\t\t\t\t{\n\t\t\t\tif (!EC_POINT_add(group, val_sub[i][j], val_sub[i][j - 1], tmp, ctx)) goto err;\n\t\t\t\t}\n\t\t\t}\n\t\t}\n#if 1\n\tif (!EC_POINTs_make_affine(group, num_val, val, ctx))\n\t\tgoto err;\n#endif\n\tr_is_at_infinity = 1;\n\tfor (k = max_len - 1; k >= 0; k--)\n\t\t{\n\t\tif (!r_is_at_infinity)\n\t\t\t{\n\t\t\tif (!EC_POINT_dbl(group, r, r, ctx)) goto err;\n\t\t\t}\n\t\tfor (i = 0; i < totalnum; i++)\n\t\t\t{\n\t\t\tif (wNAF_len[i] > (size_t)k)\n\t\t\t\t{\n\t\t\t\tint digit = wNAF[i][k];\n\t\t\t\tint is_neg;\n\t\t\t\tif (digit)\n\t\t\t\t\t{\n\t\t\t\t\tis_neg = digit < 0;\n\t\t\t\t\tif (is_neg)\n\t\t\t\t\t\tdigit = -digit;\n\t\t\t\t\tif (is_neg != r_is_inverted)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!r_is_at_infinity)\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\tif (!EC_POINT_invert(group, r, ctx)) goto err;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\tr_is_inverted = !r_is_inverted;\n\t\t\t\t\t\t}\n\t\t\t\t\tif (r_is_at_infinity)\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!EC_POINT_copy(r, val_sub[i][digit >> 1])) goto err;\n\t\t\t\t\t\tr_is_at_infinity = 0;\n\t\t\t\t\t\t}\n\t\t\t\t\telse\n\t\t\t\t\t\t{\n\t\t\t\t\t\tif (!EC_POINT_add(group, r, r, val_sub[i][digit >> 1], ctx)) goto err;\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\tif (r_is_at_infinity)\n\t\t{\n\t\tif (!EC_POINT_set_to_infinity(group, r)) goto err;\n\t\t}\n\telse\n\t\t{\n\t\tif (r_is_inverted)\n\t\t\tif (!EC_POINT_invert(group, r, ctx)) goto err;\n\t\t}\n\tret = 1;\n err:\n\tif (new_ctx != NULL)\n\t\tBN_CTX_free(new_ctx);\n\tif (tmp != NULL)\n\t\tEC_POINT_free(tmp);\n\tif (wsize != NULL)\n\t\tOPENSSL_free(wsize);\n\tif (wNAF_len != NULL)\n\t\tOPENSSL_free(wNAF_len);\n\tif (wNAF != NULL)\n\t\t{\n\t\tsigned char **w;\n\t\tfor (w = wNAF; *w != NULL; w++)\n\t\t\tOPENSSL_free(*w);\n\t\tOPENSSL_free(wNAF);\n\t\t}\n\tif (val != NULL)\n\t\t{\n\t\tfor (v = val; *v != NULL; v++)\n\t\t\tEC_POINT_clear_free(*v);\n\t\tOPENSSL_free(val);\n\t\t}\n\tif (val_sub != NULL)\n\t\t{\n\t\tOPENSSL_free(val_sub);\n\t\t}\n\treturn ret;\n\t}', 'int BN_num_bits(const BIGNUM *a)\n\t{\n\tint i = a->top - 1;\n\tbn_check_top(a);\n\tif (BN_is_zero(a)) return 0;\n\treturn ((i*BN_BITS2) + BN_num_bits_word(a->d[i]));\n\t}']