38 #ifndef _OPTIGA_CRYPT_H_ 39 #define _OPTIGA_CRYPT_H_ 81 #ifdef OPTIGA_COMMS_SHIELDED_CONNECTION 86 #endif //OPTIGA_COMMS_SHIELDED_CONNECTION 93 #ifdef OPTIGA_COMMS_SHIELDED_CONNECTION 121 uint8_t configuration_type,
179 #ifdef OPTIGA_CRYPT_RANDOM_ENABLED 217 uint8_t * random_data,
218 uint16_t random_data_length);
219 #endif //OPTIGA_CRYPT_RANDOM_ENABLED 221 #ifdef OPTIGA_CRYPT_HASH_ENABLED 295 uint8_t source_of_data_to_hash,
296 const void * data_to_hash);
333 uint8_t * hash_output);
334 #endif //OPTIGA_CRYPT_HASH_ENABLED 337 #ifdef OPTIGA_CRYPT_ECC_GENERATE_KEYPAIR_ENABLED 382 bool_t export_private_key,
384 uint8_t * public_key,
385 uint16_t * public_key_length);
386 #endif //OPTIGA_CRYPT_ECC_GENERATE_KEYPAIR_ENABLED 388 #ifdef OPTIGA_CRYPT_ECDSA_SIGN_ENABLED 425 const uint8_t * digest,
426 uint8_t digest_length,
429 uint16_t * signature_length);
430 #endif //OPTIGA_CRYPT_ECDSA_SIGN_ENABLED 432 #ifdef OPTIGA_CRYPT_ECDSA_VERIFY_ENABLED 471 const uint8_t * digest,
472 uint8_t digest_length,
473 const uint8_t * signature,
474 uint16_t signature_length,
475 uint8_t public_key_source_type,
476 const void * public_key);
477 #endif //OPTIGA_CRYPT_ECDSA_VERIFY_ENABLED 479 #ifdef OPTIGA_CRYPT_ECDH_ENABLED 524 uint8_t * shared_secret);
525 #endif //OPTIGA_CRYPT_ECDH_ENABLED 527 #ifdef OPTIGA_CRYPT_TLS_PRF_SHA256_ENABLED 575 const uint8_t * label,
576 uint16_t label_length,
577 const uint8_t * seed,
578 uint16_t seed_length,
579 uint16_t derived_key_length,
581 uint8_t * derived_key);
582 #endif //OPTIGA_CRYPT_TLS_PRF_SHA256_ENABLED 584 #ifdef OPTIGA_CRYPT_RSA_GENERATE_KEYPAIR_ENABLED 631 bool_t export_private_key,
633 uint8_t * public_key,
634 uint16_t * public_key_length);
635 #endif //OPTIGA_CRYPT_RSA_GENERATE_KEYPAIR_ENABLED 638 #ifdef OPTIGA_CRYPT_RSA_SIGN_ENABLED 676 const uint8_t * digest,
677 uint8_t digest_length,
680 uint16_t * signature_length,
681 uint16_t salt_length);
682 #endif //OPTIGA_CRYPT_RSA_SIGN_ENABLED 684 #ifdef OPTIGA_CRYPT_RSA_VERIFY_ENABLED 726 const uint8_t * digest,
727 uint8_t digest_length,
728 const uint8_t * signature,
729 uint16_t signature_length,
730 uint8_t public_key_source_type,
731 const void * public_key,
732 uint16_t salt_length);
733 #endif //OPTIGA_CRYPT_RSA_VERIFY_ENABLED 735 #ifdef OPTIGA_CRYPT_RSA_PRE_MASTER_SECRET_ENABLED 779 const uint8_t * optional_data,
780 uint16_t optional_data_length,
781 uint16_t pre_master_secret_length);
782 #endif //OPTIGA_CRYPT_RSA_PRE_MASTER_SECRET_ENABLED 784 #ifdef OPTIGA_CRYPT_RSA_ENCRYPT_ENABLED 831 const uint8_t * message,
832 uint16_t message_length,
833 const uint8_t * label,
834 uint16_t label_length,
835 uint8_t public_key_source_type,
836 const void * public_key,
837 uint8_t * encrypted_message,
838 uint16_t * encrypted_message_length);
885 const uint8_t * label,
886 uint16_t label_length,
887 uint8_t public_key_source_type,
888 const void * public_key,
889 uint8_t * encrypted_message,
890 uint16_t * encrypted_message_length);
892 #endif //OPTIGA_CRYPT_RSA_ENCRYPT_ENABLED 894 #ifdef OPTIGA_CRYPT_RSA_DECRYPT_ENABLED 937 const uint8_t * encrypted_message,
938 uint16_t encrypted_message_length,
939 const uint8_t * label,
940 uint16_t label_length,
943 uint16_t * message_length);
983 const uint8_t * encrypted_message,
984 uint16_t encrypted_message_length,
985 const uint8_t * label,
986 uint16_t label_length,
989 #endif //OPTIGA_CRYPT_RSA_DECRYPT_ENABLED 1016 #ifdef OPTIGA_COMMS_SHIELDED_CONNECTION 1017 #define OPTIGA_CRYPT_SET_COMMS_PROTECTION_LEVEL(p_instance, protection_level) \ 1019 optiga_crypt_set_comms_params(p_instance, \ 1020 OPTIGA_COMMS_PROTECTION_LEVEL, \ 1024 #define OPTIGA_CRYPT_SET_COMMS_PROTECTION_LEVEL(p_instance, protection_level) {} 1044 #ifdef OPTIGA_COMMS_SHIELDED_CONNECTION 1045 #define OPTIGA_CRYPT_SET_COMMS_PROTOCOL_VERSION(p_instance, version) \ 1047 optiga_crypt_set_comms_params(p_instance, \ 1048 OPTIGA_COMMS_PROTOCOL_VERSION, \ 1052 #define OPTIGA_CRYPT_SET_COMMS_PROTOCOL_VERSION(p_instance, version) {} 1055 #if defined (OPTIGA_LIB_ENABLE_LOGGING) && defined (OPTIGA_LIB_ENABLE_CRYPT_LOGGING) 1070 #define OPTIGA_CRYPT_LOG_MESSAGE(msg) \ 1072 optiga_lib_print_message(msg,OPTIGA_CRYPT_SERVICE,OPTIGA_CRYPT_SERVICE_COLOR);\ 1090 #define OPTIGA_CRYPT_LOG_HEX_DATA(array,array_len) \ 1092 optiga_lib_print_array_hex_format(array,array_len,OPTIGA_UNPROTECTED_DATA_COLOR);\ 1109 #define OPTIGA_CRYPT_LOG_STATUS(return_value) \ 1111 if (OPTIGA_LIB_SUCCESS != return_value) \ 1113 optiga_lib_print_status(OPTIGA_CRYPT_SERVICE,OPTIGA_ERROR_COLOR,return_value); \ 1117 optiga_lib_print_status(OPTIGA_CRYPT_SERVICE,OPTIGA_CRYPT_SERVICE_COLOR,return_value); \ 1122 #define OPTIGA_CRYPT_LOG_MESSAGE(msg) {} 1123 #define OPTIGA_CRYPT_LOG_HEX_DATA(array, array_len) {} 1124 #define OPTIGA_CRYPT_LOG_STATUS(return_value) {} Specifies the data structure of the Public Key details (key, size and type)
Definition: optiga_lib_common.h:236
optiga_encrypt_asym_params_t optiga_encrypt_asym_params
asymmetric encryption params
Definition: optiga_crypt.h:59
void optiga_crypt_set_comms_params(optiga_crypt_t *me, uint8_t configuration_type, uint8_t value)
Sets/updates the OPTIGA Comms Shielded connection configuration in the respective (optiga_util) insta...
Definition: optiga_crypt.c:375
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_ecdh(optiga_crypt_t *me, optiga_key_id_t private_key, public_key_from_host_t *public_key, bool_t export_to_host, uint8_t *shared_secret)
Calculates the shared secret using ECDH algorithm.
Definition: optiga_crypt.c:718
optiga_cmd_t * my_cmd
Command module instance.
Definition: optiga_crypt.h:74
optiga_calc_sign_params_t optiga_calc_sign_params
calc sign params
Definition: optiga_crypt.h:55
optiga_calc_ssec_params_t optiga_calc_ssec_params
calc ssec params
Definition: optiga_crypt.h:63
enum optiga_rsa_signature_scheme optiga_rsa_signature_scheme_t
Specifies the RSA signature schemes type in OPTIGA.
optiga_crypt_params_t params
Details/references (pointers) to the Application Inputs.
Definition: optiga_crypt.h:72
callback_handler_t handler
Callback handler.
Definition: optiga_crypt.h:78
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_random(optiga_crypt_t *me, optiga_rng_type_t rng_type, uint8_t *random_data, uint16_t random_data_length)
Generates a random number.
Definition: optiga_crypt.c:466
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_tls_prf_sha256(optiga_crypt_t *me, uint16_t secret, const uint8_t *label, uint16_t label_length, const uint8_t *seed, uint16_t seed_length, uint16_t derived_key_length, bool_t export_to_host, uint8_t *derived_key)
Derives a key.
Definition: optiga_crypt.c:773
uint8_t protection_level
To provide the encryption and decryption need for command and response.
Definition: optiga_crypt.h:83
optiga_verify_sign_params_t optiga_verify_sign_params
verify sign params
Definition: optiga_crypt.h:57
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_rsa_generate_pre_master_secret(optiga_crypt_t *me, const uint8_t *optional_data, uint16_t optional_data_length, uint16_t pre_master_secret_length)
Generates a pre-master secret.
Definition: optiga_crypt.c:1066
optiga_gen_keypair_params_t optiga_gen_keypair_params
get key pair params
Definition: optiga_crypt.h:53
enum optiga_rsa_key_type optiga_rsa_key_type_t
Specifies the RSA key type in OPTIGA.
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_rsa_decrypt_and_store(optiga_crypt_t *me, optiga_rsa_encryption_scheme_t encryption_scheme, const uint8_t *encrypted_message, uint16_t encrypted_message_length, const uint8_t *label, uint16_t label_length, optiga_key_id_t private_key)
Decrypts input data using OPTIGA private key and stores it in a OPTIGA session.
Definition: optiga_crypt.c:1028
Specifies the structure for derivation of key using pseudo random function.
Definition: optiga_lib_common.h:413
optiga_calc_hash_params_t optiga_calc_hash_params
calc hash params
Definition: optiga_crypt.h:61
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_destroy(optiga_crypt_t *me)
Destroys an instance of optiga_crypt_t.
Definition: optiga_crypt.c:440
uint8_t bool_t
Typedef for a boolean.
Definition: optiga_lib_types.h:91
enum optiga_ecc_curve optiga_ecc_curve_t
Specifies the key curve type in OPTIGA.
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_hash_finalize(optiga_crypt_t *me, optiga_hash_context_t *hash_ctx, uint8_t *hash_output)
Finalizes and exports the hash output.
Definition: optiga_crypt.c:603
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_rsa_decrypt_and_export(optiga_crypt_t *me, optiga_rsa_encryption_scheme_t encryption_scheme, const uint8_t *encrypted_message, uint16_t encrypted_message_length, const uint8_t *label, uint16_t label_length, optiga_key_id_t private_key, uint8_t *message, uint16_t *message_length)
Decrypts input data using OPTIGA private key and export it to the host.
Definition: optiga_crypt.c:986
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_ecdsa_verify(optiga_crypt_t *me, const uint8_t *digest, uint8_t digest_length, const uint8_t *signature, uint16_t signature_length, uint8_t public_key_source_type, const void *public_key)
Verifies the signature over the given digest.
Definition: optiga_crypt.c:695
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_rsa_generate_keypair(optiga_crypt_t *me, optiga_rsa_key_type_t key_type, uint8_t key_usage, bool_t export_private_key, void *private_key, uint8_t *public_key, uint16_t *public_key_length)
Generates an key pair based on RSA key type.
Definition: optiga_crypt.c:841
uint8_t protocol_version
To provide the presentation layer protocol version to be used.
Definition: optiga_crypt.h:85
uint16_t instance_state
To provide the busy/free status of the crypt instance.
Definition: optiga_crypt.h:80
Specifies the data structure for generate key pair.
Definition: optiga_lib_common.h:339
OPTIGA crypt instance structure.
Definition: optiga_crypt.h:69
Specifies the data structure for ecdh secret generation.
Definition: optiga_lib_common.h:398
Specifies the data structure for ECDSA signature verification.
Definition: optiga_lib_common.h:377
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_rsa_sign(optiga_crypt_t *me, optiga_rsa_signature_scheme_t signature_scheme, const uint8_t *digest, uint8_t digest_length, optiga_key_id_t private_key, uint8_t *signature, uint16_t *signature_length, uint16_t salt_length)
Generates a RSA signature for the given digest based on the input signature scheme.
Definition: optiga_crypt.c:862
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_hash_update(optiga_crypt_t *me, optiga_hash_context_t *hash_ctx, uint8_t source_of_data_to_hash, const void *data_to_hash)
Updates a hash context with the input data.
Definition: optiga_crypt.c:542
enum optiga_key_id optiga_key_id_t
Specifies the key location in OPTIGA.
optiga_get_random_params_t optiga_get_random_params
get random params
Definition: optiga_crypt.h:51
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_ecdsa_sign(optiga_crypt_t *me, const uint8_t *digest, uint8_t digest_length, optiga_key_id_t private_key, uint8_t *signature, uint16_t *signature_length)
Generates a signature for the given digest.
Definition: optiga_crypt.c:675
enum optiga_rng_type optiga_rng_type_t
Specifies the random generation types.
Command context.
Definition: optiga_cmd.c:331
Specifies the structure for asymmetric encryption and decryption.
Definition: optiga_lib_common.h:434
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_rsa_verify(optiga_crypt_t *me, optiga_rsa_signature_scheme_t signature_scheme, const uint8_t *digest, uint8_t digest_length, const uint8_t *signature, uint16_t signature_length, uint8_t public_key_source_type, const void *public_key, uint16_t salt_length)
Verifies the RSA signature over the given digest.
Definition: optiga_crypt.c:884
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_hash_start(optiga_crypt_t *me, optiga_hash_context_t *hash_ctx)
Initializes a hash context.
Definition: optiga_crypt.c:495
Specifies the data structure of calculate hash.
Definition: optiga_lib_common.h:297
Specifies the data structure for ECDSA signature.
Definition: optiga_lib_common.h:360
void * caller_context
Caller context.
Definition: optiga_crypt.h:76
optiga_derive_key_params_t optiga_derive_key_params
derive key params
Definition: optiga_crypt.h:65
This file defines APIs, types and data structures used in the Command (cmd) module implementation.
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_rsa_encrypt_session(optiga_crypt_t *me, optiga_rsa_encryption_scheme_t encryption_scheme, const uint8_t *label, uint16_t label_length, uint8_t public_key_source_type, const void *public_key, uint8_t *encrypted_message, uint16_t *encrypted_message_length)
Encrypts session data using RSA public key.
Definition: optiga_crypt.c:946
Specifies the structure to the Hash context details managed by OPTIGA.
Definition: optiga_lib_common.h:199
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_ecc_generate_keypair(optiga_crypt_t *me, optiga_ecc_curve_t curve_id, uint8_t key_usage, bool_t export_private_key, void *private_key, uint8_t *public_key, uint16_t *public_key_length)
Generates an key pair based on ECC curves.
Definition: optiga_crypt.c:655
uint16_t optiga_lib_status_t
typedef for OPTIGA host library status
Definition: optiga_lib_types.h:97
LIBRARY_EXPORTS optiga_crypt_t * optiga_crypt_create(uint8_t optiga_instance_id, callback_handler_t handler, void *caller_context)
Create an instance of optiga_crypt_t.
Definition: optiga_crypt.c:399
enum optiga_rsa_encryption_scheme optiga_rsa_encryption_scheme_t
Specifies the RSA encryption schemes.
LIBRARY_EXPORTS optiga_lib_status_t optiga_crypt_rsa_encrypt_message(optiga_crypt_t *me, optiga_rsa_encryption_scheme_t encryption_scheme, const uint8_t *message, uint16_t message_length, const uint8_t *label, uint16_t label_length, uint8_t public_key_source_type, const void *public_key, uint8_t *encrypted_message, uint16_t *encrypted_message_length)
Encrypts message using RSA public key.
Definition: optiga_crypt.c:908
void(* callback_handler_t)(void *callback_ctx, optiga_lib_status_t event)
typedef for event callback handler
Definition: optiga_lib_types.h:106
union for OPTIGA crypt parameters
Definition: optiga_crypt.h:48
Specifies the data structure of random generation.
Definition: optiga_lib_common.h:323
union optiga_crypt_params optiga_crypt_params_t
union for OPTIGA crypt parameters