6c1035f5 |
1 | /* -*-c-*- |
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\ |
64 | #ifndef GFSHARE_TAB_H\n\ |
65 | #define GFSHARE_TAB_H\n\ |
66 | \n\ |
67 | #define GFSHARE_LOG { \\\n\ |
68 | ", stdout); |
69 | |
70 | for (i = 0; i < 256; i++) { |
71 | printf("0x%02x", log[i]); |
72 | if (i == 255) |
73 | puts(" \\\n}\n"); |
74 | else if (i % 8 == 7) |
75 | fputs(", \\\n ", stdout); |
76 | else |
77 | fputs(", ", stdout); |
78 | } |
79 | |
80 | fputs("\ |
81 | #define GFSHARE_EXP { \\\n\ |
82 | ", stdout); |
83 | |
84 | for (i = 0; i < 510; i++) { |
85 | printf("0x%02x", alog[i % 255]); |
86 | if (i == 509) |
87 | puts(" \\\n}\n"); |
88 | else if (i % 8 == 7) |
89 | fputs(", \\\n ", stdout); |
90 | else |
91 | fputs(", ", stdout); |
92 | } |
93 | |
94 | /* --- Done --- */ |
95 | |
96 | fputs("#endif\n", stdout); |
97 | |
98 | if (fclose(stdout)) { |
99 | fprintf(stderr, "error writing data\n"); |
100 | exit(EXIT_FAILURE); |
101 | } |
102 | |
45c0fd36 |
103 | return (0); |
6c1035f5 |
104 | } |
105 | |
106 | /*----- That's all, folks -------------------------------------------------*/ |