-/* $OpenBSD: ec_key.c,v 1.34 2023/07/03 09:35:26 tb Exp $ */
+/* $OpenBSD: ec_key.c,v 1.35 2023/07/05 08:39:40 tb Exp $ */
/*
* Written by Nils Larsch for the OpenSSL project.
*/
}
int
-ossl_ec_key_gen(EC_KEY *eckey)
+ec_key_gen(EC_KEY *eckey)
{
BIGNUM *priv_key = NULL;
EC_POINT *pub_key = NULL;
-/* $OpenBSD: ec_kmeth.c,v 1.8 2023/06/25 18:52:27 tb Exp $ */
+/* $OpenBSD: ec_kmeth.c,v 1.9 2023/07/05 08:39:40 tb Exp $ */
/*
* Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL
* project.
.set_private = NULL,
.set_public = NULL,
- .keygen = ossl_ec_key_gen,
- .compute_key = ossl_ecdh_compute_key,
+ .keygen = ec_key_gen,
+ .compute_key = ecdh_compute_key,
- .sign = ossl_ecdsa_sign,
- .sign_setup = ossl_ecdsa_sign_setup,
- .sign_sig = ossl_ecdsa_sign_sig,
+ .sign = ecdsa_sign,
+ .sign_setup = ecdsa_sign_setup,
+ .sign_sig = ecdsa_sign_sig,
- .verify = ossl_ecdsa_verify,
- .verify_sig = ossl_ecdsa_verify_sig,
+ .verify = ecdsa_verify,
+ .verify_sig = ecdsa_verify_sig,
};
const EC_KEY_METHOD *default_ec_key_meth = &openssl_ec_key_method;
-/* $OpenBSD: ec_local.h,v 1.23 2023/07/03 07:26:40 tb Exp $ */
+/* $OpenBSD: ec_local.h,v 1.24 2023/07/05 08:39:40 tb Exp $ */
/*
* Originally written by Bodo Moeller for the OpenSSL project.
*/
#define EC_KEY_METHOD_DYNAMIC 1
-int ossl_ec_key_gen(EC_KEY *eckey);
-int ossl_ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, EC_KEY *ecdh,
+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 ossl_ecdsa_verify(int type, const unsigned char *dgst, int dgst_len,
+int ecdsa_verify(int type, const unsigned char *dgst, int dgst_len,
const unsigned char *sigbuf, int sig_len, EC_KEY *eckey);
-int ossl_ecdsa_verify_sig(const unsigned char *dgst, int dgst_len,
+int ecdsa_verify_sig(const unsigned char *dgst, int dgst_len,
const ECDSA_SIG *sig, EC_KEY *eckey);
/*
-/* $OpenBSD: ech_key.c,v 1.32 2023/07/02 11:29:36 tb Exp $ */
+/* $OpenBSD: ech_key.c,v 1.33 2023/07/05 08:39:40 tb Exp $ */
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
*/
/* XXX - KDF handling moved to ECDH_compute_key(). See OpenSSL e2285d87. */
int
-ossl_ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
- EC_KEY *ecdh,
+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))
{
BN_CTX *ctx;
- BIGNUM *x;
+ BIGNUM *cofactor, *x;
const BIGNUM *priv_key;
const EC_GROUP *group;
EC_POINT *point = NULL;
if ((x = BN_CTX_get(ctx)) == NULL)
goto err;
-
- if ((priv_key = EC_KEY_get0_private_key(ecdh)) == NULL) {
- ECDHerror(ECDH_R_NO_PRIVATE_VALUE);
+ if ((cofactor = BN_CTX_get(ctx)) == NULL)
goto err;
- }
if ((group = EC_KEY_get0_group(ecdh)) == NULL)
goto err;
goto err;
}
+ if ((priv_key = EC_KEY_get0_private_key(ecdh)) == NULL) {
+ ECDHerror(ECDH_R_NO_PRIVATE_VALUE);
+ goto err;
+ }
+
+ if ((EC_KEY_get_flags(ecdh) & EC_FLAG_COFACTOR_ECDH) != 0) {
+ if (!EC_GROUP_get_cofactor(group, cofactor, NULL)) {
+ ECDHerror(ERR_R_EC_LIB);
+ goto err;
+ }
+ if (!BN_mul(cofactor, cofactor, priv_key, ctx)) {
+ ECDHerror(ERR_R_BN_LIB);
+ goto err;
+ }
+ priv_key = cofactor;
+ }
+
if (!EC_POINT_mul(group, point, NULL, pub_key, priv_key, ctx)) {
ECDHerror(ECDH_R_POINT_ARITHMETIC_FAILURE);
goto err;
-/* $OpenBSD: ech_lib.c,v 1.22 2023/06/25 19:17:43 tb Exp $ */
+/* $OpenBSD: ech_lib.c,v 1.23 2023/07/05 08:39:40 tb Exp $ */
/* ====================================================================
* Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
*
static const ECDH_METHOD openssl_ecdh_meth = {
.name = "OpenSSL ECDH method",
- .compute_key = ossl_ecdh_compute_key,
+ .compute_key = ecdh_compute_key,
};
const ECDH_METHOD *
-/* $OpenBSD: ecs_lib.c,v 1.22 2023/06/25 19:33:39 tb Exp $ */
+/* $OpenBSD: ecs_lib.c,v 1.23 2023/07/05 08:39:40 tb Exp $ */
/* ====================================================================
* Copyright (c) 1998-2005 The OpenSSL Project. All rights reserved.
*
static const ECDSA_METHOD openssl_ecdsa_meth = {
.name = "OpenSSL ECDSA method",
- .ecdsa_do_sign = ossl_ecdsa_sign_sig,
- .ecdsa_sign_setup = ossl_ecdsa_sign_setup,
- .ecdsa_do_verify = ossl_ecdsa_verify_sig,
+ .ecdsa_do_sign = ecdsa_sign_sig,
+ .ecdsa_sign_setup = ecdsa_sign_setup,
+ .ecdsa_do_verify = ecdsa_verify_sig,
};
const ECDSA_METHOD *
-/* $OpenBSD: ecs_local.h,v 1.3 2023/06/25 18:45:56 tb Exp $ */
+/* $OpenBSD: ecs_local.h,v 1.4 2023/07/05 08:39:40 tb Exp $ */
/*
* Written by Nils Larsch for the OpenSSL project
*/
BIGNUM *s;
};
-int ossl_ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
+int ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
BIGNUM **rp);
-int ossl_ecdsa_sign(int type, const unsigned char *dgst, int dlen,
+int ecdsa_sign(int type, const unsigned char *dgst, int dlen,
unsigned char *sig, unsigned int *siglen, const BIGNUM *kinv,
const BIGNUM *r, EC_KEY *eckey);
-ECDSA_SIG *ossl_ecdsa_sign_sig(const unsigned char *dgst, int dgst_len,
+ECDSA_SIG *ecdsa_sign_sig(const unsigned char *dgst, int dgst_len,
const BIGNUM *in_kinv, const BIGNUM *in_r, EC_KEY *eckey);
__END_HIDDEN_DECLS
-/* $OpenBSD: ecs_ossl.c,v 1.71 2023/07/04 15:09:31 tb Exp $ */
+/* $OpenBSD: ecs_ossl.c,v 1.72 2023/07/05 08:39:40 tb Exp $ */
/*
* Written by Nils Larsch for the OpenSSL project
*/
}
int
-ossl_ecdsa_sign(int type, const unsigned char *digest, int digest_len,
+ecdsa_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 *key)
{
*/
int
-ossl_ecdsa_sign_setup(EC_KEY *key, BN_CTX *in_ctx, BIGNUM **out_kinv,
- BIGNUM **out_r)
+ecdsa_sign_setup(EC_KEY *key, BN_CTX *in_ctx, BIGNUM **out_kinv, BIGNUM **out_r)
{
const EC_GROUP *group;
EC_POINT *point = NULL;
*/
ECDSA_SIG *
-ossl_ecdsa_sign_sig(const unsigned char *digest, int digest_len,
+ecdsa_sign_sig(const unsigned char *digest, int digest_len,
const BIGNUM *in_kinv, const BIGNUM *in_r, EC_KEY *key)
{
BN_CTX *ctx = NULL;
}
int
-ossl_ecdsa_verify(int type, const unsigned char *digest, int digest_len,
+ecdsa_verify(int type, const unsigned char *digest, int digest_len,
const unsigned char *sigbuf, int sig_len, EC_KEY *key)
{
ECDSA_SIG *s;
*/
int
-ossl_ecdsa_verify_sig(const unsigned char *digest, int digest_len,
+ecdsa_verify_sig(const unsigned char *digest, int digest_len,
const ECDSA_SIG *sig, EC_KEY *key)
{
const EC_GROUP *group;