(* Lennart Beringer, June 2015*)
(*This is a formalization in Gallina of Dan Bernstein's document "Salsa20 specification" (version 2005.04.27), Sections 1 - 9.*)
Definition map4 {A B} (f:A -> B) a :=
match a with (a0, a1, a2, a3) => (f a0, f a1, f a2, f a3) end.
Definition bytelist2Z (l:list byte) : Z :=
match l with
[a; b; c; d] => Byte.unsigned d + Byte.unsigned c * 2^8 + Byte.unsigned b * 2^16 + Byte.unsigned a * 2^24
| _ => 0 end.
Definition hexstring_to_Z s := bytelist2Z (hexstring_to_bytelist s).
Goal Zmod (hexstring_to_Z "c0a8787e"%string +
hexstring_to_Z "9fd1161d"%string) (2^32)  =
hexstring_to_Z "60798e9b"%string.
reflexivity. Qed.
(*Explicit definition of sum following Bernstein's "Salsa20 specification" paper:*)
Definition sum (a b:int): int :=
Int.repr (Zmod (Int.unsigned a + Int.unsigned b) (2^32)).

Lemma sum_zero_r a: sum a Int.zero = a.