sync code with last fixes and improvements from OpenBSD

This commit is contained in:
purplerain 2023-07-30 17:58:45 +00:00
parent f960599e67
commit 691f97cc10
Signed by: purplerain
GPG key ID: F42C07F07E2E35B7
215 changed files with 1520 additions and 11518 deletions

View file

@ -1,4 +1,4 @@
/* $OpenBSD: ec.h,v 1.42 2023/07/05 17:10:10 tb Exp $ */
/* $OpenBSD: ec.h,v 1.45 2023/07/28 09:28:37 tb Exp $ */
/*
* Originally written by Bodo Moeller for the OpenSSL project.
*/
@ -326,6 +326,36 @@ void EC_KEY_set_default_method(const EC_KEY_METHOD *meth);
const EC_KEY_METHOD *EC_KEY_get_method(const EC_KEY *key);
int EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth);
EC_KEY *EC_KEY_new_method(ENGINE *engine);
int ECDH_size(const EC_KEY *ecdh);
int ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
EC_KEY *ecdh,
void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen));
typedef struct ECDSA_SIG_st ECDSA_SIG;
ECDSA_SIG *ECDSA_SIG_new(void);
void ECDSA_SIG_free(ECDSA_SIG *sig);
int i2d_ECDSA_SIG(const ECDSA_SIG *sig, unsigned char **pp);
ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **sig, const unsigned char **pp, long len);
const BIGNUM *ECDSA_SIG_get0_r(const ECDSA_SIG *sig);
const BIGNUM *ECDSA_SIG_get0_s(const ECDSA_SIG *sig);
void ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps);
int ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s);
int ECDSA_size(const EC_KEY *eckey);
ECDSA_SIG *ECDSA_do_sign(const unsigned char *digest, int digest_len,
EC_KEY *eckey);
int ECDSA_do_verify(const unsigned char *digest, int digest_len,
const ECDSA_SIG *sig, EC_KEY *eckey);
int ECDSA_sign(int type, const unsigned char *digest, int digest_len,
unsigned char *signature, unsigned int *signature_len, EC_KEY *eckey);
int ECDSA_verify(int type, const unsigned char *digest, int digest_len,
const unsigned char *signature, int signature_len, EC_KEY *eckey);
EC_KEY_METHOD *EC_KEY_METHOD_new(const EC_KEY_METHOD *meth);
void EC_KEY_METHOD_free(EC_KEY_METHOD *meth);
void EC_KEY_METHOD_set_init(EC_KEY_METHOD *meth,
@ -338,8 +368,20 @@ void EC_KEY_METHOD_set_init(EC_KEY_METHOD *meth,
void EC_KEY_METHOD_set_keygen(EC_KEY_METHOD *meth,
int (*keygen)(EC_KEY *key));
void EC_KEY_METHOD_set_compute_key(EC_KEY_METHOD *meth,
int (*ckey)(void *out, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh,
void *(*KDF) (const void *in, size_t inlen, void *out, size_t *outlen)));
int (*ckey)(unsigned char **out, size_t *out_len, const EC_POINT *pub_key,
const EC_KEY *ecdh));
void EC_KEY_METHOD_set_sign(EC_KEY_METHOD *meth,
int (*sign)(int type, const unsigned char *digest, int digest_len,
unsigned char *signature, unsigned int *signature_len,
const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey),
int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp),
ECDSA_SIG *(*sign_sig)(const unsigned char *digest, int digest_len,
const BIGNUM *in_kinv, const BIGNUM *in_r, EC_KEY *eckey));
void EC_KEY_METHOD_set_verify(EC_KEY_METHOD *meth,
int (*verify)(int type, const unsigned char *digest, int digest_len,
const unsigned char *signature, int signature_len, EC_KEY *eckey),
int (*verify_sig)(const unsigned char *digest, int digest_len,
const ECDSA_SIG *sig, EC_KEY *eckey));
void EC_KEY_METHOD_get_init(const EC_KEY_METHOD *meth,
int (**pinit)(EC_KEY *key),
void (**pfinish)(EC_KEY *key),
@ -350,8 +392,20 @@ void EC_KEY_METHOD_get_init(const EC_KEY_METHOD *meth,
void EC_KEY_METHOD_get_keygen(const EC_KEY_METHOD *meth,
int (**pkeygen)(EC_KEY *key));
void EC_KEY_METHOD_get_compute_key(const EC_KEY_METHOD *meth,
int (**pck)(void *out, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh,
void *(*KDF) (const void *in, size_t inlen, void *out, size_t *outlen)));
int (**pck)(unsigned char **out, size_t *out_len, const EC_POINT *pub_key,
const EC_KEY *ecdh));
void EC_KEY_METHOD_get_sign(const EC_KEY_METHOD *meth,
int (**psign)(int type, const unsigned char *digest, int digest_len,
unsigned char *signature, unsigned int *signature_len,
const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey),
int (**psign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp),
ECDSA_SIG *(**psign_sig)(const unsigned char *digest, int digest_len,
const BIGNUM *in_kinv, const BIGNUM *in_r, EC_KEY *eckey));
void EC_KEY_METHOD_get_verify(const EC_KEY_METHOD *meth,
int (**pverify)(int type, const unsigned char *digest, int digest_len,
const unsigned char *signature, int signature_len, EC_KEY *eckey),
int (**pverify_sig)(const unsigned char *digest, int digest_len,
const ECDSA_SIG *sig, EC_KEY *eckey));
EC_KEY *ECParameters_dup(EC_KEY *key);
@ -630,6 +684,7 @@ void ERR_load_EC_strings(void);
#define EC_R_INVALID_FORM 104
#define EC_R_INVALID_GROUP_ORDER 122
#define EC_R_INVALID_KEY 165
#define EC_R_INVALID_OUTPUT_LENGTH 171
#define EC_R_INVALID_PEER_KEY 152
#define EC_R_INVALID_PENTANOMIAL_BASIS 132
#define EC_R_INVALID_PRIVATE_KEY 123

View file

@ -1,4 +1,4 @@
/* $OpenBSD: ec_err.c,v 1.17 2023/07/07 13:54:45 beck Exp $ */
/* $OpenBSD: ec_err.c,v 1.18 2023/07/28 09:28:37 tb Exp $ */
/* ====================================================================
* Copyright (c) 1999-2011 The OpenSSL Project. All rights reserved.
*
@ -98,6 +98,7 @@ static ERR_STRING_DATA EC_str_reasons[] =
{ERR_REASON(EC_R_INVALID_FORM), "invalid form"},
{ERR_REASON(EC_R_INVALID_GROUP_ORDER), "invalid group order"},
{ERR_REASON(EC_R_INVALID_KEY), "invalid key"},
{ERR_REASON(EC_R_INVALID_OUTPUT_LENGTH), "invalid output length"},
{ERR_REASON(EC_R_INVALID_PEER_KEY), "invalid peer key"},
{ERR_REASON(EC_R_INVALID_PENTANOMIAL_BASIS), "invalid pentanomial basis"},
{ERR_REASON(EC_R_INVALID_PRIVATE_KEY), "invalid private key"},

View file

@ -1,4 +1,4 @@
/* $OpenBSD: ec_kmeth.c,v 1.11 2023/07/07 13:54:45 beck Exp $ */
/* $OpenBSD: ec_kmeth.c,v 1.12 2023/07/28 09:28:37 tb Exp $ */
/*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project.
@ -238,8 +238,8 @@ LCRYPTO_ALIAS(EC_KEY_METHOD_set_keygen);
void
EC_KEY_METHOD_set_compute_key(EC_KEY_METHOD *meth,
int (*ckey)(void *out, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh,
void *(*KDF) (const void *in, size_t inlen, void *out, size_t *outlen)))
int (*ckey)(unsigned char **out, size_t *out_len, const EC_POINT *pub_key,
const EC_KEY *ecdh))
{
meth->compute_key = ckey;
}
@ -310,8 +310,8 @@ LCRYPTO_ALIAS(EC_KEY_METHOD_get_keygen);
void
EC_KEY_METHOD_get_compute_key(const EC_KEY_METHOD *meth,
int (**pck)(void *out, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh,
void *(*KDF) (const void *in, size_t inlen, void *out, size_t *outlen)))
int (**pck)(unsigned char **out, size_t *out_len, const EC_POINT *pub_key,
const EC_KEY *ecdh))
{
if (pck != NULL)
*pck = meth->compute_key;

View file

@ -1,4 +1,4 @@
/* $OpenBSD: ec_local.h,v 1.24 2023/07/05 08:39:40 tb Exp $ */
/* $OpenBSD: ec_local.h,v 1.26 2023/07/28 15:50:33 tb Exp $ */
/*
* Originally written by Bodo Moeller for the OpenSSL project.
*/
@ -73,7 +73,6 @@
#include <openssl/bn.h>
#include <openssl/ec.h>
#include <openssl/ecdsa.h>
#include <openssl/objects.h>
#include "bn_local.h"
@ -323,8 +322,8 @@ struct ec_key_method_st {
int (*set_private)(EC_KEY *key, const BIGNUM *priv_key);
int (*set_public)(EC_KEY *key, const EC_POINT *pub_key);
int (*keygen)(EC_KEY *key);
int (*compute_key)(void *out, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh,
void *(*KDF) (const void *in, size_t inlen, void *out, size_t *outlen));
int (*compute_key)(unsigned char **out, size_t *out_len,
const EC_POINT *pub_key, const EC_KEY *ecdh);
int (*sign)(int type, const unsigned char *dgst, int dlen, unsigned char
*sig, unsigned int *siglen, const BIGNUM *kinv,
const BIGNUM *r, EC_KEY *eckey);
@ -342,8 +341,8 @@ struct ec_key_method_st {
#define EC_KEY_METHOD_DYNAMIC 1
int ec_key_gen(EC_KEY *eckey);
int ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh,
void *(*KDF) (const void *in, size_t inlen, void *out, size_t *outlen));
int ecdh_compute_key(unsigned char **out, size_t *out_len,
const EC_POINT *pub_key, const EC_KEY *ecdh);
int ecdsa_verify(int type, const unsigned char *dgst, int dgst_len,
const unsigned char *sigbuf, int sig_len, EC_KEY *eckey);
int ecdsa_verify_sig(const unsigned char *dgst, int dgst_len,

View file

@ -1,4 +1,4 @@
/* $OpenBSD: ec_pmeth.c,v 1.18 2023/06/25 19:26:04 tb Exp $ */
/* $OpenBSD: ec_pmeth.c,v 1.19 2023/07/28 15:50:33 tb Exp $ */
/* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project 2006.
*/
@ -61,7 +61,6 @@
#include <openssl/asn1t.h>
#include <openssl/ec.h>
#include <openssl/ecdsa.h>
#include <openssl/err.h>
#include <openssl/evp.h>
#include <openssl/x509.h>