more decompress
[wireshark-sm.git] / epan / reedsolomon.c
blob67eda403f57bd9e0b052e4dca338664fe6307d63
1 /* reedsolomon.c
3 * Reed-Solomon encoding and decoding,
4 * by Phil Karn (karn@ka9q.ampr.org) September 1996
5 * Copyright 1999 Phil Karn, KA9Q
6 * Separate CCSDS version create Dec 1998, merged into this version May 1999
8 * This file is derived from my generic RS encoder/decoder, which is
9 * in turn based on the program "new_rs_erasures.c" by Robert
10 * Morelos-Zaragoza (robert@spectra.eng.hawaii.edu) and Hari Thirumoorthy
11 * (harit@spectra.eng.hawaii.edu), Aug 1995
13 * Wireshark - Network traffic analyzer
14 * By Gerald Combs <gerald@wireshark.org>
15 * Copyright 1998 Gerald Combs
17 * SPDX-License-Identifier: GPL-2.0-or-later
20 #include "config.h"
22 #define WS_LOG_DOMAIN LOG_DOMAIN_EPAN
24 #include <stdio.h>
25 #include "reedsolomon.h"
26 #include <wsutil/wslog.h>
28 #ifdef CCSDS
29 /* CCSDS field generator polynomial: 1+x+x^2+x^7+x^8 */
30 int Pp[MM+1] = { 1, 1, 1, 0, 0, 0, 0, 1, 1 };
32 #else /* not CCSDS */
33 /* MM, KK, B0, PRIM are user-defined in rs.h */
35 /* Primitive polynomials - see Lin & Costello, Appendix A,
36 * and Lee & Messerschmitt, p. 453.
38 #if(MM == 2)/* Admittedly silly */
39 int Pp[MM+1] = { 1, 1, 1 };
41 #elif(MM == 3)
42 /* 1 + x + x^3 */
43 int Pp[MM+1] = { 1, 1, 0, 1 };
45 #elif(MM == 4)
46 /* 1 + x + x^4 */
47 int Pp[MM+1] = { 1, 1, 0, 0, 1 };
49 #elif(MM == 5)
50 /* 1 + x^2 + x^5 */
51 int Pp[MM+1] = { 1, 0, 1, 0, 0, 1 };
53 #elif(MM == 6)
54 /* 1 + x + x^6 */
55 int Pp[MM+1] = { 1, 1, 0, 0, 0, 0, 1 };
57 #elif(MM == 7)
58 /* 1 + x^3 + x^7 */
59 int Pp[MM+1] = { 1, 0, 0, 1, 0, 0, 0, 1 };
61 #elif(MM == 8)
62 /* 1+x^2+x^3+x^4+x^8 */
63 int Pp[MM+1] = { 1, 0, 1, 1, 1, 0, 0, 0, 1 };
65 #elif(MM == 9)
66 /* 1+x^4+x^9 */
67 int Pp[MM+1] = { 1, 0, 0, 0, 1, 0, 0, 0, 0, 1 };
69 #elif(MM == 10)
70 /* 1+x^3+x^10 */
71 int Pp[MM+1] = { 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 1 };
73 #elif(MM == 11)
74 /* 1+x^2+x^11 */
75 int Pp[MM+1] = { 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
77 #elif(MM == 12)
78 /* 1+x+x^4+x^6+x^12 */
79 int Pp[MM+1] = { 1, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1 };
81 #elif(MM == 13)
82 /* 1+x+x^3+x^4+x^13 */
83 int Pp[MM+1] = { 1, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
85 #elif(MM == 14)
86 /* 1+x+x^6+x^10+x^14 */
87 int Pp[MM+1] = { 1, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 0, 0, 1 };
89 #elif(MM == 15)
90 /* 1+x+x^15 */
91 int Pp[MM+1] = { 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 };
93 #elif(MM == 16)
94 /* 1+x+x^3+x^12+x^16 */
95 int Pp[MM+1] = { 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1 };
97 #else
98 #error "Either CCSDS must be defined, or MM must be set in range 2-16"
99 #endif
101 #endif
103 #ifdef STANDARD_ORDER /* first byte transmitted is index of x**(KK-1) in message poly*/
104 /* definitions used in the encode routine*/
105 #define MESSAGE(i) data[KK-(i)-1]
106 #define REMAINDER(i) bb[NN-KK-(i)-1]
107 /* definitions used in the decode routine*/
108 #define RECEIVED(i) data[NN-1-(i)]
109 #define ERAS_INDEX(i) (NN-1-eras_pos[i])
110 #define INDEX_TO_POS(i) (NN-1-(i))
111 #else /* first byte transmitted is index of x**0 in message polynomial*/
112 /* definitions used in the encode routine*/
113 #define MESSAGE(i) data[i]
114 #define REMAINDER(i) bb[i]
115 /* definitions used in the decode routine*/
116 #define RECEIVED(i) data[i]
117 #define ERAS_INDEX(i) eras_pos[i]
118 #define INDEX_TO_POS(i) i
119 #endif
122 /* This defines the type used to store an element of the Galois Field
123 * used by the code. Make sure this is something larger than a char if
124 * if anything larger than GF(256) is used.
126 * Note: unsigned char will work up to GF(256) but int seems to run
127 * faster on the Pentium.
129 typedef int gf;
131 /* index->polynomial form conversion table */
132 static gf Alpha_to[NN + 1];
134 /* Polynomial->index form conversion table */
135 static gf Index_of[NN + 1];
137 /* No legal value in index form represents zero, so
138 * we need a special value for this purpose
140 #define A0 (NN)
142 /* Generator polynomial g(x) in index form */
143 static gf Gg[NN - KK + 1];
145 static int RS_init; /* Initialization flag */
147 /* Compute x % NN, where NN is 2**MM - 1,
148 * without a slow divide
150 /* static inline gf*/
151 static gf
152 modnn(int x)
154 while (x >= NN) {
155 x -= NN;
156 x = (x >> MM) + (x & NN);
158 return x;
161 #define min_(a,b) ((a) < (b) ? (a) : (b))
163 #define CLEAR(a,n) {\
164 int ci;\
165 for(ci=(n)-1;ci >=0;ci--)\
166 (a)[ci] = 0;\
169 #define COPY(a,b,n) {\
170 int ci;\
171 for(ci=(n)-1;ci >=0;ci--)\
172 (a)[ci] = (b)[ci];\
175 #define COPYDOWN(a,b,n) {\
176 int ci;\
177 for(ci=(n)-1;ci >=0;ci--)\
178 (a)[ci] = (b)[ci];\
181 static void init_rs(void);
183 #ifdef CCSDS
184 /* Conversion lookup tables from conventional alpha to Berlekamp's
185 * dual-basis representation. Used in the CCSDS version only.
186 * taltab[] -- convert conventional to dual basis
187 * tal1tab[] -- convert dual basis to conventional
189 * Note: the actual RS encoder/decoder works with the conventional basis.
190 * So data is converted from dual to conventional basis before either
191 * encoding or decoding and then converted back.
193 static unsigned char taltab[NN+1],tal1tab[NN+1];
195 static unsigned char tal[] = { 0x8d, 0xef, 0xec, 0x86, 0xfa, 0x99, 0xaf, 0x7b };
197 /* Generate conversion lookup tables between conventional alpha representation
198 * (@**7, @**6, ...@**0)
199 * and Berlekamp's dual basis representation
200 * (l0, l1, ...l7)
202 static void
203 gen_ltab(void)
205 int i,j,k;
207 for(i=0;i<256;i++){/* For each value of input */
208 taltab[i] = 0;
209 for(j=0;j<8;j++) /* for each column of matrix */
210 for(k=0;k<8;k++){ /* for each row of matrix */
211 if(i & (1<<k))
212 taltab[i] ^= tal[7-k] & (1<<j);
214 tal1tab[taltab[i]] = i;
217 #endif /* CCSDS */
219 #if PRIM != 1
220 static int Ldec;/* Decrement for aux location variable in Chien search */
222 static void
223 gen_ldec(void)
225 for(Ldec=1;(Ldec % PRIM) != 0;Ldec+= NN)
227 Ldec /= PRIM;
229 #else
230 #define Ldec 1
231 #endif
233 /* generate GF(2**m) from the irreducible polynomial p(X) in Pp[0]..Pp[m]
234 lookup tables: index->polynomial form alpha_to[] contains j=alpha**i;
235 polynomial form -> index form index_of[j=alpha**i] = i
236 alpha=2 is the primitive element of GF(2**m)
237 HARI's COMMENT: (4/13/94) alpha_to[] can be used as follows:
238 Let @ represent the primitive element commonly called "alpha" that
239 is the root of the primitive polynomial p(x). Then in GF(2^m), for any
240 0 <= i <= 2^m-2,
241 @^i = a(0) + a(1) @ + a(2) @^2 + ... + a(m-1) @^(m-1)
242 where the binary vector (a(0),a(1),a(2),...,a(m-1)) is the representation
243 of the integer "alpha_to[i]" with a(0) being the LSB and a(m-1) the MSB. Thus for
244 example the polynomial representation of @^5 would be given by the binary
245 representation of the integer "alpha_to[5]".
246 Similarly, index_of[] can be used as follows:
247 As above, let @ represent the primitive element of GF(2^m) that is
248 the root of the primitive polynomial p(x). In order to find the power
249 of @ (alpha) that has the polynomial representation
250 a(0) + a(1) @ + a(2) @^2 + ... + a(m-1) @^(m-1)
251 we consider the integer "i" whose binary representation with a(0) being LSB
252 and a(m-1) MSB is (a(0),a(1),...,a(m-1)) and locate the entry
253 "index_of[i]". Now, @^index_of[i] is that element whose polynomial
254 representation is (a(0),a(1),a(2),...,a(m-1)).
255 NOTE:
256 The element alpha_to[2^m-1] = 0 always signifying that the
257 representation of "@^infinity" = 0 is (0,0,0,...,0).
258 Similarly, the element index_of[0] = A0 always signifying
259 that the power of alpha which has the polynomial representation
260 (0,0,...,0) is "infinity".
264 static void
265 generate_gf(void)
267 register int i, mask;
269 mask = 1;
270 Alpha_to[MM] = 0;
271 for (i = 0; i < MM; i++) {
272 Alpha_to[i] = mask;
273 Index_of[Alpha_to[i]] = i;
274 /* If Pp[i] == 1 then, term @^i occurs in poly-repr of @^MM */
275 if (Pp[i] != 0)
276 Alpha_to[MM] ^= mask; /* Bit-wise EXOR operation */
277 mask <<= 1; /* single left-shift */
279 Index_of[Alpha_to[MM]] = MM;
281 * Have obtained poly-repr of @^MM. Poly-repr of @^(i+1) is given by
282 * poly-repr of @^i shifted left one-bit and accounting for any @^MM
283 * term that may occur when poly-repr of @^i is shifted.
285 mask >>= 1;
286 for (i = MM + 1; i < NN; i++) {
287 if (Alpha_to[i - 1] >= mask)
288 Alpha_to[i] = Alpha_to[MM] ^ ((Alpha_to[i - 1] ^ mask) << 1);
289 else
290 Alpha_to[i] = Alpha_to[i - 1] << 1;
291 Index_of[Alpha_to[i]] = i;
293 Index_of[0] = A0;
294 Alpha_to[NN] = 0;
298 * Obtain the generator polynomial of the TT-error correcting, length
299 * NN=(2**MM -1) Reed Solomon code from the product of (X+@**(B0+i)), i = 0,
300 * ... ,(2*TT-1)
302 * Examples:
304 * If B0 = 1, TT = 1. deg(g(x)) = 2*TT = 2.
305 * g(x) = (x+@) (x+@**2)
307 * If B0 = 0, TT = 2. deg(g(x)) = 2*TT = 4.
308 * g(x) = (x+1) (x+@) (x+@**2) (x+@**3)
310 static void
311 gen_poly(void)
313 register int i, j;
315 Gg[0] = 1;
316 for (i = 0; i < NN - KK; i++) {
317 Gg[i+1] = 1;
319 * Below multiply (Gg[0]+Gg[1]*x + ... +Gg[i]x^i) by
320 * (@**(B0+i)*PRIM + x)
322 for (j = i; j > 0; j--)
323 if (Gg[j] != 0)
324 Gg[j] = Gg[j - 1] ^ Alpha_to[modnn((Index_of[Gg[j]]) + (B0 + i) *PRIM)];
325 else
326 Gg[j] = Gg[j - 1];
327 /* Gg[0] can never be zero */
328 Gg[0] = Alpha_to[modnn(Index_of[Gg[0]] + (B0 + i) * PRIM)];
330 /* convert Gg[] to index form for quicker encoding */
331 for (i = 0; i <= NN - KK; i++)
332 Gg[i] = Index_of[Gg[i]];
337 * take the string of symbols in data[i], i=0..(k-1) and encode
338 * systematically to produce NN-KK parity symbols in bb[0]..bb[NN-KK-1] data[]
339 * is input and bb[] is output in polynomial form. Encoding is done by using
340 * a feedback shift register with appropriate connections specified by the
341 * elements of Gg[], which was generated above. Codeword is c(X) =
342 * data(X)*X**(NN-KK)+ b(X)
346 encode_rs(dtype data[], dtype bb[])
348 register int i, j;
349 gf feedback;
351 #if DEBUG >= 1 && MM != 8
352 /* Check for illegal input values */
353 for(i=0;i<KK;i++)
354 if(MESSAGE(i) > NN)
355 return -1;
356 #endif
358 if(!RS_init)
359 init_rs();
361 CLEAR(bb,NN-KK);
363 #ifdef CCSDS
364 /* Convert to conventional basis */
365 for(i=0;i<KK;i++)
366 MESSAGE(i) = tal1tab[MESSAGE(i)];
367 #endif
369 for(i = KK - 1; i >= 0; i--) {
370 feedback = Index_of[MESSAGE(i) ^ REMAINDER(NN - KK - 1)];
371 if (feedback != A0) { /* feedback term is non-zero */
372 for (j = NN - KK - 1; j > 0; j--)
373 if (Gg[j] != A0)
374 REMAINDER(j) = REMAINDER(j - 1) ^ Alpha_to[modnn(Gg[j] + feedback)];
375 else
376 REMAINDER(j) = REMAINDER(j - 1);
377 REMAINDER(0) = Alpha_to[modnn(Gg[0] + feedback)];
378 } else { /* feedback term is zero. encoder becomes a
379 * single-byte shifter */
380 for (j = NN - KK - 1; j > 0; j--)
381 REMAINDER(j) = REMAINDER(j - 1);
382 REMAINDER(0) = 0;
385 #ifdef CCSDS
386 /* Convert to l-basis */
387 for(i=0;i<NN;i++)
388 MESSAGE(i) = taltab[MESSAGE(i)];
389 #endif
391 return 0;
395 * Performs ERRORS+ERASURES decoding of RS codes. If decoding is successful,
396 * writes the codeword into data[] itself. Otherwise data[] is unaltered.
398 * Return number of symbols corrected, or -1 if codeword is illegal
399 * or uncorrectable. If eras_pos is non-null, the detected error locations
400 * are written back. NOTE! This array must be at least NN-KK elements long.
402 * First "no_eras" erasures are declared by the calling program. Then, the
403 * maximum # of errors correctable is t_after_eras = floor((NN-KK-no_eras)/2).
404 * If the number of channel errors is not greater than "t_after_eras" the
405 * transmitted codeword will be recovered. Details of algorithm can be found
406 * in R. Blahut's "Theory ... of Error-Correcting Codes".
408 * Warning: the eras_pos[] array must not contain duplicate entries; decoder failure
409 * will result. The decoder *could* check for this condition, but it would involve
410 * extra time on every decoding operation.
414 eras_dec_rs(dtype data[], int eras_pos[], int no_eras)
416 int deg_lambda, el, deg_omega;
417 int i, j, r,k;
418 gf u,q,tmp,num1,num2,den,discr_r;
419 gf lambda[NN-KK + 1], s[NN-KK + 1]; /* Err+Eras Locator poly
420 * and syndrome poly */
421 gf b[NN-KK + 1], t[NN-KK + 1], omega[NN-KK + 1];
422 gf root[NN-KK], reg[NN-KK + 1], loc[NN-KK];
423 int syn_error, count;
425 if(!RS_init)
426 init_rs();
428 #ifdef CCSDS
429 /* Convert to conventional basis */
430 for(i=0;i<NN;i++)
431 RECEIVED(i) = tal1tab[RECEIVED(i)];
432 #endif
434 #if DEBUG >= 1 && MM != 8
435 /* Check for illegal input values */
436 for(i=0;i<NN;i++)
437 if(RECEIVED(i) > NN)
438 return -1;
439 #endif
440 /* form the syndromes; i.e., evaluate data(x) at roots of g(x)
441 * namely @**(B0+i)*PRIM, i = 0, ... ,(NN-KK-1)
443 for(i=1;i<=NN-KK;i++){
444 s[i] = RECEIVED(0);
446 for(j=1;j<NN;j++){
447 if(RECEIVED(j) == 0)
448 continue;
449 tmp = Index_of[RECEIVED(j)];
451 /* s[i] ^= Alpha_to[modnn(tmp + (B0+i-1)*j)]; */
452 for(i=1;i<=NN-KK;i++)
453 s[i] ^= Alpha_to[modnn(tmp + (B0+i-1)*PRIM*j)];
455 /* Convert syndromes to index form, checking for nonzero condition */
456 syn_error = 0;
457 for(i=1;i<=NN-KK;i++){
458 syn_error |= s[i];
459 /*ws_debug("syndrome %d = %x\n",i,s[i]);*/
460 s[i] = Index_of[s[i]];
463 if (!syn_error) {
464 /* if syndrome is zero, data[] is a codeword and there are no
465 * errors to correct. So return data[] unmodified
467 count = 0;
468 goto finish;
470 CLEAR(&lambda[1],NN-KK);
471 lambda[0] = 1;
473 if (no_eras > 0) {
474 /* Init lambda to be the erasure locator polynomial */
475 lambda[1] = Alpha_to[modnn(PRIM * ERAS_INDEX(0))];
476 for (i = 1; i < no_eras; i++) {
477 u = modnn(PRIM*ERAS_INDEX(i));
478 for (j = i+1; j > 0; j--) {
479 tmp = Index_of[lambda[j - 1]];
480 if(tmp != A0)
481 lambda[j] ^= Alpha_to[modnn(u + tmp)];
484 #if DEBUG >= 1
485 /* Test code that verifies the erasure locator polynomial just constructed
486 Needed only for decoder debugging. */
488 /* find roots of the erasure location polynomial */
489 for(i=1;i<=no_eras;i++)
490 reg[i] = Index_of[lambda[i]];
491 count = 0;
492 for (i = 1,k=NN-Ldec; i <= NN; i++,k = modnn(NN+k-Ldec)) {
493 q = 1;
494 for (j = 1; j <= no_eras; j++)
495 if (reg[j] != A0) {
496 reg[j] = modnn(reg[j] + j);
497 q ^= Alpha_to[reg[j]];
499 if (q != 0)
500 continue;
501 /* store root and error location number indices */
502 root[count] = i;
503 loc[count] = k;
504 count++;
506 if (count != no_eras) {
507 ws_debug("\n lambda(x) is WRONG\n");
508 count = -1;
509 goto finish;
511 #if DEBUG >= 2
512 printf("\n Erasure positions as determined by roots of Eras Loc Poly:\n");
513 for (i = 0; i < count; i++)
514 printf("%d ", loc[i]);
515 printf("\n");
516 #endif
517 #endif
519 for(i=0;i<NN-KK+1;i++)
520 b[i] = Index_of[lambda[i]];
523 * Begin Berlekamp-Massey algorithm to determine error+erasure
524 * locator polynomial
526 r = no_eras;
527 el = no_eras;
528 while (++r <= NN-KK) { /* r is the step number */
529 /* Compute discrepancy at the r-th step in poly-form */
530 discr_r = 0;
531 for (i = 0; i < r; i++){
532 if ((lambda[i] != 0) && (s[r - i] != A0)) {
533 discr_r ^= Alpha_to[modnn(Index_of[lambda[i]] + s[r - i])];
536 discr_r = Index_of[discr_r]; /* Index form */
537 if (discr_r == A0) {
538 /* 2 lines below: B(x) <-- x*B(x) */
539 COPYDOWN(&b[1],b,NN-KK);
540 b[0] = A0;
541 } else {
542 /* 7 lines below: T(x) <-- lambda(x) - discr_r*x*b(x) */
543 t[0] = lambda[0];
544 for (i = 0 ; i < NN-KK; i++) {
545 if(b[i] != A0)
546 t[i+1] = lambda[i+1] ^ Alpha_to[modnn(discr_r + b[i])];
547 else
548 t[i+1] = lambda[i+1];
550 if (2 * el <= r + no_eras - 1) {
551 el = r + no_eras - el;
553 * 2 lines below: B(x) <-- inv(discr_r) *
554 * lambda(x)
556 for (i = 0; i <= NN-KK; i++)
557 b[i] = (lambda[i] == 0) ? A0 : modnn(Index_of[lambda[i]] - discr_r + NN);
558 } else {
559 /* 2 lines below: B(x) <-- x*B(x) */
560 COPYDOWN(&b[1],b,NN-KK);
561 b[0] = A0;
563 COPY(lambda,t,NN-KK+1);
567 /* Convert lambda to index form and compute deg(lambda(x)) */
568 deg_lambda = 0;
569 for(i=0;i<NN-KK+1;i++){
570 lambda[i] = Index_of[lambda[i]];
571 if(lambda[i] != A0)
572 deg_lambda = i;
575 * Find roots of the error+erasure locator polynomial by Chien
576 * Search
578 COPY(&reg[1],&lambda[1],NN-KK);
579 count = 0; /* Number of roots of lambda(x) */
580 for (i = 1,k=NN-Ldec; i <= NN; i++,k = modnn(NN+k-Ldec)) {
581 q = 1;
582 for (j = deg_lambda; j > 0; j--){
583 if (reg[j] != A0) {
584 reg[j] = modnn(reg[j] + j);
585 q ^= Alpha_to[reg[j]];
588 if (q != 0)
589 continue;
590 /* store root (index-form) and error location number */
591 root[count] = i;
592 loc[count] = k;
593 /* If we've already found max possible roots,
594 * abort the search to save time
596 if(++count == deg_lambda)
597 break;
599 if (deg_lambda != count) {
601 * deg(lambda) unequal to number of roots => uncorrectable
602 * error detected
604 count = -1;
605 goto finish;
608 * Compute err+eras evaluator poly omega(x) = s(x)*lambda(x) (modulo
609 * x**(NN-KK)). in index form. Also find deg(omega).
611 deg_omega = 0;
612 for (i = 0; i < NN-KK;i++){
613 tmp = 0;
614 j = (deg_lambda < i) ? deg_lambda : i;
615 for(;j >= 0; j--){
616 if ((s[i + 1 - j] != A0) && (lambda[j] != A0))
617 tmp ^= Alpha_to[modnn(s[i + 1 - j] + lambda[j])];
619 if(tmp != 0)
620 deg_omega = i;
621 omega[i] = Index_of[tmp];
623 omega[NN-KK] = A0;
626 * Compute error values in poly-form. num1 = omega(inv(X(l))), num2 =
627 * inv(X(l))**(B0-1) and den = lambda_pr(inv(X(l))) all in poly-form
629 for (j = count-1; j >=0; j--) {
630 num1 = 0;
631 for (i = deg_omega; i >= 0; i--) {
632 if (omega[i] != A0)
633 num1 ^= Alpha_to[modnn(omega[i] + i * root[j])];
635 num2 = Alpha_to[modnn(root[j] * (B0 - 1) + NN)];
636 den = 0;
638 /* lambda[i+1] for i even is the formal derivative lambda_pr of lambda[i] */
639 for (i = min_(deg_lambda,NN-KK-1) & ~1; i >= 0; i -=2) {
640 if(lambda[i+1] != A0)
641 den ^= Alpha_to[modnn(lambda[i+1] + i * root[j])];
643 if (den == 0) {
644 #if DEBUG >= 1
645 ws_debug("\n ERROR: denominator = 0\n");
646 #endif
647 /* Convert to dual- basis */
648 count = -1;
649 goto finish;
651 /* Apply error to data */
652 if (num1 != 0) {
653 RECEIVED(loc[j]) ^= Alpha_to[modnn(Index_of[num1] + Index_of[num2] + NN - Index_of[den])];
656 finish:
657 #ifdef CCSDS
658 /* Convert to dual- basis */
659 for(i=0;i<NN;i++)
660 RECEIVED(i) = taltab[RECEIVED(i)];
661 #endif
662 if(eras_pos != NULL){
663 for(i=0;i<count;i++){
664 if(eras_pos!= NULL)
665 eras_pos[i] = INDEX_TO_POS(loc[i]);
668 return count;
670 /* Encoder/decoder initialization - call this first! */
671 static void
672 init_rs(void)
674 generate_gf();
675 gen_poly();
676 #ifdef CCSDS
677 gen_ltab();
678 #endif
679 #if PRIM != 1
680 gen_ldec();
681 #endif
682 RS_init = 1;
686 * Editor modelines - https://www.wireshark.org/tools/modelines.html
688 * Local Variables:
689 * c-basic-offset: 2
690 * tab-width: 8
691 * indent-tabs-mode: nil
692 * End:
694 * ex: set shiftwidth=2 tabstop=8 expandtab:
695 * :indentSize=2:tabSize=8:noTabs=true: