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>
This commit is contained in:
parent
dd14f91171
commit
ea6b07b54c
@ -160,7 +160,6 @@ struct dsa_st {
|
||||
*/
|
||||
int pad;
|
||||
long version;
|
||||
int write_params;
|
||||
BIGNUM *p;
|
||||
BIGNUM *q; /* == 20 */
|
||||
BIGNUM *g;
|
||||
|
@ -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);
|
||||
|
@ -132,17 +132,12 @@ IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAparams, DSAparams)
|
||||
* key as an INTEGER or the parameters and public key in a SEQUENCE
|
||||
*/
|
||||
|
||||
ASN1_SEQUENCE(dsa_pub_internal) = {
|
||||
ASN1_SEQUENCE(DSAPublicKey) = {
|
||||
ASN1_SIMPLE(DSA, pub_key, BIGNUM),
|
||||
ASN1_SIMPLE(DSA, p, BIGNUM),
|
||||
ASN1_SIMPLE(DSA, q, BIGNUM),
|
||||
ASN1_SIMPLE(DSA, g, BIGNUM)
|
||||
} ASN1_SEQUENCE_END_name(DSA, dsa_pub_internal)
|
||||
|
||||
ASN1_CHOICE_cb(DSAPublicKey, dsa_cb) = {
|
||||
ASN1_SIMPLE(DSA, pub_key, BIGNUM),
|
||||
ASN1_EX_COMBINE(0, 0, dsa_pub_internal)
|
||||
} ASN1_CHOICE_END_cb(DSA, DSAPublicKey, write_params)
|
||||
} ASN1_SEQUENCE_END_name(DSA, DSAPublicKey)
|
||||
|
||||
IMPLEMENT_ASN1_ENCODE_FUNCTIONS_const_fname(DSA, DSAPublicKey, DSAPublicKey)
|
||||
|
||||
|
@ -146,7 +146,6 @@ DSA *DSA_new_method(ENGINE *engine)
|
||||
|
||||
ret->pad = 0;
|
||||
ret->version = 0;
|
||||
ret->write_params = 1;
|
||||
ret->p = NULL;
|
||||
ret->q = NULL;
|
||||
ret->g = NULL;
|
||||
|
Loading…
x
Reference in New Issue
Block a user