6c1035f5 |
1 | /* -*-c-*- |
6c1035f5 |
2 | * |
4d47e157 |
3 | * Generate tables for %$\gf{2^8}$% multiplication |
6c1035f5 |
4 | * |
5 | * (c) 2000 Straylight/Edgeware |
6 | */ |
7 | |
45c0fd36 |
8 | /*----- Licensing notice --------------------------------------------------* |
6c1035f5 |
9 | * |
10 | * This file is part of Catacomb. |
11 | * |
12 | * Catacomb is free software; you can redistribute it and/or modify |
13 | * it under the terms of the GNU Library General Public License as |
14 | * published by the Free Software Foundation; either version 2 of the |
15 | * License, or (at your option) any later version. |
45c0fd36 |
16 | * |
6c1035f5 |
17 | * Catacomb is distributed in the hope that it will be useful, |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 | * GNU Library General Public License for more details. |
45c0fd36 |
21 | * |
6c1035f5 |
22 | * You should have received a copy of the GNU Library General Public |
23 | * License along with Catacomb; if not, write to the Free |
24 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
25 | * MA 02111-1307, USA. |
26 | */ |
27 | |
6c1035f5 |
28 | /*----- Header files ------------------------------------------------------*/ |
29 | |
30 | #include <stdio.h> |
31 | #include <stdlib.h> |
32 | |
33 | #include <mLib/bits.h> |
34 | |
35 | /*----- Magic numbers -----------------------------------------------------*/ |
36 | |
37 | #define MOD 0x11d |
38 | |
39 | /*----- Main code ---------------------------------------------------------*/ |
40 | |
41 | int main(int argc, char *argv[]) |
42 | { |
43 | octet log[256], alog[256]; |
44 | unsigned x; |
45 | unsigned i; |
46 | |
47 | x = 1; |
48 | for (i = 0; i < 255; i++) { |
49 | alog[i] = x; |
50 | log[x] = i; |
51 | x <<= 1; |
52 | if (x & 0x100) |
53 | x ^= MOD; |
54 | } |
55 | log[0] = 0; |
56 | alog[255] = 1; |
57 | |
58 | fputs("\ |
59 | /* -*-c-*-\n\ |
60 | *\n\ |
110c1845 |
61 | * Log tables for secret sharing in %$\\gf{2^8}$% [generated]\n\ |
6c1035f5 |
62 | */\n\ |
63 | \n\ |
e5b61a8d |
64 | #include <mLib/bits.h>\n\ |
6c1035f5 |
65 | \n\ |
e5b61a8d |
66 | const octet gfshare_log[256] = {\n\ |
6c1035f5 |
67 | ", stdout); |
68 | |
69 | for (i = 0; i < 256; i++) { |
70 | printf("0x%02x", log[i]); |
71 | if (i == 255) |
e5b61a8d |
72 | puts("\n};\n"); |
6c1035f5 |
73 | else if (i % 8 == 7) |
e5b61a8d |
74 | fputs(",\n ", stdout); |
6c1035f5 |
75 | else |
76 | fputs(", ", stdout); |
77 | } |
78 | |
79 | fputs("\ |
e5b61a8d |
80 | const octet gfshare_exp[510] = {\n\ |
6c1035f5 |
81 | ", stdout); |
82 | |
83 | for (i = 0; i < 510; i++) { |
84 | printf("0x%02x", alog[i % 255]); |
85 | if (i == 509) |
e5b61a8d |
86 | puts("\n};"); |
6c1035f5 |
87 | else if (i % 8 == 7) |
e5b61a8d |
88 | fputs(",\n ", stdout); |
6c1035f5 |
89 | else |
90 | fputs(", ", stdout); |
91 | } |
92 | |
93 | /* --- Done --- */ |
94 | |
6c1035f5 |
95 | if (fclose(stdout)) { |
96 | fprintf(stderr, "error writing data\n"); |
97 | exit(EXIT_FAILURE); |
98 | } |
99 | |
45c0fd36 |
100 | return (0); |
6c1035f5 |
101 | } |
102 | |
103 | /*----- That's all, folks -------------------------------------------------*/ |