@@ -9,7 +9,7 @@ open wordsLib;
9
9
open lcsymtacs;
10
10
;
11
11
12
- val _ = numLib.prefer_num()
12
+ val _ = numLib.prefer_num();
13
13
14
14
val _ = new_theory " keccakpermutation" ;
15
15
@@ -35,27 +35,33 @@ FCP i. let z=i MOD 64 in
35
35
)`;
36
36
37
37
(* 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)) =
39
39
let
40
40
val eq = (mk_eq (t,(numSyntax.mk_numeral (Arbnum.fromInt
41
41
n))))
42
42
val ineq =
43
- if (n>0 ) then
43
+ if (n>m ) then
44
44
list_mk_comb (Term `$<=`, [t, numSyntax.mk_numeral (Arbnum.fromInt
45
45
(n-1 ))])
46
46
else (Term `F`)
47
47
val term = mk_disj (eq, ineq)
48
48
val termimp = list_mk_imp (asl,term)
49
49
in
50
- (if n>0 then
50
+ (if n>m then
51
51
mp_tac (prove(termimp, simp [])) >>
52
52
rw []
53
- >| [all_tac , split_num_in_range t (n-1 )]
53
+ >| [tac , split_num_in_range_then t m (n-1 ) tac ]
54
54
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;
58
62
63
+
64
+ (* TODO *)
59
65
(* Sanity check: transformation translates back correctly *)
60
66
val matrix_representation2word_word2matrix_representation = prove(``
61
67
! w:1600 word.
@@ -64,16 +70,12 @@ matrix_representation2word (word2matrix_representation w)
64
70
``,
65
71
simp [matrix_representation2word_def, word2matrix_representation_def] >>
66
72
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! *)
72
77
);
73
78
74
-
75
-
76
-
77
79
val BSUM_def = Define`
78
80
(! f. BSUM 0 f = F)
79
81
/\
@@ -177,7 +179,7 @@ val ntimes_def = Define `
177
179
/\
178
180
(ntimes 0 f = (\x.x))`
179
181
180
- val lsfr_comp = Define `
182
+ val lsfr_comp_def = Define `
181
183
(lsfr_comp 0 = ((0b10000000w:word8),T))
182
184
/\
183
185
(lsfr_comp (SUC n) =
@@ -226,6 +228,11 @@ val round_constants_def = Define `
226
228
(round_constants 23 = 0x8000000080008008w)
227
229
`
228
230
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
+
229
236
val IsKeccakroundconstant_def = Define `
230
237
IsKeccakroundconstant RC =
231
238
! i x y z.
@@ -242,35 +249,56 @@ IsKeccakroundconstant RC =
242
249
==> (RC i (x,y,z) = F ))
243
250
`
244
251
245
-
246
-
247
-
248
252
val round_constants_correctness = prove(``
249
- IsKeccakroundconstant (word2matrix_representation o round_constants )
253
+ IsKeccakroundconstant (round_constant_matrix )
250
254
``,
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
+ );
274
302
275
303
276
304
0 commit comments