How do I multiply a regular integer by a point G? I need code that multiplies a long number by the G point of an eliptic curve represented in sec256k1 format. What library can I use for this in c++?
How do I multiply a regular integer by a point G? I need code that multiplies a long number by the G point of an eliptic curve represented in sec256k1 format. What library can I use for this in c++?
For a succint introduction to elliptic curve arithmetic check this source. A C++ implementation of the operation is roughly:
class EllipticPoint
{
double m_x, m_y;
public:
// Omited constructor and other modifiers
EllipticPoint& operator*=(int rhs) noexcept
{
EllipticPoint r;
EllipticPoint p = *this;
if(rhs < 0)
{
// change p * -rhs to -p * rhs
rhs = -rhs;
p = -p;
}
for (int i = 1; i <= rhs; i <<= 1)
{
if (i & rhs) r += p;
p.Double();
}
*this = r;
return *this;
}
};
// Example
EllipticPoint G;
G *= 3;