cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F439 AES TCP/IP Encrypt Problem

furkankilic
Associate II

Hello Dear Friends!

 

I use STM32F439 MCU and it has AES encryption peripheral. I tried to encrypt data in the format of uint32_t and it encrypted data and I tested it successfully on online tools. However, I wanted to encrypt data in the format of char which will be transferred by tcp/ip protocol. Then, when I recived this encrypted data in the format of hex it did not recive in true format. On the other hand, when I decrypt the encrypted data I got data that I sent at first. Therefore, it decrypts data correctly. But there is something wrong in the step of encryption of data. I searched for endianless topic for this problem on google but I could not solve it. Is there anyone who will help me?

 

From now on, thanks for helps!

The related part of codes are avaiable as shown below;

 

char spi_mydata[16];

 uint32_t spi_encrypted_data[16];

static err_t tcp_rmii_recv(void *arg, struct tcp_pcb *pcb, struct pbuf *p, err_t err){

   int i;

   int len;

   char *pc;

   if (err == ERR_OK && p != NULL) {

      /* Inform TCP that we have taken the data. */

      tcp_recved(pcb, p->tot_len);

      //pointer to the pay load

      pc=(char *)p->payload;

      //size of the pay load

      len =p->tot_len;

      //copy to our own buffer

      for (i=0; i<len; i++){

      spi_mydata[i]= pc[i];

      }

       //Close TCP when receiving "X"

      if (spi_mydata[0]=='X'){

      close_conn(pcb);

      }

      //Free the packet buffer

      pbuf_free(p);

      //check output buffer capacity

      if (len >tcp_sndbuf(tcp_spi_conn_pcb)){

      len= tcp_sndbuf(tcp_spi_conn_pcb);

      }

      //Send out the data

      HAL_CRYP_Encrypt(&hcryp, (uint32_t*)spi_mydata, 16, spi_encrypted_data, 1000);

      err = tcp_write(tcp_spi_conn_pcb,spi_encrypted_data , len, 0);

      tcp_sent(tcp_spi_conn_pcb, NULL); /* No need to call back */

      }

    else {

      pbuf_free(p);

    }

    if (err == ERR_OK && p == NULL) {

      close_conn(pcb);

    }

   return ERR_OK;

}

0 REPLIES 0