OPTIGA Trust M  1.1.0
C++ library for Optiga Trust M Chip Security Controller
optiga_lib_common.h File Reference

This file provides the prototypes for the commonly used functions and structures of OPTIGA Library. More...

Include dependency graph for optiga_lib_common.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  optiga_hash_context
 Specifies the structure to the Hash context details managed by OPTIGA. More...
 
struct  hash_data_from_host
 Specifies the structure to provide the details of data to be hashed from host. More...
 
struct  hash_data_in_optiga
 Specifies the structure to provide the details of data to be hashed from OPTIGA. More...
 
struct  public_key_from_host
 Specifies the data structure of the Public Key details (key, size and type) More...
 
struct  optiga_get_data_object
 Specifies the data structure for data to be read from OPTIGA. More...
 
struct  optiga_set_data_object
 Specifies the data structure for data to be written to OPTIGA. More...
 
struct  optiga_calc_hash
 Specifies the data structure of calculate hash. More...
 
struct  optiga_get_random
 Specifies the data structure of random generation. More...
 
struct  optiga_gen_keypair
 Specifies the data structure for generate key pair. More...
 
struct  optiga_calc_sign
 Specifies the data structure for ECDSA signature. More...
 
struct  optiga_verify_sign
 Specifies the data structure for ECDSA signature verification. More...
 
struct  optiga_calc_ssec
 Specifies the data structure for ecdh secret generation. More...
 
struct  optiga_derive_key
 Specifies the structure for derivation of key using pseudo random function. More...
 
struct  optiga_enc_dec_asym
 Specifies the structure for asymmetric encryption and decryption. More...
 
struct  optiga_set_object_protected_params
 Specifies the data structure for protected update. More...
 
#define OPTIGA_INSTANCE_ID_0   (0x00)
 Instance id of OPTIGA slave. More...
 
#define OPTIGA_COMMS_NO_PROTECTION   (0x00)
 When command data and response data is unprotected. More...
 
#define OPTIGA_COMMS_COMMAND_PROTECTION   (0x01)
 When command data is protected and response data is unprotected. More...
 
#define OPTIGA_COMMS_RESPONSE_PROTECTION   (0x02)
 When command data is unprotected and response data is protected. More...
 
#define OPTIGA_COMMS_FULL_PROTECTION   (0x03)
 Both command data and response data are protected. More...
 
#define OPTIGA_COMMS_RE_ESTABLISH   (0x80)
 Re-establish shielded connection. More...
 
#define OPTIGA_COMMS_PROTOCOL_VERSION_PRE_SHARED_SECRET   (0x01)
 Pre shared secret protocol version. More...
 
#define OPTIGA_CRYPT_HOST_DATA   (0x01)
 Data is provided by host. More...
 
#define OPTIGA_CRYPT_OID_DATA   (0x00)
 Data in internal to optiga OID. More...
 
#define OPTIGA_LIB_INSTANCE_BUSY   (0x0001)
 OPTIGA instance is busy. More...
 
#define OPTIGA_LIB_INSTANCE_FREE   (0x0000)
 OPTIGA instance is free. More...
 
#define OPTIGA_COMMS_PROTECTION_LEVEL   (0x01)
 Configure shielded connection protection level for instance. More...
 
#define OPTIGA_COMMS_PROTOCOL_VERSION   (0x02)
 Configure shielded connection protocol version for instance. More...
 
enum  optiga_key_id {
  OPTIGA_KEY_ID_E0F0 = 0xE0F0, OPTIGA_KEY_ID_E0F1 = 0xE0F1, OPTIGA_KEY_ID_E0F2 = 0xE0F2, OPTIGA_KEY_ID_E0F3 = 0xE0F3,
  OPTIGA_KEY_ID_E0FC = 0xE0FC, OPTIGA_KEY_ID_E0FD = 0xE0FD, OPTIGA_KEY_ID_SESSION_BASED = 0x0000
}
 Specifies the key location in OPTIGA. More...
 
enum  optiga_key_usage { OPTIGA_KEY_USAGE_AUTHENTICATION = 0x01, OPTIGA_KEY_USAGE_SIGN = 0x10, OPTIGA_KEY_USAGE_KEY_AGREEMENT = 0x20, OPTIGA_KEY_USAGE_ENCRYPTION = 0x02 }
 Specifies the key usage type in OPTIGA. More...
 
enum  optiga_set_obj_protected_tag { OPTIGA_SET_PROTECTED_UPDATE_START = 0x00, OPTIGA_SET_PROTECTED_UPDATE_CONTINUE = 0x02, OPTIGA_SET_PROTECTED_UPDATE_FINAL = 0x01 }
 Specifies the set protected object tag. More...
 
enum  optiga_ecc_curve { OPTIGA_ECC_CURVE_NIST_P_256 = 0x03, OPTIGA_ECC_CURVE_NIST_P_384 = 0x04 }
 Specifies the key curve type in OPTIGA. More...
 
enum  optiga_rsa_encryption_scheme { OPTIGA_RSAES_PKCS1_V15 = 0x11 }
 Specifies the RSA encryption schemes. More...
 
enum  optiga_rsa_key_type { OPTIGA_RSA_KEY_1024_BIT_EXPONENTIAL = 0x41, OPTIGA_RSA_KEY_2048_BIT_EXPONENTIAL = 0x42 }
 Specifies the RSA key type in OPTIGA. More...
 
enum  optiga_rsa_signature_scheme { OPTIGA_RSASSA_PKCS1_V15_SHA256 = 0x01, OPTIGA_RSASSA_PKCS1_V15_SHA384 = 0x02 }
 Specifies the RSA signature schemes type in OPTIGA. More...
 
enum  optiga_hash_type { OPTIGA_HASH_TYPE_SHA_256 = 0xE2 }
 Specifies the hashing algorithm type in OPTIGA. More...
 
enum  optiga_rng_type { OPTIGA_RNG_TYPE_TRNG = 0x00, OPTIGA_RNG_TYPE_DRNG = 0x01 }
 Specifies the random generation types. More...
 
typedef enum optiga_key_id optiga_key_id_t
 Specifies the key location in OPTIGA. More...
 
typedef enum optiga_key_usage optiga_key_usage_t
 Specifies the key usage type in OPTIGA. More...
 
typedef enum optiga_set_obj_protected_tag optiga_set_obj_protected_tag_t
 Specifies the set protected object tag. More...
 
typedef enum optiga_ecc_curve optiga_ecc_curve_t
 Specifies the key curve type in OPTIGA. More...
 
typedef enum optiga_rsa_encryption_scheme optiga_rsa_encryption_scheme_t
 Specifies the RSA encryption schemes. More...
 
typedef enum optiga_rsa_key_type optiga_rsa_key_type_t
 Specifies the RSA key type in OPTIGA. More...
 
typedef enum optiga_rsa_signature_scheme optiga_rsa_signature_scheme_t
 Specifies the RSA signature schemes type in OPTIGA. More...
 
typedef enum optiga_hash_type optiga_hash_type_t
 Specifies the hashing algorithm type in OPTIGA. More...
 
typedef enum optiga_rng_type optiga_rng_type_t
 Specifies the random generation types. More...
 
typedef struct optiga_hash_context optiga_hash_context_t
 Specifies the structure to the Hash context details managed by OPTIGA. More...
 
typedef struct hash_data_from_host hash_data_from_host_t
 Specifies the structure to provide the details of data to be hashed from host. More...
 
typedef struct hash_data_in_optiga hash_data_in_optiga_t
 Specifies the structure to provide the details of data to be hashed from OPTIGA. More...
 
typedef struct public_key_from_host public_key_from_host_t
 Specifies the data structure of the Public Key details (key, size and type) More...
 
typedef struct optiga_get_data_object optiga_get_data_object_params_t
 Specifies the data structure for data to be read from OPTIGA. More...
 
typedef struct optiga_set_data_object optiga_set_data_object_params_t
 Specifies the data structure for data to be written to OPTIGA. More...
 
typedef struct optiga_calc_hash optiga_calc_hash_params_t
 Specifies the data structure of calculate hash. More...
 
typedef struct optiga_get_random optiga_get_random_params_t
 Specifies the data structure of random generation. More...
 
typedef struct optiga_gen_keypair optiga_gen_keypair_params_t
 Specifies the data structure for generate key pair. More...
 
typedef struct optiga_calc_sign optiga_calc_sign_params_t
 Specifies the data structure for ECDSA signature. More...
 
typedef struct optiga_verify_sign optiga_verify_sign_params_t
 Specifies the data structure for ECDSA signature verification. More...
 
typedef struct optiga_calc_ssec optiga_calc_ssec_params_t
 Specifies the data structure for ecdh secret generation. More...
 
typedef struct optiga_derive_key optiga_derive_key_params_t
 Specifies the structure for derivation of key using pseudo random function. More...
 
typedef struct optiga_enc_dec_asym optiga_encrypt_asym_params_t
 Specifies the structure for asymmetric encryption and decryption. More...
 
typedef struct optiga_enc_dec_asym optiga_decrypt_asym_params_t
 
typedef struct optiga_set_object_protected_params optiga_set_object_protected_params_t
 Specifies the data structure for protected update. More...
 
uint32_t optiga_common_get_uint32 (const uint8_t *p_input_buffer)
 Prepares uint32 [Big endian] type value from the buffer and store. More...
 
void optiga_common_set_uint16 (uint8_t *p_output_buffer, uint16_t two_byte_value)
 Copies 2 bytes of uint16 type value to the buffer. More...
 
void optiga_common_set_uint32 (uint8_t *p_output_buffer, uint32_t four_byte_value)
 Copies 4 bytes of uint32 [Big endian] type value to the buffer and stores in the output pointer. More...
 
void optiga_common_get_uint16 (const uint8_t *p_input_buffer, uint16_t *p_two_byte_value)
 Prepares uint16 [Big endian] type value from the buffer and stores in the output pointer. More...
 

Detailed Description

This file provides the prototypes for the commonly used functions and structures of OPTIGA Library.

Copyright (c) 2019 Infineon Technologies AG

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE

\endcopyright

Author
Infineon Technologies AG

Macro Definition Documentation

◆ OPTIGA_COMMS_COMMAND_PROTECTION

#define OPTIGA_COMMS_COMMAND_PROTECTION   (0x01)

When command data is protected and response data is unprotected.

◆ OPTIGA_COMMS_FULL_PROTECTION

#define OPTIGA_COMMS_FULL_PROTECTION   (0x03)

Both command data and response data are protected.

◆ OPTIGA_COMMS_NO_PROTECTION

#define OPTIGA_COMMS_NO_PROTECTION   (0x00)

When command data and response data is unprotected.

◆ OPTIGA_COMMS_PROTECTION_LEVEL

#define OPTIGA_COMMS_PROTECTION_LEVEL   (0x01)

Configure shielded connection protection level for instance.

◆ OPTIGA_COMMS_PROTOCOL_VERSION

#define OPTIGA_COMMS_PROTOCOL_VERSION   (0x02)

Configure shielded connection protocol version for instance.

◆ OPTIGA_COMMS_PROTOCOL_VERSION_PRE_SHARED_SECRET

#define OPTIGA_COMMS_PROTOCOL_VERSION_PRE_SHARED_SECRET   (0x01)

Pre shared secret protocol version.

◆ OPTIGA_COMMS_RE_ESTABLISH

#define OPTIGA_COMMS_RE_ESTABLISH   (0x80)

Re-establish shielded connection.

◆ OPTIGA_COMMS_RESPONSE_PROTECTION

#define OPTIGA_COMMS_RESPONSE_PROTECTION   (0x02)

When command data is unprotected and response data is protected.

◆ OPTIGA_CRYPT_HOST_DATA

#define OPTIGA_CRYPT_HOST_DATA   (0x01)

Data is provided by host.

◆ OPTIGA_CRYPT_OID_DATA

#define OPTIGA_CRYPT_OID_DATA   (0x00)

Data in internal to optiga OID.

◆ OPTIGA_INSTANCE_ID_0

#define OPTIGA_INSTANCE_ID_0   (0x00)

Instance id of OPTIGA slave.

◆ OPTIGA_LIB_INSTANCE_BUSY

#define OPTIGA_LIB_INSTANCE_BUSY   (0x0001)

OPTIGA instance is busy.

◆ OPTIGA_LIB_INSTANCE_FREE

#define OPTIGA_LIB_INSTANCE_FREE   (0x0000)

OPTIGA instance is free.

Typedef Documentation

◆ hash_data_from_host_t

Specifies the structure to provide the details of data to be hashed from host.

◆ hash_data_in_optiga_t

Specifies the structure to provide the details of data to be hashed from OPTIGA.

◆ optiga_calc_hash_params_t

Specifies the data structure of calculate hash.

◆ optiga_calc_sign_params_t

Specifies the data structure for ECDSA signature.

◆ optiga_calc_ssec_params_t

Specifies the data structure for ecdh secret generation.

◆ optiga_decrypt_asym_params_t

◆ optiga_derive_key_params_t

Specifies the structure for derivation of key using pseudo random function.

◆ optiga_ecc_curve_t

Specifies the key curve type in OPTIGA.

◆ optiga_encrypt_asym_params_t

Specifies the structure for asymmetric encryption and decryption.

◆ optiga_gen_keypair_params_t

Specifies the data structure for generate key pair.

◆ optiga_get_data_object_params_t

Specifies the data structure for data to be read from OPTIGA.

◆ optiga_get_random_params_t

Specifies the data structure of random generation.

◆ optiga_hash_context_t

Specifies the structure to the Hash context details managed by OPTIGA.

◆ optiga_hash_type_t

Specifies the hashing algorithm type in OPTIGA.

◆ optiga_key_id_t

Specifies the key location in OPTIGA.

◆ optiga_key_usage_t

Specifies the key usage type in OPTIGA.

◆ optiga_rng_type_t

Specifies the random generation types.

◆ optiga_rsa_encryption_scheme_t

Specifies the RSA encryption schemes.

◆ optiga_rsa_key_type_t

Specifies the RSA key type in OPTIGA.

◆ optiga_rsa_signature_scheme_t

Specifies the RSA signature schemes type in OPTIGA.

◆ optiga_set_data_object_params_t

Specifies the data structure for data to be written to OPTIGA.

◆ optiga_set_obj_protected_tag_t

Specifies the set protected object tag.

◆ optiga_set_object_protected_params_t

Specifies the data structure for protected update.

◆ optiga_verify_sign_params_t

Specifies the data structure for ECDSA signature verification.

◆ public_key_from_host_t

Specifies the data structure of the Public Key details (key, size and type)

Enumeration Type Documentation

◆ optiga_ecc_curve

Specifies the key curve type in OPTIGA.

Enumerator
OPTIGA_ECC_CURVE_NIST_P_256 

Generate elliptic curve key based on NIST P256.

OPTIGA_ECC_CURVE_NIST_P_384 

Generate elliptic curve key based on NIST P384.

◆ optiga_hash_type

Specifies the hashing algorithm type in OPTIGA.

Enumerator
OPTIGA_HASH_TYPE_SHA_256 

Hash algorithm type SHA256.

◆ optiga_key_id

Specifies the key location in OPTIGA.

Enumerator
OPTIGA_KEY_ID_E0F0 

Key from key store (non-volatile)

OPTIGA_KEY_ID_E0F1 

Key from key store (non-volatile)

OPTIGA_KEY_ID_E0F2 

Key from key store (non-volatile)

OPTIGA_KEY_ID_E0F3 

Key from key store (non-volatile)

OPTIGA_KEY_ID_E0FC 

Key from key store for RSA (non-volatile)

OPTIGA_KEY_ID_E0FD 

Key from key store for RSA (non-volatile)

OPTIGA_KEY_ID_SESSION_BASED 

Key from session (volatile)

◆ optiga_key_usage

Specifies the key usage type in OPTIGA.

Enumerator
OPTIGA_KEY_USAGE_AUTHENTICATION 

This enables the private key for the signature generation as part of authentication commands.

OPTIGA_KEY_USAGE_SIGN 

This enables the private key for the signature generation.

OPTIGA_KEY_USAGE_KEY_AGREEMENT 

This enables the private key for key agreement (e.g. ecdh operations)

OPTIGA_KEY_USAGE_ENCRYPTION 

This enables the private key for encrypt and decrypt.

◆ optiga_rng_type

Specifies the random generation types.

Enumerator
OPTIGA_RNG_TYPE_TRNG 

Generate Random data using TRNG.

OPTIGA_RNG_TYPE_DRNG 

Generate Random data using DRNG.

◆ optiga_rsa_encryption_scheme

Specifies the RSA encryption schemes.

Enumerator
OPTIGA_RSAES_PKCS1_V15 

RSA PKCS1 v1.5 encryption scheme.

◆ optiga_rsa_key_type

Specifies the RSA key type in OPTIGA.

Enumerator
OPTIGA_RSA_KEY_1024_BIT_EXPONENTIAL 

Generate 1024 bit RSA key.

OPTIGA_RSA_KEY_2048_BIT_EXPONENTIAL 

Generate 2048 bit RSA key.

◆ optiga_rsa_signature_scheme

Specifies the RSA signature schemes type in OPTIGA.

Enumerator
OPTIGA_RSASSA_PKCS1_V15_SHA256 

Signature schemes RSA SSA PKCS1-v1.5 with SHA256 digest.

OPTIGA_RSASSA_PKCS1_V15_SHA384 

Signature schemes RSA SSA PKCS1-v1.5 with SHA384 digest.

◆ optiga_set_obj_protected_tag

Specifies the set protected object tag.

Enumerator
OPTIGA_SET_PROTECTED_UPDATE_START 

This enables to start of the protected update.

OPTIGA_SET_PROTECTED_UPDATE_CONTINUE 

This enables to continue of the protected update.

OPTIGA_SET_PROTECTED_UPDATE_FINAL 

This enables to finish of the protected update.

Function Documentation

◆ optiga_common_get_uint16()

void optiga_common_get_uint16 ( const uint8_t *  p_input_buffer,
uint16_t *  p_two_byte_value 
)

Prepares uint16 [Big endian] type value from the buffer and stores in the output pointer.

Prepares uint16 [Big endian] type value from the buffer and store

  • Return first 2 bytes from input buffer as uint16_t.
Precondition
  • None
Note
  • None
Parameters
[in]p_input_bufferPointer to the buffer
[in,out]p_two_byte_valuePointer to the value tobe assigne

◆ optiga_common_get_uint32()

uint32_t optiga_common_get_uint32 ( const uint8_t *  p_input_buffer)

Prepares uint32 [Big endian] type value from the buffer and store.

Prepares uint32 [Big endian] type value from the buffer and store

  • Return first 4 bytes from input buffer as uint32_t.
Precondition
  • None
Note
  • None
Parameters
[in]p_input_bufferPointer to the buffer
Return values
return32 bit value

◆ optiga_common_set_uint16()

void optiga_common_set_uint16 ( uint8_t *  p_output_buffer,
uint16_t  two_byte_value 
)

Copies 2 bytes of uint16 type value to the buffer.

Copies 2 bytes of uint16 type value to the buffer

  • Copies the 2 bytes value to input buffer in big endian format.
Precondition
  • None
Note
  • None
Parameters
[in,out]p_output_bufferPointer to the buffer
[in]two_byte_value16 bit value

◆ optiga_common_set_uint32()

void optiga_common_set_uint32 ( uint8_t *  p_output_buffer,
uint32_t  four_byte_value 
)

Copies 4 bytes of uint32 [Big endian] type value to the buffer and stores in the output pointer.

Copies 4 bytes of uint32 [Big endian] type value to the buffer and store

  • Copies the 4 bytes value to input buffer in big endian format.
Precondition
  • None
Note
  • None
Parameters
[in,out]p_output_bufferPointer to the buffer
[in]four_byte_value32 bit value