This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMDS64GPEVM: SA2UL aes-ecb-256 data length problem !

Part Number: TMDS64GPEVM

Dear Ti experts,

I'm having problem about data length in encryption and decryption proceses in aes-esb-256(Actualy SA2UL functions).
I couldn't encrypt data more than 256kb.
Is there a way to encrypt and decrypt data larger than 256kb? 
As in the decryption part of the aes_ecb_256 example, I try to decrypt the encrypted data read from the OSPI flash in a buffer I allocated on the DDR.

/* Decryption */
/* Function to transfer and receive data buffer */
status = SA2UL_contextProcess(&gSa2ulCtxObj,&FlashReadEncBuf[0], size, FlashReadDecBuf);
DebugP_assert(SystemP_SUCCESS == status);

The size argument in third parameter equals the actual size of the file in bytes (e.g. 35840 for 35kb)
But in the decrypt process, I get an error when the size of the data to be decrypted from "FlashReadEncBuf" is larger than 256kb(I tested with 908.56kb) and the application crashes.
According to the debug I did, while decrypting the large "FlashReadEncBuf" buffer, I observed that the following iteration was entered in sa2ul.c and the numChunks value was '0xC'.
(SystemP_SUCCESS == retVal)
{
	for(processIterations = 0; processIterations < numChunks;processIterations++)
    {
 	   retVal      = SA2UL_pushBuffer(pCtxObj,ptrInput, maxLength, ptrOutput);
       if(SystemP_SUCCESS == retVal)
       {
	       /* Consider timeout */
           while((doneBufAddr != (uint64_t)ptrInput) && ( donedataLen != maxLength) && (doneFlag != (uint8_t)TRUE))
           {
 	          retVal = SA2UL_popBuffer(pCtxObj, &doneBufAddr, &donedataLen, &doneFlag);
           }
       }
           ptrInput    = ptrInput + ((processIterations + 1) * maxLength);
           ptrOutput   = ptrOutput + ((processIterations + 1) * maxLength);
 }

I think there are 2 important points in this part. 
1:
For the 908kb of data I was trying to decrypt, I initially allocated two separate 1MB Encryption and Decryption buffers.
However, the buffer addresses pointed to by the "ptrInput" and "ptrOutput" pointers in the function expand well over 1MB.
Therefore I updated the buffer size to 6MB for 908kb data. 

2:
In the decryption iteration for the 908kb encrypted buffer, when the "processIterations" loop counter reaches '0x5', the "retVal" value from the "SA2UL_pushBuffer" function returns 'SystemP_FAILURE'.
At this stage of the iteration I found the source of the error in the "SA2UL_pushBuffer" function.
The following function in SA2UL_pushBuffer is causing the error:
/* Check the occupancy of storage queue */
if(SA2UL_getStorageRingOcc(object, attrs->swRingNumInt) < 2u)
{
    retVal = SystemP_FAILURE;
}

In the "SA2UL_getStorageRingOcc" function, the constant "SA2UL_RING_N_ELEMS" and the variable "object->storageQueueFree" both have the value '8U'.
Since the result of this calculation is 0, the previous function generates an error.
I think there is a size limit in the decryption process.
What is the truth here?

I hope you can help with this problem.
Best regards.

(If you want, I can share a demo project to show what I did.)