Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs

mbedtls backend undefined reference to many things

Trying to setup mbedtls backend for AES CBC. Ive included the mbedtls_backend_aes.c and init.c, I've added the folders to the user include directories, I've enabled stuff in the sdk_config, I am getting a bunch of undefined reference errors

3> C:\Users\jgusler\Desktop\nRF5_SDK_17.1.0\components\libraries\crypto\backend\mbedtls\mbedtls_backend_init.c:86:11: warning: implicit declaration of function 'mbedtls_platform_set_calloc_free' [-Wimplicit-function-declaration]
3> 86 | (void)mbedtls_platform_set_calloc_free(mbedtls_backend_calloc, mbedtls_backend_free);
3> | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8> Generating linker script ‘ble_app_uart_pca10056_s140.ld’
8> Linking ble_app_uart_pca10056_s140.elf
8> C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 6.34a/gcc/arm-none-eabi/bin/ld: Output/Release/Obj/ble_app_uart_pca10056_s140/mbedtls_backend_aes.o: in function `backend_mbedtls_key_set':
8> C:\Users\jgusler\Desktop\nRF5_SDK_17.1.0\components\libraries\crypto\backend\mbedtls/mbedtls_backend_aes.c:338: undefined reference to `mbedtls_aes_setkey_enc'
8> C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 6.34a/gcc/arm-none-eabi/bin/ld: C:\Users\jgusler\Desktop\nRF5_SDK_17.1.0\components\libraries\crypto\backend\mbedtls/mbedtls_backend_aes.c:344: undefined reference to `mbedtls_aes_setkey_dec'
8> C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 6.34a/gcc/arm-none-eabi/bin/ld: Output/Release/Obj/ble_app_uart_pca10056_s140/mbedtls_backend_aes.o: in function `backend_mbedtls_uninit':
8> C:\Users\jgusler\Desktop\nRF5_SDK_17.1.0\components\libraries\crypto\backend\mbedtls/mbedtls_backend_aes.c:280: undefined reference to `mbedtls_aes_free'
8> C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 6.34a/gcc/arm-none-eabi/bin/ld: Output/Release/Obj/ble_app_uart_pca10056_s140/mbedtls_backend_aes.o: in function `backend_mbedtls_init':
8> C:\Users\jgusler\Desktop\nRF5_SDK_17.1.0\components\libraries\crypto\backend\mbedtls/mbedtls_backend_aes.c:208: undefined reference to `mbedtls_aes_init'
8> C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 6.34a/gcc/arm-none-eabi/bin/ld: Output/Release/Obj/ble_app_uart_pca10056_s140/mbedtls_backend_aes.o: in function `backend_mbedtls_update':
8> C:\Users\jgusler\Desktop\nRF5_SDK_17.1.0\components\libraries\crypto\backend\mbedtls/mbedtls_backend_aes.c:586: undefined reference to `mbedtls_aes_crypt_cbc'
8> C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 6.34a/gcc/arm-none-eabi/bin/ld: Output/Release/Obj/ble_app_uart_pca10056_s140/mbedtls_backend_init.o: in function `mbedtls_backend_init':
8> C:\Users\jgusler\Desktop\nRF5_SDK_17.1.0\components\libraries\crypto\backend\mbedtls/mbedtls_backend_init.c:86: undefined reference to `mbedtls_platform_set_calloc_free'
8> C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 6.34a/gcc/arm-none-eabi/bin/ld: Output/Release/Obj/ble_app_uart_pca10056_s140/mbedtls_backend_init.o: in function `mbedtls_backend_free':
8> C:\Users\jgusler\Desktop\nRF5_SDK_17.1.0\components\libraries\crypto\backend\mbedtls/mbedtls_backend_init.c:78: undefined reference to `nrf_free'
8> C:/Program Files/SEGGER/SEGGER Embedded Studio for ARM 6.34a/gcc/arm-none-eabi/bin/ld: Output/Release/Obj/ble_app_uart_pca10056_s140/mbedtls_backend_init.o: in function `mbedtls_backend_calloc':
8> C:\Users\jgusler\Desktop\nRF5_SDK_17.1.0\components\libraries\crypto\backend\mbedtls/mbedtls_backend_init.c:65: undefined reference to `nrf_malloc'

Parents
  • Hi there,

    Have you already included the files that it's complaining about? Sometimes you need to keep adding source files to your project since the files you just added is dependent on other source files that hasn't been added to the project. For projects that use crypto lib, it would be easier to just start with a crypto example that already has included the necessary files and then add your code into that example.

    regards

    Jared

  • I don't know, I thought having the includes in those files where the issues are would do the including, so I don't know what my responsibility is in main vs the added on .c files' am as far as I can tell. And I can't do that because I'm already doing that with other aspects, of this project. This is based on bl_app_uart and I want to add on crypto.

  • Okay, for anyone finding this thread later, here is what all I had to do AES CBC encryption with mbedtls backend

    In mbedtls/config.h

    • uncomment MBEDTLS_MEMORY_BUFFER_ALLOC_C
    • uncomment MBEDTLS_PLATFORM_C
    • uncomment MBEDTLS_PLATFORM_MEMORY

    In sdk_config.h

    • NRF_CRYPTO_ENABLED 1
    • NRF_CRYPTO_ALLOCATOR 3
    • NRF_CRYPTO_BACKEND_MBEDTLS_ENABLED 1
    • NRF_CRYPTO_BACKEND_MBEDTLS_AES_CBC_ENABLED 1
    • might need NRF_CRYPTO_BACKEND_NRF_HW_RNG_ENABLED 1, not sure, I added this part way through as part of my own requirements to randomly generate the initialization vector

    In the flash_placement.xml

    • Verify you have  <ProgramSection alignment="4" keep="Yes" load="Yes" name=".crypto_data" inputsections="*(SORT(.crypto_data*))" address_symbol="__start_crypto_data" end_symbol="__stop_crypto_data" />

    Depending on what development environment, make sure all the following are added to the project

    And in main.c include all the following

    This worked for me, should get you close if not the whole way there. It was a pain to figure out what was missing.

Reply
  • Okay, for anyone finding this thread later, here is what all I had to do AES CBC encryption with mbedtls backend

    In mbedtls/config.h

    • uncomment MBEDTLS_MEMORY_BUFFER_ALLOC_C
    • uncomment MBEDTLS_PLATFORM_C
    • uncomment MBEDTLS_PLATFORM_MEMORY

    In sdk_config.h

    • NRF_CRYPTO_ENABLED 1
    • NRF_CRYPTO_ALLOCATOR 3
    • NRF_CRYPTO_BACKEND_MBEDTLS_ENABLED 1
    • NRF_CRYPTO_BACKEND_MBEDTLS_AES_CBC_ENABLED 1
    • might need NRF_CRYPTO_BACKEND_NRF_HW_RNG_ENABLED 1, not sure, I added this part way through as part of my own requirements to randomly generate the initialization vector

    In the flash_placement.xml

    • Verify you have  <ProgramSection alignment="4" keep="Yes" load="Yes" name=".crypto_data" inputsections="*(SORT(.crypto_data*))" address_symbol="__start_crypto_data" end_symbol="__stop_crypto_data" />

    Depending on what development environment, make sure all the following are added to the project

    And in main.c include all the following

    This worked for me, should get you close if not the whole way there. It was a pain to figure out what was missing.

Children
No Data
Related