diff options
author | tb <> | 2023-07-05 12:18:21 +0000 |
---|---|---|
committer | tb <> | 2023-07-05 12:18:21 +0000 |
commit | 26010e9c7baa4f220e97d24329f0c64fc74430dd (patch) | |
tree | b7f4ae59c723f184139ba5a50306a43fb49194f4 /src/lib | |
parent | a71fe1d5846a4f1db4c2478c65f65ca026866e81 (diff) | |
download | openbsd-26010e9c7baa4f220e97d24329f0c64fc74430dd.tar.gz openbsd-26010e9c7baa4f220e97d24329f0c64fc74430dd.tar.bz2 openbsd-26010e9c7baa4f220e97d24329f0c64fc74430dd.zip |
Merge ECDSA code that will stay into ecdsa.c
discussed with jsing
Diffstat (limited to 'src/lib')
-rw-r--r-- | src/lib/libcrypto/Makefile | 5 | ||||
-rw-r--r-- | src/lib/libcrypto/ecdsa/ecdsa.c (renamed from src/lib/libcrypto/ecdsa/ecs_ossl.c) | 101 | ||||
-rw-r--r-- | src/lib/libcrypto/ecdsa/ecs_asn1.c | 151 |
3 files changed, 97 insertions, 160 deletions
diff --git a/src/lib/libcrypto/Makefile b/src/lib/libcrypto/Makefile index d67bb4431a..bf20491fbc 100644 --- a/src/lib/libcrypto/Makefile +++ b/src/lib/libcrypto/Makefile | |||
@@ -1,4 +1,4 @@ | |||
1 | # $OpenBSD: Makefile,v 1.133 2023/06/29 06:12:04 tb Exp $ | 1 | # $OpenBSD: Makefile,v 1.134 2023/07/05 12:18:21 tb Exp $ |
2 | 2 | ||
3 | LIB= crypto | 3 | LIB= crypto |
4 | LIBREBUILD=y | 4 | LIBREBUILD=y |
@@ -357,10 +357,9 @@ SRCS+= ech_key.c | |||
357 | SRCS+= ech_lib.c | 357 | SRCS+= ech_lib.c |
358 | 358 | ||
359 | # ecdsa/ | 359 | # ecdsa/ |
360 | SRCS+= ecs_asn1.c | ||
361 | SRCS+= ecs_err.c | 360 | SRCS+= ecs_err.c |
362 | SRCS+= ecs_lib.c | 361 | SRCS+= ecs_lib.c |
363 | SRCS+= ecs_ossl.c | 362 | SRCS+= ecdsa.c |
364 | 363 | ||
365 | # engine/ | 364 | # engine/ |
366 | SRCS+= eng_all.c | 365 | SRCS+= eng_all.c |
diff --git a/src/lib/libcrypto/ecdsa/ecs_ossl.c b/src/lib/libcrypto/ecdsa/ecdsa.c index 9886852e0f..c831e9f716 100644 --- a/src/lib/libcrypto/ecdsa/ecs_ossl.c +++ b/src/lib/libcrypto/ecdsa/ecdsa.c | |||
@@ -1,9 +1,6 @@ | |||
1 | /* $OpenBSD: ecs_ossl.c,v 1.73 2023/07/05 11:37:46 tb Exp $ */ | 1 | /* $OpenBSD: ecdsa.c,v 1.1 2023/07/05 12:18:21 tb Exp $ */ |
2 | /* | ||
3 | * Written by Nils Larsch for the OpenSSL project | ||
4 | */ | ||
5 | /* ==================================================================== | 2 | /* ==================================================================== |
6 | * Copyright (c) 1998-2004 The OpenSSL Project. All rights reserved. | 3 | * Copyright (c) 2000-2002 The OpenSSL Project. All rights reserved. |
7 | * | 4 | * |
8 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | 6 | * modification, are permitted provided that the following conditions |
@@ -25,7 +22,7 @@ | |||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | 22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to |
26 | * endorse or promote products derived from this software without | 23 | * endorse or promote products derived from this software without |
27 | * prior written permission. For written permission, please contact | 24 | * prior written permission. For written permission, please contact |
28 | * openssl-core@OpenSSL.org. | 25 | * licensing@OpenSSL.org. |
29 | * | 26 | * |
30 | * 5. Products derived from this software may not be called "OpenSSL" | 27 | * 5. Products derived from this software may not be called "OpenSSL" |
31 | * nor may "OpenSSL" appear in their names without prior written | 28 | * nor may "OpenSSL" appear in their names without prior written |
@@ -60,6 +57,7 @@ | |||
60 | 57 | ||
61 | #include <openssl/opensslconf.h> | 58 | #include <openssl/opensslconf.h> |
62 | 59 | ||
60 | #include <openssl/asn1t.h> | ||
63 | #include <openssl/bn.h> | 61 | #include <openssl/bn.h> |
64 | #include <openssl/err.h> | 62 | #include <openssl/err.h> |
65 | #include <openssl/evp.h> | 63 | #include <openssl/evp.h> |
@@ -69,6 +67,97 @@ | |||
69 | #include "ec_local.h" | 67 | #include "ec_local.h" |
70 | #include "ecdsa_local.h" | 68 | #include "ecdsa_local.h" |
71 | 69 | ||
70 | static const ASN1_TEMPLATE ECDSA_SIG_seq_tt[] = { | ||
71 | { | ||
72 | .flags = 0, | ||
73 | .tag = 0, | ||
74 | .offset = offsetof(ECDSA_SIG, r), | ||
75 | .field_name = "r", | ||
76 | .item = &BIGNUM_it, | ||
77 | }, | ||
78 | { | ||
79 | .flags = 0, | ||
80 | .tag = 0, | ||
81 | .offset = offsetof(ECDSA_SIG, s), | ||
82 | .field_name = "s", | ||
83 | .item = &BIGNUM_it, | ||
84 | }, | ||
85 | }; | ||
86 | |||
87 | const ASN1_ITEM ECDSA_SIG_it = { | ||
88 | .itype = ASN1_ITYPE_SEQUENCE, | ||
89 | .utype = V_ASN1_SEQUENCE, | ||
90 | .templates = ECDSA_SIG_seq_tt, | ||
91 | .tcount = sizeof(ECDSA_SIG_seq_tt) / sizeof(ASN1_TEMPLATE), | ||
92 | .funcs = NULL, | ||
93 | .size = sizeof(ECDSA_SIG), | ||
94 | .sname = "ECDSA_SIG", | ||
95 | }; | ||
96 | |||
97 | ECDSA_SIG *ECDSA_SIG_new(void); | ||
98 | void ECDSA_SIG_free(ECDSA_SIG *a); | ||
99 | ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **a, const unsigned char **in, long len); | ||
100 | int i2d_ECDSA_SIG(const ECDSA_SIG *a, unsigned char **out); | ||
101 | |||
102 | ECDSA_SIG * | ||
103 | d2i_ECDSA_SIG(ECDSA_SIG **a, const unsigned char **in, long len) | ||
104 | { | ||
105 | return (ECDSA_SIG *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, | ||
106 | &ECDSA_SIG_it); | ||
107 | } | ||
108 | |||
109 | int | ||
110 | i2d_ECDSA_SIG(const ECDSA_SIG *a, unsigned char **out) | ||
111 | { | ||
112 | return ASN1_item_i2d((ASN1_VALUE *)a, out, &ECDSA_SIG_it); | ||
113 | } | ||
114 | |||
115 | ECDSA_SIG * | ||
116 | ECDSA_SIG_new(void) | ||
117 | { | ||
118 | return (ECDSA_SIG *)ASN1_item_new(&ECDSA_SIG_it); | ||
119 | } | ||
120 | |||
121 | void | ||
122 | ECDSA_SIG_free(ECDSA_SIG *a) | ||
123 | { | ||
124 | ASN1_item_free((ASN1_VALUE *)a, &ECDSA_SIG_it); | ||
125 | } | ||
126 | |||
127 | void | ||
128 | ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps) | ||
129 | { | ||
130 | if (pr != NULL) | ||
131 | *pr = sig->r; | ||
132 | if (ps != NULL) | ||
133 | *ps = sig->s; | ||
134 | } | ||
135 | |||
136 | const BIGNUM * | ||
137 | ECDSA_SIG_get0_r(const ECDSA_SIG *sig) | ||
138 | { | ||
139 | return sig->r; | ||
140 | } | ||
141 | |||
142 | const BIGNUM * | ||
143 | ECDSA_SIG_get0_s(const ECDSA_SIG *sig) | ||
144 | { | ||
145 | return sig->s; | ||
146 | } | ||
147 | |||
148 | int | ||
149 | ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s) | ||
150 | { | ||
151 | if (r == NULL || s == NULL) | ||
152 | return 0; | ||
153 | |||
154 | BN_free(sig->r); | ||
155 | BN_free(sig->s); | ||
156 | sig->r = r; | ||
157 | sig->s = s; | ||
158 | return 1; | ||
159 | } | ||
160 | |||
72 | /* | 161 | /* |
73 | * FIPS 186-5, section 6.4.1, step 2: convert hashed message into an integer. | 162 | * FIPS 186-5, section 6.4.1, step 2: convert hashed message into an integer. |
74 | * Use the order_bits leftmost bits if it exceeds the group order. | 163 | * Use the order_bits leftmost bits if it exceeds the group order. |
diff --git a/src/lib/libcrypto/ecdsa/ecs_asn1.c b/src/lib/libcrypto/ecdsa/ecs_asn1.c deleted file mode 100644 index 9e3506cd51..0000000000 --- a/src/lib/libcrypto/ecdsa/ecs_asn1.c +++ /dev/null | |||
@@ -1,151 +0,0 @@ | |||
1 | /* $OpenBSD: ecs_asn1.c,v 1.15 2023/07/05 11:37:46 tb Exp $ */ | ||
2 | /* ==================================================================== | ||
3 | * Copyright (c) 2000-2002 The OpenSSL Project. All rights reserved. | ||
4 | * | ||
5 | * Redistribution and use in source and binary forms, with or without | ||
6 | * modification, are permitted provided that the following conditions | ||
7 | * are met: | ||
8 | * | ||
9 | * 1. Redistributions of source code must retain the above copyright | ||
10 | * notice, this list of conditions and the following disclaimer. | ||
11 | * | ||
12 | * 2. Redistributions in binary form must reproduce the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer in | ||
14 | * the documentation and/or other materials provided with the | ||
15 | * distribution. | ||
16 | * | ||
17 | * 3. All advertising materials mentioning features or use of this | ||
18 | * software must display the following acknowledgment: | ||
19 | * "This product includes software developed by the OpenSSL Project | ||
20 | * for use in the OpenSSL Toolkit. (http://www.OpenSSL.org/)" | ||
21 | * | ||
22 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
23 | * endorse or promote products derived from this software without | ||
24 | * prior written permission. For written permission, please contact | ||
25 | * licensing@OpenSSL.org. | ||
26 | * | ||
27 | * 5. Products derived from this software may not be called "OpenSSL" | ||
28 | * nor may "OpenSSL" appear in their names without prior written | ||
29 | * permission of the OpenSSL Project. | ||
30 | * | ||
31 | * 6. Redistributions of any form whatsoever must retain the following | ||
32 | * acknowledgment: | ||
33 | * "This product includes software developed by the OpenSSL Project | ||
34 | * for use in the OpenSSL Toolkit (http://www.OpenSSL.org/)" | ||
35 | * | ||
36 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
37 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
39 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
40 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
41 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
42 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
43 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
44 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
45 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
46 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
47 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
48 | * ==================================================================== | ||
49 | * | ||
50 | * This product includes cryptographic software written by Eric Young | ||
51 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
52 | * Hudson (tjh@cryptsoft.com). | ||
53 | * | ||
54 | */ | ||
55 | |||
56 | #include <openssl/asn1t.h> | ||
57 | #include <openssl/bn.h> | ||
58 | #include <openssl/err.h> | ||
59 | |||
60 | #include "ecdsa_local.h" | ||
61 | |||
62 | static const ASN1_TEMPLATE ECDSA_SIG_seq_tt[] = { | ||
63 | { | ||
64 | .flags = 0, | ||
65 | .tag = 0, | ||
66 | .offset = offsetof(ECDSA_SIG, r), | ||
67 | .field_name = "r", | ||
68 | .item = &BIGNUM_it, | ||
69 | }, | ||
70 | { | ||
71 | .flags = 0, | ||
72 | .tag = 0, | ||
73 | .offset = offsetof(ECDSA_SIG, s), | ||
74 | .field_name = "s", | ||
75 | .item = &BIGNUM_it, | ||
76 | }, | ||
77 | }; | ||
78 | |||
79 | const ASN1_ITEM ECDSA_SIG_it = { | ||
80 | .itype = ASN1_ITYPE_SEQUENCE, | ||
81 | .utype = V_ASN1_SEQUENCE, | ||
82 | .templates = ECDSA_SIG_seq_tt, | ||
83 | .tcount = sizeof(ECDSA_SIG_seq_tt) / sizeof(ASN1_TEMPLATE), | ||
84 | .funcs = NULL, | ||
85 | .size = sizeof(ECDSA_SIG), | ||
86 | .sname = "ECDSA_SIG", | ||
87 | }; | ||
88 | |||
89 | ECDSA_SIG *ECDSA_SIG_new(void); | ||
90 | void ECDSA_SIG_free(ECDSA_SIG *a); | ||
91 | ECDSA_SIG *d2i_ECDSA_SIG(ECDSA_SIG **a, const unsigned char **in, long len); | ||
92 | int i2d_ECDSA_SIG(const ECDSA_SIG *a, unsigned char **out); | ||
93 | |||
94 | ECDSA_SIG * | ||
95 | d2i_ECDSA_SIG(ECDSA_SIG **a, const unsigned char **in, long len) | ||
96 | { | ||
97 | return (ECDSA_SIG *)ASN1_item_d2i((ASN1_VALUE **)a, in, len, | ||
98 | &ECDSA_SIG_it); | ||
99 | } | ||
100 | |||
101 | int | ||
102 | i2d_ECDSA_SIG(const ECDSA_SIG *a, unsigned char **out) | ||
103 | { | ||
104 | return ASN1_item_i2d((ASN1_VALUE *)a, out, &ECDSA_SIG_it); | ||
105 | } | ||
106 | |||
107 | ECDSA_SIG * | ||
108 | ECDSA_SIG_new(void) | ||
109 | { | ||
110 | return (ECDSA_SIG *)ASN1_item_new(&ECDSA_SIG_it); | ||
111 | } | ||
112 | |||
113 | void | ||
114 | ECDSA_SIG_free(ECDSA_SIG *a) | ||
115 | { | ||
116 | ASN1_item_free((ASN1_VALUE *)a, &ECDSA_SIG_it); | ||
117 | } | ||
118 | |||
119 | void | ||
120 | ECDSA_SIG_get0(const ECDSA_SIG *sig, const BIGNUM **pr, const BIGNUM **ps) | ||
121 | { | ||
122 | if (pr != NULL) | ||
123 | *pr = sig->r; | ||
124 | if (ps != NULL) | ||
125 | *ps = sig->s; | ||
126 | } | ||
127 | |||
128 | const BIGNUM * | ||
129 | ECDSA_SIG_get0_r(const ECDSA_SIG *sig) | ||
130 | { | ||
131 | return sig->r; | ||
132 | } | ||
133 | |||
134 | const BIGNUM * | ||
135 | ECDSA_SIG_get0_s(const ECDSA_SIG *sig) | ||
136 | { | ||
137 | return sig->s; | ||
138 | } | ||
139 | |||
140 | int | ||
141 | ECDSA_SIG_set0(ECDSA_SIG *sig, BIGNUM *r, BIGNUM *s) | ||
142 | { | ||
143 | if (r == NULL || s == NULL) | ||
144 | return 0; | ||
145 | |||
146 | BN_free(sig->r); | ||
147 | BN_free(sig->s); | ||
148 | sig->r = r; | ||
149 | sig->s = s; | ||
150 | return 1; | ||
151 | } | ||