From 2c057f60daf71daafe4e15bc4e9402a06feb4c98 Mon Sep 17 00:00:00 2001 From: ph4r05 Date: Thu, 22 Dec 2016 00:30:04 +0100 Subject: [PATCH] generating random data with TPM added generating with https://linux.die.net/man/3/tspi_tpm_getrandom --- pytss/__init__.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pytss/__init__.py b/pytss/__init__.py index eb75f22..1889773 100644 --- a/pytss/__init__.py +++ b/pytss/__init__.py @@ -474,6 +474,21 @@ def extend_pcr(self, pcr, data, event): tss_lib.Tspi_Context_FreeMemory(self.context, blob[0]) return ret + def generate_random_data(self, length): + """ + Generates random data in TPM of the given length in bytes. + + :param length: Length of data to generate in bytes + + :return: bytearray containing the random data + """ + blob = ffi.new('BYTE **') + tss_lib.Tspi_TPM_GetRandom(self.get_handle(), length, blob) + ret = bytearray(blob[0][0:length]) + tss_lib.Tspi_Context_FreeMemory(self.context, blob[0]) + return ret + + class TspiContext(): def __init__(self): self.context = ffi.new('TSS_HCONTEXT *')