This file implements cmd modules which covers OPTIGA command formation, locking mechanism, session acquisition and asynchronous data handling.
More...
|
#define | OFFSET (0x0000) |
|
#define | BYTES_TO_READ (0x0001) |
|
#define | GET_DATA_OBJECT_CMD (0x01) |
|
#define | PARAM (0x00) |
|
#define | PUBLIC_KEY_HOST ((public_key_from_host_t *)(p_optiga_encrypt_asym->key)) |
|
#define | OPTIGA_CMD_CLEAR_LAST_ERROR (0x80) |
|
#define | OPTIGA_CMD_OPEN_APPLICATION (0x70 | OPTIGA_CMD_CLEAR_LAST_ERROR) |
|
#define | OPTIGA_CMD_CLOSE_APPLICATION (0x71 | OPTIGA_CMD_CLEAR_LAST_ERROR) |
|
#define | OPTIGA_CMD_GET_DATA_OBJECT (0x01 | OPTIGA_CMD_CLEAR_LAST_ERROR) |
|
#define | OPTIGA_CMD_SET_DATA_OBJECT (0x02 | OPTIGA_CMD_CLEAR_LAST_ERROR) |
|
#define | OPTIGA_CMD_GET_RANDOM (0x0C | OPTIGA_CMD_CLEAR_LAST_ERROR) |
|
#define | OPTIGA_CMD_CALC_HASH (0x30 | OPTIGA_CMD_CLEAR_LAST_ERROR) |
|
#define | OPTIGA_CMD_CALC_SIGN (0x31 | OPTIGA_CMD_CLEAR_LAST_ERROR) |
|
#define | OPTIGA_CMD_VERIFY_SIGN (0x32 | OPTIGA_CMD_CLEAR_LAST_ERROR) |
|
#define | OPTIGA_CMD_CALC_SSEC (0x33 | OPTIGA_CMD_CLEAR_LAST_ERROR) |
|
#define | OPTIGA_CMD_DERIVE_KEY (0x34 | OPTIGA_CMD_CLEAR_LAST_ERROR) |
|
#define | OPTIGA_CMD_GEN_KEYPAIR (0x38 | OPTIGA_CMD_CLEAR_LAST_ERROR) |
|
#define | OPTIGA_CMD_ENCRYPT_ASYM (0x1E | OPTIGA_CMD_CLEAR_LAST_ERROR) |
|
#define | OPTIGA_CMD_DECRYPT_ASYM (0x1F | OPTIGA_CMD_CLEAR_LAST_ERROR) |
|
#define | OPTIGA_CMD_SET_OBJECT_PROTECTED (0x03 | OPTIGA_CMD_CLEAR_LAST_ERROR) |
|
#define | OPTIGA_CMD_MAX_NUMBER_OF_SESSIONS (0x04) |
|
#define | OPTIGA_CMD_START_SESSION_OID (0xE100) |
|
#define | OPTIGA_CMD_TOTAL_COMMS_BUFFER_SIZE (OPTIGA_MAX_COMMS_BUFFER_SIZE + OPTIGA_COMMS_PRL_OVERHEAD) |
|
#define | OPTIGA_CMD_APDU_HEADER_SIZE (0x04) |
|
#define | OPTIGA_CMD_LAST_ERROR_CODE (0xF1C2) |
|
#define | OPTIGA_CMD_APDU_INDATA_OFFSET (OPTIGA_CMD_APDU_HEADER_SIZE + OPTIGA_COMMS_DATA_OFFSET) |
|
#define | OPTIGA_CMD_HASH_HEADER_SIZE (0x06) |
|
#define | OPTIGA_CMD_INTERMEDIATE_CONTEX_HEADER (0x03) |
|
#define | OPTIGA_CMD_ZERO_LENGTH_OR_VALUE (0x0000) |
|
#define | OPTIGA_CMD_OID_DATA_LENGTH (0x0006) |
|
#define | OPTIGA_CMD_NO_OF_BYTES_IN_TAG (0x01) |
|
#define | OPTIGA_CMD_UINT16_SIZE_IN_BYTES (0x02) |
|
#define | START_OPTIGA_COMMS_CLOSE (0x02) |
|
#define | OPTIGA_CMD_APDU_SUCCESS (0x00) |
|
#define | OPTIGA_CMD_APDU_FAILURE (0xFF) |
|
#define | CMD_WRITE_ONLY (0x00) |
|
#define | CMD_READ_DATA (0x00) |
|
#define | CMD_GET_DATA_OBJECT_NO_ERROR_CLEAR (0x01) |
|
#define | CMD_SIGN_DIGEST_TAG (0x01) |
|
#define | CMD_SIGN_OID_TAG (0x03) |
|
#define | CMD_SIGN_OID_LEN (0x0002) |
|
#define | CMD_SSEC_PRIVATE_KEY_TAG (0x01) |
|
#define | CMD_SSEC_PRIVATE_KEY_LEN (0x0002) |
|
#define | CMD_SSEC_ALG_ID_TAG (0x05) |
|
#define | CMD_SSEC_ALG_ID_LEN (0x01) |
|
#define | CMD_SSEC_PUB_KEY_TAG (0x06) |
|
#define | CMD_SSEC_EXPORT_TAG (0x07) |
|
#define | CMD_SSEC_EXPORT_LEN (0x0000) |
|
#define | CMD_SSEC_STORE_SESSION_TAG (0x08) |
|
#define | CMD_SSEC_STORE_SESSION_LEN (0x0002) |
|
#define | CMD_VERIFY_SIGN_DIGEST_TAG (0x01) |
|
#define | CMD_VERIFY_SIGN_SIGNATURE_TAG (0x02) |
|
#define | CMD_VERIFY_SIGN_PUB_KEY_CERT_OID_TAG (0x04) |
|
#define | CMD_VERIFY_SIGN_PUB_KEY_CERT_OID_LENGTH (0x0002) |
|
#define | CMD_VERIFY_ALGO_ID_TAG (0x05) |
|
#define | CMD_VERIFY_ALGO_ID_LENGTH (0x0001) |
|
#define | CMD_VERIFY_PUBLIC_KEY_TAG (0x06) |
|
#define | CMD_GEN_KEY_PAIR_PRIVATE_KEY_OID_TAG (0x01) |
|
#define | CMD_GEN_KEY_PAIR_PRIVATE_KEY_OID_LENGTH (0x0002) |
|
#define | CMD_GEN_KEY_PAIR_KEY_USAGE_TAG (0x02) |
|
#define | CMD_GEN_KEY_PAIR_KEY_USAGE_LENGTH (0x0001) |
|
#define | CMD_GEN_KEY_PAIR_EXPORT_KEY_TAG (0x07) |
|
#define | CMD_GEN_KEY_PAIR_EXPORT_KEY_LENGTH (0x0000) |
|
#define | CMD_GEN_KEY_PAIR_PUBLIC_KEY_TAG (0x02) |
|
#define | CMD_GEN_KEY_PAIR_PRIVATE_KEY_TAG (0x01) |
|
#define | CMD_DERIVE_KEY_SEC_OID_TAG (0x01) |
|
#define | CMD_DERIVE_KEY_SEC_OID_TAG_LENGTH (0x0002) |
|
#define | CMD_DERIVE_KEY_DERIVATION_DATA_TAG (0x02) |
|
#define | CMD_DERIVE_KEY_KEY_LEN_TAG_LENGTH (0x0002) |
|
#define | CMD_DERIVE_KEY_KEY_LEN_TAG (0x03) |
|
#define | CMD_DERIVE_KEY_EXPORT_TAG (0x07) |
|
#define | CMD_DERIVE_KEY_STORE_TAG (0x08) |
|
#define | CMD_DERIVE_KEY_STORE_TAG_LENGTH (0x0002) |
|
#define | CMD_DERIVE_KEY_DERIVE_KEY_LEN_MIN (0x10) |
|
#define | CMD_ENCRYPT_ASYM_SESSION_OID_TAG (0x02) |
|
#define | CMD_ENCRYPT_ASYM_SESSION_OID_LENGTH (0x0002) |
|
#define | CMD_ENCRYPT_ASYM_MESSAGE_TAG (0x61) |
|
#define | CMD_ENCRYPT_ASYM_PUB_KEY_CERT_OID_TAG (0x04) |
|
#define | CMD_ENCRYPT_ASYM_PUB_KEY_CERT_OID_LENGTH (0x0002) |
|
#define | CMD_ENCRYPT_ASYM_ALGO_ID_TAG (0x05) |
|
#define | CMD_ENCRYPT_ASYM_ALGO_ID_LENGTH (0x0001) |
|
#define | CMD_ENCRYPT_ASYM_PUBLIC_KEY_TAG (0x06) |
|
#define | CMD_DECRYPT_ASYM_ENCRYPT_MESSAGE_TAG (0x61) |
|
#define | CMD_DECRYPT_ASYM_DECRYPT_KEY_TAG (0x03) |
|
#define | CMD_DECRYPT_ASYM_DECRYPT_KEY_LENGTH (0x0002) |
|
#define | CMD_DECRYPT_ASYM_SESSION_OID_TAG (0x02) |
|
#define | CMD_DECRYPT_ASYM_SESSION_OID_LENGTH (0x0002) |
|
#define | OPTIGA_PROTECTION_LEVEL_MASK (0x03) |
|
#define | OPTIGA_CMD_ERROR_CODE_PREPARE (0x01) |
|
#define | OPTIGA_CMD_ERROR_CODE_TX (0x02) |
|
#define | OPTIGA_CMD_ERROR_CODE_RX (0x03) |
|
#define | OPTIGA_CMD_ERROR_CODE_STATE_MASK (0x03) |
|
#define | OPTIGA_CMD_ENTER_HANDLER_CALL_MASK (0x80) |
|
#define | OPTIGA_CMD_ENTER_HANDLER_CALL (0x80) |
|
#define | OPTIGA_CMD_EXIT_HANDLER_CALL (0x00) |
|
#define | OPTIGA_CMD_OUT_OF_BOUNDARY_ERROR (0x08) |
|
#define | CMD_RSA_PRE_MASTER_OPTIONAL_DATA_TAG (0x41) |
|
#define | CMD_RANDOM_PARAM_TYPE_PRE_MASTER_SECRET (0x04) |
| Param type for optiga pre master secret. More...
|
|
#define | CMD_SET_OBJECT_PROTECTED_TAG (0x30) |
| Set object protected tag. More...
|
|
#define | OPTIGA_CMD_APDU_TL_LENGTH (0x03) |
|
#define | OPTIGA_CMD_PARAM_INITIALIZE_APP_CONTEXT (0x00) |
|
#define | SET_DEV_ERROR_HANDLER_STATE(state) |
|
#define | SET_DEV_ERROR_NOTIFICATION(bits_value) |
|
#define | EXIT_STATE_WITH_ERROR(ctx, exit_machine) |
|
#define | OPTIGA_CMD_QUEUE_NOT_ASSIGNED (0x00) |
|
#define | OPTIGA_CMD_QUEUE_ASSIGNED (0x01) |
|
#define | OPTIGA_CMD_QUEUE_REQUEST (0x02) |
|
#define | OPTIGA_CMD_QUEUE_PROCESSING (0x04) |
|
#define | OPTIGA_CMD_QUEUE_RESUME (0x08) |
|
#define | OPTIGA_CMD_SESSION_NOT_ASSIGNED (0x00) |
|
#define | OPTIGA_CMD_SESSION_ASSIGNED (0x10) |
|
#define | OPTIGA_CMD_NO_SESSION_OID (0x0000) |
|
#define | OPTIGA_CMD_ALL_SESSION_ASSIGNED (0x10101010) |
|
#define | OPTIGA_CMD_QUEUE_REQUEST_LOCK (0x21) |
|
#define | OPTIGA_CMD_QUEUE_REQUEST_STRICT_LOCK (0x23) |
|
#define | OPTIGA_CMD_QUEUE_REQUEST_SESSION (0x22) |
|
#define | OPTIGA_CMD_QUEUE_NO_REQUEST (0x00) |
|
#define | OPTIGA_CMD_QUEUE_SLOT_STATE (0x09) |
|
#define | OPTIGA_CMD_QUEUE_SLOT_LOCK_TYPE (0x08) |
|
#define | OPTIGA_CMD_SCHEDULER_IDLING_TIME_MS (1000U) |
|
#define | OPTIGA_CMD_SCHEDULER_RUNNING_TIME_MS (50U) |
|
enum | optiga_cmd_state {
OPTIGA_CMD_EXEC_COMMS_OPEN = 0,
OPTIGA_CMD_EXEC_COMMS_OPEN_START,
OPTIGA_CMD_EXEC_COMMS_OPEN_DONE,
OPTIGA_CMD_EXEC_COMMS_CLOSE_START,
OPTIGA_CMD_EXEC_COMMS_CLOSE_DONE,
OPTIGA_CMD_EXEC_REQUEST_SESSION,
OPTIGA_CMD_EXEC_REQUEST_LOCK,
OPTIGA_CMD_EXEC_REQUEST_STRICT_LOCK,
OPTIGA_CMD_EXEC_PREPARE_COMMAND,
OPTIGA_CMD_EXEC_PROCESS_RESPONSE,
OPTIGA_CMD_EXEC_GET_DEVICE_ERROR,
OPTIGA_CMD_EXEC_RELEASE_LOCK,
OPTIGA_CMD_STATE_EXIT
} |
| The enum represents diffrent state of command handler. More...
|
|
typedef enum optiga_cmd_state | optiga_cmd_state_t |
| The enum represents diffrent state of command handler. More...
|
|
typedef optiga_lib_status_t(* | optiga_cmd_handler_t) (optiga_cmd_t *me) |
|
typedef struct optiga_cmd_queue_slot | optiga_cmd_queue_slot_t |
| The structure represents the slot in the execution queue. More...
|
|
_STATIC_H optiga_context_t | g_optiga = {0} |
|
_STATIC_H optiga_context_t * | g_optiga_list [] = {&g_optiga} |
|
_STATIC_H uint16_t | g_hibernate_datastore_id_list [] = {OPTIGA_HIBERNATE_CONTEXT_ID} |
|
const uint8_t | g_optiga_unique_application_identifier [] |
|
_STATIC_H optiga_lib_status_t | optiga_cmd_get_error_code_handler (optiga_cmd_t *me) |
|
void | optiga_cmd_set_shielded_connection_option (optiga_cmd_t *me, uint8_t value, uint8_t shielded_connection_option) |
|
_STATIC_H void | optiga_cmd_execute (optiga_cmd_t *me, uint8_t cmd_param, optiga_cmd_handler_t cmd_hdlrs, optiga_cmd_state_t start_state, void *input) |
|
_STATIC_H void | optiga_cmd_execute_handler (void *p_ctx, optiga_lib_status_t event) |
|
_STATIC_H void | optiga_cmd_prepare_apdu_header (uint8_t cmd, uint8_t param, uint16_t in_data_length, uint8_t *p_apdu_buffer) |
|
_STATIC_H void | optiga_cmd_prepare_tag_header (uint8_t tag, uint16_t tag_length, uint8_t *buffer, uint16_t *position) |
|
_STATIC_H void | optiga_cmd_event_trigger_execute (void *p_ctx) |
|
_STATIC_H bool_t | optiga_cmd_session_available (const optiga_context_t *p_optiga) |
|
_STATIC_H void | optiga_cmd_session_assign (optiga_cmd_t *me) |
|
_STATIC_H void | optiga_cmd_session_free (optiga_cmd_t *me) |
|
_STATIC_H uint8_t | optiga_cmd_queue_get_state_of (const optiga_cmd_t *me, uint8_t slot_member) |
|
_STATIC_H uint8_t | optiga_cmd_queue_get_count_of (const optiga_context_t *p_optiga, uint8_t slot_member, uint8_t state_to_check) |
|
_STATIC_H void | optiga_cmd_queue_assign_slot (const optiga_cmd_t *me, uint8_t *queue_index_store) |
|
_STATIC_H void | optiga_cmd_queue_deassign_slot (optiga_cmd_t *me) |
|
_STATIC_H void | optiga_cmd_queue_scheduler (void *p_optiga) |
|
_STATIC_H void | optiga_cmd_queue_update_slot (optiga_cmd_t *me, uint8_t request_type) |
|
_STATIC_H void | optiga_cmd_queue_reset_slot (const optiga_cmd_t *me) |
|
optiga_lib_status_t | optiga_cmd_request_session (optiga_cmd_t *me) |
|
optiga_lib_status_t | optiga_cmd_release_session (optiga_cmd_t *me) |
|
optiga_lib_status_t | optiga_cmd_request_lock (optiga_cmd_t *me, uint8_t lock_type) |
|
optiga_lib_status_t | optiga_cmd_release_lock (const optiga_cmd_t *me) |
| Releases the OPTIGA cmd lock. More...
|
|
_STATIC_H optiga_lib_status_t | optiga_cmd_restore_context (const optiga_cmd_t *me) |
|
_STATIC_H optiga_lib_status_t | optiga_cmd_store_context (const optiga_cmd_t *me) |
|
optiga_cmd_t * | optiga_cmd_create (uint8_t optiga_instance_id, callback_handler_t handler, void *caller_context) |
| Creates an instance of optiga_cmd_t. More...
|
|
optiga_lib_status_t | optiga_cmd_destroy (optiga_cmd_t *me) |
| Destroys the instance of optiga_cmd_t. More...
|
|
_STATIC_H optiga_lib_status_t | optiga_cmd_open_application_handler (optiga_cmd_t *me) |
|
optiga_lib_status_t | optiga_cmd_open_application (optiga_cmd_t *me, uint8_t cmd_param, void *params) |
| Opens the OPTIGA Application. More...
|
|
_STATIC_H optiga_lib_status_t | optiga_cmd_close_application_handler (optiga_cmd_t *me) |
|
optiga_lib_status_t | optiga_cmd_close_application (optiga_cmd_t *me, uint8_t cmd_param, void *params) |
| Closes the OPTIGA Application. More...
|
|
_STATIC_H optiga_lib_status_t | optiga_cmd_get_data_object_handler (optiga_cmd_t *me) |
|
optiga_lib_status_t | optiga_cmd_get_data_object (optiga_cmd_t *me, uint8_t cmd_param, optiga_get_data_object_params_t *params) |
| Reads data or metadata of the specified data object. More...
|
|
_STATIC_H optiga_lib_status_t | optiga_cmd_set_data_object_handler (optiga_cmd_t *me) |
|
optiga_lib_status_t | optiga_cmd_set_data_object (optiga_cmd_t *me, uint8_t cmd_param, optiga_set_data_object_params_t *params) |
| Writes data or metadata to the specified data object. More...
|
|
_STATIC_H optiga_lib_status_t | optiga_cmd_get_random_handler (optiga_cmd_t *me) |
|
optiga_lib_status_t | optiga_cmd_get_random (optiga_cmd_t *me, uint8_t cmd_param, optiga_get_random_params_t *params) |
| Generates random data or pre-master secret for RSA key exchange. More...
|
|
_STATIC_H optiga_lib_status_t | optiga_cmd_calc_sign_handler (optiga_cmd_t *me) |
|
optiga_lib_status_t | optiga_cmd_calc_sign (optiga_cmd_t *me, uint8_t cmd_param, optiga_calc_sign_params_t *params) |
| Calculate signature on digest. More...
|
|
_STATIC_H optiga_lib_status_t | optiga_cmd_verify_sign_handler (optiga_cmd_t *me) |
|
optiga_lib_status_t | optiga_cmd_verify_sign (optiga_cmd_t *me, uint8_t cmd_param, optiga_verify_sign_params_t *params) |
| Verifies the signature over the given digest. More...
|
|
_STATIC_H optiga_lib_status_t | optiga_cmd_calc_ssec_handler (optiga_cmd_t *me) |
|
optiga_lib_status_t | optiga_cmd_calc_ssec (optiga_cmd_t *me, uint8_t cmd_param, optiga_calc_ssec_params_t *params) |
| Calculates shared secret. More...
|
|
_STATIC_H optiga_lib_status_t | optiga_cmd_derive_key_handler (optiga_cmd_t *me) |
|
optiga_lib_status_t | optiga_cmd_derive_key (optiga_cmd_t *me, uint8_t cmd_param, optiga_derive_key_params_t *params) |
| Derives a key. More...
|
|
_STATIC_H optiga_lib_status_t | optiga_cmd_gen_keypair_handler (optiga_cmd_t *me) |
|
optiga_lib_status_t | optiga_cmd_gen_keypair (optiga_cmd_t *me, uint8_t cmd_param, optiga_gen_keypair_params_t *params) |
| Generates ECC or RSA key-pair. More...
|
|
_STATIC_H optiga_lib_status_t | optiga_cmd_encrypt_asym_handler (optiga_cmd_t *me) |
|
optiga_lib_status_t | optiga_cmd_encrypt_asym (optiga_cmd_t *me, uint8_t cmd_param, optiga_encrypt_asym_params_t *params) |
| Encrypt data using RSA public key. More...
|
|
_STATIC_H optiga_lib_status_t | optiga_cmd_decrypt_asym_handler (optiga_cmd_t *me) |
|
optiga_lib_status_t | optiga_cmd_decrypt_asym (optiga_cmd_t *me, uint8_t cmd_param, optiga_decrypt_asym_params_t *params) |
| Decrypts data using OPTIGA RSA private key. More...
|
|
_STATIC_H optiga_lib_status_t | optiga_cmd_calc_hash_handler (optiga_cmd_t *me) |
|
optiga_lib_status_t | optiga_cmd_calc_hash (optiga_cmd_t *me, uint8_t cmd_param, optiga_calc_hash_params_t *params) |
| Generates hash on external data or data in OID. More...
|
|
_STATIC_H optiga_lib_status_t | optiga_cmd_set_object_protected_handler (optiga_cmd_t *me) |
|
optiga_lib_status_t | optiga_cmd_set_object_protected (optiga_cmd_t *me, uint8_t cmd_param, optiga_set_object_protected_params_t *params) |
| Writes protected object fragments to OPTIGA. More...
|
|
This file implements cmd modules which covers OPTIGA command formation, locking mechanism, session acquisition and asynchronous data handling.
- Copyright
- MIT License
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