0
$\begingroup$

I am new to SJCL library and I am working on elliptic curve cryptography at very basic level. I can't implement the add function for two points on the elliptic curve.

The signature of add function which I found on internet is curve.a.add(b), where a and b are points.

When I implemented this function syntax, I got this error

curve.Q.add(P); ^

TypeError: Cannot read property 'add' of undefined

Here P and Q are points on elliptic curve k256.

$\endgroup$
  • $\begingroup$ Please refrain from cross-posting the same question to multiple stackexchange sites. Programming questions belong on StackOverflow, even if they are using cryptography. $\endgroup$ – Ella Rose Oct 10 at 14:18
1
$\begingroup$

Assuming curve is an instance of sjcl.ecc.curve:

(1) curve.Q is undefined, there is no field named Q in the curve class.

(2) Q must be a point in Jacobian coordinates and P must be a point in affine coordinates. See the documentation.

So if P and Q are created by new point(curve, x, y), do this:

Q.toJac().add(P)

BTW: curve.a.add(b) does not do point addition. It takes the parameter a of the curve, i.e. the constant a in the equation of the curve $y^2 = x^3 + ax + b$, which is a big integer, and adds it to b (which presumably is also a big integer).

$\endgroup$
  • $\begingroup$ Ok, i got it. But now when i try to declare a new curve i.e. y=x^3+2x+2 mod 17 of order 19 and basepoint (5,1) using the following code var curve = new sjcl.ecc.curve(17, 19, 2, 5, 1); I get this error TypeError: a is not a constructor $\endgroup$ – Security Geek Oct 10 at 12:11
  • $\begingroup$ The arguments must be of type bn (Big Integer), not int. $\endgroup$ – Changyu Dong Oct 10 at 13:04
  • $\begingroup$ I have defined all the arguments as follows var p= new sjcl.bn(17); var q= new sjcl.bn(19); var a= new sjcl.bn(2); var x= new sjcl.bn(5); var y= new sjcl.bn(1); but still when i define the curve as var curve = new sjcl.ecc.curve(p, q, a, x, y); I keep getting the same error. $\endgroup$ – Security Geek Oct 10 at 13:13
  • $\begingroup$ I think there is an error in the documentation. The constructor of the curve class takes 6 argument (rather than 5). Source code here (line 266): bitwiseshiftleft.github.io/sjcl/doc/ecc.js.html It is sjcl.ecc.curve(p, q, a, b, x, y) , so you should provide 17, 19, 2, 2, 5, 1. $\endgroup$ – Changyu Dong Oct 10 at 13:23
  • $\begingroup$ even after putting var z = new sjcl.ecc.curve(p, q, a, b, x, y); I get the same error. I don't know why it is taking 'a' as a constructor while a is variable. $\endgroup$ – Security Geek Oct 10 at 13:37

Not the answer you're looking for? Browse other questions tagged or ask your own question.