Catcrypt tools: Roll out progress indicator stuff from hashsum.
[u/mdw/catacomb] / square.c
index c0b2d76..6ed8d86 100644 (file)
--- a/square.c
+++ b/square.c
@@ -1,13 +1,13 @@
 /* -*-c-*-
  *
- * $Id: square.c,v 1.2 2001/05/07 15:44:02 mdw Exp $
+ * $Id: square.c,v 1.3 2004/04/08 01:36:15 mdw Exp $
  *
  * The Square block 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: square.c,v $
- * Revision 1.2  2001/05/07 15:44:02  mdw
- * Simplify implementation.
- *
- * Revision 1.1  2000/07/15 20:51:58  mdw
- * New block cipher.
- *
- */
-
 /*----- Header files ------------------------------------------------------*/
 
 #include <assert.h>
@@ -118,7 +107,7 @@ void square_init(square_ctx *k, const void *buf, size_t sz)
 
   for (i = 0; i < nr * 4; i++) {
     uint32 w = kk[i];
-    k->w[i] = (U[0][U8(w >>  0)] ^ U[1][U8(w >>  8)] ^
+    k->w[i] = (U[0][U8(w >>  0)] ^ U[1][U8(w >>         8)] ^
               U[2][U8(w >> 16)] ^ U[3][U8(w >> 24)]);
   }
   for (; i < nw; i++)
@@ -148,7 +137,7 @@ void square_init(square_ctx *k, const void *buf, size_t sz)
  */
 
 #define SUB(s, sh, a, b, c, d)                                         \
-  (s[U8((a) >> sh)] <<  0 | s[U8((b) >> sh)] <<  8 |                   \
+  (s[U8((a) >> sh)] << 0 | s[U8((b) >> sh)] <<  8 |                    \
    s[U8((c) >> sh)] << 16 | s[U8((d) >> sh)] << 24)
 
 #define MIX(t, sh, a, b, c, d)                                         \
@@ -156,8 +145,8 @@ void square_init(square_ctx *k, const void *buf, size_t sz)
    t[2][U8((c) >> sh)] ^ t[3][U8((d) >> sh)])
 
 #define DO(what, t, aa, bb, cc, dd, a, b, c, d, w) do {                        \
-  aa = what(t,  0, a, b, c, d) ^ *w++;                                 \
-  bb = what(t,  8, a, b, c, d) ^ *w++;                                 \
+  aa = what(t, 0, a, b, c, d) ^ *w++;                                  \
+  bb = what(t, 8, a, b, c, d) ^ *w++;                                  \
   cc = what(t, 16, a, b, c, d) ^ *w++;                                 \
   dd = what(t, 24, a, b, c, d) ^ *w++;                                 \
 } while (0)
@@ -166,7 +155,7 @@ void square_eblk(const square_ctx *k, const uint32 *s, uint32 *dst)
 {
   uint32 a = s[0], b = s[1], c = s[2], d = s[3];
   uint32 aa, bb, cc, dd;
-  uint32 *w = k->w;
+  const uint32 *w = k->w;
 
   a ^= *w++; b ^= *w++; c ^= *w++; d ^= *w++;
 
@@ -186,7 +175,7 @@ void square_dblk(const square_ctx *k, const uint32 *s, uint32 *dst)
 {
   uint32 a = s[0], b = s[1], c = s[2], d = s[3];
   uint32 aa, bb, cc, dd;
-  uint32 *w = k->wi;
+  const uint32 *w = k->wi;
 
   a ^= *w++; b ^= *w++; c ^= *w++; d ^= *w++;