Skip to content

Instantly share code, notes, and snippets.

@latsku
Created August 14, 2015 13:53
Show Gist options
  • Save latsku/65ba4a2cf1d397a373e9 to your computer and use it in GitHub Desktop.
Save latsku/65ba4a2cf1d397a373e9 to your computer and use it in GitHub Desktop.
TSS hashing on Python
import os
from ctypes import cdll, create_string_buffer
import binascii
import logging
logger = logging.getLogger()
TSS_HASH_SHA1 = 0x00000001
def main():
try:
if os.name == "posix":
tspi_lib = cdll.LoadLibrary("libtspi.so.1")
elif os.name == "nt":
tspi_lib = cdll.LoadLibrary("TSS.NET.dll")
except OSError, e:
logging.error('Error loading C library: \n%r' %
(e))
raise SystemExit(1)
str = "The quick brown fox jumps over the lazy dog"
digest = create_string_buffer(20)
result = tspi_lib.Trspi_Hash(TSS_HASH_SHA1, len(str), str, digest)
print('Hash=' + binascii.hexlify(digest.raw))
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment