summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorJoel Sing <jsing@cvs.openbsd.org>2023-03-07 05:54:41 +0000
committerJoel Sing <jsing@cvs.openbsd.org>2023-03-07 05:54:41 +0000
commitb1cd8422853449a0e33b9e9480afd1690f50220f (patch)
tree02f69d96b4d56a9fb95fd77238cff7f7cdd0838f /lib
parent936406103e8535ef2ae48d5842cffa7fd0903be3 (diff)
Move EC_GFp_simple_method() to the bottom of the file.
Most of the implemeentation functions for EC_GFp_simple_method() are reused by other code, hence they cannot be made static. However, this keeps the pattern consistent. ok tb@
Diffstat (limited to 'lib')
-rw-r--r--lib/libcrypto/ec/ecp_smpl.c126
1 files changed, 51 insertions, 75 deletions
diff --git a/lib/libcrypto/ec/ecp_smpl.c b/lib/libcrypto/ec/ecp_smpl.c
index dc3b3926d18..8f53b150b8c 100644
--- a/lib/libcrypto/ec/ecp_smpl.c
+++ b/lib/libcrypto/ec/ecp_smpl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: ecp_smpl.c,v 1.38 2022/11/26 16:08:52 tb Exp $ */
+/* $OpenBSD: ecp_smpl.c,v 1.39 2023/03/07 05:54:40 jsing Exp $ */
/* Includes code written by Lenka Fibikova <fibikova@exp-math.uni-essen.de>
* for the OpenSSL project.
* Includes code written by Bodo Moeller for the OpenSSL project.
@@ -67,69 +67,20 @@
#include "bn_local.h"
#include "ec_local.h"
-const EC_METHOD *
-EC_GFp_simple_method(void)
-{
- static const EC_METHOD ret = {
- .flags = EC_FLAGS_DEFAULT_OCT,
- .field_type = NID_X9_62_prime_field,
- .group_init = ec_GFp_simple_group_init,
- .group_finish = ec_GFp_simple_group_finish,
- .group_clear_finish = ec_GFp_simple_group_clear_finish,
- .group_copy = ec_GFp_simple_group_copy,
- .group_set_curve = ec_GFp_simple_group_set_curve,
- .group_get_curve = ec_GFp_simple_group_get_curve,
- .group_get_degree = ec_GFp_simple_group_get_degree,
- .group_order_bits = ec_group_simple_order_bits,
- .group_check_discriminant =
- ec_GFp_simple_group_check_discriminant,
- .point_init = ec_GFp_simple_point_init,
- .point_finish = ec_GFp_simple_point_finish,
- .point_clear_finish = ec_GFp_simple_point_clear_finish,
- .point_copy = ec_GFp_simple_point_copy,
- .point_set_to_infinity = ec_GFp_simple_point_set_to_infinity,
- .point_set_Jprojective_coordinates =
- ec_GFp_simple_set_Jprojective_coordinates,
- .point_get_Jprojective_coordinates =
- ec_GFp_simple_get_Jprojective_coordinates,
- .point_set_affine_coordinates =
- ec_GFp_simple_point_set_affine_coordinates,
- .point_get_affine_coordinates =
- ec_GFp_simple_point_get_affine_coordinates,
- .add = ec_GFp_simple_add,
- .dbl = ec_GFp_simple_dbl,
- .invert = ec_GFp_simple_invert,
- .is_at_infinity = ec_GFp_simple_is_at_infinity,
- .is_on_curve = ec_GFp_simple_is_on_curve,
- .point_cmp = ec_GFp_simple_cmp,
- .make_affine = ec_GFp_simple_make_affine,
- .points_make_affine = ec_GFp_simple_points_make_affine,
- .mul_generator_ct = ec_GFp_simple_mul_generator_ct,
- .mul_single_ct = ec_GFp_simple_mul_single_ct,
- .mul_double_nonct = ec_GFp_simple_mul_double_nonct,
- .field_mul = ec_GFp_simple_field_mul,
- .field_sqr = ec_GFp_simple_field_sqr,
- .blind_coordinates = ec_GFp_simple_blind_coordinates,
- };
-
- return &ret;
-}
-
-
-/* Most method functions in this file are designed to work with
+/*
+ * Most method functions in this file are designed to work with
* non-trivial representations of field elements if necessary
* (see ecp_mont.c): while standard modular addition and subtraction
* are used, the field_mul and field_sqr methods will be used for
* multiplication, and field_encode and field_decode (if defined)
* will be used for converting between representations.
-
+ *
* Functions ec_GFp_simple_points_make_affine() and
* ec_GFp_simple_point_get_affine_coordinates() specifically assume
* that if a non-trivial representation is used, it is a Montgomery
* representation (i.e. 'encoding' means multiplying by some factor R).
*/
-
int
ec_GFp_simple_group_init(EC_GROUP *group)
{
@@ -140,7 +91,6 @@ ec_GFp_simple_group_init(EC_GROUP *group)
return 1;
}
-
void
ec_GFp_simple_group_finish(EC_GROUP *group)
{
@@ -149,7 +99,6 @@ ec_GFp_simple_group_finish(EC_GROUP *group)
BN_free(&group->b);
}
-
void
ec_GFp_simple_group_clear_finish(EC_GROUP *group)
{
@@ -158,7 +107,6 @@ ec_GFp_simple_group_clear_finish(EC_GROUP *group)
BN_clear_free(&group->b);
}
-
int
ec_GFp_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src)
{
@@ -174,7 +122,6 @@ ec_GFp_simple_group_copy(EC_GROUP *dest, const EC_GROUP *src)
return 1;
}
-
int
ec_GFp_simple_group_set_curve(EC_GROUP *group,
const BIGNUM *p, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
@@ -231,7 +178,6 @@ ec_GFp_simple_group_set_curve(EC_GROUP *group,
return ret;
}
-
int
ec_GFp_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNUM *b, BN_CTX *ctx)
{
@@ -275,14 +221,12 @@ ec_GFp_simple_group_get_curve(const EC_GROUP *group, BIGNUM *p, BIGNUM *a, BIGNU
return ret;
}
-
int
ec_GFp_simple_group_get_degree(const EC_GROUP *group)
{
return BN_num_bits(&group->field);
}
-
int
ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx)
{
@@ -358,7 +302,6 @@ ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx)
return ret;
}
-
int
ec_GFp_simple_point_init(EC_POINT * point)
{
@@ -370,7 +313,6 @@ ec_GFp_simple_point_init(EC_POINT * point)
return 1;
}
-
void
ec_GFp_simple_point_finish(EC_POINT *point)
{
@@ -379,7 +321,6 @@ ec_GFp_simple_point_finish(EC_POINT *point)
BN_free(&point->Z);
}
-
void
ec_GFp_simple_point_clear_finish(EC_POINT *point)
{
@@ -389,7 +330,6 @@ ec_GFp_simple_point_clear_finish(EC_POINT *point)
point->Z_is_one = 0;
}
-
int
ec_GFp_simple_point_copy(EC_POINT *dest, const EC_POINT *src)
{
@@ -404,7 +344,6 @@ ec_GFp_simple_point_copy(EC_POINT *dest, const EC_POINT *src)
return 1;
}
-
int
ec_GFp_simple_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point)
{
@@ -413,7 +352,6 @@ ec_GFp_simple_point_set_to_infinity(const EC_GROUP *group, EC_POINT *point)
return 1;
}
-
int
ec_GFp_simple_set_Jprojective_coordinates(const EC_GROUP *group,
EC_POINT *point, const BIGNUM *x, const BIGNUM *y, const BIGNUM *z,
@@ -822,7 +760,6 @@ ec_GFp_simple_add(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, const E
return ret;
}
-
int
ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX *ctx)
{
@@ -964,7 +901,6 @@ ec_GFp_simple_dbl(const EC_GROUP *group, EC_POINT *r, const EC_POINT *a, BN_CTX
return ret;
}
-
int
ec_GFp_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
{
@@ -975,14 +911,12 @@ ec_GFp_simple_invert(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
return BN_usub(&point->Y, &group->field, &point->Y);
}
-
int
ec_GFp_simple_is_at_infinity(const EC_GROUP *group, const EC_POINT *point)
{
return BN_is_zero(&point->Z);
}
-
int
ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *ctx)
{
@@ -1085,7 +1019,6 @@ ec_GFp_simple_is_on_curve(const EC_GROUP *group, const EC_POINT *point, BN_CTX *
return ret;
}
-
int
ec_GFp_simple_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, BN_CTX *ctx)
{
@@ -1187,7 +1120,6 @@ ec_GFp_simple_cmp(const EC_GROUP *group, const EC_POINT *a, const EC_POINT *b, B
return ret;
}
-
int
ec_GFp_simple_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
{
@@ -1225,7 +1157,6 @@ ec_GFp_simple_make_affine(const EC_GROUP *group, EC_POINT *point, BN_CTX *ctx)
return ret;
}
-
int
ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT *points[], BN_CTX *ctx)
{
@@ -1400,7 +1331,6 @@ ec_GFp_simple_points_make_affine(const EC_GROUP *group, size_t num, EC_POINT *po
return ret;
}
-
int
ec_GFp_simple_field_mul(const EC_GROUP *group, BIGNUM *r, const BIGNUM *a, const BIGNUM *b, BN_CTX *ctx)
{
@@ -1471,7 +1401,6 @@ ec_GFp_simple_blind_coordinates(const EC_GROUP *group, EC_POINT *p, BN_CTX *ctx)
return ret;
}
-
#define EC_POINT_BN_set_flags(P, flags) do { \
BN_set_flags(&(P)->X, (flags)); \
BN_set_flags(&(P)->Y, (flags)); \
@@ -1723,3 +1652,50 @@ ec_GFp_simple_mul_double_nonct(const EC_GROUP *group, EC_POINT *r,
{
return ec_wNAF_mul(group, r, g_scalar, 1, &point, &p_scalar, ctx);
}
+
+static const EC_METHOD ec_GFp_simple_method = {
+ .flags = EC_FLAGS_DEFAULT_OCT,
+ .field_type = NID_X9_62_prime_field,
+ .group_init = ec_GFp_simple_group_init,
+ .group_finish = ec_GFp_simple_group_finish,
+ .group_clear_finish = ec_GFp_simple_group_clear_finish,
+ .group_copy = ec_GFp_simple_group_copy,
+ .group_set_curve = ec_GFp_simple_group_set_curve,
+ .group_get_curve = ec_GFp_simple_group_get_curve,
+ .group_get_degree = ec_GFp_simple_group_get_degree,
+ .group_order_bits = ec_group_simple_order_bits,
+ .group_check_discriminant = ec_GFp_simple_group_check_discriminant,
+ .point_init = ec_GFp_simple_point_init,
+ .point_finish = ec_GFp_simple_point_finish,
+ .point_clear_finish = ec_GFp_simple_point_clear_finish,
+ .point_copy = ec_GFp_simple_point_copy,
+ .point_set_to_infinity = ec_GFp_simple_point_set_to_infinity,
+ .point_set_Jprojective_coordinates =
+ ec_GFp_simple_set_Jprojective_coordinates,
+ .point_get_Jprojective_coordinates =
+ ec_GFp_simple_get_Jprojective_coordinates,
+ .point_set_affine_coordinates =
+ ec_GFp_simple_point_set_affine_coordinates,
+ .point_get_affine_coordinates =
+ ec_GFp_simple_point_get_affine_coordinates,
+ .add = ec_GFp_simple_add,
+ .dbl = ec_GFp_simple_dbl,
+ .invert = ec_GFp_simple_invert,
+ .is_at_infinity = ec_GFp_simple_is_at_infinity,
+ .is_on_curve = ec_GFp_simple_is_on_curve,
+ .point_cmp = ec_GFp_simple_cmp,
+ .make_affine = ec_GFp_simple_make_affine,
+ .points_make_affine = ec_GFp_simple_points_make_affine,
+ .mul_generator_ct = ec_GFp_simple_mul_generator_ct,
+ .mul_single_ct = ec_GFp_simple_mul_single_ct,
+ .mul_double_nonct = ec_GFp_simple_mul_double_nonct,
+ .field_mul = ec_GFp_simple_field_mul,
+ .field_sqr = ec_GFp_simple_field_sqr,
+ .blind_coordinates = ec_GFp_simple_blind_coordinates,
+};
+
+const EC_METHOD *
+EC_GFp_simple_method(void)
+{
+ return &ec_GFp_simple_method;
+}