Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/games make factor work with and without openssl.



details:   https://anonhg.NetBSD.org/src/rev/6dde888c3a8e
branches:  trunk
changeset: 532864:6dde888c3a8e
user:      itojun <itojun%NetBSD.org@localhost>
date:      Sun Jun 16 22:24:00 2002 +0000

description:
make factor work with and without openssl.

diffstat:

 games/Makefile        |  11 ++---------
 games/factor/Makefile |  10 +++++++++-
 games/factor/factor.c |  49 ++++++++++++++++++++++++++++++++++++++++++++++---
 3 files changed, 57 insertions(+), 13 deletions(-)

diffs (149 lines):

diff -r 0a0a15467bbe -r 6dde888c3a8e games/Makefile
--- a/games/Makefile    Sun Jun 16 21:40:03 2002 +0000
+++ b/games/Makefile    Sun Jun 16 22:24:00 2002 +0000
@@ -1,21 +1,14 @@
-#      $NetBSD: Makefile,v 1.19 2002/06/16 10:21:40 martin Exp $
+#      $NetBSD: Makefile,v 1.20 2002/06/16 22:24:00 itojun Exp $
 #      @(#)Makefile    8.3 (Berkeley) 7/24/94
 
 # Missing: ching dungeon warp
 # Moved: chess
 # Don't belong: xneko xroach
 
-# For MKCRYPTO
-.include <bsd.own.mk>
-
 SUBDIR=        adventure arithmetic atc backgammon banner battlestar bcd boggle \
-       caesar canfield countmail cribbage dm fish fortune gomoku hack \
+       caesar canfield countmail cribbage dm factor fish fortune gomoku hack \
        hangman hunt larn mille monop morse number phantasia pig pom ppt \
        primes quiz rain random robots rogue sail snake tetris trek wargames \
        worm worms wtf wump
 
-.if (${MKCRYPTO} != "no")
-SUBDIR+= factor
-.endif
-
 .include <bsd.subdir.mk>
diff -r 0a0a15467bbe -r 6dde888c3a8e games/factor/Makefile
--- a/games/factor/Makefile     Sun Jun 16 21:40:03 2002 +0000
+++ b/games/factor/Makefile     Sun Jun 16 22:24:00 2002 +0000
@@ -1,11 +1,19 @@
-#      $NetBSD: Makefile,v 1.8 2002/06/15 02:12:23 simonb Exp $
+#      $NetBSD: Makefile,v 1.9 2002/06/16 22:24:01 itojun Exp $
 #      @(#)Makefile    8.1 (Berkeley) 5/31/93
 
+# For MKCRYPTO
+.include <bsd.own.mk>
+
 PROG=  factor
 SRCS=  factor.c pr_tbl.c
 CPPFLAGS+=-I${.CURDIR}/../primes
+
+.if (${MKCRYPTO} != "no")
+CPPFLAGS+=-DHAVE_OPENSSL
 LDADD+=        -lcrypto
 DPADD+=        ${LIBCRYPTO}
+.endif
+
 MAN=   factor.6
 MLINKS+=factor.6 primes.6
 .PATH: ${.CURDIR}/../primes
diff -r 0a0a15467bbe -r 6dde888c3a8e games/factor/factor.c
--- a/games/factor/factor.c     Sun Jun 16 21:40:03 2002 +0000
+++ b/games/factor/factor.c     Sun Jun 16 22:24:00 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: factor.c,v 1.10 2002/06/15 02:12:23 simonb Exp $       */
+/*     $NetBSD: factor.c,v 1.11 2002/06/16 22:24:01 itojun Exp $       */
 
 /*
  * Copyright (c) 1989, 1993
@@ -46,7 +46,7 @@
 #if 0
 static char sccsid[] = "@(#)factor.c   8.4 (Berkeley) 5/4/95";
 #else
-__RCSID("$NetBSD: factor.c,v 1.10 2002/06/15 02:12:23 simonb Exp $");
+__RCSID("$NetBSD: factor.c,v 1.11 2002/06/16 22:24:01 itojun Exp $");
 #endif
 #endif /* not lint */
 
@@ -77,7 +77,17 @@
 #include <stdlib.h>
 #include <unistd.h>
 
+#ifdef HAVE_OPENSSL
 #include <openssl/bn.h>
+#else
+typedef long   BIGNUM;
+typedef u_long BN_ULONG;
+#define BN_new()       ((BIGNUM *)calloc(sizeof(BIGNUM), 1))
+#define BN_dec2bn(pp, str)     (**(pp) = atol(str))
+#define BN_is_zero(v)  (*(v) == 0)
+#define BN_is_one(v)   (*(v) == 1)
+#define BN_mod_word(a, b)      (*(a) % (b))
+#endif
 
 #include "primes.h"
 
@@ -95,8 +105,13 @@
 int    main(int, char *[]);
 void   pr_fact(BIGNUM *);                      /* print factors of a value */
 void   BN_print_dec_fp(FILE *, const BIGNUM *);
+void   usage(void) __attribute__((__noreturn__));
+#ifdef HAVE_OPENSSL
 void   pollard_pminus1(BIGNUM *);              /* print factors for big numbers */
-void   usage(void) __attribute__((__noreturn__));
+#else
+char   *BN_bn2dec(const BIGNUM *);
+BN_ULONG BN_div_word(BIGNUM *, BN_ULONG);
+#endif
 
 int
 main(int argc, char *argv[])
@@ -186,7 +201,11 @@
 
                /* Watch for primes larger than the table. */
                if (fact > pr_limit) {
+#ifdef HAVE_OPENSSL
                        pollard_pminus1(val);
+#else
+                       (void)printf(" %s", BN_bn2dec(val));
+#endif
                        break;
                }
 
@@ -227,6 +246,7 @@
 
 
 
+#ifdef HAVE_OPENSSL
 /* pollard rho, algorithm from Jim Gillogly, May 2000 */
 
 void
@@ -276,3 +296,26 @@
                BN_add_word(i, 1);
        }
 }
+#else
+char *
+BN_bn2dec(const BIGNUM *val)
+{
+       char *buf;
+
+       buf = malloc(100);
+       if (!buf)
+               return buf;
+       snprintf(buf, 100, "%ld", (long)*val);
+       return buf;
+}
+
+BN_ULONG
+BN_div_word(BIGNUM *a, BN_ULONG b)
+{
+       BN_ULONG mod;
+
+       mod = *a % b;
+       *a /= b;
+       return mod;
+}
+#endif



Home | Main Index | Thread Index | Old Index