Skip to content

Commit

Permalink
small chacha spec reorganization
Browse files Browse the repository at this point in the history
  • Loading branch information
palmskog committed Nov 28, 2024
1 parent 760b9c1 commit 4b0bde6
Showing 1 changed file with 24 additions and 24 deletions.
48 changes: 24 additions & 24 deletions examples/riscv/chacha/chacha_specScript.sml
Original file line number Diff line number Diff line change
Expand Up @@ -66,18 +66,6 @@ Definition chacha_line_alt:
m
End

Definition chacha_line_alt_word64:
chacha_line_alt_word64 (a:word64) (b:word64) (d:word64) (s:word32)
(m:word64 -> word64) =
let m = (a =+ (sw2sw: word32 -> word64) ((w2w (m a)) + (w2w (m b)))) m in
let m = (d =+
((sw2sw: word32 -> word64) ((w2w ((m a) ?? (m d))) <<~ s))
||
((sw2sw: word32 -> word64) ((w2w ((m a) ?? (m d))) >>>~ (32w - s)))
) m
in m
End

Theorem word32_le_31_eq:
!(w:word32). w <=+ 31w ==> 31w && w = w
Proof
Expand Down Expand Up @@ -111,18 +99,6 @@ Proof
rw [chacha_line_expand,chacha_line_alt]
QED

Theorem chacha_line_alt_word64_eq[local]:
!a b d s m x.
s <=+ 31w ==>
(w2w o (chacha_line (w2w a) (w2w b) (w2w d) s (\w. w2w (m (w2w w))) o w2w)) x =
chacha_line_alt a b d s m x
Proof
rw [chacha_line_expand,chacha_line_alt] >>
rw [combinTheory.APPLY_UPDATE_THM] >>
cheat
(*rw [sw2sw_w2w]*)
QED

(*
op quarter_round a b c d : shuffle =
line a b d 16 \oo
Expand Down Expand Up @@ -658,6 +634,30 @@ End

(* ----- *)

Definition chacha_line_alt_word64:
chacha_line_alt_word64 (a:word64) (b:word64) (d:word64) (s:word32)
(m:word64 -> word64) =
let m = (a =+ (sw2sw: word32 -> word64) ((w2w (m a)) + (w2w (m b)))) m in
let m = (d =+
((sw2sw: word32 -> word64) ((w2w ((m a) ?? (m d))) <<~ s))
||
((sw2sw: word32 -> word64) ((w2w ((m a) ?? (m d))) >>>~ (32w - s)))
) m
in m
End

Theorem chacha_line_alt_word64_eq[local]:
!a b d s m x.
s <=+ 31w ==>
(w2w o (chacha_line (w2w a) (w2w b) (w2w d) s (\w. w2w (m (w2w w))) o w2w)) x =
chacha_line_alt a b d s m x
Proof
rw [chacha_line_expand,chacha_line_alt] >>
rw [combinTheory.APPLY_UPDATE_THM] >>
cheat
(*rw [sw2sw_w2w]*)
QED

Definition bspec_chacha_quarterround_exp_1:
bspec_chacha_quarterround_exp_1 varname pre_1 pre_2 : bir_exp_t =
BExp_BinPred
Expand Down

0 comments on commit 4b0bde6

Please sign in to comment.