Latest update.

This commit is contained in:
2020-04-25 19:56:17 +09:00
parent 2015c00c43
commit 80ef640063
5977 changed files with 13451 additions and 5979 deletions
+5 -2
View File
@@ -1,9 +1,12 @@
LIBS=../../libcrypto
$COMMON=dh_lib.c dh_key.c dh_group_params.c dh_check.c dh_backend.c
$COMMON=dh_lib.c dh_key.c dh_group_params.c dh_check.c dh_backend.c dh_gen.c
SOURCE[../../libcrypto]=$COMMON\
dh_asn1.c dh_gen.c dh_err.c dh_depr.c \
dh_asn1.c dh_err.c \
dh_ameth.c dh_pmeth.c dh_prn.c dh_rfc5114.c dh_kdf.c dh_meth.c
IF[{- !$disabled{'deprecated-0.9.8'} -}]
SOURCE[../../libcrypto]=dh_depr.c
ENDIF
SOURCE[../../providers/libfips.a]=$COMMON
+7 -6
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2016 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 2006-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
@@ -24,7 +24,7 @@
#include "crypto/evp.h"
#include <openssl/cms.h>
#include <openssl/core_names.h>
#include "openssl/param_build.h"
#include <openssl/param_build.h>
#include "internal/ffc.h"
/*
@@ -548,17 +548,18 @@ err:
return rv;
}
static int dh_pkey_import_from(const OSSL_PARAM params[], void *key)
static int dh_pkey_import_from(const OSSL_PARAM params[], void *vpctx)
{
EVP_PKEY *pkey = key;
DH *dh = DH_new();
EVP_PKEY_CTX *pctx = vpctx;
EVP_PKEY *pkey = EVP_PKEY_CTX_get0_pkey(pctx);
DH *dh = dh_new_with_libctx(pctx->libctx);
if (dh == NULL) {
ERR_raise(ERR_LIB_DH, ERR_R_MALLOC_FAILURE);
return 0;
}
if (!ffc_fromdata(dh_get0_params(dh), params)
if (!dh_ffc_params_fromdata(dh, params)
|| !dh_key_fromdata(dh, params)
|| !EVP_PKEY_assign_DH(pkey, dh)) {
DH_free(dh);
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 2000-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
+2 -4
View File
@@ -24,10 +24,8 @@ int dh_key_fromdata(DH *dh, const OSSL_PARAM params[])
if (dh == NULL)
return 0;
param_priv_key =
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY);
param_pub_key =
OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY);
param_priv_key = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PRIV_KEY);
param_pub_key = OSSL_PARAM_locate_const(params, OSSL_PKEY_PARAM_PUB_KEY);
/*
* DH documentation says that a public key must be present if a
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 1995-2019 The OpenSSL Project Authors. All Rights Reserved.
* 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
+5 -9
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 2002-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
@@ -16,14 +16,11 @@
#include "internal/deprecated.h"
#include <openssl/opensslconf.h>
#ifdef OPENSSL_NO_DEPRECATED_0_9_8
NON_EMPTY_TRANSLATION_UNIT
#else
# include <stdio.h>
# include "internal/cryptlib.h"
# include <openssl/bn.h>
# include <openssl/dh.h>
#include <stdio.h>
#include "internal/cryptlib.h"
#include <openssl/bn.h>
#include <openssl/dh.h>
DH *DH_generate_parameters(int prime_len, int generator,
void (*callback) (int, int, void *), void *cb_arg)
@@ -49,4 +46,3 @@ DH *DH_generate_parameters(int prime_len, int generator,
DH_free(ret);
return NULL;
}
#endif
+50 -26
View File
@@ -26,6 +26,7 @@
#include <stdio.h>
#include "internal/cryptlib.h"
#include <openssl/bn.h>
#include <openssl/sha.h>
#include "crypto/dh.h"
#include "dh_local.h"
@@ -34,47 +35,45 @@ static int dh_builtin_genparams(DH *ret, int prime_len, int generator,
BN_GENCB *cb);
#endif /* FIPS_MODE */
/*
* TODO(3.0): keygen should be able to use this method to do a FIPS186-4 style
* paramgen.
*/
int dh_generate_ffc_parameters(DH *dh, int bits,
int qbits, int gindex, BN_GENCB *cb)
int dh_generate_ffc_parameters(DH *dh, int type, int pbits,
int qbits, EVP_MD *md, BN_GENCB *cb)
{
int ret, res;
if (qbits <= 0) {
const EVP_MD *evpmd = bits >= 2048 ? EVP_sha256() : EVP_sha1();
qbits = EVP_MD_size(evpmd) * 8;
if (md != NULL)
qbits = EVP_MD_size(md) * 8;
else
qbits = (pbits >= 2048 ? SHA256_DIGEST_LENGTH :
SHA_DIGEST_LENGTH) * 8;
}
dh->params.gindex = gindex;
ret = ffc_params_FIPS186_4_generate(dh->libctx, &dh->params,
FFC_PARAM_TYPE_DH,
bits, qbits, NULL, &res, cb);
#ifndef FIPS_MODE
if (type == DH_PARAMGEN_TYPE_FIPS_186_2)
ret = ffc_params_FIPS186_2_generate(dh->libctx, &dh->params,
FFC_PARAM_TYPE_DH,
pbits, qbits, md, &res, cb);
else
#endif
ret = ffc_params_FIPS186_4_generate(dh->libctx, &dh->params,
FFC_PARAM_TYPE_DH,
pbits, qbits, md, &res, cb);
if (ret > 0)
dh->dirty_cnt++;
return ret;
}
int DH_generate_parameters_ex(DH *ret, int prime_len, int generator,
BN_GENCB *cb)
int dh_get_named_group_uid_from_size(int pbits)
{
#ifdef FIPS_MODE
/*
* Just choose an approved safe prime group.
* The alternative to this is to generate FIPS186-4 domain parameters i.e.
* return dh_generate_ffc_parameters(ret, prime_len, -1, -1, cb);
* return dh_generate_ffc_parameters(ret, prime_len, 0, NULL, cb);
* As the FIPS186-4 generated params are for backwards compatability,
* the safe prime group should be used as the default.
*/
DH *dh = NULL;
int ok = 0, nid;
int nid;
if (generator != 2)
return 0;
switch (prime_len) {
switch (pbits) {
case 2048:
nid = NID_ffdhe2048;
break;
@@ -92,15 +91,40 @@ int DH_generate_parameters_ex(DH *ret, int prime_len, int generator,
break;
/* unsupported prime_len */
default:
return 0;
return NID_undef;
}
dh = DH_new_by_nid(nid);
if (dh != NULL && ffc_params_copy(&ret->params, &dh->params)) {
return nid;
}
#ifdef FIPS_MODE
static int dh_gen_named_group(OPENSSL_CTX *libctx, DH *ret, int prime_len)
{
DH *dh;
int ok = 0;
int nid = dh_get_named_group_uid_from_size(prime_len);
if (nid == NID_undef)
return 0;
dh = dh_new_by_nid_with_libctx(libctx, nid);
if (dh != NULL
&& ffc_params_copy(&ret->params, &dh->params)) {
ok = 1;
ret->dirty_cnt++;
}
DH_free(dh);
return ok;
}
#endif /* FIPS_MODE */
int DH_generate_parameters_ex(DH *ret, int prime_len, int generator,
BN_GENCB *cb)
{
#ifdef FIPS_MODE
if (generator != 2)
return 0;
return dh_gen_named_group(ret->libctx, ret, prime_len);
#else
if (ret->meth->generate_params)
return ret->meth->generate_params(ret, prime_len, generator, cb);
+137 -75
View File
@@ -17,24 +17,43 @@
#include <stdio.h>
#include "internal/cryptlib.h"
#include "internal/ffc.h"
#include "dh_local.h"
#include <openssl/bn.h>
#include <openssl/objects.h>
#include "crypto/bn_dh.h"
#include "crypto/dh.h"
#include "crypto/security_bits.h"
#include "e_os.h" /* strcasecmp */
#define FFDHE(sz) { \
SN_ffdhe##sz, NID_ffdhe##sz, \
sz, \
&_bignum_ffdhe##sz##_p, &_bignum_ffdhe##sz##_q, &_bignum_const_2 \
}
#define FFDHE(sz) { NID_ffdhe##sz, sz, &_bignum_ffdhe##sz##_p }
#define MODP(sz) { NID_modp_##sz, sz, &_bignum_modp_##sz##_p }
#define MODP(sz) { \
SN_modp_##sz, NID_modp_##sz, \
sz, \
&_bignum_modp_##sz##_p, &_bignum_modp_##sz##_q, &_bignum_const_2 \
}
typedef struct safe_prime_group_st {
int nid;
#define RFC5114(name, uid, sz, tag) { \
name, uid, \
sz, \
&_bignum_dh##tag##_p, &_bignum_dh##tag##_q, &_bignum_dh##tag##_g \
}
typedef struct dh_named_group_st {
const char *name;
int uid;
int32_t nbits;
const BIGNUM *p;
} SP_GROUP;
const BIGNUM *q;
const BIGNUM *g;
} DH_NAMED_GROUP;
static const SP_GROUP sp_groups[] = {
static const DH_NAMED_GROUP dh_named_groups[] = {
FFDHE(2048),
FFDHE(3072),
FFDHE(4096),
@@ -48,105 +67,148 @@ static const SP_GROUP sp_groups[] = {
MODP(4096),
MODP(6144),
MODP(8192),
/*
* Additional dh named groups from RFC 5114 that have a different g.
* The uid can be any unique identifier.
*/
#ifndef FIPS_MODE
RFC5114("dh_1024_160", 1, 1024, 1024_160),
RFC5114("dh_2048_224", 2, 2048, 2048_224),
RFC5114("dh_2048_256", 3, 2048, 2048_256),
#endif
};
#ifndef FIPS_MODE
static DH *dh_new_by_nid_with_ctx(OPENSSL_CTX *libctx, int nid);
static DH *dh_param_init(OPENSSL_CTX *libctx, int nid, const BIGNUM *p,
int32_t nbits)
int ffc_named_group_to_uid(const char *name)
{
BIGNUM *q = NULL;
DH *dh = dh_new_with_ctx(libctx);
size_t i;
for (i = 0; i < OSSL_NELEM(dh_named_groups); ++i) {
if (strcasecmp(dh_named_groups[i].name, name) == 0)
return dh_named_groups[i].uid;
}
return NID_undef;
}
const char *ffc_named_group_from_uid(int uid)
{
size_t i;
for (i = 0; i < OSSL_NELEM(dh_named_groups); ++i) {
if (dh_named_groups[i].uid == uid)
return dh_named_groups[i].name;
}
return NULL;
}
static DH *dh_param_init(OPENSSL_CTX *libctx, int uid, const BIGNUM *p,
const BIGNUM *q, const BIGNUM *g)
{
DH *dh = dh_new_with_libctx(libctx);
if (dh == NULL)
return NULL;
q = BN_dup(p);
/* Set q = (p - 1) / 2 (p is known to be odd so just shift right ) */
if (q == NULL || !BN_rshift1(q, q)) {
BN_free(q);
DH_free(dh);
return NULL;
}
dh->params.nid = nid;
dh->params.nid = uid;
dh->params.p = (BIGNUM *)p;
dh->params.q = (BIGNUM *)q;
dh->params.g = (BIGNUM *)&_bignum_const_2;
/* Private key length = 2 * max_target_security_strength */
dh->length = nbits;
dh->params.g = (BIGNUM *)g;
dh->length = BN_num_bits(q);
dh->dirty_cnt++;
return dh;
}
static DH *dh_new_by_nid_with_ctx(OPENSSL_CTX *libctx, int nid)
static DH *dh_new_by_group_name(OPENSSL_CTX *libctx, const char *name)
{
int i;
for (i = 0; i < (int)OSSL_NELEM(sp_groups); ++i) {
if (sp_groups[i].nid == nid) {
int max_target_security_strength =
ifc_ffc_compute_security_bits(sp_groups[i].nbits);
if (name == NULL)
return NULL;
/*
* The last parameter specified here is
* 2 * max_target_security_strength.
* See SP800-56Ar3 Table(s) 25 & 26.
*/
return dh_param_init(libctx, nid, sp_groups[i].p,
2 * max_target_security_strength);
for (i = 0; i < (int)OSSL_NELEM(dh_named_groups); ++i) {
if (strcasecmp(dh_named_groups[i].name, name) == 0) {
return dh_param_init(libctx, dh_named_groups[i].uid,
dh_named_groups[i].p,
dh_named_groups[i].q,
dh_named_groups[i].g);
}
}
DHerr(0, DH_R_INVALID_PARAMETER_NID);
return NULL;
}
DH *dh_new_by_nid_with_libctx(OPENSSL_CTX *libctx, int nid)
{
const char *name = ffc_named_group_from_uid(nid);
return dh_new_by_group_name(libctx, name);
}
DH *DH_new_by_nid(int nid)
{
return dh_new_by_nid_with_ctx(NULL, nid);
return dh_new_by_nid_with_libctx(NULL, nid);
}
#endif
int DH_get_nid(DH *dh)
int ffc_set_group_pqg(FFC_PARAMS *ffc, const char *group_name)
{
int i;
BIGNUM *q = NULL;
int i, nid;
if (ffc == NULL)
return 0;
for (i = 0; i < (int)OSSL_NELEM(dh_named_groups); ++i) {
if (strcasecmp(dh_named_groups[i].name, group_name) == 0) {
ffc_params_set0_pqg(ffc,
(BIGNUM *)dh_named_groups[i].p,
(BIGNUM *)dh_named_groups[i].q,
(BIGNUM *)dh_named_groups[i].g);
/* flush the cached nid, The DH layer is responsible for caching */
ffc->nid = NID_undef;
return 1;
}
}
/* gets here on error or if the name was not found */
BN_free(q);
return 0;
}
void dh_cache_named_group(DH *dh)
{
int i;
if (dh == NULL)
return;
dh->params.nid = NID_undef; /* flush cached value */
/* Exit if p or g is not set */
if (dh->params.p == NULL
|| dh->params.g == NULL)
return;
for (i = 0; i < (int)OSSL_NELEM(dh_named_groups); ++i) {
/* Keep searching until a matching p and g is found */
if (BN_cmp(dh->params.p, dh_named_groups[i].p) == 0
&& BN_cmp(dh->params.g, dh_named_groups[i].g) == 0) {
/* Verify q is correct if it exists */
if (dh->params.q != NULL) {
if (BN_cmp(dh->params.q, dh_named_groups[i].q) != 0)
continue; /* ignore if q does not match */
} else {
dh->params.q = (BIGNUM *)dh_named_groups[i].q;
}
dh->params.nid = dh_named_groups[i].uid; /* cache the nid */
dh->length = BN_num_bits(dh->params.q);
dh->dirty_cnt++;
break;
}
}
}
int DH_get_nid(const DH *dh)
{
if (dh == NULL)
return NID_undef;
nid = dh->params.nid;
/* Just return if it is already cached */
if (nid != NID_undef)
return nid;
if (BN_get_word(dh->params.g) != 2)
return NID_undef;
for (i = 0; i < (int)OSSL_NELEM(sp_groups); ++i) {
/* If a matching p is found then we will break out of the loop */
if (!BN_cmp(dh->params.p, sp_groups[i].p)) {
/* Set q = (p - 1) / 2 (p is known to be odd so just shift right ) */
q = BN_dup(dh->params.p);
if (q == NULL || !BN_rshift1(q, q))
break; /* returns nid = NID_undef on failure */
/* Verify q is correct if it exists */
if (dh->params.q != NULL) {
if (BN_cmp(dh->params.q, q) != 0)
break; /* returns nid = NID_undef if q does not match */
} else {
/* assign the calculated q */
dh->params.q = q;
q = NULL; /* set to NULL so it is not freed */
}
dh->params.nid = sp_groups[i].nid; /* cache the nid */
dh->length = 2 * ifc_ffc_compute_security_bits(sp_groups[i].nbits);
dh->dirty_cnt++;
break;
}
}
BN_free(q);
return nid;
return dh->params.nid;
}
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2013-2019 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 2013-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
+14 -7
View File
@@ -18,6 +18,13 @@
#include "dh_local.h"
#include "crypto/bn.h"
#include "crypto/dh.h"
#include "crypto/security_bits.h"
#ifdef FIPS_MODE
# define MIN_STRENGTH 112
#else
# define MIN_STRENGTH 80
#endif
static int generate_key(DH *dh);
static int dh_bn_mod_exp(const DH *dh, BIGNUM *r,
@@ -246,16 +253,15 @@ static int generate_key(DH *dh)
if (generate_new_key) {
/* Is it an approved safe prime ?*/
if (DH_get_nid(dh) != NID_undef) {
/*
* The safe prime group code sets N = 2*s
* (where s = max security strength supported).
* N = dh->length (N = maximum bit length of private key)
*/
int max_strength =
ifc_ffc_compute_security_bits(BN_num_bits(dh->params.p));
if (dh->params.q == NULL
|| dh->length > BN_num_bits(dh->params.q))
goto err;
/* dh->length = maximum bit length of generated private key */
if (!ffc_generate_private_key(ctx, &dh->params, dh->length,
dh->length / 2, priv_key))
max_strength, priv_key))
goto err;
} else {
#ifdef FIPS_MODE
@@ -287,7 +293,8 @@ static int generate_key(DH *dh)
* Max Private key size N = len(q)
*/
if (!ffc_generate_private_key(ctx, &dh->params,
BN_num_bits(dh->params.q), 112,
BN_num_bits(dh->params.q),
MIN_STRENGTH,
priv_key))
goto err;
}
+221 -4
View File
@@ -1,5 +1,5 @@
/*
* Copyright 1995-2018 The OpenSSL Project Authors. All Rights Reserved.
* 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
@@ -17,8 +17,10 @@
#include <openssl/bn.h>
#include <openssl/engine.h>
#include <openssl/obj_mac.h>
#include <openssl/core_names.h>
#include "internal/cryptlib.h"
#include "internal/refcount.h"
#include "crypto/evp.h"
#include "crypto/dh.h"
#include "dh_local.h"
@@ -61,7 +63,7 @@ DH *DH_new_method(ENGINE *engine)
}
#endif /* !FIPS_MODE */
DH *dh_new_with_ctx(OPENSSL_CTX *libctx)
DH *dh_new_with_libctx(OPENSSL_CTX *libctx)
{
return dh_new_intern(NULL, libctx);
}
@@ -207,7 +209,8 @@ void DH_get0_pqg(const DH *dh,
int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
{
/* If the fields p and g in d are NULL, the corresponding input
/*
* If the fields p and g in d are NULL, the corresponding input
* parameters MUST be non-NULL. q may remain NULL.
*/
if ((dh->params.p == NULL && p == NULL)
@@ -215,7 +218,9 @@ int DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
return 0;
ffc_params_set0_pqg(&dh->params, p, q, g);
dh->params.nid = NID_undef;
dh_cache_named_group(dh);
if (q != NULL)
dh->length = BN_num_bits(q);
/*
* Check if this is a named group. If it finds a named group then the
* 'q' and 'length' value are either already set or are set by the
@@ -258,6 +263,7 @@ int DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key)
if (priv_key != NULL) {
BN_clear_free(dh->priv_key);
dh->priv_key = priv_key;
dh->length = BN_num_bits(priv_key);
}
dh->dirty_cnt++;
@@ -319,3 +325,214 @@ int dh_get0_nid(const DH *dh)
{
return dh->params.nid;
}
int dh_ffc_params_fromdata(DH *dh, const OSSL_PARAM params[])
{
int ret;
FFC_PARAMS *ffc;
if (dh == NULL)
return 0;
ffc = dh_get0_params(dh);
if (ffc == NULL)
return 0;
ret = ffc_params_fromdata(ffc, params);
if (ret) {
dh_cache_named_group(dh);
dh->dirty_cnt++;
}
return ret;
}
static int dh_paramgen_check(EVP_PKEY_CTX *ctx)
{
if (ctx == NULL || !EVP_PKEY_CTX_IS_GEN_OP(ctx)) {
ERR_raise(ERR_LIB_EVP, EVP_R_COMMAND_NOT_SUPPORTED);
/* Uses the same return values as EVP_PKEY_CTX_ctrl */
return -2;
}
/* If key type not DH return error */
if (ctx->pmeth != NULL
&& ctx->pmeth->pkey_id != EVP_PKEY_DH
&& ctx->pmeth->pkey_id != EVP_PKEY_DHX)
return -1;
return 1;
}
int EVP_PKEY_CTX_set_dh_paramgen_gindex(EVP_PKEY_CTX *ctx, int gindex)
{
int ret;
OSSL_PARAM params[2], *p = params;
if ((ret = dh_paramgen_check(ctx)) <= 0)
return ret;
*p++ = OSSL_PARAM_construct_int(OSSL_PKEY_PARAM_FFC_GINDEX, &gindex);
*p++ = OSSL_PARAM_construct_end();
return EVP_PKEY_CTX_set_params(ctx, params);
}
int EVP_PKEY_CTX_set_dh_paramgen_seed(EVP_PKEY_CTX *ctx,
const unsigned char *seed,
size_t seedlen)
{
int ret;
OSSL_PARAM params[2], *p = params;
if ((ret = dh_paramgen_check(ctx)) <= 0)
return ret;
*p++ = OSSL_PARAM_construct_octet_string(OSSL_PKEY_PARAM_FFC_SEED,
(void *)seed, seedlen);
*p++ = OSSL_PARAM_construct_end();
return EVP_PKEY_CTX_set_params(ctx, params);
}
int EVP_PKEY_CTX_set_dh_paramgen_type(EVP_PKEY_CTX *ctx, int typ)
{
int ret;
OSSL_PARAM params[2], *p = params;
const char *name;
if ((ret = dh_paramgen_check(ctx)) <= 0)
return ret;
#if !defined(FIPS_MODE)
/* TODO(3.0): Remove this eventually when no more legacy */
if (ctx->op.keymgmt.genctx == NULL)
return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN,
EVP_PKEY_CTRL_DH_PARAMGEN_TYPE, typ, NULL);
#endif
name = dh_gen_type_id2name(typ);
if (name == NULL)
return 0;
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_FFC_TYPE,
(char *) name, 0);
*p++ = OSSL_PARAM_construct_end();
return EVP_PKEY_CTX_set_params(ctx, params);
}
int EVP_PKEY_CTX_set_dh_paramgen_prime_len(EVP_PKEY_CTX *ctx, int pbits)
{
int ret;
OSSL_PARAM params[2], *p = params;
size_t bits = pbits;
if ((ret = dh_paramgen_check(ctx)) <= 0)
return ret;
#if !defined(FIPS_MODE)
/* TODO(3.0): Remove this eventually when no more legacy */
if (ctx->op.keymgmt.genctx == NULL)
return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN,
EVP_PKEY_CTRL_DH_PARAMGEN_PRIME_LEN, pbits,
NULL);
#endif
*p++ = OSSL_PARAM_construct_size_t(OSSL_PKEY_PARAM_FFC_PBITS, &bits);
*p++ = OSSL_PARAM_construct_end();
return EVP_PKEY_CTX_set_params(ctx, params);
}
int EVP_PKEY_CTX_set_dh_paramgen_subprime_len(EVP_PKEY_CTX *ctx, int qbits)
{
int ret;
OSSL_PARAM params[2], *p = params;
size_t bits2 = qbits;
if ((ret = dh_paramgen_check(ctx)) <= 0)
return ret;
#if !defined(FIPS_MODE)
/* TODO(3.0): Remove this eventually when no more legacy */
if (ctx->op.keymgmt.genctx == NULL)
return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN,
EVP_PKEY_CTRL_DH_PARAMGEN_SUBPRIME_LEN, qbits,
NULL);
#endif
*p++ = OSSL_PARAM_construct_size_t(OSSL_PKEY_PARAM_FFC_QBITS, &bits2);
*p++ = OSSL_PARAM_construct_end();
return EVP_PKEY_CTX_set_params(ctx, params);
}
int EVP_PKEY_CTX_set_dh_paramgen_generator(EVP_PKEY_CTX *ctx, int gen)
{
int ret;
OSSL_PARAM params[2], *p = params;
if ((ret = dh_paramgen_check(ctx)) <= 0)
return ret;
#if !defined(FIPS_MODE)
/* TODO(3.0): Remove this eventually when no more legacy */
if (ctx->op.keymgmt.genctx == NULL)
return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH, EVP_PKEY_OP_PARAMGEN,
EVP_PKEY_CTRL_DH_PARAMGEN_GENERATOR, gen, NULL);
#endif
*p++ = OSSL_PARAM_construct_int(OSSL_PKEY_PARAM_FFC_GENERATOR, &gen);
*p++ = OSSL_PARAM_construct_end();
return EVP_PKEY_CTX_set_params(ctx, params);
}
int EVP_PKEY_CTX_set_dh_rfc5114(EVP_PKEY_CTX *ctx, int gen)
{
int ret;
OSSL_PARAM params[2], *p = params;
const char *name;
if ((ret = dh_paramgen_check(ctx)) <= 0)
return ret;
#if !defined(FIPS_MODE)
/* TODO(3.0): Remove this eventually when no more legacy */
if (ctx->op.keymgmt.genctx == NULL)
return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DHX, EVP_PKEY_OP_PARAMGEN,
EVP_PKEY_CTRL_DH_RFC5114, gen, NULL);
#endif
name = ffc_named_group_from_uid(gen);
if (name == NULL)
return 0;
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_FFC_GROUP,
(void *)name, 0);
*p++ = OSSL_PARAM_construct_end();
return EVP_PKEY_CTX_set_params(ctx, params);
}
int EVP_PKEY_CTX_set_dhx_rfc5114(EVP_PKEY_CTX *ctx, int gen)
{
return EVP_PKEY_CTX_set_dh_rfc5114(ctx, gen);
}
int EVP_PKEY_CTX_set_dh_nid(EVP_PKEY_CTX *ctx, int nid)
{
int ret;
OSSL_PARAM params[2], *p = params;
const char *name;
if ((ret = dh_paramgen_check(ctx)) <= 0)
return ret;
#if !defined(FIPS_MODE)
/* TODO(3.0): Remove this eventually when no more legacy */
if (ctx->op.keymgmt.genctx == NULL)
return EVP_PKEY_CTX_ctrl(ctx, EVP_PKEY_DH,
EVP_PKEY_OP_PARAMGEN | EVP_PKEY_OP_KEYGEN,
EVP_PKEY_CTRL_DH_NID, nid, NULL);
#endif
name = ffc_named_group_from_uid(nid);
if (name == NULL)
return 0;
*p++ = OSSL_PARAM_construct_utf8_string(OSSL_PKEY_PARAM_FFC_GROUP,
(void *)name, 0);
*p++ = OSSL_PARAM_construct_end();
return EVP_PKEY_CTX_set_params(ctx, params);
}
+2 -1
View File
@@ -21,7 +21,8 @@ struct dh_st {
int pad;
int version;
FFC_PARAMS params;
int32_t length; /* optional value of N (if there is no q) */
/* max generated private key length (can be less than len(q)) */
int32_t length;
BIGNUM *pub_key; /* g^x % p */
BIGNUM *priv_key; /* x */
int flags;
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2016-2018 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 2016-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
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2018 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 2006-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
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 1995-2016 The OpenSSL Project Authors. All Rights Reserved.
* 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
+1 -1
View File
@@ -1,5 +1,5 @@
/*
* Copyright 2011-2016 The OpenSSL Project Authors. All Rights Reserved.
* Copyright 2011-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