| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * $Id: safer-mktab.c,v 1.1 2001/04/29 17:49:54 mdw Exp $ |
| 4 | * |
| 5 | * Generate tables for SAFER |
| 6 | * |
| 7 | * (c) 2001 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: safer-mktab.c,v $ |
| 33 | * Revision 1.1 2001/04/29 17:49:54 mdw |
| 34 | * Added SAFER block cipher. |
| 35 | * |
| 36 | */ |
| 37 | |
| 38 | /*----- Header files ------------------------------------------------------*/ |
| 39 | |
| 40 | #include <stdio.h> |
| 41 | #include <stdlib.h> |
| 42 | |
| 43 | #include <mLib/bits.h> |
| 44 | |
| 45 | /*----- Main code ---------------------------------------------------------*/ |
| 46 | |
| 47 | int main(void) |
| 48 | { |
| 49 | octet s[256], si[256]; |
| 50 | unsigned x, i; |
| 51 | |
| 52 | x = 1; |
| 53 | for (i = 0; i < 256; i++) { |
| 54 | if (x < 256) { |
| 55 | s[i] = x; |
| 56 | si[x] = i; |
| 57 | } |
| 58 | x = (x * 45)%257; |
| 59 | } |
| 60 | s[128] = 0; |
| 61 | si[0] = 128; |
| 62 | |
| 63 | fputs("\ |
| 64 | /* -*-c-*-\n\ |
| 65 | *\n\ |
| 66 | * SAFER tables [generated]\n\ |
| 67 | */\n\ |
| 68 | \n\ |
| 69 | #ifndef CATACOMB_SAFER_TAB_H\n\ |
| 70 | #define CATACOMB_SAFER_TAB_H\n\ |
| 71 | \n\ |
| 72 | ", stdout); |
| 73 | |
| 74 | fputs("\ |
| 75 | /* --- S-boxes --- */\n\ |
| 76 | \n\ |
| 77 | #define SAFER_S { \\\n\ |
| 78 | ", stdout); |
| 79 | for (i = 0; i < 256; i++) { |
| 80 | printf("0x%02x", s[i]); |
| 81 | if (i == 255) |
| 82 | fputs(" \\\n}\n\n", stdout); |
| 83 | else if ((i + 1)%8 == 0) |
| 84 | fputs(", \\\n ", stdout); |
| 85 | else |
| 86 | fputs(", ", stdout); |
| 87 | } |
| 88 | |
| 89 | fputs("\ |
| 90 | #define SAFER_SI { \\\n\ |
| 91 | ", stdout); |
| 92 | for (i = 0; i < 256; i++) { |
| 93 | printf("0x%02x", si[i]); |
| 94 | if (i == 255) |
| 95 | fputs(" \\\n}\n\n", stdout); |
| 96 | else if ((i + 1)%8 == 0) |
| 97 | fputs(", \\\n ", stdout); |
| 98 | else |
| 99 | fputs(", ", stdout); |
| 100 | } |
| 101 | |
| 102 | puts("#endif"); |
| 103 | |
| 104 | if (fclose(stdout)) { |
| 105 | fprintf(stderr, "error writing data\n"); |
| 106 | exit(EXIT_FAILURE); |
| 107 | } |
| 108 | |
| 109 | return (0); |
| 110 | } |
| 111 | |
| 112 | /*----- That's all, folks -------------------------------------------------*/ |