suculent / thinx-aes-lib

AES wrapper for ESP8266/ESP32/Arduino/nRF5x
Other
117 stars 38 forks source link

Different code here and in downloaded version from Arduino library manager #54

Closed gligorot closed 2 years ago

gligorot commented 3 years ago

I banged my head against the wall the whole day while reading the issues here, until I noticed something. The 2.2.1 version that I downloaded from the Arduino lib manager still has the old code in the encrypt function (outputting base64 instead of bytes). The one in the repo under /src/AESLib.cpp doesn't have it.

According to a past issue this shouldn't be the case (https://github.com/suculent/thinx-aes-lib/issues/44#issuecomment-838183770) . . .

This is the Arduino library code (under Arduino/libraries/AESLib/AESLib.cpp.

/* Returns message encrypted only to be used as byte array. TODO: Refactor to byte[] */
uint16_t AESLib::encrypt(const byte input[], uint16_t input_length, char * output, const byte key[], int bits, byte my_iv[]) {

  aes.set_key(key, bits);
  aes.do_aes_encrypt((byte *)input, input_length, (byte*)output, key, bits, my_iv);

  uint16_t enc_len = aes.get_size();
  uint16_t base64_len = base64_enc_len(input_length);

  char b64data[base64_len];
  // Note: arg order is base64_encode(output, input);
  base64_len = base64_encode(b64data, (char*)output, enc_len);
  memcpy(output, b64data, base64_len);

  /*
#ifdef AES_DEBUG
  printf("[AESLib::encrypt] Encoded %u bytes = ", base64_len);
  for (uint8_t pos = 0; pos < base64_len; pos++) {
    if (pos < base64_len) {
      printf("%c", output[pos]);
    }
  }
#endif
  */

#ifndef __x86_64
#ifdef AES_DEBUG
  Serial.printf("[AESLib::encrypt] Encoded %u bytes = ", base64_len);
  for (uint8_t pos = 0; pos < base64_len; pos++) {
    if (pos < base64_len) {
      Serial.printf("%c", output[pos]);
    }
  }
  Serial.println("");
#endif
#endif

  return base64_len;
}

This is what's here in src/AESLib.cpp.


/* Returns message encrypted only to be used as byte array. TODO: Refactor to byte[] */
uint16_t AESLib::encrypt(const byte input[], uint16_t input_length, char * output, const byte key[], int bits, byte my_iv[]) {

  aes.set_key(key, bits);
  aes.do_aes_encrypt((byte *)input, input_length, (byte*)output, key, bits, my_iv);

  uint16_t enc_len = aes.get_size();

  /*
#ifdef AES_DEBUG
  printf("[AESLib::encrypt] Encoded %u bytes = ", base64_len);
  for (uint8_t pos = 0; pos < base64_len; pos++) {
    if (pos < base64_len) {
      printf("%c", output[pos]);
    }
  }
#endif
  */

#ifndef __x86_64
#ifdef AES_DEBUG
  Serial.printf("[AESLib::encrypt] Encoded %u bytes = ", base64_len);
  for (uint8_t pos = 0; pos < base64_len; pos++) {
    if (pos < base64_len) {
      Serial.printf("%c", output[pos]);
    }
  }
  Serial.println("");
#endif
#endif

  return enc_len;
}
suculent commented 3 years ago

Sorry, I'm aware of that. There's some underlying issue where Arduino Library Manager does not accept new versions when I need it (sometimes the tag mismatches version or there's been a change in manifest format). I'll look into it ASAP.

suculent commented 2 years ago

This should be fixed since today's tag 2.2.5 is already available.