mirror of
https://github.com/amadvance/snapraid.git
synced 2026-10-26 19:01:57 -04:00
Adds table generation for reference.
This commit is contained in:
parent
7060ca8981
commit
ff4f080282
3 changed files with 128 additions and 4 deletions
|
|
@ -1,5 +1,6 @@
|
|||
bin_PROGRAMS = snapraid
|
||||
check_PROGRAMS = mktest
|
||||
EXTRA_PROGRAMS = mktables
|
||||
|
||||
snapraid_SOURCES = \
|
||||
snapraid.c \
|
||||
|
|
@ -26,6 +27,9 @@ snapraid_SOURCES = \
|
|||
mingw.c \
|
||||
unix.c
|
||||
|
||||
mktables_SOURCES = \
|
||||
mktables.c
|
||||
|
||||
noinst_HEADERS = \
|
||||
portable.h \
|
||||
snapraid.h \
|
||||
|
|
|
|||
122
mktables.c
Normal file
122
mktables.c
Normal file
|
|
@ -0,0 +1,122 @@
|
|||
/*
|
||||
* Copyright (C) 2011 Andrea Mazzoleni
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
unsigned char gfmul(unsigned char a, unsigned char b)
|
||||
{
|
||||
unsigned char v;
|
||||
|
||||
v = 0;
|
||||
while (b) {
|
||||
if ((b & 1) != 0)
|
||||
v ^= a;
|
||||
|
||||
if ((a & 0x80) != 0) {
|
||||
a <<= 1;
|
||||
a ^= 0x1d;
|
||||
} else {
|
||||
a <<= 1;
|
||||
}
|
||||
|
||||
b >>= 1;
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
unsigned char pow2[256];
|
||||
unsigned char log2[256];
|
||||
unsigned char v;
|
||||
int i, j;
|
||||
|
||||
/* a*b */
|
||||
printf("const unsigned char __attribute__((aligned(256))) gfmul[256][256] =\n");
|
||||
printf("{\n");
|
||||
for(i=0;i<256;++i) {
|
||||
printf("\t{\n");
|
||||
for(j=0;j<256;++j) {
|
||||
if (j % 8 == 0)
|
||||
printf("\t\t");
|
||||
printf("0x%02x,", gfmul(i, j));
|
||||
if (j % 8 == 7)
|
||||
printf("\n");
|
||||
else
|
||||
printf(" ");
|
||||
}
|
||||
printf("\t},\n");
|
||||
}
|
||||
printf("};\n\n");
|
||||
|
||||
/* 2^a */
|
||||
printf("const unsigned char __attribute__((aligned(256))) gfexp2[256] =\n");
|
||||
printf("{\n");
|
||||
v = 1;
|
||||
for(i=0;i<256;++i) {
|
||||
if (i % 8 == 0)
|
||||
printf("\t");
|
||||
pow2[i] = v;
|
||||
log2[pow2[i]] = i;
|
||||
printf("0x%02x,", v);
|
||||
v = gfmul(v, 2);
|
||||
if (i % 8 == 7)
|
||||
printf("\n");
|
||||
else
|
||||
printf(" ");
|
||||
}
|
||||
printf("};\n\n");
|
||||
|
||||
/* 4^a */
|
||||
printf("const unsigned char __attribute__((aligned(256))) gfexp4[256] =\n");
|
||||
printf("{\n");
|
||||
v = 1;
|
||||
for(i=0;i<256;++i) {
|
||||
if (i % 8 == 0)
|
||||
printf("\t");
|
||||
printf("0x%02x,", v);
|
||||
v = gfmul(v, 4);
|
||||
if (i % 8 == 7)
|
||||
printf("\n");
|
||||
else
|
||||
printf(" ");
|
||||
}
|
||||
printf("};\n\n");
|
||||
|
||||
/* 1/a */
|
||||
printf("const unsigned char __attribute__((aligned(256))) gfinv[256] =\n");
|
||||
printf("{\n");
|
||||
printf("\t/* note that the first element is not significative */\n");
|
||||
for(i=0;i<256;++i) {
|
||||
if (i % 8 == 0)
|
||||
printf("\t");
|
||||
if (i == 0)
|
||||
v = 0;
|
||||
else
|
||||
v = pow2[255 - log2[i]];
|
||||
printf("0x%02x,", v);
|
||||
if (i % 8 == 7)
|
||||
printf("\n");
|
||||
else
|
||||
printf(" ");
|
||||
}
|
||||
printf("};\n\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
6
tables.h
6
tables.h
|
|
@ -8756,8 +8756,7 @@ const unsigned char __attribute__((aligned(256))) gfexp2[256] =
|
|||
0x12, 0x24, 0x48, 0x90, 0x3d, 0x7a, 0xf4, 0xf5,
|
||||
0xf7, 0xf3, 0xfb, 0xeb, 0xcb, 0x8b, 0x0b, 0x16,
|
||||
0x2c, 0x58, 0xb0, 0x7d, 0xfa, 0xe9, 0xcf, 0x83,
|
||||
0x1b, 0x36, 0x6c, 0xd8, 0xad, 0x47, 0x8e, 0x00,
|
||||
/* note that the last element is not significative */
|
||||
0x1b, 0x36, 0x6c, 0xd8, 0xad, 0x47, 0x8e, 0x01,
|
||||
};
|
||||
|
||||
const unsigned char __attribute__((aligned(256))) gfexp4[256] =
|
||||
|
|
@ -8793,8 +8792,7 @@ const unsigned char __attribute__((aligned(256))) gfexp4[256] =
|
|||
0x19, 0x64, 0x8d, 0x0e, 0x38, 0xe0, 0xa7, 0xa6,
|
||||
0xa2, 0xb2, 0xf2, 0xef, 0x9b, 0x56, 0x45, 0x09,
|
||||
0x24, 0x90, 0x7a, 0xf5, 0xf3, 0xeb, 0x8b, 0x16,
|
||||
0x58, 0x7d, 0xe9, 0x83, 0x36, 0xd8, 0x47, 0x00,
|
||||
/* note that the last element is not significative */
|
||||
0x58, 0x7d, 0xe9, 0x83, 0x36, 0xd8, 0x47, 0x01,
|
||||
};
|
||||
|
||||
const unsigned char __attribute__((aligned(256))) gfinv[256] =
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue