2016-05-18 02:51:26 +08:00
|
|
|
/*
|
2021-03-11 21:27:36 +08:00
|
|
|
* Copyright 1995-2021 The OpenSSL Project Authors. All Rights Reserved.
|
2015-01-22 11:40:55 +08:00
|
|
|
*
|
2018-12-06 20:36:26 +08:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-18 02:51:26 +08:00
|
|
|
* 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
|
1998-12-21 18:52:47 +08:00
|
|
|
*/
|
|
|
|
|
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"
|
|
|
|
|
2016-03-19 02:30:20 +08:00
|
|
|
#include <openssl/opensslconf.h>
|
2015-01-28 01:34:45 +08:00
|
|
|
#include <stdio.h>
|
2015-05-14 22:56:48 +08:00
|
|
|
#include "internal/cryptlib.h"
|
2015-01-28 01:34:45 +08:00
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/bn.h>
|
|
|
|
#include <openssl/rand.h>
|
|
|
|
#include <openssl/sha.h>
|
2020-02-06 20:28:36 +08:00
|
|
|
#include "crypto/dsa.h"
|
2019-09-28 06:45:40 +08:00
|
|
|
#include "dsa_local.h"
|
2003-01-15 10:01:55 +08:00
|
|
|
|
Fix external symbols related to dsa keys
Partial fix for #12964
This adds ossl_ names for the following symbols:
dsa_check_pairwise, dsa_check_params, dsa_check_priv_key, dsa_check_pub_key, dsa_check_pub_key_partial,
dsa_do_sign_int, dsa_ffc_params_fromdata,
dsa_generate_ffc_parameters, dsa_generate_public_key,
dsa_get0_params, dsa_key_fromdata, dsa_new_with_ctx, dsa_pkey_method, dsa_sign_int
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14231)
2021-02-18 14:30:37 +08:00
|
|
|
int ossl_dsa_generate_ffc_parameters(DSA *dsa, int type, int pbits, int qbits,
|
|
|
|
BN_GENCB *cb)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2020-02-06 20:28:36 +08:00
|
|
|
int ret = 0, res;
|
2015-01-22 11:40:55 +08:00
|
|
|
|
2020-04-14 04:34:56 +08:00
|
|
|
#ifndef FIPS_MODULE
|
2020-02-06 20:28:36 +08:00
|
|
|
if (type == DSA_PARAMGEN_TYPE_FIPS_186_2)
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
ret = ossl_ffc_params_FIPS186_2_generate(dsa->libctx, &dsa->params,
|
|
|
|
FFC_PARAM_TYPE_DSA,
|
|
|
|
pbits, qbits, &res, cb);
|
2020-02-06 20:28:36 +08:00
|
|
|
else
|
|
|
|
#endif
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
ret = ossl_ffc_params_FIPS186_4_generate(dsa->libctx, &dsa->params,
|
|
|
|
FFC_PARAM_TYPE_DSA,
|
|
|
|
pbits, qbits, &res, cb);
|
2020-02-06 20:28:36 +08:00
|
|
|
if (ret > 0)
|
|
|
|
dsa->dirty_cnt++;
|
|
|
|
return ret;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2003-01-15 10:01:55 +08:00
|
|
|
|
2020-04-14 04:34:56 +08:00
|
|
|
#ifndef FIPS_MODULE
|
2020-02-16 11:03:46 +08:00
|
|
|
int DSA_generate_parameters_ex(DSA *dsa, int bits,
|
|
|
|
const unsigned char *seed_in, int seed_len,
|
|
|
|
int *counter_ret, unsigned long *h_ret,
|
|
|
|
BN_GENCB *cb)
|
2015-01-22 11:40:55 +08:00
|
|
|
{
|
2020-02-06 20:28:36 +08:00
|
|
|
if (dsa->meth->dsa_paramgen)
|
|
|
|
return dsa->meth->dsa_paramgen(dsa, bits, seed_in, seed_len,
|
|
|
|
counter_ret, h_ret, cb);
|
|
|
|
if (seed_in != NULL
|
ffc: add _ossl to exported but internal functions
The functions updated are:
ffc_generate_private_key, ffc_named_group_from_uid,
ffc_named_group_to_uid, ffc_params_FIPS186_2_gen_verify,
ffc_params_FIPS186_2_generate, ffc_params_FIPS186_2_validate,
ffc_params_FIPS186_4_gen_verify, ffc_params_FIPS186_4_generate,
ffc_params_FIPS186_4_validate, ffc_params_cleanup, ffc_params_cmp,
ffc_params_copy, ffc_params_enable_flags, ffc_params_flags_from_name,
ffc_params_flags_to_name, ffc_params_fromdata,
ffc_params_get0_pqg, ffc_params_get_validate_params,
ffc_params_init, ffc_params_print, ffc_params_set0_j,
ffc_params_set0_pqg, ffc_params_set_flags, ffc_params_set_gindex,
ffc_params_set_h, ffc_params_set_pcounter, ffc_params_set_seed,
ffc_params_set_validate_params, ffc_params_simple_validate,
ffc_params_todata, ffc_params_validate_unverifiable_g, ffc_set_digest,
ffc_set_group_pqg, ffc_validate_private_key, ffc_validate_public_key
and ffc_validate_public_key_partial.
Reviewed-by: Matt Caswell <matt@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/13041)
2020-09-30 13:07:24 +08:00
|
|
|
&& !ossl_ffc_params_set_validate_params(&dsa->params, seed_in, seed_len,
|
|
|
|
-1))
|
2015-01-22 11:40:55 +08:00
|
|
|
return 0;
|
|
|
|
|
2020-02-06 20:28:36 +08:00
|
|
|
/* The old code used FIPS 186-2 DSA Parameter generation */
|
2021-03-30 19:23:12 +08:00
|
|
|
if (bits < 2048 && seed_len <= 20) {
|
Fix external symbols related to dsa keys
Partial fix for #12964
This adds ossl_ names for the following symbols:
dsa_check_pairwise, dsa_check_params, dsa_check_priv_key, dsa_check_pub_key, dsa_check_pub_key_partial,
dsa_do_sign_int, dsa_ffc_params_fromdata,
dsa_generate_ffc_parameters, dsa_generate_public_key,
dsa_get0_params, dsa_key_fromdata, dsa_new_with_ctx, dsa_pkey_method, dsa_sign_int
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14231)
2021-02-18 14:30:37 +08:00
|
|
|
if (!ossl_dsa_generate_ffc_parameters(dsa, DSA_PARAMGEN_TYPE_FIPS_186_2,
|
|
|
|
bits, 160, cb))
|
2020-02-06 20:28:36 +08:00
|
|
|
return 0;
|
2020-06-17 09:33:16 +08:00
|
|
|
} else {
|
Fix external symbols related to dsa keys
Partial fix for #12964
This adds ossl_ names for the following symbols:
dsa_check_pairwise, dsa_check_params, dsa_check_priv_key, dsa_check_pub_key, dsa_check_pub_key_partial,
dsa_do_sign_int, dsa_ffc_params_fromdata,
dsa_generate_ffc_parameters, dsa_generate_public_key,
dsa_get0_params, dsa_key_fromdata, dsa_new_with_ctx, dsa_pkey_method, dsa_sign_int
Reviewed-by: Paul Dale <pauli@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/14231)
2021-02-18 14:30:37 +08:00
|
|
|
if (!ossl_dsa_generate_ffc_parameters(dsa, DSA_PARAMGEN_TYPE_FIPS_186_4,
|
|
|
|
bits, 0, cb))
|
2015-08-08 10:14:47 +08:00
|
|
|
return 0;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
|
|
|
|
2020-02-06 20:28:36 +08:00
|
|
|
if (counter_ret != NULL)
|
|
|
|
*counter_ret = dsa->params.pcounter;
|
|
|
|
if (h_ret != NULL)
|
|
|
|
*h_ret = dsa->params.h;
|
|
|
|
return 1;
|
2015-01-22 11:40:55 +08:00
|
|
|
}
|
2020-04-15 19:02:52 +08:00
|
|
|
#endif
|