/* Encoding/erasure decoding for Reed-Solomon codes over binary extension fields Author: Sian-Jheng Lin (King Abdullah University of Science and Technology (KAUST), email: sianjheng.lin@kaust.edu.sa) This program is the implementation of Lin, Han and Chung, "Novel Polynomial Basis and Its Application to Reed-Solomon Erasure Codes," FOCS14. (http://arxiv.org/abs/1404.3458) */ #include #include #include #include #include #include "RSErasureCode.h" /* typedef unsigned char GFSymbol; #define FIELD_BITS 8//2^FIELD_BITS: the size of Galois field GFSymbol mask = 0x1D; //GF(2^8): x^8 + x^4 + x^3 + x^2 + 1 GFSymbol Base[] = {1, 214, 152, 146, 86, 200, 88, 230};//Cantor basis */ typedef unsigned short GFSymbol; #define FIELD_BITS 16 GFSymbol mask = 0x2D;//x^16 + x^5 + x^3 + x^2 + 1 GFSymbol Base[FIELD_BITS] = {1, 44234, 15374, 5694, 50562, 60718, 37196, 16402, 27800, 4312, 27250, 47360, 64952, 64308, 65336, 39198};//Cantor basis #define FIELD_SIZE (1<>1];//factors used in formal derivative GFSymbol log_walsh[FIELD_SIZE];//factors used in the evaluation of the error locator polynomial //return a*EXP_TABLE[b] over GF(2^r) GFSymbol mulE(GFSymbol a, GFSymbol b){ return a ? EXP_TABLE[(LOG_TABLE[a]+b &MODULO) + (LOG_TABLE[a]+b >>FIELD_BITS)]: 0; } void walsh(GFSymbol* data, int size){//fast Walshā€“Hadamard transform over MODULOulo MODULO for (int depart_no=1; depart_no>FIELD_BITS); data[i+depart_no] = (tmp2&MODULO) + (tmp2>>FIELD_BITS); } } } return; } void formal_derivative(GFSymbol* cos, int size){//formal derivative of polynomial in the new basis for(int i=1; i>1; for(int j=i-leng; j>1; depart_no > 0; depart_no >>= 1){ for (int j = depart_no; j < size; j += depart_no<<1){ GFSymbol skew = skewVec[j+index-1]; if (skew != MODULO) for (int i=j-depart_no; i>FIELD_BITS-1){ state &= mas; state = state<<1^mask; }else state <<= 1; } EXP_TABLE[0] = MODULO; LOG_TABLE[0] = 0; for(int i=0; i0.5: parity is a power of two. // //data: message array. parity: parity array. mem: buffer(size>= n-k) // int t = n-k; // memset(parity, 0, sizeof(GFSymbol)*t); // for(int i=t; i>1]); codeword[i+1] = mulE(codeword[i+1], MODULO-B[i>>1]); } formal_derivative(codeword, n); for(int i=0; i>1]); codeword[i+1] = mulE(codeword[i+1], B[i>>1]); } FLT(codeword, n, 0); for (int i=0; i0; i--){//permuting the erasure array int pos = rand()%(i+1); if(i != pos){ Boolean tmp = erasure[i]; erasure[i] = erasure[pos]; erasure[pos] = tmp; } } #endif for (int i=0; i>>>>>>>> šŸŽ‰šŸŽ‰šŸŽ‰šŸŽ‰\n"); printf(">>>>>>>>> > Decoding is **SUCCESS** ful! šŸŽˆ\n"); printf(">>>>>>>>>\n"); return 0; } #include int test_flt_roundtrip() { const int N = 16; GFSymbol expected[16] = { 1, 2, 3, 5, 8, 13, 21, 44, 65, 0, 0xFFFF, 2, 3, 5, 7, 11, }; GFSymbol data[N]; memcpy(data, expected, N * sizeof(GFSymbol)); FLT(data, N, N/4); printf("novel basis(c)\n"); for(int i=0; i