summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authortb <>2023-06-25 18:41:36 +0000
committertb <>2023-06-25 18:41:36 +0000
commit5119a6bbd2e88876fc335ff3b50913e87b9d734f (patch)
treea3d9fe6e2dfed0e078a378a56856c728dd1a10af /src
parent4f21d97099309dee2fff64e714d96a6e3ff929ba (diff)
downloadopenbsd-5119a6bbd2e88876fc335ff3b50913e87b9d734f.tar.gz
openbsd-5119a6bbd2e88876fc335ff3b50913e87b9d734f.tar.bz2
openbsd-5119a6bbd2e88876fc335ff3b50913e87b9d734f.zip
Remove method wrappers that use {ecdh,ecdsa}_check()
Now that it is no longer possible to set a custom {ECDH,ECDSA}_METHOD, EC_KEY_METHOD can just call the relevant method directly without the need for this extra contortion. ok jsing
Diffstat (limited to 'src')
-rw-r--r--src/lib/libcrypto/ecdh/ech_key.c25
-rw-r--r--src/lib/libcrypto/ecdsa/ecs_ossl.c62
2 files changed, 14 insertions, 73 deletions
diff --git a/src/lib/libcrypto/ecdh/ech_key.c b/src/lib/libcrypto/ecdh/ech_key.c
index a5c6371f91..108a5ff8f6 100644
--- a/src/lib/libcrypto/ecdh/ech_key.c
+++ b/src/lib/libcrypto/ecdh/ech_key.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ech_key.c,v 1.14 2022/11/26 16:08:52 tb Exp $ */ 1/* $OpenBSD: ech_key.c,v 1.15 2023/06/25 18:41:36 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. 3 * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED.
4 * 4 *
@@ -81,10 +81,6 @@
81#include "ech_local.h" 81#include "ech_local.h"
82#include "ec_local.h" 82#include "ec_local.h"
83 83
84static int ecdh_compute_key(void *out, size_t len, const EC_POINT *pub_key,
85 EC_KEY *ecdh,
86 void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen));
87
88/* 84/*
89 * This implementation is based on the following primitives in the IEEE 1363 85 * This implementation is based on the following primitives in the IEEE 1363
90 * standard: 86 * standard:
@@ -92,8 +88,8 @@ static int ecdh_compute_key(void *out, size_t len, const EC_POINT *pub_key,
92 * - ECSVDP-DH 88 * - ECSVDP-DH
93 * Finally an optional KDF is applied. 89 * Finally an optional KDF is applied.
94 */ 90 */
95static int 91int
96ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, 92ossl_ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
97 EC_KEY *ecdh, 93 EC_KEY *ecdh,
98 void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen)) 94 void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen))
99{ 95{
@@ -195,7 +191,7 @@ err:
195 191
196static ECDH_METHOD openssl_ecdh_meth = { 192static ECDH_METHOD openssl_ecdh_meth = {
197 .name = "OpenSSL ECDH method", 193 .name = "OpenSSL ECDH method",
198 .compute_key = ecdh_compute_key 194 .compute_key = ossl_ecdh_compute_key,
199}; 195};
200 196
201const ECDH_METHOD * 197const ECDH_METHOD *
@@ -204,19 +200,6 @@ ECDH_OpenSSL(void)
204 return &openssl_ecdh_meth; 200 return &openssl_ecdh_meth;
205} 201}
206 202
207/* replace w/ ecdh_compute_key() when ECDH_METHOD gets removed */
208int
209ossl_ecdh_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
210 EC_KEY *eckey,
211 void *(*KDF)(const void *in, size_t inlen, void *out, size_t *outlen))
212{
213 ECDH_DATA *ecdh;
214
215 if ((ecdh = ecdh_check(eckey)) == NULL)
216 return 0;
217 return ecdh->meth->compute_key(out, outlen, pub_key, eckey, KDF);
218}
219
220int 203int
221ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key, 204ECDH_compute_key(void *out, size_t outlen, const EC_POINT *pub_key,
222 EC_KEY *eckey, 205 EC_KEY *eckey,
diff --git a/src/lib/libcrypto/ecdsa/ecs_ossl.c b/src/lib/libcrypto/ecdsa/ecs_ossl.c
index 02e38109bc..5df87f224b 100644
--- a/src/lib/libcrypto/ecdsa/ecs_ossl.c
+++ b/src/lib/libcrypto/ecdsa/ecs_ossl.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecs_ossl.c,v 1.34 2023/06/25 18:35:28 tb Exp $ */ 1/* $OpenBSD: ecs_ossl.c,v 1.35 2023/06/25 18:41:36 tb Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project 3 * Written by Nils Larsch for the OpenSSL project
4 */ 4 */
@@ -71,18 +71,12 @@
71 71
72static int ecdsa_prepare_digest(const unsigned char *dgst, int dgst_len, 72static int ecdsa_prepare_digest(const unsigned char *dgst, int dgst_len,
73 BIGNUM *order, BIGNUM *ret); 73 BIGNUM *order, BIGNUM *ret);
74static ECDSA_SIG *ecdsa_do_sign(const unsigned char *dgst, int dgst_len,
75 const BIGNUM *, const BIGNUM *, EC_KEY *eckey);
76static int ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp,
77 BIGNUM **rp);
78static int ecdsa_do_verify(const unsigned char *dgst, int dgst_len,
79 const ECDSA_SIG *sig, EC_KEY *eckey);
80 74
81static ECDSA_METHOD openssl_ecdsa_meth = { 75static ECDSA_METHOD openssl_ecdsa_meth = {
82 .name = "OpenSSL ECDSA method", 76 .name = "OpenSSL ECDSA method",
83 .ecdsa_do_sign = ecdsa_do_sign, 77 .ecdsa_do_sign = ossl_ecdsa_sign_sig,
84 .ecdsa_sign_setup = ecdsa_sign_setup, 78 .ecdsa_sign_setup = ossl_ecdsa_sign_setup,
85 .ecdsa_do_verify = ecdsa_do_verify 79 .ecdsa_do_verify = ossl_ecdsa_verify_sig,
86}; 80};
87 81
88const ECDSA_METHOD * 82const ECDSA_METHOD *
@@ -139,8 +133,8 @@ ossl_ecdsa_sign(int type, const unsigned char *dgst, int dlen, unsigned char *si
139 return ret; 133 return ret;
140} 134}
141 135
142static int 136int
143ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) 137ossl_ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
144{ 138{
145 BN_CTX *ctx = ctx_in; 139 BN_CTX *ctx = ctx_in;
146 BIGNUM *k = NULL, *r = NULL, *order = NULL, *X = NULL; 140 BIGNUM *k = NULL, *r = NULL, *order = NULL, *X = NULL;
@@ -260,18 +254,6 @@ ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
260 return (ret); 254 return (ret);
261} 255}
262 256
263/* replace w/ ecdsa_sign_setup() when ECDSA_METHOD gets removed */
264int
265ossl_ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
266{
267 ECDSA_DATA *ecdsa;
268
269 if ((ecdsa = ecdsa_check(eckey)) == NULL)
270 return 0;
271 return ecdsa->meth->ecdsa_sign_setup(eckey, ctx_in, kinvp, rp);
272}
273
274
275/* 257/*
276 * It is too expensive to check curve parameters on every sign operation. 258 * It is too expensive to check curve parameters on every sign operation.
277 * Instead, cap the number of retries. A single retry is very unlikely, so 259 * Instead, cap the number of retries. A single retry is very unlikely, so
@@ -279,8 +261,8 @@ ossl_ecdsa_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp
279 */ 261 */
280#define ECDSA_MAX_SIGN_ITERATIONS 32 262#define ECDSA_MAX_SIGN_ITERATIONS 32
281 263
282static ECDSA_SIG * 264ECDSA_SIG *
283ecdsa_do_sign(const unsigned char *dgst, int dgst_len, 265ossl_ecdsa_sign_sig(const unsigned char *dgst, int dgst_len,
284 const BIGNUM *in_kinv, const BIGNUM *in_r, EC_KEY *eckey) 266 const BIGNUM *in_kinv, const BIGNUM *in_r, EC_KEY *eckey)
285{ 267{
286 BIGNUM *b = NULL, *binv = NULL, *bm = NULL, *bxr = NULL; 268 BIGNUM *b = NULL, *binv = NULL, *bm = NULL, *bxr = NULL;
@@ -432,18 +414,6 @@ ecdsa_do_sign(const unsigned char *dgst, int dgst_len,
432 return ret; 414 return ret;
433} 415}
434 416
435/* replace w/ ecdsa_do_sign() when ECDSA_METHOD gets removed */
436ECDSA_SIG *
437ossl_ecdsa_sign_sig(const unsigned char *dgst, int dgst_len,
438 const BIGNUM *in_kinv, const BIGNUM *in_r, EC_KEY *eckey)
439{
440 ECDSA_DATA *ecdsa;
441
442 if ((ecdsa = ecdsa_check(eckey)) == NULL)
443 return NULL;
444 return ecdsa->meth->ecdsa_do_sign(dgst, dgst_len, in_kinv, in_r, eckey);
445}
446
447int 417int
448ossl_ecdsa_verify(int type, const unsigned char *dgst, int dgst_len, 418ossl_ecdsa_verify(int type, const unsigned char *dgst, int dgst_len,
449 const unsigned char *sigbuf, int sig_len, EC_KEY *eckey) 419 const unsigned char *sigbuf, int sig_len, EC_KEY *eckey)
@@ -470,8 +440,8 @@ ossl_ecdsa_verify(int type, const unsigned char *dgst, int dgst_len,
470 return (ret); 440 return (ret);
471} 441}
472 442
473static int 443int
474ecdsa_do_verify(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig, 444ossl_ecdsa_verify_sig(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig,
475 EC_KEY *eckey) 445 EC_KEY *eckey)
476{ 446{
477 BN_CTX *ctx; 447 BN_CTX *ctx;
@@ -561,18 +531,6 @@ ecdsa_do_verify(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig,
561 return ret; 531 return ret;
562} 532}
563 533
564/* replace w/ ecdsa_do_verify() when ECDSA_METHOD gets removed */
565int
566ossl_ecdsa_verify_sig(const unsigned char *dgst, int dgst_len,
567 const ECDSA_SIG *sig, EC_KEY *eckey)
568{
569 ECDSA_DATA *ecdsa;
570
571 if ((ecdsa = ecdsa_check(eckey)) == NULL)
572 return 0;
573 return ecdsa->meth->ecdsa_do_verify(dgst, dgst_len, sig, eckey);
574}
575
576ECDSA_SIG * 534ECDSA_SIG *
577ECDSA_do_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey) 535ECDSA_do_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey)
578{ 536{