Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

uECC Conflict - Multiple definitions by TinyCrypt and Cordio #2

Open
AGlass0fMilk opened this issue Nov 5, 2020 · 3 comments
Open

Comments

@AGlass0fMilk
Copy link
Owner

When building this mcuboot blinky application for Bluetooth-enabled Mbed targets using the Cordio stack, the TinyCrypt uECC symbols conflict with those used by the Cordio link layer.

The Cordio link layer uses micro-ecc:

https://github.com/ARMmbed/mbed-os/blob/cdc2d45e05622f375d222b1920a9df148c5acbab/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.c#L1-L18

The TinyCrypt implementation appears to be based on the same micro-ecc library with some modifications:
https://github.com/mcu-tools/mcuboot/blob/30898fc0038734df274e301a2f5471cb5f6c54c1/ext/tinycrypt/lib/source/ecc_dsa.c#L161-L185

Attempting to compile the example for the nRF52840_DK target results in the following build errors:

Link: mbed-mcuboot-blinky
/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: BUILD/NRF52840_DK/GCC_ARM/mcuboot/ext/tinycrypt/lib/source/ecc.o: in function `uECC_set_rng':
/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mcuboot/ext/tinycrypt/lib/source/ecc.c:69: multiple definition of `uECC_set_rng'; BUILD/NRF52840_DK/GCC_ARM/mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.o:/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.c:471: first defined here
/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: BUILD/NRF52840_DK/GCC_ARM/mcuboot/ext/tinycrypt/lib/source/ecc.o: in function `uECC_valid_public_key':
/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mcuboot/ext/tinycrypt/lib/source/ecc.c:891: multiple definition of `uECC_valid_public_key'; BUILD/NRF52840_DK/GCC_ARM/mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.o:/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.c:2115: first defined here
/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: BUILD/NRF52840_DK/GCC_ARM/mcuboot/ext/tinycrypt/lib/source/ecc.o: in function `uECC_compute_public_key':
/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mcuboot/ext/tinycrypt/lib/source/ecc.c:910: multiple definition of `uECC_compute_public_key'; BUILD/NRF52840_DK/GCC_ARM/mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.o:/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.c:2141: first defined here
/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: BUILD/NRF52840_DK/GCC_ARM/mcuboot/ext/tinycrypt/lib/source/ecc_dh.o: in function `uECC_make_key':
/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mcuboot/ext/tinycrypt/lib/source/ecc_dh.c:103: multiple definition of `uECC_make_key'; BUILD/NRF52840_DK/GCC_ARM/mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.o:/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.c:2017: first defined here
/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: BUILD/NRF52840_DK/GCC_ARM/mcuboot/ext/tinycrypt/lib/source/ecc_dh.o: in function `uECC_shared_secret':
/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mcuboot/ext/tinycrypt/lib/source/ecc_dh.c:146: multiple definition of `uECC_shared_secret'; BUILD/NRF52840_DK/GCC_ARM/mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.o:/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.c:2035: first defined here
/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: BUILD/NRF52840_DK/GCC_ARM/mcuboot/ext/tinycrypt/lib/source/ecc_dsa.o: in function `uECC_sign':
/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mcuboot/ext/tinycrypt/lib/source/ecc_dsa.c:163: multiple definition of `uECC_sign'; BUILD/NRF52840_DK/GCC_ARM/mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.o:/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.c:2523: first defined here
/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: BUILD/NRF52840_DK/GCC_ARM/mcuboot/ext/tinycrypt/lib/source/ecc_dsa.o: in function `uECC_verify':
/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mcuboot/ext/tinycrypt/lib/source/ecc_dsa.c:195: multiple definition of `uECC_verify'; BUILD/NRF52840_DK/GCC_ARM/mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.o:/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.c:2661: first defined here
collect2: error: ld returned 1 exit status
[ERROR] /opt/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: BUILD/NRF52840_DK/GCC_ARM/mcuboot/ext/tinycrypt/lib/source/ecc.o: in function `uECC_set_rng':
/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mcuboot/ext/tinycrypt/lib/source/ecc.c:69: multiple definition of `uECC_set_rng'; BUILD/NRF52840_DK/GCC_ARM/mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.o:/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.c:471: first defined here
/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: BUILD/NRF52840_DK/GCC_ARM/mcuboot/ext/tinycrypt/lib/source/ecc.o: in function `uECC_valid_public_key':
/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mcuboot/ext/tinycrypt/lib/source/ecc.c:891: multiple definition of `uECC_valid_public_key'; BUILD/NRF52840_DK/GCC_ARM/mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.o:/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.c:2115: first defined here
/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: BUILD/NRF52840_DK/GCC_ARM/mcuboot/ext/tinycrypt/lib/source/ecc.o: in function `uECC_compute_public_key':
/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mcuboot/ext/tinycrypt/lib/source/ecc.c:910: multiple definition of `uECC_compute_public_key'; BUILD/NRF52840_DK/GCC_ARM/mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.o:/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.c:2141: first defined here
/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: BUILD/NRF52840_DK/GCC_ARM/mcuboot/ext/tinycrypt/lib/source/ecc_dh.o: in function `uECC_make_key':
/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mcuboot/ext/tinycrypt/lib/source/ecc_dh.c:103: multiple definition of `uECC_make_key'; BUILD/NRF52840_DK/GCC_ARM/mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.o:/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.c:2017: first defined here
/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: BUILD/NRF52840_DK/GCC_ARM/mcuboot/ext/tinycrypt/lib/source/ecc_dh.o: in function `uECC_shared_secret':
/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mcuboot/ext/tinycrypt/lib/source/ecc_dh.c:146: multiple definition of `uECC_shared_secret'; BUILD/NRF52840_DK/GCC_ARM/mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.o:/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.c:2035: first defined here
/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: BUILD/NRF52840_DK/GCC_ARM/mcuboot/ext/tinycrypt/lib/source/ecc_dsa.o: in function `uECC_sign':
/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mcuboot/ext/tinycrypt/lib/source/ecc_dsa.c:163: multiple definition of `uECC_sign'; BUILD/NRF52840_DK/GCC_ARM/mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.o:/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.c:2523: first defined here
/opt/gcc-arm-none-eabi-9-2019-q4-major/bin/../lib/gcc/arm-none-eabi/9.2.1/../../../../arm-none-eabi/bin/ld: BUILD/NRF52840_DK/GCC_ARM/mcuboot/ext/tinycrypt/lib/source/ecc_dsa.o: in function `uECC_verify':
/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mcuboot/ext/tinycrypt/lib/source/ecc_dsa.c:195: multiple definition of `uECC_verify'; BUILD/NRF52840_DK/GCC_ARM/mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.o:/home/gdbeckstein/Documents/embeddedplanet/mbed-mcuboot-blinky/./mbed-os/connectivity/FEATURE_BLE/libraries/TARGET_CORDIO_LL/stack/thirdparty/uecc/uECC.c:2661: first defined here

@LDong-Arm @evedon @pan-

Any thoughts on the best path forward to mitigate conflicts? Would it be possible to rename the symbols in the Cordio stack implementation?

The two implementations do not seem to be compatible.

Perhaps this will be fixed when the cmake tools are adopted? I don't think the uECC calls are needed by the application and so these files can be selectively excluded from the cmake build for the application.

@AGlass0fMilk
Copy link
Owner Author

We may want to issue a patch commit to the mcuboot repository to exclude the tinycrypt library from the build to avoid this for now. We will also have to disable the use of tinycrypt until the cmake build tools are ready to go.

@LDong-Arm
Copy link
Contributor

We are really held back by the current build system :( There's not much we can do apart from disabling TinyCrypt.

For the user application, we only need boot_set_confirmed(), boot_set_pending() and boot_swap_type() (the last one checks if the app is freshly updated and need to be verified/confirmed) so crypto shouldn't be compiled. Once we have CMake, we can conditionally compile what's needed.

@AGlass0fMilk
Copy link
Owner Author

For now, mbed-os port of mcuboot has been patched to temporarily disable support for the TinyCrypt backend. Once the new build tools are released we can revisit this.

I will leave the issue open for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants