---
name: "rsff-f9"
section: "3"
platform: "linux"
package: "ecc"
version: "1.35-1"
release: "Debian 1.1 (Buzz)"
platforms: ["linux"]
url: "https://new.carta.tech/rsff-f9"
---

# rsff-f9(3)

The 3-byte error-correcting encoder and decoder based on the Reed-Soloman (255, 249) code over the Galois Field (256).

delim $$

## NAME

rs255\_249\_encode, rs255\_249\_decode, rsencode, rsdecode - The 3-byte error-correcting encoder and decoder based on the Reed-Soloman (255, 249) code over the Galois Field (256).

## SYNOPSIS

```
#include <gf256.h>
#include <rsff-f9.h>
```

**cc ... -lecc**

**void rs255\_249\_encode (***data***,** *parity***)** **const GF256 \****data***;** **GF256 \****parity***;**

*status* **= rs255\_249\_decode (***received***)** **int** *status***;** **GF256 \****received***;**

**int rs255\_249\_number\_of\_errors (***status***)** **int** *status***;**

**rsencode (***data***,** *code***)** **unsigned char** *data***\[249\],** *code***\[255\];**

**rsdecode (***msg***,** *result***,** *num\_errs***)** **unsigned char** *msg***\[255\],** *result***\[249\];** **int \****num\_errs***;**

## DESCRIPTION

This manual page documents the GNU ecc library - the 3-byte error-correcting encoder and decoder based on the Reed-Solomon (255, 249) code over Galois Field GF($2 sup 8$).

*data* points to an array of 249 unsigned char, and *parity* points to an array of 6 unsigned char. *received* points to an array of 255 unsigned char.  See below on the relationship between *received* and *data*/*parity*. The possible values for *status* is the set of symbolic constants defined below.

The generating polynomial for the Reed-Solomon (255, 249) used in this library is

g ( x ) = ( x - 2 ) cdot ( x - 2 sup 2 ) cdot ( x - 2 sup 3 ) cdot ... cdot ( x - 2 sup 6 )

For each block of 249 bytes passed in as *data*, **rs255\_249\_encode()** computes the values of the 6 bytes in *parity* such that the polynomial defined as

c ( x ) = c sub 254 cdot x sup 254 + c sub 253 cdot x sup 253 + ... + c sub 2 cdot x sup 2 + c sub 1 cdot x + c sub 0

where

c sub 254 ... c sub 6 == data\[248\] ... data\[0\]\
 c sub 5 ... c sub 0 == parity\[5\] ... parity\[0\]

is a multiple of the generating polynomial $g ( x )$.

The bytes pointed to by *data* and *parity* may be transmitted in any manner.  At the receiver, *received* is constructed as follows

received\[0\] ... received\[248\] = d\[0\] ... d\[248\]\
 received\[249\] ... received\[254\] = p\[0\] ... p\[5\]\

where *d* and *p* are the received versions of *data* and *parity* respectively.

If 3 or less errors had occurred, **rs255\_249\_decode()** will correct all the errors, and upon return from this function, the first 249 bytes of *received* may be safely assumed to be those of *data*. Some or all of the errors may occurred in *parity*, ie the bytes from *r*\[249\] to *r*\[254\]. These errors are never corrected.

If *status* is **RS255\_249\_E4**, some irrecoverable error has occurred.  This usually means that there are 4 or more errors in the block of 255 bytes.

The simplest application is to check *status*. If it is **RS255\_249\_E4**, arrange for the retransmission of the entire block.  Otherwise, ignore the last 6 bytes of *received* and return the first 249 bytes as *data* in that block.

For applications that wish to be verbose whenever 1 to 3 errors had occurred, the returned value is **RS255\_249\_E$x$\_C $y$**, where $1 \<= x \<= 3$ and $0 \<= y \<= x$. *x* is the number of errors and *y* is the number of these errors occurring in the *data* portion.  The function **rs255\_249\_number\_of\_errors()** returns the value of $x$ when it is passed the returned value of **rs255\_249\_decode()**.

**rsencode()** and **rsdecode()** are older versions of **rs255\_249\_encode()** and **rs255\_249\_decode()** respectively.  Upon return from **rsencode()**, the value of *code* is

code\[0\] ... code\[5\] = parity\[5\] ... parity\[0\]\
 code\[6\] ... code\[254\] = data\[248\] ... data\[0\]

*code* is transmitted, and in the absence of error,

msg\[0\] ... msg\[254\] = code\[254\] ... code\[0\]

Whenever the value of *\*num\_errs* is not equal to 4, *result* can be safely be assumed to be that of *data*.

## WARNING

The 2 functions **rsencode()**and **rsdecode()** are included in the library for backward-compatibility to earlier versions of this library.  They may be removed in future releases.

## SEE ALSO

[gf256(3)](/gf256/3.md)
