2 * Reed-Solomon codecs, based on libfec
4 * Copyright (C) 2004 Phil Karn, KA9Q
5 * libcryptsetup modifications
6 * Copyright (C) 2017-2021 Red Hat, Inc. All rights reserved.
8 * This file is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
13 * This file is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this file; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 /* Special reserved value encoding zero in index form. */
29 #define RS_MIN(a, b) ((a) < (b) ? (a) : (b))
31 typedef unsigned char data_t;
33 /* Reed-Solomon codec control block */
35 int mm; /* Bits per symbol */
36 int nn; /* Symbols per block (= (1<<mm)-1) */
37 data_t *alpha_to;/* log lookup table */
38 data_t *index_of;/* Antilog lookup table */
39 data_t *genpoly; /* Generator polynomial */
40 int nroots; /* Number of generator roots = number of parity symbols */
41 int fcr; /* First consecutive root, index form */
42 int prim; /* Primitive element, index form */
43 int iprim; /* prim-th root of 1, index form */
44 int pad; /* Padding bytes in shortened block */
47 static inline int modnn(struct rs *rs, int x)
51 x = (x >> rs->mm) + (x & rs->nn);
56 struct rs *init_rs_char(int symsize, int gfpoly, int fcr, int prim, int nroots, int pad);
57 void free_rs_char(struct rs *rs);
59 /* General purpose RS codec, 8-bit symbols */
60 void encode_rs_char(struct rs *rs, data_t *data, data_t *parity);
61 int decode_rs_char(struct rs *rs, data_t *data);