tpm_random.py 文件源码

python
阅读 32 收藏 0 点赞 0 评论 0

项目:python-keylime 作者: mit-ll 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号