"Fossies" - the Fresh Open Source Software Archive

Member "cryptsetup-2.4.3/lib/verity/rs.h" (13 Jan 2022, 2133 Bytes) of package /linux/misc/cryptsetup-2.4.3.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "rs.h" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * Reed-Solomon codecs, based on libfec
    3  *
    4  * Copyright (C) 2004 Phil Karn, KA9Q
    5  * libcryptsetup modifications
    6  *   Copyright (C) 2017-2021 Red Hat, Inc. All rights reserved.
    7  *
    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.
   12  *
   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.
   17  *
   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.
   21  */
   22 
   23 #ifndef _LIBFEC_RS_H
   24 #define _LIBFEC_RS_H
   25 
   26 /* Special reserved value encoding zero in index form. */
   27 #define A0 (rs->nn)
   28 
   29 #define RS_MIN(a, b) ((a) < (b) ? (a) : (b))
   30 
   31 typedef unsigned char data_t;
   32 
   33 /* Reed-Solomon codec control block */
   34 struct rs {
   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 */
   45 };
   46 
   47 static inline int modnn(struct rs *rs, int x)
   48 {
   49     while (x >= rs->nn) {
   50         x -= rs->nn;
   51         x = (x >> rs->mm) + (x & rs->nn);
   52     }
   53     return x;
   54 }
   55 
   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);
   58 
   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);
   62 
   63 #endif