Internal interface that models TPM 2.0 interfaces. More...

Functions

EpidStatus Tpm2Commit (Tpm2Ctx *ctx, EcPoint const *p1, void const *s2, size_t s2_len, FfElement const *y2, EcPoint *k, EcPoint *l, EcPoint *e, uint16_t *counter)
 Performs TPM2_Commit TPM operation. More...
 
EpidStatus Tpm2CreateContext (MemberParams const *params, Epid2Params_ const *epid2_params, BitSupplier *rnd_func, void **rnd_param, const FpElemStr **f, Tpm2Ctx **ctx)
 Creates a new Tpm context. More...
 
void Tpm2DeleteContext (Tpm2Ctx **ctx)
 Deletes an existing Tpm context. More...
 
EpidStatus Tpm2SetHashAlg (Tpm2Ctx *ctx, HashAlg hash_alg)
 Sets the hash algorithm to be used by a TPM2. More...
 
void Tpm2ResetContext (Tpm2Ctx **ctx)
 Reset an existing Tpm context. More...
 
EpidStatus Tpm2GetRandom (Tpm2Ctx *ctx, int const num_bits, void *random_data)
 Get random data. More...
 
EpidStatus Tpm2LoadExternal (Tpm2Ctx *ctx, FpElemStr const *f_str)
 Invokes TPM2_LoadExternal command. More...
 
EpidStatus Tpm2NvDefineSpace (Tpm2Ctx *ctx, uint32_t nv_index, size_t size)
 Performs TPM2_NV_DefineSpace TPM command. More...
 
EpidStatus Tpm2NvUndefineSpace (Tpm2Ctx *ctx, uint32_t nv_index)
 Performs TPM2_NV_UndefineSpace TPM command. More...
 
EpidStatus Tpm2NvWrite (Tpm2Ctx *ctx, uint32_t nv_index, size_t size, uint16_t offset, void const *data)
 Performs TPM2_NV_Write TPM command. More...
 
EpidStatus Tpm2NvRead (Tpm2Ctx *ctx, uint32_t nv_index, size_t size, uint16_t offset, void *data)
 Performs TPM2_NV_Read TPM command. More...
 
EpidStatus Tpm2Sign (Tpm2Ctx *ctx, void const *digest, size_t digest_len, uint16_t counter, FfElement *k, FfElement *s)
 Performs TPM2_Sign TPM command. More...
 
EpidStatus Tpm2ReleaseCounter (Tpm2Ctx *ctx, uint16_t counter)
 Erases random r value assosiated with counter. More...
 

Detailed Description

Internal interface that models TPM 2.0 interfaces.

Provides an interface that represents operations that can be directly translated to operations on TPM 2.0 devices.

Function Documentation

◆ Tpm2Commit()

EpidStatus Tpm2Commit ( Tpm2Ctx ctx,
EcPoint const *  p1,
void const *  s2,
size_t  s2_len,
FfElement const *  y2,
EcPoint k,
EcPoint l,
EcPoint e,
uint16_t *  counter 
)

Performs TPM2_Commit TPM operation.

Generates random r and compute K, L and E points.

Parameters
[in]ctxThe TPM context.
[in]p1A point P1 on G1 curve.
[in]s2Octet array used to derive x-coordinate of a point P2.
[in]s2_lenLength of s2 buffer.
[in]y2y coordinate of the point associated with s2.
[out]kResult of G1.exp(P2, private key f).
[out]lResult of G1.exp(P2, random r).
[out]eResult of G1.exp(P1, random r).
[out]counterA value associated with the random r. Should be initialized with zero.
Returns
EpidStatus
See also
Tpm2CreateContext

◆ Tpm2CreateContext()

EpidStatus Tpm2CreateContext ( MemberParams const *  params,
Epid2Params_ const *  epid2_params,
BitSupplier rnd_func,
void **  rnd_param,
const FpElemStr **  f,
Tpm2Ctx **  ctx 
)

Creates a new Tpm context.

Must be called to create the TPM context that is used by other TPM APIs.

You need to use a cryptographically secure random number generator to create a TPM context. The BitSupplier is provided as a function prototype for your own implementation of the random number generator.

Tpm2DeleteContext must be called to safely release the TPM context.

Parameters
[in]paramsmember parameters to initialize rnd_func, rnd_param, ff_elem, ctx.
[in]epid2_paramsThe field and group parameters.
[out]rnd_funcrandom function if exists in MemberParms
[out]rnd_paramrandom parameters if exists in MemberParms
[out]fseed f if exists in MemberParams
[out]ctxNewly constructed TPM context.
Returns
EpidStatus
See also
Tpm2DeleteContext

◆ Tpm2DeleteContext()

void Tpm2DeleteContext ( Tpm2Ctx **  ctx)

Deletes an existing Tpm context.

Must be called to safely release a TPM context created using Tpm2CreateContext.

De-initializes the context, frees memory used by the context, and sets the context pointer to NULL.

Parameters
[in,out]ctxThe TPM context. Can be NULL.
See also
Tpm2CreateContext

◆ Tpm2GetRandom()

EpidStatus Tpm2GetRandom ( Tpm2Ctx ctx,
int const  num_bits,
void *  random_data 
)

Get random data.

This command returns the next num_bits from the random number generator (RNG).

Parameters
[in,out]ctxTPM context.
[in]num_bitsNumber of bits to return.
[out]random_dataOutput random bits.
Returns
EpidStatus
See also
Tpm2CreateContext

◆ Tpm2LoadExternal()

EpidStatus Tpm2LoadExternal ( Tpm2Ctx ctx,
FpElemStr const *  f_str 
)

Invokes TPM2_LoadExternal command.

This command is used to load an object that is not a Protected Object into the TPM. The command allows loading of a public area or both a public and sensitive area.

Parameters
[in,out]ctxTPM context.
[in]f_strThe f value of the member private key.
Returns
EpidStatus

◆ Tpm2NvDefineSpace()

EpidStatus Tpm2NvDefineSpace ( Tpm2Ctx ctx,
uint32_t  nv_index,
size_t  size 
)

Performs TPM2_NV_DefineSpace TPM command.

Parameters
[in]ctxThe TPM context.
[in]nv_indexHandle of the data area.
[in]sizeSize of the data area.
Returns
EpidStatus
See also
Tpm2NvRead
Tpm2NvWrite

◆ Tpm2NvRead()

EpidStatus Tpm2NvRead ( Tpm2Ctx ctx,
uint32_t  nv_index,
size_t  size,
uint16_t  offset,
void *  data 
)

Performs TPM2_NV_Read TPM command.

Parameters
[in]ctxThe TPM context.
[in]nv_indexNV Index to be read.
[in]sizeNumber of bytes to read.
[in]offsetOffset into the area.
[out]dataData read.
Returns
EpidStatus
See also
Tpm2NvWrite

◆ Tpm2NvUndefineSpace()

EpidStatus Tpm2NvUndefineSpace ( Tpm2Ctx ctx,
uint32_t  nv_index 
)

Performs TPM2_NV_UndefineSpace TPM command.

Parameters
[in]ctxThe TPM context.
[in]nv_indexHandle of the data area to undefine.
Returns
EpidStatus
See also
Tpm2NvDefineSpace

◆ Tpm2NvWrite()

EpidStatus Tpm2NvWrite ( Tpm2Ctx ctx,
uint32_t  nv_index,
size_t  size,
uint16_t  offset,
void const *  data 
)

Performs TPM2_NV_Write TPM command.

An area in NV memory must be defined prior writing.

Parameters
[in]ctxThe TPM context.
[in]nv_indexNV Index to be write.
[in]sizeNumber of bytes to write.
[in]offsetOffset into the area.
[in]dataData to write.
Returns
EpidStatus
See also
Tpm2NvDefineSpace

◆ Tpm2ReleaseCounter()

EpidStatus Tpm2ReleaseCounter ( Tpm2Ctx ctx,
uint16_t  counter 
)

Erases random r value assosiated with counter.

Parameters
[in]ctxThe TPM context.
[in]counterTo be released value associated with the random r generated during TPM2_Commit.
Note
This function should be used if Tpm2Sign wasn't called after Tpm2Commit which created counter.
Returns
EpidStatus
See also
Tpm2Commit

◆ Tpm2ResetContext()

void Tpm2ResetContext ( Tpm2Ctx **  ctx)

Reset an existing Tpm context.

Must be called to reset a TPM context created using Tpm2CreateContext.

Re-initializes the context, reset memory used for primary key.

Parameters
[in,out]ctxThe TPM context. Can be NULL.
See also
Tpm2CreateContext

◆ Tpm2SetHashAlg()

EpidStatus Tpm2SetHashAlg ( Tpm2Ctx ctx,
HashAlg  hash_alg 
)

Sets the hash algorithm to be used by a TPM2.

Parameters
[in]ctxThe TPM2 context.
[in]hash_algThe hash algorithm to use.
Returns
EpidStatus

◆ Tpm2Sign()

EpidStatus Tpm2Sign ( Tpm2Ctx ctx,
void const *  digest,
size_t  digest_len,
uint16_t  counter,
FfElement k,
FfElement s 
)

Performs TPM2_Sign TPM command.

Calculate a pair (k, s) an ECDAA signature.

Private key f must exist in the TPM context.

Parameters
[in]ctxThe TPM context.
[in]digestDigest to be signed.
[in]digest_lenThe size of digest in bytes.
[in]counterA value associated with the random r generated during TPM2_Commit.
[out]kThe ECDAA signature k value. Nonce produced by the TPM during signing.
[out]sThe ECDAA signature s value.
Returns
EpidStatus
See also
Tpm2CreateContext
Tpm2Commit