-#include <AES.h>
+ #include <AES.h>
//#include "./printf.h"
//#include <ESP8266WiFi.h>
-const int size_mesg=256;
+const int size_mesg=16;
const int sleepTimeS = 10;
-const int h=4;
+const int h=2;
const int h2=h*h;
byte DK[64];
int rp=1;
typedef byte uchar;
+typedef unsigned int uint;
int Pbox[len];
int PboxRM[h2];
uchar Sbox2[256];
uchar RM1_cpy[h2];
+
+struct ulong2{
+ unsigned long int x, y;
+};
+
+typedef struct ulong2 ulong2;
+typedef unsigned long int ulong;
+uint xorshift32(const uint t)
+{
+ /* Algorithm "xor" from p. 4 of Marsaglia, "Xorshift RNGs" */
+ uint x = t;
+ x ^= x << 13;
+ x ^= x >> 17;
+ x ^= x << 5;
+ return x;
+}
+uint pcg32_random_r(ulong2* rng)
+{
+ // pcg32_random_t *rng=(pcg32_random_t*)rng2;
+ ulong oldstate = rng->x;
+ // Advance internal state
+ rng->x = oldstate * 6364136223846793005ULL + (rng->y|1);
+ // Calculate output function (XSH RR), uses old state for max ILP
+ uint xorshifted = ((oldstate >> 18u) ^ oldstate) >> 27u;
+ uint rot = oldstate >> 59u;
+ return (xorshifted >> rot) | (xorshifted << ((-rot) & 31));
+}
+
+
void inverse_tables(uchar *tab, int size_tab,uchar *inv_perm_tabs) {
for(int a=0;a<h2;a++) {
- X[a]=Sbox1[a&0xFF]; //Warning according to the size of h2, we can be outsize of Sbox1[a]
+ X[a]=Sbox1[a]; //Warning according to the size of h2, we can be outsize of Sbox1[a]
}
printf("\n===testng mode\n") ;
+
+
+
+
uchar sc[256];
uchar RM1[h2];
uchar RM2[h2];
- randomSeed(134);
+ randomSeed(14);
for(byte i=0;i<64;i++) {
DK[i]=random(255);
void prekey (int bits)
{
+unsigned int res=21;
+ unsigned long msms = micros ();
+ ulong2 pcg;
+ pcg.x=190812;
+ pcg.y=20911;
+ for(int i=0;i<100;i++) {
+ res=random(255);
+ //res=xorshift32(res);
+ //res=pcg32_random_r(&pcg);
+
+ }
+ unsigned long res2=micros() - msms;
+ Serial.print("rand");
+ Serial.println(res2);
+ Serial.println(res);
+
+
byte plain[size_mesg];
byte cipher [size_mesg] ;
}
-
+ printArray(RM1,16);
+ printArray(Sbox1,16);
+ printArray(Sbox2,16);
+ //printArray(Pbox,16);
+ delay(100);
unsigned long ms1 = micros ();
encrypt_ctr(plain, cipher,len,RM1,Pbox,PboxRM,Sbox1,Sbox2,1);
Serial.println(micros() - ms1);
printf("\n\nPLAIN :");
- printArray(plain,16*2);
+ printArray(plain,16);
printf("\nCIPHER:");
- printArray(cipher,16*2);
+ printArray(cipher,16);
printf("\nCHECK :");
- printArray(check,16*2);
+ printArray(check,16);
bool equal=true;
for(int i=0;i<size_mesg;i++) {
prekey (128) ;
}
+