Skip to main content
AKole.3
Visitor II
May 30, 2022
Question

X-CUBE-CRYPTOLIB cmox_eddsa_verify memory fail

  • May 30, 2022
  • 2 replies
  • 1854 views

Hi everyone!

In our project for stm32f446, we are trying to use X-CUBE-CRYPTOLIB to verify the firmware signature on the device using ED25519. Unfortunately, when trying to call the cmox_eddsa_verify method, we get the CMOX_ECC_ERR_MEMORY_FAIL error. The error occurs when memory is allocated. Tell me how to overcome this, or perhaps we are doing something wrong.

Below is the code

bool FirmwareCrypt::verify(const uint8_t* data, size_t size, const uint8_t* sign, size_t sign_size)
{
 if (!data || !size) 
 return false;
 
 cmox_ecc_handle_t handle;
 uint8_t ecc_buf[ECC_BUF_SIZE// 2048];
 uint32_t fault_check = 0;
 memset((void*)&handle, 0, sizeof(cmox_ecc_handle_t));
 cmox_ecc_construct(&handle, CMOX_ECC256_MATH_FUNCS, ecc_buf, ECC_BUF_SIZE);
 
 cmox_ecc_retval_t ret = cmox_eddsa_verify(&handle, CMOX_ECC_CURVE_ED25519, 
 public_key, PUBLIC_KEY_SIZE, data, size/*~100Kb*/, sign, sign_size, NULL/*&fault_check*/);
 
 if (/*(static_cast<uint32_t>(ret) != fault_check) && */(ret != CMOX_ECC_SUCCESS)) {
 return false;
 }
 
 return true;
}

2 replies

Jocelyn RICARD
ST Employee
June 29, 2022

Hello @AKole.3​ ,

in the example provided here STM32CubeExpansion_Crypto_V4.0.1\Projects\NUCLEO-G474RE\Applications\ECC\EDDSA_SignVerify\ I can see:

uint8_t Working_Buffer[2200];

So, maybe setting your buffer size with same value will solve your issue

Best regards

Jocelyn

HMcKi
Associate III
October 15, 2024

G'day,

Is there any documentation on how to set this buffer to be the appropriate size? This answer leads me to more questions:

  • Is 2200 always safe?
  • If you set it for one curve / memory implementation will it always work if it works once? 
  • I presume it depends on the ECC curve and the lowmem vs highmem option?

Cheers,

Hamish.

 

Jocelyn RICARD
ST Employee
October 16, 2024

Hello @HMcKi ,

if you look at the wiki here you will see the usage of the buffer depending on option used.

So, 2200 looks like a really safe value.

Best regards

Jocelyn

 

Associate
September 24, 2025

@AKole.3 
Please can you let me know public_key is provided in which format in your code?

Please can you let me know as to how you have generated public key, is it through STM32_KeyGen_CLI.exe?