hashsum.1: Fix counting error (left over from some previous edit).
[u/mdw/catacomb] / twofish.c
index 566ee1e..ad4882f 100644 (file)
--- a/twofish.c
+++ b/twofish.c
@@ -1,13 +1,13 @@
 /* -*-c-*-
  *
- * $Id: twofish.c,v 1.3 2002/01/13 13:37:59 mdw Exp $
+ * $Id: twofish.c,v 1.5 2004/04/08 01:36:15 mdw Exp $
  *
  * Implementation of the Twofish cipher
  *
  * (c) 2000 Straylight/Edgeware
  */
 
-/*----- Licensing notice --------------------------------------------------* 
+/*----- Licensing notice --------------------------------------------------*
  *
  * This file is part of Catacomb.
  *
  * 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: twofish.c,v $
- * Revision 1.3  2002/01/13 13:37:59  mdw
- * Add support for Twofish family keys.
- *
- * Revision 1.2  2000/06/22 18:58:00  mdw
- * Twofish can handle keys with any byte-aligned size.
- *
- * Revision 1.1  2000/06/17 12:10:17  mdw
- * New cipher.
- *
- */
-
 /*----- Header files ------------------------------------------------------*/
 
 #include <assert.h>
@@ -82,8 +68,8 @@ static uint32 h(uint32 x, const uint32 *l, unsigned k)
   /* --- Apply a series of @q@ tables to an integer --- */
 
 # define Q(x, qa, qb, qc, qd)                                          \
-  ((qa[((x) >>  0) & 0xff] <<  0) |                                    \
-   (qb[((x) >>  8) & 0xff] <<  8) |                                    \
+  ((qa[((x) >> 0) & 0xff] <<  0) |                                     \
+   (qb[((x) >> 8) & 0xff] <<  8) |                                     \
    (qc[((x) >> 16) & 0xff] << 16) |                                    \
    (qd[((x) >> 24) & 0xff] << 24))
 
@@ -192,7 +178,7 @@ void twofish_initfk(twofish_ctx *k, const void *buf, size_t sz,
          qq++;
          r++;
        }
-       
+
        s[j][sz - 1 - i] = ss[j] = a;
       }
       q += 8;
@@ -286,7 +272,7 @@ void twofish_initfk(twofish_ctx *k, const void *buf, size_t sz,
 
 void twofish_init(twofish_ctx *k, const void *buf, size_t sz)
 {
-  static twofish_fk fk = { { 0 } };
+  static const twofish_fk fk = { { 0 } };
   twofish_initfk(k, buf, sz, &fk);
 }
 
@@ -335,12 +321,12 @@ void twofish_fkinit(twofish_fk *fk, const void *buf, size_t sz)
 /* --- Feistel function --- */
 
 #define GG(k, t0, t1, x, y, kk) do {                                   \
-  t0 = (k->g[0][U8(x >>  0)] ^                                         \
-       k->g[1][U8(x >>  8)] ^                                          \
+  t0 = (k->g[0][U8(x >>         0)] ^                                          \
+       k->g[1][U8(x >>  8)] ^                                          \
        k->g[2][U8(x >> 16)] ^                                          \
        k->g[3][U8(x >> 24)]);                                          \
-  t1 = (k->g[1][U8(y >>  0)] ^                                         \
-       k->g[2][U8(y >>  8)] ^                                          \
+  t1 = (k->g[1][U8(y >>         0)] ^                                          \
+       k->g[2][U8(y >>  8)] ^                                          \
        k->g[3][U8(y >> 16)] ^                                          \
        k->g[0][U8(y >> 24)]);                                          \
   t0 += t1;                                                            \