diff options
author | tb <> | 2024-11-16 10:38:10 +0000 |
---|---|---|
committer | tb <> | 2024-11-16 10:38:10 +0000 |
commit | 042b7076516ad1dcaa27e6510710135bca52523f (patch) | |
tree | 2eb0f983e5bc974a2ceef774d66dbddefc4c88ec /src/lib | |
parent | ecb4083482e5b756243b582eaaa08581292915bc (diff) | |
download | openbsd-042b7076516ad1dcaa27e6510710135bca52523f.tar.gz openbsd-042b7076516ad1dcaa27e6510710135bca52523f.tar.bz2 openbsd-042b7076516ad1dcaa27e6510710135bca52523f.zip |
Merge ec_kmeth into ec_key
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/Makefile | 3 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec_key.c | 272 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ec_kmeth.c | 328 |
3 files changed, 272 insertions, 331 deletions
diff --git a/src/lib/libcrypto/Makefile b/src/lib/libcrypto/Makefile index f42ac2b9bf..c981a4189f 100644 --- a/src/lib/libcrypto/Makefile +++ b/src/lib/libcrypto/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile,v 1.227 2024/11/12 10:44:25 tb Exp $ | 1 | # $OpenBSD: Makefile,v 1.228 2024/11/16 10:38:10 tb Exp $ |
2 | 2 | ||
3 | LIB= crypto | 3 | LIB= crypto |
4 | LIBREBUILD=y | 4 | LIBREBUILD=y |
@@ -281,7 +281,6 @@ SRCS+= ec_convert.c | |||
281 | SRCS+= ec_curve.c | 281 | SRCS+= ec_curve.c |
282 | SRCS+= ec_err.c | 282 | SRCS+= ec_err.c |
283 | SRCS+= ec_key.c | 283 | SRCS+= ec_key.c |
284 | SRCS+= ec_kmeth.c | ||
285 | SRCS+= ec_lib.c | 284 | SRCS+= ec_lib.c |
286 | SRCS+= ec_mult.c | 285 | SRCS+= ec_mult.c |
287 | SRCS+= ec_pmeth.c | 286 | SRCS+= ec_pmeth.c |
diff --git a/src/lib/libcrypto/ec/ec_key.c b/src/lib/libcrypto/ec/ec_key.c index 662a7c0f49..a0a8ff2084 100644 --- a/src/lib/libcrypto/ec/ec_key.c +++ b/src/lib/libcrypto/ec/ec_key.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_key.c,v 1.47 2024/11/15 08:49:07 tb Exp $ */ | 1 | /* $OpenBSD: ec_key.c,v 1.48 2024/11/16 10:38:10 tb Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -65,10 +65,12 @@ | |||
65 | 65 | ||
66 | #include <openssl/opensslconf.h> | 66 | #include <openssl/opensslconf.h> |
67 | 67 | ||
68 | #include <openssl/ec.h> | ||
68 | #include <openssl/err.h> | 69 | #include <openssl/err.h> |
69 | 70 | ||
70 | #include "bn_local.h" | 71 | #include "bn_local.h" |
71 | #include "ec_local.h" | 72 | #include "ec_local.h" |
73 | #include "ecdsa_local.h" | ||
72 | 74 | ||
73 | EC_KEY * | 75 | EC_KEY * |
74 | EC_KEY_new(void) | 76 | EC_KEY_new(void) |
@@ -535,3 +537,271 @@ EC_KEY_clear_flags(EC_KEY *key, int flags) | |||
535 | key->flags &= ~flags; | 537 | key->flags &= ~flags; |
536 | } | 538 | } |
537 | LCRYPTO_ALIAS(EC_KEY_clear_flags); | 539 | LCRYPTO_ALIAS(EC_KEY_clear_flags); |
540 | |||
541 | const EC_KEY_METHOD * | ||
542 | EC_KEY_get_method(const EC_KEY *key) | ||
543 | { | ||
544 | return key->meth; | ||
545 | } | ||
546 | LCRYPTO_ALIAS(EC_KEY_get_method); | ||
547 | |||
548 | int | ||
549 | EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth) | ||
550 | { | ||
551 | void (*finish)(EC_KEY *key) = key->meth->finish; | ||
552 | |||
553 | if (finish != NULL) | ||
554 | finish(key); | ||
555 | |||
556 | key->meth = meth; | ||
557 | if (meth->init != NULL) | ||
558 | return meth->init(key); | ||
559 | return 1; | ||
560 | } | ||
561 | LCRYPTO_ALIAS(EC_KEY_set_method); | ||
562 | |||
563 | EC_KEY * | ||
564 | EC_KEY_new_method(ENGINE *engine) | ||
565 | { | ||
566 | EC_KEY *ret; | ||
567 | |||
568 | if ((ret = calloc(1, sizeof(EC_KEY))) == NULL) { | ||
569 | ECerror(ERR_R_MALLOC_FAILURE); | ||
570 | return NULL; | ||
571 | } | ||
572 | ret->meth = EC_KEY_get_default_method(); | ||
573 | ret->version = 1; | ||
574 | ret->flags = 0; | ||
575 | ret->group = NULL; | ||
576 | ret->pub_key = NULL; | ||
577 | ret->priv_key = NULL; | ||
578 | ret->enc_flag = 0; | ||
579 | ret->conv_form = POINT_CONVERSION_UNCOMPRESSED; | ||
580 | ret->references = 1; | ||
581 | |||
582 | if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_EC_KEY, ret, &ret->ex_data)) | ||
583 | goto err; | ||
584 | if (ret->meth->init != NULL && ret->meth->init(ret) == 0) | ||
585 | goto err; | ||
586 | |||
587 | return ret; | ||
588 | |||
589 | err: | ||
590 | EC_KEY_free(ret); | ||
591 | return NULL; | ||
592 | } | ||
593 | LCRYPTO_ALIAS(EC_KEY_new_method); | ||
594 | |||
595 | EC_KEY_METHOD * | ||
596 | EC_KEY_METHOD_new(const EC_KEY_METHOD *meth) | ||
597 | { | ||
598 | EC_KEY_METHOD *ret; | ||
599 | |||
600 | if ((ret = calloc(1, sizeof(*meth))) == NULL) | ||
601 | return NULL; | ||
602 | if (meth != NULL) | ||
603 | *ret = *meth; | ||
604 | ret->flags |= EC_KEY_METHOD_DYNAMIC; | ||
605 | return ret; | ||
606 | } | ||
607 | LCRYPTO_ALIAS(EC_KEY_METHOD_new); | ||
608 | |||
609 | void | ||
610 | EC_KEY_METHOD_free(EC_KEY_METHOD *meth) | ||
611 | { | ||
612 | if (meth == NULL) | ||
613 | return; | ||
614 | if (meth->flags & EC_KEY_METHOD_DYNAMIC) | ||
615 | free(meth); | ||
616 | } | ||
617 | LCRYPTO_ALIAS(EC_KEY_METHOD_free); | ||
618 | |||
619 | void | ||
620 | EC_KEY_METHOD_set_init(EC_KEY_METHOD *meth, | ||
621 | int (*init)(EC_KEY *key), | ||
622 | void (*finish)(EC_KEY *key), | ||
623 | int (*copy)(EC_KEY *dest, const EC_KEY *src), | ||
624 | int (*set_group)(EC_KEY *key, const EC_GROUP *grp), | ||
625 | int (*set_private)(EC_KEY *key, const BIGNUM *priv_key), | ||
626 | int (*set_public)(EC_KEY *key, const EC_POINT *pub_key)) | ||
627 | { | ||
628 | meth->init = init; | ||
629 | meth->finish = finish; | ||
630 | meth->copy = copy; | ||
631 | meth->set_group = set_group; | ||
632 | meth->set_private = set_private; | ||
633 | meth->set_public = set_public; | ||
634 | } | ||
635 | LCRYPTO_ALIAS(EC_KEY_METHOD_set_init); | ||
636 | |||
637 | void | ||
638 | EC_KEY_METHOD_set_keygen(EC_KEY_METHOD *meth, int (*keygen)(EC_KEY *key)) | ||
639 | { | ||
640 | meth->keygen = keygen; | ||
641 | } | ||
642 | LCRYPTO_ALIAS(EC_KEY_METHOD_set_keygen); | ||
643 | |||
644 | void | ||
645 | EC_KEY_METHOD_set_compute_key(EC_KEY_METHOD *meth, | ||
646 | int (*ckey)(unsigned char **out, size_t *out_len, const EC_POINT *pub_key, | ||
647 | const EC_KEY *ecdh)) | ||
648 | { | ||
649 | meth->compute_key = ckey; | ||
650 | } | ||
651 | LCRYPTO_ALIAS(EC_KEY_METHOD_set_compute_key); | ||
652 | |||
653 | void | ||
654 | EC_KEY_METHOD_set_sign(EC_KEY_METHOD *meth, | ||
655 | int (*sign)(int type, const unsigned char *dgst, | ||
656 | int dlen, unsigned char *sig, unsigned int *siglen, | ||
657 | const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey), | ||
658 | int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, | ||
659 | BIGNUM **kinvp, BIGNUM **rp), | ||
660 | ECDSA_SIG *(*sign_sig)(const unsigned char *dgst, | ||
661 | int dgst_len, const BIGNUM *in_kinv, | ||
662 | const BIGNUM *in_r, EC_KEY *eckey)) | ||
663 | { | ||
664 | meth->sign = sign; | ||
665 | meth->sign_setup = sign_setup; | ||
666 | meth->sign_sig = sign_sig; | ||
667 | } | ||
668 | LCRYPTO_ALIAS(EC_KEY_METHOD_set_sign); | ||
669 | |||
670 | void | ||
671 | EC_KEY_METHOD_set_verify(EC_KEY_METHOD *meth, | ||
672 | int (*verify)(int type, const unsigned char *dgst, int dgst_len, | ||
673 | const unsigned char *sigbuf, int sig_len, EC_KEY *eckey), | ||
674 | int (*verify_sig)(const unsigned char *dgst, int dgst_len, | ||
675 | const ECDSA_SIG *sig, EC_KEY *eckey)) | ||
676 | { | ||
677 | meth->verify = verify; | ||
678 | meth->verify_sig = verify_sig; | ||
679 | } | ||
680 | LCRYPTO_ALIAS(EC_KEY_METHOD_set_verify); | ||
681 | |||
682 | |||
683 | void | ||
684 | EC_KEY_METHOD_get_init(const EC_KEY_METHOD *meth, | ||
685 | int (**pinit)(EC_KEY *key), | ||
686 | void (**pfinish)(EC_KEY *key), | ||
687 | int (**pcopy)(EC_KEY *dest, const EC_KEY *src), | ||
688 | int (**pset_group)(EC_KEY *key, const EC_GROUP *grp), | ||
689 | int (**pset_private)(EC_KEY *key, const BIGNUM *priv_key), | ||
690 | int (**pset_public)(EC_KEY *key, const EC_POINT *pub_key)) | ||
691 | { | ||
692 | if (pinit != NULL) | ||
693 | *pinit = meth->init; | ||
694 | if (pfinish != NULL) | ||
695 | *pfinish = meth->finish; | ||
696 | if (pcopy != NULL) | ||
697 | *pcopy = meth->copy; | ||
698 | if (pset_group != NULL) | ||
699 | *pset_group = meth->set_group; | ||
700 | if (pset_private != NULL) | ||
701 | *pset_private = meth->set_private; | ||
702 | if (pset_public != NULL) | ||
703 | *pset_public = meth->set_public; | ||
704 | } | ||
705 | LCRYPTO_ALIAS(EC_KEY_METHOD_get_init); | ||
706 | |||
707 | void | ||
708 | EC_KEY_METHOD_get_keygen(const EC_KEY_METHOD *meth, | ||
709 | int (**pkeygen)(EC_KEY *key)) | ||
710 | { | ||
711 | if (pkeygen != NULL) | ||
712 | *pkeygen = meth->keygen; | ||
713 | } | ||
714 | LCRYPTO_ALIAS(EC_KEY_METHOD_get_keygen); | ||
715 | |||
716 | void | ||
717 | EC_KEY_METHOD_get_compute_key(const EC_KEY_METHOD *meth, | ||
718 | int (**pck)(unsigned char **out, size_t *out_len, const EC_POINT *pub_key, | ||
719 | const EC_KEY *ecdh)) | ||
720 | { | ||
721 | if (pck != NULL) | ||
722 | *pck = meth->compute_key; | ||
723 | } | ||
724 | LCRYPTO_ALIAS(EC_KEY_METHOD_get_compute_key); | ||
725 | |||
726 | void | ||
727 | EC_KEY_METHOD_get_sign(const EC_KEY_METHOD *meth, | ||
728 | int (**psign)(int type, const unsigned char *dgst, | ||
729 | int dlen, unsigned char *sig, unsigned int *siglen, | ||
730 | const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey), | ||
731 | int (**psign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, | ||
732 | BIGNUM **kinvp, BIGNUM **rp), | ||
733 | ECDSA_SIG *(**psign_sig)(const unsigned char *dgst, | ||
734 | int dgst_len, const BIGNUM *in_kinv, const BIGNUM *in_r, | ||
735 | EC_KEY *eckey)) | ||
736 | { | ||
737 | if (psign != NULL) | ||
738 | *psign = meth->sign; | ||
739 | if (psign_setup != NULL) | ||
740 | *psign_setup = meth->sign_setup; | ||
741 | if (psign_sig != NULL) | ||
742 | *psign_sig = meth->sign_sig; | ||
743 | } | ||
744 | LCRYPTO_ALIAS(EC_KEY_METHOD_get_sign); | ||
745 | |||
746 | void | ||
747 | EC_KEY_METHOD_get_verify(const EC_KEY_METHOD *meth, | ||
748 | int (**pverify)(int type, const unsigned char *dgst, int dgst_len, | ||
749 | const unsigned char *sigbuf, int sig_len, EC_KEY *eckey), | ||
750 | int (**pverify_sig)(const unsigned char *dgst, int dgst_len, | ||
751 | const ECDSA_SIG *sig, EC_KEY *eckey)) | ||
752 | { | ||
753 | if (pverify != NULL) | ||
754 | *pverify = meth->verify; | ||
755 | if (pverify_sig != NULL) | ||
756 | *pverify_sig = meth->verify_sig; | ||
757 | } | ||
758 | LCRYPTO_ALIAS(EC_KEY_METHOD_get_verify); | ||
759 | |||
760 | static const EC_KEY_METHOD openssl_ec_key_method = { | ||
761 | .name = "OpenSSL EC_KEY method", | ||
762 | .flags = 0, | ||
763 | |||
764 | .init = NULL, | ||
765 | .finish = NULL, | ||
766 | .copy = NULL, | ||
767 | |||
768 | .set_group = NULL, | ||
769 | .set_private = NULL, | ||
770 | .set_public = NULL, | ||
771 | |||
772 | .keygen = ec_key_gen, | ||
773 | .compute_key = ecdh_compute_key, | ||
774 | |||
775 | .sign = ecdsa_sign, | ||
776 | .sign_setup = ecdsa_sign_setup, | ||
777 | .sign_sig = ecdsa_sign_sig, | ||
778 | |||
779 | .verify = ecdsa_verify, | ||
780 | .verify_sig = ecdsa_verify_sig, | ||
781 | }; | ||
782 | |||
783 | const EC_KEY_METHOD * | ||
784 | EC_KEY_OpenSSL(void) | ||
785 | { | ||
786 | return &openssl_ec_key_method; | ||
787 | } | ||
788 | LCRYPTO_ALIAS(EC_KEY_OpenSSL); | ||
789 | |||
790 | const EC_KEY_METHOD *default_ec_key_meth = &openssl_ec_key_method; | ||
791 | |||
792 | const EC_KEY_METHOD * | ||
793 | EC_KEY_get_default_method(void) | ||
794 | { | ||
795 | return default_ec_key_meth; | ||
796 | } | ||
797 | LCRYPTO_ALIAS(EC_KEY_get_default_method); | ||
798 | |||
799 | void | ||
800 | EC_KEY_set_default_method(const EC_KEY_METHOD *meth) | ||
801 | { | ||
802 | if (meth == NULL) | ||
803 | default_ec_key_meth = &openssl_ec_key_method; | ||
804 | else | ||
805 | default_ec_key_meth = meth; | ||
806 | } | ||
807 | LCRYPTO_ALIAS(EC_KEY_set_default_method); | ||
diff --git a/src/lib/libcrypto/ec/ec_kmeth.c b/src/lib/libcrypto/ec/ec_kmeth.c deleted file mode 100644 index 43661f2c13..0000000000 --- a/src/lib/libcrypto/ec/ec_kmeth.c +++ /dev/null | |||
@@ -1,328 +0,0 @@ | |||
1 | /* $OpenBSD: ec_kmeth.c,v 1.16 2024/11/16 10:32:08 tb Exp $ */ | ||
2 | /* | ||
3 | * Written by Dr Stephen N Henson (steve@openssl.org) for the OpenSSL | ||
4 | * project. | ||
5 | */ | ||
6 | /* ==================================================================== | ||
7 | * Copyright (c) 2015 The OpenSSL Project. All rights reserved. | ||
8 | * | ||
9 | * Redistribution and use in source and binary forms, with or without | ||
10 | * modification, are permitted provided that the following conditions | ||
11 | * are met: | ||
12 | * | ||
13 | * 1. Redistributions of source code must retain the above copyright | ||
14 | * notice, this list of conditions and the following disclaimer. | ||
15 | * | ||
16 | * 2. Redistributions in binary form must reproduce the above copyright | ||
17 | * notice, this list of conditions and the following disclaimer in | ||
18 | * the documentation and/or other materials provided with the | ||
19 | * distribution. | ||
20 | * | ||
21 | * 3. All advertising materials mentioning features or use of this | ||
22 | * software must display the following acknowledgment: | ||
23 | * "This product includes software developed by the OpenSSL Project | ||
24 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
25 | * | ||
26 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
27 | * endorse or promote products derived from this software without | ||
28 | * prior written permission. For written permission, please contact | ||
29 | * licensing@OpenSSL.org. | ||
30 | * | ||
31 | * 5. Products derived from this software may not be called "OpenSSL" | ||
32 | * nor may "OpenSSL" appear in their names without prior written | ||
33 | * permission of the OpenSSL Project. | ||
34 | * | ||
35 | * 6. Redistributions of any form whatsoever must retain the following | ||
36 | * acknowledgment: | ||
37 | * "This product includes software developed by the OpenSSL Project | ||
38 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
39 | * | ||
40 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
41 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
43 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
44 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
45 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
46 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
47 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
48 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
49 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
50 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
51 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
52 | * ==================================================================== | ||
53 | */ | ||
54 | |||
55 | #include <openssl/ec.h> | ||
56 | #include <openssl/err.h> | ||
57 | |||
58 | #include "bn_local.h" | ||
59 | #include "ec_local.h" | ||
60 | #include "ecdsa_local.h" | ||
61 | |||
62 | const EC_KEY_METHOD * | ||
63 | EC_KEY_get_method(const EC_KEY *key) | ||
64 | { | ||
65 | return key->meth; | ||
66 | } | ||
67 | LCRYPTO_ALIAS(EC_KEY_get_method); | ||
68 | |||
69 | int | ||
70 | EC_KEY_set_method(EC_KEY *key, const EC_KEY_METHOD *meth) | ||
71 | { | ||
72 | void (*finish)(EC_KEY *key) = key->meth->finish; | ||
73 | |||
74 | if (finish != NULL) | ||
75 | finish(key); | ||
76 | |||
77 | key->meth = meth; | ||
78 | if (meth->init != NULL) | ||
79 | return meth->init(key); | ||
80 | return 1; | ||
81 | } | ||
82 | LCRYPTO_ALIAS(EC_KEY_set_method); | ||
83 | |||
84 | EC_KEY * | ||
85 | EC_KEY_new_method(ENGINE *engine) | ||
86 | { | ||
87 | EC_KEY *ret; | ||
88 | |||
89 | if ((ret = calloc(1, sizeof(EC_KEY))) == NULL) { | ||
90 | ECerror(ERR_R_MALLOC_FAILURE); | ||
91 | return NULL; | ||
92 | } | ||
93 | ret->meth = EC_KEY_get_default_method(); | ||
94 | ret->version = 1; | ||
95 | ret->flags = 0; | ||
96 | ret->group = NULL; | ||
97 | ret->pub_key = NULL; | ||
98 | ret->priv_key = NULL; | ||
99 | ret->enc_flag = 0; | ||
100 | ret->conv_form = POINT_CONVERSION_UNCOMPRESSED; | ||
101 | ret->references = 1; | ||
102 | |||
103 | if (!CRYPTO_new_ex_data(CRYPTO_EX_INDEX_EC_KEY, ret, &ret->ex_data)) | ||
104 | goto err; | ||
105 | if (ret->meth->init != NULL && ret->meth->init(ret) == 0) | ||
106 | goto err; | ||
107 | |||
108 | return ret; | ||
109 | |||
110 | err: | ||
111 | EC_KEY_free(ret); | ||
112 | return NULL; | ||
113 | } | ||
114 | LCRYPTO_ALIAS(EC_KEY_new_method); | ||
115 | |||
116 | EC_KEY_METHOD * | ||
117 | EC_KEY_METHOD_new(const EC_KEY_METHOD *meth) | ||
118 | { | ||
119 | EC_KEY_METHOD *ret; | ||
120 | |||
121 | if ((ret = calloc(1, sizeof(*meth))) == NULL) | ||
122 | return NULL; | ||
123 | if (meth != NULL) | ||
124 | *ret = *meth; | ||
125 | ret->flags |= EC_KEY_METHOD_DYNAMIC; | ||
126 | return ret; | ||
127 | } | ||
128 | LCRYPTO_ALIAS(EC_KEY_METHOD_new); | ||
129 | |||
130 | void | ||
131 | EC_KEY_METHOD_free(EC_KEY_METHOD *meth) | ||
132 | { | ||
133 | if (meth == NULL) | ||
134 | return; | ||
135 | if (meth->flags & EC_KEY_METHOD_DYNAMIC) | ||
136 | free(meth); | ||
137 | } | ||
138 | LCRYPTO_ALIAS(EC_KEY_METHOD_free); | ||
139 | |||
140 | void | ||
141 | EC_KEY_METHOD_set_init(EC_KEY_METHOD *meth, | ||
142 | int (*init)(EC_KEY *key), | ||
143 | void (*finish)(EC_KEY *key), | ||
144 | int (*copy)(EC_KEY *dest, const EC_KEY *src), | ||
145 | int (*set_group)(EC_KEY *key, const EC_GROUP *grp), | ||
146 | int (*set_private)(EC_KEY *key, const BIGNUM *priv_key), | ||
147 | int (*set_public)(EC_KEY *key, const EC_POINT *pub_key)) | ||
148 | { | ||
149 | meth->init = init; | ||
150 | meth->finish = finish; | ||
151 | meth->copy = copy; | ||
152 | meth->set_group = set_group; | ||
153 | meth->set_private = set_private; | ||
154 | meth->set_public = set_public; | ||
155 | } | ||
156 | LCRYPTO_ALIAS(EC_KEY_METHOD_set_init); | ||
157 | |||
158 | void | ||
159 | EC_KEY_METHOD_set_keygen(EC_KEY_METHOD *meth, int (*keygen)(EC_KEY *key)) | ||
160 | { | ||
161 | meth->keygen = keygen; | ||
162 | } | ||
163 | LCRYPTO_ALIAS(EC_KEY_METHOD_set_keygen); | ||
164 | |||
165 | void | ||
166 | EC_KEY_METHOD_set_compute_key(EC_KEY_METHOD *meth, | ||
167 | int (*ckey)(unsigned char **out, size_t *out_len, const EC_POINT *pub_key, | ||
168 | const EC_KEY *ecdh)) | ||
169 | { | ||
170 | meth->compute_key = ckey; | ||
171 | } | ||
172 | LCRYPTO_ALIAS(EC_KEY_METHOD_set_compute_key); | ||
173 | |||
174 | void | ||
175 | EC_KEY_METHOD_set_sign(EC_KEY_METHOD *meth, | ||
176 | int (*sign)(int type, const unsigned char *dgst, | ||
177 | int dlen, unsigned char *sig, unsigned int *siglen, | ||
178 | const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey), | ||
179 | int (*sign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, | ||
180 | BIGNUM **kinvp, BIGNUM **rp), | ||
181 | ECDSA_SIG *(*sign_sig)(const unsigned char *dgst, | ||
182 | int dgst_len, const BIGNUM *in_kinv, | ||
183 | const BIGNUM *in_r, EC_KEY *eckey)) | ||
184 | { | ||
185 | meth->sign = sign; | ||
186 | meth->sign_setup = sign_setup; | ||
187 | meth->sign_sig = sign_sig; | ||
188 | } | ||
189 | LCRYPTO_ALIAS(EC_KEY_METHOD_set_sign); | ||
190 | |||
191 | void | ||
192 | EC_KEY_METHOD_set_verify(EC_KEY_METHOD *meth, | ||
193 | int (*verify)(int type, const unsigned char *dgst, int dgst_len, | ||
194 | const unsigned char *sigbuf, int sig_len, EC_KEY *eckey), | ||
195 | int (*verify_sig)(const unsigned char *dgst, int dgst_len, | ||
196 | const ECDSA_SIG *sig, EC_KEY *eckey)) | ||
197 | { | ||
198 | meth->verify = verify; | ||
199 | meth->verify_sig = verify_sig; | ||
200 | } | ||
201 | LCRYPTO_ALIAS(EC_KEY_METHOD_set_verify); | ||
202 | |||
203 | |||
204 | void | ||
205 | EC_KEY_METHOD_get_init(const EC_KEY_METHOD *meth, | ||
206 | int (**pinit)(EC_KEY *key), | ||
207 | void (**pfinish)(EC_KEY *key), | ||
208 | int (**pcopy)(EC_KEY *dest, const EC_KEY *src), | ||
209 | int (**pset_group)(EC_KEY *key, const EC_GROUP *grp), | ||
210 | int (**pset_private)(EC_KEY *key, const BIGNUM *priv_key), | ||
211 | int (**pset_public)(EC_KEY *key, const EC_POINT *pub_key)) | ||
212 | { | ||
213 | if (pinit != NULL) | ||
214 | *pinit = meth->init; | ||
215 | if (pfinish != NULL) | ||
216 | *pfinish = meth->finish; | ||
217 | if (pcopy != NULL) | ||
218 | *pcopy = meth->copy; | ||
219 | if (pset_group != NULL) | ||
220 | *pset_group = meth->set_group; | ||
221 | if (pset_private != NULL) | ||
222 | *pset_private = meth->set_private; | ||
223 | if (pset_public != NULL) | ||
224 | *pset_public = meth->set_public; | ||
225 | } | ||
226 | LCRYPTO_ALIAS(EC_KEY_METHOD_get_init); | ||
227 | |||
228 | void | ||
229 | EC_KEY_METHOD_get_keygen(const EC_KEY_METHOD *meth, | ||
230 | int (**pkeygen)(EC_KEY *key)) | ||
231 | { | ||
232 | if (pkeygen != NULL) | ||
233 | *pkeygen = meth->keygen; | ||
234 | } | ||
235 | LCRYPTO_ALIAS(EC_KEY_METHOD_get_keygen); | ||
236 | |||
237 | void | ||
238 | EC_KEY_METHOD_get_compute_key(const EC_KEY_METHOD *meth, | ||
239 | int (**pck)(unsigned char **out, size_t *out_len, const EC_POINT *pub_key, | ||
240 | const EC_KEY *ecdh)) | ||
241 | { | ||
242 | if (pck != NULL) | ||
243 | *pck = meth->compute_key; | ||
244 | } | ||
245 | LCRYPTO_ALIAS(EC_KEY_METHOD_get_compute_key); | ||
246 | |||
247 | void | ||
248 | EC_KEY_METHOD_get_sign(const EC_KEY_METHOD *meth, | ||
249 | int (**psign)(int type, const unsigned char *dgst, | ||
250 | int dlen, unsigned char *sig, unsigned int *siglen, | ||
251 | const BIGNUM *kinv, const BIGNUM *r, EC_KEY *eckey), | ||
252 | int (**psign_setup)(EC_KEY *eckey, BN_CTX *ctx_in, | ||
253 | BIGNUM **kinvp, BIGNUM **rp), | ||
254 | ECDSA_SIG *(**psign_sig)(const unsigned char *dgst, | ||
255 | int dgst_len, const BIGNUM *in_kinv, const BIGNUM *in_r, | ||
256 | EC_KEY *eckey)) | ||
257 | { | ||
258 | if (psign != NULL) | ||
259 | *psign = meth->sign; | ||
260 | if (psign_setup != NULL) | ||
261 | *psign_setup = meth->sign_setup; | ||
262 | if (psign_sig != NULL) | ||
263 | *psign_sig = meth->sign_sig; | ||
264 | } | ||
265 | LCRYPTO_ALIAS(EC_KEY_METHOD_get_sign); | ||
266 | |||
267 | void | ||
268 | EC_KEY_METHOD_get_verify(const EC_KEY_METHOD *meth, | ||
269 | int (**pverify)(int type, const unsigned char *dgst, int dgst_len, | ||
270 | const unsigned char *sigbuf, int sig_len, EC_KEY *eckey), | ||
271 | int (**pverify_sig)(const unsigned char *dgst, int dgst_len, | ||
272 | const ECDSA_SIG *sig, EC_KEY *eckey)) | ||
273 | { | ||
274 | if (pverify != NULL) | ||
275 | *pverify = meth->verify; | ||
276 | if (pverify_sig != NULL) | ||
277 | *pverify_sig = meth->verify_sig; | ||
278 | } | ||
279 | LCRYPTO_ALIAS(EC_KEY_METHOD_get_verify); | ||
280 | |||
281 | static const EC_KEY_METHOD openssl_ec_key_method = { | ||
282 | .name = "OpenSSL EC_KEY method", | ||
283 | .flags = 0, | ||
284 | |||
285 | .init = NULL, | ||
286 | .finish = NULL, | ||
287 | .copy = NULL, | ||
288 | |||
289 | .set_group = NULL, | ||
290 | .set_private = NULL, | ||
291 | .set_public = NULL, | ||
292 | |||
293 | .keygen = ec_key_gen, | ||
294 | .compute_key = ecdh_compute_key, | ||
295 | |||
296 | .sign = ecdsa_sign, | ||
297 | .sign_setup = ecdsa_sign_setup, | ||
298 | .sign_sig = ecdsa_sign_sig, | ||
299 | |||
300 | .verify = ecdsa_verify, | ||
301 | .verify_sig = ecdsa_verify_sig, | ||
302 | }; | ||
303 | |||
304 | const EC_KEY_METHOD * | ||
305 | EC_KEY_OpenSSL(void) | ||
306 | { | ||
307 | return &openssl_ec_key_method; | ||
308 | } | ||
309 | LCRYPTO_ALIAS(EC_KEY_OpenSSL); | ||
310 | |||
311 | const EC_KEY_METHOD *default_ec_key_meth = &openssl_ec_key_method; | ||
312 | |||
313 | const EC_KEY_METHOD * | ||
314 | EC_KEY_get_default_method(void) | ||
315 | { | ||
316 | return default_ec_key_meth; | ||
317 | } | ||
318 | LCRYPTO_ALIAS(EC_KEY_get_default_method); | ||
319 | |||
320 | void | ||
321 | EC_KEY_set_default_method(const EC_KEY_METHOD *meth) | ||
322 | { | ||
323 | if (meth == NULL) | ||
324 | default_ec_key_meth = &openssl_ec_key_method; | ||
325 | else | ||
326 | default_ec_key_meth = meth; | ||
327 | } | ||
328 | LCRYPTO_ALIAS(EC_KEY_set_default_method); | ||