undefined reference to `mbedtls_aes_init' in SDK_2.9.0

Hi,

As shown below, which configuration should I use to resolve the error?

Parents
  • Hi,

    Do you have AES enabled in your project?

    CONFIG_MBEDTLS_AES_C=y

    Please upload the full build log as text using Insert > Code.

    Best regards,
    Marte

  • Hi,

    I have already added this configuration, but it didn't change anything, so I created this thread.

    c:/ncs/toolchains/b620d30767/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: app/libapp.a(Sunion_BleCmd.cpp.obj): in function `Sunion::BleCmd::SendBack(bt_conn*, unsigned char, unsigned char, unsigned char const*)':
    C:/nordic_prj/DL02_S2MB_KPD_Small/src/Sunion_Function/Sunion_BleCmd.cpp:1374: undefined reference to `mbedtls_aes_init'
    c:/ncs/toolchains/b620d30767/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: C:/nordic_prj/DL02_S2MB_KPD_Small/src/Sunion_Function/Sunion_BleCmd.cpp:1378: undefined reference to `mbedtls_aes_crypt_ecb'
    c:/ncs/toolchains/b620d30767/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: C:/nordic_prj/DL02_S2MB_KPD_Small/src/Sunion_Function/Sunion_BleCmd.cpp:1380: undefined reference to `mbedtls_aes_free'
    c:/ncs/toolchains/b620d30767/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: app/libapp.a(Sunion_BleCmd.cpp.obj): in function `Sunion::BleCmd::BLE_DataProcessor(unsigned char const*, unsigned char)':
    C:/nordic_prj/DL02_S2MB_KPD_Small/src/Sunion_Function/Sunion_BleCmd.cpp:99: undefined reference to `mbedtls_aes_init'
    c:/ncs/toolchains/b620d30767/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: C:/nordic_prj/DL02_S2MB_KPD_Small/src/Sunion_Function/Sunion_BleCmd.cpp:103: undefined reference to `mbedtls_aes_crypt_ecb'
    c:/ncs/toolchains/b620d30767/opt/zephyr-sdk/arm-zephyr-eabi/bin/../lib/gcc/arm-zephyr-eabi/12.2.0/../../../../arm-zephyr-eabi/bin/ld.bfd.exe: C:/nordic_prj/DL02_S2MB_KPD_Small/src/Sunion_Function/Sunion_BleCmd.cpp:105: undefined reference to `mbedtls_aes_free'
    collect2.exe: error: ld returned 1 exit status
    ninja: build stopped: subcommand failed.
    FATAL ERROR: command exited with status 1: 'C:\ncs\toolchains\b620d30767\opt\bin\cmake.EXE' --build C:/nordic_prj/DL02_S2MB_KPD_Small/build/DL02_S2MB_KPD_Small
    

  • Hi,

    Simply add the following code to the sample program, or directly replace the files in your project with the attached files.

    app_task.cpp

    #include "mbedtls/aes.h"
    #include "mbedtls/sha256.h"
    #include "mbedtls/base64.h"
    CHIP_ERROR AppTask::StartApp()
    {
    	ReturnErrorOnFailure(Init());
        mbedtls_aes_context ctx_aes;
        mbedtls_aes_init(&ctx_aes);
    	while (true) {
    		Nrf::DispatchNextTask();
    	}
    
    	return CHIP_NO_ERROR;
    }

  • Hi,

    Please also share the changes you have made to prj.conf and any other changes necessary to reproduce the issue.

    Best regards,

    Marte

  • Hi,

    You can also create a new project, and you should be able to easily find the same error.

    Alright, I may not have expressed myself clearly. Let me rephrase it. In a brand-new project, which configurations should I enable to use the AES functionality?

    To prevent other potential issues, as per your request, I have attached all the modified files from the project.

    7444.lock.zip

  • Hi,

    You can solve the issue by enabling legacy mbedTLS crypto. However, Matter uses PSA crypto, and combining legacy and modern crypto drivers can cause issues. I strongly recommend using PSA crypto instead. You can find samples that use PSA crypto under the Cryptography samples section in our documentation.

    To enable legacy crypto, set CONFIG_MBEDTLS_LEGACY_CRYPTO_C=y in prj.conf. Please note that this can result in issues and unexpected behavior.

    Best regards,
    Marte

  • Hi,

    After using CONFIG_MBEDTLS_LEGACY_CRYPTO_C, many warnings appear during compilation, including prompts that CONFIG_MBEDTLS_LEGACY_CRYPTO_C has been deprecated. If you believe there are risks, please let me know how this version should be resolved.

Reply Children
Related