## -*-makefile-*-
##
-## $Id: Makefile.m4,v 1.57 2002/10/15 22:58:29 mdw Exp $
+## $Id: Makefile.m4,v 1.58 2002/10/19 17:56:50 mdw Exp $
##
## Makefile for Catacomb
##
##----- Revision history ----------------------------------------------------
##
## $Log: Makefile.m4,v $
+## Revision 1.58 2002/10/19 17:56:50 mdw
+## Fix bit operations. Test them (a bit) better.
+##
## Revision 1.57 2002/10/15 22:58:29 mdw
## Fast estimation of number representation lengths.
##
blkc.h hash.h gcipher.h ghash.h gmac.h grand.h ghash-def.h \
lcrand.h fibrand.h rc4.h seal.h rand.h noise.h fipstest.h maurer.h \
key.h key-data.h passphrase.h pixie.h lmem.h \
- mpx.h mpw.h mpscan.h mparena.h mp.h mptext.h mpint.h \
+ mpx.h bitops.h mpw.h mpscan.h mparena.h mp.h mptext.h mpint.h \
exp.h mpbarrett.h mpmont.h mpcrt.h mprand.h mpmul.h \
gfx.h \
primetab.h pfilt.h rabin.h \
bin_PROGRAMS = dsig key pixie rspit factorial hashsum mkphrase
bin_SCRIPTS = catacomb-config xpixie
noinst_PROGRAMS = \
- genprimes mptypes serpent-check \
+ genprimes mptypes serpent-check bittest \
addsuffix(`gen_tables', `-mktab')
LDADD = libcatacomb.la
pixie_SOURCES = pixie.c pixie-common.c lmem.c arena.c
pixie_LDADD =
mkphrase_SOURCES = mkphrase.c
+bittest_SOURCES = bittest.c
+bittest_LDADD =
define(`emit', `
patsubst(_item, `[^a-zA-Z0-9]', `_')_mktab_SOURCES = _item`'-mktab.c
CTESTRIG(share)
CTESTRIG(rho)
-TESTS = serpent-check testprogs
+TESTS = serpent-check bittest testprogs
CLEANFILES = \
*.t *.to \
--- /dev/null
+/* -*-c-*-
+ *
+ * $Id: bitops.h,v 1.1 2002/10/19 17:56:50 mdw Exp $
+ *
+ * Bit operations by truth table
+ *
+ * (c) 2002 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: bitops.h,v $
+ * Revision 1.1 2002/10/19 17:56:50 mdw
+ * Fix bit operations. Test them (a bit) better.
+ *
+ */
+
+#ifndef CATACOMB_BITOPS_H
+#define CATACOMB_BITOPS_H
+
+#ifdef __cplusplus
+ extern "C" {
+#endif
+
+/*----- Macros ------------------------------------------------------------*/
+
+#define B0000(x, y) (0u)
+#define B0001(x, y) ((x) & (y))
+#define B0010(x, y) ((x) & ~(y))
+#define B0011(x, y) (x)
+#define B0100(x, y) (~(x) & (y))
+#define B0101(x, y) (y)
+#define B0110(x, y) ((x) ^ (y))
+#define B0111(x, y) ((x) | (y))
+#define B1000(x, y) (~((x) | (y)))
+#define B1001(x, y) (~((x) ^ (y)))
+#define B1010(x, y) (~(y))
+#define B1011(x, y) ((x) | ~(y))
+#define B1100(x, y) (~(x))
+#define B1101(x, y) (~(x) | (y))
+#define B1110(x, y) (~((x) & (y)))
+#define B1111(x, y) (~0u)
+
+/*----- That's all, folks -------------------------------------------------*/
+
+#ifdef __cplusplus
+ }
+#endif
+
+#endif
--- /dev/null
+/* -*-c-*-
+ *
+ * $Id: bittest.c,v 1.1 2002/10/19 17:56:50 mdw Exp $
+ *
+ * Check the bit operations work
+ *
+ * (c) 2002 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: bittest.c,v $
+ * Revision 1.1 2002/10/19 17:56:50 mdw
+ * Fix bit operations. Test them (a bit) better.
+ *
+ */
+
+/*----- Header files ------------------------------------------------------*/
+
+#include <stdio.h>
+#include <string.h>
+#include "bitops.h"
+#include "mpx.h"
+
+/*----- Main code ---------------------------------------------------------*/
+
+int main(void)
+{
+ int rc = 0;
+#define CHECK(string) do { \
+ const char *ref = #string; \
+ char buf[5]; \
+ buf[0] = B##string(0u, 0u) & 1u? '1' : '0'; \
+ buf[1] = B##string(0u, 1u) & 1u? '1' : '0'; \
+ buf[2] = B##string(1u, 0u) & 1u? '1' : '0'; \
+ buf[3] = B##string(1u, 1u) & 1u? '1' : '0'; \
+ buf[4] = 0; \
+ if (strcmp(buf, ref) != 0) { \
+ fprintf(stderr, "mismatch ref `%s' != buf `%s'\n", ref, buf); \
+ rc = 1; \
+ } \
+} while (0);
+ MPX_DOBIN(CHECK)
+ return (rc);
+}
+/*----- That's all, folks -------------------------------------------------*/
/* -*-c-*-
*
- * $Id: mp-arith.c,v 1.14 2002/10/15 19:18:31 mdw Exp $
+ * $Id: mp-arith.c,v 1.15 2002/10/19 17:56:50 mdw Exp $
*
* Basic arithmetic on multiprecision integers
*
/*----- Revision history --------------------------------------------------*
*
* $Log: mp-arith.c,v $
+ * Revision 1.15 2002/10/19 17:56:50 mdw
+ * Fix bit operations. Test them (a bit) better.
+ *
* Revision 1.14 2002/10/15 19:18:31 mdw
* New operation to negate numbers.
*
\
mp *mp_bit##string(mp *d, mp *a, mp *b) \
{ \
- MP_DEST(d, MAX(MP_LEN(a), MP_LEN(b)), a->f | b->f); \
+ MP_DEST(d, MAX(MP_LEN(a), MP_LEN(b)), (a->f | b->f) & ~MP_NEG); \
mpx_bit##string(d->v, d->vl, a->v, a->vl, b->v, b->vl); \
d->f = (a->f | b->f) & MP_BURN; \
MP_SHRINK(d); \
/* -*-c-*-
*
- * $Id: mpx.c,v 1.12 2002/10/06 22:52:50 mdw Exp $
+ * $Id: mpx.c,v 1.13 2002/10/19 17:56:50 mdw Exp $
*
* Low-level multiprecision arithmetic
*
/*----- Revision history --------------------------------------------------*
*
* $Log: mpx.c,v $
+ * Revision 1.13 2002/10/19 17:56:50 mdw
+ * Fix bit operations. Test them (a bit) better.
+ *
* Revision 1.12 2002/10/06 22:52:50 mdw
* Pile of changes for supporting two's complement properly.
*
#include "mptypes.h"
#include "mpx.h"
+#include "bitops.h"
/*----- Loading and storing -----------------------------------------------*/
mpw a, b; \
a = (av < avl) ? *av++ : 0; \
b = (bv < bvl) ? *bv++ : 0; \
- *dv++ = MPX_B##string(a, b); \
+ *dv++ = B##string(a, b); \
} \
}
/* -*-c-*-
*
- * $Id: mpx.h,v 1.14 2002/10/09 00:36:03 mdw Exp $
+ * $Id: mpx.h,v 1.15 2002/10/19 17:56:50 mdw Exp $
*
* Low level multiprecision arithmetic
*
/*----- Revision history --------------------------------------------------*
*
* $Log: mpx.h,v $
+ * Revision 1.15 2002/10/19 17:56:50 mdw
+ * Fix bit operations. Test them (a bit) better.
+ *
* Revision 1.14 2002/10/09 00:36:03 mdw
* Fix bounds on workspace for Karatsuba operations.
*
/*----- Bitwise operations ------------------------------------------------*/
-/* --- How to implement them --- *
- *
- * x: 0011
- * y: 0101
- */
-
-#define MPX_B0000(x, y) (0u)
-#define MPX_B0001(x, y) ((x) & (y))
-#define MPX_B0010(x, y) ((x) & ~(y))
-#define MPX_B0011(x, y) (x)
-#define MPX_B0100(x, y) (~(x) & ~(y))
-#define MPX_B0101(x, y) (y)
-#define MPX_B0110(x, y) ((x) ^ (y))
-#define MPX_B0111(x, y) ((x) | (y))
-#define MPX_B1000(x, y) (~((x) | (y)))
-#define MPX_B1001(x, y) (~((x) ^ (y)))
-#define MPX_B1010(x, y) (~(y))
-#define MPX_B1011(x, y) ((x) | ~(y))
-#define MPX_B1100(x, y) (~(x))
-#define MPX_B1101(x, y) (~(x) | (y))
-#define MPX_B1110(x, y) (~((x) & (y)))
-#define MPX_B1111(x, y) (~0u)
-
/* --- @mpx_bitop@ --- *
*
* Arguments: @mpw *dv, *dvl@ = destination vector
# Test vectors for MP functions
#
-# $Id: mp,v 1.12 2002/10/15 19:18:31 mdw Exp $
+# $Id: mp,v 1.13 2002/10/19 17:56:50 mdw Exp $
add {
5 4 9; 5 -4 1; -5 4 -1; -5 -4 -9;
or 5 3 7;
xor 5 3 6;
1111 0 0 -1;
+ or 45 -7 -3;
xor 0x343cd5 -0x6a49c -0x32984f;
}