-1

How to use the point addition and multiplication functions in elliptic curve using Crypto++ library?

I've tried the following code where Basepoint and point are the points on the elliptic curve.

const ECP::Point& ECP::Add(&Basepoint, &point);

ECP::Point& result = ECP::Add(Basepoint, point);

const int result = ECP::Point ECP::Add(&Basepoint, &point);

It results in:

ERROR: E0245 a nonstatic member reference must be relative to a specific object

jww
  • 97,681
  • 90
  • 411
  • 885
  • 1
    You should show more than member function declarations. You should show your code. Also see [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve). – jww May 23 '19 at 09:29
  • Also see https://stackoverflow.com/q/56273796/608639 . – jww May 23 '19 at 11:57

1 Answers1

1

in

ECP::Point& result = ECP::Add(Basepoint, point);

you call ECP::Add as a static member of ECP, the error indicates there is no static Add , you need to apply it to an instance of ECP

When I look at the documentation I only see

const Point & Add (const Point &P, const Point &Q) const

which is not static

Also

const ECP::Point& ECP::Add(&Basepoint, &point);

const int result = ECP::Point ECP::Add(&Basepoint, &point);

are an invalid forms.

Even having just ECP::Add(&Basepoint, &point); is also wrong because the operation is not static and because the arguments are pointers to Point incompatible with the operation parameters. Probably you have to look at what a reference is in C++ documentation/tutorial

A valid code can be

ECP ecp;
Point basepoint;
Point point;

// set ecp, basepoint and point to be the ones you want

const Point & r1 = ecp.Add(basepoint, point); // do not copy the result
Point r2 = ecp.Add(basepoint, point); // copy result in non const to be able to modify it later etc
Community
  • 1
  • 1
bruno
  • 32,421
  • 7
  • 25
  • 37
  • I've made the object as follows: ECP z1; ECPPoint result; result= z1.Add(Basepoint,Basepoint); but it is throwing an exception now: Exception thrown: read access violation. **CryptoPP::ECP::GetField**(...) returned nullptr. occurred –  May 23 '19 at 09:11
  • @SecurityGeek I do not know ECP, perhaps a default constructed ECP cannot be used for that. I can just react on your initial question to allow you to have a code you can compile ;-) – bruno May 23 '19 at 09:14