--- /dev/null
+#include <Crypto.h>
+
+
+
+
+int size_mesg=256;
+
+byte *key = (unsigned char*)"0123456789010123";
+byte *iv = (unsigned char*)"9210123456789010";
+
+
+void printArray(byte *mes, int n) {
+ for (byte i = 0; i < n; i++) {
+ Serial.print(mes[i]);
+ Serial.print(" ");
+ }
+ Serial.println();
+}
+
+
+
+void setup() {
+ // put your setup code here to run once:
+ Serial.begin (57600) ;
+// printf_begin();
+ delay(500);
+}
+
+void loop() {
+ // put your main code here, to run repeatedly:
+ byte myiv[AES_IV_SIZE];
+ memcpy(myiv, iv, AES_IV_SIZE);
+ //printArray(myiv,AES_IV_SIZE);
+ AES aes(key, myiv, AES::AES_MODE_128, AES::CIPHER_ENCRYPT);
+
+ uint8_t plain[size_mesg];
+ uint8_t cipher [size_mesg] ;
+ uint8_t check [size_mesg] ;
+
+
+ randomSeed(334);
+ for(int i=0;i<size_mesg;i++) {
+ plain[i]=random(255);
+ }
+
+
+unsigned long ms1 = micros ();
+
+ aes.encryptCTR(plain, cipher, size_mesg);
+ Serial.print("Encryption CTR took: ");
+ Serial.println(micros() - ms1);
+
+
+ memcpy(myiv, iv, AES_IV_SIZE);
+ // printArray(myiv,AES_IV_SIZE);
+
+
+
+AES aes2(key, myiv, AES::AES_MODE_128, AES::CIPHER_ENCRYPT);
+
+ // aes.convertKey();
+ms1 = micros ();
+ aes2.encryptCTR(cipher, check, size_mesg);
+Serial.print("Decryption CTR took: ");
+ Serial.println(micros() - ms1);
+
+
+
+
+
+
+
+
+//printArray(plain,size_mesg);
+//printArray(cipher,size_mesg);
+//printArray(check,size_mesg);
+
+ bool equal=true;
+ for(int i=0;i<size_mesg-1;i++) {
+
+ if(check[i]!=plain[i]) {
+ // printf("%d %d %d\n",plain[i],check[i],i);
+ equal=false;
+ }
+ }
+ printf("CHECK CTR %d\n",equal);
+
+
+
+
+{
+AES aes(key, myiv, AES::AES_MODE_128, AES::CIPHER_ENCRYPT);
+ms1 = micros ();
+ aes.encryptCBC(plain, cipher, size_mesg);
+
+ Serial.print("Encryption CBC took: ");
+ Serial.println(micros() - ms1);
+
+AES aes2(key, myiv, AES::AES_MODE_128, AES::CIPHER_DECRYPT);
+ms1 = micros ();
+ aes2.decryptCBC(cipher, check, size_mesg);
+
+Serial.print("Decryption CBC took: ");
+ Serial.println(micros() - ms1);
+
+
+
+
+ equal=true;
+ for(int i=0;i<size_mesg-1;i++) {
+
+ if(check[i]!=plain[i]) {
+ // printf("%d %d %d\n",plain[i],check[i],i);
+ equal=false;
+ }
+ }
+ printf("CHECK CBC %d\n",equal);
+}
+
+
+delay(2000);
+
+}