#ifndef ATCA_HOST_H
#define ATCA_HOST_H
#include <stdint.h>
#include "cryptoauthlib.h"
#define ATCA_MSG_SIZE_NONCE (55)
#define ATCA_MSG_SIZE_MAC (88)
#define ATCA_MSG_SIZE_HMAC (88)
#define ATCA_MSG_SIZE_GEN_DIG (96)
#define ATCA_MSG_SIZE_DERIVE_KEY (96)
#define ATCA_MSG_SIZE_DERIVE_KEY_MAC (39)
#define ATCA_MSG_SIZE_ENCRYPT_MAC (96)
#define ATCA_MSG_SIZE_PRIVWRITE_MAC (96)
#define ATCA_COMMAND_HEADER_SIZE ( 4)
#define ATCA_GENDIG_ZEROS_SIZE (25)
#define ATCA_WRITE_MAC_ZEROS_SIZE (25)
#define ATCA_PRIVWRITE_MAC_ZEROS_SIZE (21)
#define ATCA_PRIVWRITE_PLAIN_TEXT_SIZE (36)
#define ATCA_DERIVE_KEY_ZEROS_SIZE (25)
#define HMAC_BLOCK_SIZE (64)
#define ENCRYPTION_KEY_SIZE (64)
#define ATCA_SN_0_DEF (0x01)
#define ATCA_SN_1_DEF (0x23)
#define ATCA_SN_8_DEF (0xEE)
#define MAC_MODE_USE_TEMPKEY_MASK ((uint8_t)0x03)
typedef struct atca_temp_key
{
uint8_t value[ATCA_KEY_SIZE * 2]; unsigned key_id : 4; unsigned source_flag : 1; unsigned gen_dig_data : 1; unsigned gen_key_data : 1; unsigned no_mac_flag : 1; unsigned valid : 1; uint8_t is_64; } atca_temp_key_t;
struct atca_include_data_in_out
{
uint8_t * p_temp;
const uint8_t *otp;
const uint8_t *sn;
uint8_t mode;
};
typedef struct atca_nonce_in_out
{
uint8_t mode;
uint16_t zero;
const uint8_t * num_in;
const uint8_t * rand_out;
struct atca_temp_key *temp_key;
} atca_nonce_in_out_t;
typedef struct atca_io_decrypt_in_out
{
const uint8_t* io_key; const uint8_t* out_nonce; uint8_t* data; size_t data_size; } atca_io_decrypt_in_out_t;
typedef struct atca_verify_mac
{
uint8_t mode; uint16_t key_id; const uint8_t* signature; const uint8_t* other_data; const uint8_t* msg_dig_buf; const uint8_t* io_key; const uint8_t* sn; const atca_temp_key_t* temp_key; uint8_t* mac; } atca_verify_mac_in_out_t;
typedef struct atca_secureboot_enc_in_out
{
const uint8_t* io_key; const struct atca_temp_key* temp_key; const uint8_t* digest; uint8_t* hashed_key; uint8_t* digest_enc; } atca_secureboot_enc_in_out_t;
typedef struct atca_secureboot_mac_in_out
{
uint8_t mode; uint16_t param2; uint16_t secure_boot_config; const uint8_t* hashed_key; const uint8_t* digest; const uint8_t* signature; uint8_t* mac; } atca_secureboot_mac_in_out_t;
typedef struct atca_mac_in_out
{
uint8_t mode;
uint16_t key_id;
const uint8_t * challenge;
const uint8_t * key;
const uint8_t * otp;
const uint8_t * sn;
uint8_t * response;
struct atca_temp_key *temp_key;
} atca_mac_in_out_t;
struct atca_hmac_in_out
{
uint8_t mode;
uint16_t key_id;
const uint8_t * key;
const uint8_t * otp;
const uint8_t * sn;
uint8_t * response;
struct atca_temp_key *temp_key;
};
typedef struct atca_gen_dig_in_out
{
uint8_t zone; uint16_t key_id; uint16_t slot_conf; uint16_t key_conf; uint8_t slot_locked; uint32_t counter; bool is_key_nomac; const uint8_t * sn; const uint8_t * stored_value; const uint8_t * other_data; struct atca_temp_key *temp_key; } atca_gen_dig_in_out_t;
typedef struct atca_write_mac_in_out
{
uint8_t zone; uint16_t key_id; const uint8_t * sn; const uint8_t * input_data; uint8_t * encrypted_data; uint8_t * auth_mac; struct atca_temp_key *temp_key; } atca_write_mac_in_out_t;
struct atca_derive_key_in_out
{
uint8_t mode; uint16_t target_key_id; const uint8_t * sn; const uint8_t * parent_key; uint8_t * target_key; struct atca_temp_key *temp_key; };
struct atca_derive_key_mac_in_out
{
uint8_t mode; uint16_t target_key_id; const uint8_t *sn; const uint8_t *parent_key; uint8_t * mac; };
struct atca_decrypt_in_out
{
uint8_t * crypto_data;
struct atca_temp_key *temp_key;
};
typedef struct atca_check_mac_in_out
{
uint8_t mode; uint16_t key_id; const uint8_t *sn; const uint8_t *client_chal; uint8_t * client_resp; const uint8_t *other_data; const uint8_t *otp; const uint8_t *slot_key; const uint8_t * target_key;
struct atca_temp_key *temp_key; } atca_check_mac_in_out_t;
typedef struct atca_verify_in_out
{
uint16_t curve_type;
const uint8_t * signature;
const uint8_t * public_key;
struct atca_temp_key *temp_key;
} atca_verify_in_out_t;
typedef struct atca_gen_key_in_out
{
uint8_t mode; uint16_t key_id; const uint8_t * public_key; size_t public_key_size; const uint8_t * other_data; const uint8_t * sn; struct atca_temp_key *temp_key; } atca_gen_key_in_out_t;
typedef struct atca_sign_internal_in_out
{
uint8_t mode; uint16_t key_id; uint16_t slot_config; uint16_t key_config; uint8_t use_flag; uint8_t update_count; bool is_slot_locked; bool for_invalidate; const uint8_t * sn; const struct atca_temp_key *temp_key; uint8_t* message; uint8_t* verify_other_data; uint8_t* digest; } atca_sign_internal_in_out_t;
#ifdef __cplusplus
extern "C" {
#endif
ATCA_STATUS atcah_nonce(struct atca_nonce_in_out *param);
ATCA_STATUS atcah_mac(struct atca_mac_in_out *param);
ATCA_STATUS atcah_check_mac(struct atca_check_mac_in_out *param);
ATCA_STATUS atcah_hmac(struct atca_hmac_in_out *param);
ATCA_STATUS atcah_gen_dig(struct atca_gen_dig_in_out *param);
ATCA_STATUS atcah_gen_mac(struct atca_gen_dig_in_out *param);
ATCA_STATUS atcah_write_auth_mac(struct atca_write_mac_in_out *param);
ATCA_STATUS atcah_privwrite_auth_mac(struct atca_write_mac_in_out *param);
ATCA_STATUS atcah_derive_key(struct atca_derive_key_in_out *param);
ATCA_STATUS atcah_derive_key_mac(struct atca_derive_key_mac_in_out *param);
ATCA_STATUS atcah_decrypt(struct atca_decrypt_in_out *param);
ATCA_STATUS atcah_sha256(int32_t len, const uint8_t *message, uint8_t *digest);
uint8_t *atcah_include_data(struct atca_include_data_in_out *param);
ATCA_STATUS atcah_gen_key_msg(struct atca_gen_key_in_out *param);
ATCA_STATUS atcah_config_to_sign_internal(ATCADeviceType device_type, struct atca_sign_internal_in_out *param, const uint8_t* config);
ATCA_STATUS atcah_sign_internal_msg(ATCADeviceType device_type, struct atca_sign_internal_in_out *param);
ATCA_STATUS atcah_verify_mac(atca_verify_mac_in_out_t *param);
ATCA_STATUS atcah_secureboot_enc(atca_secureboot_enc_in_out_t* param);
ATCA_STATUS atcah_secureboot_mac(atca_secureboot_mac_in_out_t *param);
ATCA_STATUS atcah_encode_counter_match(uint32_t counter, uint8_t * counter_match);
ATCA_STATUS atcah_io_decrypt(struct atca_io_decrypt_in_out *param);
#ifdef __cplusplus
}
#endif
#endif