Definition Instantiate (entropy nonce pers_string: string) : DRBG_functions.DRBG_working_state :=
HMAC256_DRBG_instantiate_algorithm (hexstring_to_Zlist entropy)
(hexstring_to_Zlist nonce)
(hexstring_to_Zlist pers_string)
0 (*sec_strength -- ignored by HMAC256_DRBG_instantiate_algorithm*).
Definition reseedInterval:Z := 100000.
Definition Generate (WS: DRBG_functions.DRBG_working_state) (addInput:list Z): DRBG_functions.DRBG_generate_algorithm_result :=
HMAC256_DRBG_generate_algorithm reseedInterval
WS
128 (*number of bytes: 1024bits*)
addInput.
Definition CheckWS (WS:DRBG_functions.DRBG_working_state)
(V K: string) (rc:Z):=
match WS with (value, key, reseedcounter) =>
listZ_eq (hexstring_to_Zlist V) value &&
listZ_eq (hexstring_to_Zlist K) key &&
zeq reseedcounter rc = true
end.
(*no personalization string, no additional input*)
Definition Check_A (entropy nonce Value0 Key0 Value1 Key1 Bits Value2 Key2: string) :=
let ws0 := Instantiate entropy nonce ""
in match Generate ws0 nil with
DRBG_functions.generate_algorithm_success Bits1 ws1 =>
match Generate ws1 nil with
DRBG_functions.generate_algorithm_success Bits2 ws2 =>
CheckWS ws0 Value0 Key0 1 /\ CheckWS ws1 Value1 Key1 2 /\
CheckWS ws2 Value2 Key2 3 /\ Bits2 = hexstring_to_Zlist Bits
| err => False
end
| err => False
end.
(*no personalization string, but additional input*)
Definition Check_B (entropy nonce Value0 Key0 addInput1 Value1 Key1 addInput2 Bits Value2 Key2: string) :=
let ws0 := Instantiate entropy nonce ""
in match Generate ws0 (hexstring_to_Zlist addInput1) with
DRBG_functions.generate_algorithm_success Bits1 ws1 =>
match Generate ws1 (hexstring_to_Zlist addInput2) with
DRBG_functions.generate_algorithm_success Bits2 ws2 =>
CheckWS ws0 Value0 Key0 1 /\ CheckWS ws1 Value1 Key1 2 /\
CheckWS ws2 Value2 Key2 3 /\ Bits2 = hexstring_to_Zlist Bits
| err => False
end
| err => False
end.
(*personalization string, no additional input*)
Definition Check_C (entropy nonce pers Value0 Key0 Value1 Key1 Bits Value2 Key2: string) :=
let ws0 := Instantiate entropy nonce pers
in match Generate ws0 nil with
DRBG_functions.generate_algorithm_success Bits1 ws1 =>
match Generate ws1 nil with
DRBG_functions.generate_algorithm_success Bits2 ws2 =>
CheckWS ws0 Value0 Key0 1 /\ CheckWS ws1 Value1 Key1 2 /\
CheckWS ws2 Value2 Key2 3 /\ Bits2 = hexstring_to_Zlist Bits
| err => False
end
| err => False
end.
(*personalization string, additional input*)
Definition Check_D (entropy nonce pers Value0 Key0 addInput1 Value1 Key1 addInput2 Bits Value2 Key2: string) :=
let ws0 := Instantiate entropy nonce pers
in match Generate ws0 (hexstring_to_Zlist addInput1) with
DRBG_functions.generate_algorithm_success Bits1 ws1 =>
match Generate ws1 (hexstring_to_Zlist addInput2) with
DRBG_functions.generate_algorithm_success Bits2 ws2 =>
CheckWS ws0 Value0 Key0 1 /\ CheckWS ws1 Value1 Key1 2 /\
CheckWS ws2 Value2 Key2 3 /\ Bits2 = hexstring_to_Zlist Bits
| err => False
end
| err => False
end.
Module TestSection8424_8685.
(*Relevant Section of HMAC_DRBG.txt: lines 8424 -- 8685 [SHA-256] [PredictionResistance = False] [EntropyInputLen = 256] [NonceLen = 128] [PersonalizationStringLen = 0] [AdditionalInputLen = 0] [ReturnedBitsLen = 1024]*)
Definition Inst0: DRBG_functions.DRBG_working_state :=
Instantiate "ca851911349384bffe89de1cbdc46e6831e44d34a4fb935ee285dd14b71a7488"
"659ba96c601dc69fc902940805ec0ca8" "".
Definition Gen0_1: DRBG_functions.DRBG_generate_algorithm_result := Generate Inst0 nil.

Lemma Intantiate0:
CheckWS Inst0
"e75855f93b971ac468d200992e211960202d53cf08852ef86772d6490bfb53f9"
"302a4aba78412ab36940f4be7b940a0c728542b8b81d95b801a57b3797f9dd6e" 1.