Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Benoit Viguier
coq-verif-tweetnacl
Commits
c80f5322
Commit
c80f5322
authored
Feb 04, 2020
by
Benoit Viguier
Browse files
Fix alignment complaints from Peter
parent
93a90727
Changes
3
Hide whitespace changes
Inline
Side-by-side
paper/3-RFC.tex
View file @
c80f5322
...
...
@@ -13,14 +13,14 @@ Definition RFC (n: list Z) (p: list Z) : list Z :=
let k := decodeScalar25519 n in
let u := decodeUCoordinate p in
let t := montgomery
_
rec
255 (* iterate 255 times *)
k (* clamped n *)
255 (* iterate 255 times
*)
k (* clamped n
*)
1 (* x
_
2 *)
u (* x
_
3 *)
0 (* z
_
2 *)
1 (* z
_
3 *)
0 (* dummy *)
0 (* dummy *)
0 (* dummy
*)
0 (* dummy
*)
u (* x
_
1 *) in
let a := get
_
a t in
let c := get
_
c t in
...
...
@@ -38,43 +38,43 @@ Fixpoint montgomery_rec (m : nat) (z : T')
(* b: x3 *)
(* c: z2 *)
(* d: z3 *)
(* e: temporary var *)
(* f: temporary var *)
(* e: temporary var
*)
(* f: temporary var
*)
(* x: x1 *)
(T * T * T * T * T * T) :=
match m with
| 0
%nat => (a,b,c,d,e,f)
| S n =>
let r := Getbit (Z.of
_
nat n) z in
(* k
_
t = (k >> t)
&
1 *)
(* swap <- k
_
t *)
(* k
_
t = (k >> t)
&
1
*)
(* swap <- k
_
t
*)
let (a, b) := (Sel25519 r a b, Sel25519 r b a) in
(* (x
_
2, x
_
3) = cswap(swap, x
_
2, x
_
3)
*)
(* (x
_
2, x
_
3) = cswap(swap, x
_
2, x
_
3) *)
let (c, d) := (Sel25519 r c d, Sel25519 r d c) in
(* (z
_
2, z
_
3) = cswap(swap, z
_
2, z
_
3)
*)
let e := a + c in
(* A = x
_
2
+ z
_
2 *)
let a := a - c in
(* B = x
_
2
- z
_
2 *)
let c := b + d in
(* C = x
_
3
+ z
_
3 *)
let b := b - d in
(* D = x
_
3
- z
_
3 *)
let d := e
^
2
in
(* AA = A
^
2 *)
let f := a
^
2
in
(* BB = B
^
2 *)
let a := c * a in
(* CB = C * B *)
let c := b * e in
(* DA = D * A *)
let e := a + c in
(* x
_
3
= (DA + CB)
^
2 *)
let a := a - c in
(* z
_
3
= x
_
1
* (DA - CB)
^
2 *)
let b := a
^
2 in
(* z
_
3
= x
_
1
* (DA - CB)
^
2 *)
let c := d - f in
(* E = AA - BB *)
(* (z
_
2, z
_
3) = cswap(swap, z
_
2, z
_
3) *)
let e := a + c in (* A
= x
_
2+ z
_
2 *)
let a := a - c in (* B
= x
_
2- z
_
2 *)
let c := b + d in (* C
= x
_
3+ z
_
3 *)
let b := b - d in (* D
= x
_
3- z
_
3 *)
let d := e
^
2
in
(* AA = A
^
2
*)
let f := a
^
2
in
(* BB = B
^
2
*)
let a := c * a in (* CB = C * B
*)
let c := b * e in (* DA = D * A
*)
let e := a + c in (* x
_
3= (DA + CB)
^
2
*)
let a := a - c in (* z
_
3= x
_
1* (DA - CB)
^
2
*)
let b := a
^
2
in (* z
_
3= x
_
1* (DA - CB)
^
2
*)
let c := d - f in (* E
= AA - BB
*)
let a := c * C
_
121665 in
(* z
_
2 = E * (AA + a24 * E) *)
let a := a + d in
(* z
_
2 = E * (AA + a24 * E) *)
let c := c * a in
(* z
_
2 = E * (AA + a24 * E) *)
let a := d * f in
(* x
_
2 = AA * BB *)
let d := b * x in
(* z
_
3 = x
_
1
* (DA - CB)
^
2 *)
let b := e
^
2 in
(* x
_
3 = (DA + CB)
^
2 *)
(* z
_
2 = E * (AA + a24 * E)
*)
let a := a + d in (* z
_
2 = E * (AA + a24 * E)
*)
let c := c * a in (* z
_
2 = E * (AA + a24 * E)
*)
let a := d * f in (* x
_
2 = AA * BB
*)
let d := b * x in (* z
_
3 = x
_
1* (DA - CB)
^
2
*)
let b := e
^
2 in (* x
_
3 = (DA + CB)
^
2
*)
let (a, b) := (Sel25519 r a b, Sel25519 r b a) in
(* (x
_
2, x
_
3) = cswap(swap, x
_
2, x
_
3)
*)
(* (x
_
2, x
_
3) = cswap(swap, x
_
2, x
_
3) *)
let (c, d) := (Sel25519 r c d, Sel25519 r d c) in
(* (z
_
2, z
_
3) = cswap(swap, z
_
2, z
_
3)
*)
(* (z
_
2, z
_
3) = cswap(swap, z
_
2, z
_
3) *)
montgomery
_
rec n z a b c d e f x
end.
\end{lstlisting}
...
...
paper/A2_coq.tex
View file @
c80f5322
...
...
@@ -17,8 +17,8 @@ Class Ops (T T': Type) (Mod: T -> T):=
C
_
0 : T; (* Constant 0 *)
C
_
1 : T; (* Constant 1 *)
C
_
121665: T; (* const (a-2)/4 *)
Sel25519: Z -> T -> T -> T; (* CSWAP *)
Getbit: Z -> T' -> Z; (* ith bit *)
Sel25519: Z -> T -> T -> T;
(* CSWAP *)
Getbit: Z -> T' -> Z;
(* ith bit *)
}
.
Local Notation "X + Y" := (A X Y) (only parsing).
...
...
@@ -27,49 +27,49 @@ Local Notation "X * Y" := (M X Y) (only parsing).
Local Notation "X
^
2" := (Sq X) (at level 40,
only parsing, left associativity).
Fixpoint montgomery
_
rec (m: nat) (z: T')
Fixpoint montgomery
_
rec (m
: nat) (z
: T')
(a: T) (b: T) (c: T) (d: T) (e: T) (f: T) (x: T) :
(* a: x2 *)
(* b: x3 *)
(* c: z2 *)
(* d: z3 *)
(* e: temporary var *)
(* f: temporary var *)
(* e: temporary var
*)
(* f: temporary var
*)
(* x: x1 *)
(T * T * T * T * T * T) :=
match m with
| 0
%nat => (a,b,c,d,e,f)
| S n =>
let r := Getbit (Z.of
_
nat n) z in
(* k
_
t = (k >> t)
&
1 *)
(* swap <- k
_
t *)
(* k
_
t = (k >> t)
&
1
*)
(* swap <- k
_
t
*)
let (a, b) := (Sel25519 r a b, Sel25519 r b a) in
(* (x
_
2, x
_
3) = cswap(swap, x
_
2, x
_
3)
*)
(* (x
_
2, x
_
3) = cswap(swap, x
_
2, x
_
3) *)
let (c, d) := (Sel25519 r c d, Sel25519 r d c) in
(* (z
_
2, z
_
3) = cswap(swap, z
_
2, z
_
3)
*)
let e := a + c in
(* A = x
_
2
+ z
_
2 *)
let a := a - c in
(* B = x
_
2
- z
_
2 *)
let c := b + d in
(* C = x
_
3
+ z
_
3 *)
let b := b - d in
(* D = x
_
3
- z
_
3 *)
let d := e
^
2
in
(* AA = A
^
2 *)
let f := a
^
2
in
(* BB = B
^
2 *)
let a := c * a in
(* CB = C * B *)
let c := b * e in
(* DA = D * A *)
let e := a + c in
(* x
_
3
= (DA + CB)
^
2 *)
let a := a - c in
(* z
_
3
= x
_
1
* (DA - CB)
^
2 *)
let b := a
^
2 in
(* z
_
3
= x
_
1
* (DA - CB)
^
2 *)
let c := d - f in
(* E = AA - BB *)
(* (z
_
2, z
_
3) = cswap(swap, z
_
2, z
_
3) *)
let e := a + c in (* A
= x
_
2+ z
_
2 *)
let a := a - c in (* B
= x
_
2- z
_
2 *)
let c := b + d in (* C
= x
_
3+ z
_
3 *)
let b := b - d in (* D
= x
_
3- z
_
3 *)
let d := e
^
2
in
(* AA = A
^
2
*)
let f := a
^
2
in
(* BB = B
^
2
*)
let a := c * a in (* CB = C * B
*)
let c := b * e in (* DA = D * A
*)
let e := a + c in (* x
_
3= (DA + CB)
^
2
*)
let a := a - c in (* z
_
3= x
_
1* (DA - CB)
^
2
*)
let b := a
^
2
in (* z
_
3= x
_
1* (DA - CB)
^
2
*)
let c := d - f in (* E
= AA - BB
*)
let a := c * C
_
121665 in
(* z
_
2 = E * (AA + a24 * E) *)
let a := a + d in
(* z
_
2 = E * (AA + a24 * E) *)
let c := c * a in
(* z
_
2 = E * (AA + a24 * E) *)
let a := d * f in
(* x
_
2 = AA * BB *)
let d := b * x in
(* z
_
3 = x
_
1
* (DA - CB)
^
2 *)
let b := e
^
2 in
(* x
_
3 = (DA + CB)
^
2 *)
(* z
_
2 = E * (AA + a24 * E)
*)
let a := a + d in (* z
_
2 = E * (AA + a24 * E)
*)
let c := c * a in (* z
_
2 = E * (AA + a24 * E)
*)
let a := d * f in (* x
_
2 = AA * BB
*)
let d := b * x in (* z
_
3 = x
_
1* (DA - CB)
^
2
*)
let b := e
^
2 in (* x
_
3 = (DA + CB)
^
2
*)
let (a, b) := (Sel25519 r a b, Sel25519 r b a) in
(* (x
_
2, x
_
3) = cswap(swap, x
_
2, x
_
3)
*)
(* (x
_
2, x
_
3) = cswap(swap, x
_
2, x
_
3) *)
let (c, d) := (Sel25519 r c d, Sel25519 r d c) in
(* (z
_
2, z
_
3) = cswap(swap, z
_
2, z
_
3)
*)
(* (z
_
2, z
_
3) = cswap(swap, z
_
2, z
_
3) *)
montgomery
_
rec n z a b c d e f x
end.
...
...
@@ -155,7 +155,7 @@ Proof.
apply Mid.A. (* instantiate + *)
apply Mid.M. (* instantiate * *)
apply Mid.Zub. (* instantiate - *)
apply Mid.Sq. (* instantiate x
^
2
*)
apply Mid.Sq. (* instantiate x
^
2 *)
apply Mid.C
_
0. (* instantiate Const 0 *)
apply Mid.C
_
1. (* instantiate Const 1 *)
apply Mid.C
_
121665. (* instantiate (a-2)/4 *)
...
...
@@ -177,14 +177,14 @@ Definition RFC (n: list Z) (p: list Z) : list Z :=
let k := decodeScalar25519 n in
let u := decodeUCoordinate p in
let t := montgomery
_
rec
255 (* iterate 255 times *)
k (* clamped n *)
255 (* iterate 255 times
*)
k (* clamped n
*)
1 (* x
_
2 *)
u (* x
_
3 *)
0 (* z
_
2 *)
1 (* z
_
3 *)
0 (* dummy *)
0 (* dummy *)
0 (* dummy
*)
0 (* dummy
*)
u (* x
_
1 *) in
let a := get
_
a t in
let c := get
_
c t in
...
...
paper/setup.sty
View file @
c80f5322
...
...
@@ -35,7 +35,7 @@
\renewcommand
{
\algorithmicrequire
}{
\textbf
{
Input:
\
}}
\renewcommand
{
\algorithmicensure
}{
\textbf
{
Output:
\
}}
\setlength
{
\abovecaptionskip
}{
-
10
pt
}
\setlength
{
\abovecaptionskip
}{
-
9
pt
}
\newcommand
{
\todo
}
[1]
{
{
\color
{
red
}
\bf
TODO: #1
}
...
...
@@ -233,11 +233,11 @@ columns=[l]flexible,
literate=
% {\\forall}{{\color{dkgreen}{$\forall\;$}}}1
% {\\exists}{{$\exists\;$}}1
{
<-
}{{$
\leftarrow\;
$}}
1
{
<-
}{{
\makebox
[8pt][l]
{
$
\leftarrow\;
$}}
}
1
{
=>
}{{$
\Rightarrow\;
$}}
1
{
==>
}{{
\texttt
{
==>
}
\;
}}
1
% {:>}{{\texttt{:>}\;}}1
{
->
}{{$
\rightarrow\;
$}}
1
{
->
}{{
\makebox
[8pt][l]
{
$
\rightarrow\;
$}}
}
1
{
<->
}{{$
\leftrightarrow\;
$}}
1
{
<=
}{{$
\leq\;
$}}
1
{
==
}{{
\texttt
{
==
}
\;
}}
1
...
...
@@ -274,38 +274,39 @@ literate=
{^
n
}{{$^
n
$}}
1
{^
+n
}{{$^
n
$}}
1
{^
m
}{{$^
m
$}}
1
{^
2
}{{$^
2
$}}
1
{^
+2
}{{$^
2
$}}
1
{^
3
}{{$^
3
$}}
1
{^
+3
}{{$^
3
$}}
1
{^
2
}{{
\makebox
[8pt][l]
{
$^
2
$}}
}
1
{^
+2
}{{
\makebox
[8pt][l]
{
$^
2
$}}
}
1
{^
3
}{{
\makebox
[8pt][l]
{
$^
3
$}}
}
1
{^
+3
}{{
\makebox
[8pt][l]
{
$^
3
$}}
}
1
{^
nd
}{{$^{
nd
}$}}
1
{^
rd
}{{$^{
rd
}$}}
1
{^
th
}{{$^{
th
}$}}
1
{^
255
}{{$^{
255
}$}}
1
{^
-1
}{{$^{
-
1
}$}}
1
{
\%
:R
}{{}}
1
{
p1
}{{
p
$_
1
$}}
1
{
p2
}{{
p
$_
2
$}}
1
{
x1
}{{
x
$_
1
$}}
1
{
x2
}{{
x
$_
2
$}}
1
{
x3
}{{
x
$_
3
$}}
1
{
x
_
1
}{{
x
$_
1
$}}
1
{
x
_
2
}{{
x
$_
2
$}}
1
{
x
_
3
}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8pt][l]
{$_
3
$}}}
1
{
xs
}{{
x
\makebox
[8pt][l]
{$_
s
$}}}
1
{
\\
-
}{{
\makebox
[9pt][c]
{$
-
$}}}
1
{
\\
+
}{{
\makebox
[9pt][c]
{$
+
$}}}
1
{
\\*
}{{
\makebox
[9pt][c]
{$
*
$}}}
1
{
\\
boxplus
}{{$
\boxplus
$}}
1
{
\\
circ
}{{$
\circ
$}}
1
{
\\
GF
}{{$
\mathbb
{
F
}_{
2
^{
255
}
-
19
}$}}
1
...
...
@@ -385,7 +386,8 @@ literate=
% basicstyle=\ttfamily\small, % font that is used for the code
basicstyle=
\ttfamily\footnotesize
,
% font that is used for the code
identifierstyle=
\color
{
doc@lstidentifier
}
,
commentstyle=
\color
{
doc@lstcomment
}
\itshape
,
commentstyle=
\color
{
doc@lstcomment
}
\footnotesize
,
% \itshape,
stringstyle=
\color
{
doc@lststring
}
,
keywordstyle=
\color
{
doc@lstkeyword
}
,
keywordstyle=[1]
\color
{
doc@lstidentifiers2
}
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment