2016-05-17 14:51:26 -04:00
|
|
|
/*
|
2020-02-06 22:28:36 +10:00
|
|
|
* Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
|
2015-01-22 03:40:55 +00:00
|
|
|
*
|
2018-12-06 13:36:26 +01:00
|
|
|
* Licensed under the Apache License 2.0 (the "License"). You may not use
|
2016-05-17 14:51:26 -04: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 10:52:47 +00:00
|
|
|
*/
|
|
|
|
|
2020-01-30 07:23:39 +10:00
|
|
|
/*
|
|
|
|
* DSA low level APIs are deprecated for public use, but still ok for
|
|
|
|
* internal use.
|
|
|
|
*/
|
|
|
|
#include "internal/deprecated.h"
|
|
|
|
|
2016-03-18 14:30:20 -04:00
|
|
|
#include <openssl/opensslconf.h>
|
2015-01-27 12:34:45 -05:00
|
|
|
#include <stdio.h>
|
2015-05-14 16:56:48 +02:00
|
|
|
#include "internal/cryptlib.h"
|
2015-01-27 12:34:45 -05:00
|
|
|
#include <openssl/evp.h>
|
|
|
|
#include <openssl/bn.h>
|
|
|
|
#include <openssl/rand.h>
|
|
|
|
#include <openssl/sha.h>
|
2020-02-06 22:28:36 +10:00
|
|
|
#include "crypto/dsa.h"
|
2019-09-28 00:45:40 +02:00
|
|
|
#include "dsa_local.h"
|
2003-01-15 02:01:55 +00:00
|
|
|
|
2020-06-17 11:33:16 +10:00
|
|
|
int dsa_generate_ffc_parameters(DSA *dsa, int type, int pbits, int qbits,
|
|
|
|
BN_GENCB *cb)
|
2015-01-22 03:40:55 +00:00
|
|
|
{
|
2020-02-06 22:28:36 +10:00
|
|
|
int ret = 0, res;
|
2015-01-22 03:40:55 +00:00
|
|
|
|
2020-04-13 22:34:56 +02:00
|
|
|
#ifndef FIPS_MODULE
|
2020-02-06 22:28:36 +10:00
|
|
|
if (type == DSA_PARAMGEN_TYPE_FIPS_186_2)
|
2020-02-16 13:03:46 +10:00
|
|
|
ret = ffc_params_FIPS186_2_generate(dsa->libctx, &dsa->params,
|
2020-02-06 22:28:36 +10:00
|
|
|
FFC_PARAM_TYPE_DSA,
|
2020-06-17 11:33:16 +10:00
|
|
|
pbits, qbits, &res, cb);
|
2020-02-06 22:28:36 +10:00
|
|
|
else
|
|
|
|
#endif
|
2020-02-16 13:03:46 +10:00
|
|
|
ret = ffc_params_FIPS186_4_generate(dsa->libctx, &dsa->params,
|
2020-02-06 22:28:36 +10:00
|
|
|
FFC_PARAM_TYPE_DSA,
|
2020-06-17 11:33:16 +10:00
|
|
|
pbits, qbits, &res, cb);
|
2020-02-06 22:28:36 +10:00
|
|
|
if (ret > 0)
|
|
|
|
dsa->dirty_cnt++;
|
|
|
|
return ret;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2003-01-15 02:01:55 +00:00
|
|
|
|
2020-04-13 22:34:56 +02:00
|
|
|
#ifndef FIPS_MODULE
|
2020-02-16 13:03:46 +10: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 03:40:55 +00:00
|
|
|
{
|
2020-02-06 22:28:36 +10: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_params_set_validate_params(&dsa->params, seed_in, seed_len, -1))
|
2015-01-22 03:40:55 +00:00
|
|
|
return 0;
|
|
|
|
|
2020-02-06 22:28:36 +10:00
|
|
|
/* The old code used FIPS 186-2 DSA Parameter generation */
|
|
|
|
if (bits <= 1024 && seed_len == 20) {
|
2020-02-16 13:03:46 +10:00
|
|
|
if (!dsa_generate_ffc_parameters(dsa, DSA_PARAMGEN_TYPE_FIPS_186_2,
|
2020-06-17 11:33:16 +10:00
|
|
|
bits, 160, cb))
|
2020-02-06 22:28:36 +10:00
|
|
|
return 0;
|
2020-06-17 11:33:16 +10:00
|
|
|
} else {
|
2020-02-16 13:03:46 +10:00
|
|
|
if (!dsa_generate_ffc_parameters(dsa, DSA_PARAMGEN_TYPE_FIPS_186_4,
|
2020-06-23 12:30:40 +10:00
|
|
|
bits, 0, cb))
|
2015-08-07 22:14:47 -04:00
|
|
|
return 0;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
|
|
|
|
2020-02-06 22:28:36 +10:00
|
|
|
if (counter_ret != NULL)
|
|
|
|
*counter_ret = dsa->params.pcounter;
|
|
|
|
if (h_ret != NULL)
|
|
|
|
*h_ret = dsa->params.h;
|
|
|
|
return 1;
|
2015-01-22 03:40:55 +00:00
|
|
|
}
|
2020-04-15 21:02:52 +10:00
|
|
|
#endif
|