Formalisation des courbes elliptiques
Formalisation des courbes elliptiques
Evmorfia-Iro Bartzia
Thèse de doctorat
de l’Université Paris-Saclay
préparée à Inria Paris
Équipe Prosecco
Evmorfia-Iro Bartzia
A Formalization of Elliptic Curves
for Cryptography
Composition du Jury :
M. Gilles Barthe, Professeur Relecteur
IMDEA Software Institute, Madrid, Espagne
M. Karthikeyan Bhargavan, Directeur de recherche Directeur de thèse
Inria Paris, France
M. Philippe Guillot, Maître de conférences Examinateur
Université de Paris 8, France
Mme. Assia Mahboubi, Chargé de recherche Examinatrice
Inria Saclay - Île de France, France
Mme. Christine Paulin-Mohring, Professeur Présidente du jury
Université Paris-Sud, France
M. Ben Smith, Chargé de recherche Examinateur
Inria Saclay - Île de France, France
M. Bas Spitters, Professeur associé Relecteur
Université d’Aarhus, Danemark
M. Pierre-Yves Strub, Maître de conférences Co-directeur de thèse
École Polytechnique, France
To Fredo and Robert
Contents
1 Introduction 1
1.1 History of formal methods . . . . . . . . . . . . . . . . . . . . . . 1
1.2 Proof assistants . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
1.3 Use of formal methods in mathematics . . . . . . . . . . . . . . . 3
1.4 Use of formal methods in cryptography . . . . . . . . . . . . . . 5
1.5 Elliptic curves and cryptography . . . . . . . . . . . . . . . . . . 7
1.6 Contribution of this thesis . . . . . . . . . . . . . . . . . . . . . . 8
2 Background 10
2.1 Mathematical background . . . . . . . . . . . . . . . . . . . . . . 10
2.1.1 Elliptic curves definitions . . . . . . . . . . . . . . . . . . 10
2.1.2 Defining addition . . . . . . . . . . . . . . . . . . . . . . . 14
2.1.3 Riemann Roch and the group law . . . . . . . . . . . . . 16
2.2 Use of elliptic curves in cryptography . . . . . . . . . . . . . . . . 21
2.2.1 Algorithms for scalar multiplication . . . . . . . . . . . . 25
2.2.2 Use of different coordinate systems . . . . . . . . . . . . . 30
2.3 Coq and its Ssreflect extension . . . . . . . . . . . . . . . . . 31
2.3.1 Propositions and Types . . . . . . . . . . . . . . . . . . . 32
2.3.2 Coq by example . . . . . . . . . . . . . . . . . . . . . . . 33
2.3.3 Functions and Equality . . . . . . . . . . . . . . . . . . . 36
2.3.4 Inductive types . . . . . . . . . . . . . . . . . . . . . . . . 36
2.3.5 The Ssreflect extension . . . . . . . . . . . . . . . . . . 39
v
CONTENTS vi
5 Applications 95
5.1 Verifying GLV with CoqEAL (future work) . . . . . . . . . . . . 95
5.2 A Verified Library of Elliptic Curves in F∗ . . . . . . . . . . . . . 96
5.3 An Ssreflect library for monoidal algebras . . . . . . . . . . . 100
6 Conclusion 103
References 106
Une formalisation des courbes elliptiques pour la cryptographie.
Le sujet de ma thèse s’inscrit dans le domaine des preuves formelles et de la vérification des algo-
rithmes cryptographiques. L’implémentation des algorithmes cryptographiques est souvent une tâche assez
compliquée, parce qu’ils sont optimisés pour être efficaces et sûrs en même temps. Par conséquent, il n’est
pas toujours évident qu’un programme cryptographique en tant que fonction, corresponde exactement à
l’algorithme mathématique, c’est-à-dire que le programme soit correct. Les erreurs dans les programmes
cryptographiques peuvent mettre en danger la sécurité de systèmes cryptographiques entiers et donc, des
preuves de correction sont souvent nécessaires. Les systèmes formels et les assistants de preuves comme
Coq et Isabelle-HOL sont utilisés pour développer des preuves de correction des programmes. Les courbes
elliptiques sont largement utilisées en cryptographie surtout en tant que groupe cryptographique très
efficace. Pour le développement des preuves formelles des algorithmes utilisant les courbes elliptiques, une
théorie formelle de celles-ci est nécessaire. Dans ce contexte, nous avons développé une théorie formelle
des courbes elliptiques en utilisant l’assistant de preuves Coq. Cette théorie est par la suite utilisée pour
prouver la correction des algorithmes de multiplication scalaire sur le groupe des points d’une courbe
elliptique.
Plus précisément, mes travaux de thèse peuvent être divisées en deux parties principales. La première
concerne le développement de la théorie des courbes elliptiques en utilisant l’assistant des preuves Coq.
Notre développement de plus de 15000 lignes de code Coq comprend la formalisation des courbes elliptiques
données par une équation de Weierstrass, la théorie des corps des fonctions rationnelles sur une courbe, la
théorie des groupes libres et des diviseurs des fonctions rationnelles sur une courbe. Notre résultat principal
est la formalisation du théorème de Picard ; une conséquence directe de ce théorème est l’associativité de
l’opération du groupe des points d’une courbe elliptique qui est un résultat non trivial à prouver. La seconde
partie de ma thèse concerne la vérification de l’algorithme GLV pour effectuer la multiplication scalaire
sur des courbes elliptiques. Pour ce développement, nous avons vérifier trois algorithmes indépendants : la
multiexponentiation dans un groupe, la décomposition du scalaire et le calcul des endomorphismes sur
une courbe elliptique. Nous avons également développé une formalisation du plan projectif et des courbes
en coordonnées projectives et nous avons prouvé que les deux représentations (affine et projective) sont
isomorphes.
Mon travail est à la fois une première approche à la formalisation de la géométrie algébrique élémentaire
qui est intégré dans les bibliothèques de Ssreflect mais qui sert aussi à la certification de véritables
programmes cryptographiques.
The idea of mechanized reasoning probably began in the 17th century with
Leibniz who was the first to imagine a universal language (characteristica univer-
salis) where all statements could be expressed and checked for their truth value
via a calculus of reasoning (calculus ratiocinator). Interestingly, Leibniz’s char-
acteristica was not limited to expressing mathematical statements. He imagined
a universal language where all controversial statements could be resolved by his
calculus and therefore no disagreement could take place. Nevertheless, one had
to wait until the beginning of the 20th century, when important progress in the
domain of mathematical logic introduced once again Leibniz’s idea limited to
mathematical statements. The realization that common mathematical state-
ments can be expressed using formal axiomatic systems in such a way that it
would be possible (at least in principle) to automatically check if they are correct
or not, was one of the most important steps in the history of mathematics in
1
the 20th century. The first to present such a system was Frege [Fre93] in 1893,
followed by Zermelo with axiomatic set theory (in 1908), Russell and Whitehead
with ramified type theory in Principia Mathematica (in 1913), and Church with
simple type theory (in 1940).
Formalization consists of two aspects: (i) expressing statements in some
formal language and (ii) develop proofs based on a fixed set of rules, in a way
that their correctness can be checked by some algorithm. However, in practice,
formalizing mathematical theorems and proofs is extremely difficult to do by
hand:
"...the tiniest proof at the beginning of the Theory of Sets would already
require several hundreds of signs for its complete formalization... formalized
mathematics cannot in practice be written down in full... We shall therefore very
quickly abandon formalized mathematics." (Bourbaki)
Even Russell himself stated that his intellect never recovered from the strain of
writing Principia Mathematica. To sum up, as Rasiowa and Sikorski report: The
mechanical method of deducing some mathematical theorems has no practical
value, because this is too complicated in practice. As a result, the idea of
formalizing proofs has not prevailed and few mathematicians have actually
exercised it. However, the rise of computer science in the late 20th century has
made possible the complete formalization of complex mathematical theorems
and proofs. Since then, major progress has been made in the development of
axiomatic formal systems, and several impressive results have followed, like
the formalization of the prime number theorem [ADGR07] or the four color
theorem [Gon07].
2
But why one should believe that a formal proof checked by some proof
assistant is equally or even more reliable than a common hand proof? Given the
proof assistant’s architecture, the validity of a formal statement and its proof is
checked by the proof assistant’s kernel. Yet, a question naturally arises: If the
kernel checks the proof, who checks the kernel? The answer is that one needs to
trust that the kernel is correct. Nevertheless, the reliability of proof assistants
relies on their architecture: Usually the size of the kernel is much smaller and
simpler compared to the prover itself. Keeping the kernel negligibly small and
readable by humans minimizes the probability of errors. If the kernel is correct
and bug-free, then any proof checked by the kernel is guaranteed to be correct
too, and one can be certain that all the mathematical theories formalized on
top of it are correct too. As a result, the proof assistant is much easier to trust,
since we just need to trust a small readable part and then everything that is
constructed on top of it is mechanically checked for correctness. In that sense,
any proof checked by a theorem prover is more reliable than a human paper
proof, since (as will be explained next) it is not unusual for hand proofs to lack
rigor or to contain unspotted errors.
Coq [The10, BC04] is the proof assistant used in this thesis. Coq comes with a
pure functional programming language and a set of deduction and computational
rules that characterize the logic. There are proof tactics that allow the user to
interactively construct proofs and there are libraries of proved mathematical
theorems available for use. A short introduction to Coq is given in Section 2.3.
Coq logic is the Calculus of Inductive Constructions [The10, PP89], a de-
pendently typed polymorphic lambda calculus. In contrast to classical logic, Coq
logic is constructive, which means that the excluded middle principle does not
hold. Furthermore, it means that to prove any existential statement, one needs
to provide an explicit witness for the statement to hold. These consequences
of constructiveness need to be taken into account, and it remains an important
difference when trying to construct a formal proof in Coq from a non-constructive
mathematical paper proof. Another significant aspect of Coq logic is the Curry–
Howard correspondence: The relation between a program (i.e. a function) and
its type is the same as the relation between a proposition and its proof. The
Curry–Howard correspondence makes the Coq language suitable for writing both
programs and logical formulas.
3
particular standards: in other words whether it is correct. The debates on the
foundations of mathematics at the beginning of the 20th century were aiming to
address the first concern of what methods are legitimate to prove a mathematical
statement. However, formal methods are not designed to address this particular
problem, because formal correctness can be guaranteed only with respect to some
axiomatic logical framework, which is determined in advance. In a certain sense,
formal methods can be used to check the validity of mathematical statements
but only modulo a pre-existing underlying set of rules. Nevertheless, establishing
correctness and improving the rigor of mathematical statements is an important
issue for which formal methods are extremely helpful.
Indeed, guaranteeing the correctness of a mathematical statement is not a
trivial concern: unfortunately, imprecise statements and definitions, missing cases,
unclear hypotheses and unexplained inferences are very common in mathematical
literature. Moreover, mathematical proofs can sometimes be so complex that even
after being subjected to extensive peer-review, mistakes often escape unnoticed.
A large number of mathematical proofs have been found to contain errors
throughout the years: in 1935 Lecat wrote a book that includes 130 pages
of errors made by mathematicians up to 1900 [AH14]. Formal verification is
especially interesting for
1. proofs that are very long and complex such as the Classification of finite
simple groups or the Seymour-Robertson graph minor theorem,
2. proofs that rely on extensive calculation or that need explicit checking
of cases such as the Four-colour theorem or Hales’s proof of the Kepler
conjecture,
3. proofs where complete rigor is particularly painful such as program verific-
ation.
During the last few years, significant formalization efforts have taken place
and many impressive results have been formalized such as: the prime number
theorem (Avigad et al using Isabelle/HOL, Harrison et al using HOL Light), the
four-color theorem (Gonthier et al using Coq), the Jordan curve theorem (Hales
et al using HOL Light, Trybulec et al. using Mizar), the Hales proof of the
Kepler conjecture (Flyspeck project using HOL light and Isabelle) and the Feit–
Thompson Odd Order Theorem (Georges Gonthier et al using Coq). However,
maybe even more important than the results themselves are the mathematical
theories developed to support these formalizations. Those developments include
libraries about number theory, finite group theory, Galois theory, linear algebra,
real and complex analysis, probability theory and more which can be used for
future formalizations.
Formal verification is also useful in computer science to prove the correctness
of computer software and hardware. In most developments (software or hardware)
we do not even have informal proofs of correctness. To certify correctness,
4
software and hardware are routinely tested for bugs. Nevertheless it is impossible
to test exhaustively in most cases and bugs are sometimes not detected with
really disastrous consequences. Formal methods can be used to certify the
correctness of software and hardware.
5
mentations of the underlying primitives have received far less attention from the
formal verification community.
For symmetric primitives such as block ciphers and hash functions, the
algorithm is the specification. Hence, verifying a block cipher implementation
amounts to proving the equivalence between a concrete program written for
some platform and an abstract program given in the standard specification.
Practitioners commonly believe that a combination of careful code inspection
and comprehensive testing is enough to provide high-assurance for such primitives,
although a more formal approach can also be used to prove correctness [App15a].
For asymmetric primitives such as RSA encryption, finite field Diffie–Hellman,
or elliptic curves, the gap between specification and code can be large. Abstractly,
such primitives compute well-defined mathematical functions in some finite
field, whereas concretely, their implementations manipulate arrays of bytes that
represent arbitrary precision integers. Moreover, asymmetric cryptography is
based on a more complex mathematical theory than symmetric cryptography,
such as number theory and algebraic geometry in the case of elliptic curves. As a
result, asymmetric algorithms designed to exploit certain mathematical properties
(of the underlying field for example) are more complicated to understand and to
implement correctly. Such an example is the Montgomery reduction algorithm
to perform modular reduction in prime fields.
Furthermore, since asymmetric primitives are typically much slower and can
form the bottleneck in a cryptographic protocol, most implementations incorpor-
ate a range of subtle performance optimizations that further distance the code
from the mathematical specification. Further optimizations may take place in
order for the implementation to satisfy security criteria such as side channel res-
istance. Consequently, even for small prime fields, comprehensive testing is inef-
fective for guaranteeing the correctness of asymmetric primitive implementations,
leading to bugs even in well-vetted cryptographic libraries [BBPV12, Ope15].
Even worse, asymmetric primitives are often used with long-term keys, so any
bug that leaks underlying key material can be disastrous.
To sum up, besides functional correctness, cryptographic algorithms need to
achieve contradictory goals such as efficiency and side–channel resistance. Faulty
implementations of algorithms may endanger security [BBPV11a]. This is why
formal assurance of their correctness is essential; even more so when it comes to
asymmetric primitives which are based on complex mathematical theories.
Our motivation in this thesis is to develop libraries to allow the formal veri-
fication of asymmetric cryptographic algorithms, more precisely of elliptic curve
algorithms. Until now work on formal verification of security protocols assumed
that the cryptographic libraries correctly implement all algorithms [APS12].
The first step towards the formal verification of cryptographic algorithms is the
development of libraries that formally express the corresponding mathematical
6
theory. This thesis presents a formal library for elementary elliptic curve theory
that will enable formal analysis of elliptic-curve algorithms. We also present the
formalization of the GLV algorithm for scalar multiplication on an elliptic curve
group [GLV01].
7
surveillance have led to a shift towards the use of elliptic curves in preference to
older public–key primitives such as RSA, which no longer provide a sufficient level
of security. In that context, elliptic curve cryptosystems are of major significance
for many protocols and applications nowadays, and therefore the efficient and
secure implementation of elliptic curves schemes is of key importance.
The main operation performed in elliptic curve schemes is scalar multiplica-
tion, denoted [k]P in this thesis (where P is a point on an elliptic curve and k is an
integer). Several different algorithms are used to speed up scalar multiplication,
ranging from generic exponentiation algorithms such as binary exponentiation
to curve specific algorithms such as GLV [GLV01] and GLS [GLS09]. Usually,
these algorithms are further optimized to achieve better performance by using
special curve forms and alternative curve coordinate systems [CMO98, CC86].
Moreover, sometimes further optimizations are used to accelerate the underlying
field arithmetic. In practice, implementations have to take security criteria such
as side–channel resistance into consideration, so they are even further modified.
As a result, implementations of elliptic curve algorithms can be particularly
tricky, and in most cases it is not evident that an implementation is correct.
This problem can be approached with the use of formal methods, which can
provide formal certification that an implementation is correct. In that context,
libraries to provide a formal theory for elliptic curves are needed. And this is
what we provide.
8
exploits properties of the elliptic curve group in order to accelerate computation.
It is composed of three independent algorithms : multiexponentiation on a
generic group, decomposition of the scalar and computing endomorphisms on
algebraic curves. This development includes theory about endomorphisms on
elliptic curves and is more than 5000 lines of code.
An application of our formalization is presented in Chapter 5. This work
consists of formally proving real-life implementations of elliptic curve algorithms
combining our development in Coq and F∗ , which is a new higher order pro-
gramming language designed for program verification.
The entire development presented in this thesis is available at https://
[Link]/strub/glv.
9
Background
2
2.1 Mathematical background
2.1.1 Elliptic curves definitions
Definition 2.1 (Projective plane). The projective plane P2 over F is the quotient
P2 = (F \(0,0,0))/∼ where (x, y, z) ∼ (x0 , y 0 , z 0 ) if and only if there exists a λ ∈ F∗
3
Definition 2.2 (Curve of the projective plane). A curve of the projective plane
is the set of projective points (x : y : z) whose coordinates are a solution of a
homogeneous equation f (x, y, z) = 0.
Y 2 Z + a1 XY Z + a3 Y Z 2 = X 3 + a2 X 2 Z + a4 XZ 2 + a6 Z 3
10
There exists a one-to-one correspondence between the projective plane P2
and the union of an affine plane F2 and the projective line at infinity. (To be
more precise, there exists an isomorphism of algebraic varieties between the
projective plane and the above union). Indeed, let v = (x, y, z) be a non zero
vector of F3 . If z 6= 0 then the equivalence class of v (denoted here [v]) is
[v] = [z −1 v] = ( xz : yz : 1) and there exists a unique representative of the class of
the form (x0 , y 0 , 1). Hence, there is a 1-to-1 map between the set of projective
points with z 6= 0 and F2 . If z = 0, then x and y cannot both be zero because
v is a non zero vector. Moreover, if x 6= 0 then [v] = [x−1 v] = ( xx : xy : 0) and
so there exists a unique representative of the class of the form (1, y 0 , 0). So,
there exists a 1-to-1 map between the set of projective points with z, x 6= 0
and F. If z = 0 and x = 0 then [v] = [y −1 v] = [0, yy , 0] = (0 : 1 : 0). Hence,
P2 ∼= F2 ∪ F ∪ {(0 : 1 : 0)}.
In this setting, an elliptic curve of equation Y 2 Z + a1 XY Z + a3 Y Z 2 =
X 3 + a2 X 2 Z + a4 XZ 2 + a6 Z 3 in projective coordinates is isomorphic to the
curve of equation y 2 + a1 xy + a3 y = x3 + a2 x2 + a4 x + a6 of the affine plane,
together with a separate point O called the point at infinity. A projective point
of the elliptic curve with z = 0 is of the form (0 : y : 0), and since a projective
point is an equivalence class, we can choose the representative (0, 1, 0) for this
class. This is the point at infinity (0 : 1 : 0) in projective coordinates, which
plays an important role when moving to the definition of the group law. This
part is explained in details in Chapter 3.
If the characteristic of the field F is not 2 or 3, then by an appropriate change of
variables [Sil09], an elliptic curve can be written in the form y 2 z = x3 +axz 2 +bz 3 ,
where a and b are elements of F. The condition that the curve is smooth reduces
to ∆ = 4a3 + 27b2 6= 0.
Most of the time, when introducing elliptic curves in a cryptographic context,
we use its short Weierstrass form:
The below remarks are not necessary to understand the mathematics of our
development and the reader may skip them, but they provide interesting context
to elliptic curve theory.
11
Remark 1 : Isomorphisms of algebraic curves
12
equation), but unfortunately it does not work for curves of higher degree. For
example, let us consider the non-singular curves L : y = 0 and C : yz − x2 = 0.
The curves L and C are isomorphic: There exists a mapping m : (x : y : z) 7→
(x : 0 : z) from C to L and a mapping n : (x : y : z) 7→ (xz : x2 : z 2 ) from
L to C such that (m ◦ n)(x : y : z) = (x : y : z) for all (x : y : z) ∈ L and
(n ◦ m)(x : y : z) = (x : y : z) for all (x : y : z) ∈ C. One would want the
measure that characterizes the geometric complexity of algebraic curves to be
invariant under isomorphism. Nevertheless, in this case L is of degree 1 and C
is of degree 2.
The genus is a non-negative integer that can be associated to any algebraic
curve and characterizes the geometric complexity of the curve. For example:
— the curve C1 : y = x has genus 0,
— the curve C2 : y 2 = x2 + Bz 2 has genus 0,
— the curve C3 : y 2 z = x3 + Axz 2 + Bz 3 has genus 1,
— the curve C4 : y 2 z 2 = x4 has genus 1, and
— the curve C5 : y 2 z 3 = x5 + xz 4 has genus 2.
To compute the genus of a non-singular curve, we can use the formula
(d−1)(d−2)
2 ,where d is the degree of the curve. For singular curves, which is out
of scope for this thesis, see [Cas91].
A smooth projective plane curve of genus 1 is a cubic defined by a homogen-
eous polynomial of the form
f (x, y, z) = Ax3 +By 3 +Cz 3 +Dx2 y+ Ex2 z+F y 2 x+Gy 2 z+Hz 2 x+Iz 2 y+Jxyz.
13
2.1.2 Defining addition
From this point on, we consider fields with characteristic different from 2, 3
and so we are free to interchange between the projective and the short Weierstrass
form of elliptic curves.
To understand the group law, one first needs to understand Bézout’s theorem
for elliptic curves:
Lemma 2.1 (Bézout for elliptic curves). Let F be an algebraically closed field,
and f ∈ F[X, Y, Z] a homogeneous polynomial of degree 3. Let E be the elliptic
curve defined by the equation E : Y Z = X 3 + aXZ 2 + bZ 3 and L a line (not
contained in E). Then L ∩ E has exactly 3 points counted with multiplicity.
More precisely, a line in the projective space is the set of projective points
(X : Y : Z) which are the solutions of the equation kX + lY + mZ = 0 for
some k, l, m ∈ F (k, l, m not all zero). Given an elliptic curve E of equation
E : Y Z = X 3 + aXZ 2 + bZ 3 , there exist three different kinds of lines:
1. the line of equation Z = 0, which intersects the elliptic curve E at the
point at infinity (0 : 1 : 0) with multiplicity 3,
2. the line of equation X + cZ = 0 (with c 6= 0) which intersects the elliptic
curve E at the point at infinity and at the points (−c : (−c)3 − ac + b : 1),
p
y 2 = x3 + ax + b
(
kx + ly + m = 0.
14
This geometrical definition can be translated into an algebraic setting, ob-
taining the following polynomial formulas: Let P = (xP , yP ) and Q = (xQ , yQ )
be two finite points. Then:
1. if P 6= Q, then P + Q = (xS , yS ) with:
xS = λ 2 − xP − xQ
(
yP − yQ
where λ = ,
yS = −λ3 + 2λxP − λxQ − yQ xP − xQ
2. if P = Q with yP = yQ =
6 0, then will apply the previous formulas with
λ = (3xP +a)/2yP ,
2
3. if P = Q with yP = yQ = 0, then P + Q = O.
u = 3x2P + azP2 xS = vr
v = 2yP2 yS = −u(r − v 2 x) − yP v 3
r = u2 zP − 2v 2 xP zS = zP v 3 .
— If P 6= Q then
u = yQ zP − yP zQ xS = vr
v = xQ zP − xP zQ yS = −u(r − xP zQ v 2 ) − yP zQ v 3
r = u2 zP zQ − v 2 (xP zQ + xQ zP ) zS = zP zQ v 3 .
15
define an intersection multiplicity at P , denoted here as vP (C, D). We are not
going to give here the detailed definition of this intersection multiplicity, for
more details see [Sut15].
Lemma 2.2 (Bézout). Let C, D be two plane projective curves over an algebra-
ically closed field F of degree m and n respectively. Suppose that C and D share
no common components. Let S be the set of intersection points C(F) ∩ D(F).
Then P ∈S vP (C, D) = mn.
P
Theorem 2.3 (Bézout). Let X and Y be two plane projective curves defined
over a field F that do not have a common component (i.e. X and Y are defined
by polynomials whose greatest common divisor is a constant). Then the total
number of intersection points of X and Y with coordinates in an algebraically
closed field E which contains F, counted with multiplicity, is equal to the product
of the degrees of X and Y .
16
m0 m1 m2
O
l0
−(P +R) (P +R)
T
l1
R S P +Q
l2
P Q −(P +Q)
The following lemma is a direct consequence of the Bézout theorem for cubics
and allows to prove that the addition on elliptic curve points, as defined above,
is a group law.
Lemma 2.4. In a projective plane, let Aij be the intersection points of the
straight lines pi and qj where 1 ≤ i, j ≤ 3, and the points Aij are pairwise
distinct. Suppose that all points Aij , except perhaps A33 lie on a cubic. Then
A33 also lies on this cubic.
The sketch of the proof given here is partly from [Sut15] which is an adaptation
of the proof initially given in [Cas91] and partly from [HIS14]. It only concerns
the general case (meaning that in the diagram in Figure 2.1, the points are
related only by the way the diagram is constructed and in no other way).
Let P, Q, R be three distinct non-zero points of an elliptic curve E over some
field F, that we consider algebraically closed.
— Let l0 the line through P and Q. The third point of intersection with E is
the point −(P + Q).
— Let m0 the line through P and R. The third point of intersection with E
is the point −(P + R).
— Let m2 the line through −(P +Q) and P +Q. The third point of intersection
with E is the point O.
— Let l2 the line through −(P +R) and P +R. The third point of intersection
with E is the point O.
— Let m1 the line through Q and P + R. The third point of intersection with
E is the point S = −(Q + (P + R)).
— Let l1 the line through R and P + Q. The third point of intersection with
E is the point T = −(R + (P + Q)).
It suffices to show that S = T . By the aforementioned Bézout theorem, the
intersection point of m1 and l1 is on the curve E. As a result, l1 intersects the
curve at Q, P + R and A. Hence, A = S. Following the same reasoning for m1 ,
A = T and therefore T = S and the addition is associative.
17
The computational proof
18
The degree of a divisor D = P ∈C nP (P ) is defined to be the sum of the
P
has a zero at P , the order is the degree of the zero, and if f has a pole at
P , the order is the opposite of the degree of the pole). This is a degree-zero
divisor because functions on smooth projective curves have equal numbers
of zeros and poles.
3. A divisor is principal if it is the divisor of some nonzero function. The
principal divisors form a subgroup of Div0 (C) denoted Prin(C), and there-
fore we can quotient Div(C) by Prin(C) and form the group of divisors
modulo principal divisors. This quotient group is called the Picard group
and is denoted Pic(C). Two divisors are equivalent if they belong to the
same class of the Picard group.
4. Let w be a nonzero differential form on C. We do not give a definition of
differential forms here, for details see [Ful89]. We can associate a divisor
to w by computing its zeros and the corresponding orders of vanishing. All
nonzero differentials are in the same class of the Picard group, called the
canonical divisor KC .
5. A divisor D is called effective, denoted by D ≥ 0, if all coefficients of D
are greater than or equal to zero. This is extended to a partial order on
Div(C) as follows:
nP (P ) ≥ mP (P ) ⇐⇒ nP ≥ mP .
X X
∀P,
P ∈C P ∈C
To prove that the elliptic curve law is associative, one has to prove that there
exist an isomorphism between Pic0 (E) and E: note that Pic0 (E), which is the
Picard group of zero-degree divisors, is an abelian group (as it is a quotient of
19
abelian groups). Because of the Riemann–Roch theorem, every class of Pic0 (E)
has a unique representative of the form [(P ) − (O)] where P ∈ C. Thus, there
exists a bijection between Pic0 (E) and E, which is also a morphism. By transport
of structure, E is also an abelian group. The fact that every class of Pic0 (E) has
a unique representative of the form [(P ) − (O)] is a direct consequence of the
Riemann Roch theorem:
Existence Recall that an elliptic curve is a smooth curve of genus 1. From
Riemann–Roch, we have that l(D + (O)) = 1: Remark that, in the case
of elliptic curves, g = 1 =⇒ 2g − 2 = 0, so any divisor D with degree
greater than zero satisfies l(KE − D) = 0.
Given a zero degree divisor D, deg(D + (O)) = 1 > 0 =⇒ l(KE − D −
(O)) = 0. Hence, l(D + (O)) − l(KE − D − (O)) = deg(D + (O)) =⇒
l(D + (O)) = 1. Given a generator f of L(D + (O)), we have div(f ) >
−D − (O) and deg(div(f )) = 0. So there exists a point P ∈ E such that
div(f ) = −D − (O) + (P ). As a result, D ∼ (P ) − O.
Uniqueness To prove that the representative is unique, we have to prove that
if (P ) ∼ (Q) then P = Q: From Riemann–Roch, we have l((Q)) = 1.
As above, l((Q)) − l(KE − (Q)) = deg((Q)) = 1 =⇒ l(KE − (Q)) = 0.
Now, L((Q)) contains all the constant functions (whose divisors are the
zero divisor). So if we consider a generator g of L((Q)), then g must be
a constant function (if not, then all constant functions are not included
in L((Q))). If (P ) ∼ (Q) then there exists a function f ∈ K(E) such that
div(f ) = (P ) − (Q) and f ∈ L((Q)). By the above, f is constant and so
div(f ) = (P ) − (Q) = 0 which implies that P = Q.
We have formalized the above proof, with the exception of the fact that
every class of Pic0 (C) has a unique representative of the form [(P ) − (O)]. In
the above description, this is a consequence of the Riemann–Roch theorem. In
our formalization, the proof follows a more elementary path. This is because
formalizing the Riemann–Roch theorem was out of reach in this work.
20
closed field K. Let P be a point of C. Then, by the above property, l(n(P )) = n
for all n = 1, 2, . . ., since deg(n(P )) = n > 2g − 2 = 0 for all n.
— l((P )) = 1 and hence, L((P )) = K since it includes all the constant
functions. Therefore L((P )) = K has base {1}.
— l(2(P )) = 2 and so a base for L(2(P )) will be {1, x} where ordP (x) = −2
and ordQ (x) ≥ 0 for all other points Q in C.
— l(3(P )) = 3 and so a base for L(3(P )) will be {1, x, y} where ordP (y) = −3
and ordQ (y) ≥ 0 for all other points Q in C.
— In the same way, L(4(P )) has base {1, x, y, x2 } and L(5(P )) has base
{1, x, y, x2 , xy}.
— In L(6(P )) the set {1, x, y, x2 , xy, x3 , y 2 } is linearly dependent (7 functions
included). Indeed, both x3 and y 2 have order −6 at P and non-negative
order at all other points of C. In the linear relation, the coefficients of x3
and y 2 cannot be zero, because if not every other term would have a different
order at P . As a result, for appropriate constants, the linear dependence
can be written in the form y 2 + a1 xy + a3 y = x3 + a2 x + a4 x + a6 .
21
and implementations of these relatively new curves are currently being developed
and widely deployed. Verifying these fresh implementations of new elliptic curves
was given as an open challenge from practitioners to academics at the Real
World Cryptography workshop in 2015 [Kas15].
Let E be an elliptic curve over some prime field Fp . Let P ∈ E(Fp ) be a point
of order r. Given an integer k in the range [1, r − 1] we call scalar multiplication
by k, the sum of k copies of P :
[k]P = P + P + · · · + P .
22
Elliptic Curve ElGamal
The elliptic curve digital signature algorithm is the analogue of the Digital
Signature Algorithm (DSA). In what follows, H denotes a hash function that is
assumed to be collision resistant.
Suppose Alice wants to send a signed message m to Bob. Suppose also that
Alice possesses a secret private key k. Then, she chooses a random integer d
and computes the point [d]P = (x1 , y1 ). Setting z = x1 , she computes s0 = z
23
(mod r) and s1 = d−1 (H(m) + kz) (mod r), where s0 = 6 0. Then, she sends the
encrypted message to Bob together with the signature (s0 , s1 ).
To verify the signature, Bob has first to recover the plaintext m. He first
computes the hash H(m) and t = s−1 1 (mod r). Afterwards, he computes the
integers u = e (mod r) and v = s0 t (mod r) and the point T = [u]P + [v]Q =
t
Definition 2.7. Let E be an elliptic curve over some prime field Fp . Let
P ∈ E(Fp ) be a point of order r and a, b two integers in the range [1, r − 1].
24
Given the points P, [a]P and [b]P , and without knowing the integers a, b, the
ECDH is the problem of determining the point [ab]P .
Definition 2.8. Let E be an elliptic curve over some prime field Fp . Let
P ∈ E(Fp ) be a point of order r. Given the point P and the point Q in the cyclic
subgroup generated by P , the ECDLP is the problem of determining the integer
k in the range [1, r − 1] such that Q = [k]P .
The ECDLP is a separate problem from the ECDH, yet for the curves
that we use in practice, they are considered equivalent [SVM04]. The ECDLP
is considered to be harder that the DLP on some finite field or the integer
factorization problem. This is because the index calculus attack [Adl79] to solve
the DLP problem runs in subexponential time, while there is no analogue known
until now for the ECDLP. Indeed, the fastest known algorithm to solve the
ECDLP is Pollard’s rho which runs in exponential time and is no better than
the generic algorithm to solve DLP in any group.
Therefore, to achieve a satisfactory security level using RSA or standard
DL-based systems one needs to use increasingly large keys, while using elliptic
curve schemes one may achieve the same security level using much smaller keys.
For example, to achieve a 128-bit level of security, one can use 256-bit keys using
elliptic curve schemes or 3072-bit for RSA. The 128-bit security level refers to
the length of keys in a symmetric cryptosystem in which case an attack by brute
force would need 2128 steps to break the system. Concerning ECC and RSA, the
estimates are based on the size of keys for which we achieve the same security
level if we run the fastest attack algorithm for each case.
25
Binary exponentiation
When subtraction is cheap, which is always the case for elliptic curve groups,
then scalar multiplication can be optimized using a signed digit binary form for
the scalar. This form is not unique even when its weight is minimal, which is
when it gives the most advantageous result. Among different signed digit binary
representations, the non-adjacent form (NAF) is a canonical representation of
minimal weight. The NAF representation [Rei60] of an integer is unique, and
there are no zeros adjacent. For example, the NAF of 7 is 1001̄ and the NAF of
3190 is 101̄0010001̄01̄0. Here 1̄ stands for a coefficient −1 in the signed binary
expansion. Algorithm 7 presents elliptic curve scalar multiplication using NAF.
Precomputation can also be exploited to speed up Double-and-Add by means
of the Sliding Window Method. The window method decomposes the binary
form of the scalar into zero and non-zero words (windows). In general, it is not
mandatory that the length of the windows remain equal. Algorithm 8 presents
elliptic curve scalar multiplication using the Sliding Window Method.
26
Algorithm 7: NAF Double-and-Add
1 Input: k = (kt−1 , kt−2 , ..., k0 )N AF and P ∈ E(Fp )
2 Set Q ← O.
3 For i = t − 1 downto 0 do
4 Q ← [2]Q
5 if ki = 1 then Q ← Q + P
6 if ki = −1 then Q ← Q − P
7 Return Q
8 Output: Q = [k]P
Except for the standard binary representation of the scalar, there has been
other ideas proposed to speed up scalar multiplication, such as representations
based on double based number systems [DJM98, DIM05].
Montgomery Ladder
27
cryptographic schemes, such as ECDH for example, do not really need a y
coordinate. Since all computations can be executed only using the x-coordinate,
a lot of field multiplications can be spared, which results to a significant efficiency
advantage. Moreover, since the y coordinate is ignored until the end of the
routine, fewer memory is needed.
The Montgomery Ladder presents also a security advantage against side
channel attacks. This is because the conditional branching in the loop is highly
regular: whatever the processed bit, an addition and a doubling always take
place. As a result, the algorithm is constant time and therefore side–channel
resistant.
Apart from scalar multiplication algorithms for generic groups such as the
ones presented in the previous section, there exist other types of algorithms
that can only be applied on elliptic curves, mainly because they exploit the
internal structure and properties of elliptic curve groups. Such an example
is the algorithm proposed by C. Doche, T. Icart, and D.R. Kohel that uses
isogeny decomposition to accelerate computation[DIK05]. Another example is the
algorithm GLV initially proposed by Robert P. Gallant, Robert J. Lambert, and
Scott A. Vanstone in [GLV01]. The GLV algorithm performs scalar multiplication
on elliptic curves with efficiently computable endomorphisms.
The idea is the following: Let E be an elliptic curve over a prime field Fp .
We want to compute a multiple of P ∈ E, say [k]P , with k ∈ N. Suppose that
there exists an efficiently computable endomorphism φ : E → E, which one can
compute using only a few field operations, and which acts as a multiplication on
hP i; i.e. ∀Q ∈ hP i, φ(Q) = [λ]Q, for some λ ∈ N (or equivalently φ(P ) ∈ hP i).
For example, if the prime of the base field satisfies the condition p ≡ 1( mod 4)
and i is a square root of −1 in Fp , then any curve of the form y 2 = x3 + ax has
28
an explicit and very efficient endomorphism:
29
vector v in the lattice hv1 , v2 i results in the following simple decomposition
(k1 , k2 ) = (k, 0) − v. However, the GLV algorithm is efficient if k1 and k2
have roughly half the bitlength of k, which requires v to be close to (k, 0).
Such a v can be easily computed given a short basis for hv1 , v2 i, and this
basis can be easily precomputed using lattice basis reduction algorithms.
The standard technique for decomposition proposed in [GLV01] is based on
the Extended Euclidean algorithm and is presented in details in Chapter 4.
The main advantage of GLV is efficiency: assuming that k1 and k2 have half
the length of the original scalar k, then roughly half of the doublings will be
eliminated if we use multi-scalar multiplication techniques as the one presented
above. As a result, GLV is particularly fast and useful especially in the case
where the base point is variable.
However, the main disadvantage that GLV presents is that it can only be
implemented on curves with efficiently computable endomorphisms. Unfortu-
nately, finding such curves turns out to be highly nontrivial and that is why
in 2009 Galbraith, Lin and Scott proposed a modified version of GLV, named
the GLS algorithm in their article [GLS09]. GLS solves the problem of finding
such curves in the following way: starting with any elliptic curve over a prime
field, first we extend the curve to the quadratic extension field and then use
an efficiently computable homomorphism which arises from the Frobenius map
on the quadratic twist of the curve. Furthermore, the Q-curve construction
presented in [Smi16] is a generalization of the GLS algorithm.
Since its publication on 2001, significant research has been done to optim-
ize performance of GLV [FLS15], to analyze its security properties and its
applicability to different settings [BCHL13, LS14].
GLV is an algorithm particularly interesting to formalize, first because it is
an algorithm that is actually used in real-life cryptographic implementations and
secondly, because the mathematics involved are not trivial: besides two generic
algorithms (multiexponentiation and shortest vector for decomposition), the use
of endomorphisms requires formal theory for several non-trivial properties of
elliptic curves. We do this in Chapter 4.
30
coordinates of the form (X : Y : Z). The equivalence between affine and
projective representation is explained in detail in Chapter 3.
A special case of projective coordinates are Jacobian coordinates: A point in
Jacobian coordinates is the equivalence class (X : Y : Z) = {(λ2 X, λ3 Y, λZ) |
λ ∈ F∗p }. In this case, a Jacobian point (X : Y : Z), with Z 6= 0, corresponds to
the affine point ( ZX2 , ZY3 ). The curve equation becomes Y 2 = X 3 + aXZ 4 + bZ 6
and the point at infinity is the point O = (1 : 1 : 0).
There are many other variants of coordinate systems such as mixed coordin-
ates [CMO98] and modified Jacobian and Chudnovsky coordinates [CC86]. For
more details see [Lon11]. The most common form of elliptic curves over prime
fields in cryptographic settings is the short Weierstrass form y 2 = x3 + ax + b
with a, b ∈ Fp . The projective form of this equation using Jacobian or homo-
geneous projective coordinates has been accepted as a standard by NIST and
IEEE [Lon11, Nat99]. Yet, there has been significant research going on new
optimized curve forms. These forms, which are only beginning to be standardized
for some applications, may present important efficiency or security advantages
such as fast arithmetics or side channel resistance. For more details on different
curve forms see [Gal12].
To sum up, different curve forms and their corresponding coordinate system
may be a better choice depending on the scalar multiplication algorithm used.
In general, when implementing elliptic curve scalar multiplication, one has to
choose the algorithm together with the curve and the coordinate system, taking
into account all the dependences between the three. Moreover, one has to
bear in mind the underlying field arithmetic together with the efficiency and
security requirements of his own implementation. As a result, elliptic curve
scalar multiplication implementation is a complex task and most of the time
verifying that an implementation is actually correct is far from trivial.
31
such, the kernel guarantees the correctness of Coq and its proof engine. Proofs
and statements are expressed in a language called Gallina, based on an extension
of the Calculus of Inductive Constructions [The10, PP89], a dependently typed
polymorphic lambda calculus.
Coq comes with a special type named Prop which stands for the type of
propositions.
32
come back to the first rule. The Curry-Howard isomorphism establishes this
fact: The relation between a program (i.e. a function) and its type is the same
as the relation between a proposition and its proof. Hence, an expression e : T
can be either interpreted as a program e of type T or a proof e of a proposition
T . See [Gil04] for further explanations.
33
Goal (P -> (P -> Q)) -> (P -> Q).
We now give all the intermediate steps. After inputting the statement, one sees
the following:
P : Prop
Q : Prop
============================
(P -> P -> Q) -> P -> Q
Above the =-line lies the environment with all the declarations and definitions,
and bellow the =-line is the current goal that has to be proved. Using move=> HPQ,
the system introduces the head hypothesis with name HPQ. The new goal is
P -> Q:
P : Prop
Q : Prop
HPQ : P -> P -> Q
============================
P -> Q
Likewise, using move=> HP we introduce the second hypothesis HP and are left
to prove the following goal:
P : Prop
Q : Prop
HPQ : P -> P -> Q
HP : P
============================
Q
Next, we use the tactic apply to apply the hypothesis HPQ to our new goal.
34
Remark
Proofs in Coq go backwards: the users start from the conclusion and apply
tactics simplifying the goal up to a point where it appears as an hypothesis in
the environment. For instance, the apply: tactic does a modus ponens in the
reverse way: if one has to prove the goal B and has a proof H of A -> B, then
the tactic apply: H will transform the goal B to A.
In our case, applying HPQ generates two new sub-goals requiring a proof of P.
The first goal comes from the first hypothesis of HPQ, whereas the second comes
from the second one:
P : Prop
Q : Prop
HPQ : P -> P -> Q
HP : P
============================
P
subgoal 2 is:
P
Applying hypothesis HP solves the first goal. We then move to the second
sub-goal:
P : Prop
Q : Prop
HP : P -> P -> Q
HPQ : P
============================
P
Applying once more HP closes the proof and Coq displays the message
Proof completed. At that point, the proof is not checked yet. By inputting
Qed, we ask the proof engine to send the constructed proof to the kernel of Coq.
Only after this step we know that we have a formal proof of our statement.
There exist several tactics which allow the user to perform case analysis, proofs
by induction, first-order reasoning, automatic proofs search, as well as more
powerful tactics or user defined tactics coming from external libraries.
Remark:
35
tactic modifiers, such that one same tactic may cope with a wide range of similar
situations. For more details, see [AM16].
This definition produces two elements of type bool: the two constructors
true and false.
Another example of inductive types is the natural numbers. N is defined (as
in Peano arithmetic) as:
The type nat has two constructors: 0 which stands for zero and S for the
successor function.
36
For every inductive definition, an inductive principle [CP88, Tar55] is gener-
ated by Coq allowing the user to develop proofs by induction, or define function
by recursion. For example, lists of elements of type A are defined as:
Inductive list (A: Type) : Type := nil | cons of A & list A.
where nil is the empty list and cons is the function that concatenates an element
of type A with a list of type list A.
If one wishes to prove a statement on lists by induction, she needs to prove
the following facts:
1. that the statement stands for the empty list, and
2. that if the statement stands for a list L, then for any elements a, the
statement stands for the concatenation cons a L.
Let’s take a look at the following example from [Ber08]. Suppose we want to
prove the following statement, using induction on natural numbers:
Lemma addn0 : forall n, n + 0 = n.
The following two lemmas will be useful:
Lemma add0n : forall n : nat, 0 + n = n.
Lemma addnS : forall n m : nat, S n + m = S (n + m)
After inputting the statement, one sees the following:
forall n : nat, n + 0 = n
Using move=> n, the system introduces the natural number n in the environment.
The new goal is
n : nat
=============
n + 0 = n
Next we use the tactic elim: n => [|n ih] to perform induction on the natural
number n. Two subgoals are generated, the first one concerns the case where
n = 0 and the second one the general case where n is any natural number
different from 0:
2 subgoals
=============
subgoal 1 is:
0 + 0 = 0
subgoal 2 is:
S n + 0 = S n
Applying lemma add0n, the first goal disappears. Now the second goal looks
like:
37
n : nat
ih : n + 0 = n
=============
S n + 0 = S n
We observe that Coq has generated the induction hypothesis ih for the natural
number n, and we have to prove the statement for its successor S n. By rewriting
lemma addSn, we obtain:
n : nat
ih : n + 0 = n
=============
S (n + 0) = S n
Now by rewriting the induction hypothesis the goal turns to
n : nat
ih : n + 0 = n
=============
S n = S n
Using the tactic reflexivity finishes the proof and Coq displays the message
Proof completed. Indeed, reflexivity is a tactic that finishes the proof when
the goal looks like e = e. The entire proof script is
Lemma addn0 : forall n, n + 0 = n.
Proof.
move=> n.
elim: n => [|n ih].
rewrite add0n.
rewrite addSn.
rewrite ih.
reflexivity.
Qed.
Coq allows us to do proofs by case analysis using the tactic case. For
example, given a boolean statement b : bool we can perform case analysis to
prove a statement about b. Let us prove the following statement to demonstrate
how case works: Negation is involutive.
Lemma negbK (b:bool): ~~ (~~ b) = b.
The proof script will be the following:
Lemma negbK (b:bool): ~~ (~~ b) = b.
Proof. by case: b. Qed.
Let’s examine the intermediate steps. First, after inputting the statement, one
sees the following: ~~ (~~ b) = b. Next we use the tactic case: b to perform
38
case analysis on the boolean b. Two subgoals are generated, the first one concerns
the case where b = true and the second one the general case where b = f alse:
b : bool
2 subgoals
============================
subgoal 1 is:
~~ ~~ true = true
subgoal 2 is:
~~ ~~ false = false
In both goals we first apply the tactic simpl to simplify, and the goal is trans-
formed to true = true (resp. false = false) which is then resolved by the
tactic reflexivity. This is done automatically if we use the by tactical which
closes the proof script. The proof is completed.
39
conjunctive or disjunctive facts) or witnesses of existential statements. Note that
to formalize a property in bool, one needs to implement the decision procedure
that decides if the property holds. Ssreflect proposes the boolean reflection
methodology which allows interchanging between equivalent statements in Prop
or bool [AM16]: One expresses the same statement in Prop and bool, and then
has to prove a lemma (called view lemma) stating the equivalence between the
Prop and the bool statements. For more details on the Small Scale Reflection
methodology, see [AM16, GM10]. We here give the example, extracted from
the Ssreflect library, for defining what is a type whose equality predicate
is decidable (i.e. whose equality predicate can be reflected using a boolean
equality):
Record eqSpec (T: Type) := EqSpec {
eq: T -> T -> bool;
eqAxiom: forall (x y : T), (eq x y) = true <-> x=y
}.
40
More precisely, an algebraic structure is usually implemented by a record with
two fields: the carrier set and the class of the structure. The class contains the
signature (i.e. the name and type of the operations) and proofs of the properties
that the operations satisfy. For a detailed description of the algebraic structures
in Ssreflect see [Coh12].
For example, the zmodType, which stands for an abelian group, is defined as
the subtype of eqType as follows:
forall x y : G, x + y = 0
is expanded to
Nevertheless, problems may arise in other cases where one does not manipulate
directly the defined structure. For example, integers form an abelian group and
therefore share the zmodType structure. But when writing
forall x y : int, x + y = y + x
41
an error arises because int is not of type zmodType. To address this problem,
unification can be aided by Coq’s Canonical Structures mechanism. For a
detailed use of Canonical Structures in Ssreflect, see [Coh12].
Quotient Types When working with algebraic structures, one often has to
manipulate quotients and functions defined on them. In that case, different (not
equal) terms may represent the same conceptual object.
Manipulating quotients is difficult in Coq, because of type theory. In math-
ematics, algebraic quotients are sets, for which structure is transported from
the base set to the quotient. An element x of the base set characterizes its equi-
valence class of the quotient set, so one can implicitly consider x as an element
of the base set and an element of the quotient set. However when it comes to
Coq, defining a quotient type as a subtype of the base type does not allow free
interchanges between the two as they are two different types. In type theory
there are two options proposed about dealing with quotients: setoids and forging
quotient types i.e. define types where each element is one equivalence class of
the quotient. For more details, see [Coh12]. Moreover, in Coq, quotient types
are not primitive types as it would make type-checking indecidable [SvdW11].
Ssreflect deals with this problem by restricting the quotient types to
decidable ones. A quotient type U in Ssreflect is represented by a packed
structure that binds together:
1. the base type T ,
2. a function π : T → U , called canonical surjection, which is the embedding
of T in U , and
3. a function repr : U → T s.t. for a class C in U , repr(C) gives a represent-
ative in T for C
s.t. the composition of the canonical surjection with the representative function
π ◦ repr is the identity function. A quotient type Q is an instance of the following
interface:
42
Hence, to define a quotient type, one has to be able to give a function which
computes the representative for every class. A quotient type Q of base type T
and quotient structure qT results in the following equivalence for elements of T:
Two elements x y : T are equivalent if pi qT x = pi qT y. Ssreflect allows
for the following more intuitive notation x = y \%[mod qT] of the above.
Given an arbitrary type R, a function f : T -> R is compatible with the
quotient type Q if it stays constant on each equivalence class. In that case it has
a lifting which means that we can define a corresponding function g : Q -> R
on the quotient type Q, such that pi f x = g pi x for all x : T. The canonical
surjection pi is a morphism for f.
The proof of the Picard theorem requires the definition of functions over
quotients. A common method, when working with quotients, is to define a
function on the non-quotiented set and prove that the function respects the
quotient, i.e. that for any x, f (x) = f (repr(π(x))).
43
A formal library for elliptic curves
3
In this chapter, we present a formal proof of the Picard theorem for elliptic
curves: There exists an isomorphism between the Picard group of divisors
and the group of points of an elliptic curve. An important consequence of
this proposition is the associativity of the elliptic curve group operation. This
development has resulted in more than 15000 lines of code and is available at
[Link] It includes formal theory about Weierstrass
curves, the field of rational functions on a curve, theory about free groups,
divisors of rational functions on curves and isomorphic representations on different
coordinate systems. This result, has been published at the article A Formal
Library for Elliptic Curves in the Coq Proof Assistant at the International
Theorem Proving conference 2014.
44
y y
P Q
x x
P
Q
P +Q
(a) y 2 = x3 + x (b) y 2 = x3 − x + 2
where the ai ’s are in K and the curve has no singular point (i.e. no cusps or
self-intersections). The set of points, written E(K), is formed by the solutions
(x, y) of E augmented by a distinguished point O (called point at infinity):
Figure 3.1 provides graphical representations of such curves in the real plane.
Moreover, such a curve does not present any singularity if ∆(a, b) = 4a3 +27b2
— the curve’s discriminant — is not equal to 0. Our work lies in this setting.
45
Inductive point (K : Type) : Type :=
| EC_Inf : point K
| EC_In : K -> K -> point K.
46
then if (y1 == y2) && (y1 != 0)
then
let s := (3 * x1^+2 + E#a) / (2 * y1) in
let xs := s^+2 - 2 * x1 in
(| xs, - s * (xs - x1) - y1 |)
else
EC_Inf
else
let s := (y2 - y1) / (x2 - x1) in
let xs := s^+2 - x1 - x2 in
(| xs, - s * (xs - x1) - y1 |)
end.
Note that these definitions do not directly work with points on the curve,
but instead on points of the projective plane (points that do not lie on the curve
are projected to O).
We link back this algebraic definition to its geometrical interpretation. First,
we define a function line that, given two points P, Q on the curve, returns the
triplet (u, v, c) that characterizes the equation ux + vy + c = 0 of the line (P Q)
intersecting the curve at P and Q (resp. the equation of the tangent to the
curve at P if P = Q). We then show that, if (P Q) is not parallel to the y axis
(i.e. is not intersecting the curve at O), then (P Q) is intersecting E exactly at
P , Q and −(P + Q) = P Q as defined algebraically. This is the main part of
the proof of the lemma addO, which implies the computational manipulation of
polynomial formulas.
The function line is defined using polynomial formulas as below:
Definition line (p q : K * K) : K * K * K :=
let: (x1, y1) := p in
let: (x2, y2) := q in
47
end.
We then prove that these operations are internal to the curve and lift them
to E. We further prove that they satisfy all the properties of an abelian group
except associativity.
48
group.
Definition 3.2. The ring K[E] of polynomials over the curve is defined as the
quotient ring of K[x, y] by the prime ideal hy 2 − (x3 + ax + b)i. The field K(E)
is defined as the field of fractions over the integral domain K[E].
49
The type ecpoly is simply a copy of {poly K} * {poly K}, an element
([ecp p1 *Y + p2] : ecpoly) representing the class of the polynomial p1 y +
p2 ∈ K[E]. We explicitly define the addition and multiplication, that are
compatible with the one induced by the ring quotient.
For instance:
(p1 y + p2 )(q1 y + q2 ) = p1 q1 y 2 + (p1 q2 + q1 p2 )y + p2 q2
= (p1 q2 + q1 p2 )y + (p1 q1 (x3 + ax + b) + p2 q2 )
leads to:
where .1 and .2 resp. stand for the first and second projections.
Unfolding the definitions we prove that the operations satisfy the properties of a
commutative ring.
Remark. For the construction of the ring K[E], we could have used a more
general approach, relying on the general definition of a ring quotient by an
ideal — a basic construction of commutative algebra. We would have obtained
for free that K[E] is an integral domain as the ring quotient by a prime ideal.
Moreover, the quotient library of Ssreflect is built s.t. it would have been
possible to choose our canonical representatives and to stick to the y · p(x) + q(x)
representation. The only extra work would have been to link the ring operations
inherited from generic construction to the ones directly defined on the canonical
representatives. For example, for the multiplication, this would amount to prove
that:
[(y · p1 + q1 )] · [y · p2 + q2 )] =
[y · (p1 q2 + q1 p2 ) + (p1 q1 (x3 + ax + b) + p2 q2 )],
(p1 y + p2 )(q1 y + q2 ) = 0 =⇒ p2 q2 = 0 ∨ p1 q1 = 0.
50
Yet, after demonstrating the lemma idomainAxiom we are able to equip the
type ecpoly with an integralDomain structure.
The proof is based on the following idea: We can prove by contradiction that
the polynomial y 2 − (x3 + ax + b) is irreducible and therefore that K[E] is an
integral domain: Indeed, if we can factor y 2 − (x3 + ax + b) = (y − p(x))(y − q(x))
then p and q have necessarily the same degree, which is absurd since their product
is a polynomial of degree 3.
We then use the fraction [Coh13] library to built the {fraction ecpoly}
type representing K(E), the field of fractions over K[E].
Evaluation of polynomials of K[E] on points is naturally defined on the
canonical representatives. Note that while we are interested on evaluation on
curve points, evaluation is defined on all finite points in order to remain as
general as possible. Nevertheless, several lemmas concerning evaluation are true
only concerning points that belong to the curve.
To pursue with the definition of the order in the following section, three notions
are needed: the conjugate, the norm and the degree.
Lemmas concerning properties of all these notions are straightforward such as:
51
degree (p * q) = (degree p + degree q).-1.
Definition fdegree :=
lift_fun1 {fraction {ecpoly E}} fdegree_r.
In complex analysis, the zeros and poles of functions, and their order of
vanishing are notions related to analytic functions and their Laurent expansion;
while in abstract algebra, they refer to algebraic varieties and discrete valuation
rings [Ful89]. For our formalization, we follow the more elementary definitions
given in [Gui10]. More precisely, the evaluation of a function f ∈ K(E) at a
point P = (xP , yP ) ∈ E is defined as follows:
where αn (resp. αd ) is the coefficient of the higher degree term of n (resp. d).
Remark. Being not analytic, such definitions are difficult to formalize as-is
in Coq. For example, concerning evaluation at finite points, one has to provide
52
a representative matching the definition and it is not clear how to find one.
Moreover, the function is defined on fractions which means that it has to be
stable on a fraction class. Those two details have to be taken into account in
order to formalize it in Coq.
Fortunately, using uniformizers, which is a notion from algebraic geometry, we
can computationaly decompose every fraction of K(E) in a canonical form which
allows us compute the evaluation at some point, as defined above. Furthermore,
this canonical form, which we will call decomposition, allows us compute the
order of vanishing of the function at that point, which is essential in what follows.
We have chosen this way to proceed and to define evaluation.
In what follows, we explain in details how the following extra notions allow
us to decompose any rational function in some canonical representative:
Definition 3.7. A function u ∈ K(E) is called a uniformizer at P ∈ E(K) if
i) u(P ) = 0, and ii) every non-zero function f ∈ K(E) can be written in the form
f = uv g with g(P ) 6= 0, ∞ and v ∈ Z.
The exponent v is independent from the choice of the uniformizer and is
called the order of f at P , a quantity denoted by ordf (P ).
Lemma 3.1. There exists a uniformizer for every point on the curve.
To get an intuition of the previous definitions, one can make a parallel with
the notion of multiplicity for roots of univariate polynomials or with the notion
of zeros and poles in K(x).
For instance, let us first consider the ring of polynomials K[x]. Let p be a
polynomial in K[x] and r be an element of K. We can factorize p as p = (x−r)m q
such that m ∈ N and q(r) 6= 0. The exponent m is the multiplicity of p at r.
The multiplicity of r is 1 for the polynomial factor (x − r). Evaluation and
multiplicity are closely related: r is a root of p iff m > 0.
In an analogous way, we can consider the field of fractions K(E). Let P be
in E and f in K(E). Then, one can always write f in the form f = uv g with
v ∈ Z uniquely defined and P neither a zero nor a pole of g (g(P ) 6= 0, ∞). The
exponent v is the order of f at P . (Here, the function u corresponds to the
polynomial factor (x − r) for univariate polynomials) If v > 0 then P is a zero
for f , and if v < 0 then P is a pole for f .
An interesting fact, used in algebraic geometry, is that the order is a discrete
valuation for K(E), which makes K[E] a discrete valuation ring — a property
that we demonstrate later:
— for all P ∈ E and for all non zero f1 , f2 ∈ K[E],
53
The proof of Lemma 3.1 is constructive and gives all the necessary material
to define the notions of the uniformizer and the order. Indeed, the problem of
evaluating a rational function at a given point is reduced to finding a proper
decomposition of the rational function, based on the following property:
0 when d > 0
f (P ) = ∞ when d < 0
g(P ) when d = 0.
54
Let µ be the multiplicity of xP in norm(f ), and r(x) a element of K[x] s.t.
norm(f ) = (x − xP )µ r(x). Then:
f = (x − xP )µ p(x)−yq(x)
r(x)
if µp = 0
µq
µ= µp if µq = 0
min(µp , µq ) otherwise.
Let p1 (x) and q1 (x) be the elements of K[x] s.t. p(x) = (x − xP )µ p1 (x)
and q(x) = (x − xP )µ q1 (x). Then:
Definition poly_ordreg
(x y : K) (p : ecpoly) : nat * (ecpoly * ecpoly)
:=
let: (d, (pp1, pp2)) := mudiv_join x p.1 p.2 in
let: p’ := [ecp pp1 *Y + pp2] in
if p’.[x, y] == 0 then
let d’ := \mu_x (normp p’) in
let g := (normp p’) / (’X - x)^d’ in
((d + d’), ([ecp 0 *Y + g], (conjp p’)))
else
(d, (p’, 1)).
55
Definition poly_orderinf (p:ecpoly) : int * (ecpoly * ecpoly) :=
let d := (degree p).-1 in
(-d, (’X^+d * p, [ecp 1 *Y + 0] ^+ d)).
Definition poly_order
(p : ecpoly) (ecp : point K) : int * (ecpoly * ecpoly)
:=
if (p == 0) || ~~(oncurve ecp) then (0, (0, 1)) else
if ecp is (| x, y |) then
let: (n, (g, h)) := poly_orderfin x y p in (n, (g, h))
else poly_orderinf p.
Lemma poly_order_correct:
forall (f : ecpoly) (p : point), f != 0 -> oncurve p ->
let: (o, (g1, g2)) := poly_order f p in
uniok (unifun p) f p o g1 g2.
Lemma uniok_uniq:
forall f p, f != 0 -> oncurve p ->
forall o1 o2 n1 n2 d1 d2,
uniok (unifun p) f p o1 n1 d1
-> uniok (unifun p) f p o2 n2 d2
-> (o1 == o2) && (n1 // d1 == n2 // d2).
Proving that all the lifted functions are stable by quotienting allows us to
lift all the proved properties over K[E] to K(E). For instance, the order on
{fraction ecpoly} is defined as:
56
if \n_f == 0 then 0 else
(poly_order \n_f p).1 - (poly_order \d_f p).1.
Definition order f p :=
(lift_fun1 {fraction ecpoly} (orderf^~ p)) f.
Then, we prove that the order is a discrete valuation, making K[E] a discrete
valuation ring:
We can then formalize Definition 3.5 by a simple case analysis over the order,
relying on the decomposition of rational functions: Given, a rational function
f and a point P , the function decomp returns the (n, d) part of the function’s
decomposition f = ud · nd . The function leadc computes the leading coefficient
of the highest-power term of a polynomial. Next, ecreval is the extension of
eceval for all points on the curve (including the infinite point) and finally eval
is the evaluation for elements of the field of fractions K(E).
Definition decomp
(f : {fraction ecpoly}) (ecp : point K) : (ecpoly * ecpoly)
:=
let f := repr f in
if (\n_f == 0) || ~~(oncurve ecp) then (0, 1) else
let: (n1, d1) := (poly_order \n_f ecp).2 in
let: (n2, d2) := (poly_order \d_f ecp).2 in
(n1 * d2, n2 * d1).
57
if oncurve ecp then
if ecp is (|x, y|) then p.[x, y] else leadc p
else 0.
Note that the evaluation returns an element of the projective line, formalized by
the parametric type gproj:
Addition and multiplication are defined naturally on the projective line, with
the difference that multiplication of 0 with ∞ is defined to be 0 as a convention.
Lemma 3.3. A rational function f ∈ K(E) has a finite number of poles and
zeros. Moreover, assuming that K is algebraically closed, P ∈E (ordP (f )) = 0.
P
58
[seq (x, y) | y <- sqrts & f.[x, y] == 0]
It relies on the function roots that returns the roots of an univariate polyno-
mial. Note that for all polynomials f ∈ K[E], if (x, y) is a zero of f , then (x, −y)
is a zero of f¯. Using the decomposition of f , we can easily demonstrate that
ordP (f ) = ord−P (f¯). Then,
Since the order is multiplicative, we have ordP (nf ) = ordP (f ) + ordP (f¯).
Hence,
=2· ordP (f ).
X
P ∈E|P finite
=2·
X
ki .
i
59
Div(f ) = P ∈E (ordP (f ))(P ).
P
Note that Div(f ) is well defined because a rational function has only finitely
many zeros and poles. We write Prin(E) for the set of principal divisors.
The set Prin(E) forms a subgroup of Div(E), the set of formal sums over E,
a notion that we define now.
D= nP (P ),
P
P ∈E
where nP ∈ Z and only finitely many of them are nonzero. In other words, a
divisor is any expression taken in the free abelian group generated over E(K). The
domain of D is dom(D) = {P | nP 6= 0} and its degree is deg(D) = P ∈E nP .
P
The set of divisors on E is an abelian group. The sum of two divisors is defined
as the point wise addition P ∈E ak (Pk ) + P ∈E bk (Pk ) = P ∈E (ak + bk )(Pk )
P P P
whereas the zero divisor is the unique divisor with all its coefficient set to 0.
Based on the quotient libraries of Ssreflect, we develop the theory of free
abelian groups. Let T be a type. We first define the type of pre-free group as the
collection of all sequences s of type int * T s.t. no pair of the form (0, _) can
appear in s and for any z : T, a pair of the form (_, z) can appear at most
once in s.
60
From there, we equip the type freeg with a group structure (the operation is
noted additively), and define all the usual notions related to free groups (domain,
coefficient, degree, ...). For instance, assume G : zmodType (G is a Z-module)
and f : T -> G. Then, f defines a unique group homomorphism from freeg to
G that can be defined as follows:
One can check that the fglift function defines the homomorphism
(z,x)∈D zf (x)
P
The coefficient coeff and degree deg functions can be then defined as:
One can easily check that Prin(E) is a subgroup of Div0 (E). Indeed, ∀f, g ∈
K(E) i) deg(Div(f )) = 0 by Lemma 3.3, and ii) since the order function is
multiplicative (ordp (f /g) = ordp (f ) − ordp (g)), we have Div(f/g) = Div(f ) −
Div(g). Moreover, it is now clear that the coefficients associated in Div(f ), to
each point P , is the order of the function f at P , highlighting the fact that a
divisor wraps up the zeros and poles of f .
Formally, we define principal divisors for polynomials on the curve with the
function ecdivp:
where << z * P >> stands for the divisor z(P ) and the function ecroots takes
a polynomial of K[E] and returns the list of its finite zeros as explained in the
previous section.
61
Next, we lift the definition of principal divisors to K(E), prove its correctness
and recast the key Lemma 3.3 (deg_ecdiv_eq0):
62
Note that the degree is well defined on the divisor class group since if
D1 = D2 + Div(f ) then deg D1 = deg D2 + deg(Div(f )) = deg D2 + 0 = deg D2 .
In other words, Pic(E) is defined as the quotient of Div(E) by the following
equivalence relation ∼:
Definition ecdeqv D1 D2 :=
(exists f : {fraction ecring}, ecdiv f = D1 - D2).
Notation "D1 :~: D2" := (ecdeqv D1 D2).
63
Definition fgpos (D : {freeg K}) :=
\sum_(p <- dom D | coeff p D > 0) coeff p D.
Definition fgneg (D : {freeg K}) :=
\sum_(p <- dom D | coeff p D < 0) -(coeff p D).
64
defining a canonical representative for the classes of Pic0 (E):
Lemma 3.4. For every class of Pic0 (E), there exists a unique representative of
the form (P ) − (O) with P ∈ E(K).
65
From the results of Section 3.2.4:
This allows us to transport the structure from Pic0 (E) to E(K), proving that
E(K) is a group.
66
compute polynomial formulas or resolve equations in some ring, such as Sage or
Maple for example, but a theorem prover to formalize algebra proofs. However,
we chose not to use any of these software because they come with no formal
guarantee of their correctness. Our development is completely based on Coq
and no results have been admitted nor verified tools using untrusted external
tools. In that context, Pierre-Yves Strub developed an interface between the
ring tactic of Coq and the ring structures of Ssreflect which allowed us to
simplify the proof. Nevertheless, we would like to stress out the necessity for
tactics that would provide more automation in Ssreflect because it can be
frustrating and discouraging to the developer to confront this kind of difficulties.
Conclusion
In this section, we presented a formal proof of the Picard theorem for elliptic
curves, which allowed the formalization of theory about elliptic curves in affine
form, rational functions and divisors. Using this theorem, we have proven
that the elliptic curve operation defined by polynomial formulas is a group law.
Using the above, we will demonstrate that we can represent elliptic curves in
different coordinate systems (projective in our case) and that this representation
is equivalent. By transport of structure, the curve in projective coordinates also
possesses the structure of an abelian group.
67
Definition 3.12. A projective plane (P, L) is a non empty set P whose elements
are called points, together with a set L whose elements are non-empty subsets of
P called lines, satisfying three axioms:
1. For any two distinct points p1 , p2 ∈ P, there exists exactly one line l ∈ L
such that both p1 ∈ l and p2 ∈ l.
2. There exists a set of four points, such that given any set of three of these
points, no line exists that contains all three points.
3. Any two lines intersect in exactly one point.
Let K be a field and K3 the 3 dimensional vector space over K. Then we can
define the projective plane P over K as follows.
— The points of P are the lines of K3 through the origin (0, 0, 0):
— The lines of P are the planes of K3 through the origin (0, 0, 0):
The fact that the three axioms are satisfied follows from some elementary
linear algebra:
1. In K3 , two lines with exactly one point in common are contained in
exactly one plane. Hence, two distinct projective points are on exactly one
projective line and the first axiom is satisfied.
2. The projective points (1 : 0 : 0), (0 : 1 : 0), (0 : 0 : 1) and (1 : 1 : 1) satisfy
the second axiom.
3. In K3 , any two planes passing through the origin, intersect in exactly
one line passing through the origin too. Hence, any two projective lines
intersect in exactly one projective point.
To avoid confusion, from now on, we will denote v (resp. (x, y, z)) for a
vector of K3 and [v] (resp. (x : y : z)) for a projective point.
A non-zero vector in K3 determines a line in K3 passing through the origin.
Therefore we can use the non zero vectors of K3 to represent the points of P.
68
Two non-zero vectors v and w represent the same projective point of P if they
are on the same line in K3 , i.e. [v] = [w] iff v = αw for some α ∈ K∗ . Let
v = (x, y, z) be a non zero vector of K3 . If z 6= 0 then [v] = [z −1 v] = ( xz : yz : 1),
and so there exists a unique representative of the class of the form (x0 , y 0 , 1).
Hence, there exists a 1-to-1 map between the set of projective points with z = 6 0
and K2 . If z = 0, then x and y cannot both be zero because v is a non zero
vector. Moreover, if x 6= 0 then [v] = [x−1 v] = ( xx : xy : 0) and so there exists a
unique representative of the class of the form (1, y 0 , 0). So, there exists a 1-to-1
map between the set of projective points with z, x 6= 0 and K. In the same way,
when z = 0 and x = 0, we have [v] = [y −1 v] = (0 : yy : 0) = (0 : 1 : 0). Hence,
there exists an isomorphism between the set of projective points P and the set
K2 ∪ K ∪ {(0 : 1 : 0)}.
It may have become obvious to the reader by now that starting from the
geometrical definition of the projective plane (over some field K) we have arrived
to construct an algebraic quotient structure:
Y 2 Z + a1 XY Z + a3 Y Z 2 = X 3 + a2 X 2 Z + a4 XZ 2 + a6 Z 3 .
y 2 z = x3 + axz 2 + bz 3 .
69
Like in the affine setting, those rules can be translated into polynomial
formulas, which are stable by quotienting. For all P = (xP : yP : zP ) ∈ E and
Q = (xQ : yQ : zQ ) ∈ E, let S = P + Q = (xS : yS : zS ) be the sum of the two
points.
— If P = Q then
u = 3x2P + azP2 xS = vr
v = 2yP2 yS = −u(r − v 2 x) − yP v 3
r = u2 zP − 2v 2 xP zS = zP v 3 .
— If P 6= Q then
u = yQ zP − yP zQ xS = vr
v = xQ zP − xP zQ yS = −u(r − xP zQ v 2 ) − yP zQ v 3
r = u2 zP zQ − v 2 (xP zQ + xQ zP ) zS = zP zQ v 3 .
70
end.
other words, the predicate lineq holds for (a1 , a2 , · · · , an ) and (b1 , b2 , · · · , bn ),
if it exists a λ ∈ K such that (a1 , a2 , · · · , an ) = (λb1 , λb2 , · · · , λbn ), as is stated
by the following view lemma:
Note that the relation projeq is defined on triplets of K3 . Using the lemma
projeqP, we prove that projeq is indeed an equivalence relation:
71
We quotient the type prepoint by the relation projeq to obtain the type of
projective points {ppoint K}. The function Point allows us to turn any triplet
of K3 into an element of type prepoint. Indeed, if p 6= (0, 0, 0) then the function
returns p together with a proof that it is different from (0, 0, 0) while if p = (0, 0, 0)
it returns by convention the triplet (0, 0, 1).
Subsequently, we define the following notations for elements of the base type
prepoint and of the quotient type {ppoint K}:
We have left for future work the formalization of the isomorphism between
the projective plane over K and K2 ∪ K ∪ {(0 : 1 : 0)} and we move directly to
the definition of elliptic curves in projective coordinates.
Variable K : ecuFieldType.
Variable E : ecuType K.
Local Notation a := (E#a).
Local Notation b := (E#b).
Following the same steps as in the affine part of the development, we use
the pponcurve function to declare a type for projective points on the curve:
inhabitants of the type ec_proj are projective points (of type {ppoint K}) that
satisfy the curve equation.
72
Inductive ec_proj : Type :=
| EC_proj : forall p : {ppoint K}, pponcurve p -> ec_proj
Next, we demonstrate that for all points on the curve, the maps f , f −1 cancel
each others. As a result, when restricted on the curve, f is a bijection.
Like in the affine case, given the curve in projective coordinates we define
addition and doubling using polynomial formulas. Note that addition is defined
in three steps:
— the function padd_t defines addition on triplets of K3 using the polynomial
73
formulas,
— the function padd_tr restrains padd_t on K3 \ (0, 0, 0) i.e. on elements of
type prepoint assuring that outside the curve the function returns (0, 1, 0)
as a convention, and
— after demonstrating that the function padd_tr is stable by the quotient,
meaning that ∀p0 ∼ p and ∀q 0 ∼ q, we have p0 + q 0 ∼ p + q, we can lift it
to the quotient type {ppoint K}.
74
Addition as defined is stable by the quotient and therefore it is a canonical
morphism for the class. Some technical details:
— Concerning double_t: The function separates three cases: when y = 0 we
consider that the point is not on the curve ; when z = 0 and if the point
lies on the curve, it is the infinite point ; when y 6= 0 and z =
6 0 and if the
point lies on the curve, there exists a representative of the form (x0 , y 0 , 1)
and it satisfies the curve equation.
— Concerning padd_t: The function separates cases: If one of the points has
z = 0 then (if it is on the curve) it corresponds to the point at infinity, so
the result is directly the other point. Note that points that do not belong
to the curve are eliminated by padd_tr later on. In the case that z = 6 0
and the two points belong to same equivalence class, the function calls
double_t.
In the same way, we proceed for the definition of the negative of a point:
Last but not least, we demonstrate the final lemma of this section, stating
that the function p2a is an isomorphism between the two curve forms:
Based on the isomorphism that allows using all the theory of curves in affine
coordinates, we were able to prove several properties of the opposite and the
addition on projective points, such as:
75
Since we have demonstrated that the sum of two points always lies on the curve,
then we can lift the definitions of addition and the opposite to elements of type
ec_proj E. Applying the isomorphism lemma and by transport of structure,
the addition in projective coordinates satisfies all group properties and therefore
we can equip ec_proj E with a Z-module structure.
76
on case analysis and requires handling of elementary but subtle geometric
transformations and therefore uses computer-algebra systems to deal with non-
trivial computation. In our development, we give a different proof of the
associativity of the elliptic curve group law: we define an algebraic structure
(the Picard group of divisors) and proceed to prove that the elliptic curve is
isomorphic to this structure. Our formalization is more structural than [Thé07]
in the sense that it involves less computation and the definition of new algebraic
structures.
As in [HGF06] and [SD08] we wish to develop libraries that will enable
the formal analysis of elliptic curve algorithms and our proofs follow textbook
mathematics. As in [Thé07], we give a formal proof of the group law for elliptic
curves. Nevertheless, the content of our development is quite different from the
related work. To the extent of our knowledge this is the first formalization of
divisors and rational functions of a curve, which are objects of study of algebraic
geometry. Such libraries may allow the formalization of non-trivial algorithms
that involve divisors (such as the Miller algorithm for pairings [Mil86]), isogenies
(such as [BJ03], [DIK06]) or endomorphisms on elliptic curves (such as the GLV
algorithm for scalar multiplication [GLV01]).
77
A formalization of the GLV algorithm
4
In this chapter, we present a formal proof of correctness of the GLV algorithm
[GLV01] for scalar multiplication on an elliptic curve group. This proof uses
theory from the elliptic curve library that was presented in Chapter 3. The
development includes over 5k lines of code and is available at [Link]
com/strub/glv.
The GLV algorithm was initially presented in 2000 in the article [GLV01]
by Robert P. Gallant, Robert J. Lambert, and Scott A. Vanstone. It presents
an important efficiency advantage and this is the reason why it was adopted,
studied and implemented in many versions, up to now. A first complexity analysis
of GLV is presented in [GLV01] and a further analysis in [SCQ02]. Since its
publication on 2001, significant research has been made to optimize performance
of GLV [FLS15], to analyze its security properties and its applicability to different
settings.
The idea behind GLV is the following: Let us consider an elliptic curve E over
some prime field Fp . Suppose that given a random point P ∈ E we can somehow
compute easily a (non-trivial) multiple of P , say [λ]P . Then when asked to
compute another multiple [k]P , we can break it down to [k]P = [k1 ]P +[k2 ]([λ]P ),
with k1 and k2 having half the size of the initial k. Then we can use a fast double-
multiplication algorithm (multi-exponentiation), which presents an important
efficiency advantage compared to computing [k]P directly.
However, computing the multiple [λ]P of a given point P implies that
the curve has an efficiently computable endomorphism φ which acts as scalar
78
multiplication φ = [λ]; i.e. ∀Q ∈ hP i, φ(Q) = [λ]Q, for a certain λ ∈ N.
Under certain conditions (which usually hold in a cryptographic setting), all
endomorphisms act as a multiplication on the cyclic subgroup hP i. Note that
by efficiently computable endomorphism, we mean that it can be computed by
executing only a few field operations. For example, if the prime of the base field
satisfies the condition p = 1 (mod 4) and i is a square root of −1 in Fp , then any
curve of the form y 2 = x3 + ax has an explicit and very efficient endomorphism:
To compute φ(x, y), one has to perform only one field operation. In this case,
√
λ = p − 1. The integer λ that characterizes the endomorphism φ is one of the
roots of the characteristic polynomial of φ.
The main inconvenience of GLV is that it requires finding curves with
computable endomorphisms, which turns out to be highly nontrivial. This is
the reason why on 2009 Galbraith, Lin and Scott proposed a modified version of
GLV, named the GLS algorithm in [GLS09]. GLS solves the problem of finding
curves with computable endomorphisms in the following way: starting with any
elliptic curve over a prime field, first it takes the extension of the curve over the
quadratic extension field. Then it uses an efficiently computable homomorphism
which arises from the Frobenius map on the quadratic twist of the curve. In
addition, a generalization of the GLS algorithm is presented with the Q-curve
construction in [Smi16].
The GLV algorithm is especially interesting to formalize, first because of its
use in cryptographic implementations and secondly, because of the mathematics
involved: besides two generic algorithms (multiexponentiation and decomposition
of the scalar), the endomorphisms part demanded formal theory for non trivial
properties of elliptic curves. Our formalization follows the description of GLV as
in [GLV01]
We have not been concerned by any optimized versions nor the GLS algorithm
on the quadratic extension field. Note that our formal proof stays in an abstract
mathematical level, i.e. the correctness of GLV is proven as a mathematical
high-level property but we do not provide any low-level implementation that
would be running efficiently on a machine. This part is left for future work.
GLV is composed by three independent sub–algorithms: multi–exponentiation,
decomposition of the scalar and computing an endomorphism on an elliptic curve.
Therefore we divide our development in three corresponding parts:
1. a formal proof of the algorithm of double-exponentiation on an abstract
group,
2. a formal proof of a decomposition algorithm, based on the Extended
Euclidean Algorithm, and
79
3. a formal proof that any endomorphism on an elliptic curve acts as multi-
plication on a cyclic subgroup of points.
The first two algorithms are formalized exactly as presented in [GLV01] and
are completely independent from the elliptic curve development presented in
the Chapter 3. The proof of the third part is an extension of the elliptic curve
development.
Remark. In the third part, we do not formally prove how to extract the λ given
the endomorphism. Yet, we give the formal proof that given an endomorphism
φ, there exists always a λ ∈ Z such that φ(P ) = [λ]P .
80
Proof. The proof of correctness is done by induction on the number of blocks d.
Let P and Q be elements of an additive group.
1. Suppose that d = 1. Then in the first round (i.e. the only round) of the
algorithm we have:
— R←0
— R ← 2w R = 0
— R ← R + (uP + vQ) = uP + vQ
2. For all u and v integers, we suppose that the algorithm is correct for a split of
u, v in k ∈ N∗ blocks. Let u = (ut−1 , . . . u1 , u0 )2 , v = (vt−1 , . . . v1 , v0 )2 be
the binary representation of the two integers and u = (uk , . . . , u1 , u0 )2 , v =
(v k , . . . , v 1 , v 0 )2 their splitting into k+1 blocks. Let u0 = (uk−1 , . . . , u1 , u0 )2
and v 0 = (v k−1 , . . . , v 1 , v 0 )2 be the two integers that derive from the k first
blocks of u and respectively v. By the induction hypothesis, the result of
the algorithm with input the two integers u0 , v 0 decomposed into k blocks,
as above, will be u0 P + v 0 Q.
Now suppose the algorithm is called on input u and v both split into
k + 1 blocks. At the k-th iteration of the algorithm, the output will
be R ← u0 P + v 0 Q. We have to show that if we run once more the
loop of the algorithm (the last step) the result will be uP + vQ. Indeed,
R = 2w (u0 P +v 0 Q)+(uk P +v k Q) = (2w u0 +uk )P +(2w v 0 +v k )Q = uP +vQ.
Hence, the proof by induction is completed.
According to the algorithm description, the first step is to put the two
integers u and v into binary form. The function nat_to_bin gives the binary
form of an integer, starting from the least significant bit. Reversely, the function
bin_to_nat given a sequence of bits, computes the corresponding integer.
81
Lemma cancelN n : bin_to_nat (nat_to_bin n) = n.
More precisely, in the case that u is a boolean sequence that finishes with false,
that statement is not correct. Therefore we define the function norm_bin1, that
is designed in order to drop all zeros in the end of a boolean sequence:
Hence, we are able to prove the lemma cancelB and several other properties.
Next, we define the function block, that given a sequence of bits, extracts
the i-th block of size w.
Finally, we have all the elements needed to define the algorithm of double
exponentiation, on an abstract additive group G:
82
First, we extract the number of blocks d which is the number of times the loop
is executed. The loop iteration is performed via foldl that iterates the operations
of the loop exactly as many as d times. Here, we use the standard notation *+
of Ssreflect for scalar multiplication. Next we prove that the algorithm is
correct, by induction on the number of blocks, as described previously:
Note that our formal proof of correction does not regard the precomputation
part. More precisely, in this abstract version of the algorithm, we do not separate
the precomputation part as in the mathematical description.
83
be approached using lattice reduction algorithms, yet the algorithm proposed in
the article is more efficient and simple to implement.
si n + ti λ = ri for i = 0, 1, 2, . . .
with the initial (s0 , t0 , r0 ) = (1, 0, n) and (s1 , t1 , r1 ) = (0, 1, λ) and with ri ≥ 0, ∀i.
For all i we have f (ri , −ti ) = ri − λti = si n = 0 (mod n). Hence, we
can choose v1 = (ri1 , −ti1 ) and v2 = (ri2 , −ti2 ) for some i1 , i2 in the range of
i; more precisely we will choose them in order for v1 , v2 to have the smallest
√
euclidean norm. Let m be the greatest index such that rm ≥ n. We choose
v1 = (rm+1 , −tm+1 ) and v2 the shortest between (rm+2 , −tm+2 ) and (rm , −tm ).
The fact that the two vectors are linearly independent is assured by the following
well known properties of EEA:
— ri > ri+1 ≥ 0, for all i ≥ 0
— |ti | > |ti+1 |, for all i ≥ 0
Reasoning by contradiction, if v1 and v2 are not linearly independent, (without
loss of generality we assume that v2 = (rm , −tm )), then rm+1
rm = |tm | which is
|tm+1 |
x1 α + x2 β = k
(
y1 α + y2 β = 0.
This system has a solution since the vectors v1 , v2 are linearly independent as
it was shown above. We round up α, β to the nearest integers, say respectively
a, b, and we define v = av1 + bv2 . The vector u = (k, 0) − v is the short vector
satisfying f (u) = k (mod n).
84
produced by the euclidean algorithm). Note that if the output list is [(r1 , u1 , v1 ) ::
(r2 , u2 , v2 ) :: · · · :: (rN , uN , vN )] then r1 < r2 < · · · < rN .
Lemma eea_mod a b v :
let: (r, x, y) := v in
(r, x, y) \in (eea a b) -> r - y * b = x * a.
Looking closer at the auxiliary function eea_rec, we remark the extra para-
meter n which decreases with every recursive call. This parameter is necessary
to define the eea_rec function because of the problem of function termination
in Coq. Indeed, if we try writing the function without the n parameter, Coq
displays the error message:
85
Note that the sequence eea_sqrr is already sorted concerning r, so the triplet
of index m, as denoted in the mathematical description, is just the first element of
the output sequence. Given the first element of eea_sqrr, the function index_hd
returns its index m in the sequence eea, and the function base returns the two
vectors v1 = (rm+1 , −tm+1 ) and v2 the shortest between (rm+2 , −tm+2 ) and
(rm , −tm ).
We verify that the result vectors v1 , v2 satisfy f (v1 ) = f (v2 ) = 0 under the
conditions n, λ 6= 0. Those two restrictions are always satisfied in reality because
n is usually a prime number, while λ is the eigenvalue of the endomorphism and
therefore it cannot be zero.
Lemma base_modn_fst n l :
let (v1, v2) := base n l in
v1.1 + v1.2 * l = 0 %[mod n]
Arriving at the second part, we have to find a vector close to (k, 0) in the
integer lattice generated by the base v1 = (x1 , y1 ) and v2 = (x2 , y2 ). First we
have to find the α, β ∈ Q from the linear system
x1 α + x2 β = k
(
y1 α + y2 β = 0,
86
approximation function approxZ: given two integers n and m and to compute
the approximation of m n
, first we isolate the signs and then operate on the
approximation of |m| . Let the euclidean division of |n| by |m| be |n| = |m|q + r.
|n|
If |m|
r
> 21 we round up to the next integer, else to the previous one.
Next, we directly compute the solution (a, b) of the linear system applying
Cramer’s rule and round up using approxZ.
Definition cramer_coefs n l k :=
let (v1, v2) := base n l in
let D := v1.1 * v2.2 - v1.2 * v2.1 in
(approxZ (k * v2.2) D, approxZ (- k * v1.2) D).
We have all the elements in order to compute the final decomposition vector
(k1 , k2 ) = (k, 0) − (av1 + bv2 ):
Unfolding the explicit definitions of this section and the properties of the mod
function of Ssreflect, it is straightforward to prove that the output of the
decomposition is correct:
Lemma correct_decomp n l k :
let (k1, k2) := decomp n l k in
n != 0 -> l != 0 -> k = (k1 + k2 * l) %[mod n].
87
4.3 Computing the endomorphisms
In this section, we give a formal proof of the fact that an endomorphism on
an elliptic curve acts as scalar multiplication on a subgroup of curve points. This
is true under certain conditions which always hold in a cryptographic setting:
— the scalar multiplication is performed on a cyclic group generated by a
point of prime order, and
— the square of the order of the generator point does not divide the cardinal
of the curve.
We have formalized the following theorem:
Theorem 4.1. Let E be an elliptic curve defined on some finite field K and let
φ : E → E be an endomorphism of E. Let G point of E of prime order n, such that
n2 does not divide the order of E. Let hGi = {[k]G | k = 0, 1, . . . , n − 1} be the
cyclic subgroup generated by G. Then, there exists an integer λ ∈ [1, . . . , n − 1]
such that ∀A ∈ hGi , φ(A) = [λ]A.
The first step to the proof, was to formalize the subgroup of n-torsion points
with coordinates on K:
Variable K : finECUFieldType.
Variable E : ecuType K.
Variable n : nat.
88
Addition is defined as the restriction of the elliptic curve addition on elements
of type torsion. The zero element of the torsion subgroup is the point at infinity,
called tg0. To formally define addition (tgadd) and the opposite (tgopp) on
the n-torsion subgroup, first we prove that the operations are internal. Next
we prove that the operations and the point at infinity as defined, satisfy the
group properties. Consequently, we can equip torsion with the structure of a
Z-module represented by the type zmodType.
Subsequently, we assume all the cryptographic conditions of the theorem;
in our setting, G corresponds to the point G, the generator of the cyclic group.
The order of point G is n and so it is of type ntorsion, which is just a notation
for elements of type torsion E n. The variable phi defines a random curve
homomorphism and the last condition crypto_order denotes that n2 does not
divide the order of the curve. We make use of the standard Ssreflect notations
for cardinals: #|S| denotes the cardinal of a finite set S.
Variable K : finECUFieldType.
Variable E : ecuType K.
Variable n : nat.
Hypothesis prime_n : prime n.
Notation ntorsion := (torsion E n).
Variable G : ntorsion.
Hypothesis GNz : G != 0.
Variable phi : {additive (ec E) -> (ec E)}.
Hypothesis crypto_order : ~~ ( (n ^ 2) %| #|[set: ec E]| ).
The next step is to prove that in this particular setting hGi = E[n]; in other
words that that n-torsion points form a cyclic subgroup. We break it down to
two parts: i) hGi ⊆ E[n], and ii) E[n] ⊆ hGi. The first lemma is stated in Coq
as follows:
Goal forall r, (G *+ r) *+ n = 0.
Proof. Let A ∈ hGi. Then there exists a ∈ Zn such that A = [a]G. Hence,
89
Goal forall Q, tgpoint Q \in <[tgpoint G]>%g.
The proof of the above lemma necessitated the proof of several intermediate
lemmas concerning torsion points and a more general finite group result:
Proof. φ can be restricted to E[n] = hGi since ∀Q ∈ E[n] we have also that
φ(Q) ∈ E[n]. Indeed, since φ is a morphism we have [n]φ(Q) = φ([n]Q) =
φ(O) = O. Consequently if Q ∈ hGi then φ(Q) ∈ hGi too.
90
The proof of the final lemma in Coq follows the proof detailed above.
Remark that phi is a morphism defined on elliptic curve points (represented by
the type ec). To prove the final lemma, we have to consider the restriction on
n-torsion points. Indeed, at the first place we prove that ∀P ∈ E[n], φ(P ) is also
in E[n] and then we are able to define the restriction tgphi on n-torsion points.
Lemma phi_torsion_restriction n (P : ec E) :
P *+ n = 0 -> phi (P *+ n) = 0.
Variable G : zmodType.
91
Definition multiexpoGZ (w : nat) (n m : int) (P Q : G) : G :=
let: (n, P) :=
match n with Posz n => (n, P) | Negz n => (n.+1, -P) end in
let: (m, Q) :=
match m with Posz m => (m, Q) | Negz m => (m.+1, -Q) end in
Variable K : finECUFieldType.
Variable E : ecuType K.
Variable n : nat.
Hypothesis prime_n : prime n.
Variable phi : {additive (ec E) -> (ec E)}.
Notation ntorsion := (torsion E n).
Variable G : ntorsion.
Hypothesis GNz : G != 0.
Hypothesis crypto_order: ~~ ( (n ^ 2) %| #|[set: ec E]| ).
Notation l := (@phi2l K E n prime_n G GNz phi foo).
92
projective coordinate systems. The two approaches make different trade-offs,
in that the first aims towards a library extensible with minimal additional
verification effort, whereas the second focus on verifying a highly-performant
implementation of one curve.
In a separate line of work of verification of asymmetric cryptography, the
Ironclad [HHL+ 14] crypto library also provides security guarantees for SHA,
HMAC and RSA at the assembly level, but they have not verified elliptic curves
so far.
Other verification efforts have targeted symmetric cryptography. [App15b]
used the Coq proof assistant to prove that a legacy SHA-256 implementation
written in C was correct with regard to its specification and [BPYA15] showed
that the OpenSSL implementation of HMAC using SHA-256 implements its specific-
ations correctly and provides the expected cryptographic guarantees. [DHL+ 05]
presents a collection of functional correctness proofs for symmetric block en-
cryption algorithms such as AES, MARS, Twofish, RC6, Serpent and IDEA.
[Cry] provides a tool to verify that a cryptographic implementation matches a
high-level specification, and this tool has been used to verify block ciphers and
hash functions.
Most recently, [ABBD16] shows how to prove cryptographic security, func-
tional correctness, and side-channel protection for a complex cryptographic
construction all the way from high-level cryptographic definitions down to as-
sembly code, using a combination of several different verification tools. Finally,
a number of works address the problem of verifying the security of complex
cryptographic constructions, protocols, and their implementations [BGZB09,
BGHB11, BFK+ 14].
Lemma 4.5. Let E be an elliptic curve defined on some finite field K and let
φ : E → E be an endomorphism of E. Let G point of E of prime order n, such
93
that n2 does not divide the order of E. Let hGi = {[k]G | k = 0, 1, . . . , n − 1}
be the cyclic subgroup generated by G. Then, there exists λ ∈ Zn such that
∀A ∈ hGi , φ(A) = [λ]A.
Let E[n] be the subgroup of n-torsion points, over the algebraic closure of
K and E[n](K) the subgroup of n-torsion points over K. We state the following
proposition without giving a full proof:
E[n] is isomorphic to Zn × Zn
This is a well known textbook result that can be found in [Gui10]. Since,
E[n] is isomorphic to Zn × Zn , there exists a two point basis P, Q such that
∀S ∈ E[n], S = [x]P + [y]Q.
As shown in the previous section φ can be restricted to E[n]. Let the image
of the base be φ(P ) = [a]P + [b]Q and φ(Q) = [c]P + [d]Q for some a, b, c, d ∈ Zn .
Then, the image of a random point S = [x]P + [y]Q can be computed by the
linear transformation,
" # " #" #
x0 a c x
φ(S) = 0 = .
y b d y
94
5
Applications
The work presented in this thesis aimed to provide formal theory in order to
verify elliptic curve software used in cryptography. In this chapter we present
two ways of applying our work in order to certify elliptic curve algorithms for
cryptography. An independent application of our work is the use of our library
to formalize related mathematical structures.
95
rank computation, Winograd’s fast matrix product, Karatsuba’s polynomial
multiplication, and the gcd of multivariate polynomials. The main advantage
of this approach is that on one hand, the abstract high-level algorithm make
use of the dependent types of Ssreflect and all the corresponding properties
to formalize a proof of correctness and on the other hand the efficient low-
level implementation use simple types closer to real-life implementations. The
separation of proofs from the computational content, guarantees the safety of the
approach. More precisely, the following 3 steps methodology is used to construct
efficient algorithms from high-level definitions:
1. Write an abstract version of the algorithm and prove it correct using the
Ssreflect structures and theory.
2. Implement an efficient version of the algorithm using the Ssreflect
structures and prove that it corresponds to the abstract version.
3. Translate the abstract data-structures and the efficient algorithm to the
low-level data types.
The CoqEAL methodology comes with libraries that have implemented efficiently
computable counterparts to several algebraic structures: Z–modules, rings and
fields.
Using CoqEAL to refine GLV in an efficient implementation will require
writing an efficient version of the three algorithms presented in Chapter 4 (multi-
exponentiation, decomposition and computation of the endomorphisms) and
translate the elliptic curve group into an efficient data-structure. It will also
be interesting to extend the abstract proof of correctness of the algorithm by
the proof of an algorithm computing the value λ as explained in the end of
Chapter 4.
96
Figure 5.1 – Architecture of our verified elliptic curve library
97
of this thesis are carefully transcribed as an F∗ interface, the Coq theorems are
reflected as F∗ assumptions. While there is no formal link between F∗ and Coq,
an informal discipline is imposed whereby all unverified elliptic curve assumptions
in F∗ must be justified by a corresponding theorem in Coq.
In the F∗ API the curve definition assumes a finite field K represented by
elements of type felem. Points on the plane are of type affine_point: they
can either be Inf , the point at infinity, or a pair of felem coordinates. A point
that verifies the curve equation satisfies on_curve, and is represented by the
refined type celem , denoting curve elements. They define two operations over
curve points: a negation function neg and an internal group operation add . The
ec_group lemma says that Inf , neg , and add together form an abelian group
structure. Hence, they can define scalar multiplication as repeated addition
over the curve. The AbelianGroup predicate gives a textbook definition of an
abelian group equipped with a neutral element zero, an opposite function opp
and addition operator add.
We display below the F∗ API:
type AbelianGroup (#a:Type) (zero:a) (opp:a → Tot a)
(add:a → a → Tot a) =
(∀ x y z. add (add x y) z = add x (add y z)) // Associative
∧ (∀ x y. add x y = add y x) // Commutative
∧ (∀ x. add x zero = x) // Neutral element
∧ (∀ x. add x (opp x) = zero) // Inverse
type affine_point =
| Inf | Finite: x:felem → y:felem → affine_point
let add’ p1 p2 =
if not(on_curve p1) then Inf
else if not(on_curve p2) then Inf
98
else if is_Inf p1 then p2
else if is_Inf p2 then p1
else (
let x1 = get_x p1 in let x2 = get_x p2 in
let y1 = get_y p1 in let y2 = get_y p2 in
if x1 = x2 then (
if y1 = y2 && y1 6= zero then (
let lam = ((3 +∗ (x12 ) ^+ a) ^/ (2 +∗ y1)) in
let x = ((lam2 ) ^− (2 +∗ x1)) in
let y = ((lam ^∗ (x1 ^− x)) ^− y1) in
Finite x y
) else (...)))
val ec_group_lemma:
unit → Lemma (AbelianGroup #celem Inf neg add)
99
Inductive point := EC_Inf | EC_In of K & K.
Notation "(x, y)" := (EC_In x y).
100
number is any number that is not algebraic. All real transcendental numbers
are irrational, because any rational number is a root of a degree one polynomial.
Since the set of algebraic numbers is countable, and the set of real or complex
numbers is uncountable, most real or complex numbers are transcendental. The
most famous transcendental numbers are e and π.
The formalization presented in [BBRS16] relies on a proof by Niven [Niv39].
The methodology used to show that π and e are transcendental is identical [Niv39]:
Supposing that the number is algebraic, results in an equality Ep = Ep0 where
Ep and Ep0 are two expressions depending on p ∈ Z. Then for p sufficiently large,
they prove that |Ep | < (p − 1)!, while |Ep0 | > (p − 1)! and by contradiction they
conclude that the number is not algebraic. The proof that |Ep | < (p − 1)! uses
properties of real and complex analysis, while the proof that |Ep0 | > (p − 1)! is
based on arithmetic and algebraic results. As a result, there are two parts of
the proof, one based on calculus using the Coquelicot library and one based on
algebra using the Mathematical Components library [Gon07, GAA+ 13, BLM15].
The proof of transcendence of π relies heavily on properties of multivariate
and symmetric polynomials, therefore a new library was developed on top of the
Mathematical Components library to formalize multivariate polynomials.
Multivariate polynomials are polynomial expressions with several variables.
In Ssreflect, univariate polynomials are represented as the list of its coeffi-
cients. To be more precise, the polynomial Σk∈N ak xk is represented by the list
[a0 , a1 , ..., an ] where an is the last non-zero coefficient. The above representation
could lead to an intuitive representation of multivariate polynomials with a finite
set of variables, using an enumeration of the countable set Nn . In this case, a
multivariate polynomial can be represented as the list of its coefficients, taken in
the ordering given by the enumeration of Nn . However, this representation is
ineffective as explained in the article mainly because it depends on the chosen
enumeration which may cause complications and also cannot be lifted to the
case of an infinite number of variables. Another option would be representing
the multivariate polynomial ring R[x1 , x2 , ..., xn ] as R[x1 ][x2 ]...[xn ], i.e. iter-
ating the univariate construction for all indeterminates. For example, in this
case a polynomial p(x, y) is seen as a univariate polynomial of indeterminate y,
whose coefficients are polynomials of indeterminate x. This representation is
still not efficient in Coq, because again it cannot be lifted to the infinite case,
and moreover it arises problems when trying to use the Canonical Structures
mechanism of Ssreflect.
The solution described in [BBRS16] is to represent a commutative multivariate
k1 k2 kn
polynomial as a formal sum of the form Σai (X1 i X2 i ...Xni ). This part of the
development extends the freeg structure for free abelian groups, described in
Chapter 2 of this thesis, and initially designed to formalize divisors on elliptic
curves. More precisely, to construct the type of commutative multivariate
101
polynomials in n variables, they extended freeg as follows: the set of coefficients
is a monoid, and the set of generators is the type of finite functions from
I = {1, 2, ..., n} to N. Another extension of freeg results in the non-commutative
multinomials: a non-commutative multivariate polynomial in n variables, is an
instance of freeg where the set of coefficients is a monoid, and the set of
generators is the set of sequences seq I. The library formalized contains proofs
for several properties of multivariate polynomials, including evaluation, derivation
and the proof that this representation is isomorphic to the iterated construction.
102
6
Conclusion
103
algorithms (multiexponentiation on a generic group and decomposition of the
scalar) and also theory about computing endomorphisms on algebraic curves.
Furthermore, we have presented an application of our work in Chapter 5 certifying
real-life implementations of elliptic curve algorithms combining our development
in Coq and F∗ .
Automation As already mention, during the work in this thesis, there were
several times when we needed to manipulate large polynomial formulas, like
the parts concerning the group law equations equations, the decomposition of
rational functions, or the large technical part concerning the uniqueness of the
Picard group representation. Those parts turned out to be quite technical in
Ssreflect, mainly because of the lack of automation. For our formalization, we
decided not to use any mathematics software designed to compute polynomial
formulas or resolve equations in some ring, such as Sage or Maple because
they come with no formal guarantee of their correctness. Our development is
completely based on Coq and there are no holes, in the sense that there are no
results admitted nor any non-verified tools used to aid computation. In Coq
there exist a form of automation (the ring tactic) which was not compatible
with the Ssreflect methodology. As a result, there were many computational
proofs in Ssreflect which had to be developed step-by-step by the users. In
104
that context, Pierre-Yves Strub developed an interface between the ring tactic
of Coq and the ring structures of Ssreflect which allowed us to simplify the
proof. Nevertheless, we would like to stress out the necessity for tactics that
would provide more automation in Ssreflect because it can be frustrating and
discouraging to the developer to confront this kind of difficulties.
105
Bibliography
[ABBD16] José Bacelar Almeida, Manuel Barbosa, Gilles Barthe, and François
Dupressoir. Verifiable side-channel security of cryptographic imple-
mentations: Constant-time MEE-CBC. In Thomas Peyrin, editor,
Fast Software Encryption - 23rd International Conference, FSE
2016, Bochum, Germany, March 20-23, 2016, Revised Selected Pa-
pers, volume 9783 of Lecture Notes in Computer Science, pages
163–184. Springer, 2016.
[ADGR07] Jeremy Avigad, Kevin Donnelly, David Gray, and Paul Raff. A form-
ally verified proof of the prime number theorem. ACM Transactions
on Computational Logic (TOCL), 9(1):2, 2007.
106
[App15a] Andrew W Appel. Verification of a cryptographic primitive: Sha-
256. ACM Transactions on Programming Languages and Systems
(TOPLAS), 37(2):7, 2015.
[APS12] Matteo Avalle, Alfredo Pironti, and Riccardo Sisto. Formal verifica-
tion of security protocol implementations: a survey. Formal Aspects
of Computing, pages 1–25, 2012.
[BBC+ 14] Gilles Barthe, Gustavo Betarte, Juan Campo, Carlos Luna, and
David Pichardie. System-level non-interference for constant-time
cryptography. In Proceedings of the 2014 ACM SIGSAC Conference
on Computer and Communications Security, pages 1267–1279. ACM,
2014.
[BBPV11b] Billy Bob Brumley, Manuel Barbosa, Dan Page, and Frederik Ver-
cauteren. Practical realisation and elimination of an ecc-related
software bug attack. IACR Cryptology ePrint Archive, 2011:633,
2011.
[BBPV12] Billy B Brumley, Manuel Barbosa, Dan Page, and Frederik Vercaut-
eren. Practical realisation and elimination of an ecc-related software
bug attack. In Topics in Cryptology–CT-RSA 2012, pages 171–186.
Springer, 2012.
107
[BC04] Yves Bertot and Pierre Castéran. Coq’Art: examples and exercises,
2004. [Link]
[BDK13] Michael Backes, Goran Doychev, and Boris Köpf. Preventing side-
channel leaks in web traffic: A formal approach. In 20th Annual
Network and Distributed System Security Symposium, NDSS 2013,
San Diego, California, USA, February 24-27, 2013. The Internet
Society, 2013.
[BGHB11] Gilles Barthe, Benjamin Grégoire, Sylvain Heraud, and Santiago Zan-
ella Béguelin. Computer-aided security proofs for the working cryp-
tographer. In Advances in Cryptology (CRYPTO), pages 71–90,
2011.
108
[BGLB11] Gilles Barthe, Benjamin Grégoire, Yassine Lakhnech, and Santi-
ago Zanella Béguelin. Beyond provable security verifiable IND-CCA
security of OAEP. In Aggelos Kiayias, editor, Topics in Cryptology
- CT-RSA 2011 - The Cryptographers’ Track at the RSA Conference
2011, San Francisco, CA, USA, February 14-18, 2011. Proceedings,
volume 6558 of Lecture Notes in Computer Science, pages 180–196.
Springer, 2011.
[Bih09] Sidi Ould Biha. Finite groups representation theory with coq.
In Jacques Carette, Lucas Dixon, Claudio Sacerdoti Coen, and
Stephen M. Watt, editors, Intelligent Computer Mathematics, 16th
Symposium, Calculemus 2009, 8th International Conference, MKM
2009, Held as Part of CICM 2009, Grand Bend, Canada, July 6-
12, 2009. Proceedings, volume 5625 of Lecture Notes in Computer
Science, pages 438–452. Springer, 2009.
[BJ03] Eric Brier and Marc Joye. Fast point multiplication on elliptic
curves through isogenies. In AAECC, pages 43–50, 2003.
109
[CC86] David V. Chudnovsky and Gregory V. Chudnovsky. Sequences of
numbers generated by addition in formal groups and new primality
and factorization tests. Advances in Applied Mathematics, 7:385–434,
1986.
[CHL+ 14] Yu-Fang Chen, Chang-Hong Hsu, Hsin-Hung Lin, Peter Schwabe,
Ming-Hsien Tsai, Bow-Yaw Wang, Bo-Yin Yang, and Shang-Yi
Yang. Verifying curve25519 software. In Gail-Joon Ahn, Moti Yung,
and Ninghui Li, editors, Proceedings of the 2014 ACM SIGSAC
Conference on Computer and Communications Security, Scottsdale,
AZ, USA, November 3-7, 2014, pages 299–309. ACM, 2014.
[CMO98] Henri Cohen, Atsuko Miyaji, and Takatoshi Ono. Efficient elliptic
curve exponentiation using mixed coordinates. In Kazuo Ohta
and Dingyi Pei, editors, Advances in Cryptology - ASIACRYPT
’98, International Conference on the Theory and Applications of
Cryptology and Information Security, Beijing, China, October 18-
22, 1998, Proceedings, volume 1514 of Lecture Notes in Computer
Science, pages 51–65. Springer, 1998.
110
[Cry] Cryptol Development Team. Cryptol, the language of cryptography.
[Link]
[DHL+ 05] Jianjun Duan, Joe Hurd, Guodong Li, Scott Owens, Konrad Slind,
and Junxing Zhang. Functional correctness proofs of encryption
algorithms. In Geoff Sutcliffe and Andrei Voronkov, editors, Logic
for Programming, Artificial Intelligence, and Reasoning, 12th Inter-
national Conference (LPAR 2005), volume 3835 of Lecture Notes in
Artificial Intelligence, pages 519–533. Springer, December 2005.
111
[Fre93] Friedrich Ludwig Gottlob Frege. Grundgesetze der Arithmetik:
Begriffsschriftlich abgeleitet. Erster Band. Pohle, 1893.
[Fri98] Stefan Friedl. An elementary proof of the group law for elliptic
curves. The Group Law on Elliptic Curves, 1998.
[GAA+ 13] Georges Gonthier, Andrea Asperti, Jeremy Avigad, Yves Bertot,
Cyril Cohen, François Garillot, Stéphane Le Roux, Assia Mahboubi,
Russell O’Connor, Sidi Ould Biha, Ioana Pasca, Laurence Rideau,
Alexey Solovyev, Enrico Tassi, and Laurent Théry. A machine-
checked proof of the odd order theorem. In Sandrine Blazy, Christine
Paulin-Mohring, and David Pichardie, editors, Interactive Theorem
Proving - 4th International Conference, ITP 2013, Rennes, France,
July 22-26, 2013. Proceedings, volume 7998 of Lecture Notes in
Computer Science, pages 163–179. Springer, 2013.
[Gar11] François Garillot. Generic Proof Tools and Finite Group Theory.
(Outils génériques de preuve et théorie des groupes finis). PhD
thesis, École Polytechnique, Palaiseau, France, 2011.
112
In Joe Kilian, editor, Advances in Cryptology - CRYPTO 2001,
21st Annual International Cryptology Conference, Santa Barbara,
California, USA, August 19-23, 2001, Proceedings, volume 2139 of
Lecture Notes in Computer Science, pages 190–200. Springer, 2001.
[GMR+ 07] Georges Gonthier, Assia Mahboubi, Laurence Rideau, Enrico Tassi,
and Laurent Théry. A modular formalisation of finite group theory.
In Klaus Schneider and Jens Brandt, editors, Theorem Proving
in Higher Order Logics, 20th International Conference, TPHOLs
2007, Kaiserslautern, Germany, September 10-13, 2007, Proceedings,
volume 4732 of Lecture Notes in Computer Science, pages 86–101.
Springer, 2007.
[GPP+ 16] Daniel Genkin, Lev Pachmanov, Itamar Pipman, Eran Tromer,
and Yuval Yarom. Ecdsa key extraction from mobile devices via
nonintrusive physical side channels. 2016.
[HGF06] Joe Hurd, Mike Gordon, and Anthony Fox. Formalized elliptic curve
cryptography. High Confidence Software and Systems, 2006.
113
[HHL+ 14] Chris Hawblitzel, Jon Howell, Jacob R. Lorch, Arjun Narayan,
Bryan Parno, Danfeng Zhang, and Brian Zill. Ironclad apps: End-
to-end security via automated full-system verification. In 11th
USENIX Symposium on Operating Systems Design and Implement-
ation (OSDI 14), pages 165–181, Broomfield, CO, October 2014.
USENIX Association.
[Ica09] Thomas Icart. How to hash into elliptic curves. In Shai Halevi,
editor, Advances in Cryptology - CRYPTO 2009, 29th Annual Inter-
national Cryptology Conference, Santa Barbara, CA, USA, August
16-20, 2009. Proceedings, volume 5677 of Lecture Notes in Computer
Science, pages 303–316. Springer, 2009.
[LH16] Adam Langley and Mike Hamburg. Elliptic curves for security.
IETF RFC 7748, 2016.
114
[Mon87] Peter L. Montgomery. Speeding the Pollard and elliptic curve
methods of factorization. Mathematics of Computation, 48:243–264,
1987.
[Pol78] John M. Pollard. Monte Carlo methods for index computation mod
p. Mathematics of Computation, 32:918–924, 1978.
115
[PR13] Emmanuel Prouff and Matthieu Rivain. Masking against side-
channel attacks: A formal security proof. In Thomas Johansson and
Phong Q. Nguyen, editors, Advances in Cryptology - EUROCRYPT
2013, 32nd Annual International Conference on the Theory and
Applications of Cryptographic Techniques, Athens, Greece, May 26-
30, 2013. Proceedings, volume 7881 of Lecture Notes in Computer
Science, pages 142–159. Springer, 2013.
[Sch87] René Schoof. Nonsingular plane cubic curves over finite fields. J.
Comb. Theory, Ser. A, 46(2):183–211, 1987.
[SD08] Eric Whitman Smith and David L. Dill. Automatic formal veri-
fication of block cipher implementations. In FMCAD, pages 1–7,
2008.
[SHK+ 16] Nikhil Swamy, Cătălin Hriţcu, Chantal Keller, Aseem Rastogi,
Antoine Delignat-Lavaud, Simon Forest, Karthikeyan Bhargavan,
Cédric Fournet, Pierre-Yves Strub, Markulf Kohlweiss, Jean-Karim
Zinzindohoue, and Santiago Zanella-Béguelin. Dependent types and
multi-monadic effects in F*. In 43nd ACM SIGPLAN-SIGACT
Symposium on Principles of Programming Languages (POPL), pages
256–270. ACM, January 2016.
116
[Ste03] Jacques Stern. Why provable security matters? In Eli Biham,
editor, Advances in Cryptology - EUROCRYPT 2003, International
Conference on the Theory and Applications of Cryptographic Tech-
niques, Warsaw, Poland, May 4-8, 2003, Proceedings, volume 2656
of Lecture Notes in Computer Science, pages 449–461. Springer,
2003.
[SvdW11] B. Spitters and E. van der Weegen. Type classes for mathematics
in type theory. Arxiv preprint arXiv:1102.1323, 2011.
[Thé07] Laurent Théry. Proving the group law for elliptic curves formally.
Technical Report RT-0330, INRIA, 2007.
117
A Formalization of Elliptic Curves for Cryptography. This thesis is in the domain of formalization of
mathematics and of verification of cryptographic algorithms. The implementation of cryptographic algorithms
is often a complicated task because cryptographic programs are optimized in order to satisfy both efficiency
and security criteria. As a result it is not always obvious that a cryptographique program actually corresponds
to the mathematical algorithm, i.e. that the program is correct. Errors in cryprtographic programs may be
disastrous for the security of an entire cryptosystem, hence certification of their correctness is required. Formal
systems and proof assistants such as Coq and Isabelle-HOL are often used to provide guarantees and proofs
that cryptographic programs are correct. Elliptic curves are widely used in cryptography, mainly as efficient
groups for asymmetric cryptography. To develop formal proofs of correctness for elliptic-curve schemes, formal
theory of elliptic curves is needed.
Our motivation in this thesis is to formalize elliptic curve theory using the Coq proof assistant, which enables
formal analysis of elliptic-curve schemes and algorithms. For this purpose, we used the Ssreflect extension
and the mathematical libraries developed by the Mathematical Components team during the formalization
of the Four Color Theorem. Our central result is a formal proof of Picard’s theorem for elliptic curves: there
exists an isomorphism between the Picard group of divisor classes and the group of points of an elliptic
curve. An important immediate consequence of this proposition is the associativity of the elliptic curve
group operation. Furthermore, we present a formal proof of correctness for the GLV algorithm for scalar
multiplication on elliptic curve groups. The GLV algorithm exploits properties of the elliptic curve group in
order to accelerate computation. It is composed of three independent algorithms: multiexponentiation on a
generic group, decomposition of the scalar and computing endomorphisms on algebraic curves. This development
includes theory about endomorphisms on elliptic curves and is more than 5000 lines of code. An application of
our formalization is also presented.
Keywords: Cryptography, Formal methods (computer science), Elliptic curves, Coq (software)
Une formalisation des courbes elliptiques pour la cryptographie. Le sujet de ma thèse s’inscrit dans
le domaine des preuves formelles et de la vérification des algorithmes cryptographiques. L’implémentation des
algorithmes cryptographiques est souvent une tâche assez compliquée, parce qu’ils sont optimisés pour être
efficaces et sûrs en même temps. Par conséquent, il n’est pas toujours évident qu’un programme cryptographique
en tant que fonction, corresponde exactement à l’algorithme mathématique, c’est-à-dire que le programme soit
correct. Les erreurs dans les programmes cryptographiques peuvent mettre en danger la sécurité de systèmes
cryptographiques entiers et donc, des preuves de correction sont souvent nécessaires. Les systèmes formels et
les assistants de preuves comme Coq et Isabelle-HOL sont utilisés pour développer des preuves de correction
des programmes. Les courbes elliptiques sont largement utilisées en cryptographie surtout en tant que groupe
cryptographique très efficace. Pour le développement des preuves formelles des algorithmes utilisant les courbes
elliptiques, une théorie formelle de celles-ci est nécessaire. Dans ce contexte, nous avons développé une théorie
formelle des courbes elliptiques en utilisant l’assistant de preuves Coq. Cette théorie est par la suite utilisée pour
prouver la correction des algorithmes de multiplication scalaire sur le groupe des points d’une courbe elliptique.
Plus précisément, mes travaux de thèse peuvent être divisées en deux parties principales. La première
concerne le développement de la théorie des courbes elliptiques en utilisant l’assistant des preuves Coq. Notre
développement de plus de 15000 lignes de code Coq comprend la formalisation des courbes elliptiques données
par une équation de Weierstrass, la théorie des corps des fonctions rationnelles sur une courbe, la théorie
des groupes libres et des diviseurs des fonctions rationnelles sur une courbe. Notre résultat principal est la
formalisation du théorème de Picard ; une conséquence directe de ce théorème est l’associativité de l’opération
du groupe des points d’une courbe elliptique qui est un résultat non trivial à prouver. La seconde partie de
ma thèse concerne la vérification de l’algorithme GLV pour effectuer la multiplication scalaire sur des courbes
elliptiques. Pour ce développement, nous avons vérifier trois algorithmes indépendants : la multiexponentiation
dans un groupe, la décomposition du scalaire et le calcul des endomorphismes sur une courbe elliptique. Nous
avons également développé une formalisation du plan projectif et des courbes en coordonnées projectives et
nous avons prouvé que les deux représentations (affine et projective) sont isomorphes.
Mon travail est à la fois une première approche à la formalisation de la géométrie algébrique élémentaire qui
est intégré dans les bibliothèques de Ssreflect mais qui sert aussi à la certification de véritables programmes
cryptographiques.
Mots-clés : Cryptographie, Méthodes formelles (informatique), Courbes elliptiques, Coq (logi-
ciel)
Université Paris-Saclay
Espace Technologique / Immeuble Discovery
Route de l’Orme aux Merisiers RD 128 / 91190 Saint-Aubin, France