(*We're using sum in the following because it appears to compute more nicely.*)
(*hexstring_to_int*)
Definition x2i s : int := Int.repr (hexstring_to_Z s).
Goal sum (x2i "c0a8787e"%string)
(x2i "9fd1161d"%string) =
x2i "60798e9b"%string.
reflexivity. Qed.
Goal Int.xor (x2i "c0a8787e"%string)
(x2i "9fd1161d"%string) =
x2i "5f796e63"%string.
reflexivity. Qed.
Definition QuadWord:Type := (int * int * int * int)%type.
Definition quarterround (y:QuadWord): QuadWord :=
match y with (y0, y1, y2, y3) =>
let z1 := Int.xor y1 (Int.rol (sum y0 y3) (Int.repr 7)) in
let z2 := Int.xor y2 (Int.rol (sum y0 z1) (Int.repr 9)) in
let z3 := Int.xor y3 (Int.rol (sum z1 z2) (Int.repr 13)) in
let z0 := Int.xor y0 (Int.rol (sum z2 z3) (Int.repr 18))
in (z0, z1, z2, z3)
end.
Definition quarterround_old (y:QuadWord): QuadWord :=
match y with (y0, y1, y2, y3) =>
let z1 := Int.xor y1 (Int.rol (sum y0 y3) (Int.repr 7)) in
let z2 := Int.xor y2 (Int.rol (sum z1 y0) (Int.repr 9)) in
let z3 := Int.xor y3 (Int.rol (sum z2 z1) (Int.repr 13)) in
let z0 := Int.xor y0 (Int.rol (sum z3 z2) (Int.repr 18))
in (z0, z1, z2, z3)
end.

Lemma QR y: quarterround y = quarterround_old y.
destruct y as [[[y0 y1] y2] y3]. simpl. repeat rewrite sum_add.