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
path: root/core
diff options
context:
space:
mode:
authorPeter Dettman <peter.dettman@bouncycastle.org>2014-03-12 12:18:41 +0400
committerPeter Dettman <peter.dettman@bouncycastle.org>2014-03-12 12:18:41 +0400
commita2646ea154fc35b6016d309152ec83f1aaa33e7e (patch)
tree8c40e11f2ff79949cf427a76923e2eb235c01859 /core
parentd81aefcbd4adf972b04133a2c52f890351dfbcf7 (diff)
Add scaleX, scaleY methods to ECPoint
Diffstat (limited to 'core')
-rw-r--r--core/src/main/java/org/bouncycastle/math/ec/ECPoint.java82
1 files changed, 82 insertions, 0 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 7bf2d336..2aa0fd21 100644
--- a/core/src/main/java/org/bouncycastle/math/ec/ECPoint.java
+++ b/core/src/main/java/org/bouncycastle/math/ec/ECPoint.java
@@ -284,6 +284,20 @@ public abstract class ECPoint
return this.withCompression;
}
+ public ECPoint scaleX(ECFieldElement scale)
+ {
+ return isInfinity()
+ ? this
+ : getCurve().createRawPoint(getRawXCoord().multiply(scale), getRawYCoord(), getRawZCoords(), this.withCompression);
+ }
+
+ public ECPoint scaleY(ECFieldElement scale)
+ {
+ return isInfinity()
+ ? this
+ : getCurve().createRawPoint(getRawXCoord(), getRawYCoord().multiply(scale), getRawZCoords(), this.withCompression);
+ }
+
public boolean equals(ECPoint other)
{
if (null == other)
@@ -1335,6 +1349,74 @@ public abstract class ECPoint
}
}
+ public ECPoint scaleX(ECFieldElement scale)
+ {
+ if (this.isInfinity())
+ {
+ return this;
+ }
+
+ int coord = this.getCurveCoordinateSystem();
+
+ switch (coord)
+ {
+ case ECCurve.COORD_LAMBDA_AFFINE:
+ {
+ // Y is actually Lambda (X + Y/X) here
+ ECFieldElement X = getRawXCoord(), L = getRawYCoord();
+
+ ECFieldElement X2 = X.multiply(scale);
+ ECFieldElement L2 = L.add(X).divide(scale).add(X2);
+
+ return getCurve().createRawPoint(X, L2, getRawZCoords(), this.withCompression);
+ }
+ case ECCurve.COORD_LAMBDA_PROJECTIVE:
+ {
+ // Y is actually Lambda (X + Y/X) here
+ ECFieldElement X = getRawXCoord(), L = getRawYCoord(), Z = getRawZCoords()[0];
+
+ // We scale the Z coordinate also, to avoid an inversion
+ ECFieldElement X2 = X.multiply(scale.square());
+ ECFieldElement L2 = L.add(X).add(X2);
+ ECFieldElement Z2 = Z.multiply(scale);
+
+ return getCurve().createRawPoint(X2, L2, new ECFieldElement[]{ Z2 }, this.withCompression);
+ }
+ default:
+ {
+ return super.scaleX(scale);
+ }
+ }
+ }
+
+ public ECPoint scaleY(ECFieldElement scale)
+ {
+ if (this.isInfinity())
+ {
+ return this;
+ }
+
+ int coord = this.getCurveCoordinateSystem();
+
+ switch (coord)
+ {
+ case ECCurve.COORD_LAMBDA_AFFINE:
+ case ECCurve.COORD_LAMBDA_PROJECTIVE:
+ {
+ ECFieldElement X = getRawXCoord(), L = getRawYCoord();
+
+ // Y is actually Lambda (X + Y/X) here
+ ECFieldElement L2 = L.add(X).multiply(scale).add(X);
+
+ return getCurve().createRawPoint(X, L2, getRawZCoords(), this.withCompression);
+ }
+ default:
+ {
+ return super.scaleY(scale);
+ }
+ }
+ }
+
protected boolean getCompressionYTilde()
{
ECFieldElement X = this.getRawXCoord();