BN_init(&k);
static int ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,		BIGNUM **rp){	BN_CTX   *ctx = NULL;	BIGNUM	 k,*kinv=NULL,*r=NULL,*order=NULL,*X=NULL;	EC_POINT *tmp_point=NULL;	int 	 ret = 0;	if (!eckey  || !eckey->group || !eckey->pub_key || !eckey->priv_key)	{		ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, ERR_R_PASSED_NULL_PARAMETER);		return 0;	}	if (ctx_in == NULL) 	{		if ((ctx=BN_CTX_new()) == NULL)		{		ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, ERR_R_MALLOC_FAILURE);		goto err;		}	}	else		ctx=ctx_in;	if ((r = BN_new()) == NULL)	{		ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);		goto err;		}	if ((order = BN_new()) == NULL)	{		ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);		goto err;		}	if ((X = BN_new()) == NULL)	{		ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);		goto err;		}	if ((tmp_point = EC_POINT_new(eckey->group)) == NULL)	{		ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);		goto err;	}	if (!EC_GROUP_get_order(eckey->group,order,ctx))	{		ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);		goto err;	}		do	{		/* get random k */			BN_init(&k);		do			if (!BN_rand_range(&k,order))			{				ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP,				 ECDSA_R_RANDOM_NUMBER_GENERATION_FAILED);					goto err;			}		while (BN_is_zero(&k));		/* compute r the x-coordinate of generator * k */		if (!EC_POINT_mul(eckey->group, tmp_point, &k, NULL, NULL, ctx))		{			ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, ERR_R_EC_LIB);			goto err;		}		if (EC_METHOD_get_field_type(EC_GROUP_method_of(eckey->group))			== NID_X9_62_prime_field)		{			if (!EC_POINT_get_affine_coordinates_GFp(eckey->group,				tmp_point, X, NULL, ctx))			{				ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP,					ERR_R_EC_LIB);				goto err;			}		}		else /* NID_X9_62_characteristic_two_field */		{			if (!EC_POINT_get_affine_coordinates_GF2m(eckey->group,				tmp_point, X, NULL, ctx))			{				ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP,					ERR_R_EC_LIB);				goto err;			}		}		if (!BN_nnmod(r,X,order,ctx))		{			ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);			goto err;		}	}	while (BN_is_zero(r));	/* compute the inverse of k */	if ((kinv = BN_mod_inverse(NULL,&k,order,ctx)) == NULL)	{		ECDSAerr(ECDSA_F_ECDSA_SIGN_SETUP, ERR_R_BN_LIB);		goto err;		}	if (*rp == NULL)		BN_clear_free(*rp);	*rp = r;	if (*kinvp == NULL) 		BN_clear_free(*kinvp);	*kinvp = kinv;	kinv = NULL;	ret = 1;err:	if (!ret)	{		if (kinv != NULL) BN_clear_free(kinv);		if (r != NULL) BN_clear_free(r);	}	if (ctx_in == NULL) 		BN_CTX_free(ctx);	if (kinv != NULL)		BN_clear_free(kinv);	if (order != NULL)		BN_clear_free(order);	if (tmp_point != NULL) 		EC_POINT_free(tmp_point);	if (X)	BN_clear_free(X);	BN_clear_free(&k);	return(ret);}