From 3bc589c293b980b9fe54dff158e3abea5392c414 Mon Sep 17 00:00:00 2001 From: Peter Dettman Date: Sun, 29 Sep 2013 11:51:20 +0700 Subject: getYCoord for lambda-projective coords needs to consider Z --- .../java/org/bouncycastle/math/ec/ECPoint.java | 26 ++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'core/src/main/java/org/bouncycastle/math') 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 3a6faf30..eb970173 100644 --- a/core/src/main/java/org/bouncycastle/math/ec/ECPoint.java +++ b/core/src/main/java/org/bouncycastle/math/ec/ECPoint.java @@ -1117,15 +1117,37 @@ public abstract class ECPoint public ECFieldElement getYCoord() { - switch (getCurveCoordinateSystem()) + int coord = getCurveCoordinateSystem(); + + switch (coord) { case ECCurve.COORD_LAMBDA_AFFINE: case ECCurve.COORD_LAMBDA_PROJECTIVE: + { + // TODO The X == 0 stuff needs further thought + if (isInfinity() || x.isZero()) + { + return y; + } + // Y is actually Lambda (X + Y/X) here; convert to affine value on the fly - return (isInfinity() || x.isZero()) ? y : y.subtract(x).multiply(x); + ECFieldElement X = x, L = y; + ECFieldElement Y = L.subtract(X).multiply(X); + if (ECCurve.COORD_LAMBDA_PROJECTIVE == coord) + { + ECFieldElement Z = zs[0]; + if (Z.bitLength() != 1) + { + Y = Y.divide(Z); + } + } + return Y; + } default: + { return y; } + } } protected boolean getCompressionYTilde() -- cgit v1.2.3