Isognies
(Warning: This is just a brief note, so it may have some errors. )
Introduction to Isogenies
Let be the elliptic curves over a finite field . Here is some prime power. As far as we known, form a group under the addition of points and as is finite, so are these groups.
So now we want to consider a map between these two elliptic curves:
What do we actually mean by this? To define such a map, we need to understand or provide an explicit formula describing the structure of these two curves.
We also wonder what properties should this map have for it to “behave well” in both the geometric and algebraic sense?
- acts on points on the EC, which have an and a coordinate. So we can write , which acts on a point on in the following way:
- We want this map to be rational. By this we mean that if then and are just algebraic fractions where the denominator and numerator are polynomials. For example
- We want to have this property, because it is a well known fact in maths that a rational map is either surjective or constant. Though this may not seem important, once we define a few more properties and start looking at isogenies, this becomes really useful.
- As both and form groups, ideally we would like to be a group homomorphism. Intuitively, this means that will preserver the group structure. Mathematically, if is the group operation on , and are two points on then:
Review:
Rational map A rational map from a variety to a variety (over a field ) is a map that can be expressed using ratios of polynomials in the coordinates of .
Formally:
is a rational map if, for each coordinate function of , there exist a polynomial numerator and denominator in the coordinates of such that
for and
You can read more from here: https://en.wikipedia.org/wiki/Rational_mapping
For example: A rational map could be
Definition 1. A rational map is called an isogeny if where is the identity of the group .
A famous example of an isogeny when we’re working over a finite field is the Frobenius Map. If , this map is given by
Rational functions
Let be an elliptic curve with equation . Take a polynomial and consider its behavior on the points of only, ignoring its behaviour on all other values of and .
If then from our point of view, is the same as the zero function because for any point on the curve. Then by Hilbert’s Nullstellensatz theorem, a polynomial is the zero function if and only if it is a multiple of .
This leads us to define the ring of regular functions of to be
Its field of fractions is called the field of rational functions of .
Note: There are two version of Hilbert’s Nullstellensatz theorem, you can look it up on any algebraic geometry textbook
Let be a algebraically closed field, and are polynomials in variables.
Weak nullstellensatz. Let be polynomials, here is a algebraically closed field. Then exactly one of the following statements hold:
- The system of equations has a solution
- There exist polynomials such that .
Strong nullstellensatz. Same stament as above, but here we consider another polynomial . Then exactly one of the following statements hold:
- The system of equations has a solution
- There exist polynomials and a non negative integer such that .
Endomorphisms
Definition: If then is called an endomorphism.
An endomorphism is an isomorphism if it is bijective. Review that is either the identity or surjective, so we only need to check if is injective.
An injective function is a function that map distinct elements of its domain to distinct elements of its codomain; that is, for implies .
The set of endomorphisms of an elliptic curve together with the zero map (the map that sends everything to zero) actually forms a ring under the operations of pointwise addition and multiplication given by composing the endomorphisms .
A ring means that the addition and multiplication behave nicely and interact well with each other. I will write this down again for archival purpose:
Ring. A ring is an algebraic structure consisting of a set with two binary operations called addition and multiplication. Also:
- it is a group under the addition
- the multiplication is associative and has an identity
- multiplication is distributive with respect to addition
We denote this ring by .
The zero map act as an additive identity and the identity map is the multiplicative identity.
For example we can consider the endomorphisms and for . Then we have their pointwise addition as follow:
Frobenius endomorphism
j - invariant
Usually we write the Weierstrass equation for our elliptic curve using non-homogeneous coordinates , and
and point out at infinity. If then is said to be defined over .
If , then we can simplify the equation by completing the square. Thus the substitution
gives an equation of the form
where
We also define quantities
The quantity is the discriminant of the Weierstrass equation, the quantity is the - invariant of the elliptic curve.
The - invariant help us to keep track the isomorphic class of an given elliptic curve. Two elliptic curves might have very different Weierstrass equation but if their - invariant are the same, they are isomorphic ( over the algebraic closure of ; that is, ).
For Weierstrass equation with char 2,3, the - invariant is equal to
More precisely, we consider the equivalence classes of elliptic curves, where and are equivalent if and only if they are isomorphic.
Theorem Let and be elliptic curves over . The over if and only if . In general, given a field and elliptic curves over then over if and only if .
Equality of - invariants does not guarantee an isomorphism over . Curves with same can be twists of each other.
Example: Consider the quadratic twists of a given curve. We will work with the elliptic curves over . The quadratic twists of is define as follow: here
Consider a quadratic nonresidue of . That is, choose an element such that but , i.e the algebraic closure of our field.
Then we can define another curve with the same - invariant as :
And we have
We can calculate the - invariant by sagemath
sage: F = GF(5)
sage: E = EllipticCurve(F,[1,0])
sage: print(E)
Elliptic Curve defined by y^2 = x^3 + x over Finite Field of size 5
sage: E_ = EllipticCurve(F, [2,0])
sage: print(E.j_invariant())
3
sage: print(E_.j_invariant())
3
sage:Degree and separability
We have the following definition:
Degree of map: Let be a map of curves defined over . If is constant, we define the degree of to be 0. Otherwise we say that is a finite map and we define its degree to be
We say that is separable, inseparable, or purely inseparable if the field extension has the corresponding property, and we the separable and inseparable degrees of the extension by and .
Let make it more clear. We have known that every non-zero isogeny between elliptic curves of the form can be written in the standard affine form
where and are pairs of relatively prime polynomials in
The degree of this map is actually equal to . The isogeny is separable if we have where denote the derivatives of rational function.
For example, consider the isogeny that map as follow:
This is a map of degree 4 and is separable. So basically the degree of a non-zero separable isogeny is the number of elements in its kernel and it is also the degree of the isogeny as a rational map
For more details you should read this lecture notes. (i think i will skip this since the maths is too intense lol)
Another important key fact is that the finite subgroups are in one-to-one correspondence with the separable isogenies , up to isomorphism of the codomain.
That is
where is the quotient elliptic curve and .
Knowing the kernel, one can write down the isogeny explicitly base on the fact that each kernel uniquely define the map. We will later learn how to calculate this by using Velu’s formula
Isomorphisms are actually a special case of an isogeny where the kernel is trivial, in this case, the kernel is just
Isomorphisms vs isogenies
We know that if is an isomorphism then there is an inverse map and their compose map gives us the identity map. Recall that an isogeny is a group homomorphism between two curves that map the identity on to the identity on . So in general, there is no guarantee of invertibility because usually has a nontrivial kernel.
However, every isogeny has a unique dual isogeny which we denote as . Rather than composing to give the identity, if is an isogeny of degree , then is an isogeny of degree and the composition gives us where is the multiplication by map.
Torsion Points
The group of all points on such that is denoted by and are called the -torsion points. In other words, these are the points that are in the kernel of the multiplication by map.
Theorem. Let be an elliptic curve and a non zero integer. If , factor as with , otherwise, let . Then as groups:
In particular or and if then .
This come from the fact that every finitely generated abelian groups classify as products of cyclic groups.
Furthermore we have
You can also read this notes for further research https://www.math.uchicago.edu/~may/VIGRE/VIGRE2008/REUPapers/Travis.pdf
For an elliptic curve over , it can be written as a torus
The map corresponds to scaling by which gives us
The kernel is actually the lattice points which forms a grid of size . That’s why we always get torsion points.
Divisor and division polynomials
The divisor of a curve denote by is the free abelian group generated by the points of . Thus a divisor is a formal sum:
where and for all but finitely many . The degree of is defined by
For example we have then the degree of will be .
For more detail see here: https://crypto.stanford.edu/pbc/notes/elliptic/funcfield.html
Division polynomials are built from divisors of multiplication maps, and they encode torsion points. They also provide a way to calculate multiples of points on elliptic curves.
Definition (see also exercise 3.7 in silverman boook for a more generic formula)
Let be an elliptic curve over some field . The set of division polynomials is a sequence of polynomials in that is recursively defined by
and then inductively by the formulas
is also a polynomial for all , and then define further polynomials and by
Given a point on the elliptic curve over some field , we can express the coordinates for the multiple of in terms of division polynomials:
In sage, we can use E.division_polynomial(k) to call the division polynomial
sage: E = EllipticCurve(GF(101),[2,3])
sage: print(E.division_polynomial(5))
5*x^12 + 23*x^10 + 29*x^9 + 85*x^8 + 26*x^7 + 86*x^6 + 31*x^5 + 2*x^4 + 27*x^3 + 62*x^2 + 30*x + 52Read more: Docs
Another method to call is E.multiplication_by_m(k).
Practice
https://cryptohack.org/challenges/isogenies/
Image Point Arithmetic

For this challenge we can applied the property since the isomorphism preserves the group structure
from sage.all import *
p=63079
Px = 48622
Py = 27709
Qx = 9460
Qy = 13819
a = (((Py**2-Qy**2)-(Px**3-Qx**3))*pow(Px-Qx,-1,p)) % p
b = (Py**2 - Px**3 - a*Px )% p
E = EllipticCurve(GF(p), [a,b])
P = E(Px,Py)
Q = E(Qx,Qy)
print(P+Q)Montgomery Curves
Here we are given an elliptic curve over ,
There are three solutions to this problem.
The first one we can simply use the function E.montgomery_model(). This should be available in the newest version of sagemath
The second solution can be explained by following the approach in https://eprint.iacr.org/2017/212.pdf. ince the two curves are related by a degree-one isogeny, their -invariants are equal. For Montgomery curves, the -invariant is calculated as follows:
from sage.all import *
p = 1912812599
E = EllipticCurve(GF(p),[312589632,654443578])
j = E.j_invariant()
P = PolynomialRing(GF(p),'A')
A = P.gen()
f = 256*(A**2-3)**3-j*(A**2-4)
roots = f.roots(multiplicities = False)
for r in roots:
r_ = int(r)
EM = EllipticCurve(GF(p),[0,r_,0,1,0])
if EM.j_invariant() == j:
print(r_)The third solution relies on the two-torsion trick. By mapping a 2-torsion point from the short Weierstrass model to on the Montgomery model, we can derive the corresponding Montgomery coefficient.
So indeed, the 2-torsion point of correspond to another 2-torsion point of . We can pick a 2-torsion point of , for example and make the translation that send our original curve to its Montgomery form
This guarantees that the chosen torsion point in Weierstrass form becomes in the new coordinate system.
DLOG on the Surface
Source code:
import os
from Crypto.Cipher import AES
from Crypto.Hash import SHA256
from Crypto.Util.Padding import pad
proof.all(False)
FLAG = b"crypto{?????????????????????????????????????????????????????????????}"
p = 2**127 - 1
F.<i> = GF(p^2, modulus=[1,0,1])
E = EllipticCurve(F, [1,0])
P, Q = E.gens()
a = randint(0, p) | 1
b = randint(0, p) | 1
c = randint(0, p) | 1
d = randint(0, p) | 1
R = a*P + b*Q
S = c*P + d*Q
def encrypt_flag(a, b, c, d):
data_abcd = str(a) + str(b) + str(c) + str(d)
key = SHA256.new(data=data_abcd.encode()).digest()[:128]
iv = os.urandom(16)
cipher = AES.new(key, AES.MODE_CBC, iv)
ct = cipher.encrypt(pad(FLAG, 16))
return iv.hex(), ct.hex()
iv, ct = encrypt_flag(a, b, c, d)
print(f"{P = }")
print(f"{Q = }")
print(f"{R = }")
print(f"{S = }")
print()
print(f"{iv = }")
print(f"{ct = }")In this challenge, we are given four points of elliptic curve . The curve is described as follow:
p = 2**127 - 1
F.<i> = GF(p^2, modulus=[1,0,1])
E = EllipticCurve(F, [1,0])
P, Q = E.gens()Our base field is and we choose so that the polynomial has no root and is irreducible.
Moreover, there are relations between our given points:
Our goal is to find and recover the secret key.
Because we are working on supersingular elliptic curves over , the abelian group of points on the curve is isomorphic to . Every point in an be expressed as a combination of two independent generators, in our case, they are and . For the torsion subgroup , if then .
To solve this challenge I will use the Weil’s pairing. For more details, one should read the section 1.7 and 1.9 from this notes https://yx7.cc/docs/misc/isog_bristol_notes.pdf

The order of our curve is and this is also the order of .
We will have
Since the order is , solving DLP should be easy. See also the MOV attack / Weil pairing explanation: https://risencrypto.github.io/WeilMOV/
We will do the same for . Note that .
Solve script:
from sage.all import *
from Crypto.Cipher import AES
from Crypto.Hash import SHA256
p = 2**127 - 1
F = GF(p**2, name='i', modulus=[1,0,1])
i = F.gen()
E = EllipticCurve(F,[1,0])
P = E(24722427318870186874942502106037863239*i + 62223422355562631021732597235582046928 , 66881667812593541117238448140445071224*i + 149178354082347398743922440593055790802)
Q = E(136066972787979381470429160016223396048*i + 52082760150043245190232762320312239515 , 37290474751398918861353632929218878189*i + 89777436105166947842660822806860901885)
R = E(115434063687215369570994517493754451626*i + 158874018596958922133589852067300239562 , 62259011436032820287439957155108559928*i + 81253318200557694469168638082106161224)
S = E(42595488035799156418773068781330714859*i + 113049342376647649006990912915011269440 , 25404988689109287499485677343768857329*i + 125117346805247292256813555413193592812)
iv = '6f5a901b9dc00aded4add3791812883b'
ct = '56ecb68a90cad9787a24a4511720d40d625901577f6d0f1eef9fc34cf042709110cdc061fff91e934877674a30ed911283b83927dbcc270ae358d6b1fe2d5bed18ce1b02d8805de55e5b36deb0d28883'
n = P.order()
base = P.weil_pairing(Q,n)
a = discrete_log(R.weil_pairing(Q,n),base,n)
b = (-discrete_log(R.weil_pairing(P,n),base,n)) % n
c = discrete_log(S.weil_pairing(Q, n),base,n)
d = (-discrete_log(S.weil_pairing(P, n),base,n)) % n
key = SHA256.new(f'{a}{b}{c}{d}'.encode()).digest()[:128]
iv = bytes.fromhex('6f5a901b9dc00aded4add3791812883b')
ct = bytes.fromhex('56ecb68a90cad9787a24a4511720d40d625901577f6d0f1eef9fc34cf042709110cdc061fff91e934877674a30ed911283b83927dbcc270ae358d6b1fe2d5bed18ce1b02d8805de55e5b36deb0d28883')
print(AES.new(key, AES.MODE_CBC, iv).decrypt(ct).strip())You can check whether this curve is supersingular or not by using the function: E.trace_of_frobenius() % p == 0
Note:

Currently im using SageMath version 10.6 so this function should be working. Lets try it.
p = 2**127 - 1
F = GF(p**2, name='i', modulus=[1,0,1])
i = F.gen()
E = EllipticCurve(F,[1,0])
P = E(24722427318870186874942502106037863239*i + 62223422355562631021732597235582046928 , 66881667812593541117238448140445071224*i + 149178354082347398743922440593055790802)
Q = E(136066972787979381470429160016223396048*i + 52082760150043245190232762320312239515 , 37290474751398918861353632929218878189*i + 89777436105166947842660822806860901885)
R = E(115434063687215369570994517493754451626*i + 158874018596958922133589852067300239562 , 62259011436032820287439957155108559928*i + 81253318200557694469168638082106161224)
S = E(42595488035799156418773068781330714859*i + 113049342376647649006990912915011269440 , 25404988689109287499485677343768857329*i + 125117346805247292256813555413193592812)
n = P.order()
base = P.weil_pairing(Q,n)
a = discrete_log(R.weil_pairing(Q,n),base,n)
b = (-discrete_log(R.weil_pairing(P,n),base,n)) % n
a_,b_ = E.abelian_group().discrete_log(R,[P,Q])
print(a,b, '\n')
print(a_ % n ,b_ % n ,'\n')One should also including two generators [P,Q]. Without it the result will be different.
Docs
sage: x = polygen(ZZ, 'x')
sage: F.<t> = GF(1009**2, modulus=x**2+11); E = EllipticCurve(j=F(940))
sage: P, Q = E(900*t + 228, 974*t + 185), E(1007*t + 214, 865*t + 802)
sage: E.abelian_group().discrete_log(123 * P + 777 * Q, [P, Q])
(123, 777)
sage:SIDH
Now , lets talk about SIDH and Velu’s formula. There are some prequisite topics that need to be mention again.
Supersingular curve
Theorem. Let be a field of characteristic , and let be an elliptic curve. For each integer , let
be the - power frobenius map and its dual.
Then the following are equivalent:
i/ for one(all)
ii/ is purely inseparable for one(all)
iii/ The map is purely inseparable and .
iv/ is an order in a quaternion algebra
If E has the properties given above, then we say that is supersingular or that has hasse invariant 0
Some deeper properties are unnecessary to mention here, however it is important to note that supersingular curves are all define over
SIDH Scheme

At first, I was reading from this paper: https://eprint.iacr.org/2011/506.pdf
The SIDH Scheme revolve around the following commutative diagram

Setup: Fix the finite field , where
In the original SIDH paper, we choose and an integer is chosen such that is a prime number.
We want the same security level for Bob and Alice , then we set , where is a security parameter.
Then we choose a random supersingular curve over such that .
We use isogenies, with kernels of order , respectively and the following commutative diagram for the SIDH key exchange between Alice and Bob

From the diagram we can see: We first start with an supersingular curve over . Alice then choose a subgroup , Bob also choose a subgroup . The two isogenies are and . Both paths end up at the same final curve
The torsion subgroup will have two torsion bases . Same for .
We define the generators as
The remaining question is: Why does this work?(still dont know why tf this work )
Implement: You can also see this talk by Lorenz Panny
#public
lA, eA, lB, eB = 2, 91, 3, 57
p = lA^eA * lB ^ eB - 1
F.<i> = GF(p^2, modulus=x^2+1)
E0 = EllipticCurve(F, [1, 0])
PA, QA = (lB^eB * G for G in E0.gens())
PB, QB = (lA^eA * G for G in E0.gens())
#Alice
privA = randrange(lA^eA)
KA = PA + privA*QA
phiA = E0.isogeny(KA, algorithm="factored")
pubA = (phiA.codomain(), phiA(PB), phiA(QB))
#Bob
privB = randrange(lB^eB)
KB = PB + privB*QB
phiB = E0.isogeny(KB, algorithm="factored")
pubB = (phiB.codomain(), phiB(PA), phiB(QA))
#Alice
LA = pubB[1] + privA*pubB[2]
psiA = pubB[0].isogeny(LA, algorithm="factored")
sharedA = psiA.codomain()
#Bob
LB = pubA[1] + privB*pubA[2]
psiB = pubA[0].isogeny(LB, algorithm="factored")
sharedB = psiB.codomain()
assert sharedA == sharedB
print(sharedA)Velu’s formula
We have seen that abstractly, isogenies are determined by their kernels. There are some algorithms to compute separable isogenies from their kernel given the following results: Let be an elliptic curve in Weierstrass form, and a finite subgroup of . Let denote the set of nonzero points in , which are affine points .
For all affine points in and not in define:
Here are variables, are elements of and are rational functions of giving coordinates of in term of and .
For we have if and only if so
In general, these formulas are just rational functions of the output mentioned above and the degrees of these functions are the same size as the size of the kernel .
We can see that to evalute Velu’s formula takes operation and the cost is exponential in where is the map that map and
In practice, we will use the two following theorems:
Theorem 1. Let be an elliptic curve over and let be a root of . Define and . The rational map
is a separable isogeny from to where and . The kernel of is the group of order 2 generated by .
Theorem 2. Let be an elliptic curve over and let be a finite subgroup of of odd order. For each non zero in define
The rational map
is a separable isogeny from to where and with .
Practice - 2
Two Isogenies

Using the 2-isogeny formula above and implement it in sage like this:
p = 2**18*3**13-1
F = GF(p**2, names = 'i', modulus = [1,0,1])
i = F.gen()
E = EllipticCurve(F,[1,0])
K = E(i,0)
P.<x> = PolynomialRing(F)
f = x**3+x
roots = f.roots()
print(roots)
A = 1
B = 0
for i in range(len(roots)):
r = roots[i]
try:
x0 = r[0]
t = 3*x0**2 + A
w = x0 * t
A_ = A - 5*t
B_ = B - 7*w
E2 = EllipticCurve(F,[A_,B_])
print(E2.j_invariant())
except Exception as e:
continueWe can use any roots of the equation above to calculate the isogeny or we can use x0 = K.x() instead.
Note that the j_invariant() of and are different because “an isogeny is not an isomorphism”. The j-invariant classifies elliptic curves up to isomorphism, not up to isogeny — so two curves can be isogenous but have different j-invariants.
Newest version of sagemath also give us some useful built-in to work with this:
p = 2**18*3**13-1
F = GF(p**2, names = 'i', modulus = [1,0,1])
i = F.gen()
E = EllipticCurve(F,[1,0])
K = E(i,0)
phi = E.isogeny([K])
print(phi.codomain().j_invariant())Three Isogenies

We can do the same as the previous challenge
p = 2**18*3**13-1
F = GF(p**2, names = 'i', modulus = [1,0,1])
i = F.gen()
E = EllipticCurve(F,[1,0])
K= E(483728976, 174842350631)
phi = E.isogeny([K,2*K])
print(phi.codomain().j_invariant())This is easy but lets calculate it using the above formula for isogenies with odd degree.
p = 2**18*3**13-1
F = GF(p**2, names = 'i', modulus = [1,0,1])
i = F.gen()
E = EllipticCurve(F,[1,0])
K= E(483728976, 174842350631)
Kernel = [K,2*K]
A = 1
B = 0
# tQ
tQ = [3*Q.x()**2 + A for Q in Kernel]
t = sum(tQ)
uQ = [2*Q.y()**2 for Q in Kernel]
wQ = [uQ[i]+tQ[i]*Q.x() for i,Q in enumerate(Kernel)]
w = sum(wQ)
A_ = A-5*t
B_ = B-7*w
E2 = EllipticCurve(F,[A_,B_])
print(E2.j_invariant())
phi = E.isogeny(Kernel)
print(phi.rational_maps())Composite Isogenies

For isogenies with composite degree we can calculate it in sage by phi = E.isogeny(K,algorithm = 'factored').
The idea
SIDH Key Exchange

Implement:
# This file was *autogenerated* from the file SIDH.sage
from sage.all_cmdline import * # import sage library
_sage_const_110 = Integer(110); _sage_const_67 = Integer(67); _sage_const_2 = Integer(2); _sage_const_3 = Integer(3); _sage_const_1 = Integer(1); _sage_const_0 = Integer(0); _sage_const_118242575052254473701407051403380184157502700009529430046122822477 = Integer(118242575052254473701407051403380184157502700009529430046122822477); _sage_const_57638278144985143549644316704182130279784191379170896458696787312 = Integer(57638278144985143549644316704182130279784191379170896458696787312); _sage_const_80915735815367072410310689908590367651933218830435520913424043510 = Integer(80915735815367072410310689908590367651933218830435520913424043510); _sage_const_35228327576503752484578273317308597612913304063200715424014549037 = Integer(35228327576503752484578273317308597612913304063200715424014549037); _sage_const_27856673727210297071672501895829918842041821446996051944738115273 = Integer(27856673727210297071672501895829918842041821446996051944738115273); _sage_const_101349537690838191347553037323956940169953967852439843389873653018 = Integer(101349537690838191347553037323956940169953967852439843389873653018); _sage_const_45955772915614774101614751673022340983778200451506382887743008335 = Integer(45955772915614774101614751673022340983778200451506382887743008335); _sage_const_76499786039494489791183573966490259392789635716963920208794989512 = Integer(76499786039494489791183573966490259392789635716963920208794989512); _sage_const_68702305424425607424554396971378391833152415806389206440833676844 = Integer(68702305424425607424554396971378391833152415806389206440833676844); _sage_const_63162905189208938201083385603424075109355856156240516441321158383 = Integer(63162905189208938201083385603424075109355856156240516441321158383); _sage_const_14452401602439328239712793251073780692192036710425129093829067649 = Integer(14452401602439328239712793251073780692192036710425129093829067649); _sage_const_110903430163815016394569999096524527007769669322432532390635606190 = Integer(110903430163815016394569999096524527007769669322432532390635606190); _sage_const_50967992419888058158544483269655763559879646024537212566396940681 = Integer(50967992419888058158544483269655763559879646024537212566396940681); _sage_const_39165103284419354968504615023980382940222714919046676966425620242 = Integer(39165103284419354968504615023980382940222714919046676966425620242); _sage_const_113476160032430656302485251779124302915433268423829474022852380544 = Integer(113476160032430656302485251779124302915433268423829474022852380544); _sage_const_74814862075401178218909769629701747112662266906635780085603780902 = Integer(74814862075401178218909769629701747112662266906635780085603780902); _sage_const_225902606209514408534212339057054 = Integer(225902606209514408534212339057054); _sage_const_38410379124791756271891302485727 = Integer(38410379124791756271891302485727); _sage_const_128 = Integer(128); _sage_const_16 = Integer(16)
import os
from Crypto.Cipher import AES
from Crypto.Hash import SHA256
from Crypto.Util.Padding import pad,unpad
FLAG = b"crypto{?????????????????????????????????????}"
# Base field
ea, eb = _sage_const_110 , _sage_const_67
p = _sage_const_2 **ea*_sage_const_3 **eb - _sage_const_1
F = GF(p**_sage_const_2 , modulus=[_sage_const_1 ,_sage_const_0 ,_sage_const_1 ], names=('i',)); (i,) = F._first_ngens(1)
# Public curve
E0 = EllipticCurve(F, [_sage_const_1 ,_sage_const_0 ])
# Torsion points
P2 = E0(_sage_const_118242575052254473701407051403380184157502700009529430046122822477 *i + _sage_const_57638278144985143549644316704182130279784191379170896458696787312 , _sage_const_80915735815367072410310689908590367651933218830435520913424043510 *i + _sage_const_35228327576503752484578273317308597612913304063200715424014549037 )
Q2 = E0(_sage_const_27856673727210297071672501895829918842041821446996051944738115273 *i + _sage_const_101349537690838191347553037323956940169953967852439843389873653018 , _sage_const_45955772915614774101614751673022340983778200451506382887743008335 *i + _sage_const_76499786039494489791183573966490259392789635716963920208794989512 )
P3 = E0(_sage_const_68702305424425607424554396971378391833152415806389206440833676844 *i + _sage_const_63162905189208938201083385603424075109355856156240516441321158383 , _sage_const_14452401602439328239712793251073780692192036710425129093829067649 *i + _sage_const_110903430163815016394569999096524527007769669322432532390635606190 )
Q3 = E0(_sage_const_50967992419888058158544483269655763559879646024537212566396940681 *i + _sage_const_39165103284419354968504615023980382940222714919046676966425620242 , _sage_const_113476160032430656302485251779124302915433268423829474022852380544 *i + _sage_const_74814862075401178218909769629701747112662266906635780085603780902 )
# Secret Keys
sA = _sage_const_225902606209514408534212339057054
sB = _sage_const_38410379124791756271891302485727
# TODO
def gen_public_key():
KA = P2 + sA*Q2
phiA = E0.isogeny(KA, algorithm = 'factored')
KB = P3 + sB*Q3
phiB = E0.isogeny(KB, algorithm = 'factored')
Alice_pub = [phiA(P3),phiA(Q3)]
Bob_pub = [phiB(P2),phiB(Q2)]
EA = phiA.codomain()
EB = phiB.codomain()
return Alice_pub, Bob_pub, EA, EB
# TODO
def gen_shared_secret():
Alice_pub, Bob_pub, EA, EB= gen_public_key()
ker_SA = Bob_pub[_sage_const_0 ] + sA*Bob_pub[_sage_const_1 ]
phi_SA = EB.isogeny(ker_SA,algorithm='factored')
ker_SB = Alice_pub[_sage_const_0 ] + sB*Alice_pub[_sage_const_1 ]
phi_SB = EA.isogeny(ker_SB, algorithm='factored')
E_SA = phi_SA.codomain()
E_SB = phi_SB.codomain()
j_SA = E_SA.j_invariant()
j_SB = E_SB.j_invariant()
assert j_SA == j_SB
return j_SA
# TODO
shared_secret = gen_shared_secret()
s_ = E0.isogeny([P2 + sA * Q2, P3 + sB * Q3], algorithm="factored").codomain().j_invariant()
print(s_)
print(shared_secret)
def encrypt_flag(shared_secret):
key = SHA256.new(data=str(shared_secret).encode()).digest()[:_sage_const_128 ]
iv = os.urandom(_sage_const_16 )
cipher = AES.new(key, AES.MODE_CBC, iv)
ct = cipher.encrypt(pad(FLAG, _sage_const_16 ))
return iv.hex(), ct.hex()
def decrypt_flag(shared_secret, iv_hex, ct_hex):
# build same key
key = SHA256.new(data=str(shared_secret).encode()).digest()[:_sage_const_128 ]
iv = bytes.fromhex(iv_hex)
ct = bytes.fromhex(ct_hex)
cipher = AES.new(key, AES.MODE_CBC, iv)
m = cipher.decrypt(ct)
msg = unpad(m, int(_sage_const_16 ))
return msg.decode()
iv = "05a4cfbce59acb952128af83c9694390"
ct = "755b72b2e3bef2e7a4b2ce4a370f287ad04c1359bace25f3def8be23c0c49e89b4302408ad2dcb02d4875fe58c543d91"
print(decrypt_flag(s_, iv, ct))Breaking SIDH
Resources
1 Note của anh Giáp
2 Supersingular Isogeny Key Exchange for Beginners
3 Isogeny School Week 3
4 Sage’s Syntax for Isogenies
5 COSIC Mathematical Foundations of Post-Quantum Cryptography
6 Mathematics of Isogeny Based Cryptography
7 Benjamin Wesolowski’s Talk
8 Silverman - AEC
9 Isogenies for Cryptography, Maria’s Blog
10 https://eprint.iacr.org/2011/506.pdf
11 Lorenz Panny’ Thesis
12 https://www.math.auckland.ac.nz/~sgal018/Yi-Fu-Lai-PhD.pdf