Ciao SukkoPera
e grazie per la risposta. Scusa ma non ho ben capito come implementare l'operatore. Ora posto tutto il codice:
#include <AES.h>
AES aes ;
struct dataStruct {
String Data1 = "c5390e6ad642d182fe46e36c226589ff";
unsigned long Data2 = 9728667411;
unsigned long Data3 = 1968371867;
byte Data4[16] = { 0xf3, 0x44, 0x81, 0xec, 0x3c, 0xc6, 0x27, 0xba, 0xcd, 0x5d, 0xc3, 0xfb, 0x08, 0xf2, 0x73, 0xe6, };
uint64_t Data5 = 0x9281fc47b5LL;
byte Data6 = 0x44;
byte Data7 = 0xFF;
byte Data8 = 0xE3;
byte Data9 = 0x00;
byte Data10[16] = { 0xf3, 0x44, 0x81, 0xec, 0x3c, 0xc6, 0x27, 0xba, 0xcd, 0x5d, 0xc3, 0xfb, 0x08, 0xf2, 0x73, 0xe6, };
} stdPkt;
byte key[] =
{
0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
} ;
byte* plain = reinterpret_cast<byte*>(&stdPkt);
byte my_iv[] =
{
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01,
} ;
byte cipher [8*N_BLOCK] ;
byte check [8*N_BLOCK] ;
void loop ()
{}
void setup ()
{
Serial.begin (57600) ;
Serial.print ("testng mode") ;
prekey_test () ;
// otfly_test () ;
// otfly_test256 () ;
}
void prekey (int bits, int blocks)
{
byte iv [N_BLOCK] ;
long t0 = micros () ;
byte succ = aes.set_key (key, bits) ;
long t1 = micros()-t0 ;
Serial.print ("set_key ") ; Serial.print (bits) ; Serial.print (" ->") ; Serial.print ((int) succ) ;
Serial.print (" took ") ; Serial.print (t1) ; Serial.println ("us") ;
t0 = micros () ;
if (blocks == 1)
succ = aes.encrypt (plain, cipher) ;
else
{
for (byte i = 0 ; i < 16 ; i++)
iv[i] = my_iv[i] ;
succ = aes.cbc_encrypt (plain, cipher, blocks, iv) ;
}
t1 = micros () - t0 ;
Serial.print ("encrypt ") ; Serial.print ((int) succ) ;
Serial.print (" took ") ; Serial.print (t1) ; Serial.println ("us") ;
t0 = micros () ;
if (blocks == 1)
succ = aes.decrypt (cipher, plain) ;
else
{
for (byte i = 0 ; i < 16 ; i++)
iv[i] = my_iv[i] ;
succ = aes.cbc_decrypt (cipher, check, blocks, iv) ;
}
t1 = micros () - t0 ;
Serial.print ("decrypt ") ; Serial.print ((int) succ) ;
Serial.print (" took ") ; Serial.print (t1) ; Serial.println ("us") ;
for (byte ph = 0 ; ph < (blocks == 1 ? 3 : 4) ; ph++)
{
for (byte i = 0 ; i < (ph < 3 ? blocks*N_BLOCK : N_BLOCK) ; i++)
{
byte val = ph == 0 ? plain[i] : ph == 1 ? cipher[i] : ph == 2 ? check[i] : iv[i] ;
Serial.print (val>>4, HEX) ; Serial.print (val&15, HEX) ; Serial.print (" ") ;
}
Serial.println();
}
//ORA RICOMPILA LA STRUTTURA DI stdPkt DA "check" E SCRIVI SUL SERIALE UNO DEI VALORI
Serial.println (stdPkt????????????) ;
}
void prekey_test ()
{
prekey (256, 8) ;
}
Dove dovrei inserirlo? Scusa se sono insistente ma voglio capire il funzionamento esatto della cosa.