From: tb Date: Thu, 13 Apr 2023 15:00:24 +0000 (+0000) Subject: Fold ECDSA sign and verify mess into ecs_ossl.c X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=0b0422082c3ffabc556df2b9bbf05c51c70d5fa0;p=openbsd Fold ECDSA sign and verify mess into ecs_ossl.c discussed with jsing --- diff --git a/lib/libcrypto/ecdsa/ecs_ossl.c b/lib/libcrypto/ecdsa/ecs_ossl.c index 78e2b4a997f..9702cd6dab9 100644 --- a/lib/libcrypto/ecdsa/ecs_ossl.c +++ b/lib/libcrypto/ecdsa/ecs_ossl.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecs_ossl.c,v 1.32 2023/03/30 15:51:09 bluhm Exp $ */ +/* $OpenBSD: ecs_ossl.c,v 1.33 2023/04/13 15:00:24 tb Exp $ */ /* * Written by Nils Larsch for the OpenSSL project */ @@ -62,9 +62,11 @@ #include #include +#include #include #include "bn_local.h" +#include "ec_local.h" #include "ecs_local.h" static int ecdsa_prepare_digest(const unsigned char *dgst, int dgst_len, @@ -572,3 +574,66 @@ ossl_ecdsa_verify_sig(const unsigned char *dgst, int dgst_len, return 0; return ecdsa->meth->ecdsa_do_verify(dgst, dgst_len, sig, eckey); } + +ECDSA_SIG * +ECDSA_do_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey) +{ + return ECDSA_do_sign_ex(dgst, dlen, NULL, NULL, eckey); +} + +ECDSA_SIG * +ECDSA_do_sign_ex(const unsigned char *dgst, int dlen, const BIGNUM *kinv, + const BIGNUM *rp, EC_KEY *eckey) +{ + if (eckey->meth->sign_sig != NULL) + return eckey->meth->sign_sig(dgst, dlen, kinv, rp, eckey); + ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED); + return 0; +} + +int +ECDSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig, + unsigned int *siglen, EC_KEY *eckey) +{ + return ECDSA_sign_ex(type, dgst, dlen, sig, siglen, NULL, NULL, eckey); +} + +int +ECDSA_sign_ex(int type, const unsigned char *dgst, int dlen, unsigned char *sig, + unsigned int *siglen, const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey) +{ + if (eckey->meth->sign != NULL) + return eckey->meth->sign(type, dgst, dlen, sig, siglen, kinv, r, eckey); + ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED); + return 0; +} + +int +ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) +{ + if (eckey->meth->sign_setup != NULL) + return eckey->meth->sign_setup(eckey, ctx_in, kinvp, rp); + ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED); + return 0; +} + +int +ECDSA_do_verify(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig, + EC_KEY *eckey) +{ + if (eckey->meth->verify_sig != NULL) + return eckey->meth->verify_sig(dgst, dgst_len, sig, eckey); + ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED); + return 0; +} + +int +ECDSA_verify(int type, const unsigned char *dgst, int dgst_len, + const unsigned char *sigbuf, int sig_len, EC_KEY *eckey) +{ + if (eckey->meth->verify != NULL) + return eckey->meth->verify(type, dgst, dgst_len, + sigbuf, sig_len, eckey); + ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED); + return 0; +} diff --git a/lib/libcrypto/ecdsa/ecs_sign.c b/lib/libcrypto/ecdsa/ecs_sign.c index 9aab20b0da1..800529f7b2e 100644 --- a/lib/libcrypto/ecdsa/ecs_sign.c +++ b/lib/libcrypto/ecdsa/ecs_sign.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecs_sign.c,v 1.10 2022/11/26 16:08:52 tb Exp $ */ +/* $OpenBSD: ecs_sign.c,v 1.11 2023/04/13 15:00:24 tb Exp $ */ /* ==================================================================== * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. * @@ -65,44 +65,3 @@ #include "ecs_local.h" #include "ec_local.h" -ECDSA_SIG * -ECDSA_do_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey) -{ - return ECDSA_do_sign_ex(dgst, dlen, NULL, NULL, eckey); -} - -ECDSA_SIG * -ECDSA_do_sign_ex(const unsigned char *dgst, int dlen, const BIGNUM *kinv, - const BIGNUM *rp, EC_KEY *eckey) -{ - if (eckey->meth->sign_sig != NULL) - return eckey->meth->sign_sig(dgst, dlen, kinv, rp, eckey); - ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED); - return 0; -} - -int -ECDSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig, - unsigned int *siglen, EC_KEY *eckey) -{ - return ECDSA_sign_ex(type, dgst, dlen, sig, siglen, NULL, NULL, eckey); -} - -int -ECDSA_sign_ex(int type, const unsigned char *dgst, int dlen, unsigned char *sig, - unsigned int *siglen, const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey) -{ - if (eckey->meth->sign != NULL) - return eckey->meth->sign(type, dgst, dlen, sig, siglen, kinv, r, eckey); - ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED); - return 0; -} - -int -ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp) -{ - if (eckey->meth->sign_setup != NULL) - return eckey->meth->sign_setup(eckey, ctx_in, kinvp, rp); - ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED); - return 0; -} diff --git a/lib/libcrypto/ecdsa/ecs_vrf.c b/lib/libcrypto/ecdsa/ecs_vrf.c index 4be4c89d809..bfb2a253edf 100644 --- a/lib/libcrypto/ecdsa/ecs_vrf.c +++ b/lib/libcrypto/ecdsa/ecs_vrf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ecs_vrf.c,v 1.10 2022/11/26 16:08:52 tb Exp $ */ +/* $OpenBSD: ecs_vrf.c,v 1.11 2023/04/13 15:00:24 tb Exp $ */ /* * Written by Nils Larsch for the OpenSSL project */ @@ -73,28 +73,9 @@ * 0: incorrect signature * -1: error */ -int -ECDSA_do_verify(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig, - EC_KEY *eckey) -{ - if (eckey->meth->verify_sig != NULL) - return eckey->meth->verify_sig(dgst, dgst_len, sig, eckey); - ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED); - return 0; -} /* returns * 1: correct signature * 0: incorrect signature * -1: error */ -int -ECDSA_verify(int type, const unsigned char *dgst, int dgst_len, - const unsigned char *sigbuf, int sig_len, EC_KEY *eckey) -{ - if (eckey->meth->verify != NULL) - return eckey->meth->verify(type, dgst, dgst_len, - sigbuf, sig_len, eckey); - ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED); - return 0; -}