-#include <Crypto.h>
-
-
-
-
-int size_mesg=256;
-
-byte *key = (unsigned char*)"0123456789010123";
-byte *iv = (unsigned char*)"0123456789010123";
-
-
-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:
-
- AES aes(key, iv, 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.encryptCBC(plain, cipher, size_mesg);
- Serial.print("Encryption took: ");
- Serial.println(micros() - ms1);
-AES aes2(key, iv, AES::AES_MODE_128, AES::CIPHER_DECRYPT);
-
- // aes.convertKey();
-ms1 = micros ();
- aes2.decryptCBC(cipher, check, size_mesg);
-Serial.print("Decryption 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 %d\n",equal);
-
-delay(2000);
-
-}