From: couturier Date: Sun, 19 Jun 2022 18:42:45 +0000 (+0200) Subject: new X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/commitdiff_plain/1bc84f88ed0b04d141bab6a6180b69f30d318628?ds=sidebyside new --- diff --git a/Arduino/With_Duc/Makefile b/Arduino/With_Duc/Makefile new file mode 100644 index 0000000..ab3b325 --- /dev/null +++ b/Arduino/With_Duc/Makefile @@ -0,0 +1,22 @@ +CXX=g++ +C=gcc + +uname_m := $(shell uname -m) +ifeq ($(uname_m),armv7l) +CFLAGS=-O3 -march=armv7-a -mtune=cortex-a8 -mfpu=neon -ftree-vectorize -lrt `pkg-config --cflags --libs glib-2.0` +else +ifeq ($(uname_m),armv6l) +CFLAGS=-O3 -march=armv6 -mfpu=vfp -mfloat-abi=hard -lrt `pkg-config --cflags --libs glib-2.0` +else +CFLAGS=-O3 `pkg-config --cflags --libs glib-2.0` +endif +endif + +%.o: %.c + $(C) -c -o $@ $< $(CFLAGS) + +version_linux.o: version_linux.c + $(C) -c -o $@ $< $(CFLAGS) + +clean: + rm -rf *.o version_linux diff --git a/Arduino/With_Duc/version_linux.c b/Arduino/With_Duc/version_linux.c new file mode 100644 index 0000000..fceca13 --- /dev/null +++ b/Arduino/With_Duc/version_linux.c @@ -0,0 +1,444 @@ +//version to test the performance of our code with message of size 16 to 240 +//in order to make test with Duc + +//the size of the message can be changed + +#include +#include +#include +#include + +#include + +const int h=2; +const int h2=h*h; + + + +double TimeStart() +{ + struct timeval tstart; + gettimeofday(&tstart,0); + return( (double) (tstart.tv_sec + tstart.tv_usec*1e-6) ); +} + +double TimeStop(double t) +{ + struct timeval tend; + + gettimeofday(&tend,0); + t = (double) (tend.tv_sec + tend.tv_usec*1e-6) - t; + return (t); +} + + + + +typedef uint8_t uchar; +typedef uint8_t byte; +//typedef unsigned long uint; + +uint seed=123; + +#define SKEY 64 + + +#define STATIC_KEY + +//#define STATIC_KEY +//#define STATIC_KEY_256q +//#define STATIC_KEY_128 +//#define STATIC_KEY_64 +//#define STATIC_KEY_32 +#define STATIC_KEY_64 + +//dynamic key +uchar DK[SKEY]; + +#ifdef STATIC_KEY + +#ifdef STATIC_KEY_256 + +uchar Nonce[256] = { + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C, + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C, + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C, + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C, + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C, + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C, + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C, + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C, + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C, + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3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F, 0x4F, 0x3C, + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C, + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C, + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C +}; + + +#elif defined STATIC_KEY_64 + +uchar Nonce[64] = { + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C, + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C, + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C, + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C +}; + +#elif defined STATIC_KEY_32 + +uchar Nonce[32] = { + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C, + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C +}; + +#elif defined STATIC_KEY_16 + +uchar Nonce[16] = { + 0x2B, 0x7E, 0x15, 0x16, 0x28, 0xAE, 0xD2, 0xA6, 0xAB, 0xF7, 0x15, 0x88, 0x09, 0xCF, 0x4F, 0x3C +}; + +#endif + +#else + +uchar Nonce[SKEY]; + +#endif + +int rp=1; + +//number of blocks + + +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; +} + +void rc4key(uchar *key, uchar *sc, int size_DK) { + + for(int i=0;i<256;i+=4) { + sc[i]=i; + sc[i+1]=i+1; + sc[i+2]=i+2; + sc[i+3]=i+3; + } + + uchar j0 = 0; + for(int i0=0; i0<256; i0++) { + j0 = (j0 + sc[i0] + key[i0&(size_DK-1)] ); + uchar tmp = sc[i0]; + sc[i0] = sc[j0 ]; + sc[j0] = tmp; + } +} + +void rc4keyperm(uchar *key,int len, int rp,uchar *sc, int size_DK) { + + //sc=1:len; + + for (int i=0;i>=8; + X[a+1]=Sbox2[RM1[a+1]^(mm&255)]; + mm>>=8; + X[a+2]=Sbox1[RM1[a+2]^(mm&255)]; + mm>>=8; + X[a+3]=Sbox2[RM1[a+3]^(mm&255)]; + + +/* uint32_t val=*((uint32_t*)&RM1[a])^mm; + uchar *val2=(uchar*)&val; + X[a]=Sbox1[val2[0]]; + X[a+1]=Sbox2[val2[1]]; + X[a+2]=Sbox1[val2[2]]; + X[a+3]=Sbox2[val2[3]]; +*/ + + + + } + + for(int it=0;it>=8; + X[a+1]=Sbox1[X[a+1]^RM1[a+1]^(mm&255)]; + mm>>=8; + X[a+2]=Sbox2[X[a+2]^RM1[a+2]^(mm&255)]; + mm>>=8; + X[a+3]=Sbox1[X[a+3]^RM1[a+3]^(mm&255)]; + +/* uint32_t val=*((uint32_t*)&X[a])^*((uint32_t*)&RM1[a])^mm; + uchar *val2=(uchar*)&val; + X[a]=Sbox2[val2[0]]; + X[a+1]=Sbox1[val2[1]]; + X[a+2]=Sbox2[val2[2]]; + X[a+3]=Sbox1[val2[3]]; +*/ + } + + + + for(int a=0;a>=8; + DK[i+1]=val&0xFF; + val>>=8; + DK[i+2]=val&0xFF; + val>>=8; + DK[i+3]=val&0xFF; + } + + // printf("TOTO\n"); + +#ifndef STATIC_KEY + + for(int i=0;i<256;i+=4) { + seed=xorshift32(seed); + uint val=seed; + Nonce[i]=val&0xFF; + val>>=8; + Nonce[i+1]=val&0xFF; + val>>=8; + Nonce[i+2]=val&0xFF; + val>>=8; + Nonce[i+3]=val&0xFF; + } + +#endif + + //printf("DK\n"); + for(int i=0;i execution_oneround.txt -printf "size; throughtput delta enc dec; throughtput enhanced ctr delta enc dec; throughtput AES ctr enc dec" +printf "size; throughtput delta enc dec; throughtput enhanced ctr delta enc dec; throughtput AES ctr enc dec; throughtput PHAMalgo enc dec " printf "\n" -printf "64\t"; ./scprng nb10000000 lena0 h8 sizebuf8; ../OneRound/one_round_new4 nb10000000 lena0 ctr1 h8 sizebuf8; ../openssl/openssl_evp nb1000000 lena0 ctr1 h8 sizebuf8 +printf "64\t"; ./scprng nb10000000 lena0 h8 sizebuf8; ../OneRound/one_round_new4 nb10000000 lena0 ctr1 h8 sizebuf8; ../openssl/openssl_evp nb1000000 lena0 ctr1 h8 sizebuf8; ../../Arduino/With_Duc/version_linux nb10000000 sizebuf8 printf "\n" -printf "256\t"; ./scprng nb1000000 lena0 h32 sizebuf16; ../OneRound/one_round_new4 nb1000000 lena0 ctr1 h16 sizebuf16; ../openssl/openssl_evp nb1000000 lena0 ctr1 h16 sizebuf16 +printf "256\t"; ./scprng nb1000000 lena0 h32 sizebuf16; ../OneRound/one_round_new4 nb1000000 lena0 ctr1 h16 sizebuf16; ../openssl/openssl_evp nb1000000 lena0 ctr1 h16 sizebuf16; ../../Arduino/With_Duc/version_linux nb1000000 sizebuf16 printf "\n" -printf "1024\t"; ./scprng nb1000000 lena0 h128 sizebuf32; ../OneRound/one_round_new4 nb1000000 lena0 ctr1 h32 sizebuf32; ../openssl/openssl_evp nb1000000 lena0 ctr1 h32 sizebuf32 +printf "1024\t"; ./scprng nb1000000 lena0 h128 sizebuf32; ../OneRound/one_round_new4 nb1000000 lena0 ctr1 h32 sizebuf32; ../openssl/openssl_evp nb1000000 lena0 ctr1 h32 sizebuf32; ../../Arduino/With_Duc/version_linux nb1000000 sizebuf32 printf "\n" -printf "4096\t"; ./scprng nb100000 lena0 h128 sizebuf64; ../OneRound/one_round_new4 nb100000 lena0 ctr1 h32 sizebuf64; ../openssl/openssl_evp nb100000 lena0 ctr1 h32 sizebuf64 +printf "4096\t"; ./scprng nb100000 lena0 h128 sizebuf64; ../OneRound/one_round_new4 nb100000 lena0 ctr1 h32 sizebuf64; ../openssl/openssl_evp nb100000 lena0 ctr1 h32 sizebuf64; ../../Arduino/With_Duc/version_linux nb100000 sizebuf64 printf "\n" -printf "16384\t"; ./scprng nb100000 lena0 h128 sizebuf128; ../OneRound/one_round_new4 nb100000 lena0 ctr1 h32 sizebuf128; ../openssl/openssl_evp nb100000 lena0 ctr1 h32 sizebuf128 +printf "16384\t"; ./scprng nb100000 lena0 h128 sizebuf128; ../OneRound/one_round_new4 nb100000 lena0 ctr1 h32 sizebuf128; ../openssl/openssl_evp nb100000 lena0 ctr1 h32 sizebuf128; ../../Arduino/With_Duc/version_linux nb100000 sizebuf128 printf "\n" -printf "65536\t"; ./scprng nb10000 lena0 h128 sizebuf256; ../OneRound/one_round_new4 nb10000 lena0 ctr1 h32 sizebuf256; ../openssl/openssl_evp nb10000 lena0 ctr1 h32 sizebuf256 +printf "65536\t"; ./scprng nb10000 lena0 h128 sizebuf256; ../OneRound/one_round_new4 nb10000 lena0 ctr1 h32 sizebuf256; ../openssl/openssl_evp nb10000 lena0 ctr1 h32 sizebuf256; ../../Arduino/With_Duc/version_linux nb10000 sizebuf256 printf "\n" -printf "262144\t"; ./scprng nb1000 lena0 h128 sizebuf512; ../OneRound/one_round_new4 nb1000 lena0 ctr1 h32 sizebuf512; ../openssl/openssl_evp nb1000 lena0 ctr1 h32 sizebuf512 +printf "262144\t"; ./scprng nb1000 lena0 h128 sizebuf512; ../OneRound/one_round_new4 nb1000 lena0 ctr1 h32 sizebuf512; ../openssl/openssl_evp nb1000 lena0 ctr1 h32 sizebuf512; ../../Arduino/With_Duc/version_linux nb1000 sizebuf512 printf "\n"