diff options
author | Bodo Möller <bodo@openssl.org> | 2002-03-20 10:18:07 +0000 |
---|---|---|
committer | Bodo Möller <bodo@openssl.org> | 2002-03-20 10:18:07 +0000 |
commit | 17d6bb815813bab443a29cfd821d876afc9ecfef (patch) | |
tree | dedfc9937bdffa5b9d483c792653fb7781ca26ad /crypto/ec/ecp_smpl.c | |
parent | 11c26ecf810bbeb0293921b86cd75f61809947b0 (diff) |
New function EC_GROUP_check_discriminant().
Restructure implementation of EC_GROUP_check().
Submitted by: Nils Larsch
Diffstat (limited to 'crypto/ec/ecp_smpl.c')
-rw-r--r-- | crypto/ec/ecp_smpl.c | 50 |
1 files changed, 5 insertions, 45 deletions
diff --git a/crypto/ec/ecp_smpl.c b/crypto/ec/ecp_smpl.c index 8e062dc951..911a4e4760 100644 --- a/crypto/ec/ecp_smpl.c +++ b/crypto/ec/ecp_smpl.c @@ -73,7 +73,7 @@ const EC_METHOD *EC_GFp_simple_method(void) ec_GFp_simple_group_get0_generator, ec_GFp_simple_group_get_order, ec_GFp_simple_group_get_cofactor, - ec_GFp_simple_group_check, + ec_GFp_simple_group_check_discriminant, ec_GFp_simple_point_init, ec_GFp_simple_point_finish, ec_GFp_simple_point_clear_finish, @@ -339,20 +339,19 @@ int ec_GFp_simple_group_get_cofactor(const EC_GROUP *group, BIGNUM *cofactor, BN } -int ec_GFp_simple_group_check(const EC_GROUP *group, BN_CTX *ctx) +int ec_GFp_simple_group_check_discriminant(const EC_GROUP *group, BN_CTX *ctx) { int ret = 0; BIGNUM *a,*b,*order,*tmp_1,*tmp_2; const BIGNUM *p = &group->field; BN_CTX *new_ctx = NULL; - EC_POINT *point = NULL; if (ctx == NULL) { ctx = new_ctx = BN_CTX_new(); if (ctx == NULL) { - ECerr(EC_F_EC_GFP_SIMPLE_GROUP_CHECK, ERR_R_MALLOC_FAILURE); + ECerr(EC_F_EC_GFP_SIMPLE_GROUP_CHECK_DISCRIMINANT, ERR_R_MALLOC_FAILURE); goto err; } } @@ -380,11 +379,7 @@ int ec_GFp_simple_group_check(const EC_GROUP *group, BN_CTX *ctx) * 0 =< a, b < p */ if (BN_is_zero(a)) { - if (BN_is_zero(b)) - { - ECerr(EC_F_EC_GFP_SIMPLE_GROUP_CHECK, EC_R_DISCRIMINANT_IS_ZERO); - goto err; - } + if (BN_is_zero(b)) goto err; } else if (!BN_is_zero(b)) { @@ -398,49 +393,14 @@ int ec_GFp_simple_group_check(const EC_GROUP *group, BN_CTX *ctx) /* tmp_2 = 27*b^2 */ if (!BN_mod_add(a, tmp_1, tmp_2, p, ctx)) goto err; - if (BN_is_zero(a)) - { - ECerr(EC_F_EC_GFP_SIMPLE_GROUP_CHECK, EC_R_DISCRIMINANT_IS_ZERO); - goto err; - } + if (BN_is_zero(a)) goto err; } - - /* check the generator */ - if (group->generator == NULL) - { - ECerr(EC_F_EC_GFP_SIMPLE_GROUP_CHECK, EC_R_UNDEFINED_GENERATOR); - goto err; - } - if (!ec_GFp_simple_is_on_curve(group, group->generator, ctx)) - { - ECerr(EC_F_EC_GFP_SIMPLE_GROUP_CHECK, EC_R_POINT_IS_NOT_ON_CURVE); - goto err; - } - - /* check the order of the generator */ - if ((point = EC_POINT_new(group)) == NULL) goto err; - if (!EC_GROUP_get_order(group, order, ctx)) goto err; - if (BN_is_zero(order)) - { - ECerr(EC_F_EC_GFP_SIMPLE_GROUP_CHECK, EC_R_UNDEFINED_ORDER); - goto err; - } - - if (!EC_POINT_mul(group, point, order, NULL, NULL, ctx)) goto err; - if (!EC_POINT_is_at_infinity(group, point)) - { - ECerr(EC_F_EC_GFP_SIMPLE_GROUP_CHECK, EC_R_INVALID_GROUP_ORDER); - goto err; - } - ret = 1; err: BN_CTX_end(ctx); if (new_ctx != NULL) BN_CTX_free(new_ctx); - if (point) - EC_POINT_free(point); return ret; } |