3

Presently iam working on a project that uses elliptic curve. Please provide me a solution that determines whether a point is on the elliptic curve or not? and also how to get a point on the elliptic curve

RAVITEJA SATYAVADA
  • 2,503
  • 23
  • 56
  • 88

2 Answers2

16

Checking whether a point is on the elliptic curve is easy. Just check whether your point (x,y) fulfills the equation defining your elliptic curve : y^2 = x^3 + ax + b (remember to perform the calculation in the correct field).

Using Bouncycastle you can do it like this:

ECCurve curve = //...
ECFieldElement x = //...
ECFieldElement y = //...

ECFieldElement a = curve.getA();
ECFieldElement b = curve.getB();
ECFieldElement lhs = y.multiply(y);
ECFieldElement rhs = x.multiply(x).multiply(x).add(a.multiply(x)).add(b);

boolean pointIsOnCurve = lhs.equals(rhs);

You have tagged the question with cryptography, so I assume you are asking about elliptic curves over a finite field. The curve will have a generator, g and an order. To get a random point, just generate a random integer, x, between 0 and (order - 1), and choose x * g.

You can do it using Bouncycastle like this:

X9ECParameters x9 = NISTNamedCurves.getByName("P-224"); // or whatever curve you want to use
ECPoint g = x9.getG();
BigInteger n = x9.getN();
int nBitLength = n.bitLength();
BigInteger x;
do
{
    x = new BigInteger(nBitLength, random);
}
while (x.equals(ZERO)  || (x.compareTo(n) >= 0));
ECPoint randomPoint = g.multiply(x); 
Rasmus Faber
  • 48,631
  • 24
  • 141
  • 189
  • please provide me the example code to get a point on the elliptic curve using bouncy castle...... – RAVITEJA SATYAVADA Jul 12 '11 at 12:21
  • 5
    @Rasmus, who needs an education when you have stack overflow. – Petey B Jul 12 '11 at 16:41
  • Thank you very much...Please one more help is the multiplication of a elliptic curve point with 1 and -1 results the same? I tried it and getting the same point but theoritically – RAVITEJA SATYAVADA Jul 13 '11 at 04:46
  • Thank you very much...and is the multiplication of a elliptic curve point with 1 and -1 results the same point?? I tried it and getting the same point but it is theoretically wrong. – RAVITEJA SATYAVADA Jul 13 '11 at 04:49
  • @user605343: No. I am not sure Bouncycastle's ECPoint.multiply works correctly with negative numbers, but you can try using the fact that x*p = (n+x)*p, (where n is the order, x is an integer and p is a elliptic curve point). Then -1*p = (n-1)*p, which Bouncycastle should be able to compute. – Rasmus Faber Jul 13 '11 at 07:30
  • @user605343: Multiplication by 1 or -1 will give the same result if the elliptic curve is over F2m (i.e. x == -x). – Peter Dettman Sep 11 '11 at 08:57
0

without knowing what language your formula would be:

x^3+b - y^2 = 0

if this is not true then your point is not on the curve. i wrote a javascript implementation using big-integer like this:

verify(point) {
  const verificationPoint = this.modSet.subtract(
    this.modSet.add(this.modSet.power(point.x, 3), this.b),
    this.modSet.power(point.y, 2)
   )
  return bigInt(verificationPoint).equals(0)
}

if you would like to see an implementation of just the math for verification, addition, doubling, multiplication and subtraction see these links:

https://www.npmjs.com/package/simple-js-ec-math

https://github.com/Azero123/simple-js-ec-math

i suggest following this guide if you are learning how elliptic curve math works:

https://eng.paxos.com/blockchain-101-foundational-math

and there are numerous descriptions online of how to improve performance of your code:

https://en.wikipedia.org/wiki/Elliptic_curve_point_multiplication