Skip to content

Commit fc359ed

Browse files
author
Robert Künnemann
committed
Spec of Keccak permutation. Currently imcomplete: LSFR is there, matrix multiplication is missing
1 parent 173e521 commit fc359ed

File tree

2 files changed

+72
-45
lines changed

2 files changed

+72
-45
lines changed

keccakpermutationSimplifiedScript.sml

+72-44
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ open wordsLib;
99
open lcsymtacs;
1010
;
1111

12-
val _ = numLib.prefer_num()
12+
val _ = numLib.prefer_num();
1313

1414
val _ = new_theory "keccakpermutation";
1515

@@ -35,27 +35,33 @@ FCP i. let z=i MOD 64 in
3535
)`;
3636

3737
(* Tactic that performs case split for all numbers from 0 to n *)
38-
fun split_num_in_range t n (g as (asl,w)) =
38+
fun split_num_in_range_then t m n tac (g as (asl,w)) =
3939
let
4040
val eq = (mk_eq (t,(numSyntax.mk_numeral (Arbnum.fromInt
4141
n))))
4242
val ineq =
43-
if (n>0) then
43+
if (n>m) then
4444
list_mk_comb (Term `$<=`, [t, numSyntax.mk_numeral (Arbnum.fromInt
4545
(n-1))])
4646
else (Term `F`)
4747
val term = mk_disj (eq, ineq)
4848
val termimp = list_mk_imp (asl,term)
4949
in
50-
(if n>0 then
50+
(if n>m then
5151
mp_tac (prove(termimp, simp [])) >>
5252
rw []
53-
>| [all_tac, split_num_in_range t (n-1)]
53+
>| [tac, split_num_in_range_then t m (n-1) tac]
5454
else
55-
all_tac)
56-
end g;
57-
fun qsplit_num_in_range q n = Q_TAC (fn t => split_num_in_range t n) q
55+
tac)
56+
end
57+
g;
58+
fun qsplit_num_in_range_then q m n tac =
59+
Q_TAC (fn t => split_num_in_range_then t m n tac) q;
60+
fun qsplit_num_in_range q m n =
61+
qsplit_num_in_range_then q m n all_tac;
5862

63+
64+
(* TODO *)
5965
(* Sanity check: transformation translates back correctly *)
6066
val matrix_representation2word_word2matrix_representation = prove(``
6167
! w:1600 word.
@@ -64,16 +70,12 @@ matrix_representation2word (word2matrix_representation w)
6470
``,
6571
simp [matrix_representation2word_def, word2matrix_representation_def] >>
6672
rw [GSYM WORD_EQ, word_bit_def, fcpTheory.FCP_BETA] >>
67-
qsplit_num_in_range `x` 1600 >>
68-
fs []
69-
70-
`(x=0)\/(x=1)\/(x=2)\/(x=3)\/(x>3)` by simp []
71-
73+
simp [] >>
74+
(* brute force *)
75+
qsplit_num_in_range_then `x` 0 1600 (fs [])
76+
(* Can be shown this way, but it takes ages! *)
7277
);
7378

74-
75-
76-
7779
val BSUM_def = Define`
7880
(! f. BSUM 0 f = F)
7981
/\
@@ -177,7 +179,7 @@ val ntimes_def = Define `
177179
/\
178180
(ntimes 0 f = (\x.x))`
179181

180-
val lsfr_comp = Define `
182+
val lsfr_comp_def = Define `
181183
(lsfr_comp 0 = ((0b10000000w:word8),T))
182184
/\
183185
(lsfr_comp (SUC n) =
@@ -226,6 +228,11 @@ val round_constants_def = Define `
226228
(round_constants 23 = 0x8000000080008008w)
227229
`
228230

231+
val round_constant_matrix_def = Define `
232+
( round_constant_matrix i (0,0,z) = word_bit z (round_constants i) )
233+
/\
234+
( round_constant_matrix i (x,y,z) = F)`
235+
229236
val IsKeccakroundconstant_def = Define `
230237
IsKeccakroundconstant RC =
231238
! i x y z.
@@ -242,35 +249,56 @@ IsKeccakroundconstant RC =
242249
==> (RC i (x,y,z) = F ))
243250
`
244251

245-
246-
247-
248252
val round_constants_correctness = prove(``
249-
IsKeccakroundconstant (word2matrix_representation o round_constants )
253+
IsKeccakroundconstant (round_constant_matrix)
250254
``,
251-
rw [IsKeccakroundconstant_def, word2matrix_representation_def] >>
252-
Cases_on `i=0` >>
253-
simp [round_constants_def] >>
254-
qexists_tac `LOG 2 (z+1) ` >>
255-
rw [] >>
256-
257-
Cases_on `x=4` >>
258-
Cases_on `y=4` >>
259-
Cases_on `z=63` >>
260-
fs []
261-
rw []
262-
EVAL_TAC
263-
264-
qsplit_num_in_range `y` 4 >>
265-
qsplit_num_in_range `x` 4 >>
266-
qsplit_num_in_range `z` 63 >>
267-
EVAL_TAC
268-
269-
`(z=63) \/ (z <= 62)` by simp []
270-
271-
BasicProvers.EVERY_CASE_TAC >>
272-
273-
EVAL ``LOG 2 8``
255+
rw [IsKeccakroundconstant_def]
256+
>- (
257+
qexists_tac `LOG 2 (z+1) ` >>
258+
rw [] >>
259+
Cases_on `x` >>
260+
Cases_on `y` >>
261+
rw [round_constant_matrix_def] >>
262+
qsplit_num_in_range_then `i` 0 23 (rw [round_constants_def])>>
263+
qsplit_num_in_range_then `LOG 2 (z+1)` 0 6 (rw [rc_def,lsfr_comp_def])>>
264+
EVAL_TAC
265+
)
266+
>>
267+
`(z<>0) /\
268+
(z<>1) /\
269+
(z<>3) /\
270+
(z<>7) /\
271+
(z<>15) /\
272+
(z<>31) /\
273+
(z<>63)` by (spose_not_then
274+
(
275+
fn th =>
276+
(pop_assum (mp_tac) >>
277+
assume_tac th >>
278+
rw [] >>
279+
qexists_tac `LOG 2 (z+1)` >>
280+
Cases_on `z=0` >>
281+
Cases_on `z=1` >>
282+
Cases_on `z=3` >>
283+
Cases_on `z=7` >>
284+
Cases_on `z=15` >>
285+
Cases_on `z=31` >>
286+
Cases_on `z=63` >>
287+
fs []
288+
)
289+
)
290+
) >>
291+
Cases_on `x` >>
292+
Cases_on `y` >>
293+
rw [round_constant_matrix_def] >>
294+
qsplit_num_in_range_then `i` 0 23 (rw [round_constants_def])>>
295+
qsplit_num_in_range_then `z` 31 62 (fs [rc_def,lsfr_comp_def])>>
296+
qsplit_num_in_range_then `z` 15 30 (fs [rc_def,lsfr_comp_def])>>
297+
qsplit_num_in_range_then `z` 7 14 (fs [rc_def,lsfr_comp_def])>>
298+
qsplit_num_in_range_then `z` 3 6 (fs [rc_def,lsfr_comp_def])>>
299+
`( z=2 )` by simp [] >>
300+
fs []
301+
);
274302

275303

276304

mitbScript.sml

-1
Original file line numberDiff line numberDiff line change
@@ -870,7 +870,6 @@ val PROTO_def =
870870
(* Give adversary blackbox access when corrupted, but
871871
* not complete: she is not allowed to set the key.
872872
* TODO: would be nicer if we would check the ready state via the LED
873-
*
874873
* *)
875874
(* Ignore Key-overwrite *)
876875
( PROTO mitbf ((Ready,cntl,vmem),T) (AtoP (F,F,inp,len)) =

0 commit comments

Comments
 (0)