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.

CCS/MSP430FR5969: Bad working drivelib for AES 256

Part Number: MSP430FR5969

Tool/software: Code Composer Studio

Hello,

I just want to use hardware AES256 which is in FR5969 (for comparasion library TI_aes_128 from Texas uses 25% of stack size!). Now, I have a problem with hardware AES. I just get part of drivelib (http://software-dl.ti.com/msp430/msp430_public_sw/mcu/msp430/MSP430_Driver_Library/latest/index_FDS.html )

unsigned char AES_Key[16];

void AES_KeySet(void)
{
AES_Key[0] = 0x00;
AES_Key[1] = 0x01;
AES_Key[2] = 0x02;
AES_Key[3] = 0x03;
AES_Key[4] = 0x04;
AES_Key[5] = 0x05;
AES_Key[6] = 0x06;
AES_Key[7] = 0x07;
AES_Key[8] = 0x08;
AES_Key[9] = 0x09;
AES_Key[10] = 0x0A;
AES_Key[11] = 0x0B;
AES_Key[12] = 0x0C;
AES_Key[13] = 0x0D;
AES_Key[14] = 0x0E;
AES_Key[15] = 0x0F;
}

AES256_setCipherKey( AES256_BASE , AES_Key, AES256_KEYLENGTH_128BIT );
AES256_setDecipherKey( AES256_BASE, AES_Key, AES256_KEYLENGTH_128BIT );

and the algorythm:

data -> AES256_encryptData()  ->  AES256_decryptData ->someData  and the data != someData . so what could going wrong?

  • Hi Tomasz,

    You need to set the cipher key just before encryption and set the decipher key just before decryption. For example:

    void main(void){
        // stop watchdog
        WDT_A_hold(WDT_A_BASE);
    
        // Load a cipher key to module
        AES256_setCipherKey(AES256_BASE, CipherKey, AES256_KEYLENGTH_256BIT);
    
        // Encrypt data with preloaded cipher key
        AES256_encryptData(AES256_BASE, Data, DataAESencrypted);
    
        // Load a cipher key to module
        AES256_setDecipherKey(AES256_BASE, CipherKey, AES256_KEYLENGTH_256BIT);
    
        // Decrypt data
        AES256_decryptData(AES256_BASE, DataAESencrypted, DataAESdecrypted);
    
        // Array DataunAES should now contain the same data as array Data
    
        while(1)
        {
        }
        ;
    }

    In your pseudo-code you've included above, it looks like you set both the cipher and decipher key at the same time. This will cause incorrect results. 

    Best regards, 

    Caleb Overbay

  • thanks, but its not still working. another  KEYLENGTH than 256 data i array "out" are the same than in "test" afert decrypt. whats wrong?

    AES256_setCipherKey( AES256_BASE , AES_Key, AES256_KEYLENGTH_128BIT );

    AES256_encryptData( AES256_BASE , AES_DataEnc, test );

    AES256_setDecipherKey( AES256_BASE, AES_Key, AES256_KEYLENGTH_128BIT );

    AES256_decryptData( AES256_BASE , test, out );

  • Hi Tomasz,

    I just tested this out again and I'm still not observing the behavior you are. Can you post a reduced version of your code that recreates the issue so I can test it on my setup?

    Best regards,
    Caleb Overbay
  • testout_T.zipThe test project is in attachment

  • Hi Tomasz,

    I performed a comparison of the aes256.c file in your project and the one included in driverlib and found that a crucial piece of code had been commented out in your version of the file at ~line 155:

        // Key that is already written shall be used
        // Now decryption starts
       HWREG16(baseAddress + OFS_AESASTAT) |= AESKEYWR;

    This line of code as commented out in your file and once fixed the decryption began working properly.

    Best regards, 

    Caleb Overbay

  • Thanks Caleb! it works now.

    Best regards!

**Attention** This is a public forum