So I am using the following parameters that define an elliptic curve on a finite field modulo p:
p = 1331169830894825846283645180581
a = -35
b = 98
E = EllipticCurve(GF(p), [a,b])
G = E(479691812266187139164535778017, 568535594075310466177352868412)
I have the following public keys:
A = E(1110072782478160369250829345256, 800079550745409318906383650948)
B = E(1290982289093010194550717223760, 762857612860564354370535420319)
where A=a*G
I am trying to implement the MOV attack in sage using the weil_pairing()
function, in order to retrieve the private key a.
The sage docs saying that the element returned is a n'th root of unity on the base field of the curve (i.e. in the finite field modulo p). I dont really get why, because the result should be on the finite field modulo p^k based on the MOV attack(k is 2 in this curve).
The curve has another generator with the same order as G, lets name it Q. At first, I tried the following:
u = G.weil_pairing(Q, G.order())
v = A.weil_pairing(Q, G.order())
u; # 1224261643478288645398412515033
v; # 639110128106018561182432834399
v = int(v)
u = int(u)
1 == pow(u,Gk.order(),p) #True, False if modulus is p**k
1 == pow(v,Gk.order(),p) #True, False if modulus is p**k
u = Integers(p)(u)
v = Integers(p)(v)
na = discrete_log(v,u,operation="*")
na = int(na)
na; # 6458797
v = int(v)
u = int(u)
v == pow(u,na,p); #v = u^na mod p, True, False if modulus is p**k
A == na*G; #False
I tried to extend the base field to the finite field modulo p^k with the following commands:
Ek = E.base_extend(GF(p**k))
Gk = Ek(G)
Ak = Ek(A)
Qk = Ek(Q)
and then I used Gk, Ak and Qk instead, but this gave the same results.
I think this is not working because:
- Q must be a point on the finite field modulo p^k which is not included in the finite field modulo p based on this: https://risencrypto.github.io/WeilMOV/
weil_pairing()function returns an element on the finite field modulo p instead of the finite field modulo p^k
Furthermore, I tried to find a point Q with the same order as G in the finite field modulo p^k but the only algorithm I could find is the following, which is not giving any results(running forever):
E2 = EllipticCurve(GF(p**k), [a,b])
P = E2(0)
while P.order() != G.order():
R = E2.random_point()
if(R.order() == G.order()):
P = R
break
P = (E2.order()/G.order())*R
Lastly, I tried to use a different approach(frey ruck attack) based on the code here: https://github.com/jvdsn/crypto-attacks/blob/master/attacks/ecc/frey_ruck_attack.py but yet again, I dont get any results neither.
So my questions are:
- Why sage function
weil_pairing()returns the n'th root on finite field modulo p instead of p^k? - Is there a way to compute points of a specific order faster?
- How is it possible to solve this if these algorithms are taking so long?
We have three separated, more or less related question, pointing to the same target of attacking a weak elliptic curve, i am trying to address each in separate sections.
$(1)$
This question does not depend on the complexity of the given elliptic curve, we only want to check a parent. So let us consider some easy sample case, and check the
parentof the result of calling theweil_pairing$$ w $$ (in notation) for the chosen toy situation. The following sample lives over the field $F=\Bbb F_3[u]$ with nine elements, generated by the algebraic element satisfying $u^2-u-1=0$. I picked then an elliptic curve $$ E\text{ over }F=\Bbb F_3[u]\cong \Bbb F_9 \qquad :\qquad y^2=x^3 +x+1\ , $$ with order (of the rational points over $F$) equal to $16$, and two generators, $P,Q$. Note that it is pointless to have a cyclic $E(F)$, generated by one point $P$, say, since then the pairing $w$ on some points $aP$, $bP$ is equal to $w(aP,bP)=w(P,P)^{ab}=1^{ab}=1$. So we need in the example two generators, we have them below The generators have both order $4$, so $$ \begin{aligned} E(F) &=\{\ aP+bQ\ :\ a,b\in \Bbb Z\ \} \\ &=\{\ aP+bQ\ :\ a,b\in \Bbb Z/4\ \} \\ &=\{\ (a, b)\ :\ a,b\in \Bbb Z/4\ \} \\ &\cong (\Bbb Z/4)\times (\Bbb Z/4)$. \end{aligned} $$ Code for a first inspection:This gives so far the information:
Which are the results of the
weil_pairing, where do they live in?So even in the case of a result equal to one, the
parentdomain is in the sage implementation the field $F$ with $p=3^2$ elements. We have in this example $w(P,Q)=2u+2$, so in general $w(aP,bQ)=(2u+2)^{ab}$.$(2)$
The question about producing in a quick manner "some points" of a given order is not directly relevant to the attack implementation. I will say some few words. Our given curve has order computed as follows:
And the last line gives in the interpreter:
however this does not elucidate the structure of the group $E(F)$. Which is either cyclic, so it would be the integers modulo the above number, one generator, or has two cyclic components, $E(F)\cong \Bbb Z/d_1\oplus \Bbb Z/d_2$ with $d_1$ dividing $d_2$ and with product the above number. (The theorem of invariant factors would also allow further components for an arbitrary finite / torsion abelian group = $\Bbb Z$-module, but either structure theorems for elliptic curves over finite fields, or the fact that we see at most power two tells us that we have at most two cyclic pieces.)
We can even ask for the structure by associating the corresponding finite abelian group:
(Manually rearranged.) So the two invariant factors are $d_1=12838354=2 \cdot 271 \cdot 23687$, and $d_2 = 2 \cdot 7 \cdot 271 \cdot 23687 \cdot 1153763334005213$. Back to the question of finding points of a given order. Any point $S$ in $E(F)$ is a linear combination of $P,Q$, $$ S=aP+bQ\ , $$ and the order of $S$ divides $d_2$. Its order is the lcm of the orders for $aP$ and $bQ$. Given one such order, arrange for corresponding orders for $aP$ and $bQ$, make such a choice, then arrange for $a,b$ to realize the choice.
So there are for instance in $E(Q)$ only the points of order $1153763334005213$ which are of the shape $2 \cdot 7 \cdot 271 \cdot 23687 \cdot b'Q$, where $b'$ should be prime to $1153763334005213$, there are $1153763334005213-1$ choices for such a $b'$.
If we want to count points of order $271$, note that we have an injection $$ \Bbb Z/271\oplus\Bbb Z/271 \cong 2 \cdot 271 \cdot 23687\Bbb Z/d_1\oplus 2 \cdot 7 \cdot 23687 \cdot 1153763334005213\Bbb Z/d_2 \to \Bbb Z/d_1\oplus \Bbb Z/d_2\ , $$ and all points but one in the first group have order $271$. I hope it is clear now how to produce points of a given order starting from the generators $P,Q$...
$(3)$
This is in fact the main and only question.
We have to note first that for two random points $A,G$ in $E(F)$ - with order of $A$ dividing the order of $G$ to have a necessary condition for the start - there is not always possible to realize $A$ as an integer multiple of $G$. For instance, pick $A,G$ in different components of the $\Bbb Z/271\oplus \Bbb Z/271$ that injects in $E(F)$. But for the practical purpose, we may and do assume that there is a relation $$ A=mG\ , $$ and we want to determine (one choice of) $m$ making this happen.
So let us use some suitable pairing (that should not be trivial) and let us pair both $G$ and $A=mG$ with one and the same suitable point, well the generators are enough to pair with. We work over $F$ first, no extension of degree two of it, just to get an impression.
In our case, with $A$, $B$, $G$ as in the question, we have order $d_2$ for them:
so the usage of an antisymmetric may be not so fruitful. Since we have to pair with "the generator of the other, easier part $\cong \Bbb Z/d_1$, of much smaller order to get non-trivial results. Explicitly, written in terms of the generators $P$, $Q$, with orders $d_1$, respectively $d_2$ we have for the lifted instances (lifted from
EFback to points ofE)...and these generators have orders $d_1$ dividing $d_2$:
Which information can be traced back by pairing with $P$?
Which information can be traced back by pairing with $Q$?
So we can extract with the
weil_pairingthe partial information only from solving a discrete logarithm problem in a group of order $2\cdot 271\cdot 23687$. A brute force search related to this group gives:And we obtain:
Now the same should be done also for the other pieces, i.e. working also against the primes $7$ and $1153763334005213$. we only need corresponding non-trivial pairing information. And of course, the last prime is somehow too big for a naive loop. So far we have only the information: $$ A = mG\qquad\text{ with $m$ of the shape $19297151+2\cdot 271\cdot 23687\cdot N$ .} $$ We can also obtain information to cover the prime $7$ by using the
tate_pairing,or just by working with the points $1153763334005213\cdot A$ and $1153763334005213\cdot G$.
This delivers:
It remains to get the information modulo the remained prime, $1153763334005213$, the only "big prime" involved. Both discrete logarithm problems, on the elliptic curve and on the multiplicative group with this number of elements, would take a long time for a naive approach.
$(3)$ continued...
Here are some final words regarding the computation of $m$ modulo $q = 1153763334005213$, which is a prime number. It working over a field (instead in the group of rational points of an elliptic curve), then here is the field and the associated discrete logarithm problem.
We initialize the same curve over the field $K[u]$ with $p^2$ elements.
and the results are:
Now we also have the prime $q$ as factor in the order of using the
weil_pairing,so $A=mG$ implies $$ \begin{aligned} \underbrace{2 \cdot 7\cdot 271 \cdot 23687\cdot A}_{:=A_2} &= 2 \cdot 7\cdot 271 \cdot 23687\cdot mG\\ &=m\cdot\underbrace{( 2 \cdot 7\cdot 271 \cdot 23687\cdot G)}_{G_2}\ . \end{aligned} $$ applying the
weil_pairing, we need to find $m$ such that:We obtain:
We obtain: So it remains to solve for $m$ modulo $q$ in the discrete logarithm equation: $$ 573701785486394880347215076826\;u + 937462886552089156533615255382 = ( 882076139211768800810294904418\;u + 458352352918379992142983892259)^m \ . $$ (And then combine with the information for the other involved primes, $2$, $7$, $271$, $23687$.)
Good luck!