OPTIGA Trust M  1.1.0
C++ library for Optiga Trust M Chip Security Controller
optiga_lib_common.h
Go to the documentation of this file.
1 
38 #ifndef _OPTIGA_LIB_COMMON_H_
39 #define _OPTIGA_LIB_COMMON_H_
40 
41 #ifdef __cplusplus
42 extern "C" {
43 #endif
44 
45 #include "optiga_lib_config.h"
46 #include "optiga_lib_types.h"
48 
50 #define OPTIGA_INSTANCE_ID_0 (0x00)
51 
53 #define OPTIGA_COMMS_NO_PROTECTION (0x00)
54 
55 #define OPTIGA_COMMS_COMMAND_PROTECTION (0x01)
56 
57 #define OPTIGA_COMMS_RESPONSE_PROTECTION (0x02)
58 
59 #define OPTIGA_COMMS_FULL_PROTECTION (0x03)
60 
61 #define OPTIGA_COMMS_RE_ESTABLISH (0x80)
62 
63 #define OPTIGA_COMMS_PROTOCOL_VERSION_PRE_SHARED_SECRET (0x01)
64 
66 #define OPTIGA_CRYPT_HOST_DATA (0x01)
67 
68 #define OPTIGA_CRYPT_OID_DATA (0x00)
69 
71 #define OPTIGA_LIB_INSTANCE_BUSY (0x0001)
72 
73 #define OPTIGA_LIB_INSTANCE_FREE (0x0000)
74 
75 #ifdef OPTIGA_COMMS_SHIELDED_CONNECTION
76 
77 #define OPTIGA_COMMS_PROTECTION_LEVEL (0x01)
78 
79 #define OPTIGA_COMMS_PROTOCOL_VERSION (0x02)
80 #endif
81 
85 typedef enum optiga_key_id
86 {
102 
106 typedef enum optiga_key_usage
107 {
117 
122 {
130 
134 typedef enum optiga_ecc_curve
135 {
141 
146 {
150 
155 {
161 
162 
167 {
173 
177 typedef enum optiga_hash_type
178 {
182 
186 typedef enum optiga_rng_type
187 {
193 
199 typedef struct optiga_hash_context
200 {
202  uint8_t *context_buffer;
206  uint8_t hash_algo;
208 
212 typedef struct hash_data_from_host
213 {
215  const uint8_t * buffer;
217  uint32_t length;
219 
223 typedef struct hash_data_in_optiga
224 {
226  uint16_t oid;
228  uint16_t offset;
230  uint16_t length;
232 
236 typedef struct public_key_from_host
237 {
239  uint8_t * public_key;
241  uint16_t length;
243  uint8_t key_type;
245 
246 
247 
252 {
254  uint16_t oid;
256  uint16_t offset;
258  uint16_t bytes_to_read;
262  uint16_t last_read_size;
266  uint16_t * ref_bytes_to_read;
268  uint8_t * buffer;
270 
275 {
277  uint16_t oid;
279  uint16_t offset;
281  uint16_t size;
283  uint16_t written_size;
285  const uint8_t * buffer;
289  uint8_t write_type;
291  uint8_t count;
293 
297 typedef struct optiga_calc_hash
298 {
306  uint8_t hash_sequence;
310  uint32_t data_sent;
312  uint8_t * p_out_digest;
318 
319 
323 typedef struct optiga_get_random
324 {
330  uint8_t * random_data;
332  const uint8_t * optional_data;
334 
335 
339 typedef struct optiga_gen_keypair
340 {
342  uint8_t key_usage;
348  uint8_t * private_key;
350  uint16_t * private_key_length;
352  uint8_t * public_key;
354  uint16_t * public_key_length;
356 
360 typedef struct optiga_calc_sign
361 {
363  const uint8_t * p_digest;
365  uint8_t * p_signature;
367  uint16_t * p_signature_length;
371  uint8_t digest_length;
373 
377 typedef struct optiga_verify_sign
378 {
380  const uint8_t * p_digest;
382  uint8_t digest_length;
384  const uint8_t * p_signature;
392  uint16_t certificate_oid;
394 
398 typedef struct optiga_calc_ssec
399 {
403  uint8_t * shared_secret;
407  uint8_t export_to_host;
409 
413 typedef struct optiga_derive_key
414 {
418  uint16_t label_length;
420  uint16_t seed_length;
424  const uint8_t * seed;
426  const uint8_t * label;
428  uint8_t * derived_key;
430 
434 typedef struct optiga_enc_dec_asym
435 {
437  uint16_t message_length;
441  const uint8_t * message;
445  const void * key;
447  uint8_t * processed_message;
451 
452 
453 
458 {
460  const uint8_t * p_protected_update_buffer;
468 
487 uint32_t optiga_common_get_uint32 (const uint8_t* p_input_buffer);
488 
506 void optiga_common_set_uint16 (uint8_t * p_output_buffer,
507  uint16_t two_byte_value);
508 
526 void optiga_common_set_uint32 (uint8_t* p_output_buffer,
527  uint32_t four_byte_value);
528 
546 void optiga_common_get_uint16 (const uint8_t * p_input_buffer,
547  uint16_t* p_two_byte_value);
548 
549 #ifdef __cplusplus
550 }
551 #endif
552 
553 #endif /*_OPTIGA_LIB_COMMON_H_ */
554 
uint16_t length
Length of public key buffer.
Definition: optiga_lib_common.h:241
uint16_t * p_signature_length
Signature length.
Definition: optiga_lib_common.h:367
uint8_t hash_algo
hashing algorithm
Definition: optiga_lib_common.h:206
Specifies the data structure of the Public Key details (key, size and type)
Definition: optiga_lib_common.h:236
optiga_rsa_signature_scheme
Specifies the RSA signature schemes type in OPTIGA.
Definition: optiga_lib_common.h:166
bool_t chaining_status
Chaining status.
Definition: optiga_lib_common.h:314
optiga_key_id_t private_key_oid
OID of the Private Key (either Key store or Session based). Refer optiga_key_id_t for possible values...
Definition: optiga_lib_common.h:369
uint16_t offset
Offset of data with the object ID.
Definition: optiga_lib_common.h:279
const uint8_t * optional_data
user buffer which holds the optional data
Definition: optiga_lib_common.h:332
uint8_t * derived_key
Pointer to a buffer where the exported key to be stored.
Definition: optiga_lib_common.h:428
optiga_key_id_t private_key_oid
Type of public key OID.
Definition: optiga_lib_common.h:346
const uint8_t * p_protected_update_buffer
Pointer to the buffer which contains manifest/fragment.
Definition: optiga_lib_common.h:460
uint8_t * processed_message
Pointer to buffer where encrypted or decrypted message is stored.
Definition: optiga_lib_common.h:447
struct optiga_calc_hash optiga_calc_hash_params_t
Specifies the data structure of calculate hash.
const void * key
Public key provided by host.
Definition: optiga_lib_common.h:445
Key from key store for RSA (non-volatile)
Definition: optiga_lib_common.h:96
Specifies the structure to provide the details of data to be hashed from host.
Definition: optiga_lib_common.h:212
enum optiga_hash_type optiga_hash_type_t
Specifies the hashing algorithm type in OPTIGA.
enum optiga_rsa_signature_scheme optiga_rsa_signature_scheme_t
Specifies the RSA signature schemes type in OPTIGA.
optiga_rsa_key_type
Specifies the RSA key type in OPTIGA.
Definition: optiga_lib_common.h:154
uint8_t count
Count value.
Definition: optiga_lib_common.h:291
const uint8_t * p_digest
Digest buffer pointer.
Definition: optiga_lib_common.h:380
optiga_hash_context_t * p_hash_context
Context buffer pointer.
Definition: optiga_lib_common.h:304
optiga_set_obj_protected_tag
Specifies the set protected object tag.
Definition: optiga_lib_common.h:121
Key from key store (non-volatile)
Definition: optiga_lib_common.h:94
uint16_t * private_key_length
Private key length.
Definition: optiga_lib_common.h:350
uint16_t random_data_length
Random data length.
Definition: optiga_lib_common.h:326
optiga_rsa_encryption_scheme
Specifies the RSA encryption schemes.
Definition: optiga_lib_common.h:145
uint16_t oid
Object ID to be written.
Definition: optiga_lib_common.h:277
This enables the private key for the signature generation.
Definition: optiga_lib_common.h:111
const uint8_t * p_digest
Digest buffer pointer.
Definition: optiga_lib_common.h:363
const uint8_t * seed
Random Seed.
Definition: optiga_lib_common.h:424
Specifies the structure to provide the details of data to be hashed from OPTIGA.
Definition: optiga_lib_common.h:223
const uint8_t * message
Message to be encrypted. Set NULL if data from session OID.
Definition: optiga_lib_common.h:441
Signature schemes RSA SSA PKCS1-v1.5 with SHA384 digest.
Definition: optiga_lib_common.h:171
Generate Random data using TRNG.
Definition: optiga_lib_common.h:189
uint8_t source_of_data_to_hash
Type of data to be hash.
Definition: optiga_lib_common.h:308
enum optiga_rsa_key_type optiga_rsa_key_type_t
Specifies the RSA key type in OPTIGA.
Generate elliptic curve key based on NIST P384.
Definition: optiga_lib_common.h:139
uint16_t offset
Offset of data with the object ID.
Definition: optiga_lib_common.h:256
Generate Random data using DRNG.
Definition: optiga_lib_common.h:191
uint16_t context_buffer_length
context length
Definition: optiga_lib_common.h:204
struct optiga_enc_dec_asym optiga_decrypt_asym_params_t
uint8_t * private_key
Private key buffer pointer.
Definition: optiga_lib_common.h:348
uint16_t oid
Object ID to be read.
Definition: optiga_lib_common.h:254
uint16_t message_length
Length of message to be encrypted. Set 0 if data from session OID.
Definition: optiga_lib_common.h:437
Specifies the structure for derivation of key using pseudo random function.
Definition: optiga_lib_common.h:413
uint16_t size
Write data size.
Definition: optiga_lib_common.h:281
Key from key store for RSA (non-volatile)
Definition: optiga_lib_common.h:98
This file contains the type definitions for the fundamental data types.
public_key_from_host_t * public_key
Public Key of the peer.
Definition: optiga_lib_common.h:401
uint16_t p_protected_update_buffer_length
Manifest/Fragment length.
Definition: optiga_lib_common.h:462
uint16_t signature_length
Signature data length.
Definition: optiga_lib_common.h:386
struct public_key_from_host public_key_from_host_t
Specifies the data structure of the Public Key details (key, size and type)
hash_data_in_optiga_t * p_hash_oid
OID hash pointer.
Definition: optiga_lib_common.h:300
uint8_t * p_signature
Signature buffer pointer.
Definition: optiga_lib_common.h:365
This enables to finish of the protected update.
Definition: optiga_lib_common.h:128
This enables to start of the protected update.
Definition: optiga_lib_common.h:124
uint16_t optional_data_length
Optional data length.
Definition: optiga_lib_common.h:328
Key from key store (non-volatile)
Definition: optiga_lib_common.h:88
uint8_t bool_t
Typedef for a boolean.
Definition: optiga_lib_types.h:91
uint16_t label_length
Label length.
Definition: optiga_lib_common.h:418
enum optiga_ecc_curve optiga_ecc_curve_t
Specifies the key curve type in OPTIGA.
optiga_key_usage
Specifies the key usage type in OPTIGA.
Definition: optiga_lib_common.h:106
enum optiga_set_obj_protected_tag optiga_set_obj_protected_tag_t
Specifies the set protected object tag.
uint16_t input_shared_secret_oid
Session based (optiga_key_id_t) or Data object which has the pre-shared secret.
Definition: optiga_lib_common.h:416
const uint8_t * label
Label input as a constant string.
Definition: optiga_lib_common.h:426
uint16_t seed_length
Random Seed length.
Definition: optiga_lib_common.h:420
Generate 1024 bit RSA key.
Definition: optiga_lib_common.h:157
struct optiga_calc_sign optiga_calc_sign_params_t
Specifies the data structure for ECDSA signature.
uint16_t offset
Offset within the data object.
Definition: optiga_lib_common.h:228
hash_data_from_host_t * p_hash_data
Data buffer pointer.
Definition: optiga_lib_common.h:302
const uint8_t * buffer
data to hash
Definition: optiga_lib_common.h:215
uint8_t * shared_secret
Pointer to a buffer where the exported shared secret to be stored.
Definition: optiga_lib_common.h:403
uint8_t manifest_version
manifest version
Definition: optiga_lib_common.h:466
struct optiga_set_data_object optiga_set_data_object_params_t
Specifies the data structure for data to be written to OPTIGA.
Generate 2048 bit RSA key.
Definition: optiga_lib_common.h:159
struct optiga_calc_ssec optiga_calc_ssec_params_t
Specifies the data structure for ecdh secret generation.
uint8_t * public_key
Public key buffer pointer.
Definition: optiga_lib_common.h:352
Key from key store (non-volatile)
Definition: optiga_lib_common.h:90
uint32_t optiga_common_get_uint32(const uint8_t *p_input_buffer)
Prepares uint32 [Big endian] type value from the buffer and store.
Definition: optiga_lib_common.c:41
Specifies the data structure for data to be written to OPTIGA.
Definition: optiga_lib_common.h:274
Specifies the data structure for data to be read from OPTIGA.
Definition: optiga_lib_common.h:251
uint8_t public_key_source_type
Source of provided public key.
Definition: optiga_lib_common.h:388
struct optiga_gen_keypair optiga_gen_keypair_params_t
Specifies the data structure for generate key pair.
enum optiga_key_usage optiga_key_usage_t
Specifies the key usage type in OPTIGA.
uint32_t data_sent
Data length has been sent.
Definition: optiga_lib_common.h:310
uint32_t apparent_context_size
Possible context size to send in a fragment.
Definition: optiga_lib_common.h:316
uint8_t * random_data
user buffer for storing random data
Definition: optiga_lib_common.h:330
optiga_key_id
Specifies the key location in OPTIGA.
Definition: optiga_lib_common.h:85
uint16_t * ref_bytes_to_read
Pointer to the read buffer length.
Definition: optiga_lib_common.h:266
const uint8_t * buffer
Wrtie data buffer pointer.
Definition: optiga_lib_common.h:285
uint8_t key_usage
Key usage type.
Definition: optiga_lib_common.h:342
uint16_t last_read_size
Contains the data length received in last transceive. Used for chaining purpose.
Definition: optiga_lib_common.h:262
struct optiga_get_data_object optiga_get_data_object_params_t
Specifies the data structure for data to be read from OPTIGA.
Specifies the data structure for generate key pair.
Definition: optiga_lib_common.h:339
uint16_t derived_key_length
Derived Key length.
Definition: optiga_lib_common.h:422
optiga_hash_type
Specifies the hashing algorithm type in OPTIGA.
Definition: optiga_lib_common.h:177
Specifies the data structure for ecdh secret generation.
Definition: optiga_lib_common.h:398
uint8_t write_type
Type of write - Write only or Erase and write.
Definition: optiga_lib_common.h:289
Key from key store (non-volatile)
Definition: optiga_lib_common.h:92
struct optiga_verify_sign optiga_verify_sign_params_t
Specifies the data structure for ECDSA signature verification.
Specifies the data structure for ECDSA signature verification.
Definition: optiga_lib_common.h:377
uint16_t certificate_oid
Public key certificate OID.
Definition: optiga_lib_common.h:392
struct hash_data_in_optiga hash_data_in_optiga_t
Specifies the structure to provide the details of data to be hashed from OPTIGA.
uint8_t export_to_host
Export to Host (store in OPTIGA Session or export to host)
Definition: optiga_lib_common.h:407
This enables the private key for the signature generation as part of authentication commands.
Definition: optiga_lib_common.h:109
uint16_t * public_key_length
Public key length.
Definition: optiga_lib_common.h:354
uint16_t * processed_message_length
Pointer to the length of the encrypted or decrypted message.
Definition: optiga_lib_common.h:439
Hash algorithm type SHA256.
Definition: optiga_lib_common.h:180
enum optiga_key_id optiga_key_id_t
Specifies the key location in OPTIGA.
const uint8_t * p_signature
Signature buffer pointer.
Definition: optiga_lib_common.h:384
uint8_t * p_out_digest
Out digest.
Definition: optiga_lib_common.h:312
public_key_from_host_t * public_key
Public key provided by host.
Definition: optiga_lib_common.h:390
uint16_t oid
OID of data object.
Definition: optiga_lib_common.h:226
optiga_key_id_t private_key
OID of the Private Key (either Key store or Session based). Refer optiga_key_id_t for possible values...
Definition: optiga_lib_common.h:405
This file defines the error codes for the all the layers and modules. OPTIGA host library return val...
uint8_t digest_length
Digest data length.
Definition: optiga_lib_common.h:371
enum optiga_rng_type optiga_rng_type_t
Specifies the random generation types.
struct optiga_hash_context optiga_hash_context_t
Specifies the structure to the Hash context details managed by OPTIGA.
Specifies the structure for asymmetric encryption and decryption.
Definition: optiga_lib_common.h:434
Signature schemes RSA SSA PKCS1-v1.5 with SHA256 digest.
Definition: optiga_lib_common.h:169
optiga_ecc_curve
Specifies the key curve type in OPTIGA.
Definition: optiga_lib_common.h:134
Specifies the data structure for protected update.
Definition: optiga_lib_common.h:457
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.
Definition: optiga_lib_common.c:64
Generate elliptic curve key based on NIST P256.
Definition: optiga_lib_common.h:137
Key from session (volatile)
Definition: optiga_lib_common.h:100
Specifies the data structure of calculate hash.
Definition: optiga_lib_common.h:297
struct optiga_derive_key optiga_derive_key_params_t
Specifies the structure for derivation of key using pseudo random function.
This enables to continue of the protected update.
Definition: optiga_lib_common.h:126
Specifies the data structure for ECDSA signature.
Definition: optiga_lib_common.h:360
uint8_t data_or_metadata
Write to data or metadata.
Definition: optiga_lib_common.h:287
struct optiga_get_random optiga_get_random_params_t
Specifies the data structure of random generation.
uint16_t written_size
Contains length of data written in across multiple transceive calls. Used for chaining purpose.
Definition: optiga_lib_common.h:283
RSA PKCS1 v1.5 encryption scheme.
Definition: optiga_lib_common.h:148
optiga_set_obj_protected_tag_t set_obj_protected_tag
Set protected object tag.
Definition: optiga_lib_common.h:464
uint16_t accumulated_size
Contains length of data received in across multiple transceive calls. Used for chaining purpose.
Definition: optiga_lib_common.h:260
uint8_t hash_sequence
Type of hash operation.
Definition: optiga_lib_common.h:306
uint32_t length
Length of data.
Definition: optiga_lib_common.h:217
Specifies the structure to the Hash context details managed by OPTIGA.
Definition: optiga_lib_common.h:199
struct optiga_set_object_protected_params optiga_set_object_protected_params_t
Specifies the data structure for protected update.
This file is defines the compilation switches to build code with required features.
uint8_t * public_key
Pointer to Public Key.
Definition: optiga_lib_common.h:239
bool_t export_private_key
Private key export option.
Definition: optiga_lib_common.h:344
uint8_t * context_buffer
buffer to hold the hash context data
Definition: optiga_lib_common.h:202
enum optiga_rsa_encryption_scheme optiga_rsa_encryption_scheme_t
Specifies the RSA encryption schemes.
uint8_t public_key_source_type
Source of provided public key for encryption and Private key for decryption.
Definition: optiga_lib_common.h:443
struct hash_data_from_host hash_data_from_host_t
Specifies the structure to provide the details of data to be hashed from host.
uint16_t bytes_to_read
Data size to be read.
Definition: optiga_lib_common.h:258
This enables the private key for encrypt and decrypt.
Definition: optiga_lib_common.h:115
uint16_t length
Number of data bytes starting from the offset.
Definition: optiga_lib_common.h:230
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.
Definition: optiga_lib_common.c:56
uint8_t data_or_metadata
Read to data or metadata.
Definition: optiga_lib_common.h:264
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.
Definition: optiga_lib_common.c:50
uint8_t * buffer
Read data buffer pointer.
Definition: optiga_lib_common.h:268
optiga_key_id_t private_key_id
Store private key OID.
Definition: optiga_lib_common.h:449
struct optiga_enc_dec_asym optiga_encrypt_asym_params_t
Specifies the structure for asymmetric encryption and decryption.
optiga_rng_type
Specifies the random generation types.
Definition: optiga_lib_common.h:186
Specifies the data structure of random generation.
Definition: optiga_lib_common.h:323
This enables the private key for key agreement (e.g. ecdh operations)
Definition: optiga_lib_common.h:113
uint8_t key_type
Public key type details. For ECC key use optiga_ecc_curve_t and for RSA key use optiga_rsa_key_type_t...
Definition: optiga_lib_common.h:243
uint8_t digest_length
Digest data length.
Definition: optiga_lib_common.h:382