Types

The types module contains types for each of the corresponding TPM types from the following TCG specifications:

The classes contained within can be initialized based on named argument value pairs or dictionaries of key-value objects where the keys are the names of the associated type.

exception tpm2_pytss.types.ParserAttributeError[source]

Exception ocurred when when parsing.

__str__()

Return str(self).

args
with_traceback()

Exception.with_traceback(tb) – set self.__traceback__ to tb and return self.

class tpm2_pytss.types.TPM2B_ATTEST(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_AUTH(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_CONTEXT_DATA(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_CONTEXT_SENSITIVE(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_CREATION_DATA(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_DATA(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_DIGEST(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_ECC_PARAMETER(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_ECC_POINT(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_ENCRYPTED_SECRET(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_EVENT(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_ID_OBJECT(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_IV(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_MAX_BUFFER(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_MAX_NV_BUFFER(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_NAME(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_NONCE(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_NV_PUBLIC(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

get_name()[source]

Get the TPM name of the NV public area.

This function requires a populated TPM2B_NV_PUBLIC and will NOT go to the TPM to retrieve the name, and instead calculates it manually.

Returns

Returns TPM2B_NAME.

Raises

ValueError – Unsupported name digest algorithm.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_OPERAND(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_PRIVATE(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_PRIVATE_KEY_RSA(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_PRIVATE_VENDOR_SPECIFIC(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_PUBLIC(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

classmethod from_pem(data, nameAlg=TPM2_ALG_SHA256, objectAttributes=TPMA_OBJECT_DECRYPT.__or__().__or__(), symmetric=None, scheme=None, password=None)[source]

Decode the public part from standard key encodings.

Currently supports PEM, DER and SSH encoded public keys.

Parameters
  • data (bytes) – The encoded public key.

  • nameAlg (TPM2_ALG, int) – The name algorithm for the public area, default is TPM2_ALG.SHA256.

  • objectAttributes (TPMA_OBJECT, int) – The object attributes for the public area, default is (TPMA_OBJECT.DECRYPT | TPMA_OBJECT.SIGN_ENCRYPT | TPMA_OBJECT.USERWITHAUTH).

  • symmetric (TPMT_SYM_DEF_OBJECT) – The symmetric definition to use for the public area, default is None.

  • scheme (TPMT_ASYM_SCHEME) – The signing/key exchange scheme to use for the public area, default is None.

  • password (bytes) – The password used to decrypt the key, default is None.

Returns

Returns a TPMT_PUBLIC instance.

Raises

ValueError – If key parameters are not supported.

Example

ecc_key_pem = open('path/to/myecckey.pem').read().encode()
TP2B_PUBLIC.from_pem(ecc_key_pem)
get_name()[source]

Get the TPM name of the public area.

This function requires a populated TPM2B_PUBLIC and will NOT go to the TPM to retrieve the name, and instead calculates it manually.

Returns

Returns TPM2B_NAME.

Raises

ValueError – Unsupported name digest algorithm.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod parse(alg='rsa', objectAttributes=TPMA_OBJECT_DECRYPT.__or__().__or__().__or__().__or__().__or__(), nameAlg='sha256', authPolicy=None)[source]

Builds a TPM2B_PUBLIC from a tpm2-tools like specifier strings.

This builds the TPM2B_PUBLIC structure which can be used in TPM2_Create and TPM2_CreatePrimary commands that map into the tpm2-tools project as tpm2 create and createprimary commandlets. Those commands take options: -G, -n, -L and -a option to specify the object to create. This method converts those options, but does not create the object like tpm2-tools.

Parameters
Returns

A populated TPMT_PUBLIC for use.

Raises

ValueError – If a string value is not of an expected format.

Examples

TPM2B_PUBLIC.parse(
    "ecc:ecdh-sha384",
    objectAttributes=TPMA_OBJECT.DEFAULT_TPM2_TOOLS_CREATEPRIMARY_ATTRS)

TPM2B_PUBLIC.parse(
    alg="xor:sha512",
    nameAlg="sha256",
    authPolicy=b'ŁsSò›c‡rßÓºowM–Q¯îKEO‚þVó^[‡')
to_der()[source]

Encode the public key as DER encoded ASN.1.

Returns

Returns the DER encoded key as bytes.

Raises

ValueError – If key type is not supported.

Example

with ESAPI() as e:
    # public parameter is index 1 in the return tuple
    pub = e.create_primary(None)[1]
    pub.to_der()
to_pem()[source]

Encode the public key as PEM encoded ASN.1.

Returns

Returns the PEM encoded key as bytes.

Raises

ValueError – If key type is not supported.

Example

with ESAPI() as e:
    # public parameter is index 1 in the return tuple
    pub = e.create_primary(None)[1]
    pub.to_pem()
to_ssh()[source]

Encode the public key in OpenSSH format

Returns

Returns the OpenSSH encoded key as bytes.

Raises

ValueError – If key type is not supported.

Example

with ESAPI() as e:
    # public parameter is index 1 in the return tuple
    pub = e.create_primary(None)[1]
    pub.to_ssh()
classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_PUBLIC_KEY_RSA(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_SENSITIVE(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

classmethod from_pem(data, password=None)[source]

Decode the private part from standard key encodings.

Currently supports PEM, DER and SSH encoded private keys.

Parameters
  • data (bytes) – The encoded key as bytes.

  • password (bytes, optional) – The password used to decrypt the key, default is None.

Returns

Returns an instance of TPM2B_SENSITIVE.

Raises

ValueError – If key parameters are not supported.

Example

rsa_private_key = open('path/to/my/rsaprivatekey.pem').read().encode()
TPM2B_SENSITIVE.from_pem(rsa_private_key)
classmethod keyedhash_from_secret(secret, nameAlg=TPM2_ALG_SHA256, objectAttributes=TPMA_OBJECT_DECRYPT.__or__().__or__(), scheme=None, seed=None)[source]

Generate the private and public part for a keyed hash object from a secret.

Parameters
  • secret (bytes) – The HMAC key / data to be sealed.

  • nameAlg (TPM2_ALG, int) – The name algorithm for the public part, default is TPM2_ALG.SHA256.

  • objectAttributes (TPMA_OBJECT, int) – The object attributes for the public area, default is (TPMA_OBJECT.DECRYPT | TPMA_OBJECT.SIGN_ENCRYPT | TPMA_OBJECT.USERWITHAUTH).

  • scheme (TPMT_KEYEDHASH_SCHEME) – The signing/key exchange scheme to use for the public area, default is None.

  • seed (bytes) – The obfuscate value, default is a randomized value.

Returns

A tuple of TPM2B_SENSITIVE and TPM2B_PUBLIC

Raises

ValueError – If key parameters are not supported.

Example

secret = b"secret key"
scheme = TPMT_KEYEDHASH_SCHEME(scheme=TPM2_ALG.HMAC)
scheme.details.hmac.hashAlg = TPM2_ALG.SHA256
(sens, pub) = TPM2B_SENSITIVE.keyedhash_from_secret(secret, scheme=scheme)
marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod symcipher_from_secret(secret, algorithm=TPM2_ALG_AES, mode=TPM2_ALG_CFB, nameAlg=TPM2_ALG_SHA256, objectAttributes=TPMA_OBJECT_DECRYPT.__or__().__or__(), seed=None)[source]

Generate the private and public part for a symcipher object from a secret.

Parameters
  • secret (bytes) – the symmetric key.

  • algorithm (TPM2_ALG, int) – The symmetric cipher algorithm to use, default is TPM2_ALG.AES.

  • mode (TPM2_ALG. int) – The symmetric mode to use, default is TPM2_ALG.CFB.

  • nameAlg (TPM2_ALG, int) – The name algorithm for the public part, default is TPM2_ALG.SHA256.

  • objectAttributes (TPMA_OBJECT, int) – The object attributes for the public area, default is (TPMA_OBJECT.DECRYPT | TPMA_OBJECT.SIGN_ENCRYPT | TPMA_OBJECT.USERWITHAUTH).

  • seed (bytes) – The obfuscate value, default is a randomized value.

Returns

A tuple of TPM2B_SENSITIVE and TPM2B_PUBLIC

Example

secret = b"ñ" * 32
sens, pub = TPM2B_SENSITIVE.symcipher_from_secret(secret)
to_der(public)[source]

Encode the key as DER encoded ASN.1.

public(TPMT_PUBLIC): The corresponding public key.

Returns

Returns the DER encoding as bytes.

Raises

ValueError – Unsupported key type.

Example

rsa_private_key = open('path/to/my/rsaprivatekey.pem').read().encode()
priv = TPM2B_SENSITIVE.from_pem(rsa_private_key)
pub = TPM2B_PUBLIC.from_pem(rsa_private_key)
priv.to_der(pub.publicArea)
to_pem(public, password=None)[source]

Encode the key as PEM encoded ASN.1.

Parameters
  • public (TPMT_PUBLIC) – The corresponding public key.

  • password (bytes) – An optional password for encrypting the PEM with.

Returns

Returns the PEM encoding as bytes.

Raises

ValueError – Unsupported key type.

Example

rsa_private_key = open('path/to/my/rsaprivatekey.pem').read().encode()
priv = TPM2B_SENSITIVE.from_pem(rsa_private_key)
pub = TPM2B_PUBLIC.from_pem(rsa_private_key)
priv.to_pem(pub.publicArea)
to_ssh(public, password=None)[source]

Encode the key as OPENSSH PEM format.

Parameters
  • public (TPMT_PUBLIC) – The corresponding public key.

  • password (bytes) – An optional password for encrypting the PEM with.

Returns

Returns the PEM OPENSSH encoding as bytes.

Raises

ValueError – Unsupported key type.

Example

rsa_private_key = open('path/to/my/rsaprivatekey.pem').read().encode()
priv = TPM2B_SENSITIVE.from_pem(rsa_private_key)
pub = TPM2B_PUBLIC.from_pem(rsa_private_key)
priv.to_ssh(pub.publicArea)
classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_SENSITIVE_CREATE(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_SENSITIVE_DATA(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_SIMPLE_OBJECT(_cdata=None, **kwargs)[source]

Abstract Base class for all TPM2B Simple Objects. A Simple object contains only a size and byte buffer fields. This is not suitable for direct instantiation.

__str__()[source]

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_SYM_KEY(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_TEMPLATE(_cdata=None, **kwargs)[source]
__str__()

Returns a hex string representation of the underlying buffer.

This is the same as:

bytes(tpm2b_type).hex()
Returns (str):

A hex encoded string of the buffer.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2B_TIMEOUT(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM2_HANDLE[source]

“A handle to a TPM address

class tpm2_pytss.types.TPML_AC_CAPABILITIES(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPML_ALG(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod parse(algorithms)[source]

Convert an comma separated list of algorithm friendly string names to a list of numeric constants.

Friendly algorithm names are the constants representing algorithms found in the TPM2_ALG class. The string identifiers are those understood by TPM2_ALG.parse.

Parameters

algorithms (str) – A comma separated list of algorithm friendly names. May be a list of one item with no comma.

Returns

A populated TPML_ALG

Raises

ValueError – Invalid algorithms list.

Example

TPML_ALG("aes")
TPML_ALG("aes,sha256")
classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPML_ALG_PROPERTY(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPML_CC(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPML_CCA(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPML_DIGEST(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPML_DIGEST_VALUES(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPML_ECC_CURVE(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPML_HANDLE(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPML_INTEL_PTT_PROPERTY(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPML_Iterator(tpml)[source]

Iterator class for iterating over TPML data types.

This class is used in enumerated for loops, such as: .. code-block:: python

for alg in TPML_ALG:

do_something(alg)

__str__()

Return str(self).

class tpm2_pytss.types.TPML_OBJECT(_cdata=None, **kwargs)[source]

Abstract Base class for all TPML Objects. A TPML object is an object that contains a list of objects. This is not suitable for direct instantiation.

__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPML_PCR_SELECTION(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

static parse(selections)[source]

Convert a PCR selection string into the TPML_PCR_SELECTION data structure.

PCR Bank Selection lists follow the below specification:

<BANK>:<PCR>[,<PCR>] or <BANK>:all

multiple banks may be separated by ‘+’.

For Example “sha1:3,4+sha256:all”, will select PCRs 3 and 4 from the SHA1 bank and PCRs 0 to 23 from the SHA256 bank.

Parameters

algorithms (str) – A comma separated list of algorithm friendly names. May be a list of one item with no comma.

Returns

A populated TPML_PCR_SELECTION

Raises

ValueError – Invalid algorithms list.

Example

TPML_PCR_SELECTION.parse("sha256:1,3,5,7")
TPML_PCR_SELECTION.parse("sha1:3,4+sha256:all")
classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPML_TAGGED_PCR_PROPERTY(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPML_TAGGED_TPM_PROPERTY(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_AC_OUTPUT(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_ALGORITHM_DESCRIPTION(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_ALGORITHM_DETAIL_ECC(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_ALG_PROPERTY(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_ASYM_PARMS(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_ATTEST(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_AUTH_COMMAND(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_AUTH_RESPONSE(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_CAPABILITY_DATA(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_CERTIFY_INFO(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_CLOCK_INFO(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_COMMAND_AUDIT_INFO(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_CONTEXT(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

classmethod from_tools(data)[source]

Unmarshal a tpm2-tools context blob.

Note

Currently only support key object contexts from tpm2-tools.

Parameters

data (bytes) – The bytes from a tpm2-tools context file.

Returns

Returns a TPMS_CONTEXT instance.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_CONTEXT_DATA(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_CREATION_DATA(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_CREATION_INFO(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_ECC_PARMS(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_ECC_POINT(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_EMPTY(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_ID_OBJECT(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_KEYEDHASH_PARMS(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_NV_CERTIFY_INFO(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_NV_PIN_COUNTER_PARAMETERS(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_NV_PUBLIC(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

get_name()[source]

Get the TPM name of the NV public area.

Returns

Returns TPM2B_NAME.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_PCR_SELECT(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_PCR_SELECTION(pcrs=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

static parse(selection)[source]

Given a PCR selection string populate a TPMS_PCR_SELECTION structure.

A PCR Bank selection lists:

<BANK>:<PCR>[,<PCR>] or <BANK>:all

For Example “sha1:3,4”, will select PCRs 3 and 4 from the SHA1 bank.

Parameters

selection (str) – A PCR selection string.

Returns

A populated TPMS_PCR_SELECTION

Raises

ValueError – Invalid PCR specification.

Example

TPMS_PCR_SELECTION.parse("sha256:1,3,5,7")
TPMS_PCR_SELECTION.parse("sha1:all")
classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_QUOTE_INFO(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_RSA_PARMS(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_SCHEME_ECDAA(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_SCHEME_HASH(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_SCHEME_XOR(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_SENSITIVE_CREATE(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_SESSION_AUDIT_INFO(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_SIGNATURE_ECC(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_SIGNATURE_RSA(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_SYMCIPHER_PARMS(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_TAGGED_PCR_SELECT(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_TAGGED_PROPERTY(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_TIME_ATTEST_INFO(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMS_TIME_INFO(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMT_ASYM_SCHEME(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMT_ECC_SCHEME(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMT_HA(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMT_KDF_SCHEME(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMT_KEYEDHASH_SCHEME(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMT_PUBLIC(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

classmethod from_pem(data, nameAlg=TPM2_ALG_SHA256, objectAttributes=TPMA_OBJECT_DECRYPT.__or__().__or__(), symmetric=None, scheme=None, password=None)[source]

Decode the public part from standard key encodings.

Currently supports PEM, DER and SSH encoded public keys.

Parameters
  • data (bytes) – The encoded public key.

  • nameAlg (TPM2_ALG, int) – The name algorithm for the public area, default is TPM2_ALG.SHA256.

  • objectAttributes (TPMA_OBJECT, int) – The object attributes for the public area, default is (TPMA_OBJECT.DECRYPT | TPMA_OBJECT.SIGN_ENCRYPT | TPMA_OBJECT.USERWITHAUTH).

  • symmetric (TPMT_SYM_DEF_OBJECT) – The symmetric definition to use for the public area, default is None.

  • scheme (TPMT_ASYM_SCHEME) – The signing/key exchange scheme to use for the public area, default is None.

  • password (bytes) – The password used to decrypt the key, default is None.

Returns

Returns a TPMT_PUBLIC instance.

Raises

ValueError – If key parameters are not supported.

Example

ecc_key_pem = open('path/to/myecckey.pem').read().encode()
TPMT_PUBLIC.from_pem(ecc_key_pem)
get_name()[source]

Get the TPM name of the public area.

This function requires a populated TPMT_PUBLIC and will NOT go to the TPM to retrieve the name, and instead calculates it manually.

Returns

Returns TPM2B_NAME.

Raises

ValueError – Unsupported name digest algorithm.

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod parse(alg='rsa', objectAttributes=TPMA_OBJECT_DECRYPT.__or__().__or__().__or__().__or__().__or__(), nameAlg='sha256', authPolicy=None)[source]

Builds a TPMT_PUBLIC from a tpm2-tools like specifier strings.

This builds the TPMT_PUBLIC structure which can be used in TPM2_Create and TPM2_CreatePrimary commands that map into the tpm2-tools project as tpm2 create and createprimary commandlets. Those commands take options: -G, -n, -L and -a option to specify the object to create. This method converts those options, but does not create the object like tpm2-tools.

Parameters
Returns

A populated TPMT_PUBLIC for use.

Raises

ValueError – If a string value is not of an expected format.

Examples

TPMT_PUBLIC.parse(
    "ecc:ecdh-sha384",
    objectAttributes=TPMA_OBJECT.DEFAULT_TPM2_TOOLS_CREATEPRIMARY_ATTRS)

TPMT_PUBLIC.parse(
    alg="xor:sha512",
    nameAlg="sha256",
    authPolicy=b'ŁsSò›c‡rßÓºowM–Q¯îKEO‚þVó^[‡')
to_der()[source]

Encode the public key as DER encoded ASN.1.

Returns

Returns the DER encoded key as bytes.

Raises

ValueError – If key type is not supported.

Example

with ESAPI() as e:
    # public parameter is index 1 in the return tuple
    pub = e.create_primary(None)[1]
    pub.publicArea.to_der()
to_pem()[source]

Encode the public key as PEM encoded ASN.1.

Returns

Returns the PEM encoded key as bytes.

Raises

ValueError – If key type is not supported.

Example

with ESAPI() as e:
    # public parameter is index 1 in the return tuple
    pub = e.create_primary(None)[1]
    pub.publicArea.to_pem()
to_ssh()[source]

Encode the public key in OpenSSH format

Returns

Returns the OpenSSH encoded key as bytes.

Raises

ValueError – If key type is not supported.

Example

with ESAPI() as e:
    # public parameter is index 1 in the return tuple
    pub = e.create_primary(None)[1]
    pub.publicArea.to_ssh()
classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMT_PUBLIC_PARMS(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMT_RSA_DECRYPT(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMT_RSA_SCHEME(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMT_SENSITIVE(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

classmethod from_pem(data, password=None)[source]

Decode the private part from standard key encodings.

Currently supports PEM, DER and SSH encoded private keys.

Parameters
  • data (bytes) – The encoded key as bytes.

  • password (bytes, optional) – The password used to decrypt the key, default is None.

Returns

Returns an instance of TPMT_SENSITIVE.

classmethod keyedhash_from_secret(secret, nameAlg=TPM2_ALG_SHA256, objectAttributes=TPMA_OBJECT_DECRYPT.__or__().__or__(), scheme=None, seed=None)[source]

Generate the private and public part for a keyed hash object from a secret.

Parameters
  • secret (bytes) – The HMAC key / data to be sealed.

  • nameAlg (int) – The name algorithm for the public part, default is TPM2_ALG.SHA256.

  • objectAttributes (int) – The object attributes for the public area, default is (TPMA_OBJECT.DECRYPT | TPMA_OBJECT.SIGN_ENCRYPT | TPMA_OBJECT.USERWITHAUTH).

  • scheme (TPMT_KEYEDHASH_SCHEME, optional) – The signing/key exchange scheme to use for the public area, default is None.

  • seed (bytes, optional) – The obfuscate value, default is a randomized value.

Returns

A tuple of of TPMT_SENSITIVE and TPMT_PUBLIC

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod symcipher_from_secret(secret, algorithm=TPM2_ALG_AES, mode=TPM2_ALG_CFB, nameAlg=TPM2_ALG_SHA256, objectAttributes=TPMA_OBJECT_DECRYPT.__or__().__or__(), seed=None)[source]

Generate the private and public part for a symcipher object from a secret.

Parameters
  • secret (bytes) – the symmetric key.

  • algorithm (int) – The symmetric cipher algorithm to use, default is TPM2_ALG.AES.

  • mode (int) – The symmetric mode to use, default is TPM2_ALG.CFB.

  • nameAlg (int) – The name algorithm for the public part, default is TPM2_ALG.SHA256.

  • objectAttributes (int) – The object attributes for the public area, default is (TPMA_OBJECT.DECRYPT | TPMA_OBJECT.SIGN_ENCRYPT | TPMA_OBJECT.USERWITHAUTH).

  • seed (bytes, optional) – The obfuscate value, default is a randomized value.

Returns

A tuple of TPMT_SENSITIVE and TPMT_PUBLIC

to_der(public)[source]

Encode the key as DER encoded ASN.1.

public(TPMT_PUBLIC): The corresponding public key.

Returns

Returns the DER encoding as bytes.

to_pem(public, password=None)[source]

Encode the key as PEM encoded ASN.1.

public(TPMT_PUBLIC): The corresponding public key. password(bytes): An optional password for encrypting the PEM with.

Returns

Returns the PEM encoding as bytes.

to_ssh(public, password=None)[source]

Encode the key as SSH format.

public(TPMT_PUBLIC): The corresponding public key. password(bytes): An optional password for encrypting the PEM with.

Returns

Returns the DER encoding as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMT_SIGNATURE(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

verify_signature(key, data)[source]

Verify a TPM generated signature against a key.

Parameters
  • key (TPMT_PUBLIC, TPM2B_PUBLIC or bytes) – The key to verify against, bytes for HMAC, the public part for asymmetric key.

  • data (bytes) – The signed data to verify.

Raises

InvalidSignature – when the signature doesn’t match the data.

class tpm2_pytss.types.TPMT_SIG_SCHEME(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMT_SYM_DEF(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMT_SYM_DEF_OBJECT(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMT_TK_AUTH(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMT_TK_CREATION(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMT_TK_HASHCHECK(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMT_TK_VERIFIED(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMU_ASYM_SCHEME(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMU_ATTEST(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMU_CAPABILITIES(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMU_HA(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMU_PUBLIC_ID(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMU_PUBLIC_PARMS(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMU_SCHEME_KEYEDHASH(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMU_SENSITIVE_COMPOSITE(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMU_SIGNATURE(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMU_SIG_SCHEME(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMU_SYM_KEY_BITS(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPMU_SYM_MODE(_cdata=None, **kwargs)[source]
__str__()

Return str(self).

marshal()

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.

class tpm2_pytss.types.TPM_OBJECT(_cdata=None, **kwargs)[source]

Abstract Base class for all TPM Objects. Not suitable for direct instantiation.

__str__()

Return str(self).

marshal()[source]

Marshal instance into bytes.

Returns

Returns the marshaled type as bytes.

classmethod unmarshal(buf)[source]

Unmarshal bytes into type instance.

Parameters

buf (bytes) – The bytes to be unmarshaled.

Returns

Returns an instance of the current type and the number of bytes consumed.