From: couturie Date: Sun, 18 Feb 2018 19:23:04 +0000 (+0100) Subject: improvement X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/commitdiff_plain/3fbd7b35e2a1ab0574ec4fc209d3a261a98c563d?ds=sidebyside;hp=-c improvement --- 3fbd7b35e2a1ab0574ec4fc209d3a261a98c563d diff --git a/OneRoundIoT/OneRound/one_round_hash.cpp b/OneRoundIoT/OneRound/one_round_hash.cpp index 74a08a7..44773bc 100644 --- a/OneRoundIoT/OneRound/one_round_hash.cpp +++ b/OneRoundIoT/OneRound/one_round_hash.cpp @@ -135,6 +135,7 @@ void prga(uchar *sc, int ldata, uchar *r) { } } +inline uchar circ(uchar x,int n) {return (x << n) | (x >> (8 - n));} void diff(uchar *Y, uchar *X, int h) { @@ -145,7 +146,7 @@ void diff(uchar *Y, uchar *X, int h) { Y[3] = X[0]^X[1]^X[2]; } else if(h==8) { - Y[0] = X[0]^X[2]^X[3]^X[5]^X[6]^X[7]; + /*Y[0] = X[0]^X[2]^X[3]^X[5]^X[6]^X[7]; Y[1] = X[0]^X[1]^X[3]^X[4]^X[6]^X[7]; Y[2] = X[0]^X[1]^X[2]^X[4]^X[5]^X[7]; Y[3] = X[1]^X[2]^X[3]^X[4]^X[5]^X[6]; @@ -153,10 +154,32 @@ void diff(uchar *Y, uchar *X, int h) { Y[5] = X[1]^X[2]^X[4]^X[6]^X[7]; Y[6] = X[2]^X[3]^X[4]^X[5]^X[7]; Y[7] = X[0]^X[3]^X[4]^X[5]^X[6]; + */ + + + uchar X0=X[0]; + uchar X1=X[1]; + uchar X2=X[2]; + uchar X3=X[3]; + uchar X4=X[4]; + uchar X5=X[5]; + uchar X6=X[6]; + uchar X7=X[7]; + + Y[0] = X0^X2^X3^X5^X6^X7; + Y[1] = X0^X1^X3^X4^X6^X7; + Y[2] = X0^X1^X2^X4^X5^X7; + Y[3] = X1^X2^X3^X4^X5^X6; + Y[4] = X0^X1^X5^X6^X7; + Y[5] = X1^X2^X4^X6^X7; + Y[6] = X2^X3^X4^X5^X7; + Y[7] = X0^X3^X4^X5^X6; + + } else if(h==16) { - Y[0] = X[3] ^ X[4] ^ X[6] ^ X[8] ^ X[9] ^ X[13] ^ X[14]; + Y[0] = X[3] ^ X[4] ^ X[6] ^ X[8] ^ X[9] ^ X[13] ^ X[14]; Y[1] = X[2] ^ X[5] ^ X[7] ^ X[8] ^ X[9] ^ X[12] ^ X[15]; Y[2] = X[1] ^ X[4] ^ X[6] ^ X[10] ^ X[11] ^ X[12] ^ X[15]; Y[3] = X[0] ^ X[5] ^ X[7] ^ X[10] ^ X[11] ^ X[13] ^ X[14]; @@ -171,7 +194,46 @@ void diff(uchar *Y, uchar *X, int h) { Y[12] = X[1] ^ X[2] ^ X[6] ^ X[7] ^ X[9] ^ X[11] ^ X[12]; Y[13] = X[0] ^ X[3] ^ X[6] ^ X[7] ^ X[8] ^ X[10] ^ X[13]; Y[14] = X[0] ^ X[3] ^ X[4] ^ X[5] ^ X[9] ^ X[11] ^ X[14]; - Y[15] = X[1] ^ X[2] ^ X[4] ^ X[5] ^ X[8] ^ X[10] ^ X[15]; + Y[15] = X[1] ^ X[2] ^ X[4] ^ X[5] ^ X[8] ^ X[10] ^ X[15]; + + +/* uchar X0=X[0]; + uchar X1=X[1]; + uchar X2=X[2]; + uchar X3=X[3]; + uchar X4=X[4]; + uchar X5=X[5]; + uchar X6=X[6]; + uchar X7=X[7]; + uchar X8=X[8]; + uchar X9=X[9]; + uchar X10=X[10]; + uchar X11=X[11]; + uchar X12=X[12]; + uchar X13=X[13]; + uchar X14=X[14]; + uchar X15=X[15]; + + + Y[0] = X3 ^ X4 ^ X6 ^ X8 ^ X9 ^ X13 ^ X14; + Y[1] = X2 ^ X5 ^ X7 ^ X8 ^ X9 ^ X12 ^ X15; + Y[2] = X1 ^ X4 ^ X6 ^ X10 ^ X11 ^ X12 ^ X15; + Y[3] = X0 ^ X5 ^ X7 ^ X10 ^ X11 ^ X13 ^ X14; + Y[4] = X0 ^ X2 ^ X5 ^ X8 ^ X11 ^ X14 ^ X15; + Y[5] = X1 ^ X3 ^ X4 ^ X9 ^ X10 ^ X14 ^ X15; + Y[6] = X0 ^ X2 ^ X7 ^ X9 ^ X10 ^ X12 ^ X13; + Y[7] = X1 ^ X3 ^ X6 ^ X8 ^ X11 ^ X12 ^ X13; + Y[8] = X0 ^ X1 ^ X4 ^ X7 ^ X10 ^ X13 ^ X15; + Y[9] = X0 ^ X1 ^ X5 ^ X6 ^ X11 ^ X12 ^ X14; + Y[10] = X2 ^ X3 ^ X5 ^ X6 ^ X8 ^ X13 ^ X15; + Y[11] = X2 ^ X3 ^ X4 ^ X7 ^ X9 ^ X12 ^ X14; + Y[12] = X1 ^ X2 ^ X6 ^ X7 ^ X9 ^ X11 ^ X12; + Y[13] = X0 ^ X3 ^ X6 ^ X7 ^ X8 ^ X10 ^ X13; + Y[14] = X0 ^ X3 ^ X4 ^ X5 ^ X9 ^ X11 ^ X14; + Y[15] = X1 ^ X2 ^ X4 ^ X5 ^ X8 ^ X10 ^ X15; +*/ + + } else if(h==32) { @@ -257,6 +319,13 @@ void hash_DSD_BIN(uchar* seq_in, uchar* RM1,int len, int *PboxRM, uchar *Sbox1, } // Second Diffusion Operation + + /*for(int a=0;a> (8 - n));} //the proposed hash function, which is based on DSD structure. Sensitivity is ensured by employing the binary diffusion @@ -186,6 +186,7 @@ void hash_DSD_BIN(uchar* seq_in, uchar* RM1,int len, int *PboxRM, uchar *Sbox1, for(int a=0;a