X509_PUBKEY *pk;
X509_ALGOR *a;
ASN1_OBJECT *o;
- unsigned char *s,*p;
+ unsigned char *s,*p = NULL;
int i;
if (x == NULL) return(0);
dsa->write_params=0;
ASN1_TYPE_free(a->parameter);
i=i2d_DSAparams(dsa,NULL);
- p=(unsigned char *)OPENSSL_malloc(i);
+ if ((p=(unsigned char *)OPENSSL_malloc(i)) == NULL) goto err;
pp=p;
i2d_DSAparams(dsa,&pp);
a->parameter=ASN1_TYPE_new();
#ifndef OPENSSL_NO_ECDSA
else if (pkey->type == EVP_PKEY_ECDSA)
{
+ int nid=0;
unsigned char *pp;
ECDSA *ecdsa;
ecdsa = pkey->pkey.ecdsa;
ASN1_TYPE_free(a->parameter);
- if ((i = i2d_ECDSAParameters(ecdsa, NULL)) == 0)
- {
- X509err(X509_F_X509_PUBKEY_SET, ERR_R_ECDSA_LIB);
- goto err;
- }
- if ((p = (unsigned char *) OPENSSL_malloc(i)) == NULL)
- {
- X509err(X509_F_X509_PUBKEY_SET, ERR_R_MALLOC_FAILURE);
- goto err;
- }
- pp = p;
- if (!i2d_ECDSAParameters(ecdsa, &pp))
- {
- X509err(X509_F_X509_PUBKEY_SET, ERR_R_ECDSA_LIB);
- OPENSSL_free(p);
- goto err;
- }
+
if ((a->parameter = ASN1_TYPE_new()) == NULL)
{
X509err(X509_F_X509_PUBKEY_SET, ERR_R_ASN1_LIB);
- OPENSSL_free(p);
goto err;
}
- a->parameter->type = V_ASN1_SEQUENCE;
- if ((a->parameter->value.sequence = ASN1_STRING_new()) == NULL)
+
+ if (EC_GROUP_get_asn1_flag(ecdsa->group)
+ && (nid = EC_GROUP_get_nid(ecdsa->group)))
{
- X509err(X509_F_X509_PUBKEY_SET, ERR_R_ASN1_LIB);
+ /* just set the OID */
+ a->parameter->type = V_ASN1_OBJECT;
+ a->parameter->value.object = OBJ_nid2obj(nid);
+ }
+ else /* explicit parameters */
+ {
+ if ((i = i2d_ECDSAParameters(ecdsa, NULL)) == 0)
+ {
+ X509err(X509_F_X509_PUBKEY_SET, ERR_R_ECDSA_LIB);
+ goto err;
+ }
+ if ((p = (unsigned char *) OPENSSL_malloc(i)) == NULL)
+ {
+ X509err(X509_F_X509_PUBKEY_SET, ERR_R_MALLOC_FAILURE);
+ goto err;
+ }
+ pp = p;
+ if (!i2d_ECDSAParameters(ecdsa, &pp))
+ {
+ X509err(X509_F_X509_PUBKEY_SET, ERR_R_ECDSA_LIB);
+ OPENSSL_free(p);
+ goto err;
+ }
+ a->parameter->type = V_ASN1_SEQUENCE;
+ if ((a->parameter->value.sequence = ASN1_STRING_new()) == NULL)
+ {
+ X509err(X509_F_X509_PUBKEY_SET, ERR_R_ASN1_LIB);
+ OPENSSL_free(p);
+ goto err;
+ }
+ ASN1_STRING_set(a->parameter->value.sequence, p, i);
OPENSSL_free(p);
- goto err;
}
- ASN1_STRING_set(a->parameter->value.sequence, p, i);
- OPENSSL_free(p);
}
#endif
else if (1)
}
if ((i=i2d_PublicKey(pkey,NULL)) <= 0) goto err;
- if ((s=(unsigned char *)OPENSSL_malloc(i+1)) == NULL) goto err;
+ if ((s=(unsigned char *)OPENSSL_malloc(i+1)) == NULL)
+ {
+ X509err(X509_F_X509_PUBKEY_SET,ERR_R_MALLOC_FAILURE);
+ goto err;
+ }
p=s;
i2d_PublicKey(pkey,&p);
if (!M_ASN1_BIT_STRING_set(pk->public_key,s,i)) goto err;
{
if (a->parameter && (a->parameter->type == V_ASN1_SEQUENCE))
{
+ /* type == V_ASN1_SEQUENCE => we have explicit parameters
+ * (e.g. parameters in the X9_62_EC_PARAMETERS-structure )
+ */
if ((ret->pkey.ecdsa= ECDSA_new()) == NULL)
{
X509err(X509_F_X509_PUBKEY_GET, ERR_R_MALLOC_FAILURE);
goto err;
}
}
+ else if (a->parameter && (a->parameter->type == V_ASN1_OBJECT))
+ {
+ /* type == V_ASN1_OBJECT => the parameters are given
+ * by an asn1 OID
+ */
+ ECDSA *ecdsa;
+ if (ret->pkey.ecdsa == NULL)
+ ret->pkey.ecdsa = ECDSA_new();
+ ecdsa = ret->pkey.ecdsa;
+ if (ecdsa->group)
+ EC_GROUP_free(ecdsa->group);
+ if ((ecdsa->group = EC_GROUP_new_by_name(
+ OBJ_obj2nid(a->parameter->value.object))) == NULL)
+ goto err;
+ EC_GROUP_set_asn1_flag(ecdsa->group,
+ OPENSSL_EC_NAMED_CURVE);
+ }
+ /* the case implicitlyCA is currently not implemented */
ret->save_parameters = 1;
}
#endif