Skip to main content
Arno1
Senior
February 7, 2020
Question

Getting AES_ERR_BAD_OPERATION on SE_Decrypt_Append

  • February 7, 2020
  • 1 reply
  • 574 views

Hi,

I'm in the process of implementing a HTTP server in SBSFU where I can upload an update file from a webpage. I've based my work on the code in sfu_loader.c, specifically the function SFU_COM_YMODEM_DataPktRxCpltCallback() and I try to follow the same process.

So far I got the upload part working and now I try to get it to install but the issue I keep getting is that SE_Decrypt_Append() always fails on the second packet I receive.

I followed the function down the rabbit hole and the specific error that seems to occur is AES_ERR_BAD_OPERATION in SE_CRYPTO_Decrypt_Append().

Because this comes from a closed-source encryption library there's no way I can find out what is going wrong.

For error checking I check both the return value and the SE_StatusTypeDef parameter value. SE_Decrypt_Init returns SE_SUCCESS and SE_OK for both.

My TCP_MSS is set to 1072 which is what I use for my decrypted chuck buffers as well.

Here are the traces of my SBSFU which can help to give you an idea of the process:

[POST] Begin 
[POST] HTTP parameter Content-Type: multipart/form-data; boundary= value: ---------------------------19265645189796 
[POST] HTTP parameter Content-Length: value: 300880 
[POST] Start erasing 
[POST] Flash erased in 4 ms 
[POST] Receive packet 0 of size 524B 
Filename: test.sfb
[POST] Found start of image data at 173 in 0 ms 
[POST] Header verification successful. Img size: 301472. Took 2 ms 
[POST] SE_Decrypt_Init successful. Took 0 ms 
[POST] Write header to flash done in 1 ms 
[POST] Decrypting data of size 155B 
[POST] SE_Decrypt_Append finished, took 0 ms |
[POST] Receive packet 1 of size 1072B 
[POST] Decrypting data of size 1072B 
[POST] SE_Decrypt_Append failed. ret_err: 00030c1e, SE err: 0013023d 
[POST] Finished with error. Total data received 1596B of 300880B expected. 
[POST] Ready, close connection 

Note that the value of ret_err is the SE_ErrorStatus which I've altered to get more specific errors. The return value is thus: e_ret_status = SE_ERROR_AES_OFFSET + cryptolib_status; in SE_CRYPTO_Decrypt_Append()

typedef enum
{
 SE_ERROR = 0x00018799U,
 SE_ERROR_INITVAL = 0x00020000,
 SE_ERROR_CRC_0,
 SE_ERROR_CRC_1,
 SE_ERROR_INPUT_1,
 SE_ERROR_RAM_INPUT_1,
 SE_ERROR_RAM_OUTPUT_1,
 SE_ERROR_BUFFER_1,
 SE_ERROR_INPUT_2,
 SE_ERROR_RAM_INPUT_2,
 SE_ERROR_RAM_OUTPUT_2,
 SE_ERROR_BUFFER_2,
 SE_ERROR_APPEND_BUFFER,
 SE_ERROR_AES_OFFSET = 0x00030000,
 SE_ERROR_APPEND_AES_INPUT,
 SE_ERROR_APPEND_AES_OPERATION,
 SE_ERROR_APPEND_AES_CONTEXT,
 SE_ERROR_APPEND_AES_PARAMETER,
 SE_SUCCESS = 0x0012310FU
} SE_ErrorStatus;

Can you please help to find out what seems to be going wrong?

Thank you!

Arno.

This topic has been closed for replies.

1 reply

Arno1
Arno1Author
Senior
February 19, 2020

bump