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