len = EC_POINT_point2oct(pkey->pkey.ecdsa->group, point, POINT_CONVERSION_COMPRESSED,
len = EC_POINT_point2oct(pkey->pkey.ecdsa->group, point, ECDSA_get_conversion_form(pkey->pkey.ecdsa),
static int ecdsa_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey){	ASN1_STRING 	  *params=NULL;	ASN1_INTEGER      *prkey=NULL;	ASN1_TYPE         *ttmp=NULL;	STACK_OF(ASN1_TYPE) *necdsa=NULL;	unsigned char 	  *p=NULL, *q=NULL;	int len=0;	EC_POINT	  *point=NULL;	if (pkey->pkey.ecdsa == NULL || pkey->pkey.ecdsa->group == NULL)	{		EVPerr(EVP_F_ECDSA_PKEY2PKCS8, EVP_R_MISSING_PARAMETERS);		return 0;	}	p8->pkeyalg->algorithm = OBJ_nid2obj(NID_ecdsa_with_SHA1);	len = i2d_ECDSAParameters(pkey->pkey.ecdsa, NULL);	if ((p = OPENSSL_malloc(len)) == NULL)	{		EVPerr(EVP_F_ECDSA_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);		return 0;	}	q = p;	if (!i2d_ECDSAParameters(pkey->pkey.ecdsa, &q))	{		EVPerr(EVP_F_ECDSA_PKEY2PKCS8, ERR_R_ECDSA_LIB);		OPENSSL_free(p);		return 0;	}	if ((params = ASN1_STRING_new()) == NULL)	{		EVPerr(EVP_F_ECDSA_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);		OPENSSL_free(p);		return 0;			}	if (!ASN1_STRING_set(params, p, len))	{		EVPerr(EVP_F_ECDSA_PKEY2PKCS8, ERR_R_ASN1_LIB);		OPENSSL_free(p);		return 0;	}	OPENSSL_free(p);	if ((prkey = BN_to_ASN1_INTEGER(pkey->pkey.ecdsa->priv_key, NULL)) == NULL)	{		EVPerr(EVP_F_ECDSA_PKEY2PKCS8, ERR_R_ASN1_LIB);		return 0;	}	switch(p8->broken) {		case PKCS8_OK:		case PKCS8_NO_OCTET:		if (!ASN1_pack_string((char *)prkey, i2d_ASN1_INTEGER,					 &p8->pkey->value.octet_string)) 		{			EVPerr(EVP_F_ECDSA_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);			M_ASN1_INTEGER_free(prkey);			return 0;		}		ASN1_INTEGER_free(prkey);		p8->pkeyalg->parameter->value.sequence = params;		p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;		break;		case PKCS8_NS_DB:		p8->pkeyalg->parameter->value.sequence = params;		p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;		necdsa = sk_ASN1_TYPE_new_null();		if (necdsa == NULL || (ttmp = ASN1_TYPE_new()) == NULL)		{			EVPerr(EVP_F_ECDSA_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);			sk_ASN1_TYPE_pop_free(necdsa, ASN1_TYPE_free);			return 0;		}		if ((point = EC_GROUP_get0_generator(pkey->pkey.ecdsa->group)) == NULL)		{			EVPerr(EVP_F_ECDSA_PKEY2PKCS8, ERR_R_EC_LIB);			return 0;		}		len = EC_POINT_point2oct(pkey->pkey.ecdsa->group, point, POINT_CONVERSION_COMPRESSED,				         NULL, 0, NULL);		p = OPENSSL_malloc(len);		if (!len || !p || !EC_POINT_point2oct(pkey->pkey.ecdsa->group, point,			POINT_CONVERSION_COMPRESSED, p, len, NULL))		{			EVPerr(EVP_F_ECDSA_PKEY2PKCS8, ERR_R_EC_LIB);			OPENSSL_free(p);			return 0;		}		if ((ttmp->value.octet_string = ASN1_OCTET_STRING_new()) == NULL)		{			EVPerr(EVP_F_ECDSA_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);			return 0;		}		if (!ASN1_OCTET_STRING_set(ttmp->value.octet_string, p, len))		{			EVPerr(EVP_F_ECDSA_PKEY2PKCS8, EVP_R_ASN1_LIB);			return 0;		}		OPENSSL_free(p);				ttmp->type = V_ASN1_OCTET_STRING;		if (!sk_ASN1_TYPE_push(necdsa, ttmp))		{			sk_ASN1_TYPE_pop_free(necdsa, ASN1_TYPE_free);			ASN1_INTEGER_free(prkey);			return 0;		}		if ((ttmp = ASN1_TYPE_new()) == NULL)		{			EVPerr(EVP_F_ECDSA_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);			return 0;		}		ttmp->value.integer = prkey;		ttmp->type = V_ASN1_INTEGER;		if (!sk_ASN1_TYPE_push(necdsa, ttmp))		{			sk_ASN1_TYPE_pop_free(necdsa, ASN1_TYPE_free);			ASN1_INTEGER_free(prkey);			return 0;		}		if ((p8->pkey->value.octet_string = ASN1_OCTET_STRING_new()) == NULL)		{				EVPerr(EVP_F_ECDSA_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);			sk_ASN1_TYPE_pop_free(necdsa, ASN1_TYPE_free);			return 0;		}		if (!ASN1_seq_pack_ASN1_TYPE(necdsa, i2d_ASN1_TYPE,					 &p8->pkey->value.octet_string->data,					 &p8->pkey->value.octet_string->length)) 		{			EVPerr(EVP_F_ECDSA_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);			sk_ASN1_TYPE_pop_free(necdsa, ASN1_TYPE_free);			return 0;		}		sk_ASN1_TYPE_pop_free(necdsa, ASN1_TYPE_free);		break;		case PKCS8_EMBEDDED_PARAM:		p8->pkeyalg->parameter->type = V_ASN1_NULL;		necdsa = sk_ASN1_TYPE_new_null();		if ((ttmp = ASN1_TYPE_new()) == NULL)		{			EVPerr(EVP_F_ECDSA_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);			sk_ASN1_TYPE_pop_free(necdsa, ASN1_TYPE_free);			ASN1_INTEGER_free(prkey);			return 0;		}		ttmp->value.sequence = params;		ttmp->type = V_ASN1_SEQUENCE;		if (!sk_ASN1_TYPE_push(necdsa, ttmp))		{			sk_ASN1_TYPE_pop_free(necdsa, ASN1_TYPE_free);			ASN1_INTEGER_free(prkey);			return 0;		}		if ((ttmp = ASN1_TYPE_new()) == NULL)		{			EVPerr(EVP_F_ECDSA_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);			sk_ASN1_TYPE_pop_free(necdsa, ASN1_TYPE_free);			ASN1_INTEGER_free(prkey);			return 0;		}		ttmp->value.integer = prkey;		ttmp->type = V_ASN1_INTEGER;		if (!sk_ASN1_TYPE_push(necdsa, ttmp))		{			sk_ASN1_TYPE_pop_free(necdsa, ASN1_TYPE_free);			ASN1_INTEGER_free(prkey);			return 0;		}		if ((p8->pkey->value.octet_string = ASN1_OCTET_STRING_new()) == NULL)		{			EVPerr(EVP_F_ECDSA_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);			sk_ASN1_TYPE_pop_free(necdsa, ASN1_TYPE_free);			return 0;		}		if (!ASN1_seq_pack_ASN1_TYPE(necdsa, i2d_ASN1_TYPE,					 &p8->pkey->value.octet_string->data,					 &p8->pkey->value.octet_string->length)) 		{			EVPerr(EVP_F_ECDSA_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);			sk_ASN1_TYPE_pop_free(necdsa, ASN1_TYPE_free);			return 0;		}		sk_ASN1_TYPE_pop_free(necdsa, ASN1_TYPE_free);		break;	}	return 1;}