summaryrefslogtreecommitdiff
path: root/src/lib/libcrypto/ecdsa/ecs_ossl.c
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/libcrypto/ecdsa/ecs_ossl.c
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/libcrypto/ecdsa/ecs_ossl.c')
-rw-r--r--src/lib/libcrypto/ecdsa/ecs_ossl.c67
1 files changed, 66 insertions, 1 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}