diff options
author | tb <> | 2023-04-25 17:42:07 +0000 |
---|---|---|
committer | tb <> | 2023-04-25 17:42:07 +0000 |
commit | c99645e206c6a6fd786d7548a1c886d5b2d6c9cb (patch) | |
tree | 6dff91fd2b36aed111abc1147137b91c71f95e39 /src/lib/libcrypto/ec | |
parent | dfacb5f80885e54f09c7b607c4c2aa10d9f2d2cb (diff) | |
download | openbsd-c99645e206c6a6fd786d7548a1c886d5b2d6c9cb.tar.gz openbsd-c99645e206c6a6fd786d7548a1c886d5b2d6c9cb.tar.bz2 openbsd-c99645e206c6a6fd786d7548a1c886d5b2d6c9cb.zip |
Remove the horror show that is bn_nist and ecp_nist
This code is full of problematic C and is also otherwise of questionable
quality. It is far from constant time and jsing informs me it also isn't
faster. Good riddance.
Diffstat (limited to 'src/lib/libcrypto/ec')
-rw-r--r-- | src/lib/libcrypto/ec/ecp_nist.c | 177 |
1 files changed, 0 insertions, 177 deletions
diff --git a/src/lib/libcrypto/ec/ecp_nist.c b/src/lib/libcrypto/ec/ecp_nist.c deleted file mode 100644 index 9478b4dc6e..0000000000 --- a/src/lib/libcrypto/ec/ecp_nist.c +++ /dev/null | |||
@@ -1,177 +0,0 @@ | |||
1 | /* $OpenBSD: ecp_nist.c,v 1.26 2023/04/11 18:58:20 jsing Exp $ */ | ||
2 | /* | ||
3 | * Written by Nils Larsch for the OpenSSL project. | ||
4 | */ | ||
5 | /* ==================================================================== | ||
6 | * Copyright (c) 1998-2003 The OpenSSL Project. All rights reserved. | ||
7 | * | ||
8 | * Redistribution and use in source and binary forms, with or without | ||
9 | * modification, are permitted provided that the following conditions | ||
10 | * are met: | ||
11 | * | ||
12 | * 1. Redistributions of source code must retain the above copyright | ||
13 | * notice, this list of conditions and the following disclaimer. | ||
14 | * | ||
15 | * 2. Redistributions in binary form must reproduce the above copyright | ||
16 | * notice, this list of conditions and the following disclaimer in | ||
17 | * the documentation and/or other materials provided with the | ||
18 | * distribution. | ||
19 | * | ||
20 | * 3. All advertising materials mentioning features or use of this | ||
21 | * software must display the following acknowledgment: | ||
22 | * "This product includes software developed by the OpenSSL Project | ||
23 | * for use in the OpenSSL Toolkit. (http://www.openssl.org/)" | ||
24 | * | ||
25 | * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to | ||
26 | * endorse or promote products derived from this software without | ||
27 | * prior written permission. For written permission, please contact | ||
28 | * openssl-core@openssl.org. | ||
29 | * | ||
30 | * 5. Products derived from this software may not be called "OpenSSL" | ||
31 | * nor may "OpenSSL" appear in their names without prior written | ||
32 | * permission of the OpenSSL Project. | ||
33 | * | ||
34 | * 6. Redistributions of any form whatsoever must retain the following | ||
35 | * acknowledgment: | ||
36 | * "This product includes software developed by the OpenSSL Project | ||
37 | * for use in the OpenSSL Toolkit (http://www.openssl.org/)" | ||
38 | * | ||
39 | * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY | ||
40 | * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
41 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
42 | * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR | ||
43 | * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
44 | * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | ||
45 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | ||
46 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, | ||
48 | * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
49 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED | ||
50 | * OF THE POSSIBILITY OF SUCH DAMAGE. | ||
51 | * ==================================================================== | ||
52 | * | ||
53 | * This product includes cryptographic software written by Eric Young | ||
54 | * (eay@cryptsoft.com). This product includes software written by Tim | ||
55 | * Hudson (tjh@cryptsoft.com). | ||
56 | * | ||
57 | */ | ||
58 | /* ==================================================================== | ||
59 | * Copyright 2002 Sun Microsystems, Inc. ALL RIGHTS RESERVED. | ||
60 | * Portions of this software developed by SUN MICROSYSTEMS, INC., | ||
61 | * and contributed to the OpenSSL project. | ||
62 | */ | ||
63 | |||
64 | #include <limits.h> | ||
65 | |||
66 | #include <openssl/err.h> | ||
67 | #include <openssl/objects.h> | ||
68 | |||
69 | #include "ec_local.h" | ||
70 | |||
71 | static int | ||
72 | ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src) | ||
73 | { | ||
74 | dest->field_mod_func = src->field_mod_func; | ||
75 | |||
76 | return ec_GFp_simple_group_copy(dest, src); | ||
77 | } | ||
78 | |||
79 | static int | ||
80 | ec_GFp_nist_group_set_curve(EC_GROUP *group, const BIGNUM *p, | ||
81 | const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) | ||
82 | { | ||
83 | if (BN_ucmp(BN_get0_nist_prime_192(), p) == 0) | ||
84 | group->field_mod_func = BN_nist_mod_192; | ||
85 | else if (BN_ucmp(BN_get0_nist_prime_224(), p) == 0) | ||
86 | group->field_mod_func = BN_nist_mod_224; | ||
87 | else if (BN_ucmp(BN_get0_nist_prime_256(), p) == 0) | ||
88 | group->field_mod_func = BN_nist_mod_256; | ||
89 | else if (BN_ucmp(BN_get0_nist_prime_384(), p) == 0) | ||
90 | group->field_mod_func = BN_nist_mod_384; | ||
91 | else if (BN_ucmp(BN_get0_nist_prime_521(), p) == 0) | ||
92 | group->field_mod_func = BN_nist_mod_521; | ||
93 | else { | ||
94 | ECerror(EC_R_NOT_A_NIST_PRIME); | ||
95 | return 0; | ||
96 | } | ||
97 | |||
98 | return ec_GFp_simple_group_set_curve(group, p, a, b, ctx); | ||
99 | } | ||
100 | |||
101 | static int | ||
102 | ec_GFp_nist_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | ||
103 | const BIGNUM *b, BN_CTX *ctx) | ||
104 | { | ||
105 | if (group == NULL || r == NULL || a == NULL || b == NULL) { | ||
106 | ECerror(ERR_R_PASSED_NULL_PARAMETER); | ||
107 | return 0; | ||
108 | } | ||
109 | |||
110 | if (!BN_mul(r, a, b, ctx)) | ||
111 | return 0; | ||
112 | |||
113 | return group->field_mod_func(r, r, &group->field, ctx); | ||
114 | } | ||
115 | |||
116 | static int | ||
117 | ec_GFp_nist_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | ||
118 | BN_CTX *ctx) | ||
119 | { | ||
120 | if (group == NULL || r == NULL || a == NULL) { | ||
121 | ECerror(EC_R_PASSED_NULL_PARAMETER); | ||
122 | return 0; | ||
123 | } | ||
124 | |||
125 | if (!BN_sqr(r, a, ctx)) | ||
126 | return 0; | ||
127 | |||
128 | return group->field_mod_func(r, r, &group->field, ctx); | ||
129 | } | ||
130 | |||
131 | static const EC_METHOD ec_GFp_nist_method = { | ||
132 | .field_type = NID_X9_62_prime_field, | ||
133 | .group_init = ec_GFp_simple_group_init, | ||
134 | .group_finish = ec_GFp_simple_group_finish, | ||
135 | .group_copy = ec_GFp_nist_group_copy, | ||
136 | .group_set_curve = ec_GFp_nist_group_set_curve, | ||
137 | .group_get_curve = ec_GFp_simple_group_get_curve, | ||
138 | .group_get_degree = ec_GFp_simple_group_get_degree, | ||
139 | .group_order_bits = ec_group_simple_order_bits, | ||
140 | .group_check_discriminant = ec_GFp_simple_group_check_discriminant, | ||
141 | .point_init = ec_GFp_simple_point_init, | ||
142 | .point_finish = ec_GFp_simple_point_finish, | ||
143 | .point_copy = ec_GFp_simple_point_copy, | ||
144 | .point_set_to_infinity = ec_GFp_simple_point_set_to_infinity, | ||
145 | .point_set_Jprojective_coordinates = | ||
146 | ec_GFp_simple_set_Jprojective_coordinates, | ||
147 | .point_get_Jprojective_coordinates = | ||
148 | ec_GFp_simple_get_Jprojective_coordinates, | ||
149 | .point_set_affine_coordinates = | ||
150 | ec_GFp_simple_point_set_affine_coordinates, | ||
151 | .point_get_affine_coordinates = | ||
152 | ec_GFp_simple_point_get_affine_coordinates, | ||
153 | .point_set_compressed_coordinates = | ||
154 | ec_GFp_simple_set_compressed_coordinates, | ||
155 | .point2oct = ec_GFp_simple_point2oct, | ||
156 | .oct2point = ec_GFp_simple_oct2point, | ||
157 | .add = ec_GFp_simple_add, | ||
158 | .dbl = ec_GFp_simple_dbl, | ||
159 | .invert = ec_GFp_simple_invert, | ||
160 | .is_at_infinity = ec_GFp_simple_is_at_infinity, | ||
161 | .is_on_curve = ec_GFp_simple_is_on_curve, | ||
162 | .point_cmp = ec_GFp_simple_cmp, | ||
163 | .make_affine = ec_GFp_simple_make_affine, | ||
164 | .points_make_affine = ec_GFp_simple_points_make_affine, | ||
165 | .mul_generator_ct = ec_GFp_simple_mul_generator_ct, | ||
166 | .mul_single_ct = ec_GFp_simple_mul_single_ct, | ||
167 | .mul_double_nonct = ec_GFp_simple_mul_double_nonct, | ||
168 | .field_mul = ec_GFp_nist_field_mul, | ||
169 | .field_sqr = ec_GFp_nist_field_sqr, | ||
170 | .blind_coordinates = ec_GFp_simple_blind_coordinates, | ||
171 | }; | ||
172 | |||
173 | const EC_METHOD * | ||
174 | EC_GFp_nist_method(void) | ||
175 | { | ||
176 | return &ec_GFp_nist_method; | ||
177 | } | ||