projects
/
openssl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
rand: remove unimplemented librandom stub code
[openssl.git]
/
crypto
/
dh
/
dh_gen.c
diff --git
a/crypto/dh/dh_gen.c
b/crypto/dh/dh_gen.c
index 096cf1288633a10372398b8d2b76213dbb009af0..b73bfb7f3b8d96ce8655a5fc4be2b140b3447162 100644
(file)
--- a/
crypto/dh/dh_gen.c
+++ b/
crypto/dh/dh_gen.c
@@
-1,5
+1,5
@@
/*
/*
- * Copyright 1995-202
0
The OpenSSL Project Authors. All Rights Reserved.
+ * Copyright 1995-202
1
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
*
* 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
@@
-28,6
+28,7
@@
#include <openssl/bn.h>
#include <openssl/sha.h>
#include "crypto/dh.h"
#include <openssl/bn.h>
#include <openssl/sha.h>
#include "crypto/dh.h"
+#include "crypto/security_bits.h"
#include "dh_local.h"
#ifndef FIPS_MODULE
#include "dh_local.h"
#ifndef FIPS_MODULE
@@
-35,27
+36,27
@@
static int dh_builtin_genparams(DH *ret, int prime_len, int generator,
BN_GENCB *cb);
#endif /* FIPS_MODULE */
BN_GENCB *cb);
#endif /* FIPS_MODULE */
-int dh_generate_ffc_parameters(DH *dh, int type, int pbits, int qbits,
- BN_GENCB *cb)
+int
ossl_
dh_generate_ffc_parameters(DH *dh, int type, int pbits, int qbits,
+
BN_GENCB *cb)
{
int ret, res;
#ifndef FIPS_MODULE
if (type == DH_PARAMGEN_TYPE_FIPS_186_2)
{
int ret, res;
#ifndef FIPS_MODULE
if (type == DH_PARAMGEN_TYPE_FIPS_186_2)
- ret = ffc_params_FIPS186_2_generate(dh->libctx, &dh->params,
- FFC_PARAM_TYPE_DH,
- pbits, qbits, &res, cb);
+ ret =
ossl_
ffc_params_FIPS186_2_generate(dh->libctx, &dh->params,
+
FFC_PARAM_TYPE_DH,
+
pbits, qbits, &res, cb);
else
#endif
else
#endif
- ret = ffc_params_FIPS186_4_generate(dh->libctx, &dh->params,
- FFC_PARAM_TYPE_DH,
- pbits, qbits, &res, cb);
+ ret =
ossl_
ffc_params_FIPS186_4_generate(dh->libctx, &dh->params,
+
FFC_PARAM_TYPE_DH,
+
pbits, qbits, &res, cb);
if (ret > 0)
dh->dirty_cnt++;
return ret;
}
if (ret > 0)
dh->dirty_cnt++;
return ret;
}
-int dh_get_named_group_uid_from_size(int pbits)
+int
ossl_
dh_get_named_group_uid_from_size(int pbits)
{
/*
* Just choose an approved safe prime group.
{
/*
* Just choose an approved safe prime group.
@@
-91,18
+92,18
@@
int dh_get_named_group_uid_from_size(int pbits)
#ifdef FIPS_MODULE
#ifdef FIPS_MODULE
-static int dh_gen_named_group(O
PENSSL
_CTX *libctx, DH *ret, int prime_len)
+static int dh_gen_named_group(O
SSL_LIB
_CTX *libctx, DH *ret, int prime_len)
{
DH *dh;
int ok = 0;
{
DH *dh;
int ok = 0;
- int nid = dh_get_named_group_uid_from_size(prime_len);
+ int nid =
ossl_
dh_get_named_group_uid_from_size(prime_len);
if (nid == NID_undef)
return 0;
if (nid == NID_undef)
return 0;
- dh = dh_new_by_nid_ex(libctx, nid);
+ dh =
ossl_
dh_new_by_nid_ex(libctx, nid);
if (dh != NULL
if (dh != NULL
- && ffc_params_copy(&ret->params, &dh->params)) {
+ &&
ossl_
ffc_params_copy(&ret->params, &dh->params)) {
ok = 1;
ret->dirty_cnt++;
}
ok = 1;
ret->dirty_cnt++;
}
@@
-160,16
+161,16
@@
static int dh_builtin_genparams(DH *ret, int prime_len, int generator,
BN_CTX *ctx = NULL;
if (prime_len > OPENSSL_DH_MAX_MODULUS_BITS) {
BN_CTX *ctx = NULL;
if (prime_len > OPENSSL_DH_MAX_MODULUS_BITS) {
-
DHerr(DH_F_DH_BUILTIN_GENPARAMS
, DH_R_MODULUS_TOO_LARGE);
+
ERR_raise(ERR_LIB_DH
, DH_R_MODULUS_TOO_LARGE);
return 0;
}
if (prime_len < DH_MIN_MODULUS_BITS) {
return 0;
}
if (prime_len < DH_MIN_MODULUS_BITS) {
-
DHerr(DH_F_DH_BUILTIN_GENPARAMS
, DH_R_MODULUS_TOO_SMALL);
+
ERR_raise(ERR_LIB_DH
, DH_R_MODULUS_TOO_SMALL);
return 0;
}
return 0;
}
- ctx = BN_CTX_new
(
);
+ ctx = BN_CTX_new
_ex(ret->libctx
);
if (ctx == NULL)
goto err;
BN_CTX_start(ctx);
if (ctx == NULL)
goto err;
BN_CTX_start(ctx);
@@
-185,7
+186,7
@@
static int dh_builtin_genparams(DH *ret, int prime_len, int generator,
goto err;
if (generator <= 1) {
goto err;
if (generator <= 1) {
-
DHerr(DH_F_DH_BUILTIN_GENPARAMS
, DH_R_BAD_GENERATOR);
+
ERR_raise(ERR_LIB_DH
, DH_R_BAD_GENERATOR);
goto err;
}
if (generator == DH_GENERATOR_2) {
goto err;
}
if (generator == DH_GENERATOR_2) {
@@
-213,17
+214,20
@@
static int dh_builtin_genparams(DH *ret, int prime_len, int generator,
g = generator;
}
g = generator;
}
- if (!BN_generate_prime_ex
(ret->params.p, prime_len, 1, t1, t2, cb
))
+ if (!BN_generate_prime_ex
2(ret->params.p, prime_len, 1, t1, t2, cb, ctx
))
goto err;
if (!BN_GENCB_call(cb, 3, 0))
goto err;
if (!BN_set_word(ret->params.g, g))
goto err;
goto err;
if (!BN_GENCB_call(cb, 3, 0))
goto err;
if (!BN_set_word(ret->params.g, g))
goto err;
+ /* We are using safe prime p, set key length equivalent to RFC 7919 */
+ ret->length = (2 * ossl_ifc_ffc_compute_security_bits(prime_len)
+ + 24) / 25 * 25;
ret->dirty_cnt++;
ok = 1;
err:
if (ok == -1) {
ret->dirty_cnt++;
ok = 1;
err:
if (ok == -1) {
-
DHerr(DH_F_DH_BUILTIN_GENPARAMS
, ERR_R_BN_LIB);
+
ERR_raise(ERR_LIB_DH
, ERR_R_BN_LIB);
ok = 0;
}
ok = 0;
}