aboutsummaryrefslogtreecommitdiff
path: root/crypto/dsa/dsa_ameth.c
diff options
context:
space:
mode:
authorDr. Stephen Henson <steve@openssl.org>2015-03-26 14:35:49 +0000
committerDr. Stephen Henson <steve@openssl.org>2015-03-26 22:04:15 +0000
commitea6b07b54c1f8fc2275a121cdda071e2df7bd6c1 (patch)
tree1c588d9f06776c8087dd60427a917814d5708109 /crypto/dsa/dsa_ameth.c
parentdd14f911714da77876a3c17e0168b6afef923be8 (diff)
downloadopenssl-ea6b07b54c1f8fc2275a121cdda071e2df7bd6c1.zip
openssl-ea6b07b54c1f8fc2275a121cdda071e2df7bd6c1.tar.gz
openssl-ea6b07b54c1f8fc2275a121cdda071e2df7bd6c1.tar.bz2
Simplify DSA public key handling.
DSA public keys could exist in two forms: a single Integer type or a SEQUENCE containing the parameters and public key with a field called "write_params" deciding which form to use. These forms are non standard and were only used by functions containing "DSAPublicKey" in the name. Simplify code to only use the parameter form and encode the public key component directly in the DSA public key method. Reviewed-by: Richard Levitte <levitte@openssl.org>
Diffstat (limited to 'crypto/dsa/dsa_ameth.c')
-rw-r--r--crypto/dsa/dsa_ameth.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/crypto/dsa/dsa_ameth.c b/crypto/dsa/dsa_ameth.c
index 96d5c5a..65e07fd 100644
--- a/crypto/dsa/dsa_ameth.c
+++ b/crypto/dsa/dsa_ameth.c
@@ -132,6 +132,7 @@ static int dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
unsigned char *penc = NULL;
int penclen;
ASN1_STRING *str = NULL;
+ ASN1_INTEGER *pubint = NULL;
dsa = pkey->pkey.dsa;
if (pkey->save_parameters && dsa->p && dsa->q && dsa->g) {
@@ -149,9 +150,15 @@ static int dsa_pub_encode(X509_PUBKEY *pk, const EVP_PKEY *pkey)
} else
ptype = V_ASN1_UNDEF;
- dsa->write_params = 0;
+ pubint = BN_to_ASN1_INTEGER(dsa->pub_key, NULL);
- penclen = i2d_DSAPublicKey(dsa, &penc);
+ if (pubint == NULL) {
+ DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE);
+ goto err;
+ }
+
+ penclen = i2d_ASN1_INTEGER(pubint, &penc);
+ ASN1_INTEGER_free(pubint);
if (penclen <= 0) {
DSAerr(DSA_F_DSA_PUB_ENCODE, ERR_R_MALLOC_FAILURE);