PKCS8_PRIV_KEY_INFO *EVP_PKEY2PKCS8_broken(EVP_PKEY *pkey, int broken)
{
	PKCS8_PRIV_KEY_INFO *p8;
	const EVP_PKEY_ASN1_METHOD *meth;

	if (!(p8 = PKCS8_PRIV_KEY_INFO_new())) {	
		EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN,ERR_R_MALLOC_FAILURE);
		return NULL;
	}
	p8->broken = broken;

	meth = EVP_PKEY_ASN1_find(pkey->type);

	if (meth)
		{
		if (meth->priv_encode)
			{
			if (!meth->priv_encode(p8, pkey))
				{
				EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN,
					EVP_R_PRIVATE_KEY_ENCODE_ERROR);
				goto error;
				}
			}
		else
			{
			EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN,
					EVP_R_METHOD_NOT_SUPPORTED);
			goto error;
			}
		}
	else
		{
		EVPerr(EVP_F_EVP_PKEY2PKCS8_BROKEN,
				EVP_R_UNSUPPORTED_PRIVATE_KEY_ALGORITHM);
		goto error;
		}
	RAND_add(p8->pkey->value.octet_string->data,
		 p8->pkey->value.octet_string->length, 0.0);
	return p8;
	error:
	PKCS8_PRIV_KEY_INFO_free(p8);
	return NULL;
}