6-conclusion.tex 4.09 KB
Newer Older
1
\section{Conclusion}
Benoit Viguier's avatar
Benoit Viguier committed
2
\label{sec:Conclusion}
3

Benoit Viguier's avatar
Benoit Viguier committed
4
5
Any formal system relies on a trusted base. In this section we describe our
chain of trust.
6

7
8
9
10
\subheading{Trusted Code Base of the proof.}
Our proof relies on a trusted base, i.e. a foundation of definitions that must be
correct. One should not be able to prove a false statement in that system, \eg, by
proving an inconsistency.
Benoit Viguier's avatar
Benoit Viguier committed
11
12
13

In our case we rely on:
\begin{itemize}
14
  \item \textbf{Calculus of Inductive Constructions}. The intuitionistic logic
Benoit Viguier's avatar
Benoit Viguier committed
15
  used by Coq must be consistent in order to trust the proofs. As an axiom,
16
  we assume that the functional extensionality is also consistent with that logic.
Benoit Viguier's avatar
Benoit Viguier committed
17
  $$\forall x, f(x) = g(x) \implies f = g$$
Benoit Viguier's avatar
Benoit Viguier committed
18
19
20
21
22
23
\begin{lstlisting}[language=Coq]
Lemma f_ext: forall (A B:Type),
  forall (f g: A -> B),
  (forall x, f(x) = g(x)) -> f = g.
\end{lstlisting}

Benoit Viguier's avatar
Benoit Viguier committed
24
  \item \textbf{Verifiable Software Toolchain}. This framework developed at
Benoit Viguier's avatar
Benoit Viguier committed
25
  Princeton allows a user to prove that a Clight code matches pure Coq
26
  specification.
Benoit Viguier's avatar
Benoit Viguier committed
27

Freek Wiedijk's avatar
Freek Wiedijk committed
28
29
30
31
  \item \textbf{CompCert}.
% The formally proven compiler.
% We trust that the CompCert Clight semantics in Coq
% correctly captures the C17 standard.
32
  When compiling with CompCert we only need to trust CompCert's {assembly} semantics, because it has been formally proven correct.
Freek Wiedijk's avatar
Freek Wiedijk committed
33
34
35
  However, when compiling with other C compilers like Clang or GCC, we need to trust that the CompCert's Clight semantics matches the C17 standard.
% as well as
% that the compiler will compile the TweetNaCl code according to that standard.
Freek Wiedijk's avatar
Freek Wiedijk committed
36
37
  % Our proof also assumes that the TweetNaCl code will behave as expected if
  % compiled under CompCert.
38
  % We do not provide guarantees for other C compilers such as Clang or GCC.
Benoit Viguier's avatar
Benoit Viguier committed
39

Freek Wiedijk's avatar
Freek Wiedijk committed
40
41
  \item \textbf{\texttt{clightgen}}. The tool making the translation from {C} to
  {Clight}. It is the first step of the compilation.
Benoit Viguier's avatar
Benoit Viguier committed
42
43
44
45
46
47
48
  VST does not support the direct verification of \texttt{o[i] = a[i] + b[i]}.
  This required us to rewrite the lines into:
\begin{lstlisting}[language=C]
aux1 = a[i];
aux2 = b[i];
o[i] = aux1 + aux2;
\end{lstlisting}
49
  The trust of the proof relies on the trust of a correct translation from the
50
51
  initial version of \emph{TweetNaCl} to \emph{TweetNaclVerifiableC}.
  \texttt{clightgen} comes with \texttt{-normalize} flag which
52
  factors out function calls and assignments from inside subexpressions.
53
  The changes required for C code to make it verifiable are now minimal.
Benoit Viguier's avatar
Benoit Viguier committed
54

55
56
57
  \item Finally,
  % Last but not the least,
  we must trust the \textbf{Coq kernel} and its
Benoit Viguier's avatar
Benoit Viguier committed
58
59
60
61
  associated libraries; the \textbf{Ocaml compiler} on which we compiled Coq;
  the \textbf{Ocaml Runtime} and the \textbf{CPU}. Those are common to all proofs
  done with this architecture \cite{2015-Appel,coq-faq}.
\end{itemize}
62

63
\subheading{Corrections in TweetNaCl.}
Benoit Viguier's avatar
Benoit Viguier committed
64
As a result of this verification, we removed superfluous code.
65
66
67
Indeed indexes 17 to 79 of the \TNaCle{i64 x[80]} intermediate variable of
\TNaCle{crypto_scalarmult} were adding unnecessary complexity to the code,
we removed them.
68
69

Peter Wu and Jason A. Donenfeld brought to our attention that the original
Benoit Viguier's avatar
WIP    
Benoit Viguier committed
70
\TNaCle{car25519} function carried a risk of undefined behavior if \texttt{c}
71
72
73
74
75
is a negative number.
\begin{lstlisting}[language=Ctweetnacl]
c=o[i]>>16;
o[i]-=c<<16; // c < 0 = UB !
\end{lstlisting}
76
77
We replaced this statement with a logical \texttt{and}, proved correctness,
and thus solved this problem.
78
79
80
\begin{lstlisting}[language=Ctweetnacl]
o[i]&=0xffff;
\end{lstlisting}
Benoit Viguier's avatar
Benoit Viguier committed
81

82
83
We believe that the type change of the loop index (\TNaCle{int} instead of \TNaCle{i64})
does not impact the trust of our proof.
Benoit Viguier's avatar
Benoit Viguier committed
84

85
\subheading{A complete proof.}
Benoit Viguier's avatar
Benoit Viguier committed
86
87
88
89
We provide a mechanized formal proof of the correctness of the X25519
implementation in TweetNaCl.
We first formalized X25519 from RFC~7748~\cite{rfc7748} in Coq. Then we proved
that TweetNaCl's implementation of X25519 matches our formalization.
Benoit Viguier's avatar
typos    
Benoit Viguier committed
90
In a second step we extended the Coq library for elliptic curves \cite{BartziaS14}
91
by Bartzia and Strub to support Montgomery curves. Using this extension we
92
proved that the X25519 from the RFC and therefore its implementation in TweetNaCl matches
Benoit Viguier's avatar
Benoit Viguier committed
93
the mathematical definitions as given in~\cite[Sec.~2]{Ber06}.