EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
EVPerr(EVP_F_DSA_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);
static int dsa_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) *ndsa = NULL;	unsigned char *p = NULL, *q;	int len;	p8->pkeyalg->algorithm = OBJ_nid2obj(NID_dsa);	len = i2d_DSAparams (pkey->pkey.dsa, NULL);	if (!(p = OPENSSL_malloc(len))) {		EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);		goto err;	}	q = p;	i2d_DSAparams (pkey->pkey.dsa, &q);	if (!(params = ASN1_STRING_new())) {		EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);		goto err;	}	if (!ASN1_STRING_set(params, p, len)) {		EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);		goto err;	}	OPENSSL_free(p);	p = NULL;	/* Get private key into integer */	if (!(prkey = BN_to_ASN1_INTEGER (pkey->pkey.dsa->priv_key, NULL))) {		EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);		goto err;	}	switch(p8->broken) {		case PKCS8_OK:		case PKCS8_NO_OCTET:		if (!ASN1_pack_string_of(ASN1_INTEGER,prkey, i2d_ASN1_INTEGER,					 &p8->pkey->value.octet_string)) {			EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);			goto err;		}		M_ASN1_INTEGER_free (prkey);		prkey = NULL;		p8->pkeyalg->parameter->value.sequence = params;		params = NULL;		p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;		break;		case PKCS8_NS_DB:		p8->pkeyalg->parameter->value.sequence = params;		params = NULL;		p8->pkeyalg->parameter->type = V_ASN1_SEQUENCE;		if (!(ndsa = sk_ASN1_TYPE_new_null())) {			EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);			goto err;		}		if (!(ttmp = ASN1_TYPE_new())) {			EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);			goto err;		}		if (!(ttmp->value.integer =			BN_to_ASN1_INTEGER(pkey->pkey.dsa->pub_key, NULL))) {			EVPerr(EVP_F_EVP_PKEY2PKCS8,EVP_R_ENCODE_ERROR);			goto err;		}		ttmp->type = V_ASN1_INTEGER;		if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {			EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);			goto err;		}		if (!(ttmp = ASN1_TYPE_new())) {			EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);			goto err;		}		ttmp->value.integer = prkey;		prkey = NULL;		ttmp->type = V_ASN1_INTEGER;		if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {			EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);			goto err;		}		ttmp = NULL;		if (!(p8->pkey->value.octet_string = ASN1_OCTET_STRING_new())) {			EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);			goto err;		}		if (!ASN1_seq_pack_ASN1_TYPE(ndsa, i2d_ASN1_TYPE,					 &p8->pkey->value.octet_string->data,					 &p8->pkey->value.octet_string->length)) {			EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);			goto err;		}		sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);		break;		case PKCS8_EMBEDDED_PARAM:		p8->pkeyalg->parameter->type = V_ASN1_NULL;		if (!(ndsa = sk_ASN1_TYPE_new_null())) {			EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);			goto err;		}		if (!(ttmp = ASN1_TYPE_new())) {			EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);			goto err;		}		ttmp->value.sequence = params;		params = NULL;		ttmp->type = V_ASN1_SEQUENCE;		if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {			EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);			goto err;		}		if (!(ttmp = ASN1_TYPE_new())) {			EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);			goto err;		}		ttmp->value.integer = prkey;		prkey = NULL;		ttmp->type = V_ASN1_INTEGER;		if (!sk_ASN1_TYPE_push(ndsa, ttmp)) {			EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);			goto err;		}		ttmp = NULL;		if (!(p8->pkey->value.octet_string = ASN1_OCTET_STRING_new())) {			EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);			goto err;		}		if (!ASN1_seq_pack_ASN1_TYPE(ndsa, i2d_ASN1_TYPE,					 &p8->pkey->value.octet_string->data,					 &p8->pkey->value.octet_string->length)) {			EVPerr(EVP_F_EVP_PKEY2PKCS8,ERR_R_MALLOC_FAILURE);			goto err;		}		sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);		break;	}	return 1;err:	if (p != NULL) OPENSSL_free(p);	if (params != NULL) ASN1_STRING_free(params);	if (prkey != NULL) M_ASN1_INTEGER_free(prkey);	if (ttmp != NULL) ASN1_TYPE_free(ttmp);	if (ndsa != NULL) sk_ASN1_TYPE_pop_free(ndsa, ASN1_TYPE_free);	return 0;}