tpm2-tss  3.2.0
TPM Software stack 2.0 TCG spec compliant implementation
Internal Cryptographic Backend

Functions

TSS2_RC iesys_crypto_hash_get_digest_size (TPM2_ALG_ID hashAlg, size_t *size)
 
TSS2_RC iesys_cryptossl_hash_start (IESYS_CRYPTO_CONTEXT_BLOB **context, TPM2_ALG_ID hashAlg)
 
TSS2_RC iesys_cryptossl_hash_update (IESYS_CRYPTO_CONTEXT_BLOB *context, const uint8_t *buffer, size_t size)
 
TSS2_RC iesys_cryptossl_hash_update2b (IESYS_CRYPTO_CONTEXT_BLOB *context, TPM2B *b)
 
TSS2_RC iesys_cryptossl_hash_finish (IESYS_CRYPTO_CONTEXT_BLOB **context, uint8_t *buffer, size_t *size)
 
TSS2_RC iesys_cryptossl_hash_finish2b (IESYS_CRYPTO_CONTEXT_BLOB **context, TPM2B *b)
 
TSS2_RC iesys_cryptossl_hmac_start (IESYS_CRYPTO_CONTEXT_BLOB **context, TPM2_ALG_ID hashAlg, const uint8_t *key, size_t size)
 
TSS2_RC iesys_cryptossl_hmac_start2b (IESYS_CRYPTO_CONTEXT_BLOB **context, TPM2_ALG_ID hmacAlg, TPM2B *b)
 
TSS2_RC iesys_cryptossl_hmac_update (IESYS_CRYPTO_CONTEXT_BLOB *context, const uint8_t *buffer, size_t size)
 
TSS2_RC iesys_cryptossl_hmac_update2b (IESYS_CRYPTO_CONTEXT_BLOB *context, TPM2B *b)
 
TSS2_RC iesys_cryptossl_hmac_finish (IESYS_CRYPTO_CONTEXT_BLOB **context, uint8_t *buffer, size_t *size)
 
TSS2_RC iesys_cryptossl_hmac_finish2b (IESYS_CRYPTO_CONTEXT_BLOB **context, TPM2B *hmac)
 
void iesys_cryptossl_hmac_abort (IESYS_CRYPTO_CONTEXT_BLOB **context)
 
TSS2_RC iesys_crypto_pHash (TPM2_ALG_ID alg, const uint8_t rcBuffer[4], const uint8_t ccBuffer[4], const TPM2B_NAME *name1, const TPM2B_NAME *name2, const TPM2B_NAME *name3, const uint8_t *pBuffer, size_t pBuffer_size, uint8_t *pHash, size_t *pHash_size)
 
TSS2_RC iesys_crypto_authHmac (TPM2_ALG_ID alg, uint8_t *hmacKey, size_t hmacKeySize, const uint8_t *pHash, size_t pHash_size, const TPM2B_NONCE *nonceNewer, const TPM2B_NONCE *nonceOlder, const TPM2B_NONCE *nonceDecrypt, const TPM2B_NONCE *nonceEncrypt, TPMA_SESSION sessionAttributes, TPM2B_AUTH *hmac)
 
TSS2_RC iesys_cryptossl_random2b (TPM2B_NONCE *nonce, size_t num_bytes)
 
TSS2_RC iesys_cryptossl_pk_encrypt (TPM2B_PUBLIC *pub_tpm_key, size_t in_size, BYTE *in_buffer, size_t max_out_size, BYTE *out_buffer, size_t *out_size, const char *label)
 
TSS2_RC iesys_crypto_KDFaHmac (TPM2_ALG_ID alg, uint8_t *hmacKey, size_t hmacKeySize, uint32_t counter, const char *label, TPM2B_NONCE *contextU, TPM2B_NONCE *contextV, uint32_t bitlength, uint8_t *hmac, size_t *hmacSize)
 
TSS2_RC iesys_crypto_KDFa (TPM2_ALG_ID hashAlg, uint8_t *hmacKey, size_t hmacKeySize, const char *label, TPM2B_NONCE *contextU, TPM2B_NONCE *contextV, uint32_t bitLength, uint32_t *counterInOut, BYTE *outKey, BOOL use_digest_size)
 
TSS2_RC iesys_crypto_KDFe (TPM2_ALG_ID hashAlg, TPM2B_ECC_PARAMETER *Z, const char *label, TPM2B_ECC_PARAMETER *partyUInfo, TPM2B_ECC_PARAMETER *partyVInfo, UINT32 bit_size, BYTE *key)
 
TSS2_RC iesys_xor_parameter_obfuscation (TPM2_ALG_ID hash_alg, uint8_t *key, size_t key_size, TPM2B_NONCE *contextU, TPM2B_NONCE *contextV, BYTE *data, size_t data_size)
 
TSS2_RC iesys_cryptossl_get_ecdh_point (TPM2B_PUBLIC *key, size_t max_out_size, TPM2B_ECC_PARAMETER *Z, TPMS_ECC_POINT *Q, BYTE *out_buffer, size_t *out_size)
 

Detailed Description

The types and functions used internally by ESAPI for cryptographic operations. Multiple implementations of these functions may exist for different cryptographic backends.

Function Documentation

◆ iesys_crypto_authHmac()

TSS2_RC iesys_crypto_authHmac ( TPM2_ALG_ID  alg,
uint8_t *  hmacKey,
size_t  hmacKeySize,
const uint8_t *  pHash,
size_t  pHash_size,
const TPM2B_NONCE *  nonceNewer,
const TPM2B_NONCE *  nonceOlder,
const TPM2B_NONCE *  nonceDecrypt,
const TPM2B_NONCE *  nonceEncrypt,
TPMA_SESSION  sessionAttributes,
TPM2B_AUTH *  hmac 
)

Compute the HMAC for authorization.

Based on the session nonces, caller nonce, TPM nonce, if used encryption and decryption nonce, the command parameter hash, and the session attributes the HMAC used for authorization is computed.

Parameters
[in]algThe hash algorithm used for HMAC computation.
[in]hmacKeyThe HMAC key byte buffer.
[in]hmacKeySizeThe size of the HMAC key byte buffer.
[in]pHashThe command parameter hash byte buffer.
[in]pHash_sizeThe size of the command parameter hash byte buffer.
[in]nonceNewerThe TPM nonce.
[in]nonceOlderThe caller nonce.
[in]nonceDecryptThe decrypt nonce (NULL if not used).
[in]nonceEncryptThe encrypt nonce (NULL if not used).
[in]sessionAttributesThe attributes used for the current authentication.
[out]hmacThe computed HMAC.
Return values
TSS2_RC_SUCCESSon success
TSS2_ESYS_RC_BAD_REFERENCEIf a pointer is invalid.

◆ iesys_crypto_hash_get_digest_size()

TSS2_RC iesys_crypto_hash_get_digest_size ( TPM2_ALG_ID  hashAlg,
size_t *  size 
)

Provide the digest size for a given hash algorithm.

This function provides the size of the digest for a given hash algorithm.

Parameters
[in]hashAlgThe hash algorithm to get the size for.
[out]sizeThe side of a digest of the hash algorithm.
Return values
TSS2_RC_SUCCESSon success.
TSS2_ESYS_RC_BAD_VALUEif hashAlg is unknown or unsupported.

◆ iesys_crypto_KDFa()

TSS2_RC iesys_crypto_KDFa ( TPM2_ALG_ID  hashAlg,
uint8_t *  hmacKey,
size_t  hmacKeySize,
const char *  label,
TPM2B_NONCE *  contextU,
TPM2B_NONCE *  contextV,
uint32_t  bitLength,
uint32_t *  counterInOut,
BYTE *  outKey,
BOOL  use_digest_size 
)

KDFa Key derivation.

Except of ECDH this function is used for key derivation.

Parameters
[in]hashAlgThe hash algorithm to use.
[in]hmacKeyThe hmacKey used in KDFa.
[in]hmacKeySizeThe size of the HMAC key.
[in]labelIndicates the use of the produced key.
[in]contextU,contextVare used for construction of a binary string containing information related to the derived key.
[in]bitLengthThe size of generated key in bits.
[in,out]counterInOutCounter for the KDFa iterations. If set, the value will be used for the firt iteration step. The final counter value will be written to counterInOut.
[out]outKeyByte buffer for the derived key (caller-allocated).
[in]use_digest_sizeIndicate whether the digest size of hashAlg is used as size of the generated key or the bitLength parameter is used.
Return values
TSS2_RC_SUCCESSon success.
TSS2_ESYS_RC_BAD_VALUEif hashAlg is unknown or unsupported.

◆ iesys_crypto_KDFaHmac()

TSS2_RC iesys_crypto_KDFaHmac ( TPM2_ALG_ID  alg,
uint8_t *  hmacKey,
size_t  hmacKeySize,
uint32_t  counter,
const char *  label,
TPM2B_NONCE *  contextU,
TPM2B_NONCE *  contextV,
uint32_t  bitlength,
uint8_t *  hmac,
size_t *  hmacSize 
)

HMAC computation for inner loop of KDFa key derivation.

Except of ECDH this function is used for key derivation.

Parameters
[in]algThe algorithm used for the HMAC.
[in]hmacKeyThe hmacKey used in KDFa.
[in]hmacKeySizeThe size of the HMAC key.
[in]counterThe curren iteration step.
[in]labelIndicates the use of the produced key.
[in]contextU,contextVare used for construction of a binary string containing information related to the derived key.
[in]bitlengthThe size of the generated key in bits.
[out]hmacByte buffer for the generated HMAC key (caller-allocated).
[out]hmacSizeSize of the generated HMAC key.
Return values
TSS2_RC_SUCCESSon success.
TSS2_ESYS_RC_BAD_REFERENCEfor invalid parameters.

◆ iesys_crypto_KDFe()

TSS2_RC iesys_crypto_KDFe ( TPM2_ALG_ID  hashAlg,
TPM2B_ECC_PARAMETER *  Z,
const char *  label,
TPM2B_ECC_PARAMETER *  partyUInfo,
TPM2B_ECC_PARAMETER *  partyVInfo,
UINT32  bit_size,
BYTE *  key 
)

Compute KDFe as described in TPM spec part 1 C 6.1

Parameters
hashAlg[in] The nameAlg of the recipient key.
Z[in] the x coordinate (xP) of the product (P) of a public point and a private key.
label[in] KDF label.
partyUInfo[in] The x-coordinate of the secret exchange value (Qe,U).
partyVInfo[in] The x-coordinate of a public key (Qs,V).
bit_size[in] Bit size of generated key.
key[out] Key buffer.
Return values
TSS2_RC_SUCCESSon success
TSS2_ESYS_RC_BAD_REFERENCEfor invalid parameters
TSS2_ESYS_RC_MEMORYMemory cannot be allocated.

◆ iesys_crypto_pHash()

TSS2_RC iesys_crypto_pHash ( TPM2_ALG_ID  alg,
const uint8_t  rcBuffer[4],
const uint8_t  ccBuffer[4],
const TPM2B_NAME *  name1,
const TPM2B_NAME *  name2,
const TPM2B_NAME *  name3,
const uint8_t *  pBuffer,
size_t  pBuffer_size,
uint8_t *  pHash,
size_t *  pHash_size 
)

Compute the command or response parameter hash.

These hashes are needed for the computation of the HMAC used for the authorization of commands, or for the HMAC used for checking the responses. The name parameters are only used for the command parameter hash (cp) and must be NULL for the computation of the response parameter rp hash (rp).

Parameters
[in]algThe hash algorithm.
[in]rcBufferThe response code in marshaled form.
[in]ccBufferThe command code in marshaled form.
[in]name1,name2,name3The names associated with the corresponding handle. Must be NULL if no handle is passed.
[in]pBufferThe byte buffer or the command or the response.
[in]pBuffer_sizeThe size of the command or response.
[out]pHashThe result digest.
[out]pHash_sizeThe size of the result digest.
Return values
TSS2_RC_SUCCESSon success.
TSS2_ESYS_RC_BAD_REFERENCEfor invalid parameters.

◆ iesys_cryptossl_get_ecdh_point()

TSS2_RC iesys_cryptossl_get_ecdh_point ( TPM2B_PUBLIC *  key,
size_t  max_out_size,
TPM2B_ECC_PARAMETER *  Z,
TPMS_ECC_POINT *  Q,
BYTE *  out_buffer,
size_t *  out_size 
)

Computation of ephemeral ECC key and shared secret Z.

According to the description in TPM spec part 1 C 6.1 a shared secret between application and TPM is computed (ECDH). An ephemeral ECC key and a TPM keyare used for the ECDH key exchange.

Parameters
[in]keyThe key to be used for ECDH key exchange.
[in]max_out_sizethe max size for the output of the public key of the computed ephemeral key.
[out]ZThe computed shared secret.
[out]QThe public part of the ephemeral key in TPM format.
[out]out_bufferThe public part of the ephemeral key will be marshaled to this buffer.
[out]out_sizeThe size of the marshaled output.
Return values
TSS2_RC_SUCCESSon success
TSS2_ESYS_RC_BAD_VALUEThe algorithm of key is not implemented.
TSS2_ESYS_RC_GENERAL_FAILUREThe internal crypto engine failed.

◆ iesys_cryptossl_hash_finish()

TSS2_RC iesys_cryptossl_hash_finish ( IESYS_CRYPTO_CONTEXT_BLOB **  context,
uint8_t *  buffer,
size_t *  size 
)

Get the digest value of a digest object and close the context.

The digest value will written to a passed buffer and the resources of the digest object are released.

Parameters
[in,out]contextThe context of the digest object to be released
[out]bufferThe buffer for the digest value (caller-allocated).
[out]sizeThe size of the digest.
Return values
TSS2_RC_SUCCESSon success.
TSS2_ESYS_RC_BAD_REFERENCEfor invalid parameters.
TSS2_ESYS_RC_GENERAL_FAILUREfor errors of the crypto library.

◆ iesys_cryptossl_hash_finish2b()

TSS2_RC iesys_cryptossl_hash_finish2b ( IESYS_CRYPTO_CONTEXT_BLOB **  context,
TPM2B *  b 
)

void iesys_cryptossl_hash_abort(IESYS_CRYPTO_CONTEXT_BLOB **context)

◆ iesys_cryptossl_hash_start()

TSS2_RC iesys_cryptossl_hash_start ( IESYS_CRYPTO_CONTEXT_BLOB **  context,
TPM2_ALG_ID  hashAlg 
)

Provide the context for the computation of a hash digest.

The context will be created and initialized according to the hash function.

Parameters
[out]contextThe created context (callee-allocated).
[in]hashAlgThe hash algorithm for the creation of the context.
Return values
TSS2_RC_SUCCESSon success.
TSS2_ESYS_RC_BAD_VALUEor TSS2_ESYS_RC_BAD_REFERENCE for invalid parameters.
TSS2_ESYS_RC_MEMORYMemory cannot be allocated.
TSS2_ESYS_RC_GENERAL_FAILUREfor errors of the crypto library.

◆ iesys_cryptossl_hash_update()

TSS2_RC iesys_cryptossl_hash_update ( IESYS_CRYPTO_CONTEXT_BLOB context,
const uint8_t *  buffer,
size_t  size 
)

Update the digest value of a digest object from a byte buffer.

The context of a digest object will be updated according to the hash algorithm of the context. <

Parameters
[in,out]contextThe context of the digest object which will be updated.
[in]bufferThe data for the update.
[in]sizeThe size of the data buffer.
Return values
TSS2_RC_SUCCESSon success.
TSS2_ESYS_RC_BAD_REFERENCEfor invalid parameters.

◆ iesys_cryptossl_hash_update2b()

TSS2_RC iesys_cryptossl_hash_update2b ( IESYS_CRYPTO_CONTEXT_BLOB context,
TPM2B *  b 
)

Update the digest value of a digest object from a TPM2B object.

The context of a digest object will be updated according to the hash algorithm of the context.

Parameters
[in,out]contextThe context of the digest object which will be updated.
[in]bThe TPM2B object for the update.
Return values
TSS2_RC_SUCCESSon success.
TSS2_ESYS_RC_BAD_REFERENCEfor invalid parameters.

◆ iesys_cryptossl_hmac_abort()

void iesys_cryptossl_hmac_abort ( IESYS_CRYPTO_CONTEXT_BLOB **  context)

Release the resources of an HAMC object.

The assigned resources will be released and the context will be set to NULL.

Parameters
[in,out]contextThe context of the HMAC object.

◆ iesys_cryptossl_hmac_finish()

TSS2_RC iesys_cryptossl_hmac_finish ( IESYS_CRYPTO_CONTEXT_BLOB **  context,
uint8_t *  buffer,
size_t *  size 
)

Write the HMAC digest value to a byte buffer and close the context.

The digest value will written to a passed buffer and the resources of the HMAC object are released.

Parameters
[in,out]contextThe context of the HMAC object.
[out]bufferThe buffer for the digest value (caller-allocated).
[out]sizeThe size of the digest.
Return values
TSS2_RC_SUCCESSon success.
TSS2_ESYS_RC_BAD_REFERENCEfor invalid parameters.
TSS2_ESYS_RC_BAD_SIZEIf the size passed is lower than the HMAC length.
TSS2_ESYS_RC_GENERAL_FAILUREfor errors of the crypto library.

◆ iesys_cryptossl_hmac_finish2b()

TSS2_RC iesys_cryptossl_hmac_finish2b ( IESYS_CRYPTO_CONTEXT_BLOB **  context,
TPM2B *  hmac 
)

Write the HMAC digest value to a TPM2B object and close the context.

The digest value will written to a passed TPM2B object and the resources of the HMAC object are released.

Parameters
[in,out]contextThe context of the HMAC object.
[out]hmacThe buffer for the digest value (caller-allocated).
Return values
TSS2_RC_SUCCESSon success.
TSS2_ESYS_RC_BAD_REFERENCEfor invalid parameters.
TSS2_ESYS_RC_BAD_SIZEif the size passed is lower than the HMAC length.
TSS2_ESYS_RC_GENERAL_FAILUREfor errors of the crypto library.

◆ iesys_cryptossl_hmac_start()

TSS2_RC iesys_cryptossl_hmac_start ( IESYS_CRYPTO_CONTEXT_BLOB **  context,
TPM2_ALG_ID  hashAlg,
const uint8_t *  key,
size_t  size 
)

Provide the context an HMAC digest object from a byte buffer key.

The context will be created and initialized according to the hash function and the used HMAC key.

Parameters
[out]contextThe created context (callee-allocated).
[in]hashAlgThe hash algorithm for the HMAC computation.
[in]keyThe byte buffer of the HMAC key.
[in]sizeThe size of the HMAC key.
Return values
TSS2_RC_SUCCESSon success.
TSS2_ESYS_RC_BAD_REFERENCEfor invalid parameters.
TSS2_ESYS_RC_MEMORYMemory cannot be allocated.
TSS2_ESYS_RC_GENERAL_FAILUREfor errors of the crypto library.

◆ iesys_cryptossl_hmac_update()

TSS2_RC iesys_cryptossl_hmac_update ( IESYS_CRYPTO_CONTEXT_BLOB context,
const uint8_t *  buffer,
size_t  size 
)

Update and HMAC digest value from a byte buffer.

The context of a digest object will be updated according to the hash algorithm and the key of the context.

Parameters
[in,out]contextThe context of the digest object which will be updated.
[in]bufferThe data for the update.
[in]sizeThe size of the data buffer.
Return values
TSS2_RC_SUCCESSon success.
TSS2_ESYS_RC_BAD_REFERENCEfor invalid parameters.

◆ iesys_cryptossl_hmac_update2b()

TSS2_RC iesys_cryptossl_hmac_update2b ( IESYS_CRYPTO_CONTEXT_BLOB context,
TPM2B *  b 
)

Update and HMAC digest value from a TPM2B object.

The context of a digest object will be updated according to the hash algorithm and the key of the context.

Parameters
[in,out]contextThe context of the digest object which will be updated.
[in]bThe TPM2B object for the update.
Return values
TSS2_RC_SUCCESSon success.
TSS2_ESYS_RC_BAD_REFERENCEfor invalid parameters.

◆ iesys_cryptossl_pk_encrypt()

TSS2_RC iesys_cryptossl_pk_encrypt ( TPM2B_PUBLIC *  pub_tpm_key,
size_t  in_size,
BYTE *  in_buffer,
size_t  max_out_size,
BYTE *  out_buffer,
size_t *  out_size,
const char *  label 
)

Encryption of a buffer using a public (RSA) key.

Encrypting a buffer using a public key is used for example during Esys_StartAuthSession in order to encrypt the salt value.

Parameters
[in]pub_tpm_keyThe key to be used for encryption.
[in]in_sizeThe size of the buffer to be encrypted.
[in]in_bufferThe data buffer to be encrypted.
[in]max_out_sizeThe maximum size for the output encrypted buffer.
[out]out_bufferThe encrypted buffer.
[out]out_sizeThe size of the encrypted output.
[in]labelThe label used in the encryption scheme.
Return values
TSS2_RC_SUCCESSon success
TSS2_ESYS_RC_BAD_VALUEThe algorithm of key is not implemented.
TSS2_ESYS_RC_GENERAL_FAILUREThe internal crypto engine failed.

◆ iesys_cryptossl_random2b()

TSS2_RC iesys_cryptossl_random2b ( TPM2B_NONCE *  nonce,
size_t  num_bytes 
)

Compute random TPM2B data.

The random data will be generated and written to a passed TPM2B structure.

Parameters
[out]nonceThe TPM2B structure for the random data (caller-allocated).
[in]num_bytesThe number of bytes to be generated.
Return values
TSS2_RC_SUCCESSon success.

NOTE: the TPM should not be used to obtain the random data

◆ iesys_xor_parameter_obfuscation()

TSS2_RC iesys_xor_parameter_obfuscation ( TPM2_ALG_ID  hash_alg,
uint8_t *  key,
size_t  key_size,
TPM2B_NONCE *  contextU,
TPM2B_NONCE *  contextV,
BYTE *  data,
size_t  data_size 
)

Encryption/Decryption using XOR obfuscation.

The application of this function to data encrypted with this function will produce the origin data. The key for XOR obfuscation will be derived with KDFa form the passed key the session nonces, and the hash algorithm.

Parameters
[in]hash_algThe algorithm used for key derivation.
[in]keykey used for obfuscation
[in]key_sizeKey size in bits.
[in]contextU,contextVare used for construction of a binary string containing information related to the derived key.
[in,out]dataData to be encrypted/decrypted the result will be will be stored in this buffer.
[in]data_sizesize of data to be encrypted/decrypted.
Return values
TSS2_RC_SUCCESSon success, or TSS2_ESYS_RC_BAD_VALUE and
TSS2_ESYS_RC_BAD_REFERENCEfor invalid parameters.