Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/quite/humla-spongycastle.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2013-10-02 06:28:35 +0400
committerPeter Dettman <peter.dettman@bouncycastle.org>2013-10-02 06:28:35 +0400
commit7ceb82200d127e77690c1c61fd70f1a729f171e2 (patch)
treec3c800cfe52aa6a7e7a2038cc6a650b9f027dee4 /core/src/main/java/org/bouncycastle/math
parent36224c67fd1df32df160f28ba52a7b0a2d9eeec1 (diff)
Fp.twicePlus should check for y == 0
Diffstat (limited to 'core/src/main/java/org/bouncycastle/math')
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/ECPoint.java28
1 files changed, 16 insertions, 12 deletions
diff --git a/core/src/main/java/org/bouncycastle/math/ec/ECPoint.java b/core/src/main/java/org/bouncycastle/math/ec/ECPoint.java
index 75e95a63..eca1bd40 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/ECPoint.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/ECPoint.java
@@ -696,21 +696,19 @@ public abstract class ECPoint
// B.3 pg 62
public ECPoint twice()
{
- if (this.isInfinity())
+ if (isInfinity())
{
- // Twice identity element (point at infinity) is identity
return this;
}
-
+
+ ECCurve curve = getCurve();
+
ECFieldElement Y1 = this.y;
if (Y1.isZero())
{
- // if y1 == 0, then (x1, y1) == (x1, -y1)
- // and hence this = -this and thus 2(x1, y1) == infinity
- return getCurve().getInfinity();
+ return curve.getInfinity();
}
- ECCurve curve = getCurve();
int coord = curve.getCoordinateSystem();
ECFieldElement X1 = this.x;
@@ -827,7 +825,11 @@ public abstract class ECPoint
public ECPoint twicePlus(ECPoint b)
{
- if (this.isInfinity())
+ if (this == b)
+ {
+ return threeTimes();
+ }
+ if (isInfinity())
{
return b;
}
@@ -835,9 +837,11 @@ public abstract class ECPoint
{
return twice();
}
- if (this == b)
+
+ ECFieldElement Y1 = this.y;
+ if (Y1.isZero())
{
- return threeTimes();
+ return b;
}
ECCurve curve = getCurve();
@@ -847,7 +851,7 @@ public abstract class ECPoint
{
case ECCurve.COORD_AFFINE:
{
- ECFieldElement X1 = this.x, Y1 = this.y;
+ ECFieldElement X1 = this.x;
ECFieldElement X2 = b.x, Y2 = b.y;
ECFieldElement dx = X2.subtract(X1), dy = Y2.subtract(Y1);
@@ -898,7 +902,7 @@ public abstract class ECPoint
public ECPoint threeTimes()
{
- if (this.isInfinity() || this.y.isZero())
+ if (isInfinity() || this.y.isZero())
{
return this;
}