Skip to content

Commit 4427d1a

Browse files
committed
Add is_y_even method to ECPoint
1 parent 5c5f42c commit 4427d1a

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

JCMathLib/src/opencrypto/jcmathlib/ECPoint.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,21 @@ private void from_x(Bignat x) {
468468
ech.unlock(ech.uncompressed_point_arr1);
469469
}
470470

471+
/**
472+
* Returns true if Y coordinate is even; false otherwise.
473+
*
474+
* @return true if Y coordinate is even; false otherwise
475+
*/
476+
public boolean is_y_even() {
477+
ech.fnc_is_y.lock();
478+
ech.lock(ech.uncompressed_point_arr1);
479+
thePoint.getW(ech.uncompressed_point_arr1, (short) 0);
480+
boolean result = ech.uncompressed_point_arr1[(short)(theCurve.POINT_SIZE - 1)] % 2 == 0;
481+
ech.unlock(ech.uncompressed_point_arr1);
482+
ech.fnc_is_y.unlock();
483+
return result;
484+
}
485+
471486
/**
472487
* Compares this and provided point for equality. The comparison is made using hash of both values to prevent leak of position of mismatching byte.
473488
* @param other second point for comparison

JCMathLib/src/opencrypto/jcmathlib/ECPoint_Helper.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public class ECPoint_Helper extends Base_Helper {
1515
public static final byte Signature_ALG_ECDSA_SHA_256 = (byte) 33;
1616

1717
/**
18-
* I true, fast multiplication of ECPoints via KeyAgreement can be used Is
18+
* If true, fast multiplication of ECPoints via KeyAgreement can be used. Is
1919
* set automatically after successful allocation of required engines
2020
*/
2121
public boolean FLAG_FAST_EC_MULT_VIA_KA = false;
@@ -45,6 +45,8 @@ public class ECPoint_Helper extends Base_Helper {
4545
Bignat fnc_from_x_y_sq;
4646
Bignat fnc_from_x_y;
4747

48+
Bignat fnc_is_y;
49+
4850
KeyAgreement fnc_multiplication_x_keyAgreement;
4951
Signature fnc_SignVerifyECDSA_signEngine;
5052
MessageDigest fnc_isEqual_hashEngine;
@@ -92,6 +94,8 @@ void initialize() {
9294
Bignat fnc_from_x_y_sq;
9395
Bignat fnc_from_x_y;
9496

97+
fnc_is_y = rm.helperEC_BN_C;
98+
9599
fnc_isEqual_hashArray = rm.helper_hashArray;
96100
fnc_isEqual_hashEngine = rm.hashEngine;
97101

0 commit comments

Comments
 (0)