How to use this AES library?

Am trying to encrypt something using AES library from this link: GitHub - spaniakos/AES: AES for microcontrollers (Arduino & Raspberry pi)

but the instruction is very unclear for me (am just started with Arduino 2 weeks)
I tried copy this code to a Arduino file and run: AES/aes.pde at master · spaniakos/AES · GitHub
but got this error, how can I fix it?
*sorry for broken English

Arduino: 1.8.8 (Windows 10), Board: "WeMos D1 R1, 80 MHz, Flash, Disabled, 4M (no SPIFFS), v2 Lower Memory, Disabled, None, Only Sketch, 115200"

In file included from D:\Desktop on HDD\AES_test\AES_test.ino:2:0:

C:\Users\Euphoria Celestial\Documents\Arduino\libraries\AES-master/./printf.h: In function 'void printf_begin()':

C:\Users\Euphoria Celestial\Documents\Arduino\libraries\AES-master/./printf.h:31:29: error: 'fdevopen' was not declared in this scope

   fdevopen( &serial_putc, 0 );


exit status 1
Error compiling for board WeMos D1 R1.

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

but the instruction is very unclear for me (am just started with Arduino 2 weeks)

Maybe this is not the best place to start.

The code in printf.h is specific to the AVR microcontrollers. As you discovered, it won’t compile for your ESP8266 board. The purpose of that code is to redirect stdout (which is where printf() outputs to) to Serial. On the ESP8266, this can be done with a single line of code:


So you only need to remove that AVR-specific code from the example and replace it with the equivalent code for the ESP8266:

#include <AES.h>

AES aes ;

byte *key = (unsigned char*)"0123456789010123";

byte plain[] = "Add NodeAdd NodeAdd NodeAdd NodeAdd Node";
int plainLength = sizeof(plain)-1;  // don't count the trailing /0 of the string !
int padedLength = plainLength + N_BLOCK - plainLength % N_BLOCK;

//real iv = iv x2 ex: 01234567 = 0123456701234567
unsigned long long int my_iv = 36753562;

void setup ()
  Serial.begin (57600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for Leonardo only
  printf("\n===testing mode\n") ;

//  otfly_test () ;
//  otfly_test256 () ;

void loop () 
  prekey_test () ;

void prekey (int bits)
  byte iv [N_BLOCK] ;
  byte plain_p[padedLength];
  byte cipher [padedLength] ;
  byte check [padedLength] ;
  unsigned long ms = micros ();
  Serial.print("Encryption took: ");
  Serial.println(micros() - ms);
  ms = micros ();
  Serial.print("Decryption took: ");
  Serial.println(micros() - ms);
  printf("\n\nPLAIN :");
  printf("\nCHECK :");
  printf("\nIV    :");

void prekey_test ()
  prekey (128) ;

I tried Pert’s solution, it’s running now
but the cipher shown in Serial Monitor is getting messed up, like font error or something, i dont know.
Here is the screenshot

I had the same result, but the unmodified example run on an AVR board also gives the identical output:

Encryption took: 2188
Decryption took: 2872

PLAIN :Add NodeAdd NodeAdd NodeAdd NodeAdd Node


CHECK :Add NodeAdd NodeAdd NodeAdd NodeAdd Node

IV    :4e80d9daed0830d4d225e31480eba09d


I don't know anything about the subject so I can't say whether this is the expected behavior. However, I think it's clear that it's not in any way related to the modifications to the sketch I suggested in my last reply.

OK, I will search for this later, thank you for your help Pert!