CryptoAuthLib
Atmel CryptoAuthentication Library
atca_command.h
Go to the documentation of this file.
1 
48 #ifndef ATCA_COMMAND_H
49 #define ATCA_COMMAND_H
50 
51 #include "atca_compiler.h"
52 #include "atca_status.h"
53 #include "atca_devtypes.h"
54 
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 
59 /*--- ATCACommand ---------*/
60 typedef struct atca_command * ATCACommand;
61 ATCACommand newATCACommand(ATCADeviceType device_type); // constructor
62 
63 /* add ATCACommand declarations here
64  *
65  * since these are still C functions, not classes, naming is an important
66  * consideration to keep the namespace from colliding with other 3rd party
67  * libraries or even ourselves/ASF.
68  *
69  * Basic conventions:
70  * all methods start with the prefix 'at'
71  * all method names must be unique, obviously
72  * all method implementations should be proceeded by their Doxygen comment header
73  *
74  **/
75 
76 
77 // this is the ATCACommand parameter structure. The caller to the command method must
78 // initialize param1, param2 and data if appropriate. The command method will fill in the rest
79 // and initialize the packet so it's ready to send via the ATCAIFace.
80 // this particular structure mimics the ATSHA and ATECC family device's command structures
81 
82 // Note: pack @ 2 is required, @ 1 causes word alignment crash (though it should not), a known bug in GCC.
83 // @2, the wire still has the intended byte alignment with arm-eabi. this is likely the least portable part of atca
84 
85 #pragma pack( push, ATCAPacket, 2 )
86 
89 typedef struct {
90 
91  // used for transmit/send
92  uint8_t _reserved; // used by HAL layer as needed (I/O tokens, Word address values)
93 
94  //--- start of packet i/o frame----
95  uint8_t txsize;
96  uint8_t opcode;
97  uint8_t param1; // often same as mode
98  uint16_t param2;
99  uint8_t data[130]; // includes 2-byte CRC. data size is determined by largest possible data section of any
100  // command + crc (see: x08 verify data1 + data2 + data3 + data4)
101  // this is an explicit design trade-off (space) resulting in simplicity in use
102  // and implementation
103  //--- end of packet i/o frame
104 
105  // used for receive
106  uint8_t execTime; // execution time of command by opcode
107  uint16_t rxsize; // expected response size, response is held in data member
108 
109  // structure should be packed since it will be transmitted over the wire
110  // this method varies by compiler. As new compilers are supported, add their structure packing method here
111 
112 } ATCAPacket;
113 #pragma pack( pop, ATCAPacket)
114 
115 ATCA_STATUS atCheckMAC(ATCACommand cacmd, ATCAPacket *packet);
116 ATCA_STATUS atCounter(ATCACommand cacmd, ATCAPacket *packet );
117 ATCA_STATUS atDeriveKey(ATCACommand cacmd, ATCAPacket *packet, bool hasMAC );
118 ATCA_STATUS atECDH(ATCACommand cacmd, ATCAPacket *packet );
119 ATCA_STATUS atGenDig(ATCACommand cacmd, ATCAPacket *packet, bool hasMACKey );
120 ATCA_STATUS atGenKey(ATCACommand cacmd, ATCAPacket *packet, bool isPubKey );
121 ATCA_STATUS atHMAC(ATCACommand cacmd, ATCAPacket *packet );
122 ATCA_STATUS atInfo(ATCACommand cacmd, ATCAPacket *packet );
123 ATCA_STATUS atLock(ATCACommand cacmd, ATCAPacket *packet );
124 ATCA_STATUS atMAC(ATCACommand cacmd, ATCAPacket *packet );
125 ATCA_STATUS atNonce(ATCACommand cacmd, ATCAPacket *packet );
126 ATCA_STATUS atPause(ATCACommand cacmd, ATCAPacket *packet );
127 ATCA_STATUS atPrivWrite(ATCACommand cacmd, ATCAPacket *packet );
128 ATCA_STATUS atRandom(ATCACommand cacmd, ATCAPacket *packet );
129 ATCA_STATUS atRead(ATCACommand cacmd, ATCAPacket *packet );
130 ATCA_STATUS atSHA(ATCACommand cacmd, ATCAPacket *packet );
131 ATCA_STATUS atSign(ATCACommand cacmd, ATCAPacket *packet);
132 ATCA_STATUS atUpdateExtra(ATCACommand cacmd, ATCAPacket *packet);
133 ATCA_STATUS atVerify(ATCACommand cacmd, ATCAPacket *packet);
134 ATCA_STATUS atWrite(ATCACommand cacmd, ATCAPacket *packet);
135 ATCA_STATUS atWriteEnc(ATCACommand cacmd, ATCAPacket *packet);
136 
137 bool atIsSHAFamily( ATCADeviceType deviceType );
138 bool atIsECCFamily( ATCADeviceType deviceType );
139 ATCA_STATUS isATCAError( uint8_t *data );
140 
141 // this map is used to index into an array of execution times
142 typedef enum {
164  CMD_LASTCOMMAND // placeholder
165 } ATCA_CmdMap;
166 
167 ATCA_STATUS atInitExecTimes(ATCACommand cacmd, ATCADeviceType device_type);
168 uint16_t atGetExecTime( ATCACommand cacmd, ATCA_CmdMap cmd );
169 
170 void deleteATCACommand( ATCACommand * ); // destructor
171 /*---- end of ATCACommand ----*/
172 
173 // command helpers
174 void atCRC( uint8_t length, uint8_t *data, uint8_t *crc);
175 void atCalcCrc( ATCAPacket *pkt);
176 uint8_t atCheckCrc(uint8_t *response);
177 
178 
179 /* command definitions */
180 
182 #define ATCA_CMD_SIZE_MIN ((uint8_t)7)
183 #define ATCA_CMD_SIZE_MAX ((uint8_t)4 * 36 + 7)
185 #define CMD_STATUS_SUCCESS ((uint8_t)0x00)
187 #define CMD_STATUS_WAKEUP ((uint8_t)0x11)
189 #define CMD_STATUS_BYTE_PARSE ((uint8_t)0x03)
191 #define CMD_STATUS_BYTE_ECC ((uint8_t)0x05)
193 #define CMD_STATUS_BYTE_EXEC ((uint8_t)0x0F)
195 #define CMD_STATUS_BYTE_COMM ((uint8_t)0xFF)
197 
203 #define ATCA_CHECKMAC ((uint8_t)0x28)
204 #define ATCA_DERIVE_KEY ((uint8_t)0x1C)
205 #define ATCA_INFO ((uint8_t)0x30)
206 #define ATCA_GENDIG ((uint8_t)0x15)
207 #define ATCA_GENKEY ((uint8_t)0x40)
208 #define ATCA_HMAC ((uint8_t)0x11)
209 #define ATCA_LOCK ((uint8_t)0x17)
210 #define ATCA_MAC ((uint8_t)0x08)
211 #define ATCA_NONCE ((uint8_t)0x16)
212 #define ATCA_PAUSE ((uint8_t)0x01)
213 #define ATCA_PRIVWRITE ((uint8_t)0x46)
214 #define ATCA_RANDOM ((uint8_t)0x1B)
215 #define ATCA_READ ((uint8_t)0x02)
216 #define ATCA_SIGN ((uint8_t)0x41)
217 #define ATCA_UPDATE_EXTRA ((uint8_t)0x20)
218 #define ATCA_VERIFY ((uint8_t)0x45)
219 #define ATCA_WRITE ((uint8_t)0x12)
220 #define ATCA_ECDH ((uint8_t)0x43)
221 #define ATCA_COUNTER ((uint8_t)0x24)
222 #define ATCA_SHA ((uint8_t)0x47)
223 
228 #define ATCA_BLOCK_SIZE (32)
229 #define ATCA_WORD_SIZE (4)
230 #define ATCA_PUB_KEY_PAD (4)
231 #define ATCA_SERIAL_NUM_SIZE (9)
232 #define ATCA_RSP_SIZE_VAL ((uint8_t)7)
233 #define ATCA_KEY_COUNT (16)
234 #define ATCA_CONFIG_SIZE (128)
235 #define ATCA_SHA_CONFIG_SIZE (88)
236 #define ATCA_OTP_SIZE (64)
237 #define ATCA_DATA_SIZE (ATCA_KEY_COUNT * ATCA_KEY_SIZE)
238 
239 #define ATCA_COUNT_SIZE ((uint8_t)1)
240 #define ATCA_CRC_SIZE ((uint8_t)2)
241 #define ATCA_PACKET_OVERHEAD (ATCA_COUNT_SIZE + ATCA_CRC_SIZE)
242 
243 #define ATCA_PUB_KEY_SIZE (64)
244 #define ATCA_PRIV_KEY_SIZE (32)
245 #define ATCA_SIG_SIZE (64)
246 #define ATCA_KEY_SIZE (32)
247 #define RSA2048_KEY_SIZE (256)
248 
249 #define ATCA_RSP_SIZE_MIN ((uint8_t)4)
250 #define ATCA_RSP_SIZE_4 ((uint8_t)7)
251 #define ATCA_RSP_SIZE_72 ((uint8_t)75)
252 #define ATCA_RSP_SIZE_64 ((uint8_t)67)
253 #define ATCA_RSP_SIZE_32 ((uint8_t)35)
254 #define ATCA_RSP_SIZE_MAX ((uint8_t)75)
255 
256 
258 #define ATCA_KEY_ID_MAX ((uint8_t)15)
259 #define ATCA_OTP_BLOCK_MAX ((uint8_t)1)
260 
264 #define ATCA_COUNT_IDX (0)
265 #define ATCA_OPCODE_IDX (1)
266 #define ATCA_PARAM1_IDX (2)
267 #define ATCA_PARAM2_IDX (3)
268 #define ATCA_DATA_IDX (5)
269 #define ATCA_RSP_DATA_IDX (1)
270 
274 #define ATCA_ZONE_CONFIG ((uint8_t)0x00)
275 #define ATCA_ZONE_OTP ((uint8_t)0x01)
276 #define ATCA_ZONE_DATA ((uint8_t)0x02)
277 #define ATCA_ZONE_MASK ((uint8_t)0x03)
278 #define ATCA_ZONE_READWRITE_32 ((uint8_t)0x80)
279 #define ATCA_ZONE_ACCESS_4 ((uint8_t)4)
280 #define ATCA_ZONE_ACCESS_32 ((uint8_t)32)
281 #define ATCA_ADDRESS_MASK_CONFIG (0x001F)
282 #define ATCA_ADDRESS_MASK_OTP (0x000F)
283 #define ATCA_ADDRESS_MASK (0x007F)
284 
288 #define ATCA_B283_KEY_TYPE 0
289 #define ATCA_K283_KEY_TYPE 1
290 #define ATCA_P256_KEY_TYPE 4
291 
295 #define ECDH_PREFIX_MODE ((uint8_t)0x00)
296 #define ECDH_COUNT (71)
297 #define ECDH_PUBKEYIN_SIZE (64)
298 
302 #define COUNTER_COUNT ATCA_CMD_SIZE_MIN
303 #define COUNTER_MODE_IDX ATCA_PARAM1_IDX
304 #define COUNTER_KEYID_IDX ATCA_PARAM2_IDX
305 #define COUNTER_CHALLENGE_IDX ATCA_DATA_IDX
306 #define COUNTER_COUNT_LONG (70)
307 #define COUNTER_MODE_MASK ((uint8_t)0x01)
308 typedef enum {
316 #define SHA_COUNT_SHORT ATCA_CMD_SIZE_MIN
317 #define SHA_COUNT_LONG (7)
318 #define ATCA_SHA_DIGEST_SIZE (32)
319 #define SHA_DATA_MAX (64)
320 typedef enum {
321  SHA_MODE_SHA256_START = ((uint8_t) 0x00),
322  SHA_MODE_SHA256_UPDATE = ((uint8_t) 0x01),
323  SHA_MODE_SHA256_END = ((uint8_t) 0x02),
324  SHA_MODE_SHA256_PUBLIC = ((uint8_t) 0x03),
325  SHA_MODE_HMAC_START = ((uint8_t) 0x04),
326  SHA_MODE_HMAC_UPDATE = ((uint8_t) 0x05),
327  SHA_MODE_HMAC_END = ((uint8_t) 0x04)
328 } enum_sha_mode;
329 #define SHA_SHA256_START_MASK ((uint8_t)0x00)
330 #define SHA_SHA256_UPDATE_MASK ((uint8_t)0x01)
331 #define SHA_SHA256_END_MASK ((uint8_t)0x02)
332 #define SHA_SHA256_PUBLIC_MASK ((uint8_t)0x03)
333 #define SHA_HMAC_START_MASK ((uint8_t)0x04)
334 #define SHA_HMAC_END_MASK ((uint8_t)0x05)
335 
340 #define CHECKMAC_MODE_IDX ATCA_PARAM1_IDX
341 #define CHECKMAC_KEYID_IDX ATCA_PARAM2_IDX
342 #define CHECKMAC_CLIENT_CHALLENGE_IDX ATCA_DATA_IDX
343 #define CHECKMAC_CLIENT_RESPONSE_IDX (37)
344 #define CHECKMAC_DATA_IDX (69)
345 #define CHECKMAC_COUNT (84)
346 #define CHECKMAC_MODE_CHALLENGE ((uint8_t)0x00)
347 #define CHECKMAC_MODE_BLOCK2_TEMPKEY ((uint8_t)0x01)
348 #define CHECKMAC_MODE_BLOCK1_TEMPKEY ((uint8_t)0x02)
349 #define CHECKMAC_MODE_SOURCE_FLAG_MATCH ((uint8_t)0x04)
350 #define CHECKMAC_MODE_INCLUDE_OTP_64 ((uint8_t)0x20)
351 #define CHECKMAC_MODE_MASK ((uint8_t)0x27)
352 #define CHECKMAC_CLIENT_CHALLENGE_SIZE (32)
353 #define CHECKMAC_CLIENT_RESPONSE_SIZE (32)
354 #define CHECKMAC_OTHER_DATA_SIZE (13)
355 #define CHECKMAC_CLIENT_COMMAND_SIZE (4)
356 #define CHECKMAC_CMD_MATCH (0)
357 #define CHECKMAC_CMD_MISMATCH (1)
358 
362 #define DERIVE_KEY_RANDOM_IDX ATCA_PARAM1_IDX
363 #define DERIVE_KEY_TARGETKEY_IDX ATCA_PARAM2_IDX
364 #define DERIVE_KEY_MAC_IDX ATCA_DATA_IDX
365 #define DERIVE_KEY_COUNT_SMALL ATCA_CMD_SIZE_MIN
366 #define DERIVE_KEY_COUNT_LARGE (39)
367 #define DERIVE_KEY_RANDOM_FLAG ((uint8_t)4)
368 #define DERIVE_KEY_MAC_SIZE (32)
369 
373 #define GENDIG_ZONE_IDX ATCA_PARAM1_IDX
374 #define GENDIG_KEYID_IDX ATCA_PARAM2_IDX
375 #define GENDIG_DATA_IDX ATCA_DATA_IDX
376 #define GENDIG_COUNT ATCA_CMD_SIZE_MIN
377 #define GENDIG_COUNT_DATA (11)
378 #define GENDIG_OTHER_DATA_SIZE (32)
379 #define GENDIG_ZONE_CONFIG ((uint8_t)0)
380 #define GENDIG_ZONE_OTP ((uint8_t)1)
381 #define GENDIG_ZONE_DATA ((uint8_t)2)
382 
386 #define GENKEY_MODE_IDX ATCA_PARAM1_IDX
387 #define GENKEY_KEYID_IDX ATCA_PARAM2_IDX
388 #define GENKEY_DATA_IDX (5)
389 #define GENKEY_COUNT ATCA_CMD_SIZE_MIN
390 #define GENKEY_COUNT_DATA (10)
391 #define GENKEY_OTHER_DATA_SIZE (3)
392 #define GENKEY_MODE_MASK ((uint8_t)0x1C)
393 #define GENKEY_MODE_PRIVATE ((uint8_t)0x04)
394 #define GENKEY_MODE_PUBLIC ((uint8_t)0x00)
395 #define GENKEY_MODE_DIGEST ((uint8_t)0x10)
396 #define GENKEY_MODE_ADD_DIGEST ((uint8_t)0x08)
397 typedef enum {
398  GENKEY_MODE_PRIVATE_KEY_GENERATE = ((uint8_t) 0x04),
399  GENKEY_MODE_PUBLIC_KEY_DIGEST = ((uint8_t) 0x08),
400  GENKEY_MODE_DIGEST_IN_TEMPKEY = ((uint8_t) 0x10)
410 #define HMAC_MODE_IDX ATCA_PARAM1_IDX
411 #define HMAC_KEYID_IDX ATCA_PARAM2_IDX
412 #define HMAC_COUNT ATCA_CMD_SIZE_MIN
413 #define HMAC_MODE_SOURCE_FLAG_MATCH ((uint8_t)0x04)
414 #define HMAC_MODE_MASK ((uint8_t)0x74)
415 
419 #define INFO_PARAM1_IDX ATCA_PARAM1_IDX
420 #define INFO_PARAM2_IDX ATCA_PARAM2_IDX
421 #define INFO_COUNT ATCA_CMD_SIZE_MIN
422 #define INFO_MODE_REVISION ((uint8_t)0x00)
423 #define INFO_MODE_KEY_VALID ((uint8_t)0x01)
424 #define INFO_MODE_STATE ((uint8_t)0x02)
425 #define INFO_MODE_GPIO ((uint8_t)0x03)
426 #define INFO_MODE_MAX ((uint8_t)0x03)
427 #define INFO_NO_STATE ((uint8_t)0x00)
428 #define INFO_OUTPUT_STATE_MASK ((uint8_t)0x01)
429 #define INFO_DRIVER_STATE_MASK ((uint8_t)0x02)
430 #define INFO_PARAM2_MAX ((uint8_t)0x03)
431 #define INFO_SIZE ((uint8_t)0x04)
432 
436 #define LOCK_ZONE_IDX ATCA_PARAM1_IDX
437 #define LOCK_SUMMARY_IDX ATCA_PARAM2_IDX
438 #define LOCK_COUNT ATCA_CMD_SIZE_MIN
439 #define LOCK_ZONE_CONFIG ((uint8_t)0x00)
440 #define LOCK_ZONE_DATA ((uint8_t)0x01)
441 #define LOCK_ZONE_DATA_SLOT ((uint8_t)0x02)
442 #define LOCK_ZONE_NO_CRC ((uint8_t)0x80)
443 #define LOCK_ZONE_MASK (0xBF)
444 
448 #define MAC_MODE_IDX ATCA_PARAM1_IDX
449 #define MAC_KEYID_IDX ATCA_PARAM2_IDX
450 #define MAC_CHALLENGE_IDX ATCA_DATA_IDX
451 #define MAC_COUNT_SHORT ATCA_CMD_SIZE_MIN
452 #define MAC_COUNT_LONG (39)
453 #define MAC_MODE_CHALLENGE ((uint8_t)0x00)
454 #define MAC_MODE_BLOCK2_TEMPKEY ((uint8_t)0x01)
455 #define MAC_MODE_BLOCK1_TEMPKEY ((uint8_t)0x02)
456 #define MAC_MODE_SOURCE_FLAG_MATCH ((uint8_t)0x04)
457 #define MAC_MODE_PTNONCE_TEMPKEY ((uint8_t)0x06)
458 #define MAC_MODE_PASSTHROUGH ((uint8_t)0x07)
459 #define MAC_MODE_INCLUDE_OTP_88 ((uint8_t)0x10)
460 #define MAC_MODE_INCLUDE_OTP_64 ((uint8_t)0x20)
461 #define MAC_MODE_INCLUDE_SN ((uint8_t)0x40)
462 #define MAC_CHALLENGE_SIZE (32)
463 #define MAC_SIZE (32)
464 #define MAC_MODE_MASK ((uint8_t)0x77)
465 
469 #define NONCE_MODE_IDX ATCA_PARAM1_IDX
470 #define NONCE_PARAM2_IDX ATCA_PARAM2_IDX
471 #define NONCE_INPUT_IDX ATCA_DATA_IDX
472 #define NONCE_COUNT_SHORT (27)
473 #define NONCE_COUNT_LONG (39)
474 #define NONCE_MODE_MASK ((uint8_t)0x03)
475 #define NONCE_MODE_SEED_UPDATE ((uint8_t)0x00)
476 #define NONCE_MODE_NO_SEED_UPDATE ((uint8_t)0x01)
477 #define NONCE_MODE_INVALID ((uint8_t)0x02)
478 #define NONCE_MODE_PASSTHROUGH ((uint8_t)0x03)
479 #define NONCE_MODE_RANDOM_OUT ((uint16_t)0x0000)
480 #define NONCE_MODE_TEMPKEY_OUT ((uint16_t)0x0080)
481 #define NONCE_NUMIN_SIZE (20)
482 #define NONCE_NUMIN_SIZE_PASSTHROUGH (32)
483 
487 #define PAUSE_SELECT_IDX ATCA_PARAM1_IDX
488 #define PAUSE_PARAM2_IDX ATCA_PARAM2_IDX
489 #define PAUSE_COUNT ATCA_CMD_SIZE_MIN
490 
494 #define PRIVWRITE_ZONE_IDX ATCA_PARAM1_IDX
495 #define PRIVWRITE_KEYID_IDX ATCA_PARAM2_IDX
496 #define PRIVWRITE_VALUE_IDX ( 5)
497 #define PRIVWRITE_MAC_IDX (41)
498 #define PRIVWRITE_COUNT (75)
499 #define PRIVWRITE_ZONE_MASK ((uint8_t)0x40)
500 #define PRIVWRITE_MODE_ENCRYPT ((uint8_t)0x40)
501 
505 #define RANDOM_MODE_IDX ATCA_PARAM1_IDX
506 #define RANDOM_PARAM2_IDX ATCA_PARAM2_IDX
507 #define RANDOM_COUNT ATCA_CMD_SIZE_MIN
508 #define RANDOM_SEED_UPDATE ((uint8_t)0x00)
509 #define RANDOM_NO_SEED_UPDATE ((uint8_t)0x01)
510 #define RANDOM_NUM_SIZE ((uint8_t)0x20)
511 
515 #define READ_ZONE_IDX ATCA_PARAM1_IDX
516 #define READ_ADDR_IDX ATCA_PARAM2_IDX
517 #define READ_COUNT ATCA_CMD_SIZE_MIN
518 #define READ_ZONE_MASK ((uint8_t)0x83)
519 
523 #define SIGN_MODE_IDX ATCA_PARAM1_IDX
524 #define SIGN_KEYID_IDX ATCA_PARAM2_IDX
525 #define SIGN_COUNT ATCA_CMD_SIZE_MIN
526 #define SIGN_MODE_MASK ((uint8_t)0xC0)
527 #define SIGN_MODE_INTERNAL ((uint8_t)0x00)
528 #define SIGN_MODE_INCLUDE_SN ((uint8_t)0x40)
529 #define SIGN_MODE_EXTERNAL ((uint8_t)0x80)
530 
534 #define UPDATE_MODE_IDX ATCA_PARAM1_IDX
535 #define UPDATE_VALUE_IDX ATCA_PARAM2_IDX
536 #define UPDATE_COUNT ATCA_CMD_SIZE_MIN
537 #define UPDATE_CONFIG_BYTE_85 ((uint8_t)0x01)
538 
542 #define VERIFY_MODE_IDX ATCA_PARAM1_IDX
543 #define VERIFY_KEYID_IDX ATCA_PARAM2_IDX
544 #define VERIFY_DATA_IDX ( 5)
545 #define VERIFY_256_STORED_COUNT ( 71)
546 #define VERIFY_283_STORED_COUNT ( 79)
547 #define VERIFY_256_VALIDATE_COUNT ( 90)
548 #define VERIFY_283_VALIDATE_COUNT ( 98)
549 #define VERIFY_256_EXTERNAL_COUNT (135)
550 #define VERIFY_283_EXTERNAL_COUNT (151)
551 #define VERIFY_256_KEY_SIZE ( 64)
552 #define VERIFY_283_KEY_SIZE ( 72)
553 #define VERIFY_256_SIGNATURE_SIZE ( 64)
554 #define VERIFY_283_SIGNATURE_SIZE ( 72)
555 #define VERIFY_OTHER_DATA_SIZE ( 19)
556 #define VERIFY_MODE_MASK ((uint8_t)0x03)
557 #define VERIFY_MODE_STORED ((uint8_t)0x00)
558 #define VERIFY_MODE_VALIDATEEXTERNAL ((uint8_t)0x01)
559 #define VERIFY_MODE_EXTERNAL ((uint8_t)0x02)
560 #define VERIFY_MODE_VALIDATE ((uint8_t)0x03)
561 #define VERIFY_MODE_INVALIDATE ((uint8_t)0x07)
562 #define VERIFY_KEY_B283 ((uint16_t)0x0000)
563 #define VERIFY_KEY_K283 ((uint16_t)0x0001)
564 #define VERIFY_KEY_P256 ((uint16_t)0x0004)
565 
569 #define WRITE_ZONE_IDX ATCA_PARAM1_IDX
570 #define WRITE_ADDR_IDX ATCA_PARAM2_IDX
571 #define WRITE_VALUE_IDX ATCA_DATA_IDX
572 #define WRITE_MAC_VS_IDX ( 9)
573 #define WRITE_MAC_VL_IDX (37)
574 #define WRITE_COUNT_SHORT (11)
575 #define WRITE_COUNT_LONG (39)
576 #define WRITE_COUNT_SHORT_MAC (43)
577 #define WRITE_COUNT_LONG_MAC (71)
578 #define WRITE_MAC_SIZE (32)
579 #define WRITE_ZONE_MASK ((uint8_t)0xC3)
580 #define WRITE_ZONE_WITH_MAC ((uint8_t)0x40)
581 #define WRITE_ZONE_OTP ((uint8_t)1)
582 #define WRITE_ZONE_DATA ((uint8_t)2)
583 
587 #define CHECKMAC_RSP_SIZE ATCA_RSP_SIZE_MIN
588 #define DERIVE_KEY_RSP_SIZE ATCA_RSP_SIZE_MIN
589 #define GENDIG_RSP_SIZE ATCA_RSP_SIZE_MIN
590 #define GENKEY_RSP_SIZE_SHORT ATCA_RSP_SIZE_MIN
591 #define GENKEY_RSP_SIZE_LONG ATCA_RSP_SIZE_72
592 #define HMAC_RSP_SIZE ATCA_RSP_SIZE_32
593 #define INFO_RSP_SIZE ATCA_RSP_SIZE_VAL
594 #define LOCK_RSP_SIZE ATCA_RSP_SIZE_MIN
595 #define MAC_RSP_SIZE ATCA_RSP_SIZE_32
596 #define NONCE_RSP_SIZE_SHORT ATCA_RSP_SIZE_MIN
597 #define NONCE_RSP_SIZE_LONG ATCA_RSP_SIZE_32
598 #define PAUSE_RSP_SIZE ATCA_RSP_SIZE_MIN
599 #define PRIVWRITE_RSP_SIZE ATCA_RSP_SIZE_MIN
600 #define RANDOM_RSP_SIZE ATCA_RSP_SIZE_32
601 #define READ_4_RSP_SIZE ATCA_RSP_SIZE_VAL
602 #define READ_32_RSP_SIZE ATCA_RSP_SIZE_32
603 #define SIGN_RSP_SIZE ATCA_RSP_SIZE_MAX
604 #define SHA_RSP_SIZE ATCA_RSP_SIZE_32
605 #define UPDATE_RSP_SIZE ATCA_RSP_SIZE_MIN
606 #define VERIFY_RSP_SIZE ATCA_RSP_SIZE_MIN
607 #define WRITE_RSP_SIZE ATCA_RSP_SIZE_MIN
608 
609 #define ECDH_KEY_SIZE ATCA_BLOCK_SIZE
610 #define ECDH_RSP_SIZE ATCA_RSP_SIZE_32
611 #define COUNTER_RSP_SIZE ATCA_RSP_SIZE_4
612 #define SHA_RSP_SIZE_SHORT ATCA_RSP_SIZE_MIN
613 #define SHA_RSP_SIZE_LONG ATCA_RSP_SIZE_32
614 
615 #ifdef __cplusplus
616 }
617 #endif
618 #endif
619 
uint8_t atCheckCrc(uint8_t *response)
This function checks the consistency of a response.
Definition: atca_command.c:693
Definition: atca_command.h:146
ATCA_STATUS atMAC(ATCACommand cacmd, ATCAPacket *packet)
ATCACommand MAC method.
Definition: atca_command.c:277
enum_sha_mode
Definition: atca_command.h:320
Definition: atca_command.h:148
an ATCA packet structure. This is a superset of the packet transmitted on the wire. It's also used as a buffer for receiving the response
Definition: atca_command.h:89
atca_command is the C object backing ATCACommand. See the atca_command.h file for details on the ATCA...
Definition: atca_command.c:61
ATCACommand newATCACommand(ATCADeviceType device_type)
constructor for ATCACommand
Definition: atca_command.c:71
ATCA_STATUS atVerify(ATCACommand cacmd, ATCAPacket *packet)
ATCACommand ECDSA Verify method.
Definition: atca_command.c:463
Definition: atca_command.h:310
ATCA_STATUS atSign(ATCACommand cacmd, ATCAPacket *packet)
ATCACommand Sign method.
Definition: atca_command.c:427
Definition: atca_command.h:160
uint8_t opcode
Definition: atca_command.h:96
Definition: atca_command.h:327
ATCA is meant to be portable across architectures, even non-Atmel architectures and compiler environm...
ATCADeviceType
Definition: atca_devtypes.h:53
ATCA_STATUS
Definition: atca_status.h:55
uint8_t param1
Definition: atca_command.h:97
Definition: atca_command.h:159
Definition: atca_command.h:152
ATCA_STATUS atWriteEnc(ATCACommand cacmd, ATCAPacket *packet)
ATCACommand Write encrypted method.
Definition: atca_command.c:528
uint16_t rxsize
Definition: atca_command.h:107
Definition: atca_command.h:143
ATCA_STATUS atInfo(ATCACommand cacmd, ATCAPacket *packet)
ATCACommand Info method.
Definition: atca_command.c:243
ATCA_STATUS atSHA(ATCACommand cacmd, ATCAPacket *packet)
ATCACommand SHA method.
Definition: atca_command.c:395
Definition: atca_command.h:147
Definition: atca_command.h:309
uint8_t execTime
Definition: atca_command.h:106
ATCA_STATUS atUpdateExtra(ATCACommand cacmd, ATCAPacket *packet)
ATCACommand UpdateExtra method.
Definition: atca_command.c:446
void atCRC(uint8_t length, uint8_t *data, uint8_t *crc)
This function calculates CRC given raw data, puts the CRC to given pointer.
Definition: atca_command.c:649
Definition: atca_command.h:144
ATCA_CmdMap
Definition: atca_command.h:142
Definition: atca_command.h:145
ATCA_STATUS atGenKey(ATCACommand cacmd, ATCAPacket *packet, bool isPubKey)
ATCACommand Generate Key method.
Definition: atca_command.c:200
Definition: atca_command.h:154
uint16_t atGetExecTime(ATCACommand cacmd, ATCA_CmdMap cmd)
return the typical execution type for the given command
Definition: atca_command.c:636
Complete the calculation and load the digest.
Definition: atca_command.h:323
void deleteATCACommand(ATCACommand *)
ATCACommand destructor.
Definition: atca_command.c:542
Definition: atca_command.h:151
ATCA_STATUS atPrivWrite(ATCACommand cacmd, ATCAPacket *packet)
ATCACommand PrivWrite method.
Definition: atca_command.c:340
ATCA_STATUS isATCAError(uint8_t *data)
checks for basic error frame in data
Definition: atca_command.c:747
ATCA_STATUS atNonce(ATCACommand cacmd, ATCAPacket *packet)
ATCACommand Nonce method.
Definition: atca_command.c:299
ATCA_STATUS atRandom(ATCACommand cacmd, ATCAPacket *packet)
ATCACommand Random method.
Definition: atca_command.c:356
Definition: atca_command.h:164
bool atIsSHAFamily(ATCADeviceType deviceType)
determines if a given device type is a SHA device or a superset of a SHA device
Definition: atca_command.c:710
Atmel Crypto Auth.
Definition: atca_command.h:156
ATCA_STATUS atECDH(ATCACommand cacmd, ATCAPacket *packet)
ATCACommand ECDH method.
Definition: atca_command.c:157
Definition: atca_command.h:162
void atCalcCrc(ATCAPacket *pkt)
This function calculates CRC and adds it to the correct offset in the packet data.
Definition: atca_command.c:675
Private Key Creation.
Definition: atca_command.h:398
Definition: atca_command.h:158
ATCA_STATUS atRead(ATCACommand cacmd, ATCAPacket *packet)
ATCACommand Read method.
Definition: atca_command.c:373
ATCA_STATUS atHMAC(ATCACommand cacmd, ATCAPacket *packet)
ATCACommand HMAC method.
Definition: atca_command.c:226
struct atca_command * ATCACommand
Definition: atca_command.h:60
ATCA_STATUS atWrite(ATCACommand cacmd, ATCAPacket *packet)
ATCACommand Write method.
Definition: atca_command.c:498
Add 64 bytes in the meesage to the SHA context.
Definition: atca_command.h:322
Definition: atca_command.h:326
uint8_t txsize
Definition: atca_command.h:95
Initialization, does not accept a message.
Definition: atca_command.h:321
Definition: atca_command.h:157
ATCA_STATUS atDeriveKey(ATCACommand cacmd, ATCAPacket *packet, bool hasMAC)
ATCACommand DeriveKey method.
Definition: atca_command.c:131
enum_counter_mode
Definition: atca_command.h:308
Add 64 bytes in the slot to the SHA context.
Definition: atca_command.h:324
Public Key Computation.
Definition: atca_command.h:399
ATCA_STATUS atCheckMAC(ATCACommand cacmd, ATCAPacket *packet)
ATCACommand CheckMAC method.
Definition: atca_command.c:95
Atmel Crypto Auth status codes.
enum_genkey_mode
Definition: atca_command.h:397
Definition: atca_command.h:161
ATCA_STATUS atGenDig(ATCACommand cacmd, ATCAPacket *packet, bool hasMACKey)
ATCACommand Generate Digest method.
Definition: atca_command.c:175
ATCA_STATUS atInitExecTimes(ATCACommand cacmd, ATCADeviceType device_type)
initialize the execution times for a given device type
Definition: atca_command.c:611
uint8_t _reserved
Definition: atca_command.h:92
Initialization.
Definition: atca_command.h:325
ATCA_STATUS atPause(ATCACommand cacmd, ATCAPacket *packet)
ATCACommand Pause method.
Definition: atca_command.c:324
Definition: atca_command.h:149
Definition: atca_command.h:150
Digest Calculation.
Definition: atca_command.h:400
uint16_t param2
Definition: atca_command.h:98
ATCA_STATUS atLock(ATCACommand cacmd, ATCAPacket *packet)
ATCACommand Lock method.
Definition: atca_command.c:260
Definition: atca_command.h:155
Definition: atca_command.h:163
ATCA_STATUS atCounter(ATCACommand cacmd, ATCAPacket *packet)
ATCACommand Counter method.
Definition: atca_command.c:111
Definition: atca_command.h:153
bool atIsECCFamily(ATCADeviceType deviceType)
determines if a given device type is an ECC device or a superset of a ECC device
Definition: atca_command.c:729