This commit is contained in:
purplerain 2023-07-10 00:10:46 +00:00
parent 2a351e0cdc
commit f57be82572
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
704 changed files with 20524 additions and 10572 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: dh_ameth.c,v 1.28 2023/04/17 05:57:17 tb Exp $ */
/* $OpenBSD: dh_ameth.c,v 1.30 2023/07/08 15:29:03 beck Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
@ -65,6 +65,7 @@
#include <openssl/x509.h>
#include "asn1_local.h"
#include "bn_local.h"
#include "dh_local.h"
#include "evp_local.h"
@ -280,17 +281,6 @@ err:
return 0;
}
static void
update_buflen(const BIGNUM *b, size_t *pbuflen)
{
size_t i;
if (!b)
return;
if (*pbuflen < (i = (size_t)BN_num_bytes(b)))
*pbuflen = i;
}
static int
dh_param_decode(EVP_PKEY *pkey, const unsigned char **pder, int derlen)
{
@ -313,9 +303,7 @@ dh_param_encode(const EVP_PKEY *pkey, unsigned char **pder)
static int
do_dh_print(BIO *bp, const DH *x, int indent, ASN1_PCTX *ctx, int ptype)
{
unsigned char *m = NULL;
int reason = ERR_R_BUF_LIB, ret = 0;
size_t buf_len = 0;
const char *ktype = NULL;
BIGNUM *priv_key, *pub_key;
@ -329,17 +317,6 @@ do_dh_print(BIO *bp, const DH *x, int indent, ASN1_PCTX *ctx, int ptype)
else
pub_key = NULL;
update_buflen(x->p, &buf_len);
if (buf_len == 0) {
reason = ERR_R_PASSED_NULL_PARAMETER;
goto err;
}
update_buflen(x->g, &buf_len);
update_buflen(pub_key, &buf_len);
update_buflen(priv_key, &buf_len);
if (ptype == 2)
ktype = "PKCS#3 DH Private-Key";
else if (ptype == 1)
@ -347,9 +324,8 @@ do_dh_print(BIO *bp, const DH *x, int indent, ASN1_PCTX *ctx, int ptype)
else
ktype = "PKCS#3 DH Parameters";
m= malloc(buf_len + 10);
if (m == NULL) {
reason = ERR_R_MALLOC_FAILURE;
if (x->p == NULL) {
reason = ERR_R_PASSED_NULL_PARAMETER;
goto err;
}
@ -359,14 +335,14 @@ do_dh_print(BIO *bp, const DH *x, int indent, ASN1_PCTX *ctx, int ptype)
goto err;
indent += 4;
if (!ASN1_bn_print(bp, "private-key:", priv_key, m, indent))
if (!bn_printf(bp, priv_key, indent, "private-key:"))
goto err;
if (!ASN1_bn_print(bp, "public-key:", pub_key, m, indent))
if (!bn_printf(bp, pub_key, indent, "public-key:"))
goto err;
if (!ASN1_bn_print(bp, "prime:", x->p, m, indent))
if (!bn_printf(bp, x->p, indent, "prime:"))
goto err;
if (!ASN1_bn_print(bp, "generator:", x->g, m, indent))
if (!bn_printf(bp, x->g, indent, "generator:"))
goto err;
if (x->length != 0) {
if (!BIO_indent(bp, indent, 128))
@ -378,10 +354,9 @@ do_dh_print(BIO *bp, const DH *x, int indent, ASN1_PCTX *ctx, int ptype)
ret = 1;
if (0) {
err:
err:
DHerror(reason);
}
free(m);
return(ret);
}
@ -473,6 +448,7 @@ DHparams_print(BIO *bp, const DH *x)
{
return do_dh_print(bp, x, 4, NULL, 0);
}
LCRYPTO_ALIAS(DHparams_print);
int
DHparams_print_fp(FILE *fp, const DH *x)
@ -491,6 +467,7 @@ DHparams_print_fp(FILE *fp, const DH *x)
return ret;
}
LCRYPTO_ALIAS(DHparams_print_fp);
static int
dh_pkey_public_check(const EVP_PKEY *pkey)

View file

@ -1,4 +1,4 @@
/* $OpenBSD: dh_asn1.c,v 1.11 2022/01/07 09:27:13 tb Exp $ */
/* $OpenBSD: dh_asn1.c,v 1.12 2023/07/08 15:29:03 beck Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2000.
*/
@ -131,39 +131,46 @@ d2i_DHparams(DH **a, const unsigned char **in, long len)
return (DH *)ASN1_item_d2i((ASN1_VALUE **)a, in, len,
&DHparams_it);
}
LCRYPTO_ALIAS(d2i_DHparams);
int
i2d_DHparams(const DH *a, unsigned char **out)
{
return ASN1_item_i2d((ASN1_VALUE *)a, out, &DHparams_it);
}
LCRYPTO_ALIAS(i2d_DHparams);
DH *
d2i_DHparams_bio(BIO *bp, DH **a)
{
return ASN1_item_d2i_bio(&DHparams_it, bp, a);
}
LCRYPTO_ALIAS(d2i_DHparams_bio);
int
i2d_DHparams_bio(BIO *bp, DH *a)
{
return ASN1_item_i2d_bio(&DHparams_it, bp, a);
}
LCRYPTO_ALIAS(i2d_DHparams_bio);
DH *
d2i_DHparams_fp(FILE *fp, DH **a)
{
return ASN1_item_d2i_fp(&DHparams_it, fp, a);
}
LCRYPTO_ALIAS(d2i_DHparams_fp);
int
i2d_DHparams_fp(FILE *fp, DH *a)
{
return ASN1_item_i2d_fp(&DHparams_it, fp, a);
}
LCRYPTO_ALIAS(i2d_DHparams_fp);
DH *
DHparams_dup(DH *dh)
{
return ASN1_item_dup(&DHparams_it, dh);
}
LCRYPTO_ALIAS(DHparams_dup);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: dh_check.c,v 1.26 2022/11/26 16:08:51 tb Exp $ */
/* $OpenBSD: dh_check.c,v 1.27 2023/07/08 15:29:03 beck Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -227,6 +227,7 @@ DH_check(const DH *dh, int *flags)
BN_CTX_free(ctx);
return ok;
}
LCRYPTO_ALIAS(DH_check);
int
DH_check_pub_key_ex(const DH *dh, const BIGNUM *pub_key)
@ -299,3 +300,4 @@ DH_check_pub_key(const DH *dh, const BIGNUM *pub_key, int *flags)
return ok;
}
LCRYPTO_ALIAS(DH_check_pub_key);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: dh_err.c,v 1.18 2022/07/12 14:42:49 kn Exp $ */
/* $OpenBSD: dh_err.c,v 1.19 2023/07/08 15:29:03 beck Exp $ */
/* ====================================================================
* Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
*
@ -111,3 +111,4 @@ void ERR_load_DH_strings(void)
}
#endif
}
LCRYPTO_ALIAS(ERR_load_DH_strings);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: dh_gen.c,v 1.20 2023/04/13 15:18:29 tb Exp $ */
/* $OpenBSD: dh_gen.c,v 1.21 2023/07/08 15:29:03 beck Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -75,6 +75,7 @@ DH_generate_parameters_ex(DH *ret, int prime_len, int generator, BN_GENCB *cb)
return ret->meth->generate_params(ret, prime_len, generator, cb);
return dh_builtin_genparams(ret, prime_len, generator, cb);
}
LCRYPTO_ALIAS(DH_generate_parameters_ex);
/*
* We generate DH parameters as follows:
@ -193,3 +194,4 @@ DH_generate_parameters(int prime_len, int generator,
DH_free(ret);
return NULL;
}
LCRYPTO_ALIAS(DH_generate_parameters);

View file

@ -1,4 +1,4 @@
/* $OpenBSD: dh_key.c,v 1.38 2022/11/26 16:08:51 tb Exp $ */
/* $OpenBSD: dh_key.c,v 1.39 2023/07/08 15:29:03 beck Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -77,12 +77,14 @@ DH_generate_key(DH *dh)
{
return dh->meth->generate_key(dh);
}
LCRYPTO_ALIAS(DH_generate_key);
int
DH_compute_key(unsigned char *key, const BIGNUM *pub_key, DH *dh)
{
return dh->meth->compute_key(key, pub_key, dh);
}
LCRYPTO_ALIAS(DH_compute_key);
static DH_METHOD dh_ossl = {
.name = "OpenSSL DH Method",
@ -98,6 +100,7 @@ DH_OpenSSL(void)
{
return &dh_ossl;
}
LCRYPTO_ALIAS(DH_OpenSSL);
static int
generate_key(DH *dh)

View file

@ -1,4 +1,4 @@
/* $OpenBSD: dh_lib.c,v 1.38 2023/03/07 09:27:10 jsing Exp $ */
/* $OpenBSD: dh_lib.c,v 1.39 2023/07/08 15:29:03 beck Exp $ */
/* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com)
* All rights reserved.
*
@ -78,6 +78,7 @@ DH_set_default_method(const DH_METHOD *meth)
{
default_DH_method = meth;
}
LCRYPTO_ALIAS(DH_set_default_method);
const DH_METHOD *
DH_get_default_method(void)
@ -86,6 +87,7 @@ DH_get_default_method(void)
default_DH_method = DH_OpenSSL();
return default_DH_method;
}
LCRYPTO_ALIAS(DH_get_default_method);
int
DH_set_method(DH *dh, const DH_METHOD *meth)
@ -108,12 +110,14 @@ DH_set_method(DH *dh, const DH_METHOD *meth)
meth->init(dh);
return 1;
}
LCRYPTO_ALIAS(DH_set_method);
DH *
DH_new(void)
{
return DH_new_method(NULL);
}
LCRYPTO_ALIAS(DH_new);
DH *
DH_new_method(ENGINE *engine)
@ -174,6 +178,7 @@ DH_new_method(ENGINE *engine)
}
return ret;
}
LCRYPTO_ALIAS(DH_new_method);
void
DH_free(DH *r)
@ -204,6 +209,7 @@ DH_free(DH *r)
BN_free(r->priv_key);
free(r);
}
LCRYPTO_ALIAS(DH_free);
int
DH_up_ref(DH *r)
@ -212,6 +218,7 @@ DH_up_ref(DH *r)
return i > 1 ? 1 : 0;
}
LCRYPTO_ALIAS(DH_up_ref);
int
DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
@ -220,30 +227,35 @@ DH_get_ex_new_index(long argl, void *argp, CRYPTO_EX_new *new_func,
return CRYPTO_get_ex_new_index(CRYPTO_EX_INDEX_DH, argl, argp, new_func,
dup_func, free_func);
}
LCRYPTO_ALIAS(DH_get_ex_new_index);
int
DH_set_ex_data(DH *d, int idx, void *arg)
{
return CRYPTO_set_ex_data(&d->ex_data, idx, arg);
}
LCRYPTO_ALIAS(DH_set_ex_data);
void *
DH_get_ex_data(DH *d, int idx)
{
return CRYPTO_get_ex_data(&d->ex_data, idx);
}
LCRYPTO_ALIAS(DH_get_ex_data);
int
DH_size(const DH *dh)
{
return BN_num_bytes(dh->p);
}
LCRYPTO_ALIAS(DH_size);
int
DH_bits(const DH *dh)
{
return BN_num_bits(dh->p);
}
LCRYPTO_ALIAS(DH_bits);
int
DH_security_bits(const DH *dh)
@ -257,12 +269,14 @@ DH_security_bits(const DH *dh)
return BN_security_bits(BN_num_bits(dh->p), N);
}
LCRYPTO_ALIAS(DH_security_bits);
ENGINE *
DH_get0_engine(DH *dh)
{
return dh->engine;
}
LCRYPTO_ALIAS(DH_get0_engine);
void
DH_get0_pqg(const DH *dh, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
@ -274,6 +288,7 @@ DH_get0_pqg(const DH *dh, const BIGNUM **p, const BIGNUM **q, const BIGNUM **g)
if (g != NULL)
*g = dh->g;
}
LCRYPTO_ALIAS(DH_get0_pqg);
int
DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
@ -297,6 +312,7 @@ DH_set0_pqg(DH *dh, BIGNUM *p, BIGNUM *q, BIGNUM *g)
return 1;
}
LCRYPTO_ALIAS(DH_set0_pqg);
void
DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key)
@ -306,6 +322,7 @@ DH_get0_key(const DH *dh, const BIGNUM **pub_key, const BIGNUM **priv_key)
if (priv_key != NULL)
*priv_key = dh->priv_key;
}
LCRYPTO_ALIAS(DH_get0_key);
int
DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key)
@ -321,60 +338,70 @@ DH_set0_key(DH *dh, BIGNUM *pub_key, BIGNUM *priv_key)
return 1;
}
LCRYPTO_ALIAS(DH_set0_key);
const BIGNUM *
DH_get0_p(const DH *dh)
{
return dh->p;
}
LCRYPTO_ALIAS(DH_get0_p);
const BIGNUM *
DH_get0_q(const DH *dh)
{
return dh->q;
}
LCRYPTO_ALIAS(DH_get0_q);
const BIGNUM *
DH_get0_g(const DH *dh)
{
return dh->g;
}
LCRYPTO_ALIAS(DH_get0_g);
const BIGNUM *
DH_get0_priv_key(const DH *dh)
{
return dh->priv_key;
}
LCRYPTO_ALIAS(DH_get0_priv_key);
const BIGNUM *
DH_get0_pub_key(const DH *dh)
{
return dh->pub_key;
}
LCRYPTO_ALIAS(DH_get0_pub_key);
void
DH_clear_flags(DH *dh, int flags)
{
dh->flags &= ~flags;
}
LCRYPTO_ALIAS(DH_clear_flags);
int
DH_test_flags(const DH *dh, int flags)
{
return dh->flags & flags;
}
LCRYPTO_ALIAS(DH_test_flags);
void
DH_set_flags(DH *dh, int flags)
{
dh->flags |= flags;
}
LCRYPTO_ALIAS(DH_set_flags);
long
DH_get_length(const DH *dh)
{
return dh->length;
}
LCRYPTO_ALIAS(DH_get_length);
int
DH_set_length(DH *dh, long length)
@ -385,3 +412,4 @@ DH_set_length(DH *dh, long length)
dh->length = length;
return 1;
}
LCRYPTO_ALIAS(DH_set_length);