Skip to content

Commit f40a0d7

Browse files
committed
external: upgrade cryptoauthlib to v3.2.5
The library handling the secure chip. https://github.com/digitalbitbox/cryptoauthlib/tree/v3.2.5 See also: https://github.com/MicrochipTech/cryptoauthlib/wiki/Upgrading-to-v3.2#api-changes-between-v31x-and-v32x There is a new param `word_address` that according to the docs above is supposed to be sent as the first byte. We do this already manually by sending 0x03: https://github.com/digitalbitbox/bitbox02-firmware/blob/7ebb8450be8f3f9f3232f1407bfcaec4d22257e4/src/securechip/securechip.c#L134. The actual `word_address` param as set by cryptoauthlib is always 0xFF as that is the default [here](https://github.com/digitalbitbox/cryptoauthlib/blob/v3.2.5/lib/calib/calib_execution.c#L302) and not 0x03 as set [here](https://github.com/digitalbitbox/cryptoauthlib/blob/v3.2.5/lib/calib/calib_execution.c#L325) because we define iface type to be ATCA_CUSTOM_IFACE [here](https://github.com/digitalbitbox/bitbox02-firmware/blob/7ebb8450be8f3f9f3232f1407bfcaec4d22257e4/src/securechip/securechip.c#L186). 0xFF is basically a dummy value and defers to the custom implementation (ATCA_CUSTOM_IFACE). The cryptoauthlib driver code (which we currently don't use, but is a good reference) also newly sends the word address before reading: https://github.com/MicrochipTech/cryptoauthlib/blob/v3.2.5/lib/hal/hal_i2c_start.c#L230-L240. I did not port this to our securechip.c/_receive function in this commit as we didn't do it before, it seems to work without, and I could not figure out the purpose of sending the word address before reading.
1 parent b5b39d0 commit f40a0d7

File tree

4 files changed

+75
-26
lines changed

4 files changed

+75
-26
lines changed

external/CMakeLists.txt

Lines changed: 31 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -192,37 +192,46 @@ set_property(TARGET asf4-drivers PROPERTY INTERFACE_LINK_LIBRARIES "")
192192
cryptoauthlib/lib/atca_cfgs.c
193193
cryptoauthlib/lib/atca_command.c
194194
cryptoauthlib/lib/atca_device.c
195-
cryptoauthlib/lib/atca_execution.c
196195
cryptoauthlib/lib/atca_iface.c
197196
cryptoauthlib/lib/hal/atca_hal.c
198197
cryptoauthlib/lib/hal/hal_timer_start.c
199-
cryptoauthlib/lib/basic/atca_basic.c
200-
cryptoauthlib/lib/basic/atca_basic_counter.c
201-
cryptoauthlib/lib/basic/atca_basic_gendig.c
202-
cryptoauthlib/lib/basic/atca_basic_nonce.c
203-
cryptoauthlib/lib/basic/atca_basic_checkmac.c
204-
cryptoauthlib/lib/basic/atca_basic_info.c
205-
cryptoauthlib/lib/basic/atca_basic_derivekey.c
206-
cryptoauthlib/lib/basic/atca_basic_random.c
207-
cryptoauthlib/lib/basic/atca_basic_selftest.c
208-
cryptoauthlib/lib/basic/atca_basic_read.c
209-
cryptoauthlib/lib/basic/atca_basic_privwrite.c
210-
cryptoauthlib/lib/basic/atca_basic_verify.c
211-
cryptoauthlib/lib/basic/atca_basic_write.c
212-
cryptoauthlib/lib/basic/atca_basic_updateextra.c
213-
cryptoauthlib/lib/basic/atca_basic_lock.c
214-
cryptoauthlib/lib/basic/atca_basic_kdf.c
215-
cryptoauthlib/lib/basic/atca_basic_genkey.c
216-
cryptoauthlib/lib/basic/atca_basic_sign.c
198+
cryptoauthlib/lib/atca_basic.c
199+
cryptoauthlib/lib/atca_debug.c
200+
cryptoauthlib/lib/calib/calib_basic.c
201+
cryptoauthlib/lib/calib/calib_command.c
202+
cryptoauthlib/lib/calib/calib_execution.c
203+
cryptoauthlib/lib/calib/calib_counter.c
204+
cryptoauthlib/lib/calib/calib_gendig.c
205+
cryptoauthlib/lib/calib/calib_nonce.c
206+
cryptoauthlib/lib/calib/calib_checkmac.c
207+
cryptoauthlib/lib/calib/calib_info.c
208+
cryptoauthlib/lib/calib/calib_derivekey.c
209+
cryptoauthlib/lib/calib/calib_random.c
210+
cryptoauthlib/lib/calib/calib_selftest.c
211+
cryptoauthlib/lib/calib/calib_read.c
212+
cryptoauthlib/lib/calib/calib_privwrite.c
213+
cryptoauthlib/lib/calib/calib_verify.c
214+
cryptoauthlib/lib/calib/calib_write.c
215+
cryptoauthlib/lib/calib/calib_updateextra.c
216+
cryptoauthlib/lib/calib/calib_lock.c
217+
cryptoauthlib/lib/calib/calib_kdf.c
218+
cryptoauthlib/lib/calib/calib_genkey.c
219+
cryptoauthlib/lib/calib/calib_sign.c
217220
cryptoauthlib/lib/host/atca_host.c
218221
cryptoauthlib/lib/crypto/hashes/sha2_routines.c
219222
cryptoauthlib/lib/crypto/atca_crypto_sw_sha2.c
220223
)
221224
target_link_libraries(cryptoauthlib samd51a-ds asf4-drivers-min)
222225
set_property(TARGET cryptoauthlib PROPERTY INTERFACE_LINK_LIBRARIES "")
223-
target_compile_definitions(cryptoauthlib PUBLIC ATCA_HAL_CUSTOM ATCA_NO_POLL)
224-
target_include_directories(cryptoauthlib SYSTEM PUBLIC cryptoauthlib/lib)
225-
target_compile_options(cryptoauthlib PRIVATE -Wno-pedantic -Wno-incompatible-pointer-types -Wno-unused-parameter -Wno-unused-variable -Wno-cast-qual)
226+
target_compile_definitions(cryptoauthlib PUBLIC ATCA_NO_POLL)
227+
target_include_directories(cryptoauthlib SYSTEM PUBLIC
228+
cryptoauthlib/lib
229+
${CMAKE_CURRENT_SOURCE_DIR} # for the BitBox02-custom "atca_config.h"
230+
)
231+
target_compile_options(cryptoauthlib PRIVATE
232+
-Wno-pedantic -Wno-incompatible-pointer-types -Wno-unused-parameter -Wno-unused-variable -Wno-cast-qual
233+
-Wno-switch-default -Wno-format-nonliteral -Wno-missing-prototypes -Wno-missing-declarations
234+
)
226235
endif() # CMAKE_CROSSCOMPILING
227236

228237
# fatfs must to be linked together with a diskio middleware:

external/atca_config.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2020 Shift Crypto AG
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
// This file is based on the snippet from cryptoauthlib/README.md:
16+
// https://github.com/digitalbitbox/cryptoauthlib/tree/v3.2.5#configuration
17+
18+
/* Cryptoauthlib Configuration File */
19+
#ifndef ATCA_CONFIG_H
20+
#define ATCA_CONFIG_H
21+
22+
/* Include HALS */
23+
// Shift: we currently use a custom HAL config, see `ATCAIfaceCfg cfg` in securechip.c.
24+
#define ATCA_HAL_CUSTOM
25+
26+
/* Included device support */
27+
#define ATCA_ATECC608_SUPPORT
28+
29+
/* \brief How long to wait after an initial wake failure for the POST to
30+
* complete.
31+
* If Power-on self test (POST) is enabled, the self test will run on waking
32+
* from sleep or during power-on, which delays the wake reply.
33+
*/
34+
#ifndef ATCA_POST_DELAY_MSEC
35+
#define ATCA_POST_DELAY_MSEC 25
36+
#endif
37+
38+
#endif // ATCA_CONFIG_H

external/cryptoauthlib

src/securechip/securechip.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -110,9 +110,10 @@ static ATCA_STATUS _post_init(void* iface)
110110
* As output, the number of bytes received.
111111
* \return ATCA_SUCCESS on success, otherwise an error code.
112112
*/
113-
static ATCA_STATUS _receive(void* iface, uint8_t* rxdata, uint16_t* rxlength)
113+
static ATCA_STATUS _receive(void* iface, uint8_t word_address, uint8_t* rxdata, uint16_t* rxlength)
114114
{
115115
(void)iface;
116+
(void)word_address;
116117
uint8_t ret = i2c_ecc_read(rxdata, *rxlength);
117118
if (ret) {
118119
return ATCA_COMM_FAIL;
@@ -127,9 +128,10 @@ static ATCA_STATUS _receive(void* iface, uint8_t* rxdata, uint16_t* rxlength)
127128
* \param[in] txlength number of bytes to send
128129
* \return ATCA_SUCCESS on success, otherwise an error code.
129130
*/
130-
static ATCA_STATUS _send(void* iface, uint8_t* txdata, int txlength)
131+
static ATCA_STATUS _send(void* iface, uint8_t word_address, uint8_t* txdata, int txlength)
131132
{
132133
(void)iface;
134+
(void)word_address;
133135
// txdata[0] is using _reserved byte of the ATCAPacket
134136
txdata[0] = I2C_ECC_CHIP_CMD;
135137
// Account for the _reserved byte, similar to
@@ -184,7 +186,7 @@ static ATCAIfaceCfg cfg = {
184186
// TODO: can likely use cryptoauthlib/lib/hal/hal_i2c_start.(c|h) for all or
185187
// some of the functionality, possibly using cfg_ateccx08a_i2c_default
186188
.iface_type = ATCA_CUSTOM_IFACE,
187-
.devtype = ATECC608A,
189+
.devtype = ATECC608,
188190
.atcacustom.halinit = &_init,
189191
.atcacustom.halpostinit = &_post_init,
190192
.atcacustom.halreceive = &_receive,

0 commit comments

Comments
 (0)