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.

Compiler/AES-128: Using AES for F28377S

Part Number: AES-128

Tool/software: TI C/C++ Compiler

Hello! I applied the library Ti_aes_128. However, I don't quite understand how it works. I see that  the function aes_enc_dec(state,key,dir) changes the values of state and key, so I suppose that the encryption result is the new value of state? 

I tried to crypt this data: 

unsigned char state[ ] = {0x00, 0x11, 0x22, 0x33, 0x44, 0x55, 0x66, 0x77,
0x88, 0x99, 0xaa, 0xbb, 0xcc, 0xdd, 0xee, 0xff};  

with this key 

unsigned char key[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f};

(same to the example) and i got this result: 

0xFFEC, 0xFFEE, 0xFFE2, 0xFF80, 0xFF1C, 0xFF6B, 0xFFB5, 0xFFE8, 0xFF0C, 0xFFF8, 0xFF58, 0xFF74, 0xFFB2, 0xFFD4, 0xFFCF, 0xFF3A (state) 

so I'm not sure I'm getting the encrypted data right, it seems that either I did'nt get how the function works or there is a problem with the execution of the function. 

Is there a risk that the variables state and key crush other varaibles in the memory? 

thanks in advance,

Best regards, Imen Diouri

  • Imen,

    Please see this post with information on the changes required.

  • Hi, thank you for your reply, I followed the instructions, but it didn't really make it work (only the values have been sligntly changed), any other suggestions?
  • Hi Imen,

    Yes, the output will be the updated value of the state array. The key array memory is used in-place for the function and is modified, so you will need to use a new (but identical) key array to do the decryption (or re-initialize the original key before trying to decrypt).

    Are you running the function with dir = 0 (encrypt), getting the output data, then running the output data back through the same function with dir = 1 (decrypt) and the key2 = same as key1, or is this the output of just the encryption stage?

    You don't need to pass in the array sizes because aes operates on a fixed block size. If you have additional data, you just have to pad the size to fit in the fixed size block. Because of this you shouldn't have to worry about an out-of-range memory access unless your array sizes are allocated incorrectly.
  • Hi,  

    Thank you for your response, The result shown in my first message, concerns the encryption only, I wanted to see how the encrypted data look like, and it's a little disturbing, I'm wondering if you could try this AES algorithm and tell me if you get the same result. Anyway, I'm not sure this is what I'm supposed to get as encrypted data. 

    If I shouldn't worry about the array sizes, I don't see what else I could do wrong since I'm doing exactly the same thing as the example.

  • Hi Imen,

    What exactly is unexpected about the encrypted data?

    The best way to validate that the code is working is to encrypt the data, then decrypt the data to confirm the process is reversible. Then, if you are concerned the algorithm is producing the correct ciphertext per the AES standard, you can compare the ciphertext against AES 'Known Answer' vectors.