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

Lemma test_with_personalization_and_additional0: DRBG_check
"5d3286bc53a258a53ba781e2c4dcd79a790e43bbe0e89fb3eed39086be34174b"%string
"c5422294b7318952ace7055ab7570abf"
"87ce5b45d0964e20e5e56418ae1de8b6b5fa6cdf4ff0efe5ab4444bce5658b99"%string
"2ccbf4b25c4b263d59b14080c83492b05769b583adf37c57b7eb59ab07bb4d40"%string
"2dba094d008e150d51c4135bb2f03dcde9cbf3468a12908a1b025c120c985b9d"
[
("c60114af6165b77a36dbab54b96c21bae4a3aa329782f4b850f423eb3b760483"%string, "09a7df20d9f87656efa075fae3f8db432904bbd3165b125b1a688a8b5c4de88f"%string, "793a7ef8f6f0482beac542bb785c10f8b7b406a4de92667ab168ecc2cf7573c6"%string);
("ef3855c4da0eb30c90a935c98006bac71059d1a4884bc7e63f28fe56df4e92a6"%string, "7925c738fb6e7f7c7e147cb3b8b306b485a545ae63dc878cc49dd93e86dbed9b"%string, "2238cdb4e23d629fe0c2a83dd8d5144ce1a6229ef41dabe2a99ff722e510b530"%string)
]
"d04678198ae7e1aeb435b45291458ffde0891560748b43330eaf866b5a6385e74c6fa5a5a44bdb284d436e98d244018d6acedcdfa2e9f499d8089e4db86ae89a6ab2d19cb705e2f048f97fb597f04106a1fa6a1416ad3d859118e079a0c319eb95686f4cbcce3b5101c7a0b010ef029c4ef6d06cdfac97efb9773891688c37cf"%string.