(*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.
vm_compute. repeat (split;auto). Qed.

Lemma test_with_additional_input_and_personalization0: DRBG_check
"cdb0d9117cc6dbc9ef9dcb06a97579841d72dc18b2d46a1cb61e314012bdf416"
"d0c0d01d156016d0eb6b7e9c7c3c8da8"
"108a7674f3348216c91f5745dd87a919f552fc44373b84ad4b3b843a26b574cb"
"6c02577c505aed360be7b1cecb61068d8765be1391bacb10f4180d91bd3915db"
"6f0fb9eab3f9ea7ab0a719bfa879bf0aaed683307fda0c6d73ce018b6e34faaa"
"8ec6f7d5a8e2e88f43986f70b86e050d07c84b931bcf18e601c5a3eee3064c82"
"1ab4ca9014fa98a55938316de8ba5a68c629b0741bdd058c4d70c91cda5099b3"
"e57f901d4bff2909f09467003096edfdb46c89af6bd82e904d11b6753d645c90"
"21a645aeca821899e7e733a10f64565deee5ced3cd5c0356b66c76dc8a906e69"
[
("648f92d385c3fbf61526deef48ca5ca4dfe4646d82fe8e73bc1705824e181dc9"%string, "490c0b7786c80f16ad5ee1cc0efd29618968dce14cccebecec8964ea8a41b439"%string, "16e2d0721b58d839a122852abd3bf2c942a31c84d82fca74211871880d7162ff"%string);
("db4853ca51700d43c5b6d63eb6cd20ea2dbe3dff512f2dc9531b5b3d9120121c"%string, "47390036d5cb308cf9592fdfe95bf19b8ed1a3db88ed8c3b2b2d77540dfb5470"%string, "53686f042a7b087d5d2eca0d2a96de131f275ed7151189f7ca52deaa78b79fb2"%string)
]
"dda04a2ca7b8147af1548f5d086591ca4fd951a345ce52b3cd49d47e84aa31a183e31fbc42a1ff1d95afec7143c8008c97bc2a9c091df0a763848391f68cb4a366ad89857ac725a53b303ddea767be8dc5f605b1b95f6d24c9f06be65a973a089320b3cc42569dcfd4b92b62a993785b0301b3fc452445656fce22664827b88f".