match_strval > try_val_to_str
[wireshark-wip.git] / epan / reedsolomon.c
blob3fbcc0039f7c5e06ccd91f3969d7831b93e91c5d
1 /*
3 * $Id$
5 * Reed-Solomon coding and decoding
6 * Phil Karn (karn@ka9q.ampr.org) September 1996
7 * Separate CCSDS version create Dec 1998, merged into this version May 1999
8 *
9 * This file is derived from my generic RS encoder/decoder, which is
10 * in turn based on the program "new_rs_erasures.c" by Robert
11 * Morelos-Zaragoza (robert@spectra.eng.hawaii.edu) and Hari Thirumoorthy
12 * (harit@spectra.eng.hawaii.edu), Aug 1995
14 * Copyright 1999 Phil Karn, KA9Q
15 * May be used under the terms of the GNU public license
17 #include <stdio.h>
18 #include "reedsolomon.h"
20 #ifdef CCSDS
21 /* CCSDS field generator polynomial: 1+x+x^2+x^7+x^8 */
22 int Pp[MM+1] = { 1, 1, 1, 0, 0, 0, 0, 1, 1 };
24 #else /* not CCSDS */
25 /* MM, KK, B0, PRIM are user-defined in rs.h */
27 /* Primitive polynomials - see Lin & Costello, Appendix A,
28 * and Lee & Messerschmitt, p. 453.
30 #if(MM == 2)/* Admittedly silly */
31 int Pp[MM+1] = { 1, 1, 1 };
33 #elif(MM == 3)
34 /* 1 + x + x^3 */
35 int Pp[MM+1] = { 1, 1, 0, 1 };
37 #elif(MM == 4)
38 /* 1 + x + x^4 */
39 int Pp[MM+1] = { 1, 1, 0, 0, 1 };
41 #elif(MM == 5)
42 /* 1 + x^2 + x^5 */
43 int Pp[MM+1] = { 1, 0, 1, 0, 0, 1 };
45 #elif(MM == 6)
46 /* 1 + x + x^6 */
47 int Pp[MM+1] = { 1, 1, 0, 0, 0, 0, 1 };
49 #elif(MM == 7)
50 /* 1 + x^3 + x^7 */
51 int Pp[MM+1] = { 1, 0, 0, 1, 0, 0, 0, 1 };
53 #elif(MM == 8)
54 /* 1+x^2+x^3+x^4+x^8 */
55 int Pp[MM+1] = { 1, 0, 1, 1, 1, 0, 0, 0, 1 };
57 #elif(MM == 9)
58 /* 1+x^4+x^9 */
59 int Pp[MM+1] = { 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
61 #elif(MM == 10)
62 /* 1+x^3+x^10 */
63 int Pp[MM+1] = { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 };
65 #elif(MM == 11)
66 /* 1+x^2+x^11 */
67 int Pp[MM+1] = { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
69 #elif(MM == 12)
70 /* 1+x+x^4+x^6+x^12 */
71 int Pp[MM+1] = { 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1 };
73 #elif(MM == 13)
74 /* 1+x+x^3+x^4+x^13 */
75 int Pp[MM+1] = { 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
77 #elif(MM == 14)
78 /* 1+x+x^6+x^10+x^14 */
79 int Pp[MM+1] = { 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1 };
81 #elif(MM == 15)
82 /* 1+x+x^15 */
83 int Pp[MM+1] = { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
85 #elif(MM == 16)
86 /* 1+x+x^3+x^12+x^16 */
87 int Pp[MM+1] = { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 };
89 #else
90 #error "Either CCSDS must be defined, or MM must be set in range 2-16"
91 #endif
93 #endif
95 #ifdef STANDARD_ORDER /* first byte transmitted is index of x**(KK-1) in message poly*/
96 /* definitions used in the encode routine*/
97 #define MESSAGE(i) data[KK-(i)-1]
98 #define REMAINDER(i) bb[NN-KK-(i)-1]
99 /* definitions used in the decode routine*/
100 #define RECEIVED(i) data[NN-1-(i)]
101 #define ERAS_INDEX(i) (NN-1-eras_pos[i])
102 #define INDEX_TO_POS(i) (NN-1-(i))
103 #else /* first byte transmitted is index of x**0 in message polynomial*/
104 /* definitions used in the encode routine*/
105 #define MESSAGE(i) data[i]
106 #define REMAINDER(i) bb[i]
107 /* definitions used in the decode routine*/
108 #define RECEIVED(i) data[i]
109 #define ERAS_INDEX(i) eras_pos[i]
110 #define INDEX_TO_POS(i) i
111 #endif
114 /* This defines the type used to store an element of the Galois Field
115 * used by the code. Make sure this is something larger than a char if
116 * if anything larger than GF(256) is used.
118 * Note: unsigned char will work up to GF(256) but int seems to run
119 * faster on the Pentium.
121 typedef int gf;
123 /* index->polynomial form conversion table */
124 static gf Alpha_to[NN + 1];
126 /* Polynomial->index form conversion table */
127 static gf Index_of[NN + 1];
129 /* No legal value in index form represents zero, so
130 * we need a special value for this purpose
132 #define A0 (NN)
134 /* Generator polynomial g(x) in index form */
135 static gf Gg[NN - KK + 1];
137 static int RS_init; /* Initialization flag */
139 /* Compute x % NN, where NN is 2**MM - 1,
140 * without a slow divide
142 /* static inline gf*/
143 static gf
144 modnn(int x)
146 while (x >= NN) {
147 x -= NN;
148 x = (x >> MM) + (x & NN);
150 return x;
153 #define min_(a,b) ((a) < (b) ? (a) : (b))
155 #define CLEAR(a,n) {\
156 int ci;\
157 for(ci=(n)-1;ci >=0;ci--)\
158 (a)[ci] = 0;\
161 #define COPY(a,b,n) {\
162 int ci;\
163 for(ci=(n)-1;ci >=0;ci--)\
164 (a)[ci] = (b)[ci];\
167 #define COPYDOWN(a,b,n) {\
168 int ci;\
169 for(ci=(n)-1;ci >=0;ci--)\
170 (a)[ci] = (b)[ci];\
173 static void init_rs(void);
175 #ifdef CCSDS
176 /* Conversion lookup tables from conventional alpha to Berlekamp's
177 * dual-basis representation. Used in the CCSDS version only.
178 * taltab[] -- convert conventional to dual basis
179 * tal1tab[] -- convert dual basis to conventional
181 * Note: the actual RS encoder/decoder works with the conventional basis.
182 * So data is converted from dual to conventional basis before either
183 * encoding or decoding and then converted back.
185 static unsigned char taltab[NN+1],tal1tab[NN+1];
187 static unsigned char tal[] = { 0x8d, 0xef, 0xec, 0x86, 0xfa, 0x99, 0xaf, 0x7b };
189 /* Generate conversion lookup tables between conventional alpha representation
190 * (@**7, @**6, ...@**0)
191 * and Berlekamp's dual basis representation
192 * (l0, l1, ...l7)
194 static void
195 gen_ltab(void)
197 int i,j,k;
199 for(i=0;i<256;i++){/* For each value of input */
200 taltab[i] = 0;
201 for(j=0;j<8;j++) /* for each column of matrix */
202 for(k=0;k<8;k++){ /* for each row of matrix */
203 if(i & (1<<k))
204 taltab[i] ^= tal[7-k] & (1<<j);
206 tal1tab[taltab[i]] = i;
209 #endif /* CCSDS */
211 #if PRIM != 1
212 static int Ldec;/* Decrement for aux location variable in Chien search */
214 static void
215 gen_ldec(void)
217 for(Ldec=1;(Ldec % PRIM) != 0;Ldec+= NN)
219 Ldec /= PRIM;
221 #else
222 #define Ldec 1
223 #endif
225 /* generate GF(2**m) from the irreducible polynomial p(X) in Pp[0]..Pp[m]
226 lookup tables: index->polynomial form alpha_to[] contains j=alpha**i;
227 polynomial form -> index form index_of[j=alpha**i] = i
228 alpha=2 is the primitive element of GF(2**m)
229 HARI's COMMENT: (4/13/94) alpha_to[] can be used as follows:
230 Let @ represent the primitive element commonly called "alpha" that
231 is the root of the primitive polynomial p(x). Then in GF(2^m), for any
232 0 <= i <= 2^m-2,
233 @^i = a(0) + a(1) @ + a(2) @^2 + ... + a(m-1) @^(m-1)
234 where the binary vector (a(0),a(1),a(2),...,a(m-1)) is the representation
235 of the integer "alpha_to[i]" with a(0) being the LSB and a(m-1) the MSB. Thus for
236 example the polynomial representation of @^5 would be given by the binary
237 representation of the integer "alpha_to[5]".
238 Similarily, index_of[] can be used as follows:
239 As above, let @ represent the primitive element of GF(2^m) that is
240 the root of the primitive polynomial p(x). In order to find the power
241 of @ (alpha) that has the polynomial representation
242 a(0) + a(1) @ + a(2) @^2 + ... + a(m-1) @^(m-1)
243 we consider the integer "i" whose binary representation with a(0) being LSB
244 and a(m-1) MSB is (a(0),a(1),...,a(m-1)) and locate the entry
245 "index_of[i]". Now, @^index_of[i] is that element whose polynomial
246 representation is (a(0),a(1),a(2),...,a(m-1)).
247 NOTE:
248 The element alpha_to[2^m-1] = 0 always signifying that the
249 representation of "@^infinity" = 0 is (0,0,0,...,0).
250 Similarily, the element index_of[0] = A0 always signifying
251 that the power of alpha which has the polynomial representation
252 (0,0,...,0) is "infinity".
256 static void
257 generate_gf(void)
259 register int i, mask;
261 mask = 1;
262 Alpha_to[MM] = 0;
263 for (i = 0; i < MM; i++) {
264 Alpha_to[i] = mask;
265 Index_of[Alpha_to[i]] = i;
266 /* If Pp[i] == 1 then, term @^i occurs in poly-repr of @^MM */
267 if (Pp[i] != 0)
268 Alpha_to[MM] ^= mask; /* Bit-wise EXOR operation */
269 mask <<= 1; /* single left-shift */
271 Index_of[Alpha_to[MM]] = MM;
273 * Have obtained poly-repr of @^MM. Poly-repr of @^(i+1) is given by
274 * poly-repr of @^i shifted left one-bit and accounting for any @^MM
275 * term that may occur when poly-repr of @^i is shifted.
277 mask >>= 1;
278 for (i = MM + 1; i < NN; i++) {
279 if (Alpha_to[i - 1] >= mask)
280 Alpha_to[i] = Alpha_to[MM] ^ ((Alpha_to[i - 1] ^ mask) << 1);
281 else
282 Alpha_to[i] = Alpha_to[i - 1] << 1;
283 Index_of[Alpha_to[i]] = i;
285 Index_of[0] = A0;
286 Alpha_to[NN] = 0;
290 * Obtain the generator polynomial of the TT-error correcting, length
291 * NN=(2**MM -1) Reed Solomon code from the product of (X+@**(B0+i)), i = 0,
292 * ... ,(2*TT-1)
294 * Examples:
296 * If B0 = 1, TT = 1. deg(g(x)) = 2*TT = 2.
297 * g(x) = (x+@) (x+@**2)
299 * If B0 = 0, TT = 2. deg(g(x)) = 2*TT = 4.
300 * g(x) = (x+1) (x+@) (x+@**2) (x+@**3)
302 static void
303 gen_poly(void)
305 register int i, j;
307 Gg[0] = 1;
308 for (i = 0; i < NN - KK; i++) {
309 Gg[i+1] = 1;
311 * Below multiply (Gg[0]+Gg[1]*x + ... +Gg[i]x^i) by
312 * (@**(B0+i)*PRIM + x)
314 for (j = i; j > 0; j--)
315 if (Gg[j] != 0)
316 Gg[j] = Gg[j - 1] ^ Alpha_to[modnn((Index_of[Gg[j]]) + (B0 + i) *PRIM)];
317 else
318 Gg[j] = Gg[j - 1];
319 /* Gg[0] can never be zero */
320 Gg[0] = Alpha_to[modnn(Index_of[Gg[0]] + (B0 + i) * PRIM)];
322 /* convert Gg[] to index form for quicker encoding */
323 for (i = 0; i <= NN - KK; i++)
324 Gg[i] = Index_of[Gg[i]];
329 * take the string of symbols in data[i], i=0..(k-1) and encode
330 * systematically to produce NN-KK parity symbols in bb[0]..bb[NN-KK-1] data[]
331 * is input and bb[] is output in polynomial form. Encoding is done by using
332 * a feedback shift register with appropriate connections specified by the
333 * elements of Gg[], which was generated above. Codeword is c(X) =
334 * data(X)*X**(NN-KK)+ b(X)
338 encode_rs(dtype data[KK], dtype bb[NN-KK])
340 register int i, j;
341 gf feedback;
343 #if DEBUG >= 1 && MM != 8
344 /* Check for illegal input values */
345 for(i=0;i<KK;i++)
346 if(MESSAGE(i) > NN)
347 return -1;
348 #endif
350 if(!RS_init)
351 init_rs();
353 CLEAR(bb,NN-KK);
355 #ifdef CCSDS
356 /* Convert to conventional basis */
357 for(i=0;i<KK;i++)
358 MESSAGE(i) = tal1tab[MESSAGE(i)];
359 #endif
361 for(i = KK - 1; i >= 0; i--) {
362 feedback = Index_of[MESSAGE(i) ^ REMAINDER(NN - KK - 1)];
363 if (feedback != A0) { /* feedback term is non-zero */
364 for (j = NN - KK - 1; j > 0; j--)
365 if (Gg[j] != A0)
366 REMAINDER(j) = REMAINDER(j - 1) ^ Alpha_to[modnn(Gg[j] + feedback)];
367 else
368 REMAINDER(j) = REMAINDER(j - 1);
369 REMAINDER(0) = Alpha_to[modnn(Gg[0] + feedback)];
370 } else { /* feedback term is zero. encoder becomes a
371 * single-byte shifter */
372 for (j = NN - KK - 1; j > 0; j--)
373 REMAINDER(j) = REMAINDER(j - 1);
374 REMAINDER(0) = 0;
377 #ifdef CCSDS
378 /* Convert to l-basis */
379 for(i=0;i<NN;i++)
380 MESSAGE(i) = taltab[MESSAGE(i)];
381 #endif
383 return 0;
387 * Performs ERRORS+ERASURES decoding of RS codes. If decoding is successful,
388 * writes the codeword into data[] itself. Otherwise data[] is unaltered.
390 * Return number of symbols corrected, or -1 if codeword is illegal
391 * or uncorrectable. If eras_pos is non-null, the detected error locations
392 * are written back. NOTE! This array must be at least NN-KK elements long.
394 * First "no_eras" erasures are declared by the calling program. Then, the
395 * maximum # of errors correctable is t_after_eras = floor((NN-KK-no_eras)/2).
396 * If the number of channel errors is not greater than "t_after_eras" the
397 * transmitted codeword will be recovered. Details of algorithm can be found
398 * in R. Blahut's "Theory ... of Error-Correcting Codes".
400 * Warning: the eras_pos[] array must not contain duplicate entries; decoder failure
401 * will result. The decoder *could* check for this condition, but it would involve
402 * extra time on every decoding operation.
406 eras_dec_rs(dtype data[NN], int eras_pos[NN-KK], int no_eras)
408 int deg_lambda, el, deg_omega;
409 int i, j, r,k;
410 gf u,q,tmp,num1,num2,den,discr_r;
411 gf lambda[NN-KK + 1], s[NN-KK + 1]; /* Err+Eras Locator poly
412 * and syndrome poly */
413 gf b[NN-KK + 1], t[NN-KK + 1], omega[NN-KK + 1];
414 gf root[NN-KK], reg[NN-KK + 1], loc[NN-KK];
415 int syn_error, count;
417 if(!RS_init)
418 init_rs();
420 #ifdef CCSDS
421 /* Convert to conventional basis */
422 for(i=0;i<NN;i++)
423 RECEIVED(i) = tal1tab[RECEIVED(i)];
424 #endif
426 #if DEBUG >= 1 && MM != 8
427 /* Check for illegal input values */
428 for(i=0;i<NN;i++)
429 if(RECEIVED(i) > NN)
430 return -1;
431 #endif
432 /* form the syndromes; i.e., evaluate data(x) at roots of g(x)
433 * namely @**(B0+i)*PRIM, i = 0, ... ,(NN-KK-1)
435 for(i=1;i<=NN-KK;i++){
436 s[i] = RECEIVED(0);
438 for(j=1;j<NN;j++){
439 if(RECEIVED(j) == 0)
440 continue;
441 tmp = Index_of[RECEIVED(j)];
443 /* s[i] ^= Alpha_to[modnn(tmp + (B0+i-1)*j)]; */
444 for(i=1;i<=NN-KK;i++)
445 s[i] ^= Alpha_to[modnn(tmp + (B0+i-1)*PRIM*j)];
447 /* Convert syndromes to index form, checking for nonzero condition */
448 syn_error = 0;
449 for(i=1;i<=NN-KK;i++){
450 syn_error |= s[i];
451 /*printf("syndrome %d = %x\n",i,s[i]);*/
452 s[i] = Index_of[s[i]];
455 if (!syn_error) {
456 /* if syndrome is zero, data[] is a codeword and there are no
457 * errors to correct. So return data[] unmodified
459 count = 0;
460 goto finish;
462 CLEAR(&lambda[1],NN-KK);
463 lambda[0] = 1;
465 if (no_eras > 0) {
466 /* Init lambda to be the erasure locator polynomial */
467 lambda[1] = Alpha_to[modnn(PRIM * ERAS_INDEX(0))];
468 for (i = 1; i < no_eras; i++) {
469 u = modnn(PRIM*ERAS_INDEX(i));
470 for (j = i+1; j > 0; j--) {
471 tmp = Index_of[lambda[j - 1]];
472 if(tmp != A0)
473 lambda[j] ^= Alpha_to[modnn(u + tmp)];
476 #if DEBUG >= 1
477 /* Test code that verifies the erasure locator polynomial just constructed
478 Needed only for decoder debugging. */
480 /* find roots of the erasure location polynomial */
481 for(i=1;i<=no_eras;i++)
482 reg[i] = Index_of[lambda[i]];
483 count = 0;
484 for (i = 1,k=NN-Ldec; i <= NN; i++,k = modnn(NN+k-Ldec)) {
485 q = 1;
486 for (j = 1; j <= no_eras; j++)
487 if (reg[j] != A0) {
488 reg[j] = modnn(reg[j] + j);
489 q ^= Alpha_to[reg[j]];
491 if (q != 0)
492 continue;
493 /* store root and error location number indices */
494 root[count] = i;
495 loc[count] = k;
496 count++;
498 if (count != no_eras) {
499 printf("\n lambda(x) is WRONG\n");
500 count = -1;
501 goto finish;
503 #if DEBUG >= 2
504 printf("\n Erasure positions as determined by roots of Eras Loc Poly:\n");
505 for (i = 0; i < count; i++)
506 printf("%d ", loc[i]);
507 printf("\n");
508 #endif
509 #endif
511 for(i=0;i<NN-KK+1;i++)
512 b[i] = Index_of[lambda[i]];
515 * Begin Berlekamp-Massey algorithm to determine error+erasure
516 * locator polynomial
518 r = no_eras;
519 el = no_eras;
520 while (++r <= NN-KK) { /* r is the step number */
521 /* Compute discrepancy at the r-th step in poly-form */
522 discr_r = 0;
523 for (i = 0; i < r; i++){
524 if ((lambda[i] != 0) && (s[r - i] != A0)) {
525 discr_r ^= Alpha_to[modnn(Index_of[lambda[i]] + s[r - i])];
528 discr_r = Index_of[discr_r]; /* Index form */
529 if (discr_r == A0) {
530 /* 2 lines below: B(x) <-- x*B(x) */
531 COPYDOWN(&b[1],b,NN-KK);
532 b[0] = A0;
533 } else {
534 /* 7 lines below: T(x) <-- lambda(x) - discr_r*x*b(x) */
535 t[0] = lambda[0];
536 for (i = 0 ; i < NN-KK; i++) {
537 if(b[i] != A0)
538 t[i+1] = lambda[i+1] ^ Alpha_to[modnn(discr_r + b[i])];
539 else
540 t[i+1] = lambda[i+1];
542 if (2 * el <= r + no_eras - 1) {
543 el = r + no_eras - el;
545 * 2 lines below: B(x) <-- inv(discr_r) *
546 * lambda(x)
548 for (i = 0; i <= NN-KK; i++)
549 b[i] = (lambda[i] == 0) ? A0 : modnn(Index_of[lambda[i]] - discr_r + NN);
550 } else {
551 /* 2 lines below: B(x) <-- x*B(x) */
552 COPYDOWN(&b[1],b,NN-KK);
553 b[0] = A0;
555 COPY(lambda,t,NN-KK+1);
559 /* Convert lambda to index form and compute deg(lambda(x)) */
560 deg_lambda = 0;
561 for(i=0;i<NN-KK+1;i++){
562 lambda[i] = Index_of[lambda[i]];
563 if(lambda[i] != A0)
564 deg_lambda = i;
567 * Find roots of the error+erasure locator polynomial by Chien
568 * Search
570 COPY(&reg[1],&lambda[1],NN-KK);
571 count = 0; /* Number of roots of lambda(x) */
572 for (i = 1,k=NN-Ldec; i <= NN; i++,k = modnn(NN+k-Ldec)) {
573 q = 1;
574 for (j = deg_lambda; j > 0; j--){
575 if (reg[j] != A0) {
576 reg[j] = modnn(reg[j] + j);
577 q ^= Alpha_to[reg[j]];
580 if (q != 0)
581 continue;
582 /* store root (index-form) and error location number */
583 root[count] = i;
584 loc[count] = k;
585 /* If we've already found max possible roots,
586 * abort the search to save time
588 if(++count == deg_lambda)
589 break;
591 if (deg_lambda != count) {
593 * deg(lambda) unequal to number of roots => uncorrectable
594 * error detected
596 count = -1;
597 goto finish;
600 * Compute err+eras evaluator poly omega(x) = s(x)*lambda(x) (modulo
601 * x**(NN-KK)). in index form. Also find deg(omega).
603 deg_omega = 0;
604 for (i = 0; i < NN-KK;i++){
605 tmp = 0;
606 j = (deg_lambda < i) ? deg_lambda : i;
607 for(;j >= 0; j--){
608 if ((s[i + 1 - j] != A0) && (lambda[j] != A0))
609 tmp ^= Alpha_to[modnn(s[i + 1 - j] + lambda[j])];
611 if(tmp != 0)
612 deg_omega = i;
613 omega[i] = Index_of[tmp];
615 omega[NN-KK] = A0;
618 * Compute error values in poly-form. num1 = omega(inv(X(l))), num2 =
619 * inv(X(l))**(B0-1) and den = lambda_pr(inv(X(l))) all in poly-form
621 for (j = count-1; j >=0; j--) {
622 num1 = 0;
623 for (i = deg_omega; i >= 0; i--) {
624 if (omega[i] != A0)
625 num1 ^= Alpha_to[modnn(omega[i] + i * root[j])];
627 num2 = Alpha_to[modnn(root[j] * (B0 - 1) + NN)];
628 den = 0;
630 /* lambda[i+1] for i even is the formal derivative lambda_pr of lambda[i] */
631 for (i = min_(deg_lambda,NN-KK-1) & ~1; i >= 0; i -=2) {
632 if(lambda[i+1] != A0)
633 den ^= Alpha_to[modnn(lambda[i+1] + i * root[j])];
635 if (den == 0) {
636 #if DEBUG >= 1
637 printf("\n ERROR: denominator = 0\n");
638 #endif
639 /* Convert to dual- basis */
640 count = -1;
641 goto finish;
643 /* Apply error to data */
644 if (num1 != 0) {
645 RECEIVED(loc[j]) ^= Alpha_to[modnn(Index_of[num1] + Index_of[num2] + NN - Index_of[den])];
648 finish:
649 #ifdef CCSDS
650 /* Convert to dual- basis */
651 for(i=0;i<NN;i++)
652 RECEIVED(i) = taltab[RECEIVED(i)];
653 #endif
654 if(eras_pos != NULL){
655 for(i=0;i<count;i++){
656 if(eras_pos!= NULL)
657 eras_pos[i] = INDEX_TO_POS(loc[i]);
660 return count;
662 /* Encoder/decoder initialization - call this first! */
663 static void
664 init_rs(void)
666 generate_gf();
667 gen_poly();
668 #ifdef CCSDS
669 gen_ltab();
670 #endif
671 #if PRIM != 1
672 gen_ldec();
673 #endif
674 RS_init = 1;