(* 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.

Lemma test6: DRBG_check
"b512633f27fb182a076917e39888ba3ff35d23c3742eb8f3c635a044163768e0"%string
"e2c39b84629a3de5c301db5643af1c21"
"4038798b0b8bfc7be148adbdeacaf082155c46bbc86538d574aaeb0f187c52fc"%string
"e46a05a9268ecc00ecc3310947baa11d1ccd42cedd0ed80d78b6fb43bfd1b903"%string
""
[
("5464d1f719fff5cda06a0ee358b18b8a9d8dfa3525d461f343f1a3be5138fa9a"%string, "759926760ecbb5c000992227f1065c18cbff9a5aaec38911d6e7a399bab4783b"%string, ""%string);
("df2103bf3d5dd0d60870042d702478272caef5198ff71441a772d705f28ee760"%string, "cad9c856f921f6a248e0db4b3356e06e205fd9a15980030e1d32a303f4278329"%string, ""%string)
]
"fb931d0d0194a97b48d5d4c231fdad5c61aedf1c3a55ac24983ecbf38487b1c93396c6b86ff3920cfa8c77e0146de835ea5809676e702dee6a78100da9aa43d8ec0bf5720befa71f82193205ac2ea403e8d7e0e6270b366dc4200be26afd9f63b7e79286a35c688c57cbff55ac747d4c28bb80a2b2097b3b62ea439950d75dff"%string.