OPTIGA™ Trust M
Host Library Documentation
optiga_util.h File Reference

This file defines APIs, types and data structures used in the OPTIGA utility module. More...

Include dependency graph for optiga_util.h:

Go to the source code of this file.

Data Structures

union  optiga_util_params
 union for OPTIGA util parameters More...
 
struct  optiga_util
 OPTIGA util instance structure. More...
 
#define OPTIGA_UTIL_WRITE_ONLY   (0x00)
 Option to only write the data object. More...
 
#define OPTIGA_UTIL_ERASE_AND_WRITE   (0x40)
 Option to erase and write the data object. More...
 
#define OPTIGA_UTIL_CONTEXT_NONE   (0x00)
 To Initialize a clean application context. More...
 
#define OPTIGA_UTIL_SET_COMMS_PROTECTION_LEVEL(p_instance, protection_level)   {}
 Enables the protected I2C communication with OPTIGA for UTIL instances. More...
 
#define OPTIGA_UTIL_SET_COMMS_PROTOCOL_VERSION(p_instance, version)   {}
 Select the protocol version required for the I2C protected communication for UTIL instances. More...
 
typedef union optiga_util_params optiga_util_params_t
 union for OPTIGA util parameters More...
 
typedef struct optiga_util optiga_util_t
 OPTIGA util instance structure type. More...
 
LIBRARY_EXPORTS optiga_util_toptiga_util_create (uint8_t optiga_instance_id, callback_handler_t handler, void *caller_context)
 Create an instance of optiga_util_t. More...
 
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_destroy (optiga_util_t *me)
 De-Initializes the OPTIGA util instance. More...
 
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_open_application (optiga_util_t *me, bool_t perform_restore)
 Initializes the communication with optiga and open the application on OPTIGA. More...
 
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_close_application (optiga_util_t *me, bool_t perform_hibernate)
 Closes the application on OPTIGA and closes the communication with optiga. More...
 
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_read_data (optiga_util_t *me, uint16_t optiga_oid, uint16_t offset, uint8_t *buffer, uint16_t *length)
 Reads data from optiga. More...
 
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_read_metadata (optiga_util_t *me, uint16_t optiga_oid, uint8_t *buffer, uint16_t *length)
 Reads metadata of the specified data object from optiga. More...
 
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_write_data (optiga_util_t *me, uint16_t optiga_oid, uint8_t write_type, uint16_t offset, const uint8_t *buffer, uint16_t length)
 Writes data to optiga. More...
 
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_write_metadata (optiga_util_t *me, uint16_t optiga_oid, const uint8_t *buffer, uint8_t length)
 Writes metadata for the user provided data object. More...
 
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_protected_update_start (optiga_util_t *me, uint8_t manifest_version, const uint8_t *manifest, uint16_t manifest_length)
 Initiates the start of protected update of object by writing manifest into OPTIGA object. More...
 
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_protected_update_continue (optiga_util_t *me, const uint8_t *fragment, uint16_t fragment_length)
 Sends fragment(s) of data to be written to OPTIGA. More...
 
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_protected_update_final (optiga_util_t *me, const uint8_t *fragment, uint16_t fragment_length)
 Sends the last fragment to finalize the protected update of data object. More...
 
LIBRARY_EXPORTS optiga_lib_status_t optiga_util_update_count (optiga_util_t *me, uint16_t optiga_counter_oid, uint8_t count)
 Increments the counter object by a value specified by user. More...
 

Detailed Description

This file defines APIs, types and data structures used in the OPTIGA utility module.

Author
Infineon Technologies AG

Definition in file optiga_util.h.

Macro Definition Documentation

◆ OPTIGA_UTIL_CONTEXT_NONE

#define OPTIGA_UTIL_CONTEXT_NONE   (0x00)

To Initialize a clean application context.

Definition at line 55 of file optiga_util.h.

◆ OPTIGA_UTIL_ERASE_AND_WRITE

#define OPTIGA_UTIL_ERASE_AND_WRITE   (0x40)

Option to erase and write the data object.

Definition at line 51 of file optiga_util.h.

◆ OPTIGA_UTIL_SET_COMMS_PROTECTION_LEVEL

#define OPTIGA_UTIL_SET_COMMS_PROTECTION_LEVEL (   p_instance,
  protection_level 
)    {}

Enables the protected I2C communication with OPTIGA for UTIL instances.

Enables the protected I2C communication with OPTIGA

  • Sets the protection mode for the supplied instance.
  • Call this function before calling the service layer API which requires protection.
Precondition
Note
Parameters
[in]p_instanceValid pointer to an instance
[in]protection_levelRequired protection mode

Definition at line 586 of file optiga_util.h.

◆ OPTIGA_UTIL_SET_COMMS_PROTOCOL_VERSION

#define OPTIGA_UTIL_SET_COMMS_PROTOCOL_VERSION (   p_instance,
  version 
)    {}

Select the protocol version required for the I2C protected communication for UTIL instances.

Select the protocol version required for the I2C protected communication

  • Select the protocol version for the supplied instance.
Precondition
Note
  • None
Parameters
[in]p_instanceValid pointer to an instance
[in]versionRequired protocol version

Definition at line 613 of file optiga_util.h.

◆ OPTIGA_UTIL_WRITE_ONLY

#define OPTIGA_UTIL_WRITE_ONLY   (0x00)

Option to only write the data object.

Definition at line 49 of file optiga_util.h.

Typedef Documentation

◆ optiga_util_params_t

union for OPTIGA util parameters

◆ optiga_util_t

typedef struct optiga_util optiga_util_t

OPTIGA util instance structure type.

Definition at line 1 of file optiga_util.h.

Function Documentation

◆ optiga_util_close_application()

LIBRARY_EXPORTS optiga_lib_status_t optiga_util_close_application ( optiga_util_t me,
bool_t  perform_hibernate 
)

Closes the application on OPTIGA and closes the communication with optiga.

Closes the communication with OPTIGA for the given instance.

  • Initiate close application command to optiga.
  • Perform manage context secure session save operations.
  • De-Initializes the OPTIGA and closes the communication channel.
  • Power downs the OPTIGA after closing the application on optiga.
Precondition
Note
  • For protected I2C communication, Refer OPTIGA_UTIL_SET_COMMS_PROTECTION_LEVEL
  • Error codes from lower layer will be returned as it is.
  • Close application with hibernate and shielded connection establishment(negotiation/re-negotiation) will fail at OPTIGA because hibernation is not allowed when SEC value is greater than zero. The SEC value increments internally on every shielded connection negotiation process.


Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]perform_hibernateHibernate the application on OPTIGA. The values must be as defined below.
  • TRUE (1) - Performs application hibernate.
  • FALSE (0) - De-Initializes application context.
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTInput arguments are NULL
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual)

Example
main_xmc4800_sample.c

◆ optiga_util_create()

LIBRARY_EXPORTS optiga_util_t* optiga_util_create ( uint8_t  optiga_instance_id,
callback_handler_t  handler,
void *  caller_context 
)

Create an instance of optiga_util_t.

Create an instance of optiga_util_t.

  • Stores the callers context and callback handler.
  • Allocate memory for optiga_util_t.
Precondition
  • None
Note
Parameters
[in]optiga_instance_idIndicates the OPTIGA instance to be associated with optiga_util_t. Value should be defined as below
[in]handlerValid pointer to callback function
[in]caller_contextPointer to upper layer context, contains user context data
Return values
optiga_util_tOn success function will return pointer of optiga_util_t
NULLInput arguments are NULL.
Low layer function fails.
OPTIGA_CMD_MAX_REGISTRATIONS number of instances are already created.

Example
main_xmc4800_sample.c

◆ optiga_util_destroy()

LIBRARY_EXPORTS optiga_lib_status_t optiga_util_destroy ( optiga_util_t me)

De-Initializes the OPTIGA util instance.

De-Initializes the optiga_util_t instance.

Precondition
  • None
Note
  • User must take care to nullify the instance pointer.
  • Invoke this API only after all the asynchronous process is completed otherwise the behavior of software stack is not defined.
Parameters
[in]meValid instance of optiga_util_t
Return values
OPTIGA_LIB_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete

Example
main_xmc4800_sample.c

◆ optiga_util_open_application()

LIBRARY_EXPORTS optiga_lib_status_t optiga_util_open_application ( optiga_util_t me,
bool_t  perform_restore 
)

Initializes the communication with optiga and open the application on OPTIGA.

Initializes the communication with OPTIGA for the given instance.

  • Sets up optiga comms channel.
  • Initiate open application command to optiga.
  • Perform manage context , session restore operations and application restore.
Precondition
Note
  • For protected I2C communication, Refer OPTIGA_UTIL_SET_COMMS_PROTECTION_LEVEL
  • Error codes from lower layer will be returned as it is.
  • If error in lower layer occurs while restoring OPTIGA application, then initialize a clean OPTIGA application context.
Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]perform_restoreRestore application on OPTIGA from a previous hibernate state. The values must be as defined below
  • TRUE (1) - Performs application restore.
  • FALSE (0) - Initialize a clean application context.
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual)

Example
main_xmc4800_sample.c

◆ optiga_util_protected_update_continue()

LIBRARY_EXPORTS optiga_lib_status_t optiga_util_protected_update_continue ( optiga_util_t me,
const uint8_t *  fragment,
uint16_t  fragment_length 
)

Sends fragment(s) of data to be written to OPTIGA.

Sends a fragment of data to be written to OPTIGA.

Precondition
Note
Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]fragmentValid pointer to the buffer which contains fragment
  • It must be a valid fragment, otherwise OPTIGA returns an error.
[in]fragment_lengthLength of fragment to be written
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual)

Example
example_optiga_util_protected_update.c

◆ optiga_util_protected_update_final()

LIBRARY_EXPORTS optiga_lib_status_t optiga_util_protected_update_final ( optiga_util_t me,
const uint8_t *  fragment,
uint16_t  fragment_length 
)

Sends the last fragment to finalize the protected update of data object.

Sends the last fragment to finalize the protected update of data object.

Precondition
Note
  • The protected I2C communication value set in optiga_util_protected_update_start will be used in this API.
  • Error codes from lower layers will be returned as it is.
  • The strict sequence is terminated in case of an error from lower layer.
Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]fragmentValid pointer to the buffer which contains the last fragment.
  • If NULL, only strict sequence is released and no APDU is sent to OPTIGA
[in]fragment_lengthLength of fragment to be written
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual)

Example
example_optiga_util_protected_update.c

◆ optiga_util_protected_update_start()

LIBRARY_EXPORTS optiga_lib_status_t optiga_util_protected_update_start ( optiga_util_t me,
uint8_t  manifest_version,
const uint8_t *  manifest,
uint16_t  manifest_length 
)

Initiates the start of protected update of object by writing manifest into OPTIGA object.

Initiates the start of protected update of object.

  • It marks the beginning of a strict sequence. None of the service layer API will be processed until the strict sequence is terminated.
  • Invokes optiga_cmd_set_object_protected API, based on the input arguments to send manifest to OPTIGA.
Precondition
Note
Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]manifest_versionVersion of manifest to be written
[in]manifestValid pointer to the buffer which contains manifest
  • It should be a valid manifest, otherwise OPTIGA returns an error.
[in]manifest_lengthLength of manifest to be written
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual)

Example
example_optiga_util_protected_update.c

◆ optiga_util_read_data()

LIBRARY_EXPORTS optiga_lib_status_t optiga_util_read_data ( optiga_util_t me,
uint16_t  optiga_oid,
uint16_t  offset,
uint8_t *  buffer,
uint16_t *  length 
)

Reads data from optiga.

Retrieves the requested data that is stored in the user provided data object.

Precondition
Note
  • For protected I2C communication, Refer OPTIGA_UTIL_SET_COMMS_PROTECTION_LEVEL
  • Error codes from lower layers will be returned as it is.
  • The maximum value of the *length parameter must be the size of buffer buffer. In case the value is greater than buffer size, memory corruption can occur.
  • If any errors occur while retrieving the data, *length parameter is set to 0.
Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]optiga_oidOID of data object
  • It should be a valid data object, otherwise OPTIGA returns an error.
[in]offsetOffset from within data object
  • It must be valid offset from within data object, otherwise OPTIGA returns an error.
[in,out]bufferValid pointer to the buffer to which data is read
[in,out]lengthValid pointer to the length of data to be read from data object
  • When the data is successfully retrieved, it is updated with actual data length retrieved
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual)

Example
example_optiga_util_read_data.c

◆ optiga_util_read_metadata()

LIBRARY_EXPORTS optiga_lib_status_t optiga_util_read_metadata ( optiga_util_t me,
uint16_t  optiga_oid,
uint8_t *  buffer,
uint16_t *  length 
)

Reads metadata of the specified data object from optiga.

Reads the metadata of the user provided data object.

Precondition
Note
  • For protected I2C communication, Refer OPTIGA_UTIL_SET_COMMS_PROTECTION_LEVEL
  • Error codes from lower layers will be returned as it is.
  • The metadata returned will be in TLV format.
  • The maximum value of the *length parameter must be the size of buffer. In case the value is greater than buffer size, memory corruption can occur.
  • If any errors occur while retrieving the data, *length parameter is set to 0.
Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]optiga_oidOID of data object
  • It should be a valid data object, otherwise OPTIGA returns an error.
[in,out]bufferValid pointer to the buffer to which metadata is read
[in,out]lengthValid pointer to the length of metadata to be read from data object
  • When the metadata is successfully retrieved, it is updated with actual metadata length retrieved
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual)

Example
example_optiga_util_read_data.c

◆ optiga_util_update_count()

LIBRARY_EXPORTS optiga_lib_status_t optiga_util_update_count ( optiga_util_t me,
uint16_t  optiga_counter_oid,
uint8_t  count 
)

Increments the counter object by a value specified by user.

Increments the counter object by a value specified by user.

Precondition
Note
Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]optiga_counter_oidOID of counter data object
  • It should be a valid data object, otherwise OPTIGA returns an error.
[in]countCounter value to be updated
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual)

Example
example_optiga_util_update_count.c

◆ optiga_util_write_data()

LIBRARY_EXPORTS optiga_lib_status_t optiga_util_write_data ( optiga_util_t me,
uint16_t  optiga_oid,
uint8_t  write_type,
uint16_t  offset,
const uint8_t *  buffer,
uint16_t  length 
)

Writes data to optiga.

Writes the data provided by the user into the specified data object.

Precondition
Note
  • For protected I2C communication, Refer OPTIGA_UTIL_SET_COMMS_PROTECTION_LEVEL
  • Error codes from lower layers will be returned as it is.
  • The maximum value of the length parameter is size of buffer. In case the value is greater than buffer size, incorrect values can get written into the data object in OPTIGA.
  • In case the write_type provided is other than erase and write(0x00) or write only(0x40), the function returns OPTIGA_UTIL_ERROR_INVALID_INPUT.
Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]optiga_oidOID of data object
  • It should be a valid data object, otherwise OPTIGA returns an error.
[in]write_typeType of write must be either OPTIGA_UTIL_WRITE_ONLY or OPTIGA_UTIL_ERASE_AND_WRITE.
[in]offsetOffset from within data object
  • It must be valid offset from within data object, otherwise OPTIGA returns an error.
[in]bufferValid pointer to the buffer with user data to write
[in]lengthLength of data to be written
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code. (Refer Solution Reference Manual)

Example
example_optiga_util_write_data.c

◆ optiga_util_write_metadata()

LIBRARY_EXPORTS optiga_lib_status_t optiga_util_write_metadata ( optiga_util_t me,
uint16_t  optiga_oid,
const uint8_t *  buffer,
uint8_t  length 
)

Writes metadata for the user provided data object.

Writes metadata for the specified data object.

Precondition
Note
  • For protected I2C communication, Refer OPTIGA_UTIL_SET_COMMS_PROTECTION_LEVEL
  • Error codes from lower layers will be returned as it is.
  • The maximum value of the length parameter is size of buffer. In case the value is greater than buffer size, incorrect values can get written into the meta data of the data object in OPTIGA.
  • The metadata to be written must be in TLV format.
Parameters
[in]meValid instance of optiga_util_t created using optiga_util_create.
[in]optiga_oidOID of data object
  • It should be a valid data object, otherwise OPTIGA returns an error.
[in]bufferValid pointer to the buffer with metadata to write
[in]lengthLength of metadata to be written
Return values
OPTIGA_UTIL_SUCCESSSuccessful invocation
OPTIGA_UTIL_ERROR_INVALID_INPUTWrong Input arguments provided
OPTIGA_UTIL_ERROR_INSTANCE_IN_USEThe previous operation with the same instance is not complete
OPTIGA_DEVICE_ERRORCommand execution failure in OPTIGA and the LSB indicates the error code.

Example
example_optiga_util_write_data.c