diff options
author | jsing <> | 2023-03-07 05:45:14 +0000 |
---|---|---|
committer | jsing <> | 2023-03-07 05:45:14 +0000 |
commit | 235f35c0a45d4118278b84c1a7135589659ba662 (patch) | |
tree | e8cc747f3c005c616dcd66fe8ac5b63dc612fb7e | |
parent | c39278783bbfc9011f5512b634ec617c2ff00778 (diff) | |
download | openbsd-235f35c0a45d4118278b84c1a7135589659ba662.tar.gz openbsd-235f35c0a45d4118278b84c1a7135589659ba662.tar.bz2 openbsd-235f35c0a45d4118278b84c1a7135589659ba662.zip |
Use static functions for EC_GFp_nist_method() implementation.
Move the EC_METHOD to the bottom of the file, which allows implementation
functions to become static. Remove unneeded prototypes.
ok tb@
-rw-r--r-- | src/lib/libcrypto/ec/ec_local.h | 9 | ||||
-rw-r--r-- | src/lib/libcrypto/ec/ecp_nist.c | 107 |
2 files changed, 53 insertions, 63 deletions
diff --git a/src/lib/libcrypto/ec/ec_local.h b/src/lib/libcrypto/ec/ec_local.h index 1124108d57..677ae0c368 100644 --- a/src/lib/libcrypto/ec/ec_local.h +++ b/src/lib/libcrypto/ec/ec_local.h | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ec_local.h,v 1.7 2023/03/07 05:41:18 jsing Exp $ */ | 1 | /* $OpenBSD: ec_local.h,v 1.8 2023/03/07 05:45:14 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Originally written by Bodo Moeller for the OpenSSL project. | 3 | * Originally written by Bodo Moeller for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -371,13 +371,6 @@ int ec_GFp_simple_mul_double_nonct(const EC_GROUP *, EC_POINT *r, const BIGNUM * | |||
371 | 371 | ||
372 | int ec_point_blind_coordinates(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx); | 372 | int ec_point_blind_coordinates(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx); |
373 | 373 | ||
374 | /* method functions in ecp_nist.c */ | ||
375 | int ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src); | ||
376 | int ec_GFp_nist_group_set_curve(EC_GROUP *, const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *); | ||
377 | int ec_GFp_nist_field_mul(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *); | ||
378 | int ec_GFp_nist_field_sqr(const EC_GROUP *, BIGNUM *r, const BIGNUM *a, BN_CTX *); | ||
379 | |||
380 | |||
381 | /* method functions in ec2_smpl.c */ | 374 | /* method functions in ec2_smpl.c */ |
382 | int ec_GF2m_simple_group_init(EC_GROUP *); | 375 | int ec_GF2m_simple_group_init(EC_GROUP *); |
383 | void ec_GF2m_simple_group_finish(EC_GROUP *); | 376 | void ec_GF2m_simple_group_finish(EC_GROUP *); |
diff --git a/src/lib/libcrypto/ec/ecp_nist.c b/src/lib/libcrypto/ec/ecp_nist.c index cf00d3b11d..3a81a0e8d9 100644 --- a/src/lib/libcrypto/ec/ecp_nist.c +++ b/src/lib/libcrypto/ec/ecp_nist.c | |||
@@ -1,4 +1,4 @@ | |||
1 | /* $OpenBSD: ecp_nist.c,v 1.21 2022/11/26 16:08:52 tb Exp $ */ | 1 | /* $OpenBSD: ecp_nist.c,v 1.22 2023/03/07 05:45:14 jsing Exp $ */ |
2 | /* | 2 | /* |
3 | * Written by Nils Larsch for the OpenSSL project. | 3 | * Written by Nils Larsch for the OpenSSL project. |
4 | */ | 4 | */ |
@@ -68,55 +68,7 @@ | |||
68 | 68 | ||
69 | #include "ec_local.h" | 69 | #include "ec_local.h" |
70 | 70 | ||
71 | const EC_METHOD * | 71 | static int |
72 | EC_GFp_nist_method(void) | ||
73 | { | ||
74 | static const EC_METHOD ret = { | ||
75 | .flags = EC_FLAGS_DEFAULT_OCT, | ||
76 | .field_type = NID_X9_62_prime_field, | ||
77 | .group_init = ec_GFp_simple_group_init, | ||
78 | .group_finish = ec_GFp_simple_group_finish, | ||
79 | .group_clear_finish = ec_GFp_simple_group_clear_finish, | ||
80 | .group_copy = ec_GFp_nist_group_copy, | ||
81 | .group_set_curve = ec_GFp_nist_group_set_curve, | ||
82 | .group_get_curve = ec_GFp_simple_group_get_curve, | ||
83 | .group_get_degree = ec_GFp_simple_group_get_degree, | ||
84 | .group_order_bits = ec_group_simple_order_bits, | ||
85 | .group_check_discriminant = | ||
86 | ec_GFp_simple_group_check_discriminant, | ||
87 | .point_init = ec_GFp_simple_point_init, | ||
88 | .point_finish = ec_GFp_simple_point_finish, | ||
89 | .point_clear_finish = ec_GFp_simple_point_clear_finish, | ||
90 | .point_copy = ec_GFp_simple_point_copy, | ||
91 | .point_set_to_infinity = ec_GFp_simple_point_set_to_infinity, | ||
92 | .point_set_Jprojective_coordinates = | ||
93 | ec_GFp_simple_set_Jprojective_coordinates, | ||
94 | .point_get_Jprojective_coordinates = | ||
95 | ec_GFp_simple_get_Jprojective_coordinates, | ||
96 | .point_set_affine_coordinates = | ||
97 | ec_GFp_simple_point_set_affine_coordinates, | ||
98 | .point_get_affine_coordinates = | ||
99 | ec_GFp_simple_point_get_affine_coordinates, | ||
100 | .add = ec_GFp_simple_add, | ||
101 | .dbl = ec_GFp_simple_dbl, | ||
102 | .invert = ec_GFp_simple_invert, | ||
103 | .is_at_infinity = ec_GFp_simple_is_at_infinity, | ||
104 | .is_on_curve = ec_GFp_simple_is_on_curve, | ||
105 | .point_cmp = ec_GFp_simple_cmp, | ||
106 | .make_affine = ec_GFp_simple_make_affine, | ||
107 | .points_make_affine = ec_GFp_simple_points_make_affine, | ||
108 | .mul_generator_ct = ec_GFp_simple_mul_generator_ct, | ||
109 | .mul_single_ct = ec_GFp_simple_mul_single_ct, | ||
110 | .mul_double_nonct = ec_GFp_simple_mul_double_nonct, | ||
111 | .field_mul = ec_GFp_nist_field_mul, | ||
112 | .field_sqr = ec_GFp_nist_field_sqr, | ||
113 | .blind_coordinates = ec_GFp_simple_blind_coordinates, | ||
114 | }; | ||
115 | |||
116 | return &ret; | ||
117 | } | ||
118 | |||
119 | int | ||
120 | ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src) | 72 | ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src) |
121 | { | 73 | { |
122 | dest->field_mod_func = src->field_mod_func; | 74 | dest->field_mod_func = src->field_mod_func; |
@@ -124,7 +76,7 @@ ec_GFp_nist_group_copy(EC_GROUP *dest, const EC_GROUP *src) | |||
124 | return ec_GFp_simple_group_copy(dest, src); | 76 | return ec_GFp_simple_group_copy(dest, src); |
125 | } | 77 | } |
126 | 78 | ||
127 | int | 79 | static int |
128 | ec_GFp_nist_group_set_curve(EC_GROUP *group, const BIGNUM *p, | 80 | ec_GFp_nist_group_set_curve(EC_GROUP *group, const BIGNUM *p, |
129 | const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) | 81 | const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx) |
130 | { | 82 | { |
@@ -163,8 +115,7 @@ ec_GFp_nist_group_set_curve(EC_GROUP *group, const BIGNUM *p, | |||
163 | return ret; | 115 | return ret; |
164 | } | 116 | } |
165 | 117 | ||
166 | 118 | static int | |
167 | int | ||
168 | ec_GFp_nist_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | 119 | ec_GFp_nist_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, |
169 | const BIGNUM *b, BN_CTX *ctx) | 120 | const BIGNUM *b, BN_CTX *ctx) |
170 | { | 121 | { |
@@ -190,8 +141,7 @@ ec_GFp_nist_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | |||
190 | return ret; | 141 | return ret; |
191 | } | 142 | } |
192 | 143 | ||
193 | 144 | static int | |
194 | int | ||
195 | ec_GFp_nist_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | 145 | ec_GFp_nist_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, |
196 | BN_CTX *ctx) | 146 | BN_CTX *ctx) |
197 | { | 147 | { |
@@ -216,3 +166,50 @@ ec_GFp_nist_field_sqr(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, | |||
216 | BN_CTX_free(ctx_new); | 166 | BN_CTX_free(ctx_new); |
217 | return ret; | 167 | return ret; |
218 | } | 168 | } |
169 | |||
170 | static const EC_METHOD ec_GFp_nist_method = { | ||
171 | .flags = EC_FLAGS_DEFAULT_OCT, | ||
172 | .field_type = NID_X9_62_prime_field, | ||
173 | .group_init = ec_GFp_simple_group_init, | ||
174 | .group_finish = ec_GFp_simple_group_finish, | ||
175 | .group_clear_finish = ec_GFp_simple_group_clear_finish, | ||
176 | .group_copy = ec_GFp_nist_group_copy, | ||
177 | .group_set_curve = ec_GFp_nist_group_set_curve, | ||
178 | .group_get_curve = ec_GFp_simple_group_get_curve, | ||
179 | .group_get_degree = ec_GFp_simple_group_get_degree, | ||
180 | .group_order_bits = ec_group_simple_order_bits, | ||
181 | .group_check_discriminant = ec_GFp_simple_group_check_discriminant, | ||
182 | .point_init = ec_GFp_simple_point_init, | ||
183 | .point_finish = ec_GFp_simple_point_finish, | ||
184 | .point_clear_finish = ec_GFp_simple_point_clear_finish, | ||
185 | .point_copy = ec_GFp_simple_point_copy, | ||
186 | .point_set_to_infinity = ec_GFp_simple_point_set_to_infinity, | ||
187 | .point_set_Jprojective_coordinates = | ||
188 | ec_GFp_simple_set_Jprojective_coordinates, | ||
189 | .point_get_Jprojective_coordinates = | ||
190 | ec_GFp_simple_get_Jprojective_coordinates, | ||
191 | .point_set_affine_coordinates = | ||
192 | ec_GFp_simple_point_set_affine_coordinates, | ||
193 | .point_get_affine_coordinates = | ||
194 | ec_GFp_simple_point_get_affine_coordinates, | ||
195 | .add = ec_GFp_simple_add, | ||
196 | .dbl = ec_GFp_simple_dbl, | ||
197 | .invert = ec_GFp_simple_invert, | ||
198 | .is_at_infinity = ec_GFp_simple_is_at_infinity, | ||
199 | .is_on_curve = ec_GFp_simple_is_on_curve, | ||
200 | .point_cmp = ec_GFp_simple_cmp, | ||
201 | .make_affine = ec_GFp_simple_make_affine, | ||
202 | .points_make_affine = ec_GFp_simple_points_make_affine, | ||
203 | .mul_generator_ct = ec_GFp_simple_mul_generator_ct, | ||
204 | .mul_single_ct = ec_GFp_simple_mul_single_ct, | ||
205 | .mul_double_nonct = ec_GFp_simple_mul_double_nonct, | ||
206 | .field_mul = ec_GFp_nist_field_mul, | ||
207 | .field_sqr = ec_GFp_nist_field_sqr, | ||
208 | .blind_coordinates = ec_GFp_simple_blind_coordinates, | ||
209 | }; | ||
210 | |||
211 | const EC_METHOD * | ||
212 | EC_GFp_nist_method(void) | ||
213 | { | ||
214 | return &ec_GFp_nist_method; | ||
215 | } | ||