import os from hmac_drbg import HMAC_DRBG drbg = HMAC_DRBG (entropy=os.urandom (64)) while True: secret = drbg.generate (1) if secret is None: drbg.reseed (entropy=os.urandom (32)) secret = drbg.generate (1) secret = ord (secret) & 0xF print "Guess my lucky number (0 to 15):" guess = raw_input ('# ') if int (guess) == secret: print "You got it!" else: print "Nope, it was", secret
EntropyInput = read_entry (f, b'EntropyInput') Nonce = read_entry (f, b'Nonce') PersonalizationString = read_entry (f, b'PersonalizationString') EntropyInputReseed = read_entry (f, b'EntropyInputReseed') AdditionalInputReseed = read_entry (f, b'AdditionalInputReseed') AdditionalInput0 = read_entry (f, b'AdditionalInput') AdditionalInput1 = read_entry (f, b'AdditionalInput') ReturnedBits = read_entry (f, b'ReturnedBits') # This implementation does not support additional input if AdditionalInputReseed != b'' or AdditionalInput0 != b'' or AdditionalInput1 != b'': continue # Test drbg = HMAC_DRBG (entropy=(EntropyInput + Nonce), personalization_string=PersonalizationString) drbg.reseed (entropy=EntropyInputReseed) drbg.generate (len (ReturnedBits)) result = drbg.generate (len (ReturnedBits)) if result != ReturnedBits: print ("FAILURE") print ("EntropyInput = ", codecs.encode (EntropyInput, 'hex')) print ("Nonce = ", codecs.encode (Nonce, 'hex')) print ("PersonalizationString = ", codecs.encode (PersonalizationString, 'hex')) print ("EntropyInputReseed = ", codecs.encode (EntropyInputReseed, 'hex')) print ("AdditionalInputReseed = ", codecs.encode (AdditionalInputReseed, 'hex')) print ("AdditionalInput = ", codecs.encode (AdditionalInput0, 'hex')) print ("AdditionalInput = ", codecs.encode (AdditionalInput1, 'hex')) print ("ReturnedBits = ", codecs.encode (ReturnedBits, 'hex')) sys.exit (-1)
from __future__ import print_function import os from hmac_drbg import HMAC_DRBG try: input = raw_input except NameError: pass drbg = HMAC_DRBG (entropy=os.urandom (64)) while True: secret = drbg.generate (1) if secret is None: drbg.reseed (entropy=os.urandom (32)) secret = drbg.generate (1) secret = ord (secret) & 0xF print ("Guess my lucky number (0 to 15):") guess = input ('# ') if int (guess) == secret: print ("You got it!") else: print ("Nope, it was", secret)
Nonce = read_entry(f, b'Nonce') PersonalizationString = read_entry(f, b'PersonalizationString') EntropyInputReseed = read_entry(f, b'EntropyInputReseed') AdditionalInputReseed = read_entry(f, b'AdditionalInputReseed') AdditionalInput0 = read_entry(f, b'AdditionalInput') AdditionalInput1 = read_entry(f, b'AdditionalInput') ReturnedBits = read_entry(f, b'ReturnedBits') # This implementation does not support additional input if AdditionalInputReseed != b'' or AdditionalInput0 != b'' or AdditionalInput1 != b'': continue # Test drbg = HMAC_DRBG(entropy=(EntropyInput + Nonce), personalization_string=PersonalizationString) drbg.reseed(entropy=EntropyInputReseed) drbg.generate(len(ReturnedBits)) result = drbg.generate(len(ReturnedBits)) if result != ReturnedBits: print("FAILURE") print("EntropyInput = ", codecs.encode(EntropyInput, 'hex')) print("Nonce = ", codecs.encode(Nonce, 'hex')) print("PersonalizationString = ", codecs.encode(PersonalizationString, 'hex')) print("EntropyInputReseed = ", codecs.encode(EntropyInputReseed, 'hex')) print("AdditionalInputReseed = ", codecs.encode(AdditionalInputReseed, 'hex')) print("AdditionalInput = ", codecs.encode(AdditionalInput0, 'hex')) print("AdditionalInput = ", codecs.encode(AdditionalInput1, 'hex'))