| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * Build table for squaring of binary polynomials |
| 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 | /*----- Main code ---------------------------------------------------------*/ |
| 36 | |
| 37 | static void mktab(uint16 *t) |
| 38 | { |
| 39 | unsigned i, j, x; |
| 40 | |
| 41 | for (i = 0; i < 256; i++) { |
| 42 | x = 0; |
| 43 | for (j = 0; j < 8; j++) { |
| 44 | if (i & (1 << j)) |
| 45 | x |= 1 << (2 * j); |
| 46 | } |
| 47 | t[i] = x; |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | int main(void) |
| 52 | { |
| 53 | uint16 t[256]; |
| 54 | unsigned i; |
| 55 | |
| 56 | mktab(t); |
| 57 | fputs("\ |
| 58 | /* -*-c-*-\n\ |
| 59 | *\n\ |
| 60 | * Bit spacing table for binary polynomial squaring\n\ |
| 61 | */\n\ |
| 62 | \n\ |
| 63 | #include <mLib/bits.h>\n\ |
| 64 | \n\ |
| 65 | const uint16 gfx_sqrtab[256] = {\n\ |
| 66 | ", stdout); |
| 67 | |
| 68 | for (i = 0; i < 256; i++) { |
| 69 | printf("0x%04x", t[i]); |
| 70 | if (i == 255) |
| 71 | puts("\n};"); |
| 72 | else if (i % 8 == 7) |
| 73 | fputs(",\n ", stdout); |
| 74 | else |
| 75 | fputs(", ", stdout); |
| 76 | } |
| 77 | |
| 78 | if (fclose(stdout)) { |
| 79 | fprintf(stderr, "error writing data\n"); |
| 80 | exit(EXIT_FAILURE); |
| 81 | } |
| 82 | |
| 83 | return (0); |
| 84 | } |
| 85 | |
| 86 | /*----- That's all, folks -------------------------------------------------*/ |