(*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_reseed_check (state_handle: DRBG_state_handle) (entropy_input_reseed additional_input_reseed key_reseed value_reseed: string) (internal_states: list (string * string * string)) (returned_bits: string) :=
let key := hexstring_to_Zlist key_reseed in
let value := hexstring_to_Zlist value_reseed in
match HMAC256_DRBG_reseed_function 32 32 256 (stream_dummy entropy_input_reseed) state_handle false (hexstring_to_Zlist additional_input_reseed) 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.
Definition DRBG_check (entropy_input nonce key value personalization_string: string) (entropy_input_reseed additional_input_reseed key_reseed value_reseed: 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_reseed_check ((value', key', x), y, z) entropy_input_reseed additional_input_reseed key_reseed value_reseed internal_states returned_bits
| _ => False
end.
vm_compute. repeat (split;auto). Qed.

Lemma test_with_additional_input0: DRBG_check
"05ac9fc4c62a02e3f90840da5616218c6de5743d66b8e0fbf833759c5928b53d"
"2b89a17904922ed8f017a63044848545"
"8d3006bd33b7d8b935a8484b786850f107b731a7efc51521848b875c2214d154"
"eaa29892ee1e46198ea68c07588ac12641fc901e484eda321c2f26a9ff328e3d"
""
"2791126b8b52ee1fd9392a0a13e0083bed4186dc649b739607ac70ec8dcecf9b"
"43bac13bae715092cf7eb280a2e10a962faf7233c41412f69bc74a35a584e54c"
"3138df070c49f48b080004df669f386676b4cb92b40de4d021b2a9e4451e5013"
"25d3b766cd9f8ad5c45efd7fa01cc08dbce8d0d3792ec2b59bfead7bce39ed01"
[
("cac850b111de755bb8a5ed1ebc052ed53ab1ff1b9d0fab2946a3728c7e9f43e4"%string, "06624fa590e1d63397b13a0e69081274434f793fdfc1e6298a7373834024da46"%string, "3f2fed4b68d506ecefa21f3f5bb907beb0f17dbc30f6ffbba5e5861408c53a1e"%string);
("b15ae269570790a8c6a81c5be7aef33f645abb161d218761ff8739cb7997eed8"%string, "92971e96fc46608d4343821491990915cdb957ae983ab6cdab84fd094bce1380"%string, "529030df50f410985fde068df82b935ec23d839cb4b269414c0ede6cffea5b68"%string)
]
"02ddff5173da2fcffa10215b030d660d61179e61ecc22609b1151a75f1cbcbb4363c3a89299b4b63aca5e581e73c860491010aa35de3337cc6c09ebec8c91a6287586f3a74d9694b462d2720ea2e11bbd02af33adefb4a16e6b370fa0effd57d607547bdcfbb7831f54de7073ad2a7da987a0016a82fa958779a168674b56524".