CryptoAuthLib
Atmel CryptoAuthentication Library
atca_host.h
Go to the documentation of this file.
1 
44 #ifndef ATCA_HOST_H
45 # define ATCA_HOST_H
46 
47 #include "cryptoauthlib.h" // contains definitions used by chip and these routines
48 
68 #define ATCA_MSG_SIZE_NONCE (55)
70 
71 
75 #define ATCA_MSG_SIZE_MAC (88)
76 
86 #define ATCA_MSG_SIZE_HMAC_INNER (152)
87 
88 
92 #define ATCA_MSG_SIZE_HMAC (96)
93 
94 
96 #define ATCA_MSG_SIZE_GEN_DIG (96)
97 
98 
100 #define ATCA_MSG_SIZE_DERIVE_KEY (96)
101 
102 
104 #define ATCA_MSG_SIZE_DERIVE_KEY_MAC (39)
105 
107 #define ATCA_MSG_SIZE_ENCRYPT_MAC (96)
108 
110 #define ATCA_MSG_SIZE_PRIVWRITE_MAC (96)
111 
112 #define ATCA_COMMAND_HEADER_SIZE ( 4)
113 #define ATCA_GENDIG_ZEROS_SIZE (25)
114 #define ATCA_PRIVWRITE_MAC_ZEROS_SIZE (21)
115 #define ATCA_PLAIN_TEXT_SIZE (36)
116 #define ATCA_DERIVE_KEY_ZEROS_SIZE (25)
117 #define ATCA_OTP_SIZE_8 ( 8)
118 #define ATCA_OTP_SIZE_3 ( 3)
119 #define ATCA_SN_SIZE_4 ( 4)
120 #define ATCA_SN_SIZE_2 ( 2)
121 #define ATCA_OTHER_DATA_SIZE_2 ( 2)
122 #define ATCA_OTHER_DATA_SIZE_3 ( 3)
123 #define ATCA_OTHER_DATA_SIZE_4 ( 4)
124 #define HMAC_BLOCK_SIZE (64)
125 
129 #define ATCA_SN_0 (0x01)
130 #define ATCA_SN_1 (0x23)
131 #define ATCA_SN_8 (0xEE)
132 
137 #define MAC_MODE_USE_TEMPKEY_MASK ((uint8_t)0x03)
139 
141 #define ATAC_STANDARD_KEY_SIZE 32
142 
158 typedef struct atca_temp_key {
160  unsigned int key_id : 4;
161  unsigned int source_flag : 1;
162  unsigned int gen_data : 1;
163  unsigned int check_flag : 1;
164  unsigned int valid : 1;
166 
167 
178  uint8_t *p_temp;
179  const uint8_t *otp;
180  const uint8_t *sn;
181  uint8_t mode;
182 };
183 
184 
196 typedef struct atca_nonce_in_out {
197  uint8_t mode;
198  const uint8_t *num_in;
199  uint8_t *rand_out;
202 
203 
224  uint8_t mode;
225  uint16_t key_id;
226  const uint8_t *challenge;
227  const uint8_t *key;
228  const uint8_t *otp;
229  const uint8_t *sn;
230  uint8_t *response;
232 };
233 
234 
253  uint8_t mode;
254  uint16_t key_id;
255  const uint8_t *key;
256  const uint8_t *otp;
257  const uint8_t *sn;
258  uint8_t *response;
260 };
261 
262 
274 typedef struct atca_gen_dig_in_out {
275  uint8_t zone;
276  uint16_t key_id;
277  const uint8_t *stored_value;
280 
298 typedef struct atca_write_mac_in_out {
299  uint8_t zone;
300  uint16_t key_id;
301  const uint8_t *encryption_key;
302  const uint8_t *input_data;
303  uint8_t *encrypted_data; // out
304  uint8_t *auth_mac; // out
305  struct atca_temp_key *temp_key; // in
307 
322  uint8_t random;
323  uint16_t target_key_id;
324  const uint8_t *parent_key;
325  uint8_t *target_key;
327 };
328 
329 
342  uint8_t random;
343  uint16_t target_key_id;
344  const uint8_t *parent_key;
345  uint8_t *mac;
346 };
347 
348 
363  uint8_t zone;
364  uint16_t address;
365  uint8_t *crypto_data;
366  uint8_t *mac;
368 };
369 
370 
379  uint8_t *crypto_data;
381 };
382 
383 
402  uint8_t mode;
403  const uint8_t *password;
404  const uint8_t *other_data;
405  const uint8_t *otp;
406  const uint8_t *target_key;
407  uint8_t *client_resp;
409 };
410 
411 
424  uint16_t curve_type;
425  const uint8_t *signature;
426  const uint8_t *public_key;
428 };
429 
430 #ifdef __cplusplus
431 extern "C" {
432 #endif
433 
435 ATCA_STATUS atcah_mac(struct atca_mac_in_out *param);
446 ATCA_STATUS atcah_sha256(int32_t len, const uint8_t *message, uint8_t *digest);
447 uint8_t *atcah_include_data(struct atca_include_data_in_out *param);
448 
449 #ifdef __cplusplus
450 }
451 #endif
452 
455 #endif //ATCA_HOST_H
unsigned int gen_data
Indicates if TempKey has been generated by GenDig using Data zone.
Definition: atca_host.h:162
Input / output parameters for function atca_include_data().
Definition: atca_host.h:177
uint16_t target_key_id
[in] KeyID to be derived, TargetKey parameter used in DeriveKey command (Param2). ...
Definition: atca_host.h:323
const uint8_t * num_in
[in] Pointer to 20-byte NumIn data used in Nonce command.
Definition: atca_host.h:198
Input/output parameters for function atca_hmac().
Definition: atca_host.h:252
Single aggregation point for all CryptoAuthLib header files.
uint8_t random
[in] Random parameter used in DeriveKey command (Param1).
Definition: atca_host.h:322
Structure to hold TempKey fields.
Definition: atca_host.h:158
uint8_t value[ATAC_STANDARD_KEY_SIZE]
The value of TempKey. Nonce (from nonce command) or Digest (from GenDig command)
Definition: atca_host.h:159
struct atca_nonce_in_out atca_nonce_in_out_t
uint8_t mode
[in] Mode parameter used in Nonce command (Param1).
Definition: atca_host.h:197
uint8_t mode
Definition: atca_host.h:181
ATCA_STATUS atcah_gen_dig(struct atca_gen_dig_in_out *param)
This function combines the current TempKey with a stored value.
Definition: atca_host.c:443
uint16_t curve_type
[in] Curve type used in Verify command (Param2).
Definition: atca_host.h:424
ATCA_STATUS atcah_write_auth_mac(struct atca_write_mac_in_out *param)
This function calculates the input MAC for the PrivWrite command.
Definition: atca_host.c:592
ATCA_STATUS
Definition: atca_status.h:55
Input/output parameters for function atca_gen_dig().
Definition: atca_host.h:274
ATCA_STATUS atcah_mac(struct atca_mac_in_out *param)
This function generates an SHA-256 digest (MAC) of a key, challenge, and other information.
Definition: atca_host.c:158
unsigned int key_id
If TempKey was generated by GenDig (see the GenData and CheckFlag bits), these bits indicate which ke...
Definition: atca_host.h:160
const uint8_t * signature
[in] Pointer to ECDSA signature to be verified
Definition: atca_host.h:425
const uint8_t * otp
[in] pointer to one-time-programming data
Definition: atca_host.h:179
uint8_t * crypto_data
[in,out] Pointer to 32-byte data. Input cleartext data, output encrypted data to Write command (Value...
Definition: atca_host.h:365
Input/output parameters for function atca_derive_key_mac().
Definition: atca_host.h:341
uint8_t * mac
[out] Pointer to 32-byte Mac.
Definition: atca_host.h:345
uint8_t * p_temp
[out] pointer to output buffer
Definition: atca_host.h:178
uint8_t * response
[out] Pointer to 32-byte SHA-256 digest (MAC).
Definition: atca_host.h:230
const uint8_t * challenge
[in] Pointer to 32-byte Challenge data used in MAC command, depending on mode.
Definition: atca_host.h:226
unsigned int source_flag
The source of the randomness in TempKey: 0=Rand, 1=Input.
Definition: atca_host.h:161
Input/output parameters for function atca_nonce().
Definition: atca_host.h:196
#define ATAC_STANDARD_KEY_SIZE
Definition: atca_host.h:141
uint16_t address
[in] Address parameter used in Write command (Param2).
Definition: atca_host.h:364
Input/output parameters for function atca_check_mac().
Definition: atca_host.h:401
const uint8_t * sn
[in] pointer to serial number data
Definition: atca_host.h:180
Input/output parameters for function atca_auth_mac().
Definition: atca_host.h:298
ATCA_STATUS atcah_hmac(struct atca_hmac_in_out *param)
This function generates an HMAC / SHA-256 hash of a key and other information.
Definition: atca_host.c:333
Input/output parameters for function atca_derive_key().
Definition: atca_host.h:321
const uint8_t * input_data
[in] Pointer to 36-byte data value, Input cleartext data.
Definition: atca_host.h:302
uint8_t * auth_mac
[out] Pointer to 32-byte Mac.
Definition: atca_host.h:304
uint8_t * client_resp
[out] Pointer to 32-byte ClientResp to be used in CheckMac command.
Definition: atca_host.h:407
Input/output parameters for function atca_encrypt().
Definition: atca_host.h:362
ATCA_STATUS atcah_privwrite_auth_mac(struct atca_write_mac_in_out *param)
This function calculates the input MAC for the PrivWrite command.
Definition: atca_host.c:667
ATCA_STATUS atcah_sha256(int32_t len, const uint8_t *message, uint8_t *digest)
This function creates a SHA256 digest on a little-endian system.
Definition: atca_host.c:1034
ATCA_STATUS atcah_encrypt(struct atca_encrypt_in_out *param)
This function encrypts 32-byte plain text data to be written using Write opcode, and optionally calcu...
Definition: atca_host.c:895
uint8_t * encrypted_data
[out] Pointer to 32-byte data. Output encrypted data to MAC command.
Definition: atca_host.h:303
ATCA_STATUS atcah_nonce(struct atca_nonce_in_out *param)
This function calculates a 32-byte nonce based on a 20-byte input value (param->num_in) and 32-byte r...
Definition: atca_host.c:102
unsigned int check_flag
Not used in the library.
Definition: atca_host.h:163
Input/output parameters for function atca_mac().
Definition: atca_host.h:223
const uint8_t * password
[in] Pointer to 32-byte password that will be verified against Key[KeyID] in the Device.
Definition: atca_host.h:403
struct atca_write_mac_in_out atca_write_mac_in_out_t
const uint8_t * key
[in] Pointer to 32-byte key used to generate MAC digest.
Definition: atca_host.h:227
ATCA_STATUS atcah_derive_key(struct atca_derive_key_in_out *param)
This function combines a key with the TempKey.
Definition: atca_host.c:763
struct atca_temp_key atca_temp_key_t
ATCA_STATUS atcah_derive_key_mac(struct atca_derive_key_mac_in_out *param)
This function calculates the input MAC for a DeriveKey command.
Definition: atca_host.c:835
uint8_t zone
[in] Zone parameter used in GenDig command (Param1).
Definition: atca_host.h:275
ATCA_STATUS atcah_decrypt(struct atca_decrypt_in_out *param)
This function decrypts 32-byte encrypted data received with the Read command.
Definition: atca_host.c:989
unsigned int valid
Indicates if the information in TempKey is valid.
Definition: atca_host.h:164
uint8_t * atcah_include_data(struct atca_include_data_in_out *param)
This function copies otp and sn data into a command buffer.
Definition: atca_host.c:51
const uint8_t * stored_value
[in] Pointer to 32-byte stored value, can be a data slot, OTP page, configuration zone...
Definition: atca_host.h:277
Input/output parameters for function atca_verify().
Definition: atca_host.h:423
struct atca_temp_key * temp_key
[in,out] Pointer to TempKey structure.
Definition: atca_host.h:200
uint8_t * target_key
[out] Pointer to 32-byte TargetKey.
Definition: atca_host.h:325
Input/output parameters for function atca_decrypt().
Definition: atca_host.h:378
ATCA_STATUS atcah_check_mac(struct atca_check_mac_in_out *param)
This function calculates a SHA-256 digest (MAC) of a password and other information, to be verified using the CheckMac device command.
Definition: atca_host.c:249
const uint8_t * other_data
[in] Pointer to 13-byte OtherData that will be used in CheckMac command.
Definition: atca_host.h:404
const uint8_t * parent_key
[in] Pointer to 32-byte ParentKey. Set equal to target_key if Roll Key operation is intended...
Definition: atca_host.h:324
const uint8_t * encryption_key
[in] Pointer to 32-byte key.
Definition: atca_host.h:301
uint8_t * rand_out
[in] Pointer to 32-byte RandOut data from Nonce command.
Definition: atca_host.h:199
ATCA_STATUS atcah_gen_mac(struct atca_gen_dig_in_out *param)
This function combines the session key with a plain text.
Definition: atca_host.c:518
struct atca_gen_dig_in_out atca_gen_dig_in_out_t
const uint8_t * public_key
[in] Pointer to the public key to be used for verification
Definition: atca_host.h:426