X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/blobdiff_plain/7b02553c06f361be8c2f181d0a6cb4cd6b4fdb39..ea9417be1e1c60681c8dc1f5071059eb602f329e:/OneRoundIoT/OneRound/one_round_hash.cpp diff --git a/OneRoundIoT/OneRound/one_round_hash.cpp b/OneRoundIoT/OneRound/one_round_hash.cpp index e67d4bb..9733449 100644 --- a/OneRoundIoT/OneRound/one_round_hash.cpp +++ b/OneRoundIoT/OneRound/one_round_hash.cpp @@ -12,6 +12,8 @@ #include #include #include +#include + /*#include #include @@ -126,7 +128,7 @@ void prga(uchar *sc, int ldata, uchar *r) { uchar j0=0; for (int it=0; it> (8 - n));} void diff(uchar *Y, uchar *X, int h) { @@ -145,7 +148,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 +156,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,11 +196,50 @@ 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 ^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24]^X[27]^X[28]^X[29]^X[30]; Y[31]=X[2]^X[3]^X[4]^X[5]^X[12]^X[13]^X[17]^X[19]^X[21]^X[22]^X[25]^X[26]^X[28]^X[29]^X[31]; +*/ + + + 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]; + uchar X16=X[16]; + uchar X17=X[17]; + uchar X18=X[18]; + uchar X19=X[19]; + uchar X20=X[20]; + uchar X21=X[21]; + uchar X22=X[22]; + uchar X23=X[23]; + uchar X24=X[24]; + uchar X25=X[25]; + uchar X26=X[26]; + uchar X27=X[27]; + uchar X28=X[28]; + uchar X29=X[29]; + uchar X30=X[30]; + uchar X31=X[31]; + + Y[0]=X0^X1^X2^X3^X4^X7^X8^X10^X12^X15^X16^X17^X18^X20^X21^X24^X25^X28^X30; + Y[1]=X0^ X1^X2^X3^X5^X6^X9^X11^X13^X14^X16^X17^X19^X20^X21^ X24^X25^X29^X31; + Y[2]=X0^X1^X2^X3^X5^X6^X8^X10^X13^X14^X16^X18^X19^X22^X23^X26^X27^X28^X30; + Y[3]=X0^X1^X2^X3^X4^X7^X9^X11^X12^X15^X17^X18^X19^X22^X23^X26^X27^X29^X31; + Y[4]=X0^X3^X5^X6^X7^X10^X11^ X12^X13^X14^ X15^X16^X19^X21^X23^ X25^X27^X30^X31; + Y[5]=X1^X2^X4^X6^X7^X10^X11^X12^X13^X14^X16 ^X17^X18^X20^X22^X24^X26^X30^X31; + Y[6]=X1^X2^X4^X5^X7^X8^X9^X12^X13^X14^X15^ X17^X18^X21^X23^X25^X27^X28^X29; + Y[7]=X0^X3^X4^X5^X6^X9 ^X9^X12^X13^X14^X15^X16^X19^X20^X22^X24^X26^X28^X29; + Y[8]=X0^X2^X6^X7^X8^X10^X11^X14^X15^X16^X18^X21^X22^X25^X26; + Y[9]=X1^ X3^X6^X7^X9^X10^X11^X14^X15^X17^X19^X20^X23^X24^X27; + Y[10]=X0^X2^X4^X5^X8^X9^X10^X12^X13^X16^X18^X20^X23^ X24^X27; + Y[11]=X1^X3^X4^X5^X8^X9^X11^X12^X13^X17^X19^X21^X22^X25^X26; + Y[12]=X0^X3^X4^X5^X6^X7^X10^X11^X13^X14^X15^X16^X19^X21^X23^X25^X27^X30^X31; + Y[13]=X1^X2^X4^X5^X6^X7^X10^X11^X12^X14^X15^X17^ X18^X20^X22^X24^X26^X30^X31; + Y[14]=X1^X2^X4^X5^X6^X7^X8^X9^X12^X13^X15^X17^X18^X21^X23^X25^X27^X28^X29; + Y[15]=X0^X3^X4^X5^X6^X7^X8^X9^X12^X13^X14^X16^X19^X20^X22^ X24^X26^X28^X29; + Y[16]=X0^X1^X2^X4^X8 ^X8^X10^X13 ^X15^X16^X17^X18^X19^X20^X21^X24^X25^X28^X30; + Y[17]=X0^X1^X3^X5^X6^X9^X11^X13^X14^X16^X17^X18^X19^X20^X21^X24^X25^X29^X31; + Y[18]=X0^X2^X3^X5^X6^X8^X10^X13^X14^X16^X17^X18^X19^X22^X23^X26^X27^X28^X30; + Y[19]=X1^X2^X3^X4^X7^X9^X11^X12^X15^X16^X17^X18^X19^X22^X23^X26^X28 ^X29^X31; + Y[20]=X0^X1^X5^X7^X10 ^X10^X13^X15^X16^X17^X20^X21^X23^X29^X30; + Y[21]=X0^X1^X4^X6^X8^X11^X12^X14^X16^X17^X20^X21^X22^X28^X31; + Y[22]=X2^X3^X5^X7^X8^X11^X13^X15^X18^X19^X21^X22^X23^X28^X31; + Y[23]=X2^X3^X4^X6^X9^X10^X12^X14^ X18^X19^X20^X22^X23^X29^X30; + Y[24]=X0^X1^X5^X7^X9^X10^X13^X15^X16^X17^X24^X25^X27^X29^X30; + Y[25]=X0^X1^X4^X6^X8^X11^X12^X14^X16^X17^X24^X25^X26^X28^X31; + Y[26]=X2^X3^X5^X7^X8^X11^X13^X15^X18^X19^X25^X26^X27^X28^ X31; + Y[27]=X2^X3^X4^X6^X9^X10^X12^X14^X18^X19^X24^X26^X27^X29^X30; + Y[28]=X0^X2^X6^X7^X14^X15^X16^X18^X21^X22^X25^X26^X28^X30^X31; + Y[29]=X2^X3^X6^X7^X14^X15^X17^X19^X20^X23^X24^X27^X29^X30^X31; + Y[30]=X1^X2^X4^X5^X12^X13^X16^X18^X20^X23^X24^X27^X28^X29^X30; + Y[31]=X2^X3^X4^X5^X12^X13^X17^X19^X21^X22^X25^X26^X28^X29^X31; + + } } @@ -257,6 +391,13 @@ void hash_DSD_BIN(uchar* seq_in, uchar* RM1,int len, int *PboxRM, uchar *Sbox1, } // Second Diffusion Operation + + /*for(int a=0;a