(* Require Import DRBG_state_handle. Require Import DRBG_generate_function. Require Import DRBG_instantiate_function. Require Import DRBG_reseed_function.*)
Definition stream_dummy (result: string) (n: nat) : option bool :=
let hex := bytesToBits (hexstring_to_Zlist result) in
if nth_ok n hex false then Some (nth n hex false)
else None.
Definition get_nonce_dummy (result: string) (_: unit) := hexstring_to_Zlist result.
Definition noop_reseed_function (s: ENTROPY.stream) (x: DRBG_state_handle) (_: bool) (_: list Z) := ENTROPY.success x s.
Fixpoint DRBG_generate_check (state_handle: DRBG_state_handle) (internal_states: list (string * string * string)) (returned_bits: string) :=
let test_HMAC256_DRBG_generate_function := HMAC256_DRBG_generate_function noop_reseed_function 1024 128 128 in
match internal_states with
| [] => True
| (key, v, additional_input)::[] =>
let key := hexstring_to_Zlist key in
let value := hexstring_to_Zlist v in
let additional_input := hexstring_to_Zlist additional_input in
let returned_bits := hexstring_to_Zlist returned_bits in
match test_HMAC256_DRBG_generate_function (stream_dummy "") state_handle 128 256 false additional_input with
| ENTROPY.success (returned_bits', ((value', key', _), _, _)) _ => listZ_eq value value' = true /\ listZ_eq key key' = true /\ listZ_eq returned_bits returned_bits' = true
| ENTROPY.error _ _ => False
end
| (key, v, additional_input)::tl =>
let key := hexstring_to_Zlist key in
let value := hexstring_to_Zlist v in
let additional_input := hexstring_to_Zlist additional_input in
match test_HMAC256_DRBG_generate_function (stream_dummy "") state_handle 128 256 false additional_input with
| ENTROPY.success (_, ((value', key', x), y, z)) _ => listZ_eq value value' = true /\ listZ_eq key key' = true /\ DRBG_generate_check ((value', key', x), y, z) tl returned_bits
| ENTROPY.error _ _ => False
end
end.
Definition DRBG_check (entropy_input nonce key value personalization_string: string) (internal_states: list (string * string * string)) (returned_bits: string) :=
let key := hexstring_to_Zlist key in
let value := hexstring_to_Zlist value in
let personalization_string := hexstring_to_Zlist personalization_string in
match HMAC256_DRBG_instantiate_function 32 32 (get_nonce_dummy nonce) 256 256 false (stream_dummy entropy_input) 256 false personalization_string with
| ENTROPY.success ((value', key', x), y, z) _ => listZ_eq value value' = true /\ listZ_eq key key' = true /\ DRBG_generate_check ((value', key', x), y, z) internal_states returned_bits
| _ => False
end.
vm_compute. repeat (split;auto). Qed.
vm_compute. repeat (split;auto). Qed.
vm_compute. repeat (split;auto). Qed.
vm_compute. repeat (split;auto). Qed.
vm_compute. repeat (split;auto). Qed.

Lemma test5: DRBG_check
"4b222718f56a3260b3c2625a4cf80950b7d6c1250f170bd5c28b118abdf23b2f"%string
"7aed52d0016fcaef0b6492bc40bbe0e9"
"f4157eb3844c88ea985e1236683431b882b70b63db891750ab3f41b4e02819f6"%string
"b52d87fcf3249f61e9c73af4c3e0c949579aa580dd7271399b22490671a49792"%string
""
[
("f247aad1bbc398152cd0d6c9f84c0e7c8b98289ced8768bf0708efc0a90ab10f"%string, "f55a1cb5c058c5c6650e05018a7d9ea5e5cc427d1af9ca89ccf5ef59852ece80"%string, ""%string);
("4bf638e7f1e0c50014336ea17dc5f7b83ced0b780fba1c88abb5025a8bec6f28"%string, "dec827fc18d3c9691663d4bb6dd4a5202b6432549976e374ab33f4d8d9321e04"%string, ""%string)
]
"a6da029b3665cd39fd50a54c553f99fed3626f4902ffe322dc51f0670dfe8742ed48415cf04bbad5ed3b23b18b7892d170a7dcf3ef8052d5717cb0c1a8b3010d9a9ea5de70ae5356249c0e098946030c46d9d3d209864539444374d8fbcae068e1d6548fa59e6562e6b2d1acbda8da0318c23752ebc9be0c1c1c5b3cf66dd967"%string.