summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
authortb <>2023-04-13 15:00:24 +0000
committertb <>2023-04-13 15:00:24 +0000
commit1f54371dd7e7019c23e6227ddb7b0eef5ff0468c (patch)
treec77c650b80a2a5715e9d9f734b2d0a9c4b3a9ff7 /src/lib
parent15b6ca969589a3b9b2069bb0b796c42e2f146fc4 (diff)
downloadopenbsd-1f54371dd7e7019c23e6227ddb7b0eef5ff0468c.tar.gz
openbsd-1f54371dd7e7019c23e6227ddb7b0eef5ff0468c.tar.bz2
openbsd-1f54371dd7e7019c23e6227ddb7b0eef5ff0468c.zip
Fold ECDSA sign and verify mess into ecs_ossl.c
discussed with jsing
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/libcrypto/ecdsa/ecs_ossl.c67
-rw-r--r--src/lib/libcrypto/ecdsa/ecs_sign.c43
-rw-r--r--src/lib/libcrypto/ecdsa/ecs_vrf.c21
3 files changed, 68 insertions, 63 deletions
diff --git a/src/lib/libcrypto/ecdsa/ecs_ossl.c b/src/lib/libcrypto/ecdsa/ecs_ossl.c
index 78e2b4a997..9702cd6dab 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.32 2023/03/30 15:51:09 bluhm Exp $ */ 1/* $OpenBSD: ecs_ossl.c,v 1.33 2023/04/13 15:00:24 tb Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project 3 * Written by Nils Larsch for the OpenSSL project
4 */ 4 */
@@ -62,9 +62,11 @@
62 62
63#include <openssl/bn.h> 63#include <openssl/bn.h>
64#include <openssl/err.h> 64#include <openssl/err.h>
65#include <openssl/evp.h>
65#include <openssl/objects.h> 66#include <openssl/objects.h>
66 67
67#include "bn_local.h" 68#include "bn_local.h"
69#include "ec_local.h"
68#include "ecs_local.h" 70#include "ecs_local.h"
69 71
70static int ecdsa_prepare_digest(const unsigned char *dgst, int dgst_len, 72static 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,
572 return 0; 574 return 0;
573 return ecdsa->meth->ecdsa_do_verify(dgst, dgst_len, sig, eckey); 575 return ecdsa->meth->ecdsa_do_verify(dgst, dgst_len, sig, eckey);
574} 576}
577
578ECDSA_SIG *
579ECDSA_do_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey)
580{
581 return ECDSA_do_sign_ex(dgst, dlen, NULL, NULL, eckey);
582}
583
584ECDSA_SIG *
585ECDSA_do_sign_ex(const unsigned char *dgst, int dlen, const BIGNUM *kinv,
586 const BIGNUM *rp, EC_KEY *eckey)
587{
588 if (eckey->meth->sign_sig != NULL)
589 return eckey->meth->sign_sig(dgst, dlen, kinv, rp, eckey);
590 ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED);
591 return 0;
592}
593
594int
595ECDSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig,
596 unsigned int *siglen, EC_KEY *eckey)
597{
598 return ECDSA_sign_ex(type, dgst, dlen, sig, siglen, NULL, NULL, eckey);
599}
600
601int
602ECDSA_sign_ex(int type, const unsigned char *dgst, int dlen, unsigned char *sig,
603 unsigned int *siglen, const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey)
604{
605 if (eckey->meth->sign != NULL)
606 return eckey->meth->sign(type, dgst, dlen, sig, siglen, kinv, r, eckey);
607 ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED);
608 return 0;
609}
610
611int
612ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
613{
614 if (eckey->meth->sign_setup != NULL)
615 return eckey->meth->sign_setup(eckey, ctx_in, kinvp, rp);
616 ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED);
617 return 0;
618}
619
620int
621ECDSA_do_verify(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig,
622 EC_KEY *eckey)
623{
624 if (eckey->meth->verify_sig != NULL)
625 return eckey->meth->verify_sig(dgst, dgst_len, sig, eckey);
626 ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED);
627 return 0;
628}
629
630int
631ECDSA_verify(int type, const unsigned char *dgst, int dgst_len,
632 const unsigned char *sigbuf, int sig_len, EC_KEY *eckey)
633{
634 if (eckey->meth->verify != NULL)
635 return eckey->meth->verify(type, dgst, dgst_len,
636 sigbuf, sig_len, eckey);
637 ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED);
638 return 0;
639}
diff --git a/src/lib/libcrypto/ecdsa/ecs_sign.c b/src/lib/libcrypto/ecdsa/ecs_sign.c
index 9aab20b0da..800529f7b2 100644
--- a/src/lib/libcrypto/ecdsa/ecs_sign.c
+++ b/src/lib/libcrypto/ecdsa/ecs_sign.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecs_sign.c,v 1.10 2022/11/26 16:08:52 tb Exp $ */ 1/* $OpenBSD: ecs_sign.c,v 1.11 2023/04/13 15:00:24 tb Exp $ */
2/* ==================================================================== 2/* ====================================================================
3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved. 3 * Copyright (c) 1998-2002 The OpenSSL Project. All rights reserved.
4 * 4 *
@@ -65,44 +65,3 @@
65#include "ecs_local.h" 65#include "ecs_local.h"
66#include "ec_local.h" 66#include "ec_local.h"
67 67
68ECDSA_SIG *
69ECDSA_do_sign(const unsigned char *dgst, int dlen, EC_KEY *eckey)
70{
71 return ECDSA_do_sign_ex(dgst, dlen, NULL, NULL, eckey);
72}
73
74ECDSA_SIG *
75ECDSA_do_sign_ex(const unsigned char *dgst, int dlen, const BIGNUM *kinv,
76 const BIGNUM *rp, EC_KEY *eckey)
77{
78 if (eckey->meth->sign_sig != NULL)
79 return eckey->meth->sign_sig(dgst, dlen, kinv, rp, eckey);
80 ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED);
81 return 0;
82}
83
84int
85ECDSA_sign(int type, const unsigned char *dgst, int dlen, unsigned char *sig,
86 unsigned int *siglen, EC_KEY *eckey)
87{
88 return ECDSA_sign_ex(type, dgst, dlen, sig, siglen, NULL, NULL, eckey);
89}
90
91int
92ECDSA_sign_ex(int type, const unsigned char *dgst, int dlen, unsigned char *sig,
93 unsigned int *siglen, const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey)
94{
95 if (eckey->meth->sign != NULL)
96 return eckey->meth->sign(type, dgst, dlen, sig, siglen, kinv, r, eckey);
97 ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED);
98 return 0;
99}
100
101int
102ECDSA_sign_setup(EC_KEY *eckey, BN_CTX *ctx_in, BIGNUM **kinvp, BIGNUM **rp)
103{
104 if (eckey->meth->sign_setup != NULL)
105 return eckey->meth->sign_setup(eckey, ctx_in, kinvp, rp);
106 ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED);
107 return 0;
108}
diff --git a/src/lib/libcrypto/ecdsa/ecs_vrf.c b/src/lib/libcrypto/ecdsa/ecs_vrf.c
index 4be4c89d80..bfb2a253ed 100644
--- a/src/lib/libcrypto/ecdsa/ecs_vrf.c
+++ b/src/lib/libcrypto/ecdsa/ecs_vrf.c
@@ -1,4 +1,4 @@
1/* $OpenBSD: ecs_vrf.c,v 1.10 2022/11/26 16:08:52 tb Exp $ */ 1/* $OpenBSD: ecs_vrf.c,v 1.11 2023/04/13 15:00:24 tb Exp $ */
2/* 2/*
3 * Written by Nils Larsch for the OpenSSL project 3 * Written by Nils Larsch for the OpenSSL project
4 */ 4 */
@@ -73,28 +73,9 @@
73 * 0: incorrect signature 73 * 0: incorrect signature
74 * -1: error 74 * -1: error
75 */ 75 */
76int
77ECDSA_do_verify(const unsigned char *dgst, int dgst_len, const ECDSA_SIG *sig,
78 EC_KEY *eckey)
79{
80 if (eckey->meth->verify_sig != NULL)
81 return eckey->meth->verify_sig(dgst, dgst_len, sig, eckey);
82 ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED);
83 return 0;
84}
85 76
86/* returns 77/* returns
87 * 1: correct signature 78 * 1: correct signature
88 * 0: incorrect signature 79 * 0: incorrect signature
89 * -1: error 80 * -1: error
90 */ 81 */
91int
92ECDSA_verify(int type, const unsigned char *dgst, int dgst_len,
93 const unsigned char *sigbuf, int sig_len, EC_KEY *eckey)
94{
95 if (eckey->meth->verify != NULL)
96 return eckey->meth->verify(type, dgst, dgst_len,
97 sigbuf, sig_len, eckey);
98 ECDSAerror(EVP_R_METHOD_NOT_SUPPORTED);
99 return 0;
100}