From: couturie Date: Thu, 18 Jul 2019 19:36:48 +0000 (+0000) Subject: new ida X-Git-Url: https://bilbo.iut-bm.univ-fcomte.fr/and/gitweb/Cipher_code.git/commitdiff_plain/f38d8f06fcce8506dacb379ca60a319b2db908a2?ds=sidebyside;hp=a85d220dc28f5751320089246cc879fbf88686ef new ida --- diff --git a/IDA_new/Makefile b/IDA_new/Makefile index d295284..6f4f0b4 100644 --- a/IDA_new/Makefile +++ b/IDA_new/Makefile @@ -41,5 +41,10 @@ ida_gf65: ida_gf65.cpp ida_gf65_paper1: ida_gf65_paper1.cpp g++ -o $@ $< -std=c++11 -O3 -lm -g -O3 -Wall -Ijerasure/include jerasure/src/.libs/jerasure.o jerasure/src/.libs/galois.o -lgf_complete -fpermissive -lpthread -I $(C_INCLUDE) + + +ida_gf65_paper2: ida_gf65_paper2.cpp + g++ -o $@ $< -std=c++11 -O3 -lm -g -O3 -Wall -Ijerasure/include jerasure/src/.libs/jerasure.o jerasure/src/.libs/galois.o -lgf_complete -fpermissive -lpthread -I $(C_INCLUDE) + clean: - rm test_mat2 ida ida_gf64 ida_gf65_paper1 + rm test_mat2 ida ida_gf64 ida_gf65_paper1 ida_gf65_paper2 diff --git a/IDA_new/RAPH.READ.ME b/IDA_new/RAPH.READ.ME index 705476f..8c2d5fc 100644 --- a/IDA_new/RAPH.READ.ME +++ b/IDA_new/RAPH.READ.ME @@ -7,3 +7,12 @@ make cd jerasure ./configure make + + + + + +export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/home/couturie/Cipher_code/IDA_new/gf-complete/src/.libs/ +export LIBRARY_PATH=$LIBRARY_PATH:/home/couturie/Cipher_code/IDA_new/gf-complete/src/.libs/ +export C_INCLUDE_PATH=$C_INCLUDE_PATH:/home/couturie/Cipher_code/IDA_new/gf-complete/include/ +export PATH=$PATH:/home/couturie/Cipher_code/IDA_new/gf-complete diff --git a/IDA_new/ida_gf65_paper2.cpp b/IDA_new/ida_gf65_paper2.cpp new file mode 100644 index 0000000..c76744c --- /dev/null +++ b/IDA_new/ida_gf65_paper2.cpp @@ -0,0 +1,663 @@ + + +#include +#include +#include +#include +#include +#include +#include +#include +#include // std::random_shuffle +#include // std::vector +#include +#include + + +extern "C" { + #include "jerasure.h" +} + +typedef unsigned long mylong; +#define LLUI (long long unsigned int) + + +using namespace std; + +string cloud[5]={"dropboxida1","googleida1","onedriveida2","onedriveida1","pcloudida1"}; + +void rc4keyperm(uint8_t *key,int len, int rp,int *sc, int size_DK) { + + //sc=1:len; + + + + for (int i=0;imultiply.w64(gf,m1[i*c1+k], m2[k*c2+j]); + } + } + } + return product; +} + + + +int invert_matrix(gf_t *gf, mylong *mat, mylong *inv, int rows) +{ + int cols, i, j, k, x, rs2; + int row_start; + mylong tmp, inverse; + + cols = rows; + + k = 0; + for (i = 0; i < rows; i++) { + for (j = 0; j < cols; j++) { + inv[k] = (i == j) ? 1 : 0; + k++; + } + } +// display(inv, rows, rows); +// printf("\n"); + + /* First -- convert into upper triangular */ + for (i = 0; i < cols; i++) { + row_start = cols*i; + + /* Swap rows if we ave a zero i,i element. If we can't swap, then the + matrix was not invertible */ + + if (mat[row_start+i] == 0) { + for (j = i+1; j < rows && mat[cols*j+i] == 0; j++) ; + if (j == rows) return -1; + rs2 = j*cols; + for (k = 0; k < cols; k++) { + tmp = mat[row_start+k]; + mat[row_start+k] = mat[rs2+k]; + mat[rs2+k] = tmp; + tmp = inv[row_start+k]; + inv[row_start+k] = inv[rs2+k]; + inv[rs2+k] = tmp; + } + } + + /* Multiply the row by 1/element i,i */ + tmp = mat[row_start+i]; + if (tmp != 1) { + inverse = gf->divide.w64(gf,1, tmp); + for (j = 0; j < cols; j++) { + mat[row_start+j] = gf->multiply.w64(gf,mat[row_start+j], inverse); + inv[row_start+j] = gf->multiply.w64(gf,inv[row_start+j], inverse); + } + } + + /* Now for each j>i, add A_ji*Ai to Aj */ + k = row_start+i; + for (j = i+1; j != cols; j++) { + k += cols; + if (mat[k] != 0) { + if (mat[k] == 1) { + rs2 = cols*j; + for (x = 0; x < cols; x++) { + mat[rs2+x] ^= mat[row_start+x]; + inv[rs2+x] ^= inv[row_start+x]; + } + } else { + tmp = mat[k]; + rs2 = cols*j; + for (x = 0; x < cols; x++) { + mat[rs2+x] ^= gf->multiply.w64(gf,tmp, mat[row_start+x]); + inv[rs2+x] ^= gf->multiply.w64(gf,tmp, inv[row_start+x]); + } + } + } + } + } + + /* Now the matrix is upper triangular. Start at the top and multiply down */ + + for (i = rows-1; i >= 0; i--) { + row_start = i*cols; + for (j = 0; j < i; j++) { + rs2 = j*cols; + if (mat[rs2+i] != 0) { + tmp = mat[rs2+i]; + mat[rs2+i] = 0; + for (k = 0; k < cols; k++) { + inv[rs2+k] ^= gf->multiply.w64(gf,tmp, inv[row_start+k]); + } + } + } + } + +/* printf("mat\n"); + display(mat, rows, rows); + printf("\n"); + printf("inv\n"); + display(inv, rows, rows); + printf("\n"); +*/ + return 0; +} + + + + +int invertible_matrix(gf_t *gf, int *mat, int rows, int w) +{ + int cols, i, j, k, x, rs2; + int row_start; + mylong tmp, inverse; + + cols = rows; + + /* First -- convert into upper triangular */ + for (i = 0; i < cols; i++) { + row_start = cols*i; + + /* Swap rows if we ave a zero i,i element. If we can't swap, then the + matrix was not invertible */ + + if (mat[row_start+i] == 0) { + for (j = i+1; j < rows && mat[cols*j+i] == 0; j++) ; + if (j == rows) return 0; + rs2 = j*cols; + for (k = 0; k < cols; k++) { + tmp = mat[row_start+k]; + mat[row_start+k] = mat[rs2+k]; + mat[rs2+k] = tmp; + } + } + + /* Multiply the row by 1/element i,i */ + tmp = mat[row_start+i]; + if (tmp != 1) { + inverse = gf->divide.w64(gf,1, tmp); + for (j = 0; j < cols; j++) { + mat[row_start+j] = gf->multiply.w64(gf,mat[row_start+j], inverse); + } + } + + /* Now for each j>i, add A_ji*Ai to Aj */ + k = row_start+i; + for (j = i+1; j != cols; j++) { + k += cols; + if (mat[k] != 0) { + if (mat[k] == 1) { + rs2 = cols*j; + for (x = 0; x < cols; x++) { + mat[rs2+x] ^= mat[row_start+x]; + } + } else { + tmp = mat[k]; + rs2 = cols*j; + for (x = 0; x < cols; x++) { + mat[rs2+x] ^= gf->multiply.w64(gf,tmp,mat[row_start+x]); + } + } + } + } + } + return 1; +} + + + + + +mylong* readFullFile(char* filename,int n, int t, mylong& sizeFile, mylong & padded_size) { + + ifstream stream(filename, ios::in | ios::binary | ios::ate); +// ifstream stream("lena_small.png", ios::in | ios::binary | ios::ate); +// ifstream stream("/home/couturie/Downloads/CARCARIASS.zip", ios::in | ios::binary | ios::ate); + + sizeFile=stream.tellg(); +//cout << sizeFile << std::endl; + stream.seekg(0, ios::beg); + + + + + + + vector contents((istreambuf_iterator(stream)), istreambuf_iterator()); + + + + + + + + //make padding, we need to pad to be divisible by 8*t, we + if((sizeFile+8)%(8*t)!=0) { +// cout<<(int)(sizeFile/(8*t))<(p_contents); + + padded_size=contents.size()/8; + + mylong *p_contents2=new mylong[padded_size]; + memcpy(p_contents2,p_contents,sizeof(mylong)*padded_size); + //mylong *p_contents2=(mylong*)p_contents; + + p_contents2[0]=sizeFile; + + + + +/* for(int i=0;i=0;i--) { + res<<=8; + res+=p_contents[i]; + } + + cout << "convert val " << (long)res << endl; + + res=0; + for(int i=16-1;i>=8;i--) { + res<<=8; + res+=p_contents[i]; + } + + cout << "convert val " << (long)res << endl; + */ + + return p_contents2; +} + +void sendChunk(string name,int cloud_id) { + stringstream ss; + ss <<"rclone copy "<n) { + cout<<"pb t>n"< elapsed_seconds = end-start; + total_time+=elapsed_seconds.count(); +// cout << "elapsed time: " << elapsed_seconds.count() << "s\n"; + +// display(matC,t,t); + +// thread th[n]; + //Save trunks + for(int i=0;i myvector; + + // set some values: + for (int i=0; i(&matS2[1]); +// saveFile(reconstucted_data, "file.dat",new_size); + return 0; +} + + diff --git a/IDA_new/run_long_paper2.py b/IDA_new/run_long_paper2.py new file mode 100644 index 0000000..ef93abb --- /dev/null +++ b/IDA_new/run_long_paper2.py @@ -0,0 +1,20 @@ +#python3 run_long_paper2.py > exe_long_paper2.txt + + +import subprocess +import re + + +print("#size \t t \t n \t time") + +for i in range(8,20,1): + len=(2**i) + + subprocess.check_output("head -c "+str(len)+" file"+str(len),shell=True) + for k in range(2,8,2): + result=subprocess.check_output("./ida_gf65_paper2 t"+str(k)+" n8 ffile"+str(len),shell=True) + res=result.decode() + print(str(len)+"\t"+str(k)+"\t 8 \t"+res) + + +