early-access version 2698
This commit is contained in:
48
externals/libressl/crypto/dh/dh_ameth.c
vendored
48
externals/libressl/crypto/dh/dh_ameth.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: dh_ameth.c,v 1.18 2020/01/04 13:57:43 inoguchi Exp $ */
|
||||
/* $OpenBSD: dh_ameth.c,v 1.23 2022/01/20 11:00:34 inoguchi Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2006.
|
||||
*/
|
||||
@@ -10,7 +10,7 @@
|
||||
* are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
*
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in
|
||||
@@ -65,6 +65,8 @@
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#include "asn1_locl.h"
|
||||
#include "dh_local.h"
|
||||
#include "evp_locl.h"
|
||||
|
||||
static void
|
||||
int_dh_free(EVP_PKEY *pkey)
|
||||
@@ -93,7 +95,7 @@ dh_pub_decode(EVP_PKEY *pkey, X509_PUBKEY *pubkey)
|
||||
goto err;
|
||||
}
|
||||
|
||||
pstr = pval;
|
||||
pstr = pval;
|
||||
pm = pstr->data;
|
||||
pmlen = pstr->length;
|
||||
|
||||
@@ -178,7 +180,7 @@ err:
|
||||
* that the AlgorithmIdentifier contains the paramaters, the private key
|
||||
* is explcitly included and the pubkey must be recalculated.
|
||||
*/
|
||||
|
||||
|
||||
static int
|
||||
dh_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8)
|
||||
{
|
||||
@@ -202,7 +204,7 @@ dh_priv_decode(EVP_PKEY *pkey, const PKCS8_PRIV_KEY_INFO *p8)
|
||||
if (!(privkey=d2i_ASN1_INTEGER(NULL, &p, pklen)))
|
||||
goto decerr;
|
||||
|
||||
pstr = pval;
|
||||
pstr = pval;
|
||||
pm = pstr->data;
|
||||
pmlen = pstr->length;
|
||||
if (!(dh = d2i_DHparams(NULL, &pm, pmlen)))
|
||||
@@ -351,7 +353,8 @@ do_dh_print(BIO *bp, const DH *x, int indent, ASN1_PCTX *ctx, int ptype)
|
||||
goto err;
|
||||
}
|
||||
|
||||
BIO_indent(bp, indent, 128);
|
||||
if (!BIO_indent(bp, indent, 128))
|
||||
goto err;
|
||||
if (BIO_printf(bp, "%s: (%d bit)\n", ktype, BN_num_bits(x->p)) <= 0)
|
||||
goto err;
|
||||
indent += 4;
|
||||
@@ -366,7 +369,8 @@ do_dh_print(BIO *bp, const DH *x, int indent, ASN1_PCTX *ctx, int ptype)
|
||||
if (!ASN1_bn_print(bp, "generator:", x->g, m, indent))
|
||||
goto err;
|
||||
if (x->length != 0) {
|
||||
BIO_indent(bp, indent, 128);
|
||||
if (!BIO_indent(bp, indent, 128))
|
||||
goto err;
|
||||
if (BIO_printf(bp, "recommended-private-length: %d bits\n",
|
||||
(int)x->length) <= 0)
|
||||
goto err;
|
||||
@@ -464,6 +468,32 @@ DHparams_print(BIO *bp, const DH *x)
|
||||
return do_dh_print(bp, x, 4, NULL, 0);
|
||||
}
|
||||
|
||||
static int
|
||||
dh_pkey_public_check(const EVP_PKEY *pkey)
|
||||
{
|
||||
DH *dh = pkey->pkey.dh;
|
||||
|
||||
if (dh->pub_key == NULL) {
|
||||
DHerror(DH_R_MISSING_PUBKEY);
|
||||
return 0;
|
||||
}
|
||||
|
||||
return DH_check_pub_key_ex(dh, dh->pub_key);
|
||||
}
|
||||
|
||||
static int
|
||||
dh_pkey_param_check(const EVP_PKEY *pkey)
|
||||
{
|
||||
DH *dh = pkey->pkey.dh;
|
||||
|
||||
/*
|
||||
* It would have made more sense to support EVP_PKEY_check() for DH
|
||||
* keys and call DH_check_ex() there and keeping this as a wrapper
|
||||
* for DH_param_check_ex(). We follow OpenSSL's choice.
|
||||
*/
|
||||
return DH_check_ex(dh);
|
||||
}
|
||||
|
||||
const EVP_PKEY_ASN1_METHOD dh_asn1_meth = {
|
||||
.pkey_id = EVP_PKEY_DH,
|
||||
.pkey_base_id = EVP_PKEY_DH,
|
||||
@@ -491,4 +521,8 @@ const EVP_PKEY_ASN1_METHOD dh_asn1_meth = {
|
||||
.param_print = dh_param_print,
|
||||
|
||||
.pkey_free = int_dh_free,
|
||||
|
||||
.pkey_check = NULL,
|
||||
.pkey_public_check = dh_pkey_public_check,
|
||||
.pkey_param_check = dh_pkey_param_check,
|
||||
};
|
||||
|
4
externals/libressl/crypto/dh/dh_asn1.c
vendored
4
externals/libressl/crypto/dh/dh_asn1.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: dh_asn1.c,v 1.10 2016/12/30 15:26:49 jsing Exp $ */
|
||||
/* $OpenBSD: dh_asn1.c,v 1.11 2022/01/07 09:27:13 tb Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2000.
|
||||
*/
|
||||
@@ -63,6 +63,8 @@
|
||||
#include <openssl/dh.h>
|
||||
#include <openssl/objects.h>
|
||||
|
||||
#include "dh_local.h"
|
||||
|
||||
/* Override the default free and new methods */
|
||||
static int
|
||||
dh_cb(int operation, ASN1_VALUE **pval, const ASN1_ITEM *it, void *exarg)
|
||||
|
281
externals/libressl/crypto/dh/dh_check.c
vendored
281
externals/libressl/crypto/dh/dh_check.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: dh_check.c,v 1.17 2019/01/20 01:56:59 tb Exp $ */
|
||||
/* $OpenBSD: dh_check.c,v 1.24 2022/01/10 12:00:52 tb Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -60,87 +60,244 @@
|
||||
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/dh.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "bn_lcl.h"
|
||||
#include "dh_local.h"
|
||||
|
||||
#define DH_NUMBER_ITERATIONS_FOR_PRIME 64
|
||||
|
||||
/*
|
||||
* Check that p is a safe prime and
|
||||
* if g is 2, 3 or 5, check that it is a suitable generator
|
||||
* where
|
||||
* for 2, p mod 24 == 11
|
||||
* for 3, p mod 12 == 5
|
||||
* for 5, p mod 10 == 3 or 7
|
||||
* should hold.
|
||||
* Check that p is odd and 1 < g < p - 1. The _ex version removes the need of
|
||||
* inspecting flags and pushes errors on the stack instead.
|
||||
*/
|
||||
|
||||
int
|
||||
DH_check(const DH *dh, int *ret)
|
||||
DH_check_params_ex(const DH *dh)
|
||||
{
|
||||
int is_prime, ok = 0;
|
||||
BN_CTX *ctx = NULL;
|
||||
BN_ULONG l;
|
||||
BIGNUM *q = NULL;
|
||||
int flags = 0;
|
||||
|
||||
*ret = 0;
|
||||
ctx = BN_CTX_new();
|
||||
if (ctx == NULL)
|
||||
goto err;
|
||||
q = BN_new();
|
||||
if (q == NULL)
|
||||
goto err;
|
||||
if (!DH_check_params(dh, &flags))
|
||||
return 0;
|
||||
|
||||
if (BN_is_word(dh->g, DH_GENERATOR_2)) {
|
||||
l = BN_mod_word(dh->p, 24);
|
||||
if (l == (BN_ULONG)-1)
|
||||
goto err;
|
||||
if (l != 11)
|
||||
*ret |= DH_NOT_SUITABLE_GENERATOR;
|
||||
} else if (BN_is_word(dh->g, DH_GENERATOR_5)) {
|
||||
l = BN_mod_word(dh->p, 10);
|
||||
if (l == (BN_ULONG)-1)
|
||||
goto err;
|
||||
if (l != 3 && l != 7)
|
||||
*ret |= DH_NOT_SUITABLE_GENERATOR;
|
||||
} else
|
||||
*ret |= DH_UNABLE_TO_CHECK_GENERATOR;
|
||||
if ((flags & DH_CHECK_P_NOT_PRIME) != 0)
|
||||
DHerror(DH_R_CHECK_P_NOT_PRIME);
|
||||
if ((flags & DH_NOT_SUITABLE_GENERATOR) != 0)
|
||||
DHerror(DH_R_NOT_SUITABLE_GENERATOR);
|
||||
|
||||
is_prime = BN_is_prime_ex(dh->p, BN_prime_checks, ctx, NULL);
|
||||
if (is_prime < 0)
|
||||
return flags == 0;
|
||||
}
|
||||
|
||||
int
|
||||
DH_check_params(const DH *dh, int *flags)
|
||||
{
|
||||
BIGNUM *max_g = NULL;
|
||||
int ok = 0;
|
||||
|
||||
*flags = 0;
|
||||
|
||||
if (!BN_is_odd(dh->p))
|
||||
*flags |= DH_CHECK_P_NOT_PRIME;
|
||||
|
||||
/*
|
||||
* Check that 1 < dh->g < p - 1
|
||||
*/
|
||||
|
||||
if (BN_cmp(dh->g, BN_value_one()) <= 0)
|
||||
*flags |= DH_NOT_SUITABLE_GENERATOR;
|
||||
/* max_g = p - 1 */
|
||||
if ((max_g = BN_dup(dh->p)) == NULL)
|
||||
goto err;
|
||||
if (is_prime == 0)
|
||||
*ret |= DH_CHECK_P_NOT_PRIME;
|
||||
else {
|
||||
if (!BN_rshift1(q, dh->p))
|
||||
goto err;
|
||||
is_prime = BN_is_prime_ex(q, BN_prime_checks, ctx, NULL);
|
||||
if (is_prime < 0)
|
||||
goto err;
|
||||
if (is_prime == 0)
|
||||
*ret |= DH_CHECK_P_NOT_SAFE_PRIME;
|
||||
}
|
||||
if (!BN_sub_word(max_g, 1))
|
||||
goto err;
|
||||
/* check that g < max_g */
|
||||
if (BN_cmp(dh->g, max_g) >= 0)
|
||||
*flags |= DH_NOT_SUITABLE_GENERATOR;
|
||||
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
BN_free(max_g);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
||||
/*
|
||||
* Check that p is a safe prime and that g is a suitable generator.
|
||||
* The _ex version puts errors on the stack instead of returning flags.
|
||||
*/
|
||||
|
||||
int
|
||||
DH_check_ex(const DH *dh)
|
||||
{
|
||||
int flags = 0;
|
||||
|
||||
if (!DH_check(dh, &flags))
|
||||
return 0;
|
||||
|
||||
if ((flags & DH_NOT_SUITABLE_GENERATOR) != 0)
|
||||
DHerror(DH_R_NOT_SUITABLE_GENERATOR);
|
||||
if ((flags & DH_CHECK_Q_NOT_PRIME) != 0)
|
||||
DHerror(DH_R_CHECK_Q_NOT_PRIME);
|
||||
if ((flags & DH_CHECK_INVALID_Q_VALUE) != 0)
|
||||
DHerror(DH_R_CHECK_INVALID_Q_VALUE);
|
||||
if ((flags & DH_CHECK_INVALID_J_VALUE) != 0)
|
||||
DHerror(DH_R_CHECK_INVALID_J_VALUE);
|
||||
if ((flags & DH_UNABLE_TO_CHECK_GENERATOR) != 0)
|
||||
DHerror(DH_R_UNABLE_TO_CHECK_GENERATOR);
|
||||
if ((flags & DH_CHECK_P_NOT_PRIME) != 0)
|
||||
DHerror(DH_R_CHECK_P_NOT_PRIME);
|
||||
if ((flags & DH_CHECK_P_NOT_SAFE_PRIME) != 0)
|
||||
DHerror(DH_R_CHECK_P_NOT_SAFE_PRIME);
|
||||
|
||||
return flags == 0;
|
||||
}
|
||||
|
||||
int
|
||||
DH_check(const DH *dh, int *flags)
|
||||
{
|
||||
BN_CTX *ctx = NULL;
|
||||
int is_prime;
|
||||
int ok = 0;
|
||||
|
||||
*flags = 0;
|
||||
|
||||
if (!DH_check_params(dh, flags))
|
||||
goto err;
|
||||
|
||||
ctx = BN_CTX_new();
|
||||
if (ctx == NULL)
|
||||
goto err;
|
||||
BN_CTX_start(ctx);
|
||||
|
||||
if (dh->q != NULL) {
|
||||
BIGNUM *quotient, *residue;
|
||||
|
||||
if ((quotient = BN_CTX_get(ctx)) == NULL)
|
||||
goto err;
|
||||
if ((residue = BN_CTX_get(ctx)) == NULL)
|
||||
goto err;
|
||||
if ((*flags & DH_NOT_SUITABLE_GENERATOR) == 0) {
|
||||
/* Check g^q == 1 mod p */
|
||||
if (!BN_mod_exp_ct(residue, dh->g, dh->q, dh->p, ctx))
|
||||
goto err;
|
||||
if (!BN_is_one(residue))
|
||||
*flags |= DH_NOT_SUITABLE_GENERATOR;
|
||||
}
|
||||
is_prime = BN_is_prime_ex(dh->q, DH_NUMBER_ITERATIONS_FOR_PRIME,
|
||||
ctx, NULL);
|
||||
if (is_prime < 0)
|
||||
goto err;
|
||||
if (is_prime == 0)
|
||||
*flags |= DH_CHECK_Q_NOT_PRIME;
|
||||
/* Check p == 1 mod q, i.e., q divides p - 1 */
|
||||
if (!BN_div_ct(quotient, residue, dh->p, dh->q, ctx))
|
||||
goto err;
|
||||
if (!BN_is_one(residue))
|
||||
*flags |= DH_CHECK_INVALID_Q_VALUE;
|
||||
if (dh->j != NULL && BN_cmp(dh->j, quotient) != 0)
|
||||
*flags |= DH_CHECK_INVALID_J_VALUE;
|
||||
}
|
||||
|
||||
is_prime = BN_is_prime_ex(dh->p, DH_NUMBER_ITERATIONS_FOR_PRIME,
|
||||
ctx, NULL);
|
||||
if (is_prime < 0)
|
||||
goto err;
|
||||
if (is_prime == 0)
|
||||
*flags |= DH_CHECK_P_NOT_PRIME;
|
||||
else if (dh->q == NULL) {
|
||||
BIGNUM *q;
|
||||
|
||||
if ((q = BN_CTX_get(ctx)) == NULL)
|
||||
goto err;
|
||||
if (!BN_rshift1(q, dh->p))
|
||||
goto err;
|
||||
is_prime = BN_is_prime_ex(q, DH_NUMBER_ITERATIONS_FOR_PRIME,
|
||||
ctx, NULL);
|
||||
if (is_prime < 0)
|
||||
goto err;
|
||||
if (is_prime == 0)
|
||||
*flags |= DH_CHECK_P_NOT_SAFE_PRIME;
|
||||
}
|
||||
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
BN_free(q);
|
||||
return ok;
|
||||
}
|
||||
|
||||
int
|
||||
DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *ret)
|
||||
DH_check_pub_key_ex(const DH *dh, const BIGNUM *pub_key)
|
||||
{
|
||||
BIGNUM *q = NULL;
|
||||
int flags = 0;
|
||||
|
||||
*ret = 0;
|
||||
q = BN_new();
|
||||
if (q == NULL)
|
||||
if (!DH_check_pub_key(dh, pub_key, &flags))
|
||||
return 0;
|
||||
BN_set_word(q, 1);
|
||||
if (BN_cmp(pub_key, q) <= 0)
|
||||
*ret |= DH_CHECK_PUBKEY_TOO_SMALL;
|
||||
BN_copy(q, dh->p);
|
||||
BN_sub_word(q, 1);
|
||||
if (BN_cmp(pub_key, q) >= 0)
|
||||
*ret |= DH_CHECK_PUBKEY_TOO_LARGE;
|
||||
|
||||
BN_free(q);
|
||||
return 1;
|
||||
if ((flags & DH_CHECK_PUBKEY_TOO_SMALL) != 0)
|
||||
DHerror(DH_R_CHECK_PUBKEY_TOO_SMALL);
|
||||
if ((flags & DH_CHECK_PUBKEY_TOO_LARGE) != 0)
|
||||
DHerror(DH_R_CHECK_PUBKEY_TOO_LARGE);
|
||||
if ((flags & DH_CHECK_PUBKEY_INVALID) != 0)
|
||||
DHerror(DH_R_CHECK_PUBKEY_INVALID);
|
||||
|
||||
return flags == 0;
|
||||
}
|
||||
|
||||
int
|
||||
DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *flags)
|
||||
{
|
||||
BN_CTX *ctx = NULL;
|
||||
BIGNUM *max_pub_key;
|
||||
int ok = 0;
|
||||
|
||||
*flags = 0;
|
||||
|
||||
if ((ctx = BN_CTX_new()) == NULL)
|
||||
goto err;
|
||||
BN_CTX_start(ctx);
|
||||
if ((max_pub_key = BN_CTX_get(ctx)) == NULL)
|
||||
goto err;
|
||||
|
||||
/*
|
||||
* Check that 1 < pub_key < dh->p - 1
|
||||
*/
|
||||
|
||||
if (BN_cmp(pub_key, BN_value_one()) <= 0)
|
||||
*flags |= DH_CHECK_PUBKEY_TOO_SMALL;
|
||||
|
||||
/* max_pub_key = dh->p - 1 */
|
||||
if (BN_copy(max_pub_key, dh->p) == NULL)
|
||||
goto err;
|
||||
if (!BN_sub_word(max_pub_key, 1))
|
||||
goto err;
|
||||
|
||||
if (BN_cmp(pub_key, max_pub_key) >= 0)
|
||||
*flags |= DH_CHECK_PUBKEY_TOO_LARGE;
|
||||
|
||||
/*
|
||||
* If dh->q is set, check that pub_key^q == 1 mod p
|
||||
*/
|
||||
|
||||
if (dh->q != NULL) {
|
||||
BIGNUM *residue;
|
||||
|
||||
if ((residue = BN_CTX_get(ctx)) == NULL)
|
||||
goto err;
|
||||
|
||||
if (!BN_mod_exp_ct(residue, pub_key, dh->q, dh->p, ctx))
|
||||
goto err;
|
||||
if (!BN_is_one(residue))
|
||||
*flags = DH_CHECK_PUBKEY_INVALID;
|
||||
}
|
||||
|
||||
ok = 1;
|
||||
|
||||
err:
|
||||
BN_CTX_end(ctx);
|
||||
BN_CTX_free(ctx);
|
||||
|
||||
return ok;
|
||||
}
|
||||
|
4
externals/libressl/crypto/dh/dh_depr.c
vendored
4
externals/libressl/crypto/dh/dh_depr.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: dh_depr.c,v 1.6 2014/07/11 08:44:48 jsing Exp $ */
|
||||
/* $OpenBSD: dh_depr.c,v 1.7 2021/12/04 16:08:32 tb Exp $ */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
@@ -62,6 +62,8 @@
|
||||
#include <openssl/bn.h>
|
||||
#include <openssl/dh.h>
|
||||
|
||||
#include "bn_lcl.h"
|
||||
|
||||
#ifndef OPENSSL_NO_DEPRECATED
|
||||
DH *
|
||||
DH_generate_parameters(int prime_len, int generator,
|
||||
|
13
externals/libressl/crypto/dh/dh_err.c
vendored
13
externals/libressl/crypto/dh/dh_err.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: dh_err.c,v 1.16 2017/01/29 17:49:22 beck Exp $ */
|
||||
/* $OpenBSD: dh_err.c,v 1.17 2022/01/10 12:00:52 tb Exp $ */
|
||||
/* ====================================================================
|
||||
* Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
|
||||
*
|
||||
@@ -90,6 +90,17 @@ static ERR_STRING_DATA DH_str_reasons[]=
|
||||
{ERR_REASON(DH_R_NO_PARAMETERS_SET) ,"no parameters set"},
|
||||
{ERR_REASON(DH_R_NO_PRIVATE_VALUE) ,"no private value"},
|
||||
{ERR_REASON(DH_R_PARAMETER_ENCODING_ERROR),"parameter encoding error"},
|
||||
{ERR_REASON(DH_R_CHECK_INVALID_J_VALUE) ,"check invalid j value"},
|
||||
{ERR_REASON(DH_R_CHECK_INVALID_Q_VALUE) ,"check invalid q value"},
|
||||
{ERR_REASON(DH_R_CHECK_PUBKEY_INVALID) ,"check pubkey invalid"},
|
||||
{ERR_REASON(DH_R_CHECK_PUBKEY_TOO_LARGE) ,"check pubkey too large"},
|
||||
{ERR_REASON(DH_R_CHECK_PUBKEY_TOO_SMALL) ,"check pubkey too small"},
|
||||
{ERR_REASON(DH_R_CHECK_P_NOT_PRIME) ,"check p not prime"},
|
||||
{ERR_REASON(DH_R_CHECK_P_NOT_SAFE_PRIME) ,"check p not safe prime"},
|
||||
{ERR_REASON(DH_R_CHECK_Q_NOT_PRIME) ,"check q not prime"},
|
||||
{ERR_REASON(DH_R_MISSING_PUBKEY) ,"missing pubkey"},
|
||||
{ERR_REASON(DH_R_NOT_SUITABLE_GENERATOR) ,"not suitable generator"},
|
||||
{ERR_REASON(DH_R_UNABLE_TO_CHECK_GENERATOR),"unable to check generator"},
|
||||
{0,NULL}
|
||||
};
|
||||
|
||||
|
4
externals/libressl/crypto/dh/dh_gen.c
vendored
4
externals/libressl/crypto/dh/dh_gen.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: dh_gen.c,v 1.16 2017/01/29 17:49:22 beck Exp $ */
|
||||
/* $OpenBSD: dh_gen.c,v 1.17 2022/01/07 09:27:13 tb Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -67,6 +67,8 @@
|
||||
#include <openssl/dh.h>
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "dh_local.h"
|
||||
|
||||
static int dh_builtin_genparams(DH *ret, int prime_len, int generator,
|
||||
BN_GENCB *cb);
|
||||
|
||||
|
3
externals/libressl/crypto/dh/dh_key.c
vendored
3
externals/libressl/crypto/dh/dh_key.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: dh_key.c,v 1.36 2018/11/12 17:39:17 tb Exp $ */
|
||||
/* $OpenBSD: dh_key.c,v 1.37 2022/01/07 09:27:13 tb Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -63,6 +63,7 @@
|
||||
#include <openssl/err.h>
|
||||
|
||||
#include "bn_lcl.h"
|
||||
#include "dh_local.h"
|
||||
|
||||
static int generate_key(DH *dh);
|
||||
static int compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh);
|
||||
|
41
externals/libressl/crypto/dh/dh_lib.c
vendored
41
externals/libressl/crypto/dh/dh_lib.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: dh_lib.c,v 1.32 2018/05/02 15:48:38 tb Exp $ */
|
||||
/* $OpenBSD: dh_lib.c,v 1.36 2022/01/07 09:27:13 tb Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
@@ -69,6 +69,8 @@
|
||||
#include <openssl/engine.h>
|
||||
#endif
|
||||
|
||||
#include "dh_local.h"
|
||||
|
||||
static const DH_METHOD *default_DH_method = NULL;
|
||||
|
||||
void
|
||||
@@ -273,6 +275,7 @@ DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
|
||||
if (q != NULL) {
|
||||
BN_free(dh->q);
|
||||
dh->q = q;
|
||||
dh->length = BN_num_bits(dh->q);
|
||||
}
|
||||
if (g != NULL) {
|
||||
BN_free(dh->g);
|
||||
@@ -306,6 +309,36 @@ DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key)
|
||||
return 1;
|
||||
}
|
||||
|
||||
const BIGNUM *
|
||||
DH_get0_p(const DH *dh)
|
||||
{
|
||||
return dh->p;
|
||||
}
|
||||
|
||||
const BIGNUM *
|
||||
DH_get0_q(const DH *dh)
|
||||
{
|
||||
return dh->q;
|
||||
}
|
||||
|
||||
const BIGNUM *
|
||||
DH_get0_g(const DH *dh)
|
||||
{
|
||||
return dh->g;
|
||||
}
|
||||
|
||||
const BIGNUM *
|
||||
DH_get0_priv_key(const DH *dh)
|
||||
{
|
||||
return dh->priv_key;
|
||||
}
|
||||
|
||||
const BIGNUM *
|
||||
DH_get0_pub_key(const DH *dh)
|
||||
{
|
||||
return dh->pub_key;
|
||||
}
|
||||
|
||||
void
|
||||
DH_clear_flags(DH *dh, int flags)
|
||||
{
|
||||
@@ -324,6 +357,12 @@ DH_set_flags(DH *dh, int flags)
|
||||
dh->flags |= flags;
|
||||
}
|
||||
|
||||
long
|
||||
DH_get_length(const DH *dh)
|
||||
{
|
||||
return dh->length;
|
||||
}
|
||||
|
||||
int
|
||||
DH_set_length(DH *dh, long length)
|
||||
{
|
||||
|
117
externals/libressl/crypto/dh/dh_local.h
vendored
Executable file
117
externals/libressl/crypto/dh/dh_local.h
vendored
Executable file
@@ -0,0 +1,117 @@
|
||||
/* $OpenBSD: dh_local.h,v 1.3 2022/01/14 08:25:44 tb Exp $ */
|
||||
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
|
||||
* All rights reserved.
|
||||
*
|
||||
* This package is an SSL implementation written
|
||||
* by Eric Young (eay@cryptsoft.com).
|
||||
* The implementation was written so as to conform with Netscapes SSL.
|
||||
*
|
||||
* This library is free for commercial and non-commercial use as long as
|
||||
* the following conditions are aheared to. The following conditions
|
||||
* apply to all code found in this distribution, be it the RC4, RSA,
|
||||
* lhash, DES, etc., code; not just the SSL code. The SSL documentation
|
||||
* included with this distribution is covered by the same copyright terms
|
||||
* except that the holder is Tim Hudson (tjh@cryptsoft.com).
|
||||
*
|
||||
* Copyright remains Eric Young's, and as such any Copyright notices in
|
||||
* the code are not to be removed.
|
||||
* If this package is used in a product, Eric Young should be given attribution
|
||||
* as the author of the parts of the library used.
|
||||
* This can be in the form of a textual message at program startup or
|
||||
* in documentation (online or textual) provided with the package.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* "This product includes cryptographic software written by
|
||||
* Eric Young (eay@cryptsoft.com)"
|
||||
* The word 'cryptographic' can be left out if the rouines from the library
|
||||
* being used are not cryptographic related :-).
|
||||
* 4. If you include any Windows specific code (or a derivative thereof) from
|
||||
* the apps directory (application code) you must include an acknowledgement:
|
||||
* "This product includes software written by Tim Hudson (tjh@cryptsoft.com)"
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* The licence and distribution terms for any publically available version or
|
||||
* derivative of this code cannot be changed. i.e. this code cannot simply be
|
||||
* copied and put under another distribution licence
|
||||
* [including the GNU Public Licence.]
|
||||
*/
|
||||
|
||||
#ifndef HEADER_DH_LOCAL_H
|
||||
#define HEADER_DH_LOCAL_H
|
||||
|
||||
__BEGIN_HIDDEN_DECLS
|
||||
|
||||
struct dh_method {
|
||||
const char *name;
|
||||
/* Methods here */
|
||||
int (*generate_key)(DH *dh);
|
||||
int (*compute_key)(unsigned char *key,const BIGNUM *pub_key,DH *dh);
|
||||
int (*bn_mod_exp)(const DH *dh, BIGNUM *r, const BIGNUM *a,
|
||||
const BIGNUM *p, const BIGNUM *m, BN_CTX *ctx, BN_MONT_CTX *m_ctx);
|
||||
int (*init)(DH *dh);
|
||||
int (*finish)(DH *dh);
|
||||
int flags;
|
||||
char *app_data;
|
||||
/* If this is non-NULL, it will be used to generate parameters */
|
||||
int (*generate_params)(DH *dh, int prime_len, int generator,
|
||||
BN_GENCB *cb);
|
||||
};
|
||||
|
||||
struct dh_st {
|
||||
/* This first argument is used to pick up errors when
|
||||
* a DH is passed instead of a EVP_PKEY */
|
||||
int pad;
|
||||
int version;
|
||||
BIGNUM *p;
|
||||
BIGNUM *g;
|
||||
long length; /* optional */
|
||||
BIGNUM *pub_key; /* g^x */
|
||||
BIGNUM *priv_key; /* x */
|
||||
|
||||
int flags;
|
||||
BN_MONT_CTX *method_mont_p;
|
||||
/* Place holders if we want to do X9.42 DH */
|
||||
BIGNUM *q;
|
||||
BIGNUM *j;
|
||||
unsigned char *seed;
|
||||
int seedlen;
|
||||
BIGNUM *counter;
|
||||
|
||||
int references;
|
||||
CRYPTO_EX_DATA ex_data;
|
||||
const DH_METHOD *meth;
|
||||
ENGINE *engine;
|
||||
};
|
||||
|
||||
/*
|
||||
* Public API in OpenSSL that we only want to use internally.
|
||||
*/
|
||||
|
||||
int DH_check_params_ex(const DH *dh);
|
||||
int DH_check_params(const DH *dh, int *flags);
|
||||
int DH_check_ex(const DH *dh);
|
||||
int DH_check_pub_key_ex(const DH *dh, const BIGNUM *pub_key);
|
||||
|
||||
__END_HIDDEN_DECLS
|
||||
|
||||
#endif /* !HEADER_DH_LOCAL_H */
|
4
externals/libressl/crypto/dh/dh_pmeth.c
vendored
4
externals/libressl/crypto/dh/dh_pmeth.c
vendored
@@ -1,4 +1,4 @@
|
||||
/* $OpenBSD: dh_pmeth.c,v 1.10 2017/01/29 17:49:22 beck Exp $ */
|
||||
/* $OpenBSD: dh_pmeth.c,v 1.12 2022/01/07 09:27:13 tb Exp $ */
|
||||
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
|
||||
* project 2006.
|
||||
*/
|
||||
@@ -67,6 +67,8 @@
|
||||
#include <openssl/evp.h>
|
||||
#include <openssl/x509.h>
|
||||
|
||||
#include "bn_lcl.h"
|
||||
#include "dh_local.h"
|
||||
#include "evp_locl.h"
|
||||
|
||||
/* DH pkey context structure */
|
||||
|
Reference in New Issue
Block a user