From 370cdaebb1223cc6e62b791c2bb4d5815aafba2d Mon Sep 17 00:00:00 2001 From: igerasim Date: Tue, 23 May 2017 11:30:25 -0700 Subject: [PATCH] 8178135: Additional elliptic curve support Reviewed-by: mullan --- src/share/native/sun/security/ec/impl/ecp_jac.c | 9 +++++++++ src/share/native/sun/security/ec/impl/ecp_jm.c | 10 ++++++++++ 2 files changed, 19 insertions(+) diff --git a/src/share/native/sun/security/ec/impl/ecp_jac.c b/src/share/native/sun/security/ec/impl/ecp_jac.c index 12410bea6..716d931f1 100644 --- a/src/share/native/sun/security/ec/impl/ecp_jac.c +++ b/src/share/native/sun/security/ec/impl/ecp_jac.c @@ -180,6 +180,15 @@ ec_GFp_pt_add_jac_aff(const mp_int *px, const mp_int *py, const mp_int *pz, MP_CHECKOK(group->meth->field_mul(&A, qx, &A, group->meth)); MP_CHECKOK(group->meth->field_mul(&B, qy, &B, group->meth)); + /* + * Additional checks for point equality and point at infinity + */ + if (mp_cmp(px, &A) == 0 && mp_cmp(py, &B) == 0) { + /* POINT_DOUBLE(P) */ + MP_CHECKOK(ec_GFp_pt_dbl_jac(px, py, pz, rx, ry, rz, group)); + goto CLEANUP; + } + /* C = A - px, D = B - py */ MP_CHECKOK(group->meth->field_sub(&A, px, &C, group->meth)); MP_CHECKOK(group->meth->field_sub(&B, py, &D, group->meth)); diff --git a/src/share/native/sun/security/ec/impl/ecp_jm.c b/src/share/native/sun/security/ec/impl/ecp_jm.c index cdee87a59..440d0b3fb 100644 --- a/src/share/native/sun/security/ec/impl/ecp_jm.c +++ b/src/share/native/sun/security/ec/impl/ecp_jm.c @@ -165,6 +165,16 @@ ec_GFp_pt_add_jm_aff(const mp_int *px, const mp_int *py, const mp_int *pz, MP_CHECKOK(group->meth->field_mul(A, qx, A, group->meth)); MP_CHECKOK(group->meth->field_mul(B, qy, B, group->meth)); + /* + * Additional checks for point equality and point at infinity + */ + if (mp_cmp(px, A) == 0 && mp_cmp(py, B) == 0) { + /* POINT_DOUBLE(P) */ + MP_CHECKOK(ec_GFp_pt_dbl_jm(px, py, pz, paz4, rx, ry, rz, raz4, + scratch, group)); + goto CLEANUP; + } + /* C = A - px, D = B - py */ MP_CHECKOK(group->meth->field_sub(A, px, C, group->meth)); MP_CHECKOK(group->meth->field_sub(B, py, D, group->meth)); -- GitLab