Skip to content

Mbed TLS cannot be built with AES-XTS support #2254

Closed
@ainaracatgirl

Description

@ainaracatgirl

I'm trying to use the built-in pico_mbedtls library to use Mbed TLS to encrypt data using AES-XTS.

However, no matter what I try, the result remains same: no error when compiling my code, but an error at linking because it cannot find the XTS-related symbols.

I have tried adding the MBEDTLS_CIPHER_MODE_XTS=1 define in every possible way: into CMAKE_C_FLAGS, inside mbedtls_config.h, with add_compile_definitions(...) and both target_compile_definitions(pico_mbedtls_crypto INTERFACE ...) and target_compile_definitions(pico_mbedtls INTERFACE ...).

/path/to/ld: CMakeFiles/path/to/kmain.c.o: in function `aes256_xts_test':
/path/to/bench.c:76:(.text.aes256_xts_test+0x10): undefined reference to `mbedtls_aes_xts_init'
/path/to/ld: /path/to/bench.c:77:(.text.aes256_xts_test+0x1c): undefined reference to `mbedtls_aes_xts_setkey_enc'
/path/to/ld: /path/to/bench.c:83:(.text.aes256_xts_test+0x46): undefined reference to `mbedtls_aes_crypt_xts'
/path/to/ld: /path/to/bench.c:87:(.text.aes256_xts_test+0x5a): undefined reference to `mbedtls_aes_xts_setkey_dec'
/path/to/ld: /path/to/bench.c:93:(.text.aes256_xts_test+0x7e): undefined reference to `mbedtls_aes_crypt_xts'
/path/to/ld: /path/to/bench.c:104:(.text.aes256_xts_test+0xa4): undefined reference to `mbedtls_aes_xts_free'
collect2: error: ld returned 1 exit status

(yes, I am importing bench.c directly from kmain.c without using a header file as this is a temporary test that will get removed afterwards)

The relevant parts of my CMakeLists.txt are the following (with the project name replaced with ProjectNameHere):

cmake_minimum_required(VERSION 3.13)
include(pico_sdk_import.cmake)

set(CMAKE_C_STANDARD 11)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

project(ProjectNameHere)
pico_sdk_init()

target_compile_definitions(pico_mbedtls_crypto INTERFACE MBEDTLS_CIPHER_MODE_XTS=1)
target_compile_definitions(pico_mbedtls INTERFACE MBEDTLS_CIPHER_MODE_XTS=1)

set(MBEDTLS_USER_CONFIG_FILE "${CMAKE_CURRENT_LIST_DIR}/src/mbedtls_config.h")
set(PICO_MBEDTLS_CONFIG_FILE "${CMAKE_CURRENT_LIST_DIR}/src/mbedtls_config.h")
add_compile_definitions(MBEDTLS_CIPHER_MODE_XTS=1)

add_executable(ProjectNameHere
  src/kmain.c
)

target_link_libraries(ProjectNameHere
  pico_stdio pico_stdlib pico_rand
  hardware_exception hardware_watchdog hardware_clocks
  pico_sha256 pico_mbedtls
)

target_include_directories(ProjectNameHere PRIVATE src/)

pico_enable_stdio_usb(ProjectNameHere 1)
pico_enable_stdio_uart(ProjectNameHere 1)

pico_set_program_name(ProjectNameHere "Project Name Here")
pico_set_program_version(ProjectNameHere "1.0")
pico_add_extra_outputs(ProjectNameHere)

Is there something wrong in my end, or is this a shortcoming of the SDK's design?

Thanks in advance,
Ainara Garcia

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions