EVPerr(EVP_F_EC_KEY_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);
EVPerr(EVP_F_ECKEY_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);
static int eckey_pkey2pkcs8(PKCS8_PRIV_KEY_INFO *p8, EVP_PKEY *pkey){	EC_KEY		*eckey;	unsigned char	*p, *pp;	int 		nid, i, ret = 0;	unsigned int    tmp_flags;	if (pkey->pkey.eckey == NULL || pkey->pkey.eckey->group == NULL)	{		EVPerr(EVP_F_EC_KEY_PKEY2PKCS8, EVP_R_MISSING_PARAMETERS);		return 0;	}	eckey = pkey->pkey.eckey;	/* set the ec parameters OID */	if (p8->pkeyalg->algorithm)		ASN1_OBJECT_free(p8->pkeyalg->algorithm);	p8->pkeyalg->algorithm = OBJ_nid2obj(NID_X9_62_id_ecPublicKey);	/* set the ec parameters */	if (p8->pkeyalg->parameter)	{		ASN1_TYPE_free(p8->pkeyalg->parameter);		p8->pkeyalg->parameter = NULL;	}	if ((p8->pkeyalg->parameter = ASN1_TYPE_new()) == NULL)	{		EVPerr(EVP_F_EC_KEY_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);		return 0;	}		if (EC_GROUP_get_asn1_flag(eckey->group)                     && (nid = EC_GROUP_get_curve_name(eckey->group)))	{		/* we have a 'named curve' => just set the OID */		p8->pkeyalg->parameter->type = V_ASN1_OBJECT;		p8->pkeyalg->parameter->value.object = OBJ_nid2obj(nid);	}	else	/* explicit parameters */	{		if ((i = i2d_ECParameters(eckey, NULL)) == 0)		{			EVPerr(EVP_F_EC_KEY_PKEY2PKCS8, ERR_R_EC_LIB);			return 0;		}		if ((p = (unsigned char *) OPENSSL_malloc(i)) == NULL)		{			EVPerr(EVP_F_EC_KEY_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);			return 0;		}			pp = p;		if (!i2d_ECParameters(eckey, &pp))		{			EVPerr(EVP_F_EC_KEY_PKEY2PKCS8, ERR_R_EC_LIB);			OPENSSL_free(p);			return 0;		}		p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;		if ((p8->pkeyalg->parameter->value.sequence 			= ASN1_STRING_new()) == NULL)		{			EVPerr(EVP_F_EC_KEY_PKEY2PKCS8, ERR_R_ASN1_LIB);			OPENSSL_free(p);			return 0;		}		ASN1_STRING_set(p8->pkeyalg->parameter->value.sequence, p, i);		OPENSSL_free(p);	}	/* set the private key */	/* do not include the parameters in the SEC1 private key	 * see PKCS#11 12.11 */	tmp_flags  = pkey->pkey.eckey->enc_flag;	pkey->pkey.eckey->enc_flag |= EC_PKEY_NO_PARAMETERS;	i = i2d_ECPrivateKey(pkey->pkey.eckey, NULL);	if (!i)	{		pkey->pkey.eckey->enc_flag = tmp_flags;		EVPerr(EVP_F_EC_KEY_PKEY2PKCS8, ERR_R_EC_LIB);		return 0;	}	p = (unsigned char *) OPENSSL_malloc(i);	if (!p)	{		pkey->pkey.eckey->enc_flag = tmp_flags;		EVPerr(EVP_F_EC_KEY_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);		return 0;	}	pp = p;	if (!i2d_ECPrivateKey(pkey->pkey.eckey, &pp))	{		pkey->pkey.eckey->enc_flag = tmp_flags;		EVPerr(EVP_F_EC_KEY_PKEY2PKCS8, ERR_R_EC_LIB);		OPENSSL_free(p);		return 0;	}	/* restore old encoding flags */	pkey->pkey.eckey->enc_flag = tmp_flags;	switch(p8->broken) {		case PKCS8_OK:		p8->pkey->value.octet_string = ASN1_OCTET_STRING_new();		if (!p8->pkey->value.octet_string ||		    !M_ASN1_OCTET_STRING_set(p8->pkey->value.octet_string,		    (const void *)p, i))		{			EVPerr(EVP_F_EC_KEY_PKEY2PKCS8, ERR_R_MALLOC_FAILURE);		}		else			ret = 1;		break;		case PKCS8_NO_OCTET:		/* RSA specific */		case PKCS8_NS_DB:		/* DSA specific */		case PKCS8_EMBEDDED_PARAM:	/* DSA specific */		default:			EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);	}	OPENSSL_cleanse(p, (size_t)i);	OPENSSL_free(p);	return ret;}