X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/35682d2fa436ace2d7706fd6dcd852b497079860..18b3351a3791f19a63c0af05640719db8eb5d184:/square-mktab.c diff --git a/square-mktab.c b/square-mktab.c index 5c2610e..f1c7f02 100644 --- a/square-mktab.c +++ b/square-mktab.c @@ -1,13 +1,13 @@ /* -*-c-*- * - * $Id: square-mktab.c,v 1.1 2000/07/27 18:10:27 mdw Exp $ + * $Id: square-mktab.c,v 1.3 2004/04/08 01:36:15 mdw Exp $ * * Build precomputed tables for the Square block cipher * * (c) 2000 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Catacomb. * @@ -15,26 +15,18 @@ * 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: square-mktab.c,v $ - * Revision 1.1 2000/07/27 18:10:27 mdw - * Build precomuted tables for Square. - * - */ - /*----- Header files ------------------------------------------------------*/ #include @@ -84,15 +76,15 @@ static unsigned mul(unsigned x, unsigned y, unsigned m) * Build the S-box. * * This is built from inversion in the multiplicative group of - * %$\gf{2^8}[x]/(p(x))$%, where %$p(x) = x^8 + x^4 + x^3 + x + 1$%, followed - * by an affine transformation treating inputs as vectors over %$\gf{2}$%. - * The result is a horrible function. + * %$\gf{2^8}[x]/(p(x))$%, where %$p(x) = x^8+x^7+x^6+x^5+x^4+x^2+1$%, + * followed by an affine transformation treating inputs as vectors over + * %$\gf{2}$%. The result is a horrible function. * * The inversion is done slightly sneakily, by building log and antilog * tables. Let %$a$% be an element of the finite field. If the inverse of * %$a$% is %$a^{-1}$%, then %$\log a a^{-1} = 0$%. Hence * %$\log a = -\log a^{-1}$%. This saves fiddling about with Euclidean - * algorithm. + * algorithm. */ #define S_MOD 0x1f5 @@ -292,11 +284,11 @@ int main(void) \\\n\ { ", stdout); } else if (i % 4 == 3) - fputs(", \\\n ", stdout); + fputs(", \\\n ", stdout); else fputs(", ", stdout); } - } + } fputs("\ #define SQUARE_TI { \\\n\ @@ -312,7 +304,7 @@ int main(void) \\\n\ { ", stdout); } else if (i % 4 == 3) - fputs(", \\\n ", stdout); + fputs(", \\\n ", stdout); else fputs(", ", stdout); } @@ -337,11 +329,11 @@ int main(void) \\\n\ { ", stdout); } else if (i % 4 == 3) - fputs(", \\\n ", stdout); + fputs(", \\\n ", stdout); else fputs(", ", stdout); } - } + } /* --- Round constants --- */ @@ -359,7 +351,7 @@ int main(void) fputs(", \\\n ", stdout); else fputs(", ", stdout); - } + } /* --- Done --- */