-
Notifications
You must be signed in to change notification settings - Fork 1
/
blake2s.thy
409 lines (364 loc) · 12.7 KB
/
blake2s.thy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
theory blake2s
imports "HOL-SPARK.SPARK" "quadlets"
begin
(* BLAKE2S/INCORPORATE_FLEX *)
spark_open "blake2s/incorporate_flex"
spark_vc procedure_incorporate_flex_7
proof -
from `message_last - (message_first - 1) <= 64 &
message_index__1 = message_first - 1
|
64 < message_last - (message_first - 1) &
message_index__1 < message_last`
`message_last - 64 <= message_index__1`
show ?thesis by linarith
qed
spark_vc procedure_incorporate_flex_9
proof -
from `0 <= buffer_index context`
show ?C1 by (simp add: div_pos_geq sdiv_pos_pos)
show ?C2 by simp
qed
spark_vc procedure_incorporate_flex_10
proof -
from `0 <= buffer_index context` `buffer_index context mod 4 = 0`
show ?C1 using sdiv_pos_pos by auto
from `buffer_index context mod 4 = 0`
show ?C2 by auto
qed
spark_vc procedure_incorporate_flex_11
proof -
from `buffer_index context mod 4 = 1`
have "(1 + buffer_index context) mod 4 ~= 0"
using bits_one_mod_two_eq_one dvd_imp_mod_0 mod_mult_self1 mult.commute
by presburger
hence "~ 4 dvd (1 + buffer_index context)" by auto
thus ?C1 using `0 <= buffer_index context`
by (simp add: algebra_simps sdiv_pos_pos,
subst div_truncate_one, simp_all)
thus ?C2 using ` buffer_index context mod 4 = 1` by presburger
qed
spark_vc procedure_incorporate_flex_12
proof -
from `buffer_index context mod 4 = 2`
have "(1 + buffer_index context) mod 4 ~= 0"
using bits_one_mod_two_eq_one dvd_imp_mod_0 mod_mult_self1 mult.commute
by presburger
hence "~ 4 dvd (1 + buffer_index context)" by auto
thus ?C1 using `0 <= buffer_index context`
by (simp add: algebra_simps sdiv_pos_pos,
subst div_truncate_one, simp_all)
thus ?C2 using `buffer_index context mod 4 = 2` by presburger
qed
spark_vc procedure_incorporate_flex_13
proof -
from `buffer_index context mod 4 = 3`
have "(1 + (buffer_index context)) mod 4 = 0"
using bits_one_mod_two_eq_one dvd_imp_mod_0 mod_mult_self1 mult.commute
by presburger
hence l1: "4 dvd (1 + buffer_index context)" by auto
hence "~4 dvd buffer_index context"
using `buffer_index context mod 4 = 3` by auto
hence "buffer_index context div 4 =
(1 + buffer_index context) div 4 - 1"
using l1 cancel_div_mod_rules(2)
div_add_self2 nonzero_mult_div_cancel_left by auto
thus ?C1 using `0 <= buffer_index context` by (simp add: sdiv_pos_pos)
thus ?C2 using `buffer_index context mod 4 = 3` by presburger
qed
spark_vc procedure_incorporate_flex_21
proof -
from `message_last - message_index <= 64 &
message_index__4 = message_index
| 64 < message_last - message_index &
message_index__4 < message_last`
`message_last - 64 <= message_index__4`
`message_first - 1 <= message_index`
show ?C1 by auto
from `message_last - message_index <= 64 &
message_index__4 = message_index
| 64 < message_last - message_index &
message_index__4 < message_last`
`message_index < message_last`
show ?C2 by auto
from `message_last \<le> message__index__subtype__1__last`
`message_index__4 < message_last`
show ?C3 by simp
qed
spark_vc procedure_incorporate_flex_23
proof -
from `buffer_index context = 0`
show ?thesis by (simp add: sdiv_pos_pos)
qed
spark_vc procedure_incorporate_flex_26
proof -
from `buffer_index context mod 4 = 0`
have l1: "4 dvd buffer_index context" by presburger
hence "buffer_index context ~= 63" by presburger
moreover from l1 have "buffer_index context ~= 62" by presburger
moreover from l1 have "buffer_index context ~= 61" by presburger
ultimately show ?thesis using `buffer_index context < 64` by auto
qed
spark_end
(* BLAKE2S/INITIAL_KEYED_FLEX *)
spark_open "blake2s/initial_keyed_flex"
spark_vc function_initial_keyed_flex_6
proof -
from `key_length <=
key__index__subtype__1__last - key__index__subtype__1__first + 1`
`key__index__subtype__1__last <= 32`
show "key__index__subtype__1__first - 1 + key_length <= 32" by simp
qed
spark_vc function_initial_keyed_flex_11
proof -
from `(key_index - (key__index__subtype__1__first - 1)) mod 4 = 0`
show ?C1 using mod_add_self2 by presburger
from `key__index__subtype__1__first >= 1`
`key_index >= key__index__subtype__1__first - 1`
show ?C2 by (simp_all add: sdiv_pos_pos)
qed
spark_vc function_initial_keyed_flex_28
proof -
from `(key_index - (key__index__subtype__1__first - 1)) mod 4 = 0`
show ?C1 using mod_add_self2 by presburger
from `key__index__subtype__1__first >= 1`
`key_index >= key__index__subtype__1__first - 1`
show ?C2 by (simp add: sdiv_pos_pos)
qed
spark_vc function_initial_keyed_flex_30
proof -
from `(key_index - (key__index__subtype__1__first - 1)) mod 4 = 0`
show ?C1 using mod_add_self2 by presburger
from `key__index__subtype__1__first >= 1`
`key_index >= key__index__subtype__1__first - 1`
have rw: "(2 + (key_index - key__index__subtype__1__first)) div 4 =
((key_index - (key__index__subtype__1__first - 1)) + 1) div 4"
by (simp add: algebra_simps)
from `key__index__subtype__1__first >= 1`
`key_index >= key__index__subtype__1__first - 1`
`(key_index - (key__index__subtype__1__first - 1)) mod 4 = 0`
show ?C2
by (simp add: sdiv_pos_pos, subst rw, subst div_truncate_plus,
simp_all)
qed
spark_vc function_initial_keyed_flex_33
proof -
from `(key_index - (key__index__subtype__1__first - 1)) mod 4 = 1`
show ?C1 using mod_add_self2 by presburger
from `key__index__subtype__1__first >= 1`
`key_index >= key__index__subtype__1__first`
have rw: "(2 + (key_index - key__index__subtype__1__first)) div 4 =
((key_index - (key__index__subtype__1__first - 1)) + 1) div 4"
by (simp add: algebra_simps)
from `key__index__subtype__1__first >= 1`
`key_index >= key__index__subtype__1__first`
`(key_index - (key__index__subtype__1__first - 1)) mod 4 = 1`
show ?C2 by (simp add: sdiv_pos_pos, subst rw, subst div_truncate_plus,
simp_all)
qed
spark_vc function_initial_keyed_flex_38
proof-
from `(key_index - (key__index__subtype__1__first - 1)) mod 4 = 2`
show ?C1 using mod_add_self2 by presburger
from `key__index__subtype__1__first >= 1`
`key_index >= key__index__subtype__1__first + 1`
have rw: "(2 + (key_index - key__index__subtype__1__first)) div 4 =
((key_index - (key__index__subtype__1__first - 1)) + 1) div 4"
by (simp add: algebra_simps)
from `key__index__subtype__1__first >= 1`
`key_index >= key__index__subtype__1__first + 1`
`(key_index - (key__index__subtype__1__first - 1)) mod 4 = 2`
show ?C2 by (simp add: sdiv_pos_pos, subst rw, subst div_truncate_plus,
simp_all)
qed
spark_end
(* BLAKE2S/FINALIZE *)
spark_open "blake2s/finalize"
spark_vc procedure_finalize_27
proof -
from `digest__index__subtype__1__first = 1`
`digest__index__subtype__1__last -
digest__index__subtype__1__first + 1
>= digest_length(context)`
`1 < digest_length(context)`
show ?thesis by simp
qed
spark_vc procedure_finalize_28
proof -
from `digest__index__subtype__1__first = 1`
`digest__index__subtype__1__last -
digest__index__subtype__1__first + 1
>= digest_length(context)`
`digest_length(context) >= 1`
`digest__index__subtype__1__first ~=
digest_length(context)`
show ?thesis by simp
qed
spark_vc procedure_finalize_29
proof -
from `digest__index__subtype__1__first = 1`
`digest__index__subtype__1__last -
digest__index__subtype__1__first + 1
>= digest_length(context)`
`digest_index < digest_length(context)`
show ?thesis by simp
qed
spark_vc procedure_finalize_35
proof -
from `digest_length(context) <= 32`
`digest_index + 1 ~= digest_length(context)`
`digest_index < digest_length(context)`
show ?thesis by simp
qed
spark_vc procedure_finalize_39
proof -
from `digest__index__subtype__1__first = 1`
`digest__index__subtype__1__last -
digest__index__subtype__1__first + 1
>= digest_length(context)`
`2 ~= digest_length(context) `
`1 < digest_length(context) `
show ?thesis by simp
qed
spark_vc procedure_finalize_40
proof -
from `digest__index__subtype__1__first = 1`
`digest__index__subtype__1__last -
digest__index__subtype__1__first + 1
>= digest_length(context)`
`digest_length(context) >= 1`
`digest__index__subtype__1__first
~= digest_length(context)`
`digest__index__subtype__1__first + 1
~= digest_length(context)`
show ?thesis by simp
qed
spark_vc procedure_finalize_41
proof -
from `digest__index__subtype__1__first = 1`
`digest__index__subtype__1__last -
digest__index__subtype__1__first + 1
>= digest_length(context)`
`digest_index + 1 ~=
digest_length(context)`
`digest_index < digest_length(context)`
show ?thesis by simp
qed
spark_vc procedure_finalize_47
proof -
from `digest_length(context) <= 32`
`digest_index + 1 ~= digest_length(context)`
`digest_index + 2 ~= digest_length(context)`
`digest_index < digest_length(context)`
show ?thesis by simp
qed
spark_vc procedure_finalize_51
proof -
from `digest__index__subtype__1__first = 1`
`digest__index__subtype__1__last -
digest__index__subtype__1__first + 1
>= digest_length(context)`
`2 ~= digest_length(context)`
`3 ~= digest_length(context)`
`1 < digest_length(context)`
show ?thesis by simp
qed
spark_status
spark_vc procedure_finalize_52
proof -
from `digest__index__subtype__1__first = 1`
`digest__index__subtype__1__last -
digest__index__subtype__1__first + 1
>= digest_length(context)`
`digest_length(context) >= 1`
`digest__index__subtype__1__first ~=
digest_length(context)`
`digest__index__subtype__1__first + 1 ~=
digest_length(context)`
`digest__index__subtype__1__first + 2 ~=
digest_length(context)`
show ?thesis by simp
qed
spark_vc procedure_finalize_53
proof -
from `digest__index__subtype__1__first = 1`
`digest__index__subtype__1__last -
digest__index__subtype__1__first + 1
>= digest_length(context)`
`digest_index + 1 ~= digest_length(context)`
`digest_index + 2 ~= digest_length(context)`
`digest_index < digest_length(context)`
show ?thesis by simp
qed
spark_vc procedure_finalize_59
proof -
from `digest_length(context) <= 32`
`digest_index + 1 ~= digest_length(context)`
`digest_index + 2 ~= digest_length(context)`
`digest_index + 3 ~= digest_length(context)`
`digest_index < digest_length(context)`
show ?thesis by simp
qed
spark_vc procedure_finalize_66
proof -
from `2 ~= digest_length(context)`
`3 ~= digest_length(context)`
`4 ~= digest_length(context)`
`1 < digest_length(context)`
show ?C1 by simp
from `digest__index__subtype__1__first = 1`
`digest__index__subtype__1__last -
digest__index__subtype__1__first + 1
>= digest_length(context)`
`5 <= digest_length(context)`
show ?C2 by simp
qed
spark_vc procedure_finalize_67
proof -
from `digest__index__subtype__1__first = 1`
`digest_length(context) >= 1`
`digest__index__subtype__1__first ~=
digest_length(context)`
`digest__index__subtype__1__first + 1 ~=
digest_length(context)`
`digest__index__subtype__1__first + 2 ~=
digest_length(context)`
`digest__index__subtype__1__first + 3 ~=
digest_length(context)`
show ?C1 by simp
from `digest__index__subtype__1__first = 1`
`digest__index__subtype__1__last -
digest__index__subtype__1__first + 1
>= digest_length(context)`
`digest__index__subtype__1__first + 4
<= digest_length(context)`
show ?C2 by simp
from `digest__index__subtype__1__first = 1`
show ?C3 by simp
from `digest__index__subtype__1__first = 1`
sdiv_pos_pos
show ?C4 by simp
qed
spark_vc procedure_finalize_68
proof -
from `digest_index + 1 ~= digest_length(context)`
`digest_index + 2 ~= digest_length(context)`
`digest_index + 3 ~= digest_length(context)`
`digest_index < digest_length(context)`
show ?C1 by simp
from `digest__index__subtype__1__first = 1`
`digest__index__subtype__1__last -
digest__index__subtype__1__first + 1
>= digest_length(context)`
`digest_index + 4 <= digest_length(context)`
show ?C2 by simp
from `(digest_index - 1) mod 4 = 0`
show ?C3 by presburger
from `digest__index__subtype__1__first = 1`
`digest_index > digest__index__subtype__1__first`
sdiv_pos_pos
show ?C4 by simp
qed
spark_end
(* END OF BLAKE2S PROOFS *)
end