cancel
Showing results for 
Search instead for 
Did you mean: 

How to Verify obtained AES output and how to transmit the OUTPUT in UART (STM32H750VB)

nanotronicsnss
Associate II

I have used STM32H750VB as my main controller for a Project and in that i am in need of AES Encryption to be done..With the help from our community friends i am able to integrate the AES part in my main coding..I have used the 192 bit plain text array(Plaintext[16]) with the 192 bit key ( AESKey192[6]) and 128 bit initialization Vector( AESIV_CBC[4] ) and obtained the 192 bit output encrypted array (CiphertextAESCBC192[16]) given in the attached notepad. ..I am a novice so kindly explain or give me the links where i can study about the same. I am having the following doubts

1.Is the size of the encrypted data same as that of input data?

2.When i try to transfer the encrypted array through UART the 32 bit data cannot be transferred properly i am getting some special characters and i have tried splitting the data as 8 bit and now i am getting a result but i don't know whether it is correct or not? (the image is attached as UART Op)

3.When i tried checking the obtained result the link for checking AES encryption and decryption, it uses characters with each character representing 8 bit data. (https://www.devglan.com/online-tools/aes-encryption-decryption) i.e the input and output can be given in HEX format but the Key and IV cannot be given as HEX and for 128 bit AES CBC encryption the key field requires only 16 digits. Kindly suggest me a link where i can cross verify the output or suggest me what data type i can use in the place of KEY and IV...

5 REPLIES 5

1) Yes, each 16-bytes of input generates 16-bytes of output

2) 8-bit binary data contains values not described as printable ASCII. Decompose 32-bits into 4 byte, or print in ASCII ie printf("%08X,",foo);

3) The author of the online calculator doesn't seem to understand input validation properly, a 24-byte key will be 48-bytes long printed a hex digit pairs.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

Ok, this online calculator was written by someone competent

http://aes.online-domain-tools.com/

0693W000000Wkk9QAC.jpg

Own PC side AES in C

KEYLENGTH:24
0000 : F7 B0 73 8E 52 64 0E DA-2B F3 10 C8 E5 79 90 80 ..s.Rd..+....y..
0010 : D2 EA F8 62 7B 6B 2C 52-                        ...b{k,R
 
IV:16
0000 : 03 02 01 00 07 06 05 04-0B 0A 09 08 0F 0E 0D 0C ................
 
PLAIN:64
CRC32 9783A6CF
0000 : E2 BE C1 6B 96 9F 40 2E-11 7E 3D E9 2A 17 93 73 ...k..@..~=.*..s
0010 : 57 8A 2D AE 9C AC 03 1E-AC 6F B7 9E 51 8E AF 45 W.-......o..Q..E
0020 : 46 1C C8 30 11 E4 5C A3-19 C1 FB E5 EF 52 0A 1A F..0..\......R..
0030 : 45 24 9F F6 17 9B 4F DF-7B 41 2B AD 10 37 6C E6 E$....O.{A+..7l.
 
ENCRYPTED:64
CRC32 5B3B8059
0000 : EF 32 1B DD 78 C0 48 8B-1D F0 96 1D 6B 19 98 E9 .2..x.H.....k...
0010 : 7A 26 94 3A 7D 1C 0A 9F-3D 84 FE 7C A5 EE 00 19 z&.:}...=..|....
0020 : B9 45 B5 04 18 67 E4 4E-FB 98 CB 80 9B D6 47 AD .E...g.N......G.
0030 : 91 C5 6E 66 64 1E F6 CC-E1 29 8A E9 3E 79 CB 1E ..nfd....)..>y..
 
DECRYPTED:64
CRC32 9783A6CF
0000 : E2 BE C1 6B 96 9F 40 2E-11 7E 3D E9 2A 17 93 73 ...k..@..~=.*..s
0010 : 57 8A 2D AE 9C AC 03 1E-AC 6F B7 9E 51 8E AF 45 W.-......o..Q..E
0020 : 46 1C C8 30 11 E4 5C A3-19 C1 FB E5 EF 52 0A 1A F..0..\......R..
0030 : 45 24 9F F6 17 9B 4F DF-7B 41 2B AD 10 37 6C E6 E$....O.{A+..7l.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

0693W000000WmEAQA0.jpg0693W000000WmE5QAK.jpgThanks for your reply .. i just need some more clarifications..

1.when I give a 1 byte(8 bit) of input data the output encrypted text is about 16 bytes(128 bits).. Is the length of encrypted data has a minimum length of 16 bytes?.. i have cross verified the result and its correct(inserted as images)

2. In the stm32h7xx library example the encrypted text array does not match with the encrypted text obtained from the website..kindly help for a clarification

FROM LIBRARY EXAMPLE:

uint32_t AESKey192[6] = {0x8E73B0F7 ,0xDA0E6452 ,0xC810F32B ,0x809079E5 ,0x62F8EAD2 ,0x522C6B7B};

/*Initialization Vector*/ 

uint32_t AESIV_CBC[4] = {0x00010203 , 0x04050607 , 0x08090A0B , 0x0C0D0E0F};

/* Plaintext */

 uint32_t Plaintext[16]     = {0x6BC1BEE2 ,0x2E409F96 ,0xE93D7E11 ,0x7393172A ,

                   0xAE2D8A57 ,0x1E03AC9C ,0x9EB76FAC ,0x45AF8E51 ,

                   0x30C81C46 ,0xA35CE411 ,0xE5FBC119 ,0x1A0A52EF ,

                   0xF69F2445 ,0xDF4F9B17 ,0xAD2B417B ,0xE66C3710};

/* Expected CBC Ciphertext with AESKey192*/

uint32_t CiphertextAESCBC192[16] = { 0x4F021DB2 ,0x43BC633D ,0x7178183A ,0x9FA071E8 ,

                  0xB4D9ADA9 ,0xAD7DEDF4 ,0xE5E73876 ,0x3F69145A ,

                  0x571B2420 ,0x12FB7AE0 ,0x7FA9BAAC ,0x3DF102E0 ,

                  0x08B0E279 ,0x88598881 ,0xD920A9E6 ,0x4F5615CD};

Encrypted Text from website:

ENCRYPTED:64

CRC32 5B3B8059

0000 : EF 32 1B DD 78 C0 48 8B-1D F0 96 1D 6B 19 98 E9

0010 : 7A 26 94 3A 7D 1C 0A 9F-3D 84 FE 7C A5 EE 00 19

0020 : B9 45 B5 04 18 67 E4 4E-FB 98 CB 80 9B D6 47 AD

0030 : 91 C5 6E 66 64 1E F6 CC-E1 29 8A E9 3E 79 CB 1E

Not sure I can invest that much time into this. Would probably look to see if there are some endian issues with the settings.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

hcryp.Init.DataType  = CRYP_DATATYPE_32B; // Takes data Big Endian format

0693W000000Wn83QAC.jpg

https://paypal.me/cliveone

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..