-/* $OpenBSD: dsa_ameth.c,v 1.30 2022/01/07 09:35:36 tb Exp $ */
+/* $OpenBSD: dsa_ameth.c,v 1.31 2022/01/14 08:29:06 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
{
DSA *dsa;
+ ASN1_INTEGER *pubint = NULL;
void *pval = NULL;
int ptype;
unsigned char *penc = NULL;
} else
ptype = V_ASN1_UNDEF;
- dsa->write_params = 0;
- penclen = i2d_DSAPublicKey(dsa, &penc);
+ if ((pubint = BN_to_ASN1_INTEGER(dsa->pub_key, NULL)) == NULL) {
+ DSAerror(ERR_R_MALLOC_FAILURE);
+ goto err;
+ }
+
+ penclen = i2d_ASN1_INTEGER(pubint, &penc);
+ ASN1_INTEGER_free(pubint);
if (penclen <= 0) {
DSAerror(ERR_R_MALLOC_FAILURE);
-/* $OpenBSD: dsa_asn1.c,v 1.23 2022/01/07 09:35:36 tb Exp $ */
+/* $OpenBSD: dsa_asn1.c,v 1.24 2022/01/14 08:29:06 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2000.
*/
return ASN1_item_i2d_fp(&DSAparams_it, fp, a);
}
-/*
- * DSA public key is a bit trickier... its effectively a CHOICE type
- * decided by a field called write_params which can either write out
- * just the public key as an INTEGER or the parameters and public key
- * in a SEQUENCE
- */
-
-static const ASN1_TEMPLATE dsa_pub_internal_seq_tt[] = {
+static const ASN1_AUX DSAPublicKey_aux = {
+ .app_data = NULL,
+ .flags = 0,
+ .ref_offset = 0,
+ .ref_lock = 0,
+ .asn1_cb = dsa_cb,
+ .enc_offset = 0,
+};
+static const ASN1_TEMPLATE DSAPublicKey_seq_tt[] = {
{
.flags = 0,
.tag = 0,
},
};
-const ASN1_ITEM dsa_pub_internal_it = {
+const ASN1_ITEM DSAPublicKey_it = {
.itype = ASN1_ITYPE_SEQUENCE,
.utype = V_ASN1_SEQUENCE,
- .templates = dsa_pub_internal_seq_tt,
- .tcount = sizeof(dsa_pub_internal_seq_tt) / sizeof(ASN1_TEMPLATE),
- .funcs = NULL,
- .size = sizeof(DSA),
- .sname = "DSA",
-};
-
-static const ASN1_AUX DSAPublicKey_aux = {
- .app_data = NULL,
- .flags = 0,
- .ref_offset = 0,
- .ref_lock = 0,
- .asn1_cb = dsa_cb,
- .enc_offset = 0,
-};
-static const ASN1_TEMPLATE DSAPublicKey_ch_tt[] = {
- {
- .flags = 0,
- .tag = 0,
- .offset = offsetof(DSA, pub_key),
- .field_name = "pub_key",
- .item = &BIGNUM_it,
- },
- {
- .flags = 0 | ASN1_TFLG_COMBINE,
- .tag = 0,
- .offset = 0,
- .field_name = NULL,
- .item = &dsa_pub_internal_it,
- },
-};
-
-const ASN1_ITEM DSAPublicKey_it = {
- .itype = ASN1_ITYPE_CHOICE,
- .utype = offsetof(DSA, write_params),
- .templates = DSAPublicKey_ch_tt,
- .tcount = sizeof(DSAPublicKey_ch_tt) / sizeof(ASN1_TEMPLATE),
+ .templates = DSAPublicKey_seq_tt,
+ .tcount = sizeof(DSAPublicKey_seq_tt) / sizeof(ASN1_TEMPLATE),
.funcs = &DSAPublicKey_aux,
.size = sizeof(DSA),
.sname = "DSA",
};
-
DSA *
d2i_DSAPublicKey(DSA **a, const unsigned char **in, long len)
{