Skip to main content
  • Home
  • login
  • Browse the archive

    swh mirror partner logo
swh logo
SoftwareHeritage
Software
Heritage
Mirror
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • 2eddee9
  • /
  • crypto
  • /
  • dsa
  • /
  • dsa_gen.c
Raw File
Permalinks

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge Iframe embedding
swh:1:cnt:7b72867f71979143cd0796f4fb917cf7667e1be8
directory badge Iframe embedding
swh:1:dir:c9b256933fb85e922fe14045fe5c2f8b9f95edcd
dsa_gen.c
/*
 * Copyright 1995-2020 The OpenSSL Project Authors. All Rights Reserved.
 *
 * 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
 */

/*
 * DSA low level APIs are deprecated for public use, but still ok for
 * internal use.
 */
#include "internal/deprecated.h"

#include <openssl/opensslconf.h>
#include <stdio.h>
#include "internal/cryptlib.h"
#include <openssl/evp.h>
#include <openssl/bn.h>
#include <openssl/rand.h>
#include <openssl/sha.h>
#include "crypto/dsa.h"
#include "dsa_local.h"

int dsa_generate_ffc_parameters(DSA *dsa, int type,
                                int pbits, int qbits,
                                EVP_MD *md, BN_GENCB *cb)
{
    int ret = 0, res;

    if (qbits <= 0) {
        if (md != NULL)
            qbits = EVP_MD_size(md) * 8;
        else
            qbits = (pbits >= 2048 ? SHA256_DIGEST_LENGTH :
                                     SHA_DIGEST_LENGTH) * 8;
    }
#ifndef FIPS_MODE
    if (type == DSA_PARAMGEN_TYPE_FIPS_186_2)
        ret = ffc_params_FIPS186_2_generate(dsa->libctx, &dsa->params,
                                            FFC_PARAM_TYPE_DSA,
                                            pbits, qbits, md, &res, cb);
    else
#endif
        ret = ffc_params_FIPS186_4_generate(dsa->libctx, &dsa->params,
                                            FFC_PARAM_TYPE_DSA,
                                            pbits, qbits, md, &res, cb);
    if (ret > 0)
        dsa->dirty_cnt++;
    return ret;
}

#ifndef FIPS_MODE
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)
{
#ifndef FIPS_MODE
    if (dsa->meth->dsa_paramgen)
        return dsa->meth->dsa_paramgen(dsa, bits, seed_in, seed_len,
                                       counter_ret, h_ret, cb);
#endif
    if (seed_in != NULL
        && !ffc_params_set_validate_params(&dsa->params, seed_in, seed_len, -1))
        return 0;

#ifndef FIPS_MODE
    /* The old code used FIPS 186-2 DSA Parameter generation */
    if (bits <= 1024 && seed_len == 20) {
        if (!dsa_generate_ffc_parameters(dsa, DSA_PARAMGEN_TYPE_FIPS_186_2,
                                         bits, 160, NULL, cb))
            return 0;
    } else
#endif
    {
        if (!dsa_generate_ffc_parameters(dsa, DSA_PARAMGEN_TYPE_FIPS_186_4,
                                         bits, -1, NULL, cb))
            return 0;
    }

    if (counter_ret != NULL)
        *counter_ret = dsa->params.pcounter;
    if (h_ret != NULL)
        *h_ret = dsa->params.h;
    return 1;
}
#endif

ENEA — Copyright (C), ENEA. License: GNU AGPLv3+.
Legal notes  ::  JavaScript license information ::  Web API

back to top