From f3934ec23ca361ea3a240e17ff6966974817bd4b Mon Sep 17 00:00:00 2001 From: BlazingTwist Date: Tue, 23 Jun 2026 08:24:33 +0200 Subject: [PATCH] fix Java 8 support --- src/main/java/com/starkbank/ellipticcurve/Curve.java | 4 ++-- src/main/java/com/starkbank/ellipticcurve/PublicKey.java | 2 +- src/test/java/com/starkbank/ellipticcurve/SecurityTest.java | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/main/java/com/starkbank/ellipticcurve/Curve.java b/src/main/java/com/starkbank/ellipticcurve/Curve.java index c4533e9..8f516c6 100644 --- a/src/main/java/com/starkbank/ellipticcurve/Curve.java +++ b/src/main/java/com/starkbank/ellipticcurve/Curve.java @@ -120,7 +120,7 @@ public boolean contains(Point p) { return false; } // y^2 - (x^3 + A*x + B) mod P == 0 - BigInteger lhs = p.y.modPow(BigInteger.TWO, this.P); + BigInteger lhs = p.y.modPow(BigInteger.valueOf(2), this.P); BigInteger rhs = p.x.modPow(BigInteger.valueOf(3), this.P) .add(this.A.multiply(p.x)) .add(this.B) @@ -148,7 +148,7 @@ public BigInteger y(BigInteger x, boolean isEven) { .add(this.B) .mod(this.P); BigInteger y = Math.modularSquareRoot(ySquared, this.P); - if (isEven != y.mod(BigInteger.TWO).equals(BigInteger.ZERO)) { + if (isEven != y.mod(BigInteger.valueOf(2)).equals(BigInteger.ZERO)) { y = this.P.subtract(y); } return y; diff --git a/src/main/java/com/starkbank/ellipticcurve/PublicKey.java b/src/main/java/com/starkbank/ellipticcurve/PublicKey.java index 72cbf33..c97fabe 100644 --- a/src/main/java/com/starkbank/ellipticcurve/PublicKey.java +++ b/src/main/java/com/starkbank/ellipticcurve/PublicKey.java @@ -70,7 +70,7 @@ public String toString(boolean encoded) { */ public String toCompressed() { int baseLength = 2 * curve.length(); - String parityTag = point.y.mod(BigInteger.TWO).equals(BigInteger.ZERO) ? EVEN_TAG : ODD_TAG; + String parityTag = point.y.mod(BigInteger.valueOf(2)).equals(BigInteger.ZERO) ? EVEN_TAG : ODD_TAG; String xHex = leftPad(point.x.toString(16), baseLength); return parityTag + xHex; } diff --git a/src/test/java/com/starkbank/ellipticcurve/SecurityTest.java b/src/test/java/com/starkbank/ellipticcurve/SecurityTest.java index 306f9bf..df95914 100644 --- a/src/test/java/com/starkbank/ellipticcurve/SecurityTest.java +++ b/src/test/java/com/starkbank/ellipticcurve/SecurityTest.java @@ -422,7 +422,7 @@ public void testPrimeCongruent1Mod4() { BigInteger P = BigInteger.valueOf(17); for (int value = 1; value < 17; value++) { BigInteger val = BigInteger.valueOf(value); - BigInteger halfP = P.subtract(BigInteger.ONE).divide(BigInteger.TWO); + BigInteger halfP = P.subtract(BigInteger.ONE).divide(BigInteger.valueOf(2)); if (val.modPow(halfP, P).equals(BigInteger.ONE)) { BigInteger root = Math.modularSquareRoot(val, P); assertEquals(val, root.multiply(root).mod(P)); @@ -436,7 +436,7 @@ public void testPrimeCongruent5Mod8() { BigInteger P = BigInteger.valueOf(13); for (int value = 1; value < 13; value++) { BigInteger val = BigInteger.valueOf(value); - BigInteger halfP = P.subtract(BigInteger.ONE).divide(BigInteger.TWO); + BigInteger halfP = P.subtract(BigInteger.ONE).divide(BigInteger.valueOf(2)); if (val.modPow(halfP, P).equals(BigInteger.ONE)) { BigInteger root = Math.modularSquareRoot(val, P); assertEquals(val, root.multiply(root).mod(P)); @@ -450,7 +450,7 @@ public void testPrimeCongruent3Mod4() { BigInteger P = BigInteger.valueOf(7); for (int value = 1; value < 7; value++) { BigInteger val = BigInteger.valueOf(value); - BigInteger halfP = P.subtract(BigInteger.ONE).divide(BigInteger.TWO); + BigInteger halfP = P.subtract(BigInteger.ONE).divide(BigInteger.valueOf(2)); if (val.modPow(halfP, P).equals(BigInteger.ONE)) { BigInteger root = Math.modularSquareRoot(val, P); assertEquals(val, root.multiply(root).mod(P));