From 13aebbbf61c6e855a3209d7e2dca927afebe3457 Mon Sep 17 00:00:00 2001 From: mdw Date: Sun, 29 Apr 2001 17:49:54 +0000 Subject: [PATCH] Added SAFER block cipher. --- safer-mktab.c | 112 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 safer-mktab.c diff --git a/safer-mktab.c b/safer-mktab.c new file mode 100644 index 0000000..783ef14 --- /dev/null +++ b/safer-mktab.c @@ -0,0 +1,112 @@ +/* -*-c-*- + * + * $Id: safer-mktab.c,v 1.1 2001/04/29 17:49:54 mdw Exp $ + * + * Generate tables for SAFER + * + * (c) 2001 Straylight/Edgeware + */ + +/*----- Licensing notice --------------------------------------------------* + * + * This file is part of Catacomb. + * + * Catacomb is free software; you can redistribute it and/or modify + * it under the terms of the GNU Library General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * Catacomb is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Library General Public License for more details. + * + * You should have received a copy of the GNU Library General Public + * License along with Catacomb; if not, write to the Free + * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, + * MA 02111-1307, USA. + */ + +/*----- Revision history --------------------------------------------------* + * + * $Log: safer-mktab.c,v $ + * Revision 1.1 2001/04/29 17:49:54 mdw + * Added SAFER block cipher. + * + */ + +/*----- Header files ------------------------------------------------------*/ + +#include +#include + +#include + +/*----- Main code ---------------------------------------------------------*/ + +int main(void) +{ + octet s[256], si[256]; + unsigned x, i; + + x = 1; + for (i = 0; i < 256; i++) { + if (x < 256) { + s[i] = x; + si[x] = i; + } + x = (x * 45)%257; + } + s[128] = 0; + si[0] = 128; + + fputs("\ +/* -*-c-*-\n\ + *\n\ + * SAFER tables [generated]\n\ + */\n\ +\n\ +#ifndef CATACOMB_SAFER_TAB_H\n\ +#define CATACOMB_SAFER_TAB_H\n\ +\n\ +", stdout); + + fputs("\ +/* --- S-boxes --- */\n\ +\n\ +#define SAFER_S { \\\n\ + ", stdout); + for (i = 0; i < 256; i++) { + printf("0x%02x", s[i]); + if (i == 255) + fputs(" \\\n}\n\n", stdout); + else if ((i + 1)%8 == 0) + fputs(", \\\n ", stdout); + else + fputs(", ", stdout); + } + + fputs("\ +#define SAFER_SI { \\\n\ + ", stdout); + for (i = 0; i < 256; i++) { + printf("0x%02x", si[i]); + if (i == 255) + fputs(" \\\n}\n\n", stdout); + else if ((i + 1)%8 == 0) + fputs(", \\\n ", stdout); + else + fputs(", ", stdout); + } + + puts("#endif"); + + if (fclose(stdout)) { + fprintf(stderr, "error writing data\n"); + exit(EXIT_FAILURE); + } + + return (0); +} + +/*----- That's all, folks -------------------------------------------------*/ -- 2.11.0