/src/cryptsetup/lib/verity/rs.h
Line | Count | Source |
1 | | // SPDX-License-Identifier: LGPL-2.1-or-later |
2 | | /* |
3 | | * Reed-Solomon codecs, based on libfec |
4 | | * |
5 | | * Copyright (C) 2004 Phil Karn, KA9Q |
6 | | * libcryptsetup modifications |
7 | | * Copyright (C) 2017-2025 Red Hat, Inc. All rights reserved. |
8 | | */ |
9 | | |
10 | | #ifndef _LIBFEC_RS_H |
11 | | #define _LIBFEC_RS_H |
12 | | |
13 | | /* Special reserved value encoding zero in index form. */ |
14 | 0 | #define A0 (rs->nn) |
15 | | |
16 | 0 | #define RS_MIN(a, b) ((a) < (b) ? (a) : (b)) |
17 | | |
18 | | typedef unsigned char data_t; |
19 | | |
20 | | /* Reed-Solomon codec control block */ |
21 | | struct rs { |
22 | | int mm; /* Bits per symbol */ |
23 | | int nn; /* Symbols per block (= (1<<mm)-1) */ |
24 | | data_t *alpha_to;/* log lookup table */ |
25 | | data_t *index_of;/* Antilog lookup table */ |
26 | | data_t *genpoly; /* Generator polynomial */ |
27 | | int nroots; /* Number of generator roots = number of parity symbols */ |
28 | | int fcr; /* First consecutive root, index form */ |
29 | | int prim; /* Primitive element, index form */ |
30 | | int iprim; /* prim-th root of 1, index form */ |
31 | | int pad; /* Padding bytes in shortened block */ |
32 | | }; |
33 | | |
34 | | static inline int modnn(struct rs *rs, int x) |
35 | 0 | { |
36 | 0 | while (x >= rs->nn) { |
37 | 0 | x -= rs->nn; |
38 | 0 | x = (x >> rs->mm) + (x & rs->nn); |
39 | 0 | } |
40 | 0 | return x; |
41 | 0 | } Unexecuted instantiation: verity_fec.c:modnn Unexecuted instantiation: rs_encode_char.c:modnn Unexecuted instantiation: rs_decode_char.c:modnn |
42 | | |
43 | | struct rs *init_rs_char(int symsize, int gfpoly, int fcr, int prim, int nroots, int pad); |
44 | | void free_rs_char(struct rs *rs); |
45 | | |
46 | | /* General purpose RS codec, 8-bit symbols */ |
47 | | void encode_rs_char(struct rs *rs, data_t *data, data_t *parity); |
48 | | int decode_rs_char(struct rs *rs, data_t *data); |
49 | | |
50 | | #endif |