| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * Generate tables for %$\gf{2^8}$% multiplication |
| 4 | * |
| 5 | * (c) 2000 Straylight/Edgeware |
| 6 | */ |
| 7 | |
| 8 | /*----- Licensing notice --------------------------------------------------* |
| 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. |
| 16 | * |
| 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. |
| 21 | * |
| 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 | |
| 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\ |
| 61 | * Log tables for secret sharing in %$\\gf{2^8}$% [generated]\n\ |
| 62 | */\n\ |
| 63 | \n\ |
| 64 | #include <mLib/bits.h>\n\ |
| 65 | \n\ |
| 66 | const octet gfshare_log[256] = {\n\ |
| 67 | ", stdout); |
| 68 | |
| 69 | for (i = 0; i < 256; i++) { |
| 70 | printf("0x%02x", log[i]); |
| 71 | if (i == 255) |
| 72 | puts("\n};\n"); |
| 73 | else if (i % 8 == 7) |
| 74 | fputs(",\n ", stdout); |
| 75 | else |
| 76 | fputs(", ", stdout); |
| 77 | } |
| 78 | |
| 79 | fputs("\ |
| 80 | const octet gfshare_exp[510] = {\n\ |
| 81 | ", stdout); |
| 82 | |
| 83 | for (i = 0; i < 510; i++) { |
| 84 | printf("0x%02x", alog[i % 255]); |
| 85 | if (i == 509) |
| 86 | puts("\n};"); |
| 87 | else if (i % 8 == 7) |
| 88 | fputs(",\n ", stdout); |
| 89 | else |
| 90 | fputs(", ", stdout); |
| 91 | } |
| 92 | |
| 93 | /* --- Done --- */ |
| 94 | |
| 95 | if (fclose(stdout)) { |
| 96 | fprintf(stderr, "error writing data\n"); |
| 97 | exit(EXIT_FAILURE); |
| 98 | } |
| 99 | |
| 100 | return (0); |
| 101 | } |
| 102 | |
| 103 | /*----- That's all, folks -------------------------------------------------*/ |