Path: blob/master/Diffie-Hellman-Key-Exchange/Attack-Invalid-Curve-Point/README.md
1402 views
Invalid Curve Point Attack
Prerequisites:
In this article, we will discuss an online attack on ECDH that arises due to incorrect check mechanism for points on an Elliptic Curve, eventually leading to leakage of secret key of the target involved, under specific circumstances.
The write-up is divided into three sections:
Attack Case Scenario
Invalid Curve Point Attack
Protections against the Attack
Note: The attack can be considered a variant of Small Subgroup Confinement Attack, but the circumstances under which a typical Small Subgroup Confinement works in ECDH and those under which Invalid Curve Point attack works are completely different.
Variable Notation:
E: Elliptic Curve defined as
a: Parameter of the Elliptic Curve
b: Parameter of the Elliptic Curve
e: Cardinality of the curve E
P: Base point on the Elliptic Curve
E
.c: Order of the subgroup generated by
P
Q: Alice's public key
x: Alice's secret key
u: Upper limit in the range of
x
and is equal toc
ni: Cardinality of curve Ei, where (0 <= i <= 1)
Attack Case Scenario and Background
Alice and Bob decide to exchange public keys using ECDH and derive the shared secret S
. The x-coordinate of the shared secret is then used as a key for MAC.
As an attacker, our motive is to get Alice's secret key.
To send keys via ECDH, they need to choose a finite field over which all the necessary computations can happen. Assume it to be GF(p). In most cases, p
will chosen as be a prime number for convenience.
Suppose Alice and Bob choose P
as the base point for ECDH computation.
We know that Small Subgroup Confinement attack will work in cases when order c
of the subgroup generated by base point P
on the curve has many smaller factors.
What if c
doesn't have small factors? Can we do something in such a situation?
Suppose initialisation of any point on the curve looks like this:
Do you see anything missing in the above code snippet? A point that is not on the curve will be initialised without any error, since there is no mechanism to check that!
The question is, can we do something with it?
Let us dig into Elliptic Curves to find an answer to the above question Have a look at the formula for point doubling in an Elliptic Curve
Point Doubling in Elliptic Curves
Notice that point doubling and point addition do not depend on b
parameter of an Elliptic Curve, hence changing the value of b
will not change the results of Elliptic Curve Arithmetic (Scalar Multiplication, Point Addition, Point Doubling) on any pair of points.
Using the above property, we can say that different points can be chosen from different curves having the same a
but different values of b
:
Now we have multiple curves from which we can choose our points and share as public keys, and this will not affect the results of Elliptic Curve Arithmetic due to reasons we discussed above. We can selectively choose points having small order of the subgroup, generated by scalar multiplication.
The remaining steps are the same as Small Subgroup Attacks on ECDH- find value of x
mod different moduli and as soon as the moduli product exceeds the upper limit of x
, calculate the CRT to get the value of x
But, it's not so easy as it sounds. There are some complications in the attack, as we will see in the next section.
Invalid Curve Point Attack
The attack requires the attacker to be able to intercept the channel (Man-In-The-Middle)
At first, Alice calculates her public key as
, where
P
is the base point on an Elliptic CurveE
, and shares it over the channelFind the upper limit of
x
and assign it asu
. The upper limit is equal to the order of the subgroup generated by pointP
. How do we calculate the order of the subgroup generated by pointP
?We know from Lagrange's Theorem that order of the subgroup generated by any point on a curve is a divisor of the cardinality of that curve.
Calculating order of a point
P
on a curveE
: Find smallest divisori
of cardinality of the curveE
such that
Find suitable curves with cardinality having many small factors
--> E1
--> E2
To choose appropriate values of b1 & b2, iterate over possible values of bi, calculate the cardinality of the curve and check if it has multiple small factors.
Select a point Pi from a curve Ei (0 <= i <= 1), having a small order
, where pi is a prime number and is a factor of the cardinality ni of the curve Ei. Now, the question is: how do we select such a point?
Find a generator point
X
on the curve Ei. A generator point here means thatX
can be used to generate all points on the Elliptic Curve upon scalar multiplication.Calculate
and check if it is equal to arbitrary point at INFINITY(0, 0)
If True, then select another generator point
X
on the curve and repeat this process.If False, then the resultant point Pi =
has order
. Move to step-5.
Send this point Pi to Alice as your public key.
Alice calculates the shared secret
S
asAlice computes MAC(S[0], "testmessage") and shares it over the channel. Let the value of MAC be
M
.Notice that only the
x
-coordinate of the shared secretS
is used for calculating the Message Authentication Code, hence the notation S[0]
We intercept the channel again and get the value of MAC
M
. Since order of Pi is, we have effectively reduced the possible values of S[0]. All we need to do now is to find 1 < k <
such that MAC((k*Pi)[0], "testmessage") ==
M
. Here is where a problem arises:We can find two such values of
k
having the same (k*Pi)[0]. Why does this happen? We know that P and (-P) have the same value ofx
coordinate. Hence, the x-coordinate ofand that
will be the same. Therefore, we have
k
and-k mod p
, which when multiplied with Pi give the same value of x-coordinate.How do we solve this problem? We know that
. So, what we can do is find
instead of finding
, by finding any
k
in the range 1 < k <such that MAC((k*Pi)[0], "testmessage") ==
M
.Finding
k
is very easy as we have reduced the range of possible values ofk
to less than or equal to.
Repeat steps 4-8 for different points Pi having different orders (where p1, p2, p3,..., pn are primes) on curves E1 and E2 to obtain:
^^ label the above system of equations as (1)
Since, p1, p2, p3,..., pn are primes, are pairwise coprime.
One thing to remember is that we can solve (1) only if >= u, where
u
is the upper limit of range of possible values of secret key x
. Otherwise, find values of for more values of
until the product
>= u.
We can perform Chinese Remainder Theorem and get the value of . Since,
x
< . We can uniquely determine value of
x
from by using Tonelli Shanks Algorithm to get value of
!