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
问题:
回答1:
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);
回答2:
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