From 75ef718820c44d8eb5efd98425c64b584ce2f5d5 Mon Sep 17 00:00:00 2001 From: "Dr. Stephen Henson" Date: Wed, 12 Apr 2006 11:14:11 +0000 Subject: [PATCH 1/1] Support for DSA keygen, fix for genpkey. --- apps/genpkey.c | 4 +--- crypto/dsa/dsa.h | 2 ++ crypto/dsa/dsa_err.c | 2 ++ crypto/dsa/dsa_pmeth.c | 21 ++++++++++++++++++++- 4 files changed, 25 insertions(+), 4 deletions(-) diff --git a/apps/genpkey.c b/apps/genpkey.c index 34432874e8..9a58b64e92 100644 --- a/apps/genpkey.c +++ b/apps/genpkey.c @@ -87,7 +87,7 @@ int MAIN(int argc, char **argv) int badarg = 0; int ret = 1; - int do_param = -1; + int do_param = 0; if (bio_err == NULL) bio_err = BIO_new_fp (stderr, BIO_NOCLOSE); @@ -147,8 +147,6 @@ int MAIN(int argc, char **argv) { if (!args[1]) goto bad; - if (do_param == -1) - do_param = 0; if (!init_gen_str(bio_err, &ctx, *(++args),e, do_param)) goto end; } diff --git a/crypto/dsa/dsa.h b/crypto/dsa/dsa.h index 97efb92bd9..c4d440d51c 100644 --- a/crypto/dsa/dsa.h +++ b/crypto/dsa/dsa.h @@ -279,6 +279,7 @@ void ERR_load_DSA_strings(void); #define DSA_F_DSA_VERIFY 108 #define DSA_F_I2D_DSA_SIG 111 #define DSA_F_PKEY_DSA_CTRL 120 +#define DSA_F_PKEY_DSA_KEYGEN 121 #define DSA_F_SIG_CB 114 /* Reason codes. */ @@ -288,6 +289,7 @@ void ERR_load_DSA_strings(void); #define DSA_R_DECODE_ERROR 104 #define DSA_R_INVALID_DIGEST_TYPE 106 #define DSA_R_MISSING_PARAMETERS 101 +#define DSA_R_NO_PARAMETERS_SET 107 #define DSA_R_PARAMETER_ENCODING_ERROR 105 #ifdef __cplusplus diff --git a/crypto/dsa/dsa_err.c b/crypto/dsa/dsa_err.c index 5365f614a4..8bd6968fa7 100644 --- a/crypto/dsa/dsa_err.c +++ b/crypto/dsa/dsa_err.c @@ -89,6 +89,7 @@ static ERR_STRING_DATA DSA_str_functs[]= {ERR_FUNC(DSA_F_DSA_VERIFY), "DSA_verify"}, {ERR_FUNC(DSA_F_I2D_DSA_SIG), "i2d_DSA_SIG"}, {ERR_FUNC(DSA_F_PKEY_DSA_CTRL), "PKEY_DSA_CTRL"}, +{ERR_FUNC(DSA_F_PKEY_DSA_KEYGEN), "PKEY_DSA_KEYGEN"}, {ERR_FUNC(DSA_F_SIG_CB), "SIG_CB"}, {0,NULL} }; @@ -101,6 +102,7 @@ static ERR_STRING_DATA DSA_str_reasons[]= {ERR_REASON(DSA_R_DECODE_ERROR) ,"decode error"}, {ERR_REASON(DSA_R_INVALID_DIGEST_TYPE) ,"invalid digest type"}, {ERR_REASON(DSA_R_MISSING_PARAMETERS) ,"missing parameters"}, +{ERR_REASON(DSA_R_NO_PARAMETERS_SET) ,"no parameters set"}, {ERR_REASON(DSA_R_PARAMETER_ENCODING_ERROR),"parameter encoding error"}, {0,NULL} }; diff --git a/crypto/dsa/dsa_pmeth.c b/crypto/dsa/dsa_pmeth.c index f91d03c208..364ba15a12 100644 --- a/crypto/dsa/dsa_pmeth.c +++ b/crypto/dsa/dsa_pmeth.c @@ -200,6 +200,24 @@ static int pkey_dsa_paramgen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) return ret; } +static int pkey_dsa_keygen(EVP_PKEY_CTX *ctx, EVP_PKEY *pkey) + { + DSA *dsa = NULL; + if (ctx->pkey == NULL) + { + DSAerr(DSA_F_PKEY_DSA_KEYGEN, DSA_R_NO_PARAMETERS_SET); + return 0; + } + dsa = DSA_new(); + if (!dsa) + return 0; + EVP_PKEY_assign_DSA(pkey, dsa); + /* Note: if error return, pkey is freed by parent routine */ + if (!EVP_PKEY_copy_parameters(pkey, ctx->pkey)) + return 0; + return DSA_generate_key(pkey->pkey.dsa); + } + const EVP_PKEY_METHOD dsa_pkey_meth = { EVP_PKEY_DSA, @@ -210,7 +228,8 @@ const EVP_PKEY_METHOD dsa_pkey_meth = 0, pkey_dsa_paramgen, - 0,0, + 0, + pkey_dsa_keygen, 0, pkey_dsa_sign, -- 2.34.1