cancel
Showing results for 
Search instead for 
Did you mean: 

STSAFE-A110, Key Establish and Wrap/Unwrap example doesn't work

sunghwan
Associate

Hi,

I have issue on Key Establish and Wrap/Unwrap example.

I have X-NUCLEO-SAFEA1 and NUCLEO-L476RG for testing.

I downloaded X-CUBE-SAFEA1 from ST web site, version is V1.2.2.

 

Here's what I tried.

  • I ran paring example.
    • I commented out "_FORCE_DEFAULT_FLASH_" like "//#define _FORCE_DEFAULT_FLASH_"
    • it works successfully.
  • I ran All_Use_Cases example in Example_X-Cube_Cryptolib.
    • Authentication worked.
    • Key-pair generation worked.
    • Key establish is failed.
      • it fails at step 5, "5. Verify if shared secret is identical (0 means success): 49"
        • StSafeA_AssignLVBuffer() function returns STSAFEA_INVALID_RESP_LENGTH
        • pDestLVBuffer->Length was 16927 (looks like garbage value), but ExpectedLen was 32
    • Wrap/unwrap is failed.
      • it also fails at step 5, "5. Local envelope Local envelope demonstration result (0x0 means success): 0x6"
        • StSafeA_ReceiveBytes() function returns STSAFEA_BUFFER_LENGTH_EXCEEDED
        • pOutBuffer->LV.Length was 65009 (garbage value), but STSAFEA_BUFFER_DATA_PACKET_SIZE 507

Could you help me to understand what's going on?

 

Sung

 

3 REPLIES 3
Billy OWEN
ST Employee

Hi @sunghwan 

 

This post has been escalated to the ST Online Support Team for additional assistance.  We'll contact you directly.

 

Regards,

Billy

Teedoubleyuh
Associate II

I have a very similar issue to original post where the Key Establishment and Wrap/Unwrap envelope demos do not succeed.

Key Establishment demo fails on step 3 when calling mbedtls_ecp_mul. It is passing a NULL value for rng function to mbedtls_ecp_mul_restartable which then returns MBEDTLS_ERR_ECP_BAD_INPUT_DATA. 

Wrap/Unwrap demonstration fails on step 2 StSafeA_WrapLocalEnvelope where the local envelope response is STSAFEA_KEY_NOT_FOUND

 

Here are a few things that were interfering with my "all_use_cases" not running properly:

  • I hadn't done initial pairing between the host microcontroller and the STSAFE-A110. The pairing function isn't included in the code generated by Cube for "all_use_cases", it is its own option under STSAFE_Applications when adding the X-CUBE_SAFEA1 middleware:

     

Teedoubleyuh_2-1740774609603.png

  • Take care when running the pairing function. There are default cipher and MAC keys defined in the code produced by Cube that work well for debugging. You can set these debug host keys in the STSAFE-A110 using the StSafeA_PutAttribute function. If you elect to generate new keys and store them in the STSAFE-A110, take great care to ensure your host micro also remembers these keys! The host must also have access to the same keys when authenticating with the STSTAFE-A110. Pay special attention to the #defines for _FORCE_DEFAULT_FLASH_ and USE_HOST_KEYS_SET_BY_PAIRING_APP as these settings will determine how the pairing is performed and if/how the host keys are stored locally (outside the STSAFE-A110).
  • When generating "all_use_cases" examples with X-CUBE-SAFEA1 middleware, you'll be encouraged to select a supporting security library by the Cube GUI: ST_Cryptolib or MbedTLS. I already had the latest LTS version of Mbed-TLS in my project (v3.6.2), but you'll see that the Cube generated code will add v2.26.0 of MbedTLS if you add it through the middleware GUI. I selected neither since I already had Mbed-TLS but the code generated by Cube did NOT play nicely with the newer version of Mbed-TLS that I had. There was much pain and suffering (and a lot of hacking) getting them to play nicely with each other. 

Teedoubleyuh_3-1740775054526.png