Mercury Modem
Mercury ARQ/Broadcast modem
Loading...
Searching...
No Matches
rs_erasure.h
Go to the documentation of this file.
1/* datalink_arq/rs_erasure.h -- systematic Reed-Solomon erasure code over GF(256)
2 *
3 * A block is K data pieces of P bytes. Pieces 0..K-1 ARE the data (systematic);
4 * pieces K..K+R-1 are repair, each a Cauchy combination of all data pieces.
5 * The code is MDS: ANY K distinct pieces of the K+R recover the block, never
6 * more -- so a receiver can say exactly how many it still needs.
7 *
8 * Limits: K >= 1 and K + R <= 256 (the Cauchy points must be distinct field
9 * elements).
10 *
11 * Copyright (C) 2026 Rhizomatica
12 * SPDX-License-Identifier: GPL-3.0-or-later
13 */
14#ifndef RS_ERASURE_H
15#define RS_ERASURE_H
16
17#include <stddef.h>
18#include <stdint.h>
19
20#define RS_MAX_PIECES 256
21
22/* Repair piece j (0-based) of a block of K data pieces, P bytes each.
23 * data[i] points to data piece i. Returns 0, or -1 if the parameters are out
24 * of range. */
25int rs_encode_repair(int K, size_t P, const uint8_t *const *data, int j, uint8_t *out);
26
27/* Recover the K data pieces from K distinct pieces.
28 * idx[r] is the piece index (0..K+R-1) of pieces[r], r = 0..K-1.
29 * On success writes data piece i to out[i] and returns 0; returns -1 on bad
30 * input (duplicate indices, out of range, singular -- which cannot happen for
31 * distinct indices of an MDS code). */
32int rs_decode(int K, size_t P, const int *idx, const uint8_t *const *pieces, uint8_t **out);
33
34#endif
int rs_decode(int K, size_t P, const int *idx, const uint8_t *const *pieces, uint8_t **out)
Definition rs_erasure.c:76
int rs_encode_repair(int K, size_t P, const uint8_t *const *data, int j, uint8_t *out)
Definition rs_erasure.c:66