// clang time.c LagCoef.o M.o -O3 #include #include typedef long unsigned int L; typedef L ft(L); extern ft * T[256]; // in M.c typedef unsigned char uc; void LagCoef(int n, uc r, uc av[n], uc coef[n]); static L ru(){return (L)arc4random()<<32 | arc4random();} int main(){L * area = malloc((11+3+3+1)*512*sizeof(L)); if(!area) exit(printf("No space\n")); L * base = (L *)((L)(area+511)&(-1L<<12)); // 17 aligned pages. for(int j=0; j<11*512; ++j) base[j] = ru(); // generate the asset. uc av[11]; for(int j=0; j<11; ++j) av[j]=j; // page number is portion argument for both asset and aux. for(int j=11; j<11+3; ++j) { // generate each aux page. uc coe[11]; LagCoef(11, j, av, coe); for(int n=0; n<512; ++n) base[(j<<9)+n] = 0; for(int k=0; k<11; ++k) {ft * m = T[coe[k]]; for(int n=0; n<512; ++n) base[(j<<9)+n] ^= (*m)(base[(k<<9)+n]);}} if(0) for(int y=0; y<13; ++y) printf("%016lx\n", base[(11<<9)+y]); // We have now constructed the 3 auxiliaries. uc sur[11] = {1, 2, 4, 5, 7, 8, 9, 10, 11, 12, 13}; uc lost[3] = {0, 3, 6}; for(int n=0; n<3; ++n) for(int k=0; k<512; ++k) // copy the three lost pages. base[((14+n)<<9)+k] = base[(lost[n]<<9)+k]; // reconstruct the three lost pages. for(int cc=0; cc<10000; ++cc) { // .... timing for(int n=0; n<3; ++n) for(int k=0; k<512; ++k) base[(lost[n]<<9)+k] = 0; for(int n=0; n<3; ++n) {uc coe[11]; LagCoef(11, lost[n], sur, coe); for(int j=0; j<11; ++j) { // consult each surviving page. ft * m = T[coe[j]]; for(int k=0; k<512; ++k) base[(lost[n]<<9)+k] ^= (*m)(base[(sur[j]<<9)+k]);}}} // Now the asset should be like new. for(int n = 0; n<3; n++) { // verify each page. for(int k=0; k<512; ++k) if(base[(lost[n]<<9)+k] ^ base[((14+n)<<9)+k]) exit(printf("Bad!!\n"));} return 0;}