|
15 | 15 | #ifndef _ATECC_H_
|
16 | 16 | #define _ATECC_H_
|
17 | 17 |
|
| 18 | +/* ATECC implementation of the secure chip functions. */ |
| 19 | +/* See securechip.h for the docstrings of the individual functions. */ |
| 20 | + |
18 | 21 | #include "compiler_util.h"
|
19 | 22 | #include "securechip/securechip.h"
|
20 | 23 | #include <platform/platform_config.h>
|
21 | 24 | #include <stdbool.h>
|
22 | 25 | #include <stddef.h>
|
23 | 26 | #include <stdint.h>
|
24 | 27 |
|
25 |
| -typedef enum { |
26 |
| - ATECC_ERR_ZONE_UNLOCKED_CONFIG = -1, |
27 |
| - ATECC_ERR_ZONE_UNLOCKED_DATA = -2, |
28 |
| - ATECC_ERR_CONFIG_MISMATCH = -3, |
29 |
| - ATECC_ERR_SLOT_UNLOCKED_IO = -4, |
30 |
| - ATECC_ERR_SLOT_UNLOCKED_AUTH = -5, |
31 |
| - ATECC_ERR_SLOT_UNLOCKED_ENC = -6, |
32 |
| - ATECC_ERR_IFS = -7, |
33 |
| - ATECC_ERR_INVALID_ARGS = -8, |
34 |
| -} atecc_error_t; |
35 |
| - |
36 |
| -/** |
37 |
| - * Initializes the cryptoauthlib communication, by providing a custom i2c chip |
38 |
| - * communication interface/bridge to cryptoauthlib. On first call, the chip |
39 |
| - * is configured and locked. |
40 |
| - * @param[in] ifs Interface functions. |
41 |
| - * @return values of `atecc_error_t` if negative, values of `ATCA_STATUS` if positive, 0 on |
42 |
| - * success. |
43 |
| - */ |
44 | 28 | USE_RESULT int atecc_setup(const securechip_interface_functions_t* ifs);
|
45 |
| - |
46 |
| -/** |
47 |
| - * Updates the two KDF keys (rollkey and kdf key). The previous keys are lost |
48 |
| - * and cannot be restored. Calling this function does not increment the |
49 |
| - * monotonic counter Counter0. |
50 |
| - * @return true on success. |
51 |
| - */ |
52 | 29 | USE_RESULT bool atecc_update_keys(void);
|
53 |
| - |
54 |
| -/** |
55 |
| - * Perform HMAC using the key in KDF slot with the input msg. |
56 |
| - * @param[in] msg Use this msg as input |
57 |
| - * @param[in] len Must be <= 127. |
58 |
| - * @param[out] kdf_out Must have size 32. Result of the kdf will be stored here. |
59 |
| - * Cannot be the same as `msg`. |
60 |
| - * @return values of `atecc_error_t` if negative, values of `ATCA_STATUS` if positive, 0 on |
61 |
| - */ |
62 | 30 | USE_RESULT int atecc_kdf(const uint8_t* msg, size_t len, uint8_t* kdf_out);
|
63 |
| - |
64 |
| -/** |
65 |
| - * Perform KDF using the key in rollkey slot with the input msg. |
66 |
| - * Calling this function increments the |
67 |
| - * monotonic counter Counter0. |
68 |
| - * @param[in] msg Use this msg as input |
69 |
| - * @param[in] len Must be <= 127. |
70 |
| - * @param[out] kdf_out Must have size 32. Result of the kdf will be stored here. |
71 |
| - * Cannot be the same as `msg`. |
72 |
| - * @return values of `securechip_error_t` if negative, values of `ATCA_STATUS` if positive, 0 on |
73 |
| - */ |
74 | 31 | USE_RESULT int atecc_kdf_rollkey(const uint8_t* msg, size_t len, uint8_t* kdf_out);
|
75 |
| - |
76 |
| -/** |
77 |
| - * Generates a new attestation device key and outputs the public key. |
78 |
| - * @param[out] pubkey_out |
79 |
| - */ |
80 | 32 | USE_RESULT bool atecc_gen_attestation_key(uint8_t* pubkey_out);
|
81 |
| - |
82 |
| -/** |
83 |
| - * @param[in] msg 32 byte message to sign. |
84 |
| - * @param[out] signature_out must be 64 bytes. R/S P256 signature. |
85 |
| - */ |
86 | 33 | USE_RESULT bool atecc_attestation_sign(const uint8_t* challenge, uint8_t* signature_out);
|
87 |
| - |
88 |
| -/** |
89 |
| - * Retrieves the number of remaining possible counter increments (max value - Counter0). |
90 |
| - * The counter is increment when using `atecc_kdf()` (see its docstring). |
91 |
| - * @param[out] remaining_out current value of the monotonic counter. |
92 |
| - * @return false if there was a communication error with the SC. |
93 |
| - */ |
94 | 34 | USE_RESULT bool atecc_monotonic_increments_remaining(uint32_t* remaining_out);
|
95 |
| - |
96 |
| -/** |
97 |
| - * @param[out] rand_out must be 32 bytes. |
98 |
| - */ |
99 | 35 | USE_RESULT bool atecc_random(uint8_t* rand_out);
|
100 |
| - |
101 | 36 | #if APP_U2F == 1 || FACTORYSETUP == 1
|
102 |
| -/** |
103 |
| - * Set the u2f counter to `counter`. Should only be used for initialization. |
104 |
| - * @param[in] counter Value to set counter to |
105 |
| - * @return True if success |
106 |
| - */ |
107 | 37 | USE_RESULT bool atecc_u2f_counter_set(uint32_t counter);
|
108 | 38 | #endif
|
109 |
| - |
110 | 39 | #if APP_U2F == 1
|
111 |
| -/** |
112 |
| - * Monotonically increase the U2F counter and return the current value |
113 |
| - * @param[out] counter Next counter value |
114 |
| - * @return True if success |
115 |
| - */ |
116 | 40 | USE_RESULT bool atecc_u2f_counter_inc(uint32_t* counter);
|
117 | 41 | #endif
|
118 |
| - |
119 |
| -/** |
120 |
| - * Output the atecc model. |
121 |
| - * @param[out] model_out atecc model |
122 |
| - * @return True if success |
123 |
| - */ |
124 | 42 | USE_RESULT bool atecc_model(securechip_model_t* model_out);
|
125 | 43 |
|
126 | 44 | #endif
|
0 commit comments