def get_tpm_rand_block(size=4096):
global warned
randpath = None
try:
#make a temp file for the output
randfd,randpath = tempfile.mkstemp()
command = "getrandom -size %d -out %s" % (size,randpath)
tpm_exec.run(command)
# read in the quote
f = open(randpath,"rb")
rand = f.read()
f.close()
os.close(randfd)
except Exception as e:
if not warned:
logger.warn("TPM randomness not available: %s"%e)
warned=True
return []
finally:
if randpath is not None:
os.remove(randpath)
return rand
评论列表
文章目录