8178135: Additional elliptic curve support
authorvinnie
Tue, 23 May 2017 16:59:50 +0100
changeset 45994 25cb5143b701
parent 45993 076a6b39a5a9
child 45995 711620fe3171
8178135: Additional elliptic curve support Reviewed-by: mullan
jdk/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_jac.c
jdk/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_jm.c
--- a/jdk/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_jac.c	Fri May 12 17:30:47 2017 +0100
+++ b/jdk/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_jac.c	Tue May 23 16:59:50 2017 +0100
@@ -181,6 +181,15 @@
         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));
--- a/jdk/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_jm.c	Fri May 12 17:30:47 2017 +0100
+++ b/jdk/src/jdk.crypto.ec/share/native/libsunec/impl/ecp_jm.c	Tue May 23 16:59:50 2017 +0100
@@ -166,6 +166,16 @@
         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));