Add an internal-representation no-op function.
[u/mdw/catacomb] / gfshare-mktab.c
1 /* -*-c-*-
2 *
3 * $Id: gfshare-mktab.c,v 1.3 2000/06/18 23:26:09 mdw Exp $
4 *
5 * Generate tables for %$\gf{2^8}$% multiplication
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
30 /*----- Revision history --------------------------------------------------*
31 *
32 * $Log: gfshare-mktab.c,v $
33 * Revision 1.3 2000/06/18 23:26:09 mdw
34 * Whoops. Fix a typo.
35 *
36 * Revision 1.2 2000/06/18 23:12:15 mdw
37 * Change typesetting of Galois Field names.
38 *
39 * Revision 1.1 2000/06/17 10:56:30 mdw
40 * Fast but nonstandard secret sharing system.
41 *
42 */
43
44 /*----- Header files ------------------------------------------------------*/
45
46 #include <stdio.h>
47 #include <stdlib.h>
48
49 #include <mLib/bits.h>
50
51 /*----- Magic numbers -----------------------------------------------------*/
52
53 #define MOD 0x11d
54
55 /*----- Main code ---------------------------------------------------------*/
56
57 int main(int argc, char *argv[])
58 {
59 octet log[256], alog[256];
60 unsigned x;
61 unsigned i;
62
63 x = 1;
64 for (i = 0; i < 255; i++) {
65 alog[i] = x;
66 log[x] = i;
67 x <<= 1;
68 if (x & 0x100)
69 x ^= MOD;
70 }
71 log[0] = 0;
72 alog[255] = 1;
73
74 fputs("\
75 /* -*-c-*-\n\
76 *\n\
77 * Log tables for secret sharing in %$\\gf{2^8}$% [generated]\n\
78 */\n\
79 \n\
80 #ifndef GFSHARE_TAB_H\n\
81 #define GFSHARE_TAB_H\n\
82 \n\
83 #define GFSHARE_LOG { \\\n\
84 ", stdout);
85
86 for (i = 0; i < 256; i++) {
87 printf("0x%02x", log[i]);
88 if (i == 255)
89 puts(" \\\n}\n");
90 else if (i % 8 == 7)
91 fputs(", \\\n ", stdout);
92 else
93 fputs(", ", stdout);
94 }
95
96 fputs("\
97 #define GFSHARE_EXP { \\\n\
98 ", stdout);
99
100 for (i = 0; i < 510; i++) {
101 printf("0x%02x", alog[i % 255]);
102 if (i == 509)
103 puts(" \\\n}\n");
104 else if (i % 8 == 7)
105 fputs(", \\\n ", stdout);
106 else
107 fputs(", ", stdout);
108 }
109
110 /* --- Done --- */
111
112 fputs("#endif\n", stdout);
113
114 if (fclose(stdout)) {
115 fprintf(stderr, "error writing data\n");
116 exit(EXIT_FAILURE);
117 }
118
119 return (0);
120 }
121
122 /*----- That's all, folks -------------------------------------------------*/