AES encrypt function example



  • Hi, can anyone explain me how to retrieve the result of the aes_encrypt function, please?

    I tryed to follow the example of the library, but i don't understand how to get the encrypted data from the handle function, thanks.

    The library is inside the SDK and its name is aes.h.

    typedef void (aes_func_result_cb) (uint8_t status, const uint8_t aes_res, uint32_t src_info);

    /*

    • FUNCTIONS
      */

    /*********************************************************************

    • @fn aes_encrypt
    • @brief Perform an AES encryption - result within callback
    •      Sample:
      
    •          const uint8_t key[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x00};
      
    •          const uint8_t value[] = {0x11, 0x22, 0x33, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0xee, 0x0f, 0xaa};
      
    •          aes_encrypt(key, value, true, aes_enc_result_cb, 0);
      
    • @param key - Key used for the encryption
    •      val         - Value to encrypt using AES
      
    •      copy        - Copy parameters because source is destroyed
      
    •      res_cb      - Function that will handle the AES based result (16 bytes)
      
    •      src_info    - Information used retrieve requester
      
    • @return None.
      /
      void aes_encrypt(const uint8_t
      key, const uint8_t *val, bool copy, aes_func_result_cb res_cb, uint32_t src_info);


  • unsigned long aes_cbc_encrypt(unsigned char in_data[],unsigned long InputLen, unsigned char out_data[]) {
    unsigned long outlen;
    outlen = AES128_CBC_Encrypt(in_data,InputLen, KEY, out_data);
    return outlen;
    }

    unsigned long aes_cbc_decrypt(unsigned char in_data[],unsigned long InputLen, unsigned char out_data[]) {
    unsigned long outlen;
    outlen = AES128_CBC_Decrypt(in_data, InputLen, KEY, out_data);
    return outlen;
    }



  • "aes_enc_result_cb" is the encode result