cc-hash.c (fhash): The FILE name may be null.
[u/mdw/catacomb] / karatsuba.h
index 885d907..d0b81fc 100644 (file)
@@ -1,13 +1,13 @@
 /* -*-c-*-
  *
- * $Id: karatsuba.h,v 1.1 2000/06/17 11:42:11 mdw Exp $
+ * $Id: karatsuba.h,v 1.3 2004/04/08 01:36:15 mdw Exp $
  *
  * Macros for Karatsuba functions
  *
  * (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: karatsuba.h,v $
- * Revision 1.1  2000/06/17 11:42:11  mdw
- * Moved the Karatsuba macros into a separate file for better sharing.
- * Fixed some comments.
- *
- */
-
-#ifndef CATACOMB_MPX_KMAC_H
-#define CATACOMB_MPX_KMAC_H
+#ifndef CATACOMB_KARATSUBA_H
+#define CATACOMB_KARATSUBA_H
 
 #ifdef __cplusplus
   extern "C" {
@@ -49,7 +40,7 @@
 #  include "mpw.h"
 #endif
 
-/*----- Macros provided ---------------------------------------------------*/
+/*----- Normal arithmetic macros ------------------------------------------*/
 
 #define UADD(dv, av, avl) do {                                         \
   mpw *_dv = (dv);                                                     \
   }                                                                    \
 } while (0)
 
+/*----- Binary polynomial arithmetic macros -------------------------------*/
+
+#define UXOR(dv, av, avl) do {                                         \
+  mpw *_dv = (dv);                                                     \
+  const mpw *_av = (av), *_avl = (avl);                                        \
+                                                                       \
+  while (_av < _avl)                                                   \
+    *_dv++ ^= *_av++;                                                  \
+} while (0)
+
+#define UXOR2(dv, dvl, av, avl, bv, bvl) do {                          \
+  mpw *_dv = (dv), *_dvl = (dvl);                                      \
+  const mpw *_av = (av), *_avl = (avl);                                        \
+  const mpw *_bv = (bv), *_bvl = (bvl);                                        \
+                                                                       \
+  while (_av < _avl || _bv < _bvl) {                                   \
+    mpw _a, _b;                                                                \
+    _a = (_av < _avl) ? *_av++ : 0;                                    \
+    _b = (_bv < _bvl) ? *_bv++ : 0;                                    \
+    *_dv++ = _a ^ _b;                                                  \
+  }                                                                    \
+  while (_dv < _dvl)                                                   \
+    *_dv++ = 0;                                                                \
+} while (0)
+
 /*----- That's all, folks -------------------------------------------------*/
 
 #ifdef __cplusplus