| 
									
										
										
										
											2019-08-30 20:33:37 +08:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2020-01-21 13:57:25 +08:00
										 |  |  |  * Copyright 2019-2020 The OpenSSL Project Authors. All Rights Reserved. | 
					
						
							| 
									
										
										
										
											2019-08-30 20:33:37 +08:00
										 |  |  |  * | 
					
						
							|  |  |  |  * Licensed under the Apache License 2.0 (the "License").  You may not use | 
					
						
							|  |  |  |  * this file except in compliance with the License.  You can obtain a copy | 
					
						
							|  |  |  |  * in the file LICENSE in the source distribution or at | 
					
						
							|  |  |  |  * https://www.openssl.org/source/license.html
 | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-30 05:23:39 +08:00
										 |  |  | /*
 | 
					
						
							|  |  |  |  * DSA low level APIs are deprecated for public use, but still ok for | 
					
						
							|  |  |  |  * internal use. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #include "internal/deprecated.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  | #include "e_os.h" /* strcasecmp */
 | 
					
						
							| 
									
										
										
										
											2020-06-21 07:21:19 +08:00
										 |  |  | #include <openssl/core_dispatch.h>
 | 
					
						
							| 
									
										
										
										
											2019-08-30 20:33:37 +08:00
										 |  |  | #include <openssl/core_names.h>
 | 
					
						
							|  |  |  | #include <openssl/bn.h>
 | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  | #include <openssl/err.h>
 | 
					
						
							| 
									
										
										
										
											2019-11-08 22:24:42 +08:00
										 |  |  | #include "prov/providercommon.h"
 | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  | #include "prov/implementations.h"
 | 
					
						
							| 
									
										
										
										
											2020-01-12 09:32:12 +08:00
										 |  |  | #include "prov/provider_ctx.h"
 | 
					
						
							|  |  |  | #include "crypto/dsa.h"
 | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  | #include "internal/sizes.h"
 | 
					
						
							|  |  |  | #include "internal/nelem.h"
 | 
					
						
							|  |  |  | #include "internal/param_build_set.h"
 | 
					
						
							| 
									
										
										
										
											2019-08-30 20:33:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-21 07:19:16 +08:00
										 |  |  | static OSSL_FUNC_keymgmt_new_fn dsa_newdata; | 
					
						
							|  |  |  | static OSSL_FUNC_keymgmt_free_fn dsa_freedata; | 
					
						
							|  |  |  | static OSSL_FUNC_keymgmt_gen_init_fn dsa_gen_init; | 
					
						
							|  |  |  | static OSSL_FUNC_keymgmt_gen_set_template_fn dsa_gen_set_template; | 
					
						
							|  |  |  | static OSSL_FUNC_keymgmt_gen_set_params_fn dsa_gen_set_params; | 
					
						
							|  |  |  | static OSSL_FUNC_keymgmt_gen_settable_params_fn dsa_gen_settable_params; | 
					
						
							|  |  |  | static OSSL_FUNC_keymgmt_gen_fn dsa_gen; | 
					
						
							|  |  |  | static OSSL_FUNC_keymgmt_gen_cleanup_fn dsa_gen_cleanup; | 
					
						
							| 
									
										
										
										
											2020-07-28 00:40:05 +08:00
										 |  |  | static OSSL_FUNC_keymgmt_load_fn dsa_load; | 
					
						
							| 
									
										
										
										
											2020-06-21 07:19:16 +08:00
										 |  |  | static OSSL_FUNC_keymgmt_get_params_fn dsa_get_params; | 
					
						
							|  |  |  | static OSSL_FUNC_keymgmt_gettable_params_fn dsa_gettable_params; | 
					
						
							|  |  |  | static OSSL_FUNC_keymgmt_has_fn dsa_has; | 
					
						
							|  |  |  | static OSSL_FUNC_keymgmt_match_fn dsa_match; | 
					
						
							|  |  |  | static OSSL_FUNC_keymgmt_validate_fn dsa_validate; | 
					
						
							|  |  |  | static OSSL_FUNC_keymgmt_import_fn dsa_import; | 
					
						
							|  |  |  | static OSSL_FUNC_keymgmt_import_types_fn dsa_import_types; | 
					
						
							|  |  |  | static OSSL_FUNC_keymgmt_export_fn dsa_export; | 
					
						
							|  |  |  | static OSSL_FUNC_keymgmt_export_types_fn dsa_export_types; | 
					
						
							| 
									
										
										
										
											2019-08-30 20:33:37 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-13 15:54:47 +08:00
										 |  |  | #define DSA_DEFAULT_MD "SHA256"
 | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  | #define DSA_POSSIBLE_SELECTIONS                                                \
 | 
					
						
							| 
									
										
										
										
											2020-02-05 00:49:28 +08:00
										 |  |  |     (OSSL_KEYMGMT_SELECT_KEYPAIR | OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) | 
					
						
							| 
									
										
										
										
											2020-01-13 15:54:47 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  | struct dsa_gen_ctx { | 
					
						
							|  |  |  |     OPENSSL_CTX *libctx; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     FFC_PARAMS *ffc_params; | 
					
						
							|  |  |  |     int selection; | 
					
						
							|  |  |  |     /* All these parameters are used for parameter generation only */ | 
					
						
							|  |  |  |     size_t pbits; | 
					
						
							|  |  |  |     size_t qbits; | 
					
						
							|  |  |  |     unsigned char *seed; /* optional FIPS186-4 param for testing */ | 
					
						
							|  |  |  |     size_t seedlen; | 
					
						
							|  |  |  |     int gindex; /* optional  FIPS186-4 generator index (ignored if -1) */ | 
					
						
							|  |  |  |     int gen_type; /* DSA_PARAMGEN_TYPE_FIPS_186_2 or DSA_PARAMGEN_TYPE_FIPS_186_4 */ | 
					
						
							|  |  |  |     int pcounter; | 
					
						
							|  |  |  |     int hindex; | 
					
						
							| 
									
										
										
										
											2020-06-17 09:33:16 +08:00
										 |  |  |     const char *mdname; | 
					
						
							|  |  |  |     const char *mdprops; | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  |     OSSL_CALLBACK *cb; | 
					
						
							|  |  |  |     void *cbarg; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | typedef struct dh_name2id_st{ | 
					
						
							|  |  |  |     const char *name; | 
					
						
							|  |  |  |     int id; | 
					
						
							|  |  |  | } DSA_GENTYPE_NAME2ID; | 
					
						
							| 
									
										
										
										
											2019-10-14 16:37:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  | static const DSA_GENTYPE_NAME2ID dsatype2id[]= | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     { "default", DSA_PARAMGEN_TYPE_FIPS_186_4 }, | 
					
						
							|  |  |  |     { "fips186_4", DSA_PARAMGEN_TYPE_FIPS_186_4 }, | 
					
						
							|  |  |  |     { "fips186_2", DSA_PARAMGEN_TYPE_FIPS_186_2 }, | 
					
						
							|  |  |  | }; | 
					
						
							| 
									
										
										
										
											2019-10-14 16:37:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  | static int dsa_gen_type_name2id(const char *name) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     size_t i; | 
					
						
							| 
									
										
										
										
											2019-10-14 16:37:08 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  |     for (i = 0; i < OSSL_NELEM(dsatype2id); ++i) { | 
					
						
							|  |  |  |         if (strcasecmp(dsatype2id[i].name, name) == 0) | 
					
						
							|  |  |  |             return dsatype2id[i].id; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return -1; | 
					
						
							| 
									
										
										
										
											2019-10-14 16:37:08 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  | static int dsa_key_todata(DSA *dsa, OSSL_PARAM_BLD *bld, OSSL_PARAM params[]) | 
					
						
							| 
									
										
										
										
											2019-10-14 16:37:08 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  |     const BIGNUM *priv = NULL, *pub = NULL; | 
					
						
							| 
									
										
										
										
											2019-10-14 16:37:08 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (dsa == NULL) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  |     DSA_get0_key(dsa, &pub, &priv); | 
					
						
							|  |  |  |     if (priv != NULL | 
					
						
							|  |  |  |         && !ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_PRIV_KEY, priv)) | 
					
						
							| 
									
										
										
										
											2019-10-14 16:37:08 +08:00
										 |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  |     if (pub != NULL | 
					
						
							|  |  |  |         && !ossl_param_build_set_bn(bld, params, OSSL_PKEY_PARAM_PUB_KEY, pub)) | 
					
						
							| 
									
										
										
										
											2019-10-14 16:37:08 +08:00
										 |  |  |         return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  | static void *dsa_newdata(void *provctx) | 
					
						
							| 
									
										
										
										
											2019-10-14 16:11:40 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-16 11:03:46 +08:00
										 |  |  |     return dsa_new_with_ctx(PROV_LIBRARY_CONTEXT_OF(provctx)); | 
					
						
							| 
									
										
										
										
											2019-10-14 16:11:40 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  | static void dsa_freedata(void *keydata) | 
					
						
							| 
									
										
										
										
											2019-10-14 16:37:08 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  |     DSA_free(keydata); | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2019-11-08 22:24:42 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  | static int dsa_has(void *keydata, int selection) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DSA *dsa = keydata; | 
					
						
							|  |  |  |     int ok = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-03-21 13:03:39 +08:00
										 |  |  |     if (dsa != NULL) { | 
					
						
							|  |  |  |         if ((selection & DSA_POSSIBLE_SELECTIONS) != 0) | 
					
						
							|  |  |  |             ok = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) | 
					
						
							|  |  |  |             ok = ok && (DSA_get0_pub_key(dsa) != NULL); | 
					
						
							|  |  |  |         if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) | 
					
						
							|  |  |  |             ok = ok && (DSA_get0_priv_key(dsa) != NULL); | 
					
						
							|  |  |  |         if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) | 
					
						
							|  |  |  |             ok = ok && (DSA_get0_p(dsa) != NULL && DSA_get0_g(dsa) != NULL); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  |     return ok; | 
					
						
							| 
									
										
										
										
											2019-10-14 16:37:08 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-06 16:53:15 +08:00
										 |  |  | static int dsa_match(const void *keydata1, const void *keydata2, int selection) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     const DSA *dsa1 = keydata1; | 
					
						
							|  |  |  |     const DSA *dsa2 = keydata2; | 
					
						
							|  |  |  |     int ok = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) | 
					
						
							|  |  |  |         ok = ok | 
					
						
							|  |  |  |             && BN_cmp(DSA_get0_pub_key(dsa1), DSA_get0_pub_key(dsa2)) == 0; | 
					
						
							|  |  |  |     if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) | 
					
						
							|  |  |  |         ok = ok | 
					
						
							|  |  |  |             && BN_cmp(DSA_get0_priv_key(dsa1), DSA_get0_priv_key(dsa2)) == 0; | 
					
						
							|  |  |  |     if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) { | 
					
						
							|  |  |  |         FFC_PARAMS *dsaparams1 = dsa_get0_params((DSA *)dsa1); | 
					
						
							|  |  |  |         FFC_PARAMS *dsaparams2 = dsa_get0_params((DSA *)dsa2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         ok = ok && ffc_params_cmp(dsaparams1, dsaparams2, 1); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return ok; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  | static int dsa_import(void *keydata, int selection, const OSSL_PARAM params[]) | 
					
						
							| 
									
										
										
										
											2019-08-30 20:33:37 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  |     DSA *dsa = keydata; | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  |     int ok = 1; | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (dsa == NULL) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  |     if ((selection & DSA_POSSIBLE_SELECTIONS) == 0) | 
					
						
							|  |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0) | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  |         ok = ok && dsa_ffc_params_fromdata(dsa, params); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  |     if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) | 
					
						
							| 
									
										
										
										
											2020-03-23 12:40:47 +08:00
										 |  |  |         ok = ok && dsa_key_fromdata(dsa, params); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     return ok; | 
					
						
							| 
									
										
										
										
											2019-08-30 20:33:37 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  | static int dsa_export(void *keydata, int selection, OSSL_CALLBACK *param_cb, | 
					
						
							|  |  |  |                       void *cbarg) | 
					
						
							| 
									
										
										
										
											2019-10-14 16:37:08 +08:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  |     DSA *dsa = keydata; | 
					
						
							| 
									
										
										
										
											2020-03-26 07:28:01 +08:00
										 |  |  |     OSSL_PARAM_BLD *tmpl = OSSL_PARAM_BLD_new(); | 
					
						
							| 
									
										
										
										
											2019-11-08 22:24:42 +08:00
										 |  |  |     OSSL_PARAM *params = NULL; | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  |     int ok = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (dsa == NULL) | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  |         goto err; | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0) | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  |         ok = ok && ffc_params_todata(dsa_get0_params(dsa), tmpl, NULL); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  |     if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  |         ok = ok && dsa_key_todata(dsa, tmpl, NULL); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (!ok | 
					
						
							| 
									
										
										
										
											2020-03-26 07:28:01 +08:00
										 |  |  |         || (params = OSSL_PARAM_BLD_to_param(tmpl)) == NULL) | 
					
						
							|  |  |  |         goto err;; | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |     ok = param_cb(params, cbarg); | 
					
						
							| 
									
										
										
										
											2020-03-26 07:28:01 +08:00
										 |  |  |     OSSL_PARAM_BLD_free_params(params); | 
					
						
							|  |  |  | err: | 
					
						
							|  |  |  |     OSSL_PARAM_BLD_free(tmpl); | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  |     return ok; | 
					
						
							| 
									
										
										
										
											2019-10-14 16:37:08 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-05 00:49:28 +08:00
										 |  |  | /* IMEXPORT = IMPORT + EXPORT */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  | # define DSA_IMEXPORTABLE_PARAMETERS                                           \
 | 
					
						
							|  |  |  |     OSSL_PARAM_BN(OSSL_PKEY_PARAM_FFC_P, NULL, 0),                             \ | 
					
						
							|  |  |  |     OSSL_PARAM_BN(OSSL_PKEY_PARAM_FFC_Q, NULL, 0),                             \ | 
					
						
							|  |  |  |     OSSL_PARAM_BN(OSSL_PKEY_PARAM_FFC_G, NULL, 0),                             \ | 
					
						
							|  |  |  |     OSSL_PARAM_BN(OSSL_PKEY_PARAM_FFC_COFACTOR, NULL, 0),                      \ | 
					
						
							|  |  |  |     OSSL_PARAM_int(OSSL_PKEY_PARAM_FFC_GINDEX, NULL),                          \ | 
					
						
							|  |  |  |     OSSL_PARAM_int(OSSL_PKEY_PARAM_FFC_PCOUNTER, NULL),                        \ | 
					
						
							|  |  |  |     OSSL_PARAM_int(OSSL_PKEY_PARAM_FFC_H, NULL),                               \ | 
					
						
							|  |  |  |     OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_FFC_SEED, NULL, 0) | 
					
						
							| 
									
										
										
										
											2020-02-05 00:49:28 +08:00
										 |  |  | # define DSA_IMEXPORTABLE_PUBLIC_KEY                    \
 | 
					
						
							| 
									
										
										
										
											2020-01-28 00:57:03 +08:00
										 |  |  |     OSSL_PARAM_BN(OSSL_PKEY_PARAM_PUB_KEY, NULL, 0) | 
					
						
							| 
									
										
										
										
											2020-02-05 00:49:28 +08:00
										 |  |  | # define DSA_IMEXPORTABLE_PRIVATE_KEY                   \
 | 
					
						
							| 
									
										
										
										
											2020-01-28 00:57:03 +08:00
										 |  |  |     OSSL_PARAM_BN(OSSL_PKEY_PARAM_PRIV_KEY, NULL, 0) | 
					
						
							| 
									
										
										
										
											2020-02-05 00:49:28 +08:00
										 |  |  | static const OSSL_PARAM dsa_all_types[] = { | 
					
						
							|  |  |  |     DSA_IMEXPORTABLE_PARAMETERS, | 
					
						
							|  |  |  |     DSA_IMEXPORTABLE_PUBLIC_KEY, | 
					
						
							|  |  |  |     DSA_IMEXPORTABLE_PRIVATE_KEY, | 
					
						
							|  |  |  |     OSSL_PARAM_END | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | static const OSSL_PARAM dsa_parameter_types[] = { | 
					
						
							|  |  |  |     DSA_IMEXPORTABLE_PARAMETERS, | 
					
						
							|  |  |  |     OSSL_PARAM_END | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | static const OSSL_PARAM dsa_key_types[] = { | 
					
						
							|  |  |  |     DSA_IMEXPORTABLE_PUBLIC_KEY, | 
					
						
							|  |  |  |     DSA_IMEXPORTABLE_PRIVATE_KEY, | 
					
						
							|  |  |  |     OSSL_PARAM_END | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | static const OSSL_PARAM *dsa_types[] = { | 
					
						
							|  |  |  |     NULL,                        /* Index 0 = none of them */ | 
					
						
							|  |  |  |     dsa_parameter_types,          /* Index 1 = parameter types */ | 
					
						
							|  |  |  |     dsa_key_types,                /* Index 2 = key types */ | 
					
						
							|  |  |  |     dsa_all_types                 /* Index 3 = 1 + 2 */ | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const OSSL_PARAM *dsa_imexport_types(int selection) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int type_select = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((selection & OSSL_KEYMGMT_SELECT_ALL_PARAMETERS) != 0) | 
					
						
							|  |  |  |         type_select += 1; | 
					
						
							|  |  |  |     if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) | 
					
						
							|  |  |  |         type_select += 2; | 
					
						
							|  |  |  |     return dsa_types[type_select]; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const OSSL_PARAM *dsa_import_types(int selection) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return dsa_imexport_types(selection); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const OSSL_PARAM *dsa_export_types(int selection) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return dsa_imexport_types(selection); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  | static ossl_inline int dsa_get_params(void *key, OSSL_PARAM params[]) | 
					
						
							| 
									
										
										
										
											2020-01-08 10:49:08 +08:00
										 |  |  | { | 
					
						
							|  |  |  |     DSA *dsa = key; | 
					
						
							|  |  |  |     OSSL_PARAM *p; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_BITS)) != NULL | 
					
						
							|  |  |  |         && !OSSL_PARAM_set_int(p, DSA_bits(dsa))) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_SECURITY_BITS)) != NULL | 
					
						
							|  |  |  |         && !OSSL_PARAM_set_int(p, DSA_security_bits(dsa))) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_MAX_SIZE)) != NULL | 
					
						
							|  |  |  |         && !OSSL_PARAM_set_int(p, DSA_size(dsa))) | 
					
						
							|  |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2020-01-13 15:54:47 +08:00
										 |  |  |     if ((p = OSSL_PARAM_locate(params, OSSL_PKEY_PARAM_DEFAULT_DIGEST)) != NULL | 
					
						
							|  |  |  |         && !OSSL_PARAM_set_utf8_string(p, DSA_DEFAULT_MD)) | 
					
						
							|  |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  |     return ffc_params_todata(dsa_get0_params(dsa), NULL, params) | 
					
						
							|  |  |  |            && dsa_key_todata(dsa, NULL, params); | 
					
						
							| 
									
										
										
										
											2020-01-08 10:49:08 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-02-05 00:49:28 +08:00
										 |  |  | static const OSSL_PARAM dsa_params[] = { | 
					
						
							|  |  |  |     OSSL_PARAM_int(OSSL_PKEY_PARAM_BITS, NULL), | 
					
						
							|  |  |  |     OSSL_PARAM_int(OSSL_PKEY_PARAM_SECURITY_BITS, NULL), | 
					
						
							|  |  |  |     OSSL_PARAM_int(OSSL_PKEY_PARAM_MAX_SIZE, NULL), | 
					
						
							|  |  |  |     OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_DEFAULT_DIGEST, NULL, 0), | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  |     DSA_IMEXPORTABLE_PARAMETERS, | 
					
						
							|  |  |  |     DSA_IMEXPORTABLE_PUBLIC_KEY, | 
					
						
							|  |  |  |     DSA_IMEXPORTABLE_PRIVATE_KEY, | 
					
						
							| 
									
										
										
										
											2020-02-05 00:49:28 +08:00
										 |  |  |     OSSL_PARAM_END | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const OSSL_PARAM *dsa_gettable_params(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     return dsa_params; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-01-21 13:57:25 +08:00
										 |  |  | static int dsa_validate_domparams(DSA *dsa) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int status = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return dsa_check_params(dsa, &status); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int dsa_validate_public(DSA *dsa) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int status = 0; | 
					
						
							|  |  |  |     const BIGNUM *pub_key = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     DSA_get0_key(dsa, &pub_key, NULL); | 
					
						
							| 
									
										
										
										
											2020-04-22 03:13:16 +08:00
										 |  |  |     if (pub_key == NULL) | 
					
						
							|  |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2020-01-21 13:57:25 +08:00
										 |  |  |     return dsa_check_pub_key(dsa, pub_key, &status); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int dsa_validate_private(DSA *dsa) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     int status = 0; | 
					
						
							|  |  |  |     const BIGNUM *priv_key = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     DSA_get0_key(dsa, NULL, &priv_key); | 
					
						
							| 
									
										
										
										
											2020-04-22 03:13:16 +08:00
										 |  |  |     if (priv_key == NULL) | 
					
						
							|  |  |  |         return 0; | 
					
						
							| 
									
										
										
										
											2020-01-21 13:57:25 +08:00
										 |  |  |     return dsa_check_priv_key(dsa, priv_key, &status); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int dsa_validate(void *keydata, int selection) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DSA *dsa = keydata; | 
					
						
							|  |  |  |     int ok = 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((selection & DSA_POSSIBLE_SELECTIONS) != 0) | 
					
						
							|  |  |  |         ok = 1; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) | 
					
						
							|  |  |  |         ok = ok && dsa_validate_domparams(dsa); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((selection & OSSL_KEYMGMT_SELECT_PUBLIC_KEY) != 0) | 
					
						
							|  |  |  |         ok = ok && dsa_validate_public(dsa); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((selection & OSSL_KEYMGMT_SELECT_PRIVATE_KEY) != 0) | 
					
						
							|  |  |  |         ok = ok && dsa_validate_private(dsa); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     /* If the whole key is selected, we do a pairwise validation */ | 
					
						
							|  |  |  |     if ((selection & OSSL_KEYMGMT_SELECT_KEYPAIR) | 
					
						
							|  |  |  |         == OSSL_KEYMGMT_SELECT_KEYPAIR) | 
					
						
							|  |  |  |         ok = ok && dsa_check_pairwise(dsa); | 
					
						
							|  |  |  |     return ok; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  | static void *dsa_gen_init(void *provctx, int selection) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     OPENSSL_CTX *libctx = PROV_LIBRARY_CONTEXT_OF(provctx); | 
					
						
							|  |  |  |     struct dsa_gen_ctx *gctx = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((selection & DSA_POSSIBLE_SELECTIONS) == 0) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((gctx = OPENSSL_zalloc(sizeof(*gctx))) != NULL) { | 
					
						
							|  |  |  |         gctx->selection = selection; | 
					
						
							|  |  |  |         gctx->libctx = libctx; | 
					
						
							|  |  |  |         gctx->pbits = 2048; | 
					
						
							|  |  |  |         gctx->qbits = 224; | 
					
						
							|  |  |  |         gctx->gen_type = DSA_PARAMGEN_TYPE_FIPS_186_4; | 
					
						
							|  |  |  |         gctx->gindex = -1; | 
					
						
							|  |  |  |         gctx->pcounter = -1; | 
					
						
							|  |  |  |         gctx->hindex = 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return gctx; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int dsa_gen_set_template(void *genctx, void *templ) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     struct dsa_gen_ctx *gctx = genctx; | 
					
						
							|  |  |  |     DSA *dsa = templ; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (gctx == NULL || dsa == NULL) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     gctx->ffc_params = dsa_get0_params(dsa); | 
					
						
							|  |  |  |     return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int dsa_set_gen_seed(struct dsa_gen_ctx *gctx, unsigned char *seed, | 
					
						
							|  |  |  |                             size_t seedlen) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     OPENSSL_clear_free(gctx->seed, gctx->seedlen); | 
					
						
							|  |  |  |     gctx->seed = NULL; | 
					
						
							|  |  |  |     gctx->seedlen = 0; | 
					
						
							|  |  |  |     if (seed != NULL && seedlen > 0) { | 
					
						
							|  |  |  |         gctx->seed = OPENSSL_memdup(seed, seedlen); | 
					
						
							|  |  |  |         if (gctx->seed == NULL) | 
					
						
							|  |  |  |             return 0; | 
					
						
							|  |  |  |         gctx->seedlen = seedlen; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int dsa_gen_set_params(void *genctx, const OSSL_PARAM params[]) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     struct dsa_gen_ctx *gctx = genctx; | 
					
						
							|  |  |  |     const OSSL_PARAM *p; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (gctx == NULL) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_TYPE); | 
					
						
							|  |  |  |     if (p != NULL) { | 
					
						
							|  |  |  |         if (p->data_type != OSSL_PARAM_UTF8_STRING | 
					
						
							|  |  |  |             || ((gctx->gen_type = dsa_gen_type_name2id(p->data)) == -1)) { | 
					
						
							|  |  |  |             ERR_raise(ERR_LIB_PROV, ERR_R_PASSED_INVALID_ARGUMENT); | 
					
						
							|  |  |  |             return 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_GINDEX); | 
					
						
							|  |  |  |     if (p != NULL | 
					
						
							|  |  |  |         && !OSSL_PARAM_get_int(p, &gctx->gindex)) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_PCOUNTER); | 
					
						
							|  |  |  |     if (p != NULL | 
					
						
							|  |  |  |         && !OSSL_PARAM_get_int(p, &gctx->pcounter)) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_H); | 
					
						
							|  |  |  |     if (p != NULL | 
					
						
							|  |  |  |         && !OSSL_PARAM_get_int(p, &gctx->hindex)) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_SEED); | 
					
						
							|  |  |  |     if (p != NULL | 
					
						
							|  |  |  |         && (p->data_type != OSSL_PARAM_OCTET_STRING | 
					
						
							|  |  |  |             || !dsa_set_gen_seed(gctx, p->data, p->data_size))) | 
					
						
							|  |  |  |             return 0; | 
					
						
							|  |  |  |     if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_PBITS)) != NULL | 
					
						
							|  |  |  |         && !OSSL_PARAM_get_size_t(p, &gctx->pbits)) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     if ((p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_QBITS)) != NULL | 
					
						
							|  |  |  |         && !OSSL_PARAM_get_size_t(p, &gctx->qbits)) | 
					
						
							|  |  |  |         return 0; | 
					
						
							|  |  |  |     p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_DIGEST); | 
					
						
							|  |  |  |     if (p != NULL) { | 
					
						
							|  |  |  |         if (p->data_type != OSSL_PARAM_UTF8_STRING) | 
					
						
							|  |  |  |             return 0; | 
					
						
							| 
									
										
										
										
											2020-06-17 09:33:16 +08:00
										 |  |  |         gctx->mdname = p->data; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     p = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_FFC_DIGEST_PROPS); | 
					
						
							|  |  |  |     if (p != NULL) { | 
					
						
							|  |  |  |         if (p->data_type != OSSL_PARAM_UTF8_STRING) | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  |             return 0; | 
					
						
							| 
									
										
										
										
											2020-06-17 09:33:16 +08:00
										 |  |  |         gctx->mdprops = p->data; | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  |     } | 
					
						
							|  |  |  |     return 1; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static const OSSL_PARAM *dsa_gen_settable_params(void *provctx) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     static OSSL_PARAM settable[] = { | 
					
						
							|  |  |  |         OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_FFC_TYPE, NULL, 0), | 
					
						
							|  |  |  |         OSSL_PARAM_size_t(OSSL_PKEY_PARAM_FFC_PBITS, NULL), | 
					
						
							|  |  |  |         OSSL_PARAM_size_t(OSSL_PKEY_PARAM_FFC_QBITS, NULL), | 
					
						
							|  |  |  |         OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_FFC_DIGEST, NULL, 0), | 
					
						
							|  |  |  |         OSSL_PARAM_utf8_string(OSSL_PKEY_PARAM_FFC_DIGEST_PROPS, NULL, 0), | 
					
						
							|  |  |  |         OSSL_PARAM_int(OSSL_PKEY_PARAM_FFC_GINDEX, NULL), | 
					
						
							|  |  |  |         OSSL_PARAM_octet_string(OSSL_PKEY_PARAM_FFC_SEED, NULL, 0), | 
					
						
							|  |  |  |         OSSL_PARAM_int(OSSL_PKEY_PARAM_FFC_PCOUNTER, NULL), | 
					
						
							|  |  |  |         OSSL_PARAM_int(OSSL_PKEY_PARAM_FFC_H, NULL), | 
					
						
							|  |  |  |         OSSL_PARAM_END | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  |     return settable; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static int dsa_gencb(int p, int n, BN_GENCB *cb) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     struct dsa_gen_ctx *gctx = BN_GENCB_get_arg(cb); | 
					
						
							|  |  |  |     OSSL_PARAM params[] = { OSSL_PARAM_END, OSSL_PARAM_END, OSSL_PARAM_END }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     params[0] = OSSL_PARAM_construct_int(OSSL_GEN_PARAM_POTENTIAL, &p); | 
					
						
							|  |  |  |     params[1] = OSSL_PARAM_construct_int(OSSL_GEN_PARAM_ITERATION, &n); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return gctx->cb(params, gctx->cbarg); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void *dsa_gen(void *genctx, OSSL_CALLBACK *osslcb, void *cbarg) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     struct dsa_gen_ctx *gctx = genctx; | 
					
						
							|  |  |  |     DSA *dsa = NULL; | 
					
						
							|  |  |  |     BN_GENCB *gencb = NULL; | 
					
						
							|  |  |  |     int ret = 0; | 
					
						
							|  |  |  |     FFC_PARAMS *ffc; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (gctx == NULL) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  |     dsa = dsa_new_with_ctx(gctx->libctx); | 
					
						
							|  |  |  |     if (dsa == NULL) | 
					
						
							|  |  |  |         return NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     gctx->cb = osslcb; | 
					
						
							|  |  |  |     gctx->cbarg = cbarg; | 
					
						
							|  |  |  |     gencb = BN_GENCB_new(); | 
					
						
							|  |  |  |     if (gencb != NULL) | 
					
						
							|  |  |  |         BN_GENCB_set(gencb, dsa_gencb, genctx); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     ffc = dsa_get0_params(dsa); | 
					
						
							|  |  |  |     /* Copy the template value if one was passed */ | 
					
						
							|  |  |  |     if (gctx->ffc_params != NULL | 
					
						
							|  |  |  |         && !ffc_params_copy(ffc, gctx->ffc_params)) | 
					
						
							|  |  |  |         goto end; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (gctx->seed != NULL | 
					
						
							|  |  |  |         && !ffc_params_set_seed(ffc, gctx->seed, gctx->seedlen)) | 
					
						
							|  |  |  |         goto end; | 
					
						
							|  |  |  |     if (gctx->gindex != -1) { | 
					
						
							|  |  |  |         ffc_params_set_gindex(ffc, gctx->gindex); | 
					
						
							|  |  |  |         if (gctx->pcounter != -1) | 
					
						
							|  |  |  |             ffc_params_set_pcounter(ffc, gctx->pcounter); | 
					
						
							|  |  |  |     } else if (gctx->hindex != 0) { | 
					
						
							|  |  |  |         ffc_params_set_h(ffc, gctx->hindex); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-06-17 09:33:16 +08:00
										 |  |  |     if (gctx->mdname != NULL) { | 
					
						
							|  |  |  |         if (!ffc_set_digest(ffc, gctx->mdname, gctx->mdprops)) | 
					
						
							|  |  |  |             goto end; | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  |     if ((gctx->selection & OSSL_KEYMGMT_SELECT_DOMAIN_PARAMETERS) != 0) { | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |          if (dsa_generate_ffc_parameters(dsa, gctx->gen_type, | 
					
						
							| 
									
										
										
										
											2020-06-17 09:33:16 +08:00
										 |  |  |                                          gctx->pbits, gctx->qbits, | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  |                                          gencb) <= 0) | 
					
						
							|  |  |  |              goto end; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     if ((gctx->selection & OSSL_KEYMGMT_SELECT_KEYPAIR) != 0) { | 
					
						
							|  |  |  |         if (ffc->p == NULL | 
					
						
							|  |  |  |             || ffc->q == NULL | 
					
						
							|  |  |  |             || ffc->g == NULL) | 
					
						
							|  |  |  |             goto end; | 
					
						
							|  |  |  |         if (DSA_generate_key(dsa) <= 0) | 
					
						
							|  |  |  |             goto end; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     ret = 1; | 
					
						
							|  |  |  | end: | 
					
						
							|  |  |  |     if (ret <= 0) { | 
					
						
							|  |  |  |         DSA_free(dsa); | 
					
						
							|  |  |  |         dsa = NULL; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     BN_GENCB_free(gencb); | 
					
						
							|  |  |  |     return dsa; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static void dsa_gen_cleanup(void *genctx) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     struct dsa_gen_ctx *gctx = genctx; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (gctx == NULL) | 
					
						
							|  |  |  |         return; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     OPENSSL_clear_free(gctx->seed, gctx->seedlen); | 
					
						
							|  |  |  |     OPENSSL_free(gctx); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-07-28 00:40:05 +08:00
										 |  |  | void *dsa_load(const void *reference, size_t reference_sz) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DSA *dsa = NULL; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (reference_sz == sizeof(dsa)) { | 
					
						
							|  |  |  |         /* The contents of the reference is the address to our object */ | 
					
						
							|  |  |  |         dsa = *(DSA **)reference; | 
					
						
							|  |  |  |         /* We grabbed, so we detach it */ | 
					
						
							|  |  |  |         *(DSA **)reference = NULL; | 
					
						
							|  |  |  |         return dsa; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     return NULL; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-30 20:33:37 +08:00
										 |  |  | const OSSL_DISPATCH dsa_keymgmt_functions[] = { | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  |     { OSSL_FUNC_KEYMGMT_NEW, (void (*)(void))dsa_newdata }, | 
					
						
							| 
									
										
										
										
											2020-04-15 19:02:52 +08:00
										 |  |  |     { OSSL_FUNC_KEYMGMT_GEN_INIT, (void (*)(void))dsa_gen_init }, | 
					
						
							|  |  |  |     { OSSL_FUNC_KEYMGMT_GEN_SET_TEMPLATE, (void (*)(void))dsa_gen_set_template }, | 
					
						
							|  |  |  |     { OSSL_FUNC_KEYMGMT_GEN_SET_PARAMS, (void (*)(void))dsa_gen_set_params }, | 
					
						
							|  |  |  |     { OSSL_FUNC_KEYMGMT_GEN_SETTABLE_PARAMS, | 
					
						
							|  |  |  |       (void (*)(void))dsa_gen_settable_params }, | 
					
						
							|  |  |  |     { OSSL_FUNC_KEYMGMT_GEN, (void (*)(void))dsa_gen }, | 
					
						
							|  |  |  |     { OSSL_FUNC_KEYMGMT_GEN_CLEANUP, (void (*)(void))dsa_gen_cleanup }, | 
					
						
							| 
									
										
										
										
											2020-07-28 00:40:05 +08:00
										 |  |  |     { OSSL_FUNC_KEYMGMT_LOAD, (void (*)(void))dsa_load }, | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  |     { OSSL_FUNC_KEYMGMT_FREE, (void (*)(void))dsa_freedata }, | 
					
						
							| 
									
										
										
										
											2020-02-05 00:49:28 +08:00
										 |  |  |     { OSSL_FUNC_KEYMGMT_GET_PARAMS, (void (*) (void))dsa_get_params }, | 
					
						
							|  |  |  |     { OSSL_FUNC_KEYMGMT_GETTABLE_PARAMS, (void (*) (void))dsa_gettable_params }, | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  |     { OSSL_FUNC_KEYMGMT_HAS, (void (*)(void))dsa_has }, | 
					
						
							| 
									
										
										
										
											2020-02-06 16:53:15 +08:00
										 |  |  |     { OSSL_FUNC_KEYMGMT_MATCH, (void (*)(void))dsa_match }, | 
					
						
							| 
									
										
										
										
											2020-01-21 13:57:25 +08:00
										 |  |  |     { OSSL_FUNC_KEYMGMT_VALIDATE, (void (*)(void))dsa_validate }, | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  |     { OSSL_FUNC_KEYMGMT_IMPORT, (void (*)(void))dsa_import }, | 
					
						
							| 
									
										
										
										
											2020-02-05 00:49:28 +08:00
										 |  |  |     { OSSL_FUNC_KEYMGMT_IMPORT_TYPES, (void (*)(void))dsa_import_types }, | 
					
						
							| 
									
										
										
										
											2020-02-03 19:00:53 +08:00
										 |  |  |     { OSSL_FUNC_KEYMGMT_EXPORT, (void (*)(void))dsa_export }, | 
					
						
							| 
									
										
										
										
											2020-02-05 00:49:28 +08:00
										 |  |  |     { OSSL_FUNC_KEYMGMT_EXPORT_TYPES, (void (*)(void))dsa_export_types }, | 
					
						
							| 
									
										
										
										
											2019-08-30 20:33:37 +08:00
										 |  |  |     { 0, NULL } | 
					
						
							|  |  |  | }; |