RosettaCodeData/Task/Elliptic-curve-arithmetic/00-TASK.txt

43 lines
3.2 KiB
Plaintext

[[wp:Elliptic curve|Elliptic curve]]s   are sometimes used in   [[wp:cryptography|cryptography]]   as a way to perform   [[wp:digital signature|digital signature]]s.
The purpose of this task is to implement a simplified (without modular arithmetic) version of the elliptic curve arithmetic which is required by the   [[wp:ECDSA|elliptic curve DSA]]   protocol.
In a nutshell, an elliptic curve is a bi-dimensional curve defined by the following relation between the '''x''' and '''y''' coordinates of any point on the curve:
:::: &nbsp; <big><big><math>y^2 = x^3 + a x + b</math></big></big>
'''a''' and '''b''' are arbitrary parameters that define the specific curve which is used.
For this particular task, we'll use the following parameters:
:::: &nbsp; <big> a=0<b>,</b> &nbsp; b=7 </big>
The most interesting thing about elliptic curves is the fact that it is possible to define a &nbsp; [[wp:group|group]] &nbsp; structure on it.
To do so we define an &nbsp; [[wp:internal composition|internal composition]] &nbsp; rule with an additive notation '''+''', &nbsp; such that for any three distinct points '''P''', '''Q''' and '''R''' on the curve, whenever these points are aligned, we have:
:::: &nbsp; <big> P + Q + R = 0 </big>
Here &nbsp; <big>'''0'''</big> &nbsp; (zero) &nbsp; is the ''infinity point'', &nbsp; for which the '''x''' and '''y''' values are not defined. &nbsp; It's basically the same kind of point which defines the horizon in &nbsp; [[wp:projective geometry|projective geometry]].
We'll also assume here that this infinity point is unique and defines the &nbsp; [[wp:identity element|neutral element]] &nbsp; of the addition.
This was not the definition of the addition, but only its desired property. &nbsp; For a more accurate definition, we proceed as such:
Given any three aligned points '''P''', '''Q''' and '''R''', &nbsp; we define the sum &nbsp; '''S = P + Q''' &nbsp; as the point (possibly the infinity point) such that &nbsp; '''S''', '''R''' &nbsp; and the infinity point are aligned.
Considering the symmetry of the curve around the x-axis, it's easy to convince oneself that two points '''S''' and '''R''' can be aligned with the infinity point if and only if '''S''' and '''R''' are symmetric of one another towards the x-axis &nbsp; (because in that case there is no other candidate than the infinity point to complete the alignment triplet).
'''S''' is thus defined as the symmetric of '''R''' towards the '''x''' axis.
The task consists in defining the addition which, for any two points of the curve, returns the sum of these two points. &nbsp; You will pick two random points on the curve, compute their sum and show that the symmetric of the sum is aligned with the two initial points.
You will use the '''a''' and '''b''' parameters of secp256k1, i.e. respectively zero and seven.
''Hint'': &nbsp; You might need to define a "doubling" function, that returns '''P+P''' for any given point '''P'''.
''Extra credit'': &nbsp; define the full elliptic curve arithmetic (still not modular, though) by defining a "multiply" function that returns,
<br>for any point '''P''' and integer '''n''', &nbsp; the point '''P + P + ... + P''' &nbsp; &nbsp; ('''n''' times).
<br><br>