Skip to content

Commit

Permalink
generating random data with TPM added
Browse files Browse the repository at this point in the history
  • Loading branch information
ph4r05 committed Dec 21, 2016
1 parent 6582bc6 commit 2c057f6
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pytss/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *')
Expand Down

0 comments on commit 2c057f6

Please sign in to comment.