This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

error in mbedtls_ecp_gen_keypair()

Hello,

I am using nRF52840, SDK16 & SoftDevice140.

I am integrating pm_init()(Peer Manager) into my project and I am getting error 0xFFFFB180 from mbedtls_ecp_gen_keypair(). I looked out for the problem and find this thread which says there may be a problem of mbed libraries.

I am already using AES-ECB-256 encryption (mbedtls library) in my code. I don't think so but to be sure, can that be a cause of this error?

Kindly help me out!

Parents
  • Hi,

    I do not immediately see the link. Do you have a piece of code you can upload that reproduces this on a DK?

  • I don't have any different code because I am ported my code to the design of our custom board. But for this problem, I have just copied the peer_manager_init() from ble_app_hrs example.

    Before adding that I had already added crypto libraries for another purpose and as mentioned earlier, I needed 256-bit encryption so instead of using CC310, I am using mbedtls library. So all the crypto libraries were already there to support peer_manager_init().

    Now when I run, I get the error 0xFFFFB180 in mbedtls_ecp_gen_keypair() (peer_manager_init --> pm_init --> sm_init --> nrf_ble_lesc_init --> nrf_ble_lesc_keypair_generate--> nrf_crypto_ecc_key_pair_generate --> nrf_crypto_backend_mbedtls_key_pair_generate --> mbedtls_ecp_gen_keypair)

  • Hi,

    I have managed to reproduce this, and get memory corruption in mbed TLS using the default sdk_config.h memory manager configurations from the BLE peripheral examples, which do not use mbed TLS by default. Modifying the configuration like this fixed the issue (sdk_config.h snippet):

    ...
    
    // <e> MEM_MANAGER_ENABLED - mem_manager - Dynamic memory allocator
    //==========================================================
    #ifndef MEM_MANAGER_ENABLED
    #define MEM_MANAGER_ENABLED 1
    #endif
    // <o> MEMORY_MANAGER_SMALL_BLOCK_COUNT - Size of each memory blocks identified as 'small' block.  <0-255> 
    
    
    #ifndef MEMORY_MANAGER_SMALL_BLOCK_COUNT
    #define MEMORY_MANAGER_SMALL_BLOCK_COUNT 128
    #endif
    
    // <o> MEMORY_MANAGER_SMALL_BLOCK_SIZE -  Size of each memory blocks identified as 'small' block. 
    // <i>  Size of each memory blocks identified as 'small' block. Memory block are recommended to be word-sized.
    
    #ifndef MEMORY_MANAGER_SMALL_BLOCK_SIZE
    #define MEMORY_MANAGER_SMALL_BLOCK_SIZE 32
    #endif
    
    // <o> MEMORY_MANAGER_MEDIUM_BLOCK_COUNT - Size of each memory blocks identified as 'medium' block.  <0-255> 
    
    
    #ifndef MEMORY_MANAGER_MEDIUM_BLOCK_COUNT
    #define MEMORY_MANAGER_MEDIUM_BLOCK_COUNT 64
    #endif
    
    // <o> MEMORY_MANAGER_MEDIUM_BLOCK_SIZE -  Size of each memory blocks identified as 'medium' block. 
    // <i>  Size of each memory blocks identified as 'medium' block. Memory block are recommended to be word-sized.
    
    #ifndef MEMORY_MANAGER_MEDIUM_BLOCK_SIZE
    #define MEMORY_MANAGER_MEDIUM_BLOCK_SIZE 64
    #endif
    
    // <o> MEMORY_MANAGER_LARGE_BLOCK_COUNT - Size of each memory blocks identified as 'large' block.  <0-255> 
    
    
    #ifndef MEMORY_MANAGER_LARGE_BLOCK_COUNT
    #define MEMORY_MANAGER_LARGE_BLOCK_COUNT 32
    #endif
    
    // <o> MEMORY_MANAGER_LARGE_BLOCK_SIZE -  Size of each memory blocks identified as 'large' block. 
    // <i>  Size of each memory blocks identified as 'large' block. Memory block are recommended to be word-sized.
    
    #ifndef MEMORY_MANAGER_LARGE_BLOCK_SIZE
    #define MEMORY_MANAGER_LARGE_BLOCK_SIZE 128
    #endif
    
    // <o> MEMORY_MANAGER_XLARGE_BLOCK_COUNT - Size of each memory blocks identified as 'extra large' block.  <0-255> 
    
    
    #ifndef MEMORY_MANAGER_XLARGE_BLOCK_COUNT
    #define MEMORY_MANAGER_XLARGE_BLOCK_COUNT 8
    #endif
    
    // <o> MEMORY_MANAGER_XLARGE_BLOCK_SIZE -  Size of each memory blocks identified as 'extra large' block. 
    // <i>  Size of each memory blocks identified as 'extra large' block. Memory block are recommended to be word-sized.
    
    #ifndef MEMORY_MANAGER_XLARGE_BLOCK_SIZE
    #define MEMORY_MANAGER_XLARGE_BLOCK_SIZE 256
    #endif
    
    // <o> MEMORY_MANAGER_XXLARGE_BLOCK_COUNT - Size of each memory blocks identified as 'extra extra large' block.  <0-255> 
    
    
    #ifndef MEMORY_MANAGER_XXLARGE_BLOCK_COUNT
    #define MEMORY_MANAGER_XXLARGE_BLOCK_COUNT 4
    #endif
    
    // <o> MEMORY_MANAGER_XXLARGE_BLOCK_SIZE -  Size of each memory blocks identified as 'extra extra large' block. 
    // <i>  Size of each memory blocks identified as 'extra extra large' block. Memory block are recommended to be word-sized.
    
    #ifndef MEMORY_MANAGER_XXLARGE_BLOCK_SIZE
    #define MEMORY_MANAGER_XXLARGE_BLOCK_SIZE 2048
    #endif
    
    ...

  • I suspected this may be the problem but am not that master to update them!Sweat smile

    1. After changing this, it will not affect other encryption APIs (if not all other), right?

    2. And just to know, for what are these defines used, fds?

  • Hi,

    Vishwas Jain said:
    1. After changing this, it will not affect other encryption APIs (if not all other), right?

    No, it will not cause any problems for other crypto APIs.

    Vishwas Jain said:
    2. And just to know, for what are these defines used, fds?

    No, it is not related to FDS. These defines are used for configuring the memory manager library. This is a module that handles dynamic memory / heap memory (think malloc()), which is extensively used by mbed TLS. The updated configuration will reserve more RAM for the memory manager, but will not have any bad side effects. The only potential problem would be if you were to run out of RAM, but then you would get a linker error when building.

  • Okay. Understood.

    Right now, I have lot of RAM so it won't be a problem! I will update the changes and will verify the answer.

    Thanks!

  • Hello,

    Unfortunately, the problem persists! I am also attaching the debug snippet here.

    Debug snip

Reply Children
Related