de.flexiprovider.common.math.ellipticcurves
Class PointGFP

java.lang.Object
  |
  +--de.flexiprovider.common.math.ellipticcurves.Point
        |
        +--de.flexiprovider.common.math.ellipticcurves.PointGFP

public class PointGFP
extends Point

This class implements points and their arithmetic on elliptic curves over finite prime fields (GF(p)). For more information on the arithmetic see for example Certicom online- tutorial.

Author:
Birgit Henhapl
See Also:
EllipticCurveGFP, PointGFP

Fields inherited from class de.flexiprovider.common.math.ellipticcurves.Point
ENCODING_TYPE_COMPRESSED, ENCODING_TYPE_HYBRID, ENCODING_TYPE_UNCOMPRESSED, mE, mP
 
Constructor Summary
PointGFP(byte[] encoded, EllipticCurveGFP E)
          Constructs a new point.
PointGFP(EllipticCurveGFP E)
          Construct the point at infinity on the specified elliptic curve.
PointGFP(EllipticCurveGFP E, java.util.Random rand)
          Construct a random point on the specified elliptic curve using the given source of randomness.
PointGFP(GFPElement x, GFPElement y, EllipticCurveGFP E)
          Constructs point with specified parameters.
PointGFP(GFPElement x, GFPElement y, GFPElement z, EllipticCurveGFP E)
          Constructs point with specified parameters.
PointGFP(PointGFP other)
          Copy constructor.
 
Method Summary
 Point add(Point other)
          Adds to this point other.
 Point addAffine(Point other)
          Adds in affine coordinates to this point the point other.
 void addToThis(Point other)
          Adds to this point other.
 java.lang.Object clone()
           
(package private)  byte[] encodeCompressed()
          Returns this point in affine, compressed form as a byte array.
(package private)  byte[] encodeHybrid()
          Returns this point in affine, hybrid form as a byte array.
(package private)  byte[] encodeUncompressed()
          Returns this point in affine, decompressed form as a byte array.
 boolean equals(java.lang.Object other)
          Tests whether this Point is equal to other.
 Point getAffin()
          Returns this point with affine coordinates.
 GFElement getX()
           
 GFElement getXAffin()
          Return the x-coordinate of this point in affine representation.
 GFElement getY()
           
 GFElement getYAffin()
          Return the y-coordinate of this point in affine representation.
 GFElement getZ()
           
 int hashCode()
           
 boolean isZero()
          Tests, whether this point is at infinity.
 Point multiplyBy2()
          Returns 2*this.
 Point multiplyBy2Affine()
          Doubles this point in affine coordinates.
 void multiplyThisBy2()
          This = 2*this.
 Point negate()
          Returns the inverse of this point.
 void negateThis()
          Returns the inverse of this point.
 boolean onCurve()
          Tests whether this point is on the curve mE.
 Point subtract(Point other)
          Subtracts point other from this point.
 void subtractFromThis(Point other)
          Subtracts point other from this point.
 java.lang.String toString()
          Returns this point in affine representation as a String: (x, y), where x = mX/mZ2 and y = mZ/mZ3.
 
Methods inherited from class de.flexiprovider.common.math.ellipticcurves.Point
EC2OSP, getE, isNegativeOf, OS2ECP
 
Methods inherited from class java.lang.Object
, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PointGFP

public PointGFP(EllipticCurveGFP E)
Construct the point at infinity on the specified elliptic curve.
Parameters:
E - EllipticCurveGFP is the elliptic curve this point lies on

PointGFP

public PointGFP(EllipticCurveGFP E,
                java.util.Random rand)
Construct a random point on the specified elliptic curve using the given source of randomness.
Parameters:
E - EllipticCurveGFP is the elliptic curve this point lies on
rand - the source of randomness

PointGFP

public PointGFP(GFPElement x,
                GFPElement y,
                EllipticCurveGFP E)
         throws InvalidPointException,
                DifferentFieldsException
Constructs point with specified parameters. This method throws an InvalidPointException, if (x, y, z) is not on curve E.
Parameters:
x - x-coordinate
y - y-coordinate
E - EllipticCurveGFP is the elliptic curve this point lies on
Throws:
InvalidPointException - if the specified point is not on the curve.
DifferentFieldsException - if x and y are defined over different fields.

PointGFP

public PointGFP(GFPElement x,
                GFPElement y,
                GFPElement z,
                EllipticCurveGFP E)
         throws InvalidPointException,
                DifferentFieldsException
Constructs point with specified parameters. This method throws an InvalidPointException, if (x, y, z) is not on curve E.
Parameters:
x - x-coordinate
y - y-coordinate
z - z-coordinate
E - the elliptic curve this point lies on
Throws:
InvalidPointException - if the specified point is not on the curve.
DifferentFieldsException - if x, y, and z are defined over different fields.

PointGFP

public PointGFP(byte[] encoded,
                EllipticCurveGFP E)
         throws InvalidPointException,
                InvalidFormatException
Constructs a new point. The information is packed in the given byte array together with the given elliptic curve. (see X9.63-199x)
Parameters:
encoded - the point in normal, compressed or hybrid form.
E - the underlying elliptic curve
Throws:
InvalidPointException - if the point is not on the curve.
InvalidFormatException - if the point representation is invalid.

PointGFP

public PointGFP(PointGFP other)
Copy constructor.
Parameters:
other - point to copy
Method Detail

clone

public java.lang.Object clone()
Overrides:
clone in class Point
Returns:
a clone of this point

equals

public boolean equals(java.lang.Object other)
Tests whether this Point is equal to other. The points are equal, if
mX*other.mZ2 == other.mX*mZ2 and mY*other.mZ3 other.mY*mZ3.
Overrides:
equals in class Point
Parameters:
other - Point to compare this Point with
Returns:
(mX*other.mZ2 == other.mX*mZ2) AND (mY*other.mZ3 other.mY*mZ3)

hashCode

public int hashCode()
Overrides:
hashCode in class Point
Returns:
the hash code of this point
See Also:
Object.hashCode()

toString

public java.lang.String toString()
Returns this point in affine representation as a String: (x, y), where x = mX/mZ2 and y = mZ/mZ3. If this point is at infinity (that means, mZ = 0), the output is (0, 0).
Overrides:
toString in class java.lang.Object
Returns:
String (x, y)

getX

public GFElement getX()
Overrides:
getX in class Point
Returns:
the x-coordinate of this point

getY

public GFElement getY()
Overrides:
getY in class Point
Returns:
the y-coordinate of this point

getZ

public GFElement getZ()
Overrides:
getZ in class Point
Returns:
the z-coordinate of this point

getXAffin

public GFElement getXAffin()
Return the x-coordinate of this point in affine representation. In this class, the projective representation x = X/Z2 and y = Y/Z3 is chosen to speed up point addition. This method returns the x-coordinate in affine representation.
Overrides:
getXAffin in class Point
Returns:
the x-coordinate of this point in affine representation

getYAffin

public GFElement getYAffin()
Return the y-coordinate of this point in affine representation. In this class, the projective representation x = X/Z2 and y = Y/Z3 is chosen to speed up point addition. This method returns the y-coordinate in affine representation.
Overrides:
getYAffin in class Point
Returns:
the y-coordinate of this point in affine representation

getAffin

public Point getAffin()
Returns this point with affine coordinates.
Overrides:
getAffin in class Point
Returns:
this

onCurve

public boolean onCurve()
Tests whether this point is on the curve mE. This method returns true, if
mY2 - mX3 - mA*mX* mZ4 - mB*mZ6 = 0,
otherwise false.
Overrides:
onCurve in class Point
Returns:
mY2 - mX 3 - mA*mX*mZ 4 - mB*mZ6 == 0
See Also:
EllipticCurveGFP

isZero

public boolean isZero()
Description copied from class: Point
Tests, whether this point is at infinity.
Overrides:
isZero in class Point
Returns:
true if this point is the point at infinity, false otherwise.

add

public Point add(Point other)
Adds to this point other. The formula is:
X3 = -H3 - 2U1H2 + r2
Y3 = -S1H3 + r*(U1H2 - X3
Z3 = Z1Z2H
Z32 = Z32
Z33 = Z33
with
U1 = X1Z22
U2 = X2Z12
S1 = Y1Z23
S2 = Y2Z13
H = U2 - U1
r = S2 - S1
Overrides:
add in class Point
Parameters:
other - point to add to this point
Returns:
this + other

addToThis

public void addToThis(Point other)
Adds to this point other. The formula is:
X3 = -H3 - 2U1H2 + r2
Y3 = -S1H3 + r*(U1H2 - X3
Z3 = Z1Z2H
Z32 = Z32
Z33 = Z33
with
U1 = X1Z22
U2 = X2Z12
S1 = Y1Z23
S2 = Y2Z13
H = U2 - U1
r = S2 - S1
Overrides:
addToThis in class Point
Parameters:
other - point to add to this point

addAffine

public Point addAffine(Point other)
Adds in affine coordinates to this point the point other.
Overrides:
addAffine in class Point
Parameters:
other - point to add to this point
Returns:
this + other in affine coordinates
Throws:
DifferentCurvesException - when other is defined over another curve

subtract

public Point subtract(Point other)
Subtracts point other from this point.
Overrides:
subtract in class Point
Parameters:
other - another Point
Returns:
this - other

subtractFromThis

public void subtractFromThis(Point other)
Subtracts point other from this point.
Overrides:
subtractFromThis in class Point
Parameters:
other - another Point

negate

public Point negate()
Returns the inverse of this point.
Overrides:
negate in class Point
Returns:
-this

negateThis

public void negateThis()
Returns the inverse of this point.
Overrides:
negateThis in class Point

multiplyBy2

public Point multiplyBy2()
Returns 2*this. The formula is:
X2 = T
Y2 = 8Y4 + M(S - T)
Z2 = 2YZ
Z22 = Z22
Z23 = Z23
with
S = 4XY2
M = 3X2 + a(Z2)2
T = -2S + M2
Overrides:
multiplyBy2 in class Point
Returns:
2*this

multiplyThisBy2

public void multiplyThisBy2()
This = 2*this. The formula is:
X2 = -2S + M2
Y2 = M(S - X2) - T
Z2 = 2YZ
Z22 = Z22
Z23 = Z23
with
S = 4XY2
M = 3X2 + aZ4
T = 8Y4
Overrides:
multiplyThisBy2 in class Point

multiplyBy2Affine

public Point multiplyBy2Affine()
Doubles this point in affine coordinates.
Overrides:
multiplyBy2Affine in class Point
Returns:
2*this in affine coordinates

encodeUncompressed

byte[] encodeUncompressed()
Returns this point in affine, decompressed form as a byte array. The first byte keeps the value 4, to indicate, that this point is stored in an uncompressed format. The rest of the returned array is split in two halves, the first holds the x-coordinate mX and the second they-coordinate mY.
Overrides:
encodeUncompressed in class Point
Returns:
this as byte array

encodeCompressed

byte[] encodeCompressed()
Returns this point in affine, compressed form as a byte array. The first byte keeps the value 2 or 3, to indicate, that this point is stored in a compressed format. The rest of the returned array is the x-coordinate mX.
Overrides:
encodeCompressed in class Point
Returns:
this as byte array

encodeHybrid

byte[] encodeHybrid()
Returns this point in affine, hybrid form as a byte array. The first byte keeps the value 6 or 7, to indicate, that this point is stored in a hybrid format. The rest of the returned array is split in two halves, the first holds the x-coordinate mX and the second they-coordinate mY.
Overrides:
encodeHybrid in class Point
Returns:
this as byte array