Browse code

libclamav: use LibTomMath by Tom St Denis instead of libgmp for multiple precision integer arithmetic (bb#1366)

git-svn: trunk@4650

Tomasz Kojm authored on 2009/01/27 04:47:02
Showing 51 changed files
... ...
@@ -1,3 +1,10 @@
1
+Mon Jan 26 21:06:36 CET 2009 (tk)
2
+---------------------------------
3
+ * libclamav: use LibTomMath by Tom St Denis instead of libgmp for multiple
4
+	      precision integer arithmetic (bb#1366); the library is bundled
5
+	      with ClamAV what means that the digital signature support is
6
+	      now available out-of-box
7
+
1 8
 Fri Jan 23 13:33:18 EET 2009 (edwin)
2 9
 ------------------------------------
3 10
  * libclamav/clamav.h, libclamav/others.c, libclamav/others.h: fix
... ...
@@ -162,7 +162,6 @@ GENHTML = @GENHTML@
162 162
 GETENT = @GETENT@
163 163
 GPERF = @GPERF@
164 164
 GREP = @GREP@
165
-HAVE_LIBGMP = @HAVE_LIBGMP@
166 165
 INCLTDL = @INCLTDL@
167 166
 INSTALL = @INSTALL@
168 167
 INSTALL_DATA = @INSTALL_DATA@
... ...
@@ -180,8 +179,6 @@ LIBBZ2 = @LIBBZ2@
180 180
 LIBBZ2_PREFIX = @LIBBZ2_PREFIX@
181 181
 LIBCLAMAV_LIBS = @LIBCLAMAV_LIBS@
182 182
 LIBCLAMAV_VERSION = @LIBCLAMAV_VERSION@
183
-LIBGMP = @LIBGMP@
184
-LIBGMP_PREFIX = @LIBGMP_PREFIX@
185 183
 LIBLTDL = @LIBLTDL@
186 184
 LIBOBJS = @LIBOBJS@
187 185
 LIBS = @LIBS@
... ...
@@ -192,7 +189,6 @@ LTDLDEPS = @LTDLDEPS@
192 192
 LTDLINCL = @LTDLINCL@
193 193
 LTDLOPEN = @LTDLOPEN@
194 194
 LTLIBBZ2 = @LTLIBBZ2@
195
-LTLIBGMP = @LTLIBGMP@
196 195
 LTLIBOBJS = @LTLIBOBJS@
197 196
 LT_CONFIG_H = @LT_CONFIG_H@
198 197
 LT_DLLOADERS = @LT_DLLOADERS@
... ...
@@ -130,6 +130,6658 @@ test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
130 130
 AC_LIB_PROG_LD_GNU
131 131
 ])
132 132
 
133
+# libtool.m4 - Configure libtool for the host system. -*-Autoconf-*-
134
+
135
+# serial 52 Debian 1.5.26-4 AC_PROG_LIBTOOL
136
+
137
+
138
+# AC_PROVIDE_IFELSE(MACRO-NAME, IF-PROVIDED, IF-NOT-PROVIDED)
139
+# -----------------------------------------------------------
140
+# If this macro is not defined by Autoconf, define it here.
141
+m4_ifdef([AC_PROVIDE_IFELSE],
142
+         [],
143
+         [m4_define([AC_PROVIDE_IFELSE],
144
+	         [m4_ifdef([AC_PROVIDE_$1],
145
+		           [$2], [$3])])])
146
+
147
+
148
+# AC_PROG_LIBTOOL
149
+# ---------------
150
+AC_DEFUN([AC_PROG_LIBTOOL],
151
+[AC_REQUIRE([_AC_PROG_LIBTOOL])dnl
152
+dnl If AC_PROG_CXX has already been expanded, run AC_LIBTOOL_CXX
153
+dnl immediately, otherwise, hook it in at the end of AC_PROG_CXX.
154
+  AC_PROVIDE_IFELSE([AC_PROG_CXX],
155
+    [AC_LIBTOOL_CXX],
156
+    [define([AC_PROG_CXX], defn([AC_PROG_CXX])[AC_LIBTOOL_CXX
157
+  ])])
158
+dnl And a similar setup for Fortran 77 support
159
+  AC_PROVIDE_IFELSE([AC_PROG_F77],
160
+    [AC_LIBTOOL_F77],
161
+    [define([AC_PROG_F77], defn([AC_PROG_F77])[AC_LIBTOOL_F77
162
+])])
163
+
164
+dnl Quote A][M_PROG_GCJ so that aclocal doesn't bring it in needlessly.
165
+dnl If either AC_PROG_GCJ or A][M_PROG_GCJ have already been expanded, run
166
+dnl AC_LIBTOOL_GCJ immediately, otherwise, hook it in at the end of both.
167
+  AC_PROVIDE_IFELSE([AC_PROG_GCJ],
168
+    [AC_LIBTOOL_GCJ],
169
+    [AC_PROVIDE_IFELSE([A][M_PROG_GCJ],
170
+      [AC_LIBTOOL_GCJ],
171
+      [AC_PROVIDE_IFELSE([LT_AC_PROG_GCJ],
172
+	[AC_LIBTOOL_GCJ],
173
+      [ifdef([AC_PROG_GCJ],
174
+	     [define([AC_PROG_GCJ], defn([AC_PROG_GCJ])[AC_LIBTOOL_GCJ])])
175
+       ifdef([A][M_PROG_GCJ],
176
+	     [define([A][M_PROG_GCJ], defn([A][M_PROG_GCJ])[AC_LIBTOOL_GCJ])])
177
+       ifdef([LT_AC_PROG_GCJ],
178
+	     [define([LT_AC_PROG_GCJ],
179
+		defn([LT_AC_PROG_GCJ])[AC_LIBTOOL_GCJ])])])])
180
+])])# AC_PROG_LIBTOOL
181
+
182
+
183
+# _AC_PROG_LIBTOOL
184
+# ----------------
185
+AC_DEFUN([_AC_PROG_LIBTOOL],
186
+[AC_REQUIRE([AC_LIBTOOL_SETUP])dnl
187
+AC_BEFORE([$0],[AC_LIBTOOL_CXX])dnl
188
+AC_BEFORE([$0],[AC_LIBTOOL_F77])dnl
189
+AC_BEFORE([$0],[AC_LIBTOOL_GCJ])dnl
190
+
191
+# This can be used to rebuild libtool when needed
192
+LIBTOOL_DEPS="$ac_aux_dir/ltmain.sh"
193
+
194
+# Always use our own libtool.
195
+LIBTOOL='$(SHELL) $(top_builddir)/libtool'
196
+AC_SUBST(LIBTOOL)dnl
197
+
198
+# Prevent multiple expansion
199
+define([AC_PROG_LIBTOOL], [])
200
+])# _AC_PROG_LIBTOOL
201
+
202
+
203
+# AC_LIBTOOL_SETUP
204
+# ----------------
205
+AC_DEFUN([AC_LIBTOOL_SETUP],
206
+[AC_PREREQ(2.50)dnl
207
+AC_REQUIRE([AC_ENABLE_SHARED])dnl
208
+AC_REQUIRE([AC_ENABLE_STATIC])dnl
209
+AC_REQUIRE([AC_ENABLE_FAST_INSTALL])dnl
210
+AC_REQUIRE([AC_CANONICAL_HOST])dnl
211
+AC_REQUIRE([AC_CANONICAL_BUILD])dnl
212
+AC_REQUIRE([AC_PROG_CC])dnl
213
+AC_REQUIRE([AC_PROG_LD])dnl
214
+AC_REQUIRE([AC_PROG_LD_RELOAD_FLAG])dnl
215
+AC_REQUIRE([AC_PROG_NM])dnl
216
+
217
+AC_REQUIRE([AC_PROG_LN_S])dnl
218
+AC_REQUIRE([AC_DEPLIBS_CHECK_METHOD])dnl
219
+# Autoconf 2.13's AC_OBJEXT and AC_EXEEXT macros only works for C compilers!
220
+AC_REQUIRE([AC_OBJEXT])dnl
221
+AC_REQUIRE([AC_EXEEXT])dnl
222
+dnl
223
+AC_LIBTOOL_SYS_MAX_CMD_LEN
224
+AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE
225
+AC_LIBTOOL_OBJDIR
226
+
227
+AC_REQUIRE([_LT_AC_SYS_COMPILER])dnl
228
+_LT_AC_PROG_ECHO_BACKSLASH
229
+
230
+case $host_os in
231
+aix3*)
232
+  # AIX sometimes has problems with the GCC collect2 program.  For some
233
+  # reason, if we set the COLLECT_NAMES environment variable, the problems
234
+  # vanish in a puff of smoke.
235
+  if test "X${COLLECT_NAMES+set}" != Xset; then
236
+    COLLECT_NAMES=
237
+    export COLLECT_NAMES
238
+  fi
239
+  ;;
240
+esac
241
+
242
+# Sed substitution that helps us do robust quoting.  It backslashifies
243
+# metacharacters that are still active within double-quoted strings.
244
+Xsed='sed -e 1s/^X//'
245
+[sed_quote_subst='s/\([\\"\\`$\\\\]\)/\\\1/g']
246
+
247
+# Same as above, but do not quote variable references.
248
+[double_quote_subst='s/\([\\"\\`\\\\]\)/\\\1/g']
249
+
250
+# Sed substitution to delay expansion of an escaped shell variable in a
251
+# double_quote_subst'ed string.
252
+delay_variable_subst='s/\\\\\\\\\\\$/\\\\\\$/g'
253
+
254
+# Sed substitution to avoid accidental globbing in evaled expressions
255
+no_glob_subst='s/\*/\\\*/g'
256
+
257
+# Constants:
258
+rm="rm -f"
259
+
260
+# Global variables:
261
+default_ofile=libtool
262
+can_build_shared=yes
263
+
264
+# All known linkers require a `.a' archive for static linking (except MSVC,
265
+# which needs '.lib').
266
+libext=a
267
+ltmain="$ac_aux_dir/ltmain.sh"
268
+ofile="$default_ofile"
269
+with_gnu_ld="$lt_cv_prog_gnu_ld"
270
+
271
+AC_CHECK_TOOL(AR, ar, false)
272
+AC_CHECK_TOOL(RANLIB, ranlib, :)
273
+AC_CHECK_TOOL(STRIP, strip, :)
274
+
275
+old_CC="$CC"
276
+old_CFLAGS="$CFLAGS"
277
+
278
+# Set sane defaults for various variables
279
+test -z "$AR" && AR=ar
280
+test -z "$AR_FLAGS" && AR_FLAGS=cru
281
+test -z "$AS" && AS=as
282
+test -z "$CC" && CC=cc
283
+test -z "$LTCC" && LTCC=$CC
284
+test -z "$LTCFLAGS" && LTCFLAGS=$CFLAGS
285
+test -z "$DLLTOOL" && DLLTOOL=dlltool
286
+test -z "$LD" && LD=ld
287
+test -z "$LN_S" && LN_S="ln -s"
288
+test -z "$MAGIC_CMD" && MAGIC_CMD=file
289
+test -z "$NM" && NM=nm
290
+test -z "$SED" && SED=sed
291
+test -z "$OBJDUMP" && OBJDUMP=objdump
292
+test -z "$RANLIB" && RANLIB=:
293
+test -z "$STRIP" && STRIP=:
294
+test -z "$ac_objext" && ac_objext=o
295
+
296
+# Determine commands to create old-style static archives.
297
+old_archive_cmds='$AR $AR_FLAGS $oldlib$oldobjs'
298
+old_postinstall_cmds='chmod 644 $oldlib'
299
+old_postuninstall_cmds=
300
+
301
+if test -n "$RANLIB"; then
302
+  case $host_os in
303
+  openbsd*)
304
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB -t \$oldlib"
305
+    ;;
306
+  *)
307
+    old_postinstall_cmds="$old_postinstall_cmds~\$RANLIB \$oldlib"
308
+    ;;
309
+  esac
310
+  old_archive_cmds="$old_archive_cmds~\$RANLIB \$oldlib"
311
+fi
312
+
313
+_LT_CC_BASENAME([$compiler])
314
+
315
+# Only perform the check for file, if the check method requires it
316
+case $deplibs_check_method in
317
+file_magic*)
318
+  if test "$file_magic_cmd" = '$MAGIC_CMD'; then
319
+    AC_PATH_MAGIC
320
+  fi
321
+  ;;
322
+esac
323
+
324
+_LT_REQUIRED_DARWIN_CHECKS
325
+
326
+AC_PROVIDE_IFELSE([AC_LIBTOOL_DLOPEN], enable_dlopen=yes, enable_dlopen=no)
327
+AC_PROVIDE_IFELSE([AC_LIBTOOL_WIN32_DLL],
328
+enable_win32_dll=yes, enable_win32_dll=no)
329
+
330
+AC_ARG_ENABLE([libtool-lock],
331
+    [AC_HELP_STRING([--disable-libtool-lock],
332
+	[avoid locking (might break parallel builds)])])
333
+test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
334
+
335
+AC_ARG_WITH([pic],
336
+    [AC_HELP_STRING([--with-pic],
337
+	[try to use only PIC/non-PIC objects @<:@default=use both@:>@])],
338
+    [pic_mode="$withval"],
339
+    [pic_mode=default])
340
+test -z "$pic_mode" && pic_mode=default
341
+
342
+# Use C for the default configuration in the libtool script
343
+tagname=
344
+AC_LIBTOOL_LANG_C_CONFIG
345
+_LT_AC_TAGCONFIG
346
+])# AC_LIBTOOL_SETUP
347
+
348
+
349
+# _LT_AC_SYS_COMPILER
350
+# -------------------
351
+AC_DEFUN([_LT_AC_SYS_COMPILER],
352
+[AC_REQUIRE([AC_PROG_CC])dnl
353
+
354
+# If no C compiler was specified, use CC.
355
+LTCC=${LTCC-"$CC"}
356
+
357
+# If no C compiler flags were specified, use CFLAGS.
358
+LTCFLAGS=${LTCFLAGS-"$CFLAGS"}
359
+
360
+# Allow CC to be a program name with arguments.
361
+compiler=$CC
362
+])# _LT_AC_SYS_COMPILER
363
+
364
+
365
+# _LT_CC_BASENAME(CC)
366
+# -------------------
367
+# Calculate cc_basename.  Skip known compiler wrappers and cross-prefix.
368
+AC_DEFUN([_LT_CC_BASENAME],
369
+[for cc_temp in $1""; do
370
+  case $cc_temp in
371
+    compile | *[[\\/]]compile | ccache | *[[\\/]]ccache ) ;;
372
+    distcc | *[[\\/]]distcc | purify | *[[\\/]]purify ) ;;
373
+    \-*) ;;
374
+    *) break;;
375
+  esac
376
+done
377
+cc_basename=`$echo "X$cc_temp" | $Xsed -e 's%.*/%%' -e "s%^$host_alias-%%"`
378
+])
379
+
380
+
381
+# _LT_COMPILER_BOILERPLATE
382
+# ------------------------
383
+# Check for compiler boilerplate output or warnings with
384
+# the simple compiler test code.
385
+AC_DEFUN([_LT_COMPILER_BOILERPLATE],
386
+[AC_REQUIRE([LT_AC_PROG_SED])dnl
387
+ac_outfile=conftest.$ac_objext
388
+echo "$lt_simple_compile_test_code" >conftest.$ac_ext
389
+eval "$ac_compile" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
390
+_lt_compiler_boilerplate=`cat conftest.err`
391
+$rm conftest*
392
+])# _LT_COMPILER_BOILERPLATE
393
+
394
+
395
+# _LT_LINKER_BOILERPLATE
396
+# ----------------------
397
+# Check for linker boilerplate output or warnings with
398
+# the simple link test code.
399
+AC_DEFUN([_LT_LINKER_BOILERPLATE],
400
+[AC_REQUIRE([LT_AC_PROG_SED])dnl
401
+ac_outfile=conftest.$ac_objext
402
+echo "$lt_simple_link_test_code" >conftest.$ac_ext
403
+eval "$ac_link" 2>&1 >/dev/null | $SED '/^$/d; /^ *+/d' >conftest.err
404
+_lt_linker_boilerplate=`cat conftest.err`
405
+$rm -r conftest*
406
+])# _LT_LINKER_BOILERPLATE
407
+
408
+# _LT_REQUIRED_DARWIN_CHECKS
409
+# --------------------------
410
+# Check for some things on darwin
411
+AC_DEFUN([_LT_REQUIRED_DARWIN_CHECKS],[
412
+  case $host_os in
413
+    rhapsody* | darwin*)
414
+    AC_CHECK_TOOL([DSYMUTIL], [dsymutil], [:])
415
+    AC_CHECK_TOOL([NMEDIT], [nmedit], [:])
416
+
417
+    AC_CACHE_CHECK([for -single_module linker flag],[lt_cv_apple_cc_single_mod],
418
+      [lt_cv_apple_cc_single_mod=no
419
+      if test -z "${LT_MULTI_MODULE}"; then
420
+   # By default we will add the -single_module flag. You can override
421
+   # by either setting the environment variable LT_MULTI_MODULE
422
+   # non-empty at configure time, or by adding -multi_module to the
423
+   # link flags.
424
+   echo "int foo(void){return 1;}" > conftest.c
425
+   $LTCC $LTCFLAGS $LDFLAGS -o libconftest.dylib \
426
+     -dynamiclib ${wl}-single_module conftest.c
427
+   if test -f libconftest.dylib; then
428
+     lt_cv_apple_cc_single_mod=yes
429
+     rm -rf libconftest.dylib*
430
+   fi
431
+   rm conftest.c
432
+      fi])
433
+    AC_CACHE_CHECK([for -exported_symbols_list linker flag],
434
+      [lt_cv_ld_exported_symbols_list],
435
+      [lt_cv_ld_exported_symbols_list=no
436
+      save_LDFLAGS=$LDFLAGS
437
+      echo "_main" > conftest.sym
438
+      LDFLAGS="$LDFLAGS -Wl,-exported_symbols_list,conftest.sym"
439
+      AC_LINK_IFELSE([AC_LANG_PROGRAM([],[])],
440
+   [lt_cv_ld_exported_symbols_list=yes],
441
+   [lt_cv_ld_exported_symbols_list=no])
442
+   LDFLAGS="$save_LDFLAGS"
443
+    ])
444
+    case $host_os in
445
+    rhapsody* | darwin1.[[0123]])
446
+      _lt_dar_allow_undefined='${wl}-undefined ${wl}suppress' ;;
447
+    darwin1.*)
448
+     _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
449
+    darwin*)
450
+      # if running on 10.5 or later, the deployment target defaults
451
+      # to the OS version, if on x86, and 10.4, the deployment
452
+      # target defaults to 10.4. Don't you love it?
453
+      case ${MACOSX_DEPLOYMENT_TARGET-10.0},$host in
454
+   10.0,*86*-darwin8*|10.0,*-darwin[[91]]*)
455
+     _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
456
+   10.[[012]]*)
457
+     _lt_dar_allow_undefined='${wl}-flat_namespace ${wl}-undefined ${wl}suppress' ;;
458
+   10.*)
459
+     _lt_dar_allow_undefined='${wl}-undefined ${wl}dynamic_lookup' ;;
460
+      esac
461
+    ;;
462
+  esac
463
+    if test "$lt_cv_apple_cc_single_mod" = "yes"; then
464
+      _lt_dar_single_mod='$single_module'
465
+    fi
466
+    if test "$lt_cv_ld_exported_symbols_list" = "yes"; then
467
+      _lt_dar_export_syms=' ${wl}-exported_symbols_list,$output_objdir/${libname}-symbols.expsym'
468
+    else
469
+      _lt_dar_export_syms="~$NMEDIT -s \$output_objdir/\${libname}-symbols.expsym \${lib}"
470
+    fi
471
+    if test "$DSYMUTIL" != ":"; then
472
+      _lt_dsymutil="~$DSYMUTIL \$lib || :"
473
+    else
474
+      _lt_dsymutil=
475
+    fi
476
+    ;;
477
+  esac
478
+])
479
+
480
+# _LT_AC_SYS_LIBPATH_AIX
481
+# ----------------------
482
+# Links a minimal program and checks the executable
483
+# for the system default hardcoded library path. In most cases,
484
+# this is /usr/lib:/lib, but when the MPI compilers are used
485
+# the location of the communication and MPI libs are included too.
486
+# If we don't find anything, use the default library path according
487
+# to the aix ld manual.
488
+AC_DEFUN([_LT_AC_SYS_LIBPATH_AIX],
489
+[AC_REQUIRE([LT_AC_PROG_SED])dnl
490
+AC_LINK_IFELSE(AC_LANG_PROGRAM,[
491
+lt_aix_libpath_sed='
492
+    /Import File Strings/,/^$/ {
493
+	/^0/ {
494
+	    s/^0  *\(.*\)$/\1/
495
+	    p
496
+	}
497
+    }'
498
+aix_libpath=`dump -H conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
499
+# Check for a 64-bit object if we didn't find anything.
500
+if test -z "$aix_libpath"; then
501
+  aix_libpath=`dump -HX64 conftest$ac_exeext 2>/dev/null | $SED -n -e "$lt_aix_libpath_sed"`
502
+fi],[])
503
+if test -z "$aix_libpath"; then aix_libpath="/usr/lib:/lib"; fi
504
+])# _LT_AC_SYS_LIBPATH_AIX
505
+
506
+
507
+# _LT_AC_SHELL_INIT(ARG)
508
+# ----------------------
509
+AC_DEFUN([_LT_AC_SHELL_INIT],
510
+[ifdef([AC_DIVERSION_NOTICE],
511
+	     [AC_DIVERT_PUSH(AC_DIVERSION_NOTICE)],
512
+	 [AC_DIVERT_PUSH(NOTICE)])
513
+$1
514
+AC_DIVERT_POP
515
+])# _LT_AC_SHELL_INIT
516
+
517
+
518
+# _LT_AC_PROG_ECHO_BACKSLASH
519
+# --------------------------
520
+# Add some code to the start of the generated configure script which
521
+# will find an echo command which doesn't interpret backslashes.
522
+AC_DEFUN([_LT_AC_PROG_ECHO_BACKSLASH],
523
+[_LT_AC_SHELL_INIT([
524
+# Check that we are running under the correct shell.
525
+SHELL=${CONFIG_SHELL-/bin/sh}
526
+
527
+case X$ECHO in
528
+X*--fallback-echo)
529
+  # Remove one level of quotation (which was required for Make).
530
+  ECHO=`echo "$ECHO" | sed 's,\\\\\[$]\\[$]0,'[$]0','`
531
+  ;;
532
+esac
533
+
534
+echo=${ECHO-echo}
535
+if test "X[$]1" = X--no-reexec; then
536
+  # Discard the --no-reexec flag, and continue.
537
+  shift
538
+elif test "X[$]1" = X--fallback-echo; then
539
+  # Avoid inline document here, it may be left over
540
+  :
541
+elif test "X`($echo '\t') 2>/dev/null`" = 'X\t' ; then
542
+  # Yippee, $echo works!
543
+  :
544
+else
545
+  # Restart under the correct shell.
546
+  exec $SHELL "[$]0" --no-reexec ${1+"[$]@"}
547
+fi
548
+
549
+if test "X[$]1" = X--fallback-echo; then
550
+  # used as fallback echo
551
+  shift
552
+  cat <<EOF
553
+[$]*
554
+EOF
555
+  exit 0
556
+fi
557
+
558
+# The HP-UX ksh and POSIX shell print the target directory to stdout
559
+# if CDPATH is set.
560
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
561
+
562
+if test -z "$ECHO"; then
563
+if test "X${echo_test_string+set}" != Xset; then
564
+# find a string as large as possible, as long as the shell can cope with it
565
+  for cmd in 'sed 50q "[$]0"' 'sed 20q "[$]0"' 'sed 10q "[$]0"' 'sed 2q "[$]0"' 'echo test'; do
566
+    # expected sizes: less than 2Kb, 1Kb, 512 bytes, 16 bytes, ...
567
+    if (echo_test_string=`eval $cmd`) 2>/dev/null &&
568
+       echo_test_string=`eval $cmd` &&
569
+       (test "X$echo_test_string" = "X$echo_test_string") 2>/dev/null
570
+    then
571
+      break
572
+    fi
573
+  done
574
+fi
575
+
576
+if test "X`($echo '\t') 2>/dev/null`" = 'X\t' &&
577
+   echo_testing_string=`($echo "$echo_test_string") 2>/dev/null` &&
578
+   test "X$echo_testing_string" = "X$echo_test_string"; then
579
+  :
580
+else
581
+  # The Solaris, AIX, and Digital Unix default echo programs unquote
582
+  # backslashes.  This makes it impossible to quote backslashes using
583
+  #   echo "$something" | sed 's/\\/\\\\/g'
584
+  #
585
+  # So, first we look for a working echo in the user's PATH.
586
+
587
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
588
+  for dir in $PATH /usr/ucb; do
589
+    IFS="$lt_save_ifs"
590
+    if (test -f $dir/echo || test -f $dir/echo$ac_exeext) &&
591
+       test "X`($dir/echo '\t') 2>/dev/null`" = 'X\t' &&
592
+       echo_testing_string=`($dir/echo "$echo_test_string") 2>/dev/null` &&
593
+       test "X$echo_testing_string" = "X$echo_test_string"; then
594
+      echo="$dir/echo"
595
+      break
596
+    fi
597
+  done
598
+  IFS="$lt_save_ifs"
599
+
600
+  if test "X$echo" = Xecho; then
601
+    # We didn't find a better echo, so look for alternatives.
602
+    if test "X`(print -r '\t') 2>/dev/null`" = 'X\t' &&
603
+       echo_testing_string=`(print -r "$echo_test_string") 2>/dev/null` &&
604
+       test "X$echo_testing_string" = "X$echo_test_string"; then
605
+      # This shell has a builtin print -r that does the trick.
606
+      echo='print -r'
607
+    elif (test -f /bin/ksh || test -f /bin/ksh$ac_exeext) &&
608
+	 test "X$CONFIG_SHELL" != X/bin/ksh; then
609
+      # If we have ksh, try running configure again with it.
610
+      ORIGINAL_CONFIG_SHELL=${CONFIG_SHELL-/bin/sh}
611
+      export ORIGINAL_CONFIG_SHELL
612
+      CONFIG_SHELL=/bin/ksh
613
+      export CONFIG_SHELL
614
+      exec $CONFIG_SHELL "[$]0" --no-reexec ${1+"[$]@"}
615
+    else
616
+      # Try using printf.
617
+      echo='printf %s\n'
618
+      if test "X`($echo '\t') 2>/dev/null`" = 'X\t' &&
619
+	 echo_testing_string=`($echo "$echo_test_string") 2>/dev/null` &&
620
+	 test "X$echo_testing_string" = "X$echo_test_string"; then
621
+	# Cool, printf works
622
+	:
623
+      elif echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` &&
624
+	   test "X$echo_testing_string" = 'X\t' &&
625
+	   echo_testing_string=`($ORIGINAL_CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
626
+	   test "X$echo_testing_string" = "X$echo_test_string"; then
627
+	CONFIG_SHELL=$ORIGINAL_CONFIG_SHELL
628
+	export CONFIG_SHELL
629
+	SHELL="$CONFIG_SHELL"
630
+	export SHELL
631
+	echo="$CONFIG_SHELL [$]0 --fallback-echo"
632
+      elif echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo '\t') 2>/dev/null` &&
633
+	   test "X$echo_testing_string" = 'X\t' &&
634
+	   echo_testing_string=`($CONFIG_SHELL "[$]0" --fallback-echo "$echo_test_string") 2>/dev/null` &&
635
+	   test "X$echo_testing_string" = "X$echo_test_string"; then
636
+	echo="$CONFIG_SHELL [$]0 --fallback-echo"
637
+      else
638
+	# maybe with a smaller string...
639
+	prev=:
640
+
641
+	for cmd in 'echo test' 'sed 2q "[$]0"' 'sed 10q "[$]0"' 'sed 20q "[$]0"' 'sed 50q "[$]0"'; do
642
+	  if (test "X$echo_test_string" = "X`eval $cmd`") 2>/dev/null
643
+	  then
644
+	    break
645
+	  fi
646
+	  prev="$cmd"
647
+	done
648
+
649
+	if test "$prev" != 'sed 50q "[$]0"'; then
650
+	  echo_test_string=`eval $prev`
651
+	  export echo_test_string
652
+	  exec ${ORIGINAL_CONFIG_SHELL-${CONFIG_SHELL-/bin/sh}} "[$]0" ${1+"[$]@"}
653
+	else
654
+	  # Oops.  We lost completely, so just stick with echo.
655
+	  echo=echo
656
+	fi
657
+      fi
658
+    fi
659
+  fi
660
+fi
661
+fi
662
+
663
+# Copy echo and quote the copy suitably for passing to libtool from
664
+# the Makefile, instead of quoting the original, which is used later.
665
+ECHO=$echo
666
+if test "X$ECHO" = "X$CONFIG_SHELL [$]0 --fallback-echo"; then
667
+   ECHO="$CONFIG_SHELL \\\$\[$]0 --fallback-echo"
668
+fi
669
+
670
+AC_SUBST(ECHO)
671
+])])# _LT_AC_PROG_ECHO_BACKSLASH
672
+
673
+
674
+# _LT_AC_LOCK
675
+# -----------
676
+AC_DEFUN([_LT_AC_LOCK],
677
+[AC_ARG_ENABLE([libtool-lock],
678
+    [AC_HELP_STRING([--disable-libtool-lock],
679
+	[avoid locking (might break parallel builds)])])
680
+test "x$enable_libtool_lock" != xno && enable_libtool_lock=yes
681
+
682
+# Some flags need to be propagated to the compiler or linker for good
683
+# libtool support.
684
+case $host in
685
+ia64-*-hpux*)
686
+  # Find out which ABI we are using.
687
+  echo 'int i;' > conftest.$ac_ext
688
+  if AC_TRY_EVAL(ac_compile); then
689
+    case `/usr/bin/file conftest.$ac_objext` in
690
+    *ELF-32*)
691
+      HPUX_IA64_MODE="32"
692
+      ;;
693
+    *ELF-64*)
694
+      HPUX_IA64_MODE="64"
695
+      ;;
696
+    esac
697
+  fi
698
+  rm -rf conftest*
699
+  ;;
700
+*-*-irix6*)
701
+  # Find out which ABI we are using.
702
+  echo '[#]line __oline__ "configure"' > conftest.$ac_ext
703
+  if AC_TRY_EVAL(ac_compile); then
704
+   if test "$lt_cv_prog_gnu_ld" = yes; then
705
+    case `/usr/bin/file conftest.$ac_objext` in
706
+    *32-bit*)
707
+      LD="${LD-ld} -melf32bsmip"
708
+      ;;
709
+    *N32*)
710
+      LD="${LD-ld} -melf32bmipn32"
711
+      ;;
712
+    *64-bit*)
713
+      LD="${LD-ld} -melf64bmip"
714
+      ;;
715
+    esac
716
+   else
717
+    case `/usr/bin/file conftest.$ac_objext` in
718
+    *32-bit*)
719
+      LD="${LD-ld} -32"
720
+      ;;
721
+    *N32*)
722
+      LD="${LD-ld} -n32"
723
+      ;;
724
+    *64-bit*)
725
+      LD="${LD-ld} -64"
726
+      ;;
727
+    esac
728
+   fi
729
+  fi
730
+  rm -rf conftest*
731
+  ;;
732
+
733
+x86_64-*kfreebsd*-gnu|x86_64-*linux*|ppc*-*linux*|powerpc*-*linux*| \
734
+s390*-*linux*|sparc*-*linux*)
735
+  # Find out which ABI we are using.
736
+  echo 'int i;' > conftest.$ac_ext
737
+  if AC_TRY_EVAL(ac_compile); then
738
+    case `/usr/bin/file conftest.o` in
739
+    *32-bit*)
740
+      case $host in
741
+        x86_64-*kfreebsd*-gnu)
742
+          LD="${LD-ld} -m elf_i386_fbsd"
743
+          ;;
744
+        x86_64-*linux*)
745
+          LD="${LD-ld} -m elf_i386"
746
+          ;;
747
+        ppc64-*linux*|powerpc64-*linux*)
748
+          LD="${LD-ld} -m elf32ppclinux"
749
+          ;;
750
+        s390x-*linux*)
751
+          LD="${LD-ld} -m elf_s390"
752
+          ;;
753
+        sparc64-*linux*)
754
+          LD="${LD-ld} -m elf32_sparc"
755
+          ;;
756
+      esac
757
+      ;;
758
+    *64-bit*)
759
+      case $host in
760
+        x86_64-*kfreebsd*-gnu)
761
+          LD="${LD-ld} -m elf_x86_64_fbsd"
762
+          ;;
763
+        x86_64-*linux*)
764
+          LD="${LD-ld} -m elf_x86_64"
765
+          ;;
766
+        ppc*-*linux*|powerpc*-*linux*)
767
+          LD="${LD-ld} -m elf64ppc"
768
+          ;;
769
+        s390*-*linux*)
770
+          LD="${LD-ld} -m elf64_s390"
771
+          ;;
772
+        sparc*-*linux*)
773
+          LD="${LD-ld} -m elf64_sparc"
774
+          ;;
775
+      esac
776
+      ;;
777
+    esac
778
+  fi
779
+  rm -rf conftest*
780
+  ;;
781
+
782
+*-*-sco3.2v5*)
783
+  # On SCO OpenServer 5, we need -belf to get full-featured binaries.
784
+  SAVE_CFLAGS="$CFLAGS"
785
+  CFLAGS="$CFLAGS -belf"
786
+  AC_CACHE_CHECK([whether the C compiler needs -belf], lt_cv_cc_needs_belf,
787
+    [AC_LANG_PUSH(C)
788
+     AC_TRY_LINK([],[],[lt_cv_cc_needs_belf=yes],[lt_cv_cc_needs_belf=no])
789
+     AC_LANG_POP])
790
+  if test x"$lt_cv_cc_needs_belf" != x"yes"; then
791
+    # this is probably gcc 2.8.0, egcs 1.0 or newer; no need for -belf
792
+    CFLAGS="$SAVE_CFLAGS"
793
+  fi
794
+  ;;
795
+sparc*-*solaris*)
796
+  # Find out which ABI we are using.
797
+  echo 'int i;' > conftest.$ac_ext
798
+  if AC_TRY_EVAL(ac_compile); then
799
+    case `/usr/bin/file conftest.o` in
800
+    *64-bit*)
801
+      case $lt_cv_prog_gnu_ld in
802
+      yes*) LD="${LD-ld} -m elf64_sparc" ;;
803
+      *)
804
+        if ${LD-ld} -64 -r -o conftest2.o conftest.o >/dev/null 2>&1; then
805
+	  LD="${LD-ld} -64"
806
+	fi
807
+	;;
808
+      esac
809
+      ;;
810
+    esac
811
+  fi
812
+  rm -rf conftest*
813
+  ;;
814
+
815
+AC_PROVIDE_IFELSE([AC_LIBTOOL_WIN32_DLL],
816
+[*-*-cygwin* | *-*-mingw* | *-*-pw32*)
817
+  AC_CHECK_TOOL(DLLTOOL, dlltool, false)
818
+  AC_CHECK_TOOL(AS, as, false)
819
+  AC_CHECK_TOOL(OBJDUMP, objdump, false)
820
+  ;;
821
+  ])
822
+esac
823
+
824
+need_locks="$enable_libtool_lock"
825
+
826
+])# _LT_AC_LOCK
827
+
828
+
829
+# AC_LIBTOOL_COMPILER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS,
830
+#		[OUTPUT-FILE], [ACTION-SUCCESS], [ACTION-FAILURE])
831
+# ----------------------------------------------------------------
832
+# Check whether the given compiler option works
833
+AC_DEFUN([AC_LIBTOOL_COMPILER_OPTION],
834
+[AC_REQUIRE([LT_AC_PROG_SED])
835
+AC_CACHE_CHECK([$1], [$2],
836
+  [$2=no
837
+  ifelse([$4], , [ac_outfile=conftest.$ac_objext], [ac_outfile=$4])
838
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
839
+   lt_compiler_flag="$3"
840
+   # Insert the option either (1) after the last *FLAGS variable, or
841
+   # (2) before a word containing "conftest.", or (3) at the end.
842
+   # Note that $ac_compile itself does not contain backslashes and begins
843
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
844
+   # The option is referenced via a variable to avoid confusing sed.
845
+   lt_compile=`echo "$ac_compile" | $SED \
846
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
847
+   -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \
848
+   -e 's:$: $lt_compiler_flag:'`
849
+   (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD)
850
+   (eval "$lt_compile" 2>conftest.err)
851
+   ac_status=$?
852
+   cat conftest.err >&AS_MESSAGE_LOG_FD
853
+   echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
854
+   if (exit $ac_status) && test -s "$ac_outfile"; then
855
+     # The compiler can only warn and ignore the option if not recognized
856
+     # So say no if there are warnings other than the usual output.
857
+     $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' >conftest.exp
858
+     $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
859
+     if test ! -s conftest.er2 || diff conftest.exp conftest.er2 >/dev/null; then
860
+       $2=yes
861
+     fi
862
+   fi
863
+   $rm conftest*
864
+])
865
+
866
+if test x"[$]$2" = xyes; then
867
+    ifelse([$5], , :, [$5])
868
+else
869
+    ifelse([$6], , :, [$6])
870
+fi
871
+])# AC_LIBTOOL_COMPILER_OPTION
872
+
873
+
874
+# AC_LIBTOOL_LINKER_OPTION(MESSAGE, VARIABLE-NAME, FLAGS,
875
+#                          [ACTION-SUCCESS], [ACTION-FAILURE])
876
+# ------------------------------------------------------------
877
+# Check whether the given compiler option works
878
+AC_DEFUN([AC_LIBTOOL_LINKER_OPTION],
879
+[AC_REQUIRE([LT_AC_PROG_SED])dnl
880
+AC_CACHE_CHECK([$1], [$2],
881
+  [$2=no
882
+   save_LDFLAGS="$LDFLAGS"
883
+   LDFLAGS="$LDFLAGS $3"
884
+   echo "$lt_simple_link_test_code" > conftest.$ac_ext
885
+   if (eval $ac_link 2>conftest.err) && test -s conftest$ac_exeext; then
886
+     # The linker can only warn and ignore the option if not recognized
887
+     # So say no if there are warnings
888
+     if test -s conftest.err; then
889
+       # Append any errors to the config.log.
890
+       cat conftest.err 1>&AS_MESSAGE_LOG_FD
891
+       $echo "X$_lt_linker_boilerplate" | $Xsed -e '/^$/d' > conftest.exp
892
+       $SED '/^$/d; /^ *+/d' conftest.err >conftest.er2
893
+       if diff conftest.exp conftest.er2 >/dev/null; then
894
+         $2=yes
895
+       fi
896
+     else
897
+       $2=yes
898
+     fi
899
+   fi
900
+   $rm -r conftest*
901
+   LDFLAGS="$save_LDFLAGS"
902
+])
903
+
904
+if test x"[$]$2" = xyes; then
905
+    ifelse([$4], , :, [$4])
906
+else
907
+    ifelse([$5], , :, [$5])
908
+fi
909
+])# AC_LIBTOOL_LINKER_OPTION
910
+
911
+
912
+# AC_LIBTOOL_SYS_MAX_CMD_LEN
913
+# --------------------------
914
+AC_DEFUN([AC_LIBTOOL_SYS_MAX_CMD_LEN],
915
+[# find the maximum length of command line arguments
916
+AC_MSG_CHECKING([the maximum length of command line arguments])
917
+AC_CACHE_VAL([lt_cv_sys_max_cmd_len], [dnl
918
+  i=0
919
+  teststring="ABCD"
920
+
921
+  case $build_os in
922
+  msdosdjgpp*)
923
+    # On DJGPP, this test can blow up pretty badly due to problems in libc
924
+    # (any single argument exceeding 2000 bytes causes a buffer overrun
925
+    # during glob expansion).  Even if it were fixed, the result of this
926
+    # check would be larger than it should be.
927
+    lt_cv_sys_max_cmd_len=12288;    # 12K is about right
928
+    ;;
929
+
930
+  gnu*)
931
+    # Under GNU Hurd, this test is not required because there is
932
+    # no limit to the length of command line arguments.
933
+    # Libtool will interpret -1 as no limit whatsoever
934
+    lt_cv_sys_max_cmd_len=-1;
935
+    ;;
936
+
937
+  cygwin* | mingw*)
938
+    # On Win9x/ME, this test blows up -- it succeeds, but takes
939
+    # about 5 minutes as the teststring grows exponentially.
940
+    # Worse, since 9x/ME are not pre-emptively multitasking,
941
+    # you end up with a "frozen" computer, even though with patience
942
+    # the test eventually succeeds (with a max line length of 256k).
943
+    # Instead, let's just punt: use the minimum linelength reported by
944
+    # all of the supported platforms: 8192 (on NT/2K/XP).
945
+    lt_cv_sys_max_cmd_len=8192;
946
+    ;;
947
+
948
+  amigaos*)
949
+    # On AmigaOS with pdksh, this test takes hours, literally.
950
+    # So we just punt and use a minimum line length of 8192.
951
+    lt_cv_sys_max_cmd_len=8192;
952
+    ;;
953
+
954
+  netbsd* | freebsd* | openbsd* | darwin* | dragonfly*)
955
+    # This has been around since 386BSD, at least.  Likely further.
956
+    if test -x /sbin/sysctl; then
957
+      lt_cv_sys_max_cmd_len=`/sbin/sysctl -n kern.argmax`
958
+    elif test -x /usr/sbin/sysctl; then
959
+      lt_cv_sys_max_cmd_len=`/usr/sbin/sysctl -n kern.argmax`
960
+    else
961
+      lt_cv_sys_max_cmd_len=65536	# usable default for all BSDs
962
+    fi
963
+    # And add a safety zone
964
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
965
+    lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
966
+    ;;
967
+
968
+  interix*)
969
+    # We know the value 262144 and hardcode it with a safety zone (like BSD)
970
+    lt_cv_sys_max_cmd_len=196608
971
+    ;;
972
+
973
+  osf*)
974
+    # Dr. Hans Ekkehard Plesser reports seeing a kernel panic running configure
975
+    # due to this test when exec_disable_arg_limit is 1 on Tru64. It is not
976
+    # nice to cause kernel panics so lets avoid the loop below.
977
+    # First set a reasonable default.
978
+    lt_cv_sys_max_cmd_len=16384
979
+    #
980
+    if test -x /sbin/sysconfig; then
981
+      case `/sbin/sysconfig -q proc exec_disable_arg_limit` in
982
+        *1*) lt_cv_sys_max_cmd_len=-1 ;;
983
+      esac
984
+    fi
985
+    ;;
986
+  sco3.2v5*)
987
+    lt_cv_sys_max_cmd_len=102400
988
+    ;;
989
+  sysv5* | sco5v6* | sysv4.2uw2*)
990
+    kargmax=`grep ARG_MAX /etc/conf/cf.d/stune 2>/dev/null`
991
+    if test -n "$kargmax"; then
992
+      lt_cv_sys_max_cmd_len=`echo $kargmax | sed 's/.*[[ 	]]//'`
993
+    else
994
+      lt_cv_sys_max_cmd_len=32768
995
+    fi
996
+    ;;
997
+  *)
998
+    lt_cv_sys_max_cmd_len=`(getconf ARG_MAX) 2> /dev/null`
999
+    if test -n "$lt_cv_sys_max_cmd_len"; then
1000
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 4`
1001
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \* 3`
1002
+    else
1003
+      SHELL=${SHELL-${CONFIG_SHELL-/bin/sh}}
1004
+      while (test "X"`$SHELL [$]0 --fallback-echo "X$teststring" 2>/dev/null` \
1005
+	       = "XX$teststring") >/dev/null 2>&1 &&
1006
+	      new_result=`expr "X$teststring" : ".*" 2>&1` &&
1007
+	      lt_cv_sys_max_cmd_len=$new_result &&
1008
+	      test $i != 17 # 1/2 MB should be enough
1009
+      do
1010
+        i=`expr $i + 1`
1011
+        teststring=$teststring$teststring
1012
+      done
1013
+      teststring=
1014
+      # Add a significant safety factor because C++ compilers can tack on massive
1015
+      # amounts of additional arguments before passing them to the linker.
1016
+      # It appears as though 1/2 is a usable value.
1017
+      lt_cv_sys_max_cmd_len=`expr $lt_cv_sys_max_cmd_len \/ 2`
1018
+    fi
1019
+    ;;
1020
+  esac
1021
+])
1022
+if test -n $lt_cv_sys_max_cmd_len ; then
1023
+  AC_MSG_RESULT($lt_cv_sys_max_cmd_len)
1024
+else
1025
+  AC_MSG_RESULT(none)
1026
+fi
1027
+])# AC_LIBTOOL_SYS_MAX_CMD_LEN
1028
+
1029
+
1030
+# _LT_AC_CHECK_DLFCN
1031
+# ------------------
1032
+AC_DEFUN([_LT_AC_CHECK_DLFCN],
1033
+[AC_CHECK_HEADERS(dlfcn.h)dnl
1034
+])# _LT_AC_CHECK_DLFCN
1035
+
1036
+
1037
+# _LT_AC_TRY_DLOPEN_SELF (ACTION-IF-TRUE, ACTION-IF-TRUE-W-USCORE,
1038
+#                           ACTION-IF-FALSE, ACTION-IF-CROSS-COMPILING)
1039
+# ---------------------------------------------------------------------
1040
+AC_DEFUN([_LT_AC_TRY_DLOPEN_SELF],
1041
+[AC_REQUIRE([_LT_AC_CHECK_DLFCN])dnl
1042
+if test "$cross_compiling" = yes; then :
1043
+  [$4]
1044
+else
1045
+  lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
1046
+  lt_status=$lt_dlunknown
1047
+  cat > conftest.$ac_ext <<EOF
1048
+[#line __oline__ "configure"
1049
+#include "confdefs.h"
1050
+
1051
+#if HAVE_DLFCN_H
1052
+#include <dlfcn.h>
1053
+#endif
1054
+
1055
+#include <stdio.h>
1056
+
1057
+#ifdef RTLD_GLOBAL
1058
+#  define LT_DLGLOBAL		RTLD_GLOBAL
1059
+#else
1060
+#  ifdef DL_GLOBAL
1061
+#    define LT_DLGLOBAL		DL_GLOBAL
1062
+#  else
1063
+#    define LT_DLGLOBAL		0
1064
+#  endif
1065
+#endif
1066
+
1067
+/* We may have to define LT_DLLAZY_OR_NOW in the command line if we
1068
+   find out it does not work in some platform. */
1069
+#ifndef LT_DLLAZY_OR_NOW
1070
+#  ifdef RTLD_LAZY
1071
+#    define LT_DLLAZY_OR_NOW		RTLD_LAZY
1072
+#  else
1073
+#    ifdef DL_LAZY
1074
+#      define LT_DLLAZY_OR_NOW		DL_LAZY
1075
+#    else
1076
+#      ifdef RTLD_NOW
1077
+#        define LT_DLLAZY_OR_NOW	RTLD_NOW
1078
+#      else
1079
+#        ifdef DL_NOW
1080
+#          define LT_DLLAZY_OR_NOW	DL_NOW
1081
+#        else
1082
+#          define LT_DLLAZY_OR_NOW	0
1083
+#        endif
1084
+#      endif
1085
+#    endif
1086
+#  endif
1087
+#endif
1088
+
1089
+#ifdef __cplusplus
1090
+extern "C" void exit (int);
1091
+#endif
1092
+
1093
+void fnord() { int i=42;}
1094
+int main ()
1095
+{
1096
+  void *self = dlopen (0, LT_DLGLOBAL|LT_DLLAZY_OR_NOW);
1097
+  int status = $lt_dlunknown;
1098
+
1099
+  if (self)
1100
+    {
1101
+      if (dlsym (self,"fnord"))       status = $lt_dlno_uscore;
1102
+      else if (dlsym( self,"_fnord")) status = $lt_dlneed_uscore;
1103
+      /* dlclose (self); */
1104
+    }
1105
+  else
1106
+    puts (dlerror ());
1107
+
1108
+    exit (status);
1109
+}]
1110
+EOF
1111
+  if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} 2>/dev/null; then
1112
+    (./conftest; exit; ) >&AS_MESSAGE_LOG_FD 2>/dev/null
1113
+    lt_status=$?
1114
+    case x$lt_status in
1115
+      x$lt_dlno_uscore) $1 ;;
1116
+      x$lt_dlneed_uscore) $2 ;;
1117
+      x$lt_dlunknown|x*) $3 ;;
1118
+    esac
1119
+  else :
1120
+    # compilation failed
1121
+    $3
1122
+  fi
1123
+fi
1124
+rm -fr conftest*
1125
+])# _LT_AC_TRY_DLOPEN_SELF
1126
+
1127
+
1128
+# AC_LIBTOOL_DLOPEN_SELF
1129
+# ----------------------
1130
+AC_DEFUN([AC_LIBTOOL_DLOPEN_SELF],
1131
+[AC_REQUIRE([_LT_AC_CHECK_DLFCN])dnl
1132
+if test "x$enable_dlopen" != xyes; then
1133
+  enable_dlopen=unknown
1134
+  enable_dlopen_self=unknown
1135
+  enable_dlopen_self_static=unknown
1136
+else
1137
+  lt_cv_dlopen=no
1138
+  lt_cv_dlopen_libs=
1139
+
1140
+  case $host_os in
1141
+  beos*)
1142
+    lt_cv_dlopen="load_add_on"
1143
+    lt_cv_dlopen_libs=
1144
+    lt_cv_dlopen_self=yes
1145
+    ;;
1146
+
1147
+  mingw* | pw32*)
1148
+    lt_cv_dlopen="LoadLibrary"
1149
+    lt_cv_dlopen_libs=
1150
+   ;;
1151
+
1152
+  cygwin*)
1153
+    lt_cv_dlopen="dlopen"
1154
+    lt_cv_dlopen_libs=
1155
+   ;;
1156
+
1157
+  darwin*)
1158
+  # if libdl is installed we need to link against it
1159
+    AC_CHECK_LIB([dl], [dlopen],
1160
+		[lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],[
1161
+    lt_cv_dlopen="dyld"
1162
+    lt_cv_dlopen_libs=
1163
+    lt_cv_dlopen_self=yes
1164
+    ])
1165
+   ;;
1166
+
1167
+  *)
1168
+    AC_CHECK_FUNC([shl_load],
1169
+	  [lt_cv_dlopen="shl_load"],
1170
+      [AC_CHECK_LIB([dld], [shl_load],
1171
+	    [lt_cv_dlopen="shl_load" lt_cv_dlopen_libs="-ldld"],
1172
+	[AC_CHECK_FUNC([dlopen],
1173
+	      [lt_cv_dlopen="dlopen"],
1174
+	  [AC_CHECK_LIB([dl], [dlopen],
1175
+		[lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-ldl"],
1176
+	    [AC_CHECK_LIB([svld], [dlopen],
1177
+		  [lt_cv_dlopen="dlopen" lt_cv_dlopen_libs="-lsvld"],
1178
+	      [AC_CHECK_LIB([dld], [dld_link],
1179
+		    [lt_cv_dlopen="dld_link" lt_cv_dlopen_libs="-ldld"])
1180
+	      ])
1181
+	    ])
1182
+	  ])
1183
+	])
1184
+      ])
1185
+    ;;
1186
+  esac
1187
+
1188
+  if test "x$lt_cv_dlopen" != xno; then
1189
+    enable_dlopen=yes
1190
+  else
1191
+    enable_dlopen=no
1192
+  fi
1193
+
1194
+  case $lt_cv_dlopen in
1195
+  dlopen)
1196
+    save_CPPFLAGS="$CPPFLAGS"
1197
+    test "x$ac_cv_header_dlfcn_h" = xyes && CPPFLAGS="$CPPFLAGS -DHAVE_DLFCN_H"
1198
+
1199
+    save_LDFLAGS="$LDFLAGS"
1200
+    wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $export_dynamic_flag_spec\"
1201
+
1202
+    save_LIBS="$LIBS"
1203
+    LIBS="$lt_cv_dlopen_libs $LIBS"
1204
+
1205
+    AC_CACHE_CHECK([whether a program can dlopen itself],
1206
+	  lt_cv_dlopen_self, [dnl
1207
+	  _LT_AC_TRY_DLOPEN_SELF(
1208
+	    lt_cv_dlopen_self=yes, lt_cv_dlopen_self=yes,
1209
+	    lt_cv_dlopen_self=no, lt_cv_dlopen_self=cross)
1210
+    ])
1211
+
1212
+    if test "x$lt_cv_dlopen_self" = xyes; then
1213
+      wl=$lt_prog_compiler_wl eval LDFLAGS=\"\$LDFLAGS $lt_prog_compiler_static\"
1214
+      AC_CACHE_CHECK([whether a statically linked program can dlopen itself],
1215
+    	  lt_cv_dlopen_self_static, [dnl
1216
+	  _LT_AC_TRY_DLOPEN_SELF(
1217
+	    lt_cv_dlopen_self_static=yes, lt_cv_dlopen_self_static=yes,
1218
+	    lt_cv_dlopen_self_static=no,  lt_cv_dlopen_self_static=cross)
1219
+      ])
1220
+    fi
1221
+
1222
+    CPPFLAGS="$save_CPPFLAGS"
1223
+    LDFLAGS="$save_LDFLAGS"
1224
+    LIBS="$save_LIBS"
1225
+    ;;
1226
+  esac
1227
+
1228
+  case $lt_cv_dlopen_self in
1229
+  yes|no) enable_dlopen_self=$lt_cv_dlopen_self ;;
1230
+  *) enable_dlopen_self=unknown ;;
1231
+  esac
1232
+
1233
+  case $lt_cv_dlopen_self_static in
1234
+  yes|no) enable_dlopen_self_static=$lt_cv_dlopen_self_static ;;
1235
+  *) enable_dlopen_self_static=unknown ;;
1236
+  esac
1237
+fi
1238
+])# AC_LIBTOOL_DLOPEN_SELF
1239
+
1240
+
1241
+# AC_LIBTOOL_PROG_CC_C_O([TAGNAME])
1242
+# ---------------------------------
1243
+# Check to see if options -c and -o are simultaneously supported by compiler
1244
+AC_DEFUN([AC_LIBTOOL_PROG_CC_C_O],
1245
+[AC_REQUIRE([LT_AC_PROG_SED])dnl
1246
+AC_REQUIRE([_LT_AC_SYS_COMPILER])dnl
1247
+AC_CACHE_CHECK([if $compiler supports -c -o file.$ac_objext],
1248
+  [_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)],
1249
+  [_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)=no
1250
+   $rm -r conftest 2>/dev/null
1251
+   mkdir conftest
1252
+   cd conftest
1253
+   mkdir out
1254
+   echo "$lt_simple_compile_test_code" > conftest.$ac_ext
1255
+
1256
+   lt_compiler_flag="-o out/conftest2.$ac_objext"
1257
+   # Insert the option either (1) after the last *FLAGS variable, or
1258
+   # (2) before a word containing "conftest.", or (3) at the end.
1259
+   # Note that $ac_compile itself does not contain backslashes and begins
1260
+   # with a dollar sign (not a hyphen), so the echo should work correctly.
1261
+   lt_compile=`echo "$ac_compile" | $SED \
1262
+   -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
1263
+   -e 's: [[^ ]]*conftest\.: $lt_compiler_flag&:; t' \
1264
+   -e 's:$: $lt_compiler_flag:'`
1265
+   (eval echo "\"\$as_me:__oline__: $lt_compile\"" >&AS_MESSAGE_LOG_FD)
1266
+   (eval "$lt_compile" 2>out/conftest.err)
1267
+   ac_status=$?
1268
+   cat out/conftest.err >&AS_MESSAGE_LOG_FD
1269
+   echo "$as_me:__oline__: \$? = $ac_status" >&AS_MESSAGE_LOG_FD
1270
+   if (exit $ac_status) && test -s out/conftest2.$ac_objext
1271
+   then
1272
+     # The compiler can only warn and ignore the option if not recognized
1273
+     # So say no if there are warnings
1274
+     $echo "X$_lt_compiler_boilerplate" | $Xsed -e '/^$/d' > out/conftest.exp
1275
+     $SED '/^$/d; /^ *+/d' out/conftest.err >out/conftest.er2
1276
+     if test ! -s out/conftest.er2 || diff out/conftest.exp out/conftest.er2 >/dev/null; then
1277
+       _LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes
1278
+     fi
1279
+   fi
1280
+   chmod u+w . 2>&AS_MESSAGE_LOG_FD
1281
+   $rm conftest*
1282
+   # SGI C++ compiler will create directory out/ii_files/ for
1283
+   # template instantiation
1284
+   test -d out/ii_files && $rm out/ii_files/* && rmdir out/ii_files
1285
+   $rm out/* && rmdir out
1286
+   cd ..
1287
+   rmdir conftest
1288
+   $rm conftest*
1289
+])
1290
+])# AC_LIBTOOL_PROG_CC_C_O
1291
+
1292
+
1293
+# AC_LIBTOOL_SYS_HARD_LINK_LOCKS([TAGNAME])
1294
+# -----------------------------------------
1295
+# Check to see if we can do hard links to lock some files if needed
1296
+AC_DEFUN([AC_LIBTOOL_SYS_HARD_LINK_LOCKS],
1297
+[AC_REQUIRE([_LT_AC_LOCK])dnl
1298
+
1299
+hard_links="nottested"
1300
+if test "$_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)" = no && test "$need_locks" != no; then
1301
+  # do not overwrite the value of need_locks provided by the user
1302
+  AC_MSG_CHECKING([if we can lock with hard links])
1303
+  hard_links=yes
1304
+  $rm conftest*
1305
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
1306
+  touch conftest.a
1307
+  ln conftest.a conftest.b 2>&5 || hard_links=no
1308
+  ln conftest.a conftest.b 2>/dev/null && hard_links=no
1309
+  AC_MSG_RESULT([$hard_links])
1310
+  if test "$hard_links" = no; then
1311
+    AC_MSG_WARN([`$CC' does not support `-c -o', so `make -j' may be unsafe])
1312
+    need_locks=warn
1313
+  fi
1314
+else
1315
+  need_locks=no
1316
+fi
1317
+])# AC_LIBTOOL_SYS_HARD_LINK_LOCKS
1318
+
1319
+
1320
+# AC_LIBTOOL_OBJDIR
1321
+# -----------------
1322
+AC_DEFUN([AC_LIBTOOL_OBJDIR],
1323
+[AC_CACHE_CHECK([for objdir], [lt_cv_objdir],
1324
+[rm -f .libs 2>/dev/null
1325
+mkdir .libs 2>/dev/null
1326
+if test -d .libs; then
1327
+  lt_cv_objdir=.libs
1328
+else
1329
+  # MS-DOS does not allow filenames that begin with a dot.
1330
+  lt_cv_objdir=_libs
1331
+fi
1332
+rmdir .libs 2>/dev/null])
1333
+objdir=$lt_cv_objdir
1334
+])# AC_LIBTOOL_OBJDIR
1335
+
1336
+
1337
+# AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH([TAGNAME])
1338
+# ----------------------------------------------
1339
+# Check hardcoding attributes.
1340
+AC_DEFUN([AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH],
1341
+[AC_MSG_CHECKING([how to hardcode library paths into programs])
1342
+_LT_AC_TAGVAR(hardcode_action, $1)=
1343
+if test -n "$_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)" || \
1344
+   test -n "$_LT_AC_TAGVAR(runpath_var, $1)" || \
1345
+   test "X$_LT_AC_TAGVAR(hardcode_automatic, $1)" = "Xyes" ; then
1346
+
1347
+  # We can hardcode non-existant directories.
1348
+  if test "$_LT_AC_TAGVAR(hardcode_direct, $1)" != no &&
1349
+     # If the only mechanism to avoid hardcoding is shlibpath_var, we
1350
+     # have to relink, otherwise we might link with an installed library
1351
+     # when we should be linking with a yet-to-be-installed one
1352
+     ## test "$_LT_AC_TAGVAR(hardcode_shlibpath_var, $1)" != no &&
1353
+     test "$_LT_AC_TAGVAR(hardcode_minus_L, $1)" != no; then
1354
+    # Linking always hardcodes the temporary library directory.
1355
+    _LT_AC_TAGVAR(hardcode_action, $1)=relink
1356
+  else
1357
+    # We can link without hardcoding, and we can hardcode nonexisting dirs.
1358
+    _LT_AC_TAGVAR(hardcode_action, $1)=immediate
1359
+  fi
1360
+else
1361
+  # We cannot hardcode anything, or else we can only hardcode existing
1362
+  # directories.
1363
+  _LT_AC_TAGVAR(hardcode_action, $1)=unsupported
1364
+fi
1365
+AC_MSG_RESULT([$_LT_AC_TAGVAR(hardcode_action, $1)])
1366
+
1367
+if test "$_LT_AC_TAGVAR(hardcode_action, $1)" = relink; then
1368
+  # Fast installation is not supported
1369
+  enable_fast_install=no
1370
+elif test "$shlibpath_overrides_runpath" = yes ||
1371
+     test "$enable_shared" = no; then
1372
+  # Fast installation is not necessary
1373
+  enable_fast_install=needless
1374
+fi
1375
+])# AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH
1376
+
1377
+
1378
+# AC_LIBTOOL_SYS_LIB_STRIP
1379
+# ------------------------
1380
+AC_DEFUN([AC_LIBTOOL_SYS_LIB_STRIP],
1381
+[striplib=
1382
+old_striplib=
1383
+AC_MSG_CHECKING([whether stripping libraries is possible])
1384
+if test -n "$STRIP" && $STRIP -V 2>&1 | grep "GNU strip" >/dev/null; then
1385
+  test -z "$old_striplib" && old_striplib="$STRIP --strip-debug"
1386
+  test -z "$striplib" && striplib="$STRIP --strip-unneeded"
1387
+  AC_MSG_RESULT([yes])
1388
+else
1389
+# FIXME - insert some real tests, host_os isn't really good enough
1390
+  case $host_os in
1391
+   darwin*)
1392
+       if test -n "$STRIP" ; then
1393
+         striplib="$STRIP -x"
1394
+         old_striplib="$STRIP -S"
1395
+         AC_MSG_RESULT([yes])
1396
+       else
1397
+  AC_MSG_RESULT([no])
1398
+fi
1399
+       ;;
1400
+   *)
1401
+  AC_MSG_RESULT([no])
1402
+    ;;
1403
+  esac
1404
+fi
1405
+])# AC_LIBTOOL_SYS_LIB_STRIP
1406
+
1407
+
1408
+# AC_LIBTOOL_SYS_DYNAMIC_LINKER
1409
+# -----------------------------
1410
+# PORTME Fill in your ld.so characteristics
1411
+AC_DEFUN([AC_LIBTOOL_SYS_DYNAMIC_LINKER],
1412
+[AC_REQUIRE([LT_AC_PROG_SED])dnl
1413
+AC_MSG_CHECKING([dynamic linker characteristics])
1414
+library_names_spec=
1415
+libname_spec='lib$name'
1416
+soname_spec=
1417
+shrext_cmds=".so"
1418
+postinstall_cmds=
1419
+postuninstall_cmds=
1420
+finish_cmds=
1421
+finish_eval=
1422
+shlibpath_var=
1423
+shlibpath_overrides_runpath=unknown
1424
+version_type=none
1425
+dynamic_linker="$host_os ld.so"
1426
+sys_lib_dlsearch_path_spec="/lib /usr/lib"
1427
+m4_if($1,[],[
1428
+if test "$GCC" = yes; then
1429
+  case $host_os in
1430
+    darwin*) lt_awk_arg="/^libraries:/,/LR/" ;;
1431
+    *) lt_awk_arg="/^libraries:/" ;;
1432
+  esac
1433
+  lt_search_path_spec=`$CC -print-search-dirs | awk $lt_awk_arg | $SED -e "s/^libraries://" -e "s,=/,/,g"`
1434
+  if echo "$lt_search_path_spec" | grep ';' >/dev/null ; then
1435
+    # if the path contains ";" then we assume it to be the separator
1436
+    # otherwise default to the standard path separator (i.e. ":") - it is
1437
+    # assumed that no part of a normal pathname contains ";" but that should
1438
+    # okay in the real world where ";" in dirpaths is itself problematic.
1439
+    lt_search_path_spec=`echo "$lt_search_path_spec" | $SED -e 's/;/ /g'`
1440
+  else
1441
+    lt_search_path_spec=`echo "$lt_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
1442
+  fi
1443
+  # Ok, now we have the path, separated by spaces, we can step through it
1444
+  # and add multilib dir if necessary.
1445
+  lt_tmp_lt_search_path_spec=
1446
+  lt_multi_os_dir=`$CC $CPPFLAGS $CFLAGS $LDFLAGS -print-multi-os-directory 2>/dev/null`
1447
+  for lt_sys_path in $lt_search_path_spec; do
1448
+    if test -d "$lt_sys_path/$lt_multi_os_dir"; then
1449
+      lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path/$lt_multi_os_dir"
1450
+    else
1451
+      test -d "$lt_sys_path" && \
1452
+	lt_tmp_lt_search_path_spec="$lt_tmp_lt_search_path_spec $lt_sys_path"
1453
+    fi
1454
+  done
1455
+  lt_search_path_spec=`echo $lt_tmp_lt_search_path_spec | awk '
1456
+BEGIN {RS=" "; FS="/|\n";} {
1457
+  lt_foo="";
1458
+  lt_count=0;
1459
+  for (lt_i = NF; lt_i > 0; lt_i--) {
1460
+    if ($lt_i != "" && $lt_i != ".") {
1461
+      if ($lt_i == "..") {
1462
+        lt_count++;
1463
+      } else {
1464
+        if (lt_count == 0) {
1465
+          lt_foo="/" $lt_i lt_foo;
1466
+        } else {
1467
+          lt_count--;
1468
+        }
1469
+      }
1470
+    }
1471
+  }
1472
+  if (lt_foo != "") { lt_freq[[lt_foo]]++; }
1473
+  if (lt_freq[[lt_foo]] == 1) { print lt_foo; }
1474
+}'`
1475
+  sys_lib_search_path_spec=`echo $lt_search_path_spec`
1476
+else
1477
+  sys_lib_search_path_spec="/lib /usr/lib /usr/local/lib"
1478
+fi])
1479
+need_lib_prefix=unknown
1480
+hardcode_into_libs=no
1481
+
1482
+# when you set need_version to no, make sure it does not cause -set_version
1483
+# flags to be left without arguments
1484
+need_version=unknown
1485
+
1486
+case $host_os in
1487
+aix3*)
1488
+  version_type=linux
1489
+  library_names_spec='${libname}${release}${shared_ext}$versuffix $libname.a'
1490
+  shlibpath_var=LIBPATH
1491
+
1492
+  # AIX 3 has no versioning support, so we append a major version to the name.
1493
+  soname_spec='${libname}${release}${shared_ext}$major'
1494
+  ;;
1495
+
1496
+aix[[4-9]]*)
1497
+  version_type=linux
1498
+  need_lib_prefix=no
1499
+  need_version=no
1500
+  hardcode_into_libs=yes
1501
+  if test "$host_cpu" = ia64; then
1502
+    # AIX 5 supports IA64
1503
+    library_names_spec='${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext}$versuffix $libname${shared_ext}'
1504
+    shlibpath_var=LD_LIBRARY_PATH
1505
+  else
1506
+    # With GCC up to 2.95.x, collect2 would create an import file
1507
+    # for dependence libraries.  The import file would start with
1508
+    # the line `#! .'.  This would cause the generated library to
1509
+    # depend on `.', always an invalid library.  This was fixed in
1510
+    # development snapshots of GCC prior to 3.0.
1511
+    case $host_os in
1512
+      aix4 | aix4.[[01]] | aix4.[[01]].*)
1513
+      if { echo '#if __GNUC__ > 2 || (__GNUC__ == 2 && __GNUC_MINOR__ >= 97)'
1514
+	   echo ' yes '
1515
+	   echo '#endif'; } | ${CC} -E - | grep yes > /dev/null; then
1516
+	:
1517
+      else
1518
+	can_build_shared=no
1519
+      fi
1520
+      ;;
1521
+    esac
1522
+    # AIX (on Power*) has no versioning support, so currently we can not hardcode correct
1523
+    # soname into executable. Probably we can add versioning support to
1524
+    # collect2, so additional links can be useful in future.
1525
+    if test "$aix_use_runtimelinking" = yes; then
1526
+      # If using run time linking (on AIX 4.2 or later) use lib<name>.so
1527
+      # instead of lib<name>.a to let people know that these are not
1528
+      # typical AIX shared libraries.
1529
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
1530
+    else
1531
+      # We preserve .a as extension for shared libraries through AIX4.2
1532
+      # and later when we are not doing run time linking.
1533
+      library_names_spec='${libname}${release}.a $libname.a'
1534
+      soname_spec='${libname}${release}${shared_ext}$major'
1535
+    fi
1536
+    shlibpath_var=LIBPATH
1537
+  fi
1538
+  ;;
1539
+
1540
+amigaos*)
1541
+  library_names_spec='$libname.ixlibrary $libname.a'
1542
+  # Create ${libname}_ixlibrary.a entries in /sys/libs.
1543
+  finish_eval='for lib in `ls $libdir/*.ixlibrary 2>/dev/null`; do libname=`$echo "X$lib" | $Xsed -e '\''s%^.*/\([[^/]]*\)\.ixlibrary$%\1%'\''`; test $rm /sys/libs/${libname}_ixlibrary.a; $show "cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a"; cd /sys/libs && $LN_S $lib ${libname}_ixlibrary.a || exit 1; done'
1544
+  ;;
1545
+
1546
+beos*)
1547
+  library_names_spec='${libname}${shared_ext}'
1548
+  dynamic_linker="$host_os ld.so"
1549
+  shlibpath_var=LIBRARY_PATH
1550
+  ;;
1551
+
1552
+bsdi[[45]]*)
1553
+  version_type=linux
1554
+  need_version=no
1555
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
1556
+  soname_spec='${libname}${release}${shared_ext}$major'
1557
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig $libdir'
1558
+  shlibpath_var=LD_LIBRARY_PATH
1559
+  sys_lib_search_path_spec="/shlib /usr/lib /usr/X11/lib /usr/contrib/lib /lib /usr/local/lib"
1560
+  sys_lib_dlsearch_path_spec="/shlib /usr/lib /usr/local/lib"
1561
+  # the default ld.so.conf also contains /usr/contrib/lib and
1562
+  # /usr/X11R6/lib (/usr/X11 is a link to /usr/X11R6), but let us allow
1563
+  # libtool to hard-code these into programs
1564
+  ;;
1565
+
1566
+cygwin* | mingw* | pw32*)
1567
+  version_type=windows
1568
+  shrext_cmds=".dll"
1569
+  need_version=no
1570
+  need_lib_prefix=no
1571
+
1572
+  case $GCC,$host_os in
1573
+  yes,cygwin* | yes,mingw* | yes,pw32*)
1574
+    library_names_spec='$libname.dll.a'
1575
+    # DLL is installed to $(libdir)/../bin by postinstall_cmds
1576
+    postinstall_cmds='base_file=`basename \${file}`~
1577
+      dlpath=`$SHELL 2>&1 -c '\''. $dir/'\''\${base_file}'\''i;echo \$dlname'\''`~
1578
+      dldir=$destdir/`dirname \$dlpath`~
1579
+      test -d \$dldir || mkdir -p \$dldir~
1580
+      $install_prog $dir/$dlname \$dldir/$dlname~
1581
+      chmod a+x \$dldir/$dlname'
1582
+    postuninstall_cmds='dldll=`$SHELL 2>&1 -c '\''. $file; echo \$dlname'\''`~
1583
+      dlpath=$dir/\$dldll~
1584
+       $rm \$dlpath'
1585
+    shlibpath_overrides_runpath=yes
1586
+
1587
+    case $host_os in
1588
+    cygwin*)
1589
+      # Cygwin DLLs use 'cyg' prefix rather than 'lib'
1590
+      soname_spec='`echo ${libname} | sed -e 's/^lib/cyg/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
1591
+      sys_lib_search_path_spec="/usr/lib /lib/w32api /lib /usr/local/lib"
1592
+      ;;
1593
+    mingw*)
1594
+      # MinGW DLLs use traditional 'lib' prefix
1595
+      soname_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
1596
+      sys_lib_search_path_spec=`$CC -print-search-dirs | grep "^libraries:" | $SED -e "s/^libraries://" -e "s,=/,/,g"`
1597
+      if echo "$sys_lib_search_path_spec" | [grep ';[c-zC-Z]:/' >/dev/null]; then
1598
+        # It is most probably a Windows format PATH printed by
1599
+        # mingw gcc, but we are running on Cygwin. Gcc prints its search
1600
+        # path with ; separators, and with drive letters. We can handle the
1601
+        # drive letters (cygwin fileutils understands them), so leave them,
1602
+        # especially as we might pass files found there to a mingw objdump,
1603
+        # which wouldn't understand a cygwinified path. Ahh.
1604
+        sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED -e 's/;/ /g'`
1605
+      else
1606
+        sys_lib_search_path_spec=`echo "$sys_lib_search_path_spec" | $SED  -e "s/$PATH_SEPARATOR/ /g"`
1607
+      fi
1608
+      ;;
1609
+    pw32*)
1610
+      # pw32 DLLs use 'pw' prefix rather than 'lib'
1611
+      library_names_spec='`echo ${libname} | sed -e 's/^lib/pw/'``echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext}'
1612
+      ;;
1613
+    esac
1614
+    ;;
1615
+
1616
+  *)
1617
+    library_names_spec='${libname}`echo ${release} | $SED -e 's/[[.]]/-/g'`${versuffix}${shared_ext} $libname.lib'
1618
+    ;;
1619
+  esac
1620
+  dynamic_linker='Win32 ld.exe'
1621
+  # FIXME: first we should search . and the directory the executable is in
1622
+  shlibpath_var=PATH
1623
+  ;;
1624
+
1625
+darwin* | rhapsody*)
1626
+  dynamic_linker="$host_os dyld"
1627
+  version_type=darwin
1628
+  need_lib_prefix=no
1629
+  need_version=no
1630
+  library_names_spec='${libname}${release}${versuffix}$shared_ext ${libname}${release}${major}$shared_ext ${libname}$shared_ext'
1631
+  soname_spec='${libname}${release}${major}$shared_ext'
1632
+  shlibpath_overrides_runpath=yes
1633
+  shlibpath_var=DYLD_LIBRARY_PATH
1634
+  shrext_cmds='`test .$module = .yes && echo .so || echo .dylib`'
1635
+  m4_if([$1], [],[
1636
+  sys_lib_search_path_spec="$sys_lib_search_path_spec /usr/local/lib"]) 
1637
+  sys_lib_dlsearch_path_spec='/usr/local/lib /lib /usr/lib'
1638
+  ;;
1639
+
1640
+dgux*)
1641
+  version_type=linux
1642
+  need_lib_prefix=no
1643
+  need_version=no
1644
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname$shared_ext'
1645
+  soname_spec='${libname}${release}${shared_ext}$major'
1646
+  shlibpath_var=LD_LIBRARY_PATH
1647
+  ;;
1648
+
1649
+freebsd1*)
1650
+  dynamic_linker=no
1651
+  ;;
1652
+
1653
+freebsd* | dragonfly*)
1654
+  # DragonFly does not have aout.  When/if they implement a new
1655
+  # versioning mechanism, adjust this.
1656
+  if test -x /usr/bin/objformat; then
1657
+    objformat=`/usr/bin/objformat`
1658
+  else
1659
+    case $host_os in
1660
+    freebsd[[123]]*) objformat=aout ;;
1661
+    *) objformat=elf ;;
1662
+    esac
1663
+  fi
1664
+  version_type=freebsd-$objformat
1665
+  case $version_type in
1666
+    freebsd-elf*)
1667
+      library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
1668
+      need_version=no
1669
+      need_lib_prefix=no
1670
+      ;;
1671
+    freebsd-*)
1672
+      library_names_spec='${libname}${release}${shared_ext}$versuffix $libname${shared_ext}$versuffix'
1673
+      need_version=yes
1674
+      ;;
1675
+  esac
1676
+  shlibpath_var=LD_LIBRARY_PATH
1677
+  case $host_os in
1678
+  freebsd2*)
1679
+    shlibpath_overrides_runpath=yes
1680
+    ;;
1681
+  freebsd3.[[01]]* | freebsdelf3.[[01]]*)
1682
+    shlibpath_overrides_runpath=yes
1683
+    hardcode_into_libs=yes
1684
+    ;;
1685
+  freebsd3.[[2-9]]* | freebsdelf3.[[2-9]]* | \
1686
+  freebsd4.[[0-5]] | freebsdelf4.[[0-5]] | freebsd4.1.1 | freebsdelf4.1.1)
1687
+    shlibpath_overrides_runpath=no
1688
+    hardcode_into_libs=yes
1689
+    ;;
1690
+  *) # from 4.6 on, and DragonFly
1691
+    shlibpath_overrides_runpath=yes
1692
+    hardcode_into_libs=yes
1693
+    ;;
1694
+  esac
1695
+  ;;
1696
+
1697
+gnu*)
1698
+  version_type=linux
1699
+  need_lib_prefix=no
1700
+  need_version=no
1701
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}${major} ${libname}${shared_ext}'
1702
+  soname_spec='${libname}${release}${shared_ext}$major'
1703
+  shlibpath_var=LD_LIBRARY_PATH
1704
+  hardcode_into_libs=yes
1705
+  ;;
1706
+
1707
+hpux9* | hpux10* | hpux11*)
1708
+  # Give a soname corresponding to the major version so that dld.sl refuses to
1709
+  # link against other versions.
1710
+  version_type=sunos
1711
+  need_lib_prefix=no
1712
+  need_version=no
1713
+  case $host_cpu in
1714
+  ia64*)
1715
+    shrext_cmds='.so'
1716
+    hardcode_into_libs=yes
1717
+    dynamic_linker="$host_os dld.so"
1718
+    shlibpath_var=LD_LIBRARY_PATH
1719
+    shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
1720
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
1721
+    soname_spec='${libname}${release}${shared_ext}$major'
1722
+    if test "X$HPUX_IA64_MODE" = X32; then
1723
+      sys_lib_search_path_spec="/usr/lib/hpux32 /usr/local/lib/hpux32 /usr/local/lib"
1724
+    else
1725
+      sys_lib_search_path_spec="/usr/lib/hpux64 /usr/local/lib/hpux64"
1726
+    fi
1727
+    sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
1728
+    ;;
1729
+   hppa*64*)
1730
+     shrext_cmds='.sl'
1731
+     hardcode_into_libs=yes
1732
+     dynamic_linker="$host_os dld.sl"
1733
+     shlibpath_var=LD_LIBRARY_PATH # How should we handle SHLIB_PATH
1734
+     shlibpath_overrides_runpath=yes # Unless +noenvvar is specified.
1735
+     library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
1736
+     soname_spec='${libname}${release}${shared_ext}$major'
1737
+     sys_lib_search_path_spec="/usr/lib/pa20_64 /usr/ccs/lib/pa20_64"
1738
+     sys_lib_dlsearch_path_spec=$sys_lib_search_path_spec
1739
+     ;;
1740
+   *)
1741
+    shrext_cmds='.sl'
1742
+    dynamic_linker="$host_os dld.sl"
1743
+    shlibpath_var=SHLIB_PATH
1744
+    shlibpath_overrides_runpath=no # +s is required to enable SHLIB_PATH
1745
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
1746
+    soname_spec='${libname}${release}${shared_ext}$major'
1747
+    ;;
1748
+  esac
1749
+  # HP-UX runs *really* slowly unless shared libraries are mode 555.
1750
+  postinstall_cmds='chmod 555 $lib'
1751
+  ;;
1752
+
1753
+interix[[3-9]]*)
1754
+  version_type=linux
1755
+  need_lib_prefix=no
1756
+  need_version=no
1757
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
1758
+  soname_spec='${libname}${release}${shared_ext}$major'
1759
+  dynamic_linker='Interix 3.x ld.so.1 (PE, like ELF)'
1760
+  shlibpath_var=LD_LIBRARY_PATH
1761
+  shlibpath_overrides_runpath=no
1762
+  hardcode_into_libs=yes
1763
+  ;;
1764
+
1765
+irix5* | irix6* | nonstopux*)
1766
+  case $host_os in
1767
+    nonstopux*) version_type=nonstopux ;;
1768
+    *)
1769
+	if test "$lt_cv_prog_gnu_ld" = yes; then
1770
+		version_type=linux
1771
+	else
1772
+		version_type=irix
1773
+	fi ;;
1774
+  esac
1775
+  need_lib_prefix=no
1776
+  need_version=no
1777
+  soname_spec='${libname}${release}${shared_ext}$major'
1778
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${release}${shared_ext} $libname${shared_ext}'
1779
+  case $host_os in
1780
+  irix5* | nonstopux*)
1781
+    libsuff= shlibsuff=
1782
+    ;;
1783
+  *)
1784
+    case $LD in # libtool.m4 will add one of these switches to LD
1785
+    *-32|*"-32 "|*-melf32bsmip|*"-melf32bsmip ")
1786
+      libsuff= shlibsuff= libmagic=32-bit;;
1787
+    *-n32|*"-n32 "|*-melf32bmipn32|*"-melf32bmipn32 ")
1788
+      libsuff=32 shlibsuff=N32 libmagic=N32;;
1789
+    *-64|*"-64 "|*-melf64bmip|*"-melf64bmip ")
1790
+      libsuff=64 shlibsuff=64 libmagic=64-bit;;
1791
+    *) libsuff= shlibsuff= libmagic=never-match;;
1792
+    esac
1793
+    ;;
1794
+  esac
1795
+  shlibpath_var=LD_LIBRARY${shlibsuff}_PATH
1796
+  shlibpath_overrides_runpath=no
1797
+  sys_lib_search_path_spec="/usr/lib${libsuff} /lib${libsuff} /usr/local/lib${libsuff}"
1798
+  sys_lib_dlsearch_path_spec="/usr/lib${libsuff} /lib${libsuff}"
1799
+  hardcode_into_libs=yes
1800
+  ;;
1801
+
1802
+# No shared lib support for Linux oldld, aout, or coff.
1803
+linux*oldld* | linux*aout* | linux*coff*)
1804
+  dynamic_linker=no
1805
+  ;;
1806
+
1807
+# This must be Linux ELF.
1808
+linux* | k*bsd*-gnu)
1809
+  version_type=linux
1810
+  need_lib_prefix=no
1811
+  need_version=no
1812
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
1813
+  soname_spec='${libname}${release}${shared_ext}$major'
1814
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -n $libdir'
1815
+  shlibpath_var=LD_LIBRARY_PATH
1816
+  shlibpath_overrides_runpath=no
1817
+  # This implies no fast_install, which is unacceptable.
1818
+  # Some rework will be needed to allow for fast_install
1819
+  # before this can be enabled.
1820
+  hardcode_into_libs=yes
1821
+
1822
+  # Append ld.so.conf contents to the search path
1823
+  if test -f /etc/ld.so.conf; then
1824
+    lt_ld_extra=`awk '/^include / { system(sprintf("cd /etc; cat %s 2>/dev/null", \[$]2)); skip = 1; } { if (!skip) print \[$]0; skip = 0; }' < /etc/ld.so.conf | $SED -e 's/#.*//;/^[ 	]*hwcap[ 	]/d;s/[:,	]/ /g;s/=[^=]*$//;s/=[^= ]* / /g;/^$/d' | tr '\n' ' '`
1825
+    sys_lib_dlsearch_path_spec="/lib /usr/lib $lt_ld_extra"
1826
+  fi
1827
+
1828
+  # We used to test for /lib/ld.so.1 and disable shared libraries on
1829
+  # powerpc, because MkLinux only supported shared libraries with the
1830
+  # GNU dynamic linker.  Since this was broken with cross compilers,
1831
+  # most powerpc-linux boxes support dynamic linking these days and
1832
+  # people can always --disable-shared, the test was removed, and we
1833
+  # assume the GNU/Linux dynamic linker is in use.
1834
+  dynamic_linker='GNU/Linux ld.so'
1835
+  ;;
1836
+
1837
+netbsdelf*-gnu)
1838
+  version_type=linux
1839
+  need_lib_prefix=no
1840
+  need_version=no
1841
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
1842
+  soname_spec='${libname}${release}${shared_ext}$major'
1843
+  shlibpath_var=LD_LIBRARY_PATH
1844
+  shlibpath_overrides_runpath=no
1845
+  hardcode_into_libs=yes
1846
+  dynamic_linker='NetBSD ld.elf_so'
1847
+  ;;
1848
+
1849
+netbsd*)
1850
+  version_type=sunos
1851
+  need_lib_prefix=no
1852
+  need_version=no
1853
+  if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
1854
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
1855
+    finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
1856
+    dynamic_linker='NetBSD (a.out) ld.so'
1857
+  else
1858
+    library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major ${libname}${shared_ext}'
1859
+    soname_spec='${libname}${release}${shared_ext}$major'
1860
+    dynamic_linker='NetBSD ld.elf_so'
1861
+  fi
1862
+  shlibpath_var=LD_LIBRARY_PATH
1863
+  shlibpath_overrides_runpath=yes
1864
+  hardcode_into_libs=yes
1865
+  ;;
1866
+
1867
+newsos6)
1868
+  version_type=linux
1869
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
1870
+  shlibpath_var=LD_LIBRARY_PATH
1871
+  shlibpath_overrides_runpath=yes
1872
+  ;;
1873
+
1874
+nto-qnx*)
1875
+  version_type=linux
1876
+  need_lib_prefix=no
1877
+  need_version=no
1878
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
1879
+  soname_spec='${libname}${release}${shared_ext}$major'
1880
+  shlibpath_var=LD_LIBRARY_PATH
1881
+  shlibpath_overrides_runpath=yes
1882
+  ;;
1883
+
1884
+openbsd*)
1885
+  version_type=sunos
1886
+  sys_lib_dlsearch_path_spec="/usr/lib"
1887
+  need_lib_prefix=no
1888
+  # Some older versions of OpenBSD (3.3 at least) *do* need versioned libs.
1889
+  case $host_os in
1890
+    openbsd3.3 | openbsd3.3.*) need_version=yes ;;
1891
+    *)                         need_version=no  ;;
1892
+  esac
1893
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
1894
+  finish_cmds='PATH="\$PATH:/sbin" ldconfig -m $libdir'
1895
+  shlibpath_var=LD_LIBRARY_PATH
1896
+  if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
1897
+    case $host_os in
1898
+      openbsd2.[[89]] | openbsd2.[[89]].*)
1899
+	shlibpath_overrides_runpath=no
1900
+	;;
1901
+      *)
1902
+	shlibpath_overrides_runpath=yes
1903
+	;;
1904
+      esac
1905
+  else
1906
+    shlibpath_overrides_runpath=yes
1907
+  fi
1908
+  ;;
1909
+
1910
+os2*)
1911
+  libname_spec='$name'
1912
+  shrext_cmds=".dll"
1913
+  need_lib_prefix=no
1914
+  library_names_spec='$libname${shared_ext} $libname.a'
1915
+  dynamic_linker='OS/2 ld.exe'
1916
+  shlibpath_var=LIBPATH
1917
+  ;;
1918
+
1919
+osf3* | osf4* | osf5*)
1920
+  version_type=osf
1921
+  need_lib_prefix=no
1922
+  need_version=no
1923
+  soname_spec='${libname}${release}${shared_ext}$major'
1924
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
1925
+  shlibpath_var=LD_LIBRARY_PATH
1926
+  sys_lib_search_path_spec="/usr/shlib /usr/ccs/lib /usr/lib/cmplrs/cc /usr/lib /usr/local/lib /var/shlib"
1927
+  sys_lib_dlsearch_path_spec="$sys_lib_search_path_spec"
1928
+  ;;
1929
+
1930
+rdos*)
1931
+  dynamic_linker=no
1932
+  ;;
1933
+
1934
+solaris*)
1935
+  version_type=linux
1936
+  need_lib_prefix=no
1937
+  need_version=no
1938
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
1939
+  soname_spec='${libname}${release}${shared_ext}$major'
1940
+  shlibpath_var=LD_LIBRARY_PATH
1941
+  shlibpath_overrides_runpath=yes
1942
+  hardcode_into_libs=yes
1943
+  # ldd complains unless libraries are executable
1944
+  postinstall_cmds='chmod +x $lib'
1945
+  ;;
1946
+
1947
+sunos4*)
1948
+  version_type=sunos
1949
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${shared_ext}$versuffix'
1950
+  finish_cmds='PATH="\$PATH:/usr/etc" ldconfig $libdir'
1951
+  shlibpath_var=LD_LIBRARY_PATH
1952
+  shlibpath_overrides_runpath=yes
1953
+  if test "$with_gnu_ld" = yes; then
1954
+    need_lib_prefix=no
1955
+  fi
1956
+  need_version=yes
1957
+  ;;
1958
+
1959
+sysv4 | sysv4.3*)
1960
+  version_type=linux
1961
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
1962
+  soname_spec='${libname}${release}${shared_ext}$major'
1963
+  shlibpath_var=LD_LIBRARY_PATH
1964
+  case $host_vendor in
1965
+    sni)
1966
+      shlibpath_overrides_runpath=no
1967
+      need_lib_prefix=no
1968
+      export_dynamic_flag_spec='${wl}-Blargedynsym'
1969
+      runpath_var=LD_RUN_PATH
1970
+      ;;
1971
+    siemens)
1972
+      need_lib_prefix=no
1973
+      ;;
1974
+    motorola)
1975
+      need_lib_prefix=no
1976
+      need_version=no
1977
+      shlibpath_overrides_runpath=no
1978
+      sys_lib_search_path_spec='/lib /usr/lib /usr/ccs/lib'
1979
+      ;;
1980
+  esac
1981
+  ;;
1982
+
1983
+sysv4*MP*)
1984
+  if test -d /usr/nec ;then
1985
+    version_type=linux
1986
+    library_names_spec='$libname${shared_ext}.$versuffix $libname${shared_ext}.$major $libname${shared_ext}'
1987
+    soname_spec='$libname${shared_ext}.$major'
1988
+    shlibpath_var=LD_LIBRARY_PATH
1989
+  fi
1990
+  ;;
1991
+
1992
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
1993
+  version_type=freebsd-elf
1994
+  need_lib_prefix=no
1995
+  need_version=no
1996
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext} $libname${shared_ext}'
1997
+  soname_spec='${libname}${release}${shared_ext}$major'
1998
+  shlibpath_var=LD_LIBRARY_PATH
1999
+  hardcode_into_libs=yes
2000
+  if test "$with_gnu_ld" = yes; then
2001
+    sys_lib_search_path_spec='/usr/local/lib /usr/gnu/lib /usr/ccs/lib /usr/lib /lib'
2002
+    shlibpath_overrides_runpath=no
2003
+  else
2004
+    sys_lib_search_path_spec='/usr/ccs/lib /usr/lib'
2005
+    shlibpath_overrides_runpath=yes
2006
+    case $host_os in
2007
+      sco3.2v5*)
2008
+        sys_lib_search_path_spec="$sys_lib_search_path_spec /lib"
2009
+	;;
2010
+    esac
2011
+  fi
2012
+  sys_lib_dlsearch_path_spec='/usr/lib'
2013
+  ;;
2014
+
2015
+uts4*)
2016
+  version_type=linux
2017
+  library_names_spec='${libname}${release}${shared_ext}$versuffix ${libname}${release}${shared_ext}$major $libname${shared_ext}'
2018
+  soname_spec='${libname}${release}${shared_ext}$major'
2019
+  shlibpath_var=LD_LIBRARY_PATH
2020
+  ;;
2021
+
2022
+*)
2023
+  dynamic_linker=no
2024
+  ;;
2025
+esac
2026
+AC_MSG_RESULT([$dynamic_linker])
2027
+test "$dynamic_linker" = no && can_build_shared=no
2028
+
2029
+AC_CACHE_VAL([lt_cv_sys_lib_search_path_spec],
2030
+[lt_cv_sys_lib_search_path_spec="$sys_lib_search_path_spec"])
2031
+sys_lib_search_path_spec="$lt_cv_sys_lib_search_path_spec"
2032
+AC_CACHE_VAL([lt_cv_sys_lib_dlsearch_path_spec],
2033
+[lt_cv_sys_lib_dlsearch_path_spec="$sys_lib_dlsearch_path_spec"])
2034
+sys_lib_dlsearch_path_spec="$lt_cv_sys_lib_dlsearch_path_spec"
2035
+
2036
+variables_saved_for_relink="PATH $shlibpath_var $runpath_var"
2037
+if test "$GCC" = yes; then
2038
+  variables_saved_for_relink="$variables_saved_for_relink GCC_EXEC_PREFIX COMPILER_PATH LIBRARY_PATH"
2039
+fi
2040
+])# AC_LIBTOOL_SYS_DYNAMIC_LINKER
2041
+
2042
+
2043
+# _LT_AC_TAGCONFIG
2044
+# ----------------
2045
+AC_DEFUN([_LT_AC_TAGCONFIG],
2046
+[AC_REQUIRE([LT_AC_PROG_SED])dnl
2047
+AC_ARG_WITH([tags],
2048
+    [AC_HELP_STRING([--with-tags@<:@=TAGS@:>@],
2049
+        [include additional configurations @<:@automatic@:>@])],
2050
+    [tagnames="$withval"])
2051
+
2052
+if test -f "$ltmain" && test -n "$tagnames"; then
2053
+  if test ! -f "${ofile}"; then
2054
+    AC_MSG_WARN([output file `$ofile' does not exist])
2055
+  fi
2056
+
2057
+  if test -z "$LTCC"; then
2058
+    eval "`$SHELL ${ofile} --config | grep '^LTCC='`"
2059
+    if test -z "$LTCC"; then
2060
+      AC_MSG_WARN([output file `$ofile' does not look like a libtool script])
2061
+    else
2062
+      AC_MSG_WARN([using `LTCC=$LTCC', extracted from `$ofile'])
2063
+    fi
2064
+  fi
2065
+  if test -z "$LTCFLAGS"; then
2066
+    eval "`$SHELL ${ofile} --config | grep '^LTCFLAGS='`"
2067
+  fi
2068
+
2069
+  # Extract list of available tagged configurations in $ofile.
2070
+  # Note that this assumes the entire list is on one line.
2071
+  available_tags=`grep "^available_tags=" "${ofile}" | $SED -e 's/available_tags=\(.*$\)/\1/' -e 's/\"//g'`
2072
+
2073
+  lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
2074
+  for tagname in $tagnames; do
2075
+    IFS="$lt_save_ifs"
2076
+    # Check whether tagname contains only valid characters
2077
+    case `$echo "X$tagname" | $Xsed -e 's:[[-_ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890,/]]::g'` in
2078
+    "") ;;
2079
+    *)  AC_MSG_ERROR([invalid tag name: $tagname])
2080
+	;;
2081
+    esac
2082
+
2083
+    if grep "^# ### BEGIN LIBTOOL TAG CONFIG: $tagname$" < "${ofile}" > /dev/null
2084
+    then
2085
+      AC_MSG_ERROR([tag name \"$tagname\" already exists])
2086
+    fi
2087
+
2088
+    # Update the list of available tags.
2089
+    if test -n "$tagname"; then
2090
+      echo appending configuration tag \"$tagname\" to $ofile
2091
+
2092
+      case $tagname in
2093
+      CXX)
2094
+	if test -n "$CXX" && ( test "X$CXX" != "Xno" &&
2095
+	    ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) ||
2096
+	    (test "X$CXX" != "Xg++"))) ; then
2097
+	  AC_LIBTOOL_LANG_CXX_CONFIG
2098
+	else
2099
+	  tagname=""
2100
+	fi
2101
+	;;
2102
+
2103
+      F77)
2104
+	if test -n "$F77" && test "X$F77" != "Xno"; then
2105
+	  AC_LIBTOOL_LANG_F77_CONFIG
2106
+	else
2107
+	  tagname=""
2108
+	fi
2109
+	;;
2110
+
2111
+      GCJ)
2112
+	if test -n "$GCJ" && test "X$GCJ" != "Xno"; then
2113
+	  AC_LIBTOOL_LANG_GCJ_CONFIG
2114
+	else
2115
+	  tagname=""
2116
+	fi
2117
+	;;
2118
+
2119
+      RC)
2120
+	AC_LIBTOOL_LANG_RC_CONFIG
2121
+	;;
2122
+
2123
+      *)
2124
+	AC_MSG_ERROR([Unsupported tag name: $tagname])
2125
+	;;
2126
+      esac
2127
+
2128
+      # Append the new tag name to the list of available tags.
2129
+      if test -n "$tagname" ; then
2130
+      available_tags="$available_tags $tagname"
2131
+    fi
2132
+    fi
2133
+  done
2134
+  IFS="$lt_save_ifs"
2135
+
2136
+  # Now substitute the updated list of available tags.
2137
+  if eval "sed -e 's/^available_tags=.*\$/available_tags=\"$available_tags\"/' \"$ofile\" > \"${ofile}T\""; then
2138
+    mv "${ofile}T" "$ofile"
2139
+    chmod +x "$ofile"
2140
+  else
2141
+    rm -f "${ofile}T"
2142
+    AC_MSG_ERROR([unable to update list of available tagged configurations.])
2143
+  fi
2144
+fi
2145
+])# _LT_AC_TAGCONFIG
2146
+
2147
+
2148
+# AC_LIBTOOL_DLOPEN
2149
+# -----------------
2150
+# enable checks for dlopen support
2151
+AC_DEFUN([AC_LIBTOOL_DLOPEN],
2152
+ [AC_BEFORE([$0],[AC_LIBTOOL_SETUP])
2153
+])# AC_LIBTOOL_DLOPEN
2154
+
2155
+
2156
+# AC_LIBTOOL_WIN32_DLL
2157
+# --------------------
2158
+# declare package support for building win32 DLLs
2159
+AC_DEFUN([AC_LIBTOOL_WIN32_DLL],
2160
+[AC_BEFORE([$0], [AC_LIBTOOL_SETUP])
2161
+])# AC_LIBTOOL_WIN32_DLL
2162
+
2163
+
2164
+# AC_ENABLE_SHARED([DEFAULT])
2165
+# ---------------------------
2166
+# implement the --enable-shared flag
2167
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
2168
+AC_DEFUN([AC_ENABLE_SHARED],
2169
+[define([AC_ENABLE_SHARED_DEFAULT], ifelse($1, no, no, yes))dnl
2170
+AC_ARG_ENABLE([shared],
2171
+    [AC_HELP_STRING([--enable-shared@<:@=PKGS@:>@],
2172
+	[build shared libraries @<:@default=]AC_ENABLE_SHARED_DEFAULT[@:>@])],
2173
+    [p=${PACKAGE-default}
2174
+    case $enableval in
2175
+    yes) enable_shared=yes ;;
2176
+    no) enable_shared=no ;;
2177
+    *)
2178
+      enable_shared=no
2179
+      # Look at the argument we got.  We use all the common list separators.
2180
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
2181
+      for pkg in $enableval; do
2182
+	IFS="$lt_save_ifs"
2183
+	if test "X$pkg" = "X$p"; then
2184
+	  enable_shared=yes
2185
+	fi
2186
+      done
2187
+      IFS="$lt_save_ifs"
2188
+      ;;
2189
+    esac],
2190
+    [enable_shared=]AC_ENABLE_SHARED_DEFAULT)
2191
+])# AC_ENABLE_SHARED
2192
+
2193
+
2194
+# AC_DISABLE_SHARED
2195
+# -----------------
2196
+# set the default shared flag to --disable-shared
2197
+AC_DEFUN([AC_DISABLE_SHARED],
2198
+[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
2199
+AC_ENABLE_SHARED(no)
2200
+])# AC_DISABLE_SHARED
2201
+
2202
+
2203
+# AC_ENABLE_STATIC([DEFAULT])
2204
+# ---------------------------
2205
+# implement the --enable-static flag
2206
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
2207
+AC_DEFUN([AC_ENABLE_STATIC],
2208
+[define([AC_ENABLE_STATIC_DEFAULT], ifelse($1, no, no, yes))dnl
2209
+AC_ARG_ENABLE([static],
2210
+    [AC_HELP_STRING([--enable-static@<:@=PKGS@:>@],
2211
+	[build static libraries @<:@default=]AC_ENABLE_STATIC_DEFAULT[@:>@])],
2212
+    [p=${PACKAGE-default}
2213
+    case $enableval in
2214
+    yes) enable_static=yes ;;
2215
+    no) enable_static=no ;;
2216
+    *)
2217
+     enable_static=no
2218
+      # Look at the argument we got.  We use all the common list separators.
2219
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
2220
+      for pkg in $enableval; do
2221
+	IFS="$lt_save_ifs"
2222
+	if test "X$pkg" = "X$p"; then
2223
+	  enable_static=yes
2224
+	fi
2225
+      done
2226
+      IFS="$lt_save_ifs"
2227
+      ;;
2228
+    esac],
2229
+    [enable_static=]AC_ENABLE_STATIC_DEFAULT)
2230
+])# AC_ENABLE_STATIC
2231
+
2232
+
2233
+# AC_DISABLE_STATIC
2234
+# -----------------
2235
+# set the default static flag to --disable-static
2236
+AC_DEFUN([AC_DISABLE_STATIC],
2237
+[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
2238
+AC_ENABLE_STATIC(no)
2239
+])# AC_DISABLE_STATIC
2240
+
2241
+
2242
+# AC_ENABLE_FAST_INSTALL([DEFAULT])
2243
+# ---------------------------------
2244
+# implement the --enable-fast-install flag
2245
+# DEFAULT is either `yes' or `no'.  If omitted, it defaults to `yes'.
2246
+AC_DEFUN([AC_ENABLE_FAST_INSTALL],
2247
+[define([AC_ENABLE_FAST_INSTALL_DEFAULT], ifelse($1, no, no, yes))dnl
2248
+AC_ARG_ENABLE([fast-install],
2249
+    [AC_HELP_STRING([--enable-fast-install@<:@=PKGS@:>@],
2250
+    [optimize for fast installation @<:@default=]AC_ENABLE_FAST_INSTALL_DEFAULT[@:>@])],
2251
+    [p=${PACKAGE-default}
2252
+    case $enableval in
2253
+    yes) enable_fast_install=yes ;;
2254
+    no) enable_fast_install=no ;;
2255
+    *)
2256
+      enable_fast_install=no
2257
+      # Look at the argument we got.  We use all the common list separators.
2258
+      lt_save_ifs="$IFS"; IFS="${IFS}$PATH_SEPARATOR,"
2259
+      for pkg in $enableval; do
2260
+	IFS="$lt_save_ifs"
2261
+	if test "X$pkg" = "X$p"; then
2262
+	  enable_fast_install=yes
2263
+	fi
2264
+      done
2265
+      IFS="$lt_save_ifs"
2266
+      ;;
2267
+    esac],
2268
+    [enable_fast_install=]AC_ENABLE_FAST_INSTALL_DEFAULT)
2269
+])# AC_ENABLE_FAST_INSTALL
2270
+
2271
+
2272
+# AC_DISABLE_FAST_INSTALL
2273
+# -----------------------
2274
+# set the default to --disable-fast-install
2275
+AC_DEFUN([AC_DISABLE_FAST_INSTALL],
2276
+[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
2277
+AC_ENABLE_FAST_INSTALL(no)
2278
+])# AC_DISABLE_FAST_INSTALL
2279
+
2280
+
2281
+# AC_LIBTOOL_PICMODE([MODE])
2282
+# --------------------------
2283
+# implement the --with-pic flag
2284
+# MODE is either `yes' or `no'.  If omitted, it defaults to `both'.
2285
+AC_DEFUN([AC_LIBTOOL_PICMODE],
2286
+[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
2287
+pic_mode=ifelse($#,1,$1,default)
2288
+])# AC_LIBTOOL_PICMODE
2289
+
2290
+
2291
+# AC_PROG_EGREP
2292
+# -------------
2293
+# This is predefined starting with Autoconf 2.54, so this conditional
2294
+# definition can be removed once we require Autoconf 2.54 or later.
2295
+m4_ifndef([AC_PROG_EGREP], [AC_DEFUN([AC_PROG_EGREP],
2296
+[AC_CACHE_CHECK([for egrep], [ac_cv_prog_egrep],
2297
+   [if echo a | (grep -E '(a|b)') >/dev/null 2>&1
2298
+    then ac_cv_prog_egrep='grep -E'
2299
+    else ac_cv_prog_egrep='egrep'
2300
+    fi])
2301
+ EGREP=$ac_cv_prog_egrep
2302
+ AC_SUBST([EGREP])
2303
+])])
2304
+
2305
+
2306
+# AC_PATH_TOOL_PREFIX
2307
+# -------------------
2308
+# find a file program which can recognize shared library
2309
+AC_DEFUN([AC_PATH_TOOL_PREFIX],
2310
+[AC_REQUIRE([AC_PROG_EGREP])dnl
2311
+AC_MSG_CHECKING([for $1])
2312
+AC_CACHE_VAL(lt_cv_path_MAGIC_CMD,
2313
+[case $MAGIC_CMD in
2314
+[[\\/*] |  ?:[\\/]*])
2315
+  lt_cv_path_MAGIC_CMD="$MAGIC_CMD" # Let the user override the test with a path.
2316
+  ;;
2317
+*)
2318
+  lt_save_MAGIC_CMD="$MAGIC_CMD"
2319
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
2320
+dnl $ac_dummy forces splitting on constant user-supplied paths.
2321
+dnl POSIX.2 word splitting is done only on the output of word expansions,
2322
+dnl not every word.  This closes a longstanding sh security hole.
2323
+  ac_dummy="ifelse([$2], , $PATH, [$2])"
2324
+  for ac_dir in $ac_dummy; do
2325
+    IFS="$lt_save_ifs"
2326
+    test -z "$ac_dir" && ac_dir=.
2327
+    if test -f $ac_dir/$1; then
2328
+      lt_cv_path_MAGIC_CMD="$ac_dir/$1"
2329
+      if test -n "$file_magic_test_file"; then
2330
+	case $deplibs_check_method in
2331
+	"file_magic "*)
2332
+	  file_magic_regex=`expr "$deplibs_check_method" : "file_magic \(.*\)"`
2333
+	  MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
2334
+	  if eval $file_magic_cmd \$file_magic_test_file 2> /dev/null |
2335
+	    $EGREP "$file_magic_regex" > /dev/null; then
2336
+	    :
2337
+	  else
2338
+	    cat <<EOF 1>&2
2339
+
2340
+*** Warning: the command libtool uses to detect shared libraries,
2341
+*** $file_magic_cmd, produces output that libtool cannot recognize.
2342
+*** The result is that libtool may fail to recognize shared libraries
2343
+*** as such.  This will affect the creation of libtool libraries that
2344
+*** depend on shared libraries, but programs linked with such libtool
2345
+*** libraries will work regardless of this problem.  Nevertheless, you
2346
+*** may want to report the problem to your system manager and/or to
2347
+*** bug-libtool@gnu.org
2348
+
2349
+EOF
2350
+	  fi ;;
2351
+	esac
2352
+      fi
2353
+      break
2354
+    fi
2355
+  done
2356
+  IFS="$lt_save_ifs"
2357
+  MAGIC_CMD="$lt_save_MAGIC_CMD"
2358
+  ;;
2359
+esac])
2360
+MAGIC_CMD="$lt_cv_path_MAGIC_CMD"
2361
+if test -n "$MAGIC_CMD"; then
2362
+  AC_MSG_RESULT($MAGIC_CMD)
2363
+else
2364
+  AC_MSG_RESULT(no)
2365
+fi
2366
+])# AC_PATH_TOOL_PREFIX
2367
+
2368
+
2369
+# AC_PATH_MAGIC
2370
+# -------------
2371
+# find a file program which can recognize a shared library
2372
+AC_DEFUN([AC_PATH_MAGIC],
2373
+[AC_PATH_TOOL_PREFIX(${ac_tool_prefix}file, /usr/bin$PATH_SEPARATOR$PATH)
2374
+if test -z "$lt_cv_path_MAGIC_CMD"; then
2375
+  if test -n "$ac_tool_prefix"; then
2376
+    AC_PATH_TOOL_PREFIX(file, /usr/bin$PATH_SEPARATOR$PATH)
2377
+  else
2378
+    MAGIC_CMD=:
2379
+  fi
2380
+fi
2381
+])# AC_PATH_MAGIC
2382
+
2383
+
2384
+# AC_PROG_LD
2385
+# ----------
2386
+# find the pathname to the GNU or non-GNU linker
2387
+AC_DEFUN([AC_PROG_LD],
2388
+[AC_ARG_WITH([gnu-ld],
2389
+    [AC_HELP_STRING([--with-gnu-ld],
2390
+	[assume the C compiler uses GNU ld @<:@default=no@:>@])],
2391
+    [test "$withval" = no || with_gnu_ld=yes],
2392
+    [with_gnu_ld=no])
2393
+AC_REQUIRE([LT_AC_PROG_SED])dnl
2394
+AC_REQUIRE([AC_PROG_CC])dnl
2395
+AC_REQUIRE([AC_CANONICAL_HOST])dnl
2396
+AC_REQUIRE([AC_CANONICAL_BUILD])dnl
2397
+ac_prog=ld
2398
+if test "$GCC" = yes; then
2399
+  # Check if gcc -print-prog-name=ld gives a path.
2400
+  AC_MSG_CHECKING([for ld used by $CC])
2401
+  case $host in
2402
+  *-*-mingw*)
2403
+    # gcc leaves a trailing carriage return which upsets mingw
2404
+    ac_prog=`($CC -print-prog-name=ld) 2>&5 | tr -d '\015'` ;;
2405
+  *)
2406
+    ac_prog=`($CC -print-prog-name=ld) 2>&5` ;;
2407
+  esac
2408
+  case $ac_prog in
2409
+    # Accept absolute paths.
2410
+    [[\\/]]* | ?:[[\\/]]*)
2411
+      re_direlt='/[[^/]][[^/]]*/\.\./'
2412
+      # Canonicalize the pathname of ld
2413
+      ac_prog=`echo $ac_prog| $SED 's%\\\\%/%g'`
2414
+      while echo $ac_prog | grep "$re_direlt" > /dev/null 2>&1; do
2415
+	ac_prog=`echo $ac_prog| $SED "s%$re_direlt%/%"`
2416
+      done
2417
+      test -z "$LD" && LD="$ac_prog"
2418
+      ;;
2419
+  "")
2420
+    # If it fails, then pretend we aren't using GCC.
2421
+    ac_prog=ld
2422
+    ;;
2423
+  *)
2424
+    # If it is relative, then search for the first ld in PATH.
2425
+    with_gnu_ld=unknown
2426
+    ;;
2427
+  esac
2428
+elif test "$with_gnu_ld" = yes; then
2429
+  AC_MSG_CHECKING([for GNU ld])
2430
+else
2431
+  AC_MSG_CHECKING([for non-GNU ld])
2432
+fi
2433
+AC_CACHE_VAL(lt_cv_path_LD,
2434
+[if test -z "$LD"; then
2435
+  lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
2436
+  for ac_dir in $PATH; do
2437
+    IFS="$lt_save_ifs"
2438
+    test -z "$ac_dir" && ac_dir=.
2439
+    if test -f "$ac_dir/$ac_prog" || test -f "$ac_dir/$ac_prog$ac_exeext"; then
2440
+      lt_cv_path_LD="$ac_dir/$ac_prog"
2441
+      # Check to see if the program is GNU ld.  I'd rather use --version,
2442
+      # but apparently some variants of GNU ld only accept -v.
2443
+      # Break only if it was the GNU/non-GNU ld that we prefer.
2444
+      case `"$lt_cv_path_LD" -v 2>&1 </dev/null` in
2445
+      *GNU* | *'with BFD'*)
2446
+	test "$with_gnu_ld" != no && break
2447
+	;;
2448
+      *)
2449
+	test "$with_gnu_ld" != yes && break
2450
+	;;
2451
+      esac
2452
+    fi
2453
+  done
2454
+  IFS="$lt_save_ifs"
2455
+else
2456
+  lt_cv_path_LD="$LD" # Let the user override the test with a path.
2457
+fi])
2458
+LD="$lt_cv_path_LD"
2459
+if test -n "$LD"; then
2460
+  AC_MSG_RESULT($LD)
2461
+else
2462
+  AC_MSG_RESULT(no)
2463
+fi
2464
+test -z "$LD" && AC_MSG_ERROR([no acceptable ld found in \$PATH])
2465
+AC_PROG_LD_GNU
2466
+])# AC_PROG_LD
2467
+
2468
+
2469
+# AC_PROG_LD_GNU
2470
+# --------------
2471
+AC_DEFUN([AC_PROG_LD_GNU],
2472
+[AC_REQUIRE([AC_PROG_EGREP])dnl
2473
+AC_CACHE_CHECK([if the linker ($LD) is GNU ld], lt_cv_prog_gnu_ld,
2474
+[# I'd rather use --version here, but apparently some GNU lds only accept -v.
2475
+case `$LD -v 2>&1 </dev/null` in
2476
+*GNU* | *'with BFD'*)
2477
+  lt_cv_prog_gnu_ld=yes
2478
+  ;;
2479
+*)
2480
+  lt_cv_prog_gnu_ld=no
2481
+  ;;
2482
+esac])
2483
+with_gnu_ld=$lt_cv_prog_gnu_ld
2484
+])# AC_PROG_LD_GNU
2485
+
2486
+
2487
+# AC_PROG_LD_RELOAD_FLAG
2488
+# ----------------------
2489
+# find reload flag for linker
2490
+#   -- PORTME Some linkers may need a different reload flag.
2491
+AC_DEFUN([AC_PROG_LD_RELOAD_FLAG],
2492
+[AC_CACHE_CHECK([for $LD option to reload object files],
2493
+  lt_cv_ld_reload_flag,
2494
+  [lt_cv_ld_reload_flag='-r'])
2495
+reload_flag=$lt_cv_ld_reload_flag
2496
+case $reload_flag in
2497
+"" | " "*) ;;
2498
+*) reload_flag=" $reload_flag" ;;
2499
+esac
2500
+reload_cmds='$LD$reload_flag -o $output$reload_objs'
2501
+case $host_os in
2502
+  darwin*)
2503
+    if test "$GCC" = yes; then
2504
+      reload_cmds='$LTCC $LTCFLAGS -nostdlib ${wl}-r -o $output$reload_objs'
2505
+    else
2506
+      reload_cmds='$LD$reload_flag -o $output$reload_objs'
2507
+    fi
2508
+    ;;
2509
+esac
2510
+])# AC_PROG_LD_RELOAD_FLAG
2511
+
2512
+
2513
+# AC_DEPLIBS_CHECK_METHOD
2514
+# -----------------------
2515
+# how to check for library dependencies
2516
+#  -- PORTME fill in with the dynamic library characteristics
2517
+AC_DEFUN([AC_DEPLIBS_CHECK_METHOD],
2518
+[AC_CACHE_CHECK([how to recognize dependent libraries],
2519
+lt_cv_deplibs_check_method,
2520
+[lt_cv_file_magic_cmd='$MAGIC_CMD'
2521
+lt_cv_file_magic_test_file=
2522
+lt_cv_deplibs_check_method='unknown'
2523
+# Need to set the preceding variable on all platforms that support
2524
+# interlibrary dependencies.
2525
+# 'none' -- dependencies not supported.
2526
+# `unknown' -- same as none, but documents that we really don't know.
2527
+# 'pass_all' -- all dependencies passed with no checks.
2528
+# 'test_compile' -- check by making test program.
2529
+# 'file_magic [[regex]]' -- check by looking for files in library path
2530
+# which responds to the $file_magic_cmd with a given extended regex.
2531
+# If you have `file' or equivalent on your system and you're not sure
2532
+# whether `pass_all' will *always* work, you probably want this one.
2533
+
2534
+case $host_os in
2535
+aix[[4-9]]*)
2536
+  lt_cv_deplibs_check_method=pass_all
2537
+  ;;
2538
+
2539
+beos*)
2540
+  lt_cv_deplibs_check_method=pass_all
2541
+  ;;
2542
+
2543
+bsdi[[45]]*)
2544
+  lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib)'
2545
+  lt_cv_file_magic_cmd='/usr/bin/file -L'
2546
+  lt_cv_file_magic_test_file=/shlib/libc.so
2547
+  ;;
2548
+
2549
+cygwin*)
2550
+  # func_win32_libid is a shell function defined in ltmain.sh
2551
+  lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
2552
+  lt_cv_file_magic_cmd='func_win32_libid'
2553
+  ;;
2554
+
2555
+mingw* | pw32*)
2556
+  # Base MSYS/MinGW do not provide the 'file' command needed by
2557
+  # func_win32_libid shell function, so use a weaker test based on 'objdump',
2558
+  # unless we find 'file', for example because we are cross-compiling.
2559
+  if ( file / ) >/dev/null 2>&1; then
2560
+    lt_cv_deplibs_check_method='file_magic ^x86 archive import|^x86 DLL'
2561
+    lt_cv_file_magic_cmd='func_win32_libid'
2562
+  else
2563
+    lt_cv_deplibs_check_method='file_magic file format pei*-i386(.*architecture: i386)?'
2564
+    lt_cv_file_magic_cmd='$OBJDUMP -f'
2565
+  fi
2566
+  ;;
2567
+
2568
+darwin* | rhapsody*)
2569
+  lt_cv_deplibs_check_method=pass_all
2570
+  ;;
2571
+
2572
+freebsd* | dragonfly*)
2573
+  if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then
2574
+    case $host_cpu in
2575
+    i*86 )
2576
+      # Not sure whether the presence of OpenBSD here was a mistake.
2577
+      # Let's accept both of them until this is cleared up.
2578
+      lt_cv_deplibs_check_method='file_magic (FreeBSD|OpenBSD|DragonFly)/i[[3-9]]86 (compact )?demand paged shared library'
2579
+      lt_cv_file_magic_cmd=/usr/bin/file
2580
+      lt_cv_file_magic_test_file=`echo /usr/lib/libc.so.*`
2581
+      ;;
2582
+    esac
2583
+  else
2584
+    lt_cv_deplibs_check_method=pass_all
2585
+  fi
2586
+  ;;
2587
+
2588
+gnu*)
2589
+  lt_cv_deplibs_check_method=pass_all
2590
+  ;;
2591
+
2592
+hpux10.20* | hpux11*)
2593
+  lt_cv_file_magic_cmd=/usr/bin/file
2594
+  case $host_cpu in
2595
+  ia64*)
2596
+    lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|ELF-[[0-9]][[0-9]]) shared object file - IA64'
2597
+    lt_cv_file_magic_test_file=/usr/lib/hpux32/libc.so
2598
+    ;;
2599
+  hppa*64*)
2600
+    [lt_cv_deplibs_check_method='file_magic (s[0-9][0-9][0-9]|ELF-[0-9][0-9]) shared object file - PA-RISC [0-9].[0-9]']
2601
+    lt_cv_file_magic_test_file=/usr/lib/pa20_64/libc.sl
2602
+    ;;
2603
+  *)
2604
+    lt_cv_deplibs_check_method='file_magic (s[[0-9]][[0-9]][[0-9]]|PA-RISC[[0-9]].[[0-9]]) shared library'
2605
+    lt_cv_file_magic_test_file=/usr/lib/libc.sl
2606
+    ;;
2607
+  esac
2608
+  ;;
2609
+
2610
+interix[[3-9]]*)
2611
+  # PIC code is broken on Interix 3.x, that's why |\.a not |_pic\.a here
2612
+  lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|\.a)$'
2613
+  ;;
2614
+
2615
+irix5* | irix6* | nonstopux*)
2616
+  case $LD in
2617
+  *-32|*"-32 ") libmagic=32-bit;;
2618
+  *-n32|*"-n32 ") libmagic=N32;;
2619
+  *-64|*"-64 ") libmagic=64-bit;;
2620
+  *) libmagic=never-match;;
2621
+  esac
2622
+  lt_cv_deplibs_check_method=pass_all
2623
+  ;;
2624
+
2625
+# This must be Linux ELF.
2626
+linux* | k*bsd*-gnu)
2627
+  lt_cv_deplibs_check_method=pass_all
2628
+  ;;
2629
+
2630
+netbsd* | netbsdelf*-gnu)
2631
+  if echo __ELF__ | $CC -E - | grep __ELF__ > /dev/null; then
2632
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
2633
+  else
2634
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so|_pic\.a)$'
2635
+  fi
2636
+  ;;
2637
+
2638
+newos6*)
2639
+  lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (executable|dynamic lib)'
2640
+  lt_cv_file_magic_cmd=/usr/bin/file
2641
+  lt_cv_file_magic_test_file=/usr/lib/libnls.so
2642
+  ;;
2643
+
2644
+nto-qnx*)
2645
+  lt_cv_deplibs_check_method=unknown
2646
+  ;;
2647
+
2648
+openbsd*)
2649
+  if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
2650
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|\.so|_pic\.a)$'
2651
+  else
2652
+    lt_cv_deplibs_check_method='match_pattern /lib[[^/]]+(\.so\.[[0-9]]+\.[[0-9]]+|_pic\.a)$'
2653
+  fi
2654
+  ;;
2655
+
2656
+osf3* | osf4* | osf5*)
2657
+  lt_cv_deplibs_check_method=pass_all
2658
+  ;;
2659
+
2660
+rdos*)
2661
+  lt_cv_deplibs_check_method=pass_all
2662
+  ;;
2663
+
2664
+solaris*)
2665
+  lt_cv_deplibs_check_method=pass_all
2666
+  ;;
2667
+
2668
+sysv4 | sysv4.3*)
2669
+  case $host_vendor in
2670
+  motorola)
2671
+    lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[ML]]SB (shared object|dynamic lib) M[[0-9]][[0-9]]* Version [[0-9]]'
2672
+    lt_cv_file_magic_test_file=`echo /usr/lib/libc.so*`
2673
+    ;;
2674
+  ncr)
2675
+    lt_cv_deplibs_check_method=pass_all
2676
+    ;;
2677
+  sequent)
2678
+    lt_cv_file_magic_cmd='/bin/file'
2679
+    lt_cv_deplibs_check_method='file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB (shared object|dynamic lib )'
2680
+    ;;
2681
+  sni)
2682
+    lt_cv_file_magic_cmd='/bin/file'
2683
+    lt_cv_deplibs_check_method="file_magic ELF [[0-9]][[0-9]]*-bit [[LM]]SB dynamic lib"
2684
+    lt_cv_file_magic_test_file=/lib/libc.so
2685
+    ;;
2686
+  siemens)
2687
+    lt_cv_deplibs_check_method=pass_all
2688
+    ;;
2689
+  pc)
2690
+    lt_cv_deplibs_check_method=pass_all
2691
+    ;;
2692
+  esac
2693
+  ;;
2694
+
2695
+sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX* | sysv4*uw2*)
2696
+  lt_cv_deplibs_check_method=pass_all
2697
+  ;;
2698
+esac
2699
+])
2700
+file_magic_cmd=$lt_cv_file_magic_cmd
2701
+deplibs_check_method=$lt_cv_deplibs_check_method
2702
+test -z "$deplibs_check_method" && deplibs_check_method=unknown
2703
+])# AC_DEPLIBS_CHECK_METHOD
2704
+
2705
+
2706
+# AC_PROG_NM
2707
+# ----------
2708
+# find the pathname to a BSD-compatible name lister
2709
+AC_DEFUN([AC_PROG_NM],
2710
+[AC_CACHE_CHECK([for BSD-compatible nm], lt_cv_path_NM,
2711
+[if test -n "$NM"; then
2712
+  # Let the user override the test.
2713
+  lt_cv_path_NM="$NM"
2714
+else
2715
+  lt_nm_to_check="${ac_tool_prefix}nm"
2716
+  if test -n "$ac_tool_prefix" && test "$build" = "$host"; then
2717
+    lt_nm_to_check="$lt_nm_to_check nm"
2718
+  fi
2719
+  for lt_tmp_nm in $lt_nm_to_check; do
2720
+    lt_save_ifs="$IFS"; IFS=$PATH_SEPARATOR
2721
+    for ac_dir in $PATH /usr/ccs/bin/elf /usr/ccs/bin /usr/ucb /bin; do
2722
+      IFS="$lt_save_ifs"
2723
+      test -z "$ac_dir" && ac_dir=.
2724
+      tmp_nm="$ac_dir/$lt_tmp_nm"
2725
+      if test -f "$tmp_nm" || test -f "$tmp_nm$ac_exeext" ; then
2726
+	# Check to see if the nm accepts a BSD-compat flag.
2727
+	# Adding the `sed 1q' prevents false positives on HP-UX, which says:
2728
+	#   nm: unknown option "B" ignored
2729
+	# Tru64's nm complains that /dev/null is an invalid object file
2730
+	case `"$tmp_nm" -B /dev/null 2>&1 | sed '1q'` in
2731
+	*/dev/null* | *'Invalid file or object type'*)
2732
+	  lt_cv_path_NM="$tmp_nm -B"
2733
+	  break
2734
+	  ;;
2735
+	*)
2736
+	  case `"$tmp_nm" -p /dev/null 2>&1 | sed '1q'` in
2737
+	  */dev/null*)
2738
+	    lt_cv_path_NM="$tmp_nm -p"
2739
+	    break
2740
+	    ;;
2741
+	  *)
2742
+	    lt_cv_path_NM=${lt_cv_path_NM="$tmp_nm"} # keep the first match, but
2743
+	    continue # so that we can try to find one that supports BSD flags
2744
+	    ;;
2745
+	  esac
2746
+	  ;;
2747
+	esac
2748
+      fi
2749
+    done
2750
+    IFS="$lt_save_ifs"
2751
+  done
2752
+  test -z "$lt_cv_path_NM" && lt_cv_path_NM=nm
2753
+fi])
2754
+NM="$lt_cv_path_NM"
2755
+])# AC_PROG_NM
2756
+
2757
+
2758
+# AC_CHECK_LIBM
2759
+# -------------
2760
+# check for math library
2761
+AC_DEFUN([AC_CHECK_LIBM],
2762
+[AC_REQUIRE([AC_CANONICAL_HOST])dnl
2763
+LIBM=
2764
+case $host in
2765
+*-*-beos* | *-*-cygwin* | *-*-pw32* | *-*-darwin*)
2766
+  # These system don't have libm, or don't need it
2767
+  ;;
2768
+*-ncr-sysv4.3*)
2769
+  AC_CHECK_LIB(mw, _mwvalidcheckl, LIBM="-lmw")
2770
+  AC_CHECK_LIB(m, cos, LIBM="$LIBM -lm")
2771
+  ;;
2772
+*)
2773
+  AC_CHECK_LIB(m, cos, LIBM="-lm")
2774
+  ;;
2775
+esac
2776
+])# AC_CHECK_LIBM
2777
+
2778
+
2779
+# AC_LIBLTDL_CONVENIENCE([DIRECTORY])
2780
+# -----------------------------------
2781
+# sets LIBLTDL to the link flags for the libltdl convenience library and
2782
+# LTDLINCL to the include flags for the libltdl header and adds
2783
+# --enable-ltdl-convenience to the configure arguments.  Note that
2784
+# AC_CONFIG_SUBDIRS is not called here.  If DIRECTORY is not provided,
2785
+# it is assumed to be `libltdl'.  LIBLTDL will be prefixed with
2786
+# '${top_builddir}/' and LTDLINCL will be prefixed with '${top_srcdir}/'
2787
+# (note the single quotes!).  If your package is not flat and you're not
2788
+# using automake, define top_builddir and top_srcdir appropriately in
2789
+# the Makefiles.
2790
+AC_DEFUN([AC_LIBLTDL_CONVENIENCE],
2791
+[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
2792
+  case $enable_ltdl_convenience in
2793
+  no) AC_MSG_ERROR([this package needs a convenience libltdl]) ;;
2794
+  "") enable_ltdl_convenience=yes
2795
+      ac_configure_args="$ac_configure_args --enable-ltdl-convenience" ;;
2796
+  esac
2797
+  LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdlc.la
2798
+  LTDLINCL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl'])
2799
+  # For backwards non-gettext consistent compatibility...
2800
+  INCLTDL="$LTDLINCL"
2801
+])# AC_LIBLTDL_CONVENIENCE
2802
+
2803
+
2804
+# AC_LIBLTDL_INSTALLABLE([DIRECTORY])
2805
+# -----------------------------------
2806
+# sets LIBLTDL to the link flags for the libltdl installable library and
2807
+# LTDLINCL to the include flags for the libltdl header and adds
2808
+# --enable-ltdl-install to the configure arguments.  Note that
2809
+# AC_CONFIG_SUBDIRS is not called here.  If DIRECTORY is not provided,
2810
+# and an installed libltdl is not found, it is assumed to be `libltdl'.
2811
+# LIBLTDL will be prefixed with '${top_builddir}/'# and LTDLINCL with
2812
+# '${top_srcdir}/' (note the single quotes!).  If your package is not
2813
+# flat and you're not using automake, define top_builddir and top_srcdir
2814
+# appropriately in the Makefiles.
2815
+# In the future, this macro may have to be called after AC_PROG_LIBTOOL.
2816
+AC_DEFUN([AC_LIBLTDL_INSTALLABLE],
2817
+[AC_BEFORE([$0],[AC_LIBTOOL_SETUP])dnl
2818
+  AC_CHECK_LIB(ltdl, lt_dlinit,
2819
+  [test x"$enable_ltdl_install" != xyes && enable_ltdl_install=no],
2820
+  [if test x"$enable_ltdl_install" = xno; then
2821
+     AC_MSG_WARN([libltdl not installed, but installation disabled])
2822
+   else
2823
+     enable_ltdl_install=yes
2824
+   fi
2825
+  ])
2826
+  if test x"$enable_ltdl_install" = x"yes"; then
2827
+    ac_configure_args="$ac_configure_args --enable-ltdl-install"
2828
+    LIBLTDL='${top_builddir}/'ifelse($#,1,[$1],['libltdl'])/libltdl.la
2829
+    LTDLINCL='-I${top_srcdir}/'ifelse($#,1,[$1],['libltdl'])
2830
+  else
2831
+    ac_configure_args="$ac_configure_args --enable-ltdl-install=no"
2832
+    LIBLTDL="-lltdl"
2833
+    LTDLINCL=
2834
+  fi
2835
+  # For backwards non-gettext consistent compatibility...
2836
+  INCLTDL="$LTDLINCL"
2837
+])# AC_LIBLTDL_INSTALLABLE
2838
+
2839
+
2840
+# AC_LIBTOOL_CXX
2841
+# --------------
2842
+# enable support for C++ libraries
2843
+AC_DEFUN([AC_LIBTOOL_CXX],
2844
+[AC_REQUIRE([_LT_AC_LANG_CXX])
2845
+])# AC_LIBTOOL_CXX
2846
+
2847
+
2848
+# _LT_AC_LANG_CXX
2849
+# ---------------
2850
+AC_DEFUN([_LT_AC_LANG_CXX],
2851
+[AC_REQUIRE([AC_PROG_CXX])
2852
+AC_REQUIRE([_LT_AC_PROG_CXXCPP])
2853
+_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}CXX])
2854
+])# _LT_AC_LANG_CXX
2855
+
2856
+# _LT_AC_PROG_CXXCPP
2857
+# ------------------
2858
+AC_DEFUN([_LT_AC_PROG_CXXCPP],
2859
+[
2860
+AC_REQUIRE([AC_PROG_CXX])
2861
+if test -n "$CXX" && ( test "X$CXX" != "Xno" &&
2862
+    ( (test "X$CXX" = "Xg++" && `g++ -v >/dev/null 2>&1` ) ||
2863
+    (test "X$CXX" != "Xg++"))) ; then
2864
+  AC_PROG_CXXCPP
2865
+fi
2866
+])# _LT_AC_PROG_CXXCPP
2867
+
2868
+# AC_LIBTOOL_F77
2869
+# --------------
2870
+# enable support for Fortran 77 libraries
2871
+AC_DEFUN([AC_LIBTOOL_F77],
2872
+[AC_REQUIRE([_LT_AC_LANG_F77])
2873
+])# AC_LIBTOOL_F77
2874
+
2875
+
2876
+# _LT_AC_LANG_F77
2877
+# ---------------
2878
+AC_DEFUN([_LT_AC_LANG_F77],
2879
+[AC_REQUIRE([AC_PROG_F77])
2880
+_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}F77])
2881
+])# _LT_AC_LANG_F77
2882
+
2883
+
2884
+# AC_LIBTOOL_GCJ
2885
+# --------------
2886
+# enable support for GCJ libraries
2887
+AC_DEFUN([AC_LIBTOOL_GCJ],
2888
+[AC_REQUIRE([_LT_AC_LANG_GCJ])
2889
+])# AC_LIBTOOL_GCJ
2890
+
2891
+
2892
+# _LT_AC_LANG_GCJ
2893
+# ---------------
2894
+AC_DEFUN([_LT_AC_LANG_GCJ],
2895
+[AC_PROVIDE_IFELSE([AC_PROG_GCJ],[],
2896
+  [AC_PROVIDE_IFELSE([A][M_PROG_GCJ],[],
2897
+    [AC_PROVIDE_IFELSE([LT_AC_PROG_GCJ],[],
2898
+      [ifdef([AC_PROG_GCJ],[AC_REQUIRE([AC_PROG_GCJ])],
2899
+	 [ifdef([A][M_PROG_GCJ],[AC_REQUIRE([A][M_PROG_GCJ])],
2900
+	   [AC_REQUIRE([A][C_PROG_GCJ_OR_A][M_PROG_GCJ])])])])])])
2901
+_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}GCJ])
2902
+])# _LT_AC_LANG_GCJ
2903
+
2904
+
2905
+# AC_LIBTOOL_RC
2906
+# -------------
2907
+# enable support for Windows resource files
2908
+AC_DEFUN([AC_LIBTOOL_RC],
2909
+[AC_REQUIRE([LT_AC_PROG_RC])
2910
+_LT_AC_SHELL_INIT([tagnames=${tagnames+${tagnames},}RC])
2911
+])# AC_LIBTOOL_RC
2912
+
2913
+
2914
+# AC_LIBTOOL_LANG_C_CONFIG
2915
+# ------------------------
2916
+# Ensure that the configuration vars for the C compiler are
2917
+# suitably defined.  Those variables are subsequently used by
2918
+# AC_LIBTOOL_CONFIG to write the compiler configuration to `libtool'.
2919
+AC_DEFUN([AC_LIBTOOL_LANG_C_CONFIG], [_LT_AC_LANG_C_CONFIG])
2920
+AC_DEFUN([_LT_AC_LANG_C_CONFIG],
2921
+[lt_save_CC="$CC"
2922
+AC_LANG_PUSH(C)
2923
+
2924
+# Source file extension for C test sources.
2925
+ac_ext=c
2926
+
2927
+# Object file extension for compiled C test sources.
2928
+objext=o
2929
+_LT_AC_TAGVAR(objext, $1)=$objext
2930
+
2931
+# Code to be used in simple compile tests
2932
+lt_simple_compile_test_code="int some_variable = 0;"
2933
+
2934
+# Code to be used in simple link tests
2935
+lt_simple_link_test_code='int main(){return(0);}'
2936
+
2937
+_LT_AC_SYS_COMPILER
2938
+
2939
+# save warnings/boilerplate of simple test code
2940
+_LT_COMPILER_BOILERPLATE
2941
+_LT_LINKER_BOILERPLATE
2942
+
2943
+AC_LIBTOOL_PROG_COMPILER_NO_RTTI($1)
2944
+AC_LIBTOOL_PROG_COMPILER_PIC($1)
2945
+AC_LIBTOOL_PROG_CC_C_O($1)
2946
+AC_LIBTOOL_SYS_HARD_LINK_LOCKS($1)
2947
+AC_LIBTOOL_PROG_LD_SHLIBS($1)
2948
+AC_LIBTOOL_SYS_DYNAMIC_LINKER($1)
2949
+AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH($1)
2950
+AC_LIBTOOL_SYS_LIB_STRIP
2951
+AC_LIBTOOL_DLOPEN_SELF
2952
+
2953
+# Report which library types will actually be built
2954
+AC_MSG_CHECKING([if libtool supports shared libraries])
2955
+AC_MSG_RESULT([$can_build_shared])
2956
+
2957
+AC_MSG_CHECKING([whether to build shared libraries])
2958
+test "$can_build_shared" = "no" && enable_shared=no
2959
+
2960
+# On AIX, shared libraries and static libraries use the same namespace, and
2961
+# are all built from PIC.
2962
+case $host_os in
2963
+aix3*)
2964
+  test "$enable_shared" = yes && enable_static=no
2965
+  if test -n "$RANLIB"; then
2966
+    archive_cmds="$archive_cmds~\$RANLIB \$lib"
2967
+    postinstall_cmds='$RANLIB $lib'
2968
+  fi
2969
+  ;;
2970
+
2971
+aix[[4-9]]*)
2972
+  if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
2973
+    test "$enable_shared" = yes && enable_static=no
2974
+  fi
2975
+    ;;
2976
+esac
2977
+AC_MSG_RESULT([$enable_shared])
2978
+
2979
+AC_MSG_CHECKING([whether to build static libraries])
2980
+# Make sure either enable_shared or enable_static is yes.
2981
+test "$enable_shared" = yes || enable_static=yes
2982
+AC_MSG_RESULT([$enable_static])
2983
+
2984
+AC_LIBTOOL_CONFIG($1)
2985
+
2986
+AC_LANG_POP
2987
+CC="$lt_save_CC"
2988
+])# AC_LIBTOOL_LANG_C_CONFIG
2989
+
2990
+
2991
+# AC_LIBTOOL_LANG_CXX_CONFIG
2992
+# --------------------------
2993
+# Ensure that the configuration vars for the C compiler are
2994
+# suitably defined.  Those variables are subsequently used by
2995
+# AC_LIBTOOL_CONFIG to write the compiler configuration to `libtool'.
2996
+AC_DEFUN([AC_LIBTOOL_LANG_CXX_CONFIG], [_LT_AC_LANG_CXX_CONFIG(CXX)])
2997
+AC_DEFUN([_LT_AC_LANG_CXX_CONFIG],
2998
+[AC_LANG_PUSH(C++)
2999
+AC_REQUIRE([AC_PROG_CXX])
3000
+AC_REQUIRE([_LT_AC_PROG_CXXCPP])
3001
+
3002
+_LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
3003
+_LT_AC_TAGVAR(allow_undefined_flag, $1)=
3004
+_LT_AC_TAGVAR(always_export_symbols, $1)=no
3005
+_LT_AC_TAGVAR(archive_expsym_cmds, $1)=
3006
+_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)=
3007
+_LT_AC_TAGVAR(hardcode_direct, $1)=no
3008
+_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)=
3009
+_LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
3010
+_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=
3011
+_LT_AC_TAGVAR(hardcode_minus_L, $1)=no
3012
+_LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
3013
+_LT_AC_TAGVAR(hardcode_automatic, $1)=no
3014
+_LT_AC_TAGVAR(module_cmds, $1)=
3015
+_LT_AC_TAGVAR(module_expsym_cmds, $1)=
3016
+_LT_AC_TAGVAR(link_all_deplibs, $1)=unknown
3017
+_LT_AC_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
3018
+_LT_AC_TAGVAR(no_undefined_flag, $1)=
3019
+_LT_AC_TAGVAR(whole_archive_flag_spec, $1)=
3020
+_LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=no
3021
+
3022
+# Dependencies to place before and after the object being linked:
3023
+_LT_AC_TAGVAR(predep_objects, $1)=
3024
+_LT_AC_TAGVAR(postdep_objects, $1)=
3025
+_LT_AC_TAGVAR(predeps, $1)=
3026
+_LT_AC_TAGVAR(postdeps, $1)=
3027
+_LT_AC_TAGVAR(compiler_lib_search_path, $1)=
3028
+_LT_AC_TAGVAR(compiler_lib_search_dirs, $1)=
3029
+
3030
+# Source file extension for C++ test sources.
3031
+ac_ext=cpp
3032
+
3033
+# Object file extension for compiled C++ test sources.
3034
+objext=o
3035
+_LT_AC_TAGVAR(objext, $1)=$objext
3036
+
3037
+# Code to be used in simple compile tests
3038
+lt_simple_compile_test_code="int some_variable = 0;"
3039
+
3040
+# Code to be used in simple link tests
3041
+lt_simple_link_test_code='int main(int, char *[[]]) { return(0); }'
3042
+
3043
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
3044
+_LT_AC_SYS_COMPILER
3045
+
3046
+# save warnings/boilerplate of simple test code
3047
+_LT_COMPILER_BOILERPLATE
3048
+_LT_LINKER_BOILERPLATE
3049
+
3050
+# Allow CC to be a program name with arguments.
3051
+lt_save_CC=$CC
3052
+lt_save_LD=$LD
3053
+lt_save_GCC=$GCC
3054
+GCC=$GXX
3055
+lt_save_with_gnu_ld=$with_gnu_ld
3056
+lt_save_path_LD=$lt_cv_path_LD
3057
+if test -n "${lt_cv_prog_gnu_ldcxx+set}"; then
3058
+  lt_cv_prog_gnu_ld=$lt_cv_prog_gnu_ldcxx
3059
+else
3060
+  $as_unset lt_cv_prog_gnu_ld
3061
+fi
3062
+if test -n "${lt_cv_path_LDCXX+set}"; then
3063
+  lt_cv_path_LD=$lt_cv_path_LDCXX
3064
+else
3065
+  $as_unset lt_cv_path_LD
3066
+fi
3067
+test -z "${LDCXX+set}" || LD=$LDCXX
3068
+CC=${CXX-"c++"}
3069
+compiler=$CC
3070
+_LT_AC_TAGVAR(compiler, $1)=$CC
3071
+_LT_CC_BASENAME([$compiler])
3072
+
3073
+# We don't want -fno-exception wen compiling C++ code, so set the
3074
+# no_builtin_flag separately
3075
+if test "$GXX" = yes; then
3076
+  _LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin'
3077
+else
3078
+  _LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=
3079
+fi
3080
+
3081
+if test "$GXX" = yes; then
3082
+  # Set up default GNU C++ configuration
3083
+
3084
+  AC_PROG_LD
3085
+
3086
+  # Check if GNU C++ uses GNU ld as the underlying linker, since the
3087
+  # archiving commands below assume that GNU ld is being used.
3088
+  if test "$with_gnu_ld" = yes; then
3089
+    _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
3090
+    _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
3091
+
3092
+    _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir'
3093
+    _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
3094
+
3095
+    # If archive_cmds runs LD, not CC, wlarc should be empty
3096
+    # XXX I think wlarc can be eliminated in ltcf-cxx, but I need to
3097
+    #     investigate it a little bit more. (MM)
3098
+    wlarc='${wl}'
3099
+
3100
+    # ancient GNU ld didn't support --whole-archive et. al.
3101
+    if eval "`$CC -print-prog-name=ld` --help 2>&1" | \
3102
+	grep 'no-whole-archive' > /dev/null; then
3103
+      _LT_AC_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
3104
+    else
3105
+      _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=
3106
+    fi
3107
+  else
3108
+    with_gnu_ld=no
3109
+    wlarc=
3110
+
3111
+    # A generic and very simple default shared library creation
3112
+    # command for GNU C++ for the case where it uses the native
3113
+    # linker, instead of GNU ld.  If possible, this setting should
3114
+    # overridden to take advantage of the native linker features on
3115
+    # the platform it is being used on.
3116
+    _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
3117
+  fi
3118
+
3119
+  # Commands to make compiler produce verbose output that lists
3120
+  # what "hidden" libraries, object files and flags are used when
3121
+  # linking a shared library.
3122
+  output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"'
3123
+
3124
+else
3125
+  GXX=no
3126
+  with_gnu_ld=no
3127
+  wlarc=
3128
+fi
3129
+
3130
+# PORTME: fill in a description of your system's C++ link characteristics
3131
+AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries])
3132
+_LT_AC_TAGVAR(ld_shlibs, $1)=yes
3133
+case $host_os in
3134
+  aix3*)
3135
+    # FIXME: insert proper C++ library support
3136
+    _LT_AC_TAGVAR(ld_shlibs, $1)=no
3137
+    ;;
3138
+  aix[[4-9]]*)
3139
+    if test "$host_cpu" = ia64; then
3140
+      # On IA64, the linker does run time linking by default, so we don't
3141
+      # have to do anything special.
3142
+      aix_use_runtimelinking=no
3143
+      exp_sym_flag='-Bexport'
3144
+      no_entry_flag=""
3145
+    else
3146
+      aix_use_runtimelinking=no
3147
+
3148
+      # Test if we are trying to use run time linking or normal
3149
+      # AIX style linking. If -brtl is somewhere in LDFLAGS, we
3150
+      # need to do runtime linking.
3151
+      case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*)
3152
+	for ld_flag in $LDFLAGS; do
3153
+	  case $ld_flag in
3154
+	  *-brtl*)
3155
+	    aix_use_runtimelinking=yes
3156
+	    break
3157
+	    ;;
3158
+	  esac
3159
+	done
3160
+	;;
3161
+      esac
3162
+
3163
+      exp_sym_flag='-bexport'
3164
+      no_entry_flag='-bnoentry'
3165
+    fi
3166
+
3167
+    # When large executables or shared objects are built, AIX ld can
3168
+    # have problems creating the table of contents.  If linking a library
3169
+    # or program results in "error TOC overflow" add -mminimal-toc to
3170
+    # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
3171
+    # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
3172
+
3173
+    _LT_AC_TAGVAR(archive_cmds, $1)=''
3174
+    _LT_AC_TAGVAR(hardcode_direct, $1)=yes
3175
+    _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=':'
3176
+    _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
3177
+
3178
+    if test "$GXX" = yes; then
3179
+      case $host_os in aix4.[[012]]|aix4.[[012]].*)
3180
+      # We only want to do this on AIX 4.2 and lower, the check
3181
+      # below for broken collect2 doesn't work under 4.3+
3182
+	collect2name=`${CC} -print-prog-name=collect2`
3183
+	if test -f "$collect2name" && \
3184
+	   strings "$collect2name" | grep resolve_lib_name >/dev/null
3185
+	then
3186
+	  # We have reworked collect2
3187
+	  :
3188
+	else
3189
+	  # We have old collect2
3190
+	  _LT_AC_TAGVAR(hardcode_direct, $1)=unsupported
3191
+	  # It fails to find uninstalled libraries when the uninstalled
3192
+	  # path is not listed in the libpath.  Setting hardcode_minus_L
3193
+	  # to unsupported forces relinking
3194
+	  _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
3195
+	  _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
3196
+	  _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=
3197
+	fi
3198
+	;;
3199
+      esac
3200
+      shared_flag='-shared'
3201
+      if test "$aix_use_runtimelinking" = yes; then
3202
+	shared_flag="$shared_flag "'${wl}-G'
3203
+      fi
3204
+    else
3205
+      # not using gcc
3206
+      if test "$host_cpu" = ia64; then
3207
+	# VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
3208
+	# chokes on -Wl,-G. The following line is correct:
3209
+	shared_flag='-G'
3210
+      else
3211
+	if test "$aix_use_runtimelinking" = yes; then
3212
+	  shared_flag='${wl}-G'
3213
+	else
3214
+	  shared_flag='${wl}-bM:SRE'
3215
+	fi
3216
+      fi
3217
+    fi
3218
+
3219
+    # It seems that -bexpall does not export symbols beginning with
3220
+    # underscore (_), so it is better to generate a list of symbols to export.
3221
+    _LT_AC_TAGVAR(always_export_symbols, $1)=yes
3222
+    if test "$aix_use_runtimelinking" = yes; then
3223
+      # Warning - without using the other runtime loading flags (-brtl),
3224
+      # -berok will link without error, but may produce a broken library.
3225
+      _LT_AC_TAGVAR(allow_undefined_flag, $1)='-berok'
3226
+      # Determine the default libpath from the value encoded in an empty executable.
3227
+      _LT_AC_SYS_LIBPATH_AIX
3228
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
3229
+
3230
+      _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then echo "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
3231
+     else
3232
+      if test "$host_cpu" = ia64; then
3233
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib'
3234
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)="-z nodefs"
3235
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
3236
+      else
3237
+	# Determine the default libpath from the value encoded in an empty executable.
3238
+	_LT_AC_SYS_LIBPATH_AIX
3239
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
3240
+	# Warning - without using the other run time loading flags,
3241
+	# -berok will link without error, but may produce a broken library.
3242
+	_LT_AC_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok'
3243
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok'
3244
+	# Exported symbols can be pulled into shared objects from archives
3245
+	_LT_AC_TAGVAR(whole_archive_flag_spec, $1)='$convenience'
3246
+	_LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes
3247
+	# This is similar to how AIX traditionally builds its shared libraries.
3248
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
3249
+      fi
3250
+    fi
3251
+    ;;
3252
+
3253
+  beos*)
3254
+    if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
3255
+      _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
3256
+      # Joseph Beckenbach <jrb3@best.com> says some releases of gcc
3257
+      # support --undefined.  This deserves some investigation.  FIXME
3258
+      _LT_AC_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
3259
+    else
3260
+      _LT_AC_TAGVAR(ld_shlibs, $1)=no
3261
+    fi
3262
+    ;;
3263
+
3264
+  chorus*)
3265
+    case $cc_basename in
3266
+      *)
3267
+	# FIXME: insert proper C++ library support
3268
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
3269
+	;;
3270
+    esac
3271
+    ;;
3272
+
3273
+  cygwin* | mingw* | pw32*)
3274
+    # _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
3275
+    # as there is no search path for DLLs.
3276
+    _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
3277
+    _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
3278
+    _LT_AC_TAGVAR(always_export_symbols, $1)=no
3279
+    _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
3280
+
3281
+    if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then
3282
+      _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
3283
+      # If the export-symbols file already is a .def file (1st line
3284
+      # is EXPORTS), use it as is; otherwise, prepend...
3285
+      _LT_AC_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
3286
+	cp $export_symbols $output_objdir/$soname.def;
3287
+      else
3288
+	echo EXPORTS > $output_objdir/$soname.def;
3289
+	cat $export_symbols >> $output_objdir/$soname.def;
3290
+      fi~
3291
+      $CC -shared -nostdlib $output_objdir/$soname.def $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
3292
+    else
3293
+      _LT_AC_TAGVAR(ld_shlibs, $1)=no
3294
+    fi
3295
+  ;;
3296
+      darwin* | rhapsody*)
3297
+      _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
3298
+      _LT_AC_TAGVAR(hardcode_direct, $1)=no
3299
+      _LT_AC_TAGVAR(hardcode_automatic, $1)=yes
3300
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
3301
+      _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=''
3302
+      _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
3303
+      _LT_AC_TAGVAR(allow_undefined_flag, $1)="$_lt_dar_allow_undefined"
3304
+      if test "$GXX" = yes ; then
3305
+      output_verbose_link_cmd='echo'
3306
+      _LT_AC_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}"
3307
+      _LT_AC_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}"
3308
+      _LT_AC_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}"
3309
+      _LT_AC_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}"
3310
+      if test "$lt_cv_apple_cc_single_mod" != "yes"; then
3311
+        _LT_AC_TAGVAR(archive_cmds, $1)="\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dsymutil}"
3312
+        _LT_AC_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -r -keep_private_externs -nostdlib -o \${lib}-master.o \$libobjs~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \${lib}-master.o \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring${_lt_dar_export_syms}${_lt_dsymutil}"
3313
+      fi
3314
+      else
3315
+      case $cc_basename in
3316
+        xlc*)
3317
+         output_verbose_link_cmd='echo'
3318
+          _LT_AC_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj ${wl}-single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}`echo $rpath/$soname` $xlcverstring'
3319
+          _LT_AC_TAGVAR(module_cmds, $1)='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
3320
+          # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds
3321
+          _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -qmkshrobj ${wl}-single_module $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}$rpath/$soname $xlcverstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
3322
+          _LT_AC_TAGVAR(module_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag  -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
3323
+          ;;
3324
+       *)
3325
+         _LT_AC_TAGVAR(ld_shlibs, $1)=no
3326
+          ;;
3327
+      esac
3328
+      fi
3329
+        ;;
3330
+
3331
+  dgux*)
3332
+    case $cc_basename in
3333
+      ec++*)
3334
+	# FIXME: insert proper C++ library support
3335
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
3336
+	;;
3337
+      ghcx*)
3338
+	# Green Hills C++ Compiler
3339
+	# FIXME: insert proper C++ library support
3340
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
3341
+	;;
3342
+      *)
3343
+	# FIXME: insert proper C++ library support
3344
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
3345
+	;;
3346
+    esac
3347
+    ;;
3348
+  freebsd[[12]]*)
3349
+    # C++ shared libraries reported to be fairly broken before switch to ELF
3350
+    _LT_AC_TAGVAR(ld_shlibs, $1)=no
3351
+    ;;
3352
+  freebsd-elf*)
3353
+    _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
3354
+    ;;
3355
+  freebsd* | dragonfly*)
3356
+    # FreeBSD 3 and later use GNU C++ and GNU ld with standard ELF
3357
+    # conventions
3358
+    _LT_AC_TAGVAR(ld_shlibs, $1)=yes
3359
+    ;;
3360
+  gnu*)
3361
+    ;;
3362
+  hpux9*)
3363
+    _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
3364
+    _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
3365
+    _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
3366
+    _LT_AC_TAGVAR(hardcode_direct, $1)=yes
3367
+    _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH,
3368
+				# but as the default
3369
+				# location of the library.
3370
+
3371
+    case $cc_basename in
3372
+    CC*)
3373
+      # FIXME: insert proper C++ library support
3374
+      _LT_AC_TAGVAR(ld_shlibs, $1)=no
3375
+      ;;
3376
+    aCC*)
3377
+      _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$CC -b ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
3378
+      # Commands to make compiler produce verbose output that lists
3379
+      # what "hidden" libraries, object files and flags are used when
3380
+      # linking a shared library.
3381
+      #
3382
+      # There doesn't appear to be a way to prevent this compiler from
3383
+      # explicitly linking system object files so we need to strip them
3384
+      # from the output so that they don't get included in the library
3385
+      # dependencies.
3386
+      output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | grep "[[-]]L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
3387
+      ;;
3388
+    *)
3389
+      if test "$GXX" = yes; then
3390
+        _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$CC -shared -nostdlib -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
3391
+      else
3392
+        # FIXME: insert proper C++ library support
3393
+        _LT_AC_TAGVAR(ld_shlibs, $1)=no
3394
+      fi
3395
+      ;;
3396
+    esac
3397
+    ;;
3398
+  hpux10*|hpux11*)
3399
+    if test $with_gnu_ld = no; then
3400
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
3401
+      _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
3402
+
3403
+      case $host_cpu in
3404
+      hppa*64*|ia64*) ;;
3405
+      *)
3406
+	_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
3407
+        ;;
3408
+      esac
3409
+    fi
3410
+    case $host_cpu in
3411
+    hppa*64*|ia64*)
3412
+      _LT_AC_TAGVAR(hardcode_direct, $1)=no
3413
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
3414
+      ;;
3415
+    *)
3416
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
3417
+      _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes # Not in the search PATH,
3418
+					      # but as the default
3419
+					      # location of the library.
3420
+      ;;
3421
+    esac
3422
+
3423
+    case $cc_basename in
3424
+      CC*)
3425
+	# FIXME: insert proper C++ library support
3426
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
3427
+	;;
3428
+      aCC*)
3429
+	case $host_cpu in
3430
+	hppa*64*)
3431
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
3432
+	  ;;
3433
+	ia64*)
3434
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
3435
+	  ;;
3436
+	*)
3437
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
3438
+	  ;;
3439
+	esac
3440
+	# Commands to make compiler produce verbose output that lists
3441
+	# what "hidden" libraries, object files and flags are used when
3442
+	# linking a shared library.
3443
+	#
3444
+	# There doesn't appear to be a way to prevent this compiler from
3445
+	# explicitly linking system object files so we need to strip them
3446
+	# from the output so that they don't get included in the library
3447
+	# dependencies.
3448
+	output_verbose_link_cmd='templist=`($CC -b $CFLAGS -v conftest.$objext 2>&1) | grep "\-L"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
3449
+	;;
3450
+      *)
3451
+	if test "$GXX" = yes; then
3452
+	  if test $with_gnu_ld = no; then
3453
+	    case $host_cpu in
3454
+	    hppa*64*)
3455
+	      _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
3456
+	      ;;
3457
+	    ia64*)
3458
+	      _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
3459
+	      ;;
3460
+	    *)
3461
+	      _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
3462
+	      ;;
3463
+	    esac
3464
+	  fi
3465
+	else
3466
+	  # FIXME: insert proper C++ library support
3467
+	  _LT_AC_TAGVAR(ld_shlibs, $1)=no
3468
+	fi
3469
+	;;
3470
+    esac
3471
+    ;;
3472
+  interix[[3-9]]*)
3473
+    _LT_AC_TAGVAR(hardcode_direct, $1)=no
3474
+    _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
3475
+    _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
3476
+    _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
3477
+    # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
3478
+    # Instead, shared libraries are loaded at an image base (0x10000000 by
3479
+    # default) and relocated if they conflict, which is a slow very memory
3480
+    # consuming and fragmenting process.  To avoid this, we pick a random,
3481
+    # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
3482
+    # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
3483
+    _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
3484
+    _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
3485
+    ;;
3486
+  irix5* | irix6*)
3487
+    case $cc_basename in
3488
+      CC*)
3489
+	# SGI C++
3490
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -all -multigot $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
3491
+
3492
+	# Archives containing C++ object files must be created using
3493
+	# "CC -ar", where "CC" is the IRIX C++ compiler.  This is
3494
+	# necessary to make sure instantiated templates are included
3495
+	# in the archive.
3496
+	_LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -ar -WR,-u -o $oldlib $oldobjs'
3497
+	;;
3498
+      *)
3499
+	if test "$GXX" = yes; then
3500
+	  if test "$with_gnu_ld" = no; then
3501
+	    _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
3502
+	  else
3503
+	    _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` -o $lib'
3504
+	  fi
3505
+	fi
3506
+	_LT_AC_TAGVAR(link_all_deplibs, $1)=yes
3507
+	;;
3508
+    esac
3509
+    _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
3510
+    _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
3511
+    ;;
3512
+  linux* | k*bsd*-gnu)
3513
+    case $cc_basename in
3514
+      KCC*)
3515
+	# Kuck and Associates, Inc. (KAI) C++ Compiler
3516
+
3517
+	# KCC will only create a shared library if the output file
3518
+	# ends with ".so" (or ".sl" for HP-UX), so rename the library
3519
+	# to its proper name (with version) after linking.
3520
+	_LT_AC_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
3521
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib ${wl}-retain-symbols-file,$export_symbols; mv \$templib $lib'
3522
+	# Commands to make compiler produce verbose output that lists
3523
+	# what "hidden" libraries, object files and flags are used when
3524
+	# linking a shared library.
3525
+	#
3526
+	# There doesn't appear to be a way to prevent this compiler from
3527
+	# explicitly linking system object files so we need to strip them
3528
+	# from the output so that they don't get included in the library
3529
+	# dependencies.
3530
+	output_verbose_link_cmd='templist=`$CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1 | grep "ld"`; rm -f libconftest$shared_ext; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
3531
+
3532
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath,$libdir'
3533
+	_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
3534
+
3535
+	# Archives containing C++ object files must be created using
3536
+	# "CC -Bstatic", where "CC" is the KAI C++ compiler.
3537
+	_LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs'
3538
+	;;
3539
+      icpc*)
3540
+	# Intel C++
3541
+	with_gnu_ld=yes
3542
+	# version 8.0 and above of icpc choke on multiply defined symbols
3543
+	# if we add $predep_objects and $postdep_objects, however 7.1 and
3544
+	# earlier do not add the objects themselves.
3545
+	case `$CC -V 2>&1` in
3546
+	*"Version 7."*)
3547
+  	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
3548
+  	  _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
3549
+	  ;;
3550
+	*)  # Version 8.0 or newer
3551
+	  tmp_idyn=
3552
+	  case $host_cpu in
3553
+	    ia64*) tmp_idyn=' -i_dynamic';;
3554
+	  esac
3555
+  	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
3556
+	  _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared'"$tmp_idyn"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
3557
+	  ;;
3558
+	esac
3559
+	_LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
3560
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
3561
+	_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
3562
+	_LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive$convenience ${wl}--no-whole-archive'
3563
+	;;
3564
+      pgCC* | pgcpp*)
3565
+        # Portland Group C++ compiler
3566
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname -o $lib'
3567
+  	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname ${wl}-retain-symbols-file ${wl}$export_symbols -o $lib'
3568
+
3569
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir'
3570
+	_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
3571
+	_LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
3572
+        ;;
3573
+      cxx*)
3574
+	# Compaq C++
3575
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname -o $lib'
3576
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $wl$soname  -o $lib ${wl}-retain-symbols-file $wl$export_symbols'
3577
+
3578
+	runpath_var=LD_RUN_PATH
3579
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
3580
+	_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
3581
+
3582
+	# Commands to make compiler produce verbose output that lists
3583
+	# what "hidden" libraries, object files and flags are used when
3584
+	# linking a shared library.
3585
+	#
3586
+	# There doesn't appear to be a way to prevent this compiler from
3587
+	# explicitly linking system object files so we need to strip them
3588
+	# from the output so that they don't get included in the library
3589
+	# dependencies.
3590
+	output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld .*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
3591
+	;;
3592
+      *)
3593
+	case `$CC -V 2>&1 | sed 5q` in
3594
+	*Sun\ C*)
3595
+	  # Sun C++ 5.9
3596
+	  _LT_AC_TAGVAR(no_undefined_flag, $1)=' -zdefs'
3597
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
3598
+	  _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -G${allow_undefined_flag} -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file ${wl}$export_symbols'
3599
+	  _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
3600
+	  _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
3601
+
3602
+	  # Not sure whether something based on
3603
+	  # $CC $CFLAGS -v conftest.$objext -o libconftest$shared_ext 2>&1
3604
+	  # would be better.
3605
+	  output_verbose_link_cmd='echo'
3606
+
3607
+	  # Archives containing C++ object files must be created using
3608
+	  # "CC -xar", where "CC" is the Sun C++ compiler.  This is
3609
+	  # necessary to make sure instantiated templates are included
3610
+	  # in the archive.
3611
+	  _LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs'
3612
+	  ;;
3613
+	esac
3614
+	;;
3615
+    esac
3616
+    ;;
3617
+  lynxos*)
3618
+    # FIXME: insert proper C++ library support
3619
+    _LT_AC_TAGVAR(ld_shlibs, $1)=no
3620
+    ;;
3621
+  m88k*)
3622
+    # FIXME: insert proper C++ library support
3623
+    _LT_AC_TAGVAR(ld_shlibs, $1)=no
3624
+    ;;
3625
+  mvs*)
3626
+    case $cc_basename in
3627
+      cxx*)
3628
+	# FIXME: insert proper C++ library support
3629
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
3630
+	;;
3631
+      *)
3632
+	# FIXME: insert proper C++ library support
3633
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
3634
+	;;
3635
+    esac
3636
+    ;;
3637
+  netbsd* | netbsdelf*-gnu)
3638
+    if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
3639
+      _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable  -o $lib $predep_objects $libobjs $deplibs $postdep_objects $linker_flags'
3640
+      wlarc=
3641
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
3642
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
3643
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
3644
+    fi
3645
+    # Workaround some broken pre-1.5 toolchains
3646
+    output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep conftest.$objext | $SED -e "s:-lgcc -lc -lgcc::"'
3647
+    ;;
3648
+  openbsd2*)
3649
+    # C++ shared libraries are fairly broken
3650
+    _LT_AC_TAGVAR(ld_shlibs, $1)=no
3651
+    ;;
3652
+  openbsd*)
3653
+    if test -f /usr/libexec/ld.so; then
3654
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
3655
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
3656
+      _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -o $lib'
3657
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
3658
+      if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
3659
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-retain-symbols-file,$export_symbols -o $lib'
3660
+	_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
3661
+	_LT_AC_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
3662
+      fi
3663
+      output_verbose_link_cmd='echo'
3664
+    else
3665
+      _LT_AC_TAGVAR(ld_shlibs, $1)=no
3666
+    fi
3667
+    ;;
3668
+  osf3*)
3669
+    case $cc_basename in
3670
+      KCC*)
3671
+	# Kuck and Associates, Inc. (KAI) C++ Compiler
3672
+
3673
+	# KCC will only create a shared library if the output file
3674
+	# ends with ".so" (or ".sl" for HP-UX), so rename the library
3675
+	# to its proper name (with version) after linking.
3676
+	_LT_AC_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
3677
+
3678
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
3679
+	_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
3680
+
3681
+	# Archives containing C++ object files must be created using
3682
+	# "CC -Bstatic", where "CC" is the KAI C++ compiler.
3683
+	_LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -Bstatic -o $oldlib $oldobjs'
3684
+
3685
+	;;
3686
+      RCC*)
3687
+	# Rational C++ 2.4.1
3688
+	# FIXME: insert proper C++ library support
3689
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
3690
+	;;
3691
+      cxx*)
3692
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
3693
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname $soname `test -n "$verstring" && echo ${wl}-set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
3694
+
3695
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
3696
+	_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
3697
+
3698
+	# Commands to make compiler produce verbose output that lists
3699
+	# what "hidden" libraries, object files and flags are used when
3700
+	# linking a shared library.
3701
+	#
3702
+	# There doesn't appear to be a way to prevent this compiler from
3703
+	# explicitly linking system object files so we need to strip them
3704
+	# from the output so that they don't get included in the library
3705
+	# dependencies.
3706
+	output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld" | grep -v "ld:"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
3707
+	;;
3708
+      *)
3709
+	if test "$GXX" = yes && test "$with_gnu_ld" = no; then
3710
+	  _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
3711
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
3712
+
3713
+	  _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
3714
+	  _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
3715
+
3716
+	  # Commands to make compiler produce verbose output that lists
3717
+	  # what "hidden" libraries, object files and flags are used when
3718
+	  # linking a shared library.
3719
+	  output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"'
3720
+
3721
+	else
3722
+	  # FIXME: insert proper C++ library support
3723
+	  _LT_AC_TAGVAR(ld_shlibs, $1)=no
3724
+	fi
3725
+	;;
3726
+    esac
3727
+    ;;
3728
+  osf4* | osf5*)
3729
+    case $cc_basename in
3730
+      KCC*)
3731
+	# Kuck and Associates, Inc. (KAI) C++ Compiler
3732
+
3733
+	# KCC will only create a shared library if the output file
3734
+	# ends with ".so" (or ".sl" for HP-UX), so rename the library
3735
+	# to its proper name (with version) after linking.
3736
+	_LT_AC_TAGVAR(archive_cmds, $1)='tempext=`echo $shared_ext | $SED -e '\''s/\([[^()0-9A-Za-z{}]]\)/\\\\\1/g'\''`; templib=`echo $lib | $SED -e "s/\${tempext}\..*/.so/"`; $CC $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags --soname $soname -o \$templib; mv \$templib $lib'
3737
+
3738
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
3739
+	_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
3740
+
3741
+	# Archives containing C++ object files must be created using
3742
+	# the KAI C++ compiler.
3743
+	_LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -o $oldlib $oldobjs'
3744
+	;;
3745
+      RCC*)
3746
+	# Rational C++ 2.4.1
3747
+	# FIXME: insert proper C++ library support
3748
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
3749
+	;;
3750
+      cxx*)
3751
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
3752
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
3753
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done~
3754
+	  echo "-hidden">> $lib.exp~
3755
+	  $CC -shared$allow_undefined_flag $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags -msym -soname $soname -Wl,-input -Wl,$lib.exp  `test -n "$verstring" && echo -set_version	$verstring` -update_registry ${output_objdir}/so_locations -o $lib~
3756
+	  $rm $lib.exp'
3757
+
3758
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
3759
+	_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
3760
+
3761
+	# Commands to make compiler produce verbose output that lists
3762
+	# what "hidden" libraries, object files and flags are used when
3763
+	# linking a shared library.
3764
+	#
3765
+	# There doesn't appear to be a way to prevent this compiler from
3766
+	# explicitly linking system object files so we need to strip them
3767
+	# from the output so that they don't get included in the library
3768
+	# dependencies.
3769
+	output_verbose_link_cmd='templist=`$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "ld" | grep -v "ld:"`; templist=`echo $templist | $SED "s/\(^.*ld.*\)\( .*ld.*$\)/\1/"`; list=""; for z in $templist; do case $z in conftest.$objext) list="$list $z";; *.$objext);; *) list="$list $z";;esac; done; echo $list'
3770
+	;;
3771
+      *)
3772
+	if test "$GXX" = yes && test "$with_gnu_ld" = no; then
3773
+	  _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
3774
+	 _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib ${allow_undefined_flag} $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
3775
+
3776
+	  _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
3777
+	  _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
3778
+
3779
+	  # Commands to make compiler produce verbose output that lists
3780
+	  # what "hidden" libraries, object files and flags are used when
3781
+	  # linking a shared library.
3782
+	  output_verbose_link_cmd='$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep "\-L"'
3783
+
3784
+	else
3785
+	  # FIXME: insert proper C++ library support
3786
+	  _LT_AC_TAGVAR(ld_shlibs, $1)=no
3787
+	fi
3788
+	;;
3789
+    esac
3790
+    ;;
3791
+  psos*)
3792
+    # FIXME: insert proper C++ library support
3793
+    _LT_AC_TAGVAR(ld_shlibs, $1)=no
3794
+    ;;
3795
+  sunos4*)
3796
+    case $cc_basename in
3797
+      CC*)
3798
+	# Sun C++ 4.x
3799
+	# FIXME: insert proper C++ library support
3800
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
3801
+	;;
3802
+      lcc*)
3803
+	# Lucid
3804
+	# FIXME: insert proper C++ library support
3805
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
3806
+	;;
3807
+      *)
3808
+	# FIXME: insert proper C++ library support
3809
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
3810
+	;;
3811
+    esac
3812
+    ;;
3813
+  solaris*)
3814
+    case $cc_basename in
3815
+      CC*)
3816
+	# Sun C++ 4.2, 5.x and Centerline C++
3817
+        _LT_AC_TAGVAR(archive_cmds_need_lc,$1)=yes
3818
+	_LT_AC_TAGVAR(no_undefined_flag, $1)=' -zdefs'
3819
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -G${allow_undefined_flag}  -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags'
3820
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
3821
+	$CC -G${allow_undefined_flag}  ${wl}-M ${wl}$lib.exp -h$soname -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp'
3822
+
3823
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
3824
+	_LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
3825
+	case $host_os in
3826
+	  solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
3827
+	  *)
3828
+	    # The compiler driver will combine and reorder linker options,
3829
+	    # but understands `-z linker_flag'.
3830
+	    # Supported since Solaris 2.6 (maybe 2.5.1?)
3831
+	    _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract'
3832
+	    ;;
3833
+	esac
3834
+	_LT_AC_TAGVAR(link_all_deplibs, $1)=yes
3835
+
3836
+	output_verbose_link_cmd='echo'
3837
+
3838
+	# Archives containing C++ object files must be created using
3839
+	# "CC -xar", where "CC" is the Sun C++ compiler.  This is
3840
+	# necessary to make sure instantiated templates are included
3841
+	# in the archive.
3842
+	_LT_AC_TAGVAR(old_archive_cmds, $1)='$CC -xar -o $oldlib $oldobjs'
3843
+	;;
3844
+      gcx*)
3845
+	# Green Hills C++ Compiler
3846
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
3847
+
3848
+	# The C++ compiler must be used to create the archive.
3849
+	_LT_AC_TAGVAR(old_archive_cmds, $1)='$CC $LDFLAGS -archive -o $oldlib $oldobjs'
3850
+	;;
3851
+      *)
3852
+	# GNU C++ compiler with Solaris linker
3853
+	if test "$GXX" = yes && test "$with_gnu_ld" = no; then
3854
+	  _LT_AC_TAGVAR(no_undefined_flag, $1)=' ${wl}-z ${wl}defs'
3855
+	  if $CC --version | grep -v '^2\.7' > /dev/null; then
3856
+	    _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
3857
+	    _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
3858
+		$CC -shared -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp'
3859
+
3860
+	    # Commands to make compiler produce verbose output that lists
3861
+	    # what "hidden" libraries, object files and flags are used when
3862
+	    # linking a shared library.
3863
+	    output_verbose_link_cmd="$CC -shared $CFLAGS -v conftest.$objext 2>&1 | grep \"\-L\""
3864
+	  else
3865
+	    # g++ 2.7 appears to require `-G' NOT `-shared' on this
3866
+	    # platform.
3867
+	    _LT_AC_TAGVAR(archive_cmds, $1)='$CC -G -nostdlib $LDFLAGS $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags ${wl}-h $wl$soname -o $lib'
3868
+	    _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
3869
+		$CC -G -nostdlib ${wl}-M $wl$lib.exp -o $lib $predep_objects $libobjs $deplibs $postdep_objects $compiler_flags~$rm $lib.exp'
3870
+
3871
+	    # Commands to make compiler produce verbose output that lists
3872
+	    # what "hidden" libraries, object files and flags are used when
3873
+	    # linking a shared library.
3874
+	    output_verbose_link_cmd="$CC -G $CFLAGS -v conftest.$objext 2>&1 | grep \"\-L\""
3875
+	  fi
3876
+
3877
+	  _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $wl$libdir'
3878
+	  case $host_os in
3879
+	  solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
3880
+	  *)
3881
+	    _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
3882
+	    ;;
3883
+	  esac
3884
+	fi
3885
+	;;
3886
+    esac
3887
+    ;;
3888
+  sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*)
3889
+    _LT_AC_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
3890
+    _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
3891
+    _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
3892
+    runpath_var='LD_RUN_PATH'
3893
+
3894
+    case $cc_basename in
3895
+      CC*)
3896
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
3897
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
3898
+	;;
3899
+      *)
3900
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
3901
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
3902
+	;;
3903
+    esac
3904
+    ;;
3905
+  sysv5* | sco3.2v5* | sco5v6*)
3906
+    # Note: We can NOT use -z defs as we might desire, because we do not
3907
+    # link with -lc, and that would cause any symbols used from libc to
3908
+    # always be unresolved, which means just about no library would
3909
+    # ever link correctly.  If we're not using GNU ld we use -z text
3910
+    # though, which does catch some bad symbols but isn't as heavy-handed
3911
+    # as -z defs.
3912
+    # For security reasons, it is highly recommended that you always
3913
+    # use absolute paths for naming shared libraries, and exclude the
3914
+    # DT_RUNPATH tag from executables and libraries.  But doing so
3915
+    # requires that you compile everything twice, which is a pain.
3916
+    # So that behaviour is only enabled if SCOABSPATH is set to a
3917
+    # non-empty value in the environment.  Most likely only useful for
3918
+    # creating official distributions of packages.
3919
+    # This is a hack until libtool officially supports absolute path
3920
+    # names for shared libraries.
3921
+    _LT_AC_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
3922
+    _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs'
3923
+    _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
3924
+    _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
3925
+    _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`'
3926
+    _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=':'
3927
+    _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
3928
+    _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport'
3929
+    runpath_var='LD_RUN_PATH'
3930
+
3931
+    case $cc_basename in
3932
+      CC*)
3933
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
3934
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
3935
+	;;
3936
+      *)
3937
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
3938
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
3939
+	;;
3940
+    esac
3941
+    ;;
3942
+  tandem*)
3943
+    case $cc_basename in
3944
+      NCC*)
3945
+	# NonStop-UX NCC 3.20
3946
+	# FIXME: insert proper C++ library support
3947
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
3948
+	;;
3949
+      *)
3950
+	# FIXME: insert proper C++ library support
3951
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
3952
+	;;
3953
+    esac
3954
+    ;;
3955
+  vxworks*)
3956
+    # FIXME: insert proper C++ library support
3957
+    _LT_AC_TAGVAR(ld_shlibs, $1)=no
3958
+    ;;
3959
+  *)
3960
+    # FIXME: insert proper C++ library support
3961
+    _LT_AC_TAGVAR(ld_shlibs, $1)=no
3962
+    ;;
3963
+esac
3964
+AC_MSG_RESULT([$_LT_AC_TAGVAR(ld_shlibs, $1)])
3965
+test "$_LT_AC_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
3966
+
3967
+_LT_AC_TAGVAR(GCC, $1)="$GXX"
3968
+_LT_AC_TAGVAR(LD, $1)="$LD"
3969
+
3970
+AC_LIBTOOL_POSTDEP_PREDEP($1)
3971
+AC_LIBTOOL_PROG_COMPILER_PIC($1)
3972
+AC_LIBTOOL_PROG_CC_C_O($1)
3973
+AC_LIBTOOL_SYS_HARD_LINK_LOCKS($1)
3974
+AC_LIBTOOL_PROG_LD_SHLIBS($1)
3975
+AC_LIBTOOL_SYS_DYNAMIC_LINKER($1)
3976
+AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH($1)
3977
+
3978
+AC_LIBTOOL_CONFIG($1)
3979
+
3980
+AC_LANG_POP
3981
+CC=$lt_save_CC
3982
+LDCXX=$LD
3983
+LD=$lt_save_LD
3984
+GCC=$lt_save_GCC
3985
+with_gnu_ldcxx=$with_gnu_ld
3986
+with_gnu_ld=$lt_save_with_gnu_ld
3987
+lt_cv_path_LDCXX=$lt_cv_path_LD
3988
+lt_cv_path_LD=$lt_save_path_LD
3989
+lt_cv_prog_gnu_ldcxx=$lt_cv_prog_gnu_ld
3990
+lt_cv_prog_gnu_ld=$lt_save_with_gnu_ld
3991
+])# AC_LIBTOOL_LANG_CXX_CONFIG
3992
+
3993
+# AC_LIBTOOL_POSTDEP_PREDEP([TAGNAME])
3994
+# ------------------------------------
3995
+# Figure out "hidden" library dependencies from verbose
3996
+# compiler output when linking a shared library.
3997
+# Parse the compiler output and extract the necessary
3998
+# objects, libraries and library flags.
3999
+AC_DEFUN([AC_LIBTOOL_POSTDEP_PREDEP],
4000
+[AC_REQUIRE([LT_AC_PROG_SED])dnl
4001
+dnl we can't use the lt_simple_compile_test_code here,
4002
+dnl because it contains code intended for an executable,
4003
+dnl not a library.  It's possible we should let each
4004
+dnl tag define a new lt_????_link_test_code variable,
4005
+dnl but it's only used here...
4006
+ifelse([$1],[],[cat > conftest.$ac_ext <<EOF
4007
+int a;
4008
+void foo (void) { a = 0; }
4009
+EOF
4010
+],[$1],[CXX],[cat > conftest.$ac_ext <<EOF
4011
+class Foo
4012
+{
4013
+public:
4014
+  Foo (void) { a = 0; }
4015
+private:
4016
+  int a;
4017
+};
4018
+EOF
4019
+],[$1],[F77],[cat > conftest.$ac_ext <<EOF
4020
+      subroutine foo
4021
+      implicit none
4022
+      integer*4 a
4023
+      a=0
4024
+      return
4025
+      end
4026
+EOF
4027
+],[$1],[GCJ],[cat > conftest.$ac_ext <<EOF
4028
+public class foo {
4029
+  private int a;
4030
+  public void bar (void) {
4031
+    a = 0;
4032
+  }
4033
+};
4034
+EOF
4035
+])
4036
+dnl Parse the compiler output and extract the necessary
4037
+dnl objects, libraries and library flags.
4038
+if AC_TRY_EVAL(ac_compile); then
4039
+  # Parse the compiler output and extract the necessary
4040
+  # objects, libraries and library flags.
4041
+
4042
+  # Sentinel used to keep track of whether or not we are before
4043
+  # the conftest object file.
4044
+  pre_test_object_deps_done=no
4045
+
4046
+  # The `*' in the case matches for architectures that use `case' in
4047
+  # $output_verbose_cmd can trigger glob expansion during the loop
4048
+  # eval without this substitution.
4049
+  output_verbose_link_cmd=`$echo "X$output_verbose_link_cmd" | $Xsed -e "$no_glob_subst"`
4050
+
4051
+  for p in `eval $output_verbose_link_cmd`; do
4052
+    case $p in
4053
+
4054
+    -L* | -R* | -l*)
4055
+       # Some compilers place space between "-{L,R}" and the path.
4056
+       # Remove the space.
4057
+       if test $p = "-L" \
4058
+	  || test $p = "-R"; then
4059
+	 prev=$p
4060
+	 continue
4061
+       else
4062
+	 prev=
4063
+       fi
4064
+
4065
+       if test "$pre_test_object_deps_done" = no; then
4066
+	 case $p in
4067
+	 -L* | -R*)
4068
+	   # Internal compiler library paths should come after those
4069
+	   # provided the user.  The postdeps already come after the
4070
+	   # user supplied libs so there is no need to process them.
4071
+	   if test -z "$_LT_AC_TAGVAR(compiler_lib_search_path, $1)"; then
4072
+	     _LT_AC_TAGVAR(compiler_lib_search_path, $1)="${prev}${p}"
4073
+	   else
4074
+	     _LT_AC_TAGVAR(compiler_lib_search_path, $1)="${_LT_AC_TAGVAR(compiler_lib_search_path, $1)} ${prev}${p}"
4075
+	   fi
4076
+	   ;;
4077
+	 # The "-l" case would never come before the object being
4078
+	 # linked, so don't bother handling this case.
4079
+	 esac
4080
+       else
4081
+	 if test -z "$_LT_AC_TAGVAR(postdeps, $1)"; then
4082
+	   _LT_AC_TAGVAR(postdeps, $1)="${prev}${p}"
4083
+	 else
4084
+	   _LT_AC_TAGVAR(postdeps, $1)="${_LT_AC_TAGVAR(postdeps, $1)} ${prev}${p}"
4085
+	 fi
4086
+       fi
4087
+       ;;
4088
+
4089
+    *.$objext)
4090
+       # This assumes that the test object file only shows up
4091
+       # once in the compiler output.
4092
+       if test "$p" = "conftest.$objext"; then
4093
+	 pre_test_object_deps_done=yes
4094
+	 continue
4095
+       fi
4096
+
4097
+       if test "$pre_test_object_deps_done" = no; then
4098
+	 if test -z "$_LT_AC_TAGVAR(predep_objects, $1)"; then
4099
+	   _LT_AC_TAGVAR(predep_objects, $1)="$p"
4100
+	 else
4101
+	   _LT_AC_TAGVAR(predep_objects, $1)="$_LT_AC_TAGVAR(predep_objects, $1) $p"
4102
+	 fi
4103
+       else
4104
+	 if test -z "$_LT_AC_TAGVAR(postdep_objects, $1)"; then
4105
+	   _LT_AC_TAGVAR(postdep_objects, $1)="$p"
4106
+	 else
4107
+	   _LT_AC_TAGVAR(postdep_objects, $1)="$_LT_AC_TAGVAR(postdep_objects, $1) $p"
4108
+	 fi
4109
+       fi
4110
+       ;;
4111
+
4112
+    *) ;; # Ignore the rest.
4113
+
4114
+    esac
4115
+  done
4116
+
4117
+  # Clean up.
4118
+  rm -f a.out a.exe
4119
+else
4120
+  echo "libtool.m4: error: problem compiling $1 test program"
4121
+fi
4122
+
4123
+$rm -f confest.$objext
4124
+
4125
+_LT_AC_TAGVAR(compiler_lib_search_dirs, $1)=
4126
+if test -n "$_LT_AC_TAGVAR(compiler_lib_search_path, $1)"; then
4127
+  _LT_AC_TAGVAR(compiler_lib_search_dirs, $1)=`echo " ${_LT_AC_TAGVAR(compiler_lib_search_path, $1)}" | ${SED} -e 's! -L! !g' -e 's!^ !!'`
4128
+fi
4129
+
4130
+# PORTME: override above test on systems where it is broken
4131
+ifelse([$1],[CXX],
4132
+[case $host_os in
4133
+interix[[3-9]]*)
4134
+  # Interix 3.5 installs completely hosed .la files for C++, so rather than
4135
+  # hack all around it, let's just trust "g++" to DTRT.
4136
+  _LT_AC_TAGVAR(predep_objects,$1)=
4137
+  _LT_AC_TAGVAR(postdep_objects,$1)=
4138
+  _LT_AC_TAGVAR(postdeps,$1)=
4139
+  ;;
4140
+
4141
+linux*)
4142
+  case `$CC -V 2>&1 | sed 5q` in
4143
+  *Sun\ C*)
4144
+    # Sun C++ 5.9
4145
+    #
4146
+    # The more standards-conforming stlport4 library is
4147
+    # incompatible with the Cstd library. Avoid specifying
4148
+    # it if it's in CXXFLAGS. Ignore libCrun as
4149
+    # -library=stlport4 depends on it.
4150
+    case " $CXX $CXXFLAGS " in
4151
+    *" -library=stlport4 "*)
4152
+      solaris_use_stlport4=yes
4153
+      ;;
4154
+    esac
4155
+    if test "$solaris_use_stlport4" != yes; then
4156
+      _LT_AC_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun'
4157
+    fi
4158
+    ;;
4159
+  esac
4160
+  ;;
4161
+
4162
+solaris*)
4163
+  case $cc_basename in
4164
+  CC*)
4165
+    # The more standards-conforming stlport4 library is
4166
+    # incompatible with the Cstd library. Avoid specifying
4167
+    # it if it's in CXXFLAGS. Ignore libCrun as
4168
+    # -library=stlport4 depends on it.
4169
+    case " $CXX $CXXFLAGS " in
4170
+    *" -library=stlport4 "*)
4171
+      solaris_use_stlport4=yes
4172
+      ;;
4173
+    esac
4174
+
4175
+    # Adding this requires a known-good setup of shared libraries for
4176
+    # Sun compiler versions before 5.6, else PIC objects from an old
4177
+    # archive will be linked into the output, leading to subtle bugs.
4178
+    if test "$solaris_use_stlport4" != yes; then
4179
+      _LT_AC_TAGVAR(postdeps,$1)='-library=Cstd -library=Crun'
4180
+    fi
4181
+    ;;
4182
+  esac
4183
+  ;;
4184
+esac
4185
+])
4186
+case " $_LT_AC_TAGVAR(postdeps, $1) " in
4187
+*" -lc "*) _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no ;;
4188
+esac
4189
+])# AC_LIBTOOL_POSTDEP_PREDEP
4190
+
4191
+# AC_LIBTOOL_LANG_F77_CONFIG
4192
+# --------------------------
4193
+# Ensure that the configuration vars for the C compiler are
4194
+# suitably defined.  Those variables are subsequently used by
4195
+# AC_LIBTOOL_CONFIG to write the compiler configuration to `libtool'.
4196
+AC_DEFUN([AC_LIBTOOL_LANG_F77_CONFIG], [_LT_AC_LANG_F77_CONFIG(F77)])
4197
+AC_DEFUN([_LT_AC_LANG_F77_CONFIG],
4198
+[AC_REQUIRE([AC_PROG_F77])
4199
+AC_LANG_PUSH(Fortran 77)
4200
+
4201
+_LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
4202
+_LT_AC_TAGVAR(allow_undefined_flag, $1)=
4203
+_LT_AC_TAGVAR(always_export_symbols, $1)=no
4204
+_LT_AC_TAGVAR(archive_expsym_cmds, $1)=
4205
+_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)=
4206
+_LT_AC_TAGVAR(hardcode_direct, $1)=no
4207
+_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)=
4208
+_LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
4209
+_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=
4210
+_LT_AC_TAGVAR(hardcode_minus_L, $1)=no
4211
+_LT_AC_TAGVAR(hardcode_automatic, $1)=no
4212
+_LT_AC_TAGVAR(module_cmds, $1)=
4213
+_LT_AC_TAGVAR(module_expsym_cmds, $1)=
4214
+_LT_AC_TAGVAR(link_all_deplibs, $1)=unknown
4215
+_LT_AC_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
4216
+_LT_AC_TAGVAR(no_undefined_flag, $1)=
4217
+_LT_AC_TAGVAR(whole_archive_flag_spec, $1)=
4218
+_LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=no
4219
+
4220
+# Source file extension for f77 test sources.
4221
+ac_ext=f
4222
+
4223
+# Object file extension for compiled f77 test sources.
4224
+objext=o
4225
+_LT_AC_TAGVAR(objext, $1)=$objext
4226
+
4227
+# Code to be used in simple compile tests
4228
+lt_simple_compile_test_code="\
4229
+      subroutine t
4230
+      return
4231
+      end
4232
+"
4233
+
4234
+# Code to be used in simple link tests
4235
+lt_simple_link_test_code="\
4236
+      program t
4237
+      end
4238
+"
4239
+
4240
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
4241
+_LT_AC_SYS_COMPILER
4242
+
4243
+# save warnings/boilerplate of simple test code
4244
+_LT_COMPILER_BOILERPLATE
4245
+_LT_LINKER_BOILERPLATE
4246
+
4247
+# Allow CC to be a program name with arguments.
4248
+lt_save_CC="$CC"
4249
+CC=${F77-"f77"}
4250
+compiler=$CC
4251
+_LT_AC_TAGVAR(compiler, $1)=$CC
4252
+_LT_CC_BASENAME([$compiler])
4253
+
4254
+AC_MSG_CHECKING([if libtool supports shared libraries])
4255
+AC_MSG_RESULT([$can_build_shared])
4256
+
4257
+AC_MSG_CHECKING([whether to build shared libraries])
4258
+test "$can_build_shared" = "no" && enable_shared=no
4259
+
4260
+# On AIX, shared libraries and static libraries use the same namespace, and
4261
+# are all built from PIC.
4262
+case $host_os in
4263
+aix3*)
4264
+  test "$enable_shared" = yes && enable_static=no
4265
+  if test -n "$RANLIB"; then
4266
+    archive_cmds="$archive_cmds~\$RANLIB \$lib"
4267
+    postinstall_cmds='$RANLIB $lib'
4268
+  fi
4269
+  ;;
4270
+aix[[4-9]]*)
4271
+  if test "$host_cpu" != ia64 && test "$aix_use_runtimelinking" = no ; then
4272
+    test "$enable_shared" = yes && enable_static=no
4273
+  fi
4274
+  ;;
4275
+esac
4276
+AC_MSG_RESULT([$enable_shared])
4277
+
4278
+AC_MSG_CHECKING([whether to build static libraries])
4279
+# Make sure either enable_shared or enable_static is yes.
4280
+test "$enable_shared" = yes || enable_static=yes
4281
+AC_MSG_RESULT([$enable_static])
4282
+
4283
+_LT_AC_TAGVAR(GCC, $1)="$G77"
4284
+_LT_AC_TAGVAR(LD, $1)="$LD"
4285
+
4286
+AC_LIBTOOL_PROG_COMPILER_PIC($1)
4287
+AC_LIBTOOL_PROG_CC_C_O($1)
4288
+AC_LIBTOOL_SYS_HARD_LINK_LOCKS($1)
4289
+AC_LIBTOOL_PROG_LD_SHLIBS($1)
4290
+AC_LIBTOOL_SYS_DYNAMIC_LINKER($1)
4291
+AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH($1)
4292
+
4293
+AC_LIBTOOL_CONFIG($1)
4294
+
4295
+AC_LANG_POP
4296
+CC="$lt_save_CC"
4297
+])# AC_LIBTOOL_LANG_F77_CONFIG
4298
+
4299
+
4300
+# AC_LIBTOOL_LANG_GCJ_CONFIG
4301
+# --------------------------
4302
+# Ensure that the configuration vars for the C compiler are
4303
+# suitably defined.  Those variables are subsequently used by
4304
+# AC_LIBTOOL_CONFIG to write the compiler configuration to `libtool'.
4305
+AC_DEFUN([AC_LIBTOOL_LANG_GCJ_CONFIG], [_LT_AC_LANG_GCJ_CONFIG(GCJ)])
4306
+AC_DEFUN([_LT_AC_LANG_GCJ_CONFIG],
4307
+[AC_LANG_SAVE
4308
+
4309
+# Source file extension for Java test sources.
4310
+ac_ext=java
4311
+
4312
+# Object file extension for compiled Java test sources.
4313
+objext=o
4314
+_LT_AC_TAGVAR(objext, $1)=$objext
4315
+
4316
+# Code to be used in simple compile tests
4317
+lt_simple_compile_test_code="class foo {}"
4318
+
4319
+# Code to be used in simple link tests
4320
+lt_simple_link_test_code='public class conftest { public static void main(String[[]] argv) {}; }'
4321
+
4322
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
4323
+_LT_AC_SYS_COMPILER
4324
+
4325
+# save warnings/boilerplate of simple test code
4326
+_LT_COMPILER_BOILERPLATE
4327
+_LT_LINKER_BOILERPLATE
4328
+
4329
+# Allow CC to be a program name with arguments.
4330
+lt_save_CC="$CC"
4331
+CC=${GCJ-"gcj"}
4332
+compiler=$CC
4333
+_LT_AC_TAGVAR(compiler, $1)=$CC
4334
+_LT_CC_BASENAME([$compiler])
4335
+
4336
+# GCJ did not exist at the time GCC didn't implicitly link libc in.
4337
+_LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
4338
+
4339
+_LT_AC_TAGVAR(old_archive_cmds, $1)=$old_archive_cmds
4340
+
4341
+AC_LIBTOOL_PROG_COMPILER_NO_RTTI($1)
4342
+AC_LIBTOOL_PROG_COMPILER_PIC($1)
4343
+AC_LIBTOOL_PROG_CC_C_O($1)
4344
+AC_LIBTOOL_SYS_HARD_LINK_LOCKS($1)
4345
+AC_LIBTOOL_PROG_LD_SHLIBS($1)
4346
+AC_LIBTOOL_SYS_DYNAMIC_LINKER($1)
4347
+AC_LIBTOOL_PROG_LD_HARDCODE_LIBPATH($1)
4348
+
4349
+AC_LIBTOOL_CONFIG($1)
4350
+
4351
+AC_LANG_RESTORE
4352
+CC="$lt_save_CC"
4353
+])# AC_LIBTOOL_LANG_GCJ_CONFIG
4354
+
4355
+
4356
+# AC_LIBTOOL_LANG_RC_CONFIG
4357
+# -------------------------
4358
+# Ensure that the configuration vars for the Windows resource compiler are
4359
+# suitably defined.  Those variables are subsequently used by
4360
+# AC_LIBTOOL_CONFIG to write the compiler configuration to `libtool'.
4361
+AC_DEFUN([AC_LIBTOOL_LANG_RC_CONFIG], [_LT_AC_LANG_RC_CONFIG(RC)])
4362
+AC_DEFUN([_LT_AC_LANG_RC_CONFIG],
4363
+[AC_LANG_SAVE
4364
+
4365
+# Source file extension for RC test sources.
4366
+ac_ext=rc
4367
+
4368
+# Object file extension for compiled RC test sources.
4369
+objext=o
4370
+_LT_AC_TAGVAR(objext, $1)=$objext
4371
+
4372
+# Code to be used in simple compile tests
4373
+lt_simple_compile_test_code='sample MENU { MENUITEM "&Soup", 100, CHECKED }'
4374
+
4375
+# Code to be used in simple link tests
4376
+lt_simple_link_test_code="$lt_simple_compile_test_code"
4377
+
4378
+# ltmain only uses $CC for tagged configurations so make sure $CC is set.
4379
+_LT_AC_SYS_COMPILER
4380
+
4381
+# save warnings/boilerplate of simple test code
4382
+_LT_COMPILER_BOILERPLATE
4383
+_LT_LINKER_BOILERPLATE
4384
+
4385
+# Allow CC to be a program name with arguments.
4386
+lt_save_CC="$CC"
4387
+CC=${RC-"windres"}
4388
+compiler=$CC
4389
+_LT_AC_TAGVAR(compiler, $1)=$CC
4390
+_LT_CC_BASENAME([$compiler])
4391
+_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)=yes
4392
+
4393
+AC_LIBTOOL_CONFIG($1)
4394
+
4395
+AC_LANG_RESTORE
4396
+CC="$lt_save_CC"
4397
+])# AC_LIBTOOL_LANG_RC_CONFIG
4398
+
4399
+
4400
+# AC_LIBTOOL_CONFIG([TAGNAME])
4401
+# ----------------------------
4402
+# If TAGNAME is not passed, then create an initial libtool script
4403
+# with a default configuration from the untagged config vars.  Otherwise
4404
+# add code to config.status for appending the configuration named by
4405
+# TAGNAME from the matching tagged config vars.
4406
+AC_DEFUN([AC_LIBTOOL_CONFIG],
4407
+[# The else clause should only fire when bootstrapping the
4408
+# libtool distribution, otherwise you forgot to ship ltmain.sh
4409
+# with your package, and you will get complaints that there are
4410
+# no rules to generate ltmain.sh.
4411
+if test -f "$ltmain"; then
4412
+  # See if we are running on zsh, and set the options which allow our commands through
4413
+  # without removal of \ escapes.
4414
+  if test -n "${ZSH_VERSION+set}" ; then
4415
+    setopt NO_GLOB_SUBST
4416
+  fi
4417
+  # Now quote all the things that may contain metacharacters while being
4418
+  # careful not to overquote the AC_SUBSTed values.  We take copies of the
4419
+  # variables and quote the copies for generation of the libtool script.
4420
+  for var in echo old_CC old_CFLAGS AR AR_FLAGS EGREP RANLIB LN_S LTCC LTCFLAGS NM \
4421
+    SED SHELL STRIP \
4422
+    libname_spec library_names_spec soname_spec extract_expsyms_cmds \
4423
+    old_striplib striplib file_magic_cmd finish_cmds finish_eval \
4424
+    deplibs_check_method reload_flag reload_cmds need_locks \
4425
+    lt_cv_sys_global_symbol_pipe lt_cv_sys_global_symbol_to_cdecl \
4426
+    lt_cv_sys_global_symbol_to_c_name_address \
4427
+    sys_lib_search_path_spec sys_lib_dlsearch_path_spec \
4428
+    old_postinstall_cmds old_postuninstall_cmds \
4429
+    _LT_AC_TAGVAR(compiler, $1) \
4430
+    _LT_AC_TAGVAR(CC, $1) \
4431
+    _LT_AC_TAGVAR(LD, $1) \
4432
+    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1) \
4433
+    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1) \
4434
+    _LT_AC_TAGVAR(lt_prog_compiler_static, $1) \
4435
+    _LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) \
4436
+    _LT_AC_TAGVAR(export_dynamic_flag_spec, $1) \
4437
+    _LT_AC_TAGVAR(thread_safe_flag_spec, $1) \
4438
+    _LT_AC_TAGVAR(whole_archive_flag_spec, $1) \
4439
+    _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1) \
4440
+    _LT_AC_TAGVAR(old_archive_cmds, $1) \
4441
+    _LT_AC_TAGVAR(old_archive_from_new_cmds, $1) \
4442
+    _LT_AC_TAGVAR(predep_objects, $1) \
4443
+    _LT_AC_TAGVAR(postdep_objects, $1) \
4444
+    _LT_AC_TAGVAR(predeps, $1) \
4445
+    _LT_AC_TAGVAR(postdeps, $1) \
4446
+    _LT_AC_TAGVAR(compiler_lib_search_path, $1) \
4447
+    _LT_AC_TAGVAR(compiler_lib_search_dirs, $1) \
4448
+    _LT_AC_TAGVAR(archive_cmds, $1) \
4449
+    _LT_AC_TAGVAR(archive_expsym_cmds, $1) \
4450
+    _LT_AC_TAGVAR(postinstall_cmds, $1) \
4451
+    _LT_AC_TAGVAR(postuninstall_cmds, $1) \
4452
+    _LT_AC_TAGVAR(old_archive_from_expsyms_cmds, $1) \
4453
+    _LT_AC_TAGVAR(allow_undefined_flag, $1) \
4454
+    _LT_AC_TAGVAR(no_undefined_flag, $1) \
4455
+    _LT_AC_TAGVAR(export_symbols_cmds, $1) \
4456
+    _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1) \
4457
+    _LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1) \
4458
+    _LT_AC_TAGVAR(hardcode_libdir_separator, $1) \
4459
+    _LT_AC_TAGVAR(hardcode_automatic, $1) \
4460
+    _LT_AC_TAGVAR(module_cmds, $1) \
4461
+    _LT_AC_TAGVAR(module_expsym_cmds, $1) \
4462
+    _LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1) \
4463
+    _LT_AC_TAGVAR(fix_srcfile_path, $1) \
4464
+    _LT_AC_TAGVAR(exclude_expsyms, $1) \
4465
+    _LT_AC_TAGVAR(include_expsyms, $1); do
4466
+
4467
+    case $var in
4468
+    _LT_AC_TAGVAR(old_archive_cmds, $1) | \
4469
+    _LT_AC_TAGVAR(old_archive_from_new_cmds, $1) | \
4470
+    _LT_AC_TAGVAR(archive_cmds, $1) | \
4471
+    _LT_AC_TAGVAR(archive_expsym_cmds, $1) | \
4472
+    _LT_AC_TAGVAR(module_cmds, $1) | \
4473
+    _LT_AC_TAGVAR(module_expsym_cmds, $1) | \
4474
+    _LT_AC_TAGVAR(old_archive_from_expsyms_cmds, $1) | \
4475
+    _LT_AC_TAGVAR(export_symbols_cmds, $1) | \
4476
+    extract_expsyms_cmds | reload_cmds | finish_cmds | \
4477
+    postinstall_cmds | postuninstall_cmds | \
4478
+    old_postinstall_cmds | old_postuninstall_cmds | \
4479
+    sys_lib_search_path_spec | sys_lib_dlsearch_path_spec)
4480
+      # Double-quote double-evaled strings.
4481
+      eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$double_quote_subst\" -e \"\$sed_quote_subst\" -e \"\$delay_variable_subst\"\`\\\""
4482
+      ;;
4483
+    *)
4484
+      eval "lt_$var=\\\"\`\$echo \"X\$$var\" | \$Xsed -e \"\$sed_quote_subst\"\`\\\""
4485
+      ;;
4486
+    esac
4487
+  done
4488
+
4489
+  case $lt_echo in
4490
+  *'\[$]0 --fallback-echo"')
4491
+    lt_echo=`$echo "X$lt_echo" | $Xsed -e 's/\\\\\\\[$]0 --fallback-echo"[$]/[$]0 --fallback-echo"/'`
4492
+    ;;
4493
+  esac
4494
+
4495
+ifelse([$1], [],
4496
+  [cfgfile="${ofile}T"
4497
+  trap "$rm \"$cfgfile\"; exit 1" 1 2 15
4498
+  $rm -f "$cfgfile"
4499
+  AC_MSG_NOTICE([creating $ofile])],
4500
+  [cfgfile="$ofile"])
4501
+
4502
+  cat <<__EOF__ >> "$cfgfile"
4503
+ifelse([$1], [],
4504
+[#! $SHELL
4505
+
4506
+# `$echo "$cfgfile" | sed 's%^.*/%%'` - Provide generalized library-building support services.
4507
+# Generated automatically by $PROGRAM (GNU $PACKAGE $VERSION$TIMESTAMP)
4508
+# NOTE: Changes made to this file will be lost: look at ltmain.sh.
4509
+#
4510
+# Copyright (C) 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008
4511
+# Free Software Foundation, Inc.
4512
+#
4513
+# This file is part of GNU Libtool:
4514
+# Originally by Gordon Matzigkeit <gord@gnu.ai.mit.edu>, 1996
4515
+#
4516
+# This program is free software; you can redistribute it and/or modify
4517
+# it under the terms of the GNU General Public License as published by
4518
+# the Free Software Foundation; either version 2 of the License, or
4519
+# (at your option) any later version.
4520
+#
4521
+# This program is distributed in the hope that it will be useful, but
4522
+# WITHOUT ANY WARRANTY; without even the implied warranty of
4523
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4524
+# General Public License for more details.
4525
+#
4526
+# You should have received a copy of the GNU General Public License
4527
+# along with this program; if not, write to the Free Software
4528
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
4529
+#
4530
+# As a special exception to the GNU General Public License, if you
4531
+# distribute this file as part of a program that contains a
4532
+# configuration script generated by Autoconf, you may include it under
4533
+# the same distribution terms that you use for the rest of that program.
4534
+
4535
+# A sed program that does not truncate output.
4536
+SED=$lt_SED
4537
+
4538
+# Sed that helps us avoid accidentally triggering echo(1) options like -n.
4539
+Xsed="$SED -e 1s/^X//"
4540
+
4541
+# The HP-UX ksh and POSIX shell print the target directory to stdout
4542
+# if CDPATH is set.
4543
+(unset CDPATH) >/dev/null 2>&1 && unset CDPATH
4544
+
4545
+# The names of the tagged configurations supported by this script.
4546
+available_tags=
4547
+
4548
+# ### BEGIN LIBTOOL CONFIG],
4549
+[# ### BEGIN LIBTOOL TAG CONFIG: $tagname])
4550
+
4551
+# Libtool was configured on host `(hostname || uname -n) 2>/dev/null | sed 1q`:
4552
+
4553
+# Shell to use when invoking shell scripts.
4554
+SHELL=$lt_SHELL
4555
+
4556
+# Whether or not to build shared libraries.
4557
+build_libtool_libs=$enable_shared
4558
+
4559
+# Whether or not to build static libraries.
4560
+build_old_libs=$enable_static
4561
+
4562
+# Whether or not to add -lc for building shared libraries.
4563
+build_libtool_need_lc=$_LT_AC_TAGVAR(archive_cmds_need_lc, $1)
4564
+
4565
+# Whether or not to disallow shared libs when runtime libs are static
4566
+allow_libtool_libs_with_static_runtimes=$_LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)
4567
+
4568
+# Whether or not to optimize for fast installation.
4569
+fast_install=$enable_fast_install
4570
+
4571
+# The host system.
4572
+host_alias=$host_alias
4573
+host=$host
4574
+host_os=$host_os
4575
+
4576
+# The build system.
4577
+build_alias=$build_alias
4578
+build=$build
4579
+build_os=$build_os
4580
+
4581
+# An echo program that does not interpret backslashes.
4582
+echo=$lt_echo
4583
+
4584
+# The archiver.
4585
+AR=$lt_AR
4586
+AR_FLAGS=$lt_AR_FLAGS
4587
+
4588
+# A C compiler.
4589
+LTCC=$lt_LTCC
4590
+
4591
+# LTCC compiler flags.
4592
+LTCFLAGS=$lt_LTCFLAGS
4593
+
4594
+# A language-specific compiler.
4595
+CC=$lt_[]_LT_AC_TAGVAR(compiler, $1)
4596
+
4597
+# Is the compiler the GNU C compiler?
4598
+with_gcc=$_LT_AC_TAGVAR(GCC, $1)
4599
+
4600
+# An ERE matcher.
4601
+EGREP=$lt_EGREP
4602
+
4603
+# The linker used to build libraries.
4604
+LD=$lt_[]_LT_AC_TAGVAR(LD, $1)
4605
+
4606
+# Whether we need hard or soft links.
4607
+LN_S=$lt_LN_S
4608
+
4609
+# A BSD-compatible nm program.
4610
+NM=$lt_NM
4611
+
4612
+# A symbol stripping program
4613
+STRIP=$lt_STRIP
4614
+
4615
+# Used to examine libraries when file_magic_cmd begins "file"
4616
+MAGIC_CMD=$MAGIC_CMD
4617
+
4618
+# Used on cygwin: DLL creation program.
4619
+DLLTOOL="$DLLTOOL"
4620
+
4621
+# Used on cygwin: object dumper.
4622
+OBJDUMP="$OBJDUMP"
4623
+
4624
+# Used on cygwin: assembler.
4625
+AS="$AS"
4626
+
4627
+# The name of the directory that contains temporary libtool files.
4628
+objdir=$objdir
4629
+
4630
+# How to create reloadable object files.
4631
+reload_flag=$lt_reload_flag
4632
+reload_cmds=$lt_reload_cmds
4633
+
4634
+# How to pass a linker flag through the compiler.
4635
+wl=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_wl, $1)
4636
+
4637
+# Object file suffix (normally "o").
4638
+objext="$ac_objext"
4639
+
4640
+# Old archive suffix (normally "a").
4641
+libext="$libext"
4642
+
4643
+# Shared library suffix (normally ".so").
4644
+shrext_cmds='$shrext_cmds'
4645
+
4646
+# Executable file suffix (normally "").
4647
+exeext="$exeext"
4648
+
4649
+# Additional compiler flags for building library objects.
4650
+pic_flag=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)
4651
+pic_mode=$pic_mode
4652
+
4653
+# What is the maximum length of a command?
4654
+max_cmd_len=$lt_cv_sys_max_cmd_len
4655
+
4656
+# Does compiler simultaneously support -c and -o options?
4657
+compiler_c_o=$lt_[]_LT_AC_TAGVAR(lt_cv_prog_compiler_c_o, $1)
4658
+
4659
+# Must we lock files when doing compilation?
4660
+need_locks=$lt_need_locks
4661
+
4662
+# Do we need the lib prefix for modules?
4663
+need_lib_prefix=$need_lib_prefix
4664
+
4665
+# Do we need a version for libraries?
4666
+need_version=$need_version
4667
+
4668
+# Whether dlopen is supported.
4669
+dlopen_support=$enable_dlopen
4670
+
4671
+# Whether dlopen of programs is supported.
4672
+dlopen_self=$enable_dlopen_self
4673
+
4674
+# Whether dlopen of statically linked programs is supported.
4675
+dlopen_self_static=$enable_dlopen_self_static
4676
+
4677
+# Compiler flag to prevent dynamic linking.
4678
+link_static_flag=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_static, $1)
4679
+
4680
+# Compiler flag to turn off builtin functions.
4681
+no_builtin_flag=$lt_[]_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)
4682
+
4683
+# Compiler flag to allow reflexive dlopens.
4684
+export_dynamic_flag_spec=$lt_[]_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)
4685
+
4686
+# Compiler flag to generate shared objects directly from archives.
4687
+whole_archive_flag_spec=$lt_[]_LT_AC_TAGVAR(whole_archive_flag_spec, $1)
4688
+
4689
+# Compiler flag to generate thread-safe objects.
4690
+thread_safe_flag_spec=$lt_[]_LT_AC_TAGVAR(thread_safe_flag_spec, $1)
4691
+
4692
+# Library versioning type.
4693
+version_type=$version_type
4694
+
4695
+# Format of library name prefix.
4696
+libname_spec=$lt_libname_spec
4697
+
4698
+# List of archive names.  First name is the real one, the rest are links.
4699
+# The last name is the one that the linker finds with -lNAME.
4700
+library_names_spec=$lt_library_names_spec
4701
+
4702
+# The coded name of the library, if different from the real name.
4703
+soname_spec=$lt_soname_spec
4704
+
4705
+# Commands used to build and install an old-style archive.
4706
+RANLIB=$lt_RANLIB
4707
+old_archive_cmds=$lt_[]_LT_AC_TAGVAR(old_archive_cmds, $1)
4708
+old_postinstall_cmds=$lt_old_postinstall_cmds
4709
+old_postuninstall_cmds=$lt_old_postuninstall_cmds
4710
+
4711
+# Create an old-style archive from a shared archive.
4712
+old_archive_from_new_cmds=$lt_[]_LT_AC_TAGVAR(old_archive_from_new_cmds, $1)
4713
+
4714
+# Create a temporary old-style archive to link instead of a shared archive.
4715
+old_archive_from_expsyms_cmds=$lt_[]_LT_AC_TAGVAR(old_archive_from_expsyms_cmds, $1)
4716
+
4717
+# Commands used to build and install a shared archive.
4718
+archive_cmds=$lt_[]_LT_AC_TAGVAR(archive_cmds, $1)
4719
+archive_expsym_cmds=$lt_[]_LT_AC_TAGVAR(archive_expsym_cmds, $1)
4720
+postinstall_cmds=$lt_postinstall_cmds
4721
+postuninstall_cmds=$lt_postuninstall_cmds
4722
+
4723
+# Commands used to build a loadable module (assumed same as above if empty)
4724
+module_cmds=$lt_[]_LT_AC_TAGVAR(module_cmds, $1)
4725
+module_expsym_cmds=$lt_[]_LT_AC_TAGVAR(module_expsym_cmds, $1)
4726
+
4727
+# Commands to strip libraries.
4728
+old_striplib=$lt_old_striplib
4729
+striplib=$lt_striplib
4730
+
4731
+# Dependencies to place before the objects being linked to create a
4732
+# shared library.
4733
+predep_objects=$lt_[]_LT_AC_TAGVAR(predep_objects, $1)
4734
+
4735
+# Dependencies to place after the objects being linked to create a
4736
+# shared library.
4737
+postdep_objects=$lt_[]_LT_AC_TAGVAR(postdep_objects, $1)
4738
+
4739
+# Dependencies to place before the objects being linked to create a
4740
+# shared library.
4741
+predeps=$lt_[]_LT_AC_TAGVAR(predeps, $1)
4742
+
4743
+# Dependencies to place after the objects being linked to create a
4744
+# shared library.
4745
+postdeps=$lt_[]_LT_AC_TAGVAR(postdeps, $1)
4746
+
4747
+# The directories searched by this compiler when creating a shared
4748
+# library
4749
+compiler_lib_search_dirs=$lt_[]_LT_AC_TAGVAR(compiler_lib_search_dirs, $1)
4750
+
4751
+# The library search path used internally by the compiler when linking
4752
+# a shared library.
4753
+compiler_lib_search_path=$lt_[]_LT_AC_TAGVAR(compiler_lib_search_path, $1)
4754
+
4755
+# Method to check whether dependent libraries are shared objects.
4756
+deplibs_check_method=$lt_deplibs_check_method
4757
+
4758
+# Command to use when deplibs_check_method == file_magic.
4759
+file_magic_cmd=$lt_file_magic_cmd
4760
+
4761
+# Flag that allows shared libraries with undefined symbols to be built.
4762
+allow_undefined_flag=$lt_[]_LT_AC_TAGVAR(allow_undefined_flag, $1)
4763
+
4764
+# Flag that forces no undefined symbols.
4765
+no_undefined_flag=$lt_[]_LT_AC_TAGVAR(no_undefined_flag, $1)
4766
+
4767
+# Commands used to finish a libtool library installation in a directory.
4768
+finish_cmds=$lt_finish_cmds
4769
+
4770
+# Same as above, but a single script fragment to be evaled but not shown.
4771
+finish_eval=$lt_finish_eval
4772
+
4773
+# Take the output of nm and produce a listing of raw symbols and C names.
4774
+global_symbol_pipe=$lt_lt_cv_sys_global_symbol_pipe
4775
+
4776
+# Transform the output of nm in a proper C declaration
4777
+global_symbol_to_cdecl=$lt_lt_cv_sys_global_symbol_to_cdecl
4778
+
4779
+# Transform the output of nm in a C name address pair
4780
+global_symbol_to_c_name_address=$lt_lt_cv_sys_global_symbol_to_c_name_address
4781
+
4782
+# This is the shared library runtime path variable.
4783
+runpath_var=$runpath_var
4784
+
4785
+# This is the shared library path variable.
4786
+shlibpath_var=$shlibpath_var
4787
+
4788
+# Is shlibpath searched before the hard-coded library search path?
4789
+shlibpath_overrides_runpath=$shlibpath_overrides_runpath
4790
+
4791
+# How to hardcode a shared library path into an executable.
4792
+hardcode_action=$_LT_AC_TAGVAR(hardcode_action, $1)
4793
+
4794
+# Whether we should hardcode library paths into libraries.
4795
+hardcode_into_libs=$hardcode_into_libs
4796
+
4797
+# Flag to hardcode \$libdir into a binary during linking.
4798
+# This must work even if \$libdir does not exist.
4799
+hardcode_libdir_flag_spec=$lt_[]_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)
4800
+
4801
+# If ld is used when linking, flag to hardcode \$libdir into
4802
+# a binary during linking. This must work even if \$libdir does
4803
+# not exist.
4804
+hardcode_libdir_flag_spec_ld=$lt_[]_LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)
4805
+
4806
+# Whether we need a single -rpath flag with a separated argument.
4807
+hardcode_libdir_separator=$lt_[]_LT_AC_TAGVAR(hardcode_libdir_separator, $1)
4808
+
4809
+# Set to yes if using DIR/libNAME${shared_ext} during linking hardcodes DIR into the
4810
+# resulting binary.
4811
+hardcode_direct=$_LT_AC_TAGVAR(hardcode_direct, $1)
4812
+
4813
+# Set to yes if using the -LDIR flag during linking hardcodes DIR into the
4814
+# resulting binary.
4815
+hardcode_minus_L=$_LT_AC_TAGVAR(hardcode_minus_L, $1)
4816
+
4817
+# Set to yes if using SHLIBPATH_VAR=DIR during linking hardcodes DIR into
4818
+# the resulting binary.
4819
+hardcode_shlibpath_var=$_LT_AC_TAGVAR(hardcode_shlibpath_var, $1)
4820
+
4821
+# Set to yes if building a shared library automatically hardcodes DIR into the library
4822
+# and all subsequent libraries and executables linked against it.
4823
+hardcode_automatic=$_LT_AC_TAGVAR(hardcode_automatic, $1)
4824
+
4825
+# Variables whose values should be saved in libtool wrapper scripts and
4826
+# restored at relink time.
4827
+variables_saved_for_relink="$variables_saved_for_relink"
4828
+
4829
+# Whether libtool must link a program against all its dependency libraries.
4830
+link_all_deplibs=$_LT_AC_TAGVAR(link_all_deplibs, $1)
4831
+
4832
+# Compile-time system search path for libraries
4833
+sys_lib_search_path_spec=$lt_sys_lib_search_path_spec
4834
+
4835
+# Run-time system search path for libraries
4836
+sys_lib_dlsearch_path_spec=$lt_sys_lib_dlsearch_path_spec
4837
+
4838
+# Fix the shell variable \$srcfile for the compiler.
4839
+fix_srcfile_path=$lt_fix_srcfile_path
4840
+
4841
+# Set to yes if exported symbols are required.
4842
+always_export_symbols=$_LT_AC_TAGVAR(always_export_symbols, $1)
4843
+
4844
+# The commands to list exported symbols.
4845
+export_symbols_cmds=$lt_[]_LT_AC_TAGVAR(export_symbols_cmds, $1)
4846
+
4847
+# The commands to extract the exported symbol list from a shared archive.
4848
+extract_expsyms_cmds=$lt_extract_expsyms_cmds
4849
+
4850
+# Symbols that should not be listed in the preloaded symbols.
4851
+exclude_expsyms=$lt_[]_LT_AC_TAGVAR(exclude_expsyms, $1)
4852
+
4853
+# Symbols that must always be exported.
4854
+include_expsyms=$lt_[]_LT_AC_TAGVAR(include_expsyms, $1)
4855
+
4856
+ifelse([$1],[],
4857
+[# ### END LIBTOOL CONFIG],
4858
+[# ### END LIBTOOL TAG CONFIG: $tagname])
4859
+
4860
+__EOF__
4861
+
4862
+ifelse([$1],[], [
4863
+  case $host_os in
4864
+  aix3*)
4865
+    cat <<\EOF >> "$cfgfile"
4866
+
4867
+# AIX sometimes has problems with the GCC collect2 program.  For some
4868
+# reason, if we set the COLLECT_NAMES environment variable, the problems
4869
+# vanish in a puff of smoke.
4870
+if test "X${COLLECT_NAMES+set}" != Xset; then
4871
+  COLLECT_NAMES=
4872
+  export COLLECT_NAMES
4873
+fi
4874
+EOF
4875
+    ;;
4876
+  esac
4877
+
4878
+  # We use sed instead of cat because bash on DJGPP gets confused if
4879
+  # if finds mixed CR/LF and LF-only lines.  Since sed operates in
4880
+  # text mode, it properly converts lines to CR/LF.  This bash problem
4881
+  # is reportedly fixed, but why not run on old versions too?
4882
+  sed '$q' "$ltmain" >> "$cfgfile" || (rm -f "$cfgfile"; exit 1)
4883
+
4884
+  mv -f "$cfgfile" "$ofile" || \
4885
+    (rm -f "$ofile" && cp "$cfgfile" "$ofile" && rm -f "$cfgfile")
4886
+  chmod +x "$ofile"
4887
+])
4888
+else
4889
+  # If there is no Makefile yet, we rely on a make rule to execute
4890
+  # `config.status --recheck' to rerun these tests and create the
4891
+  # libtool script then.
4892
+  ltmain_in=`echo $ltmain | sed -e 's/\.sh$/.in/'`
4893
+  if test -f "$ltmain_in"; then
4894
+    test -f Makefile && make "$ltmain"
4895
+  fi
4896
+fi
4897
+])# AC_LIBTOOL_CONFIG
4898
+
4899
+
4900
+# AC_LIBTOOL_PROG_COMPILER_NO_RTTI([TAGNAME])
4901
+# -------------------------------------------
4902
+AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_NO_RTTI],
4903
+[AC_REQUIRE([_LT_AC_SYS_COMPILER])dnl
4904
+
4905
+_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=
4906
+
4907
+if test "$GCC" = yes; then
4908
+  _LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)=' -fno-builtin'
4909
+
4910
+  AC_LIBTOOL_COMPILER_OPTION([if $compiler supports -fno-rtti -fno-exceptions],
4911
+    lt_cv_prog_compiler_rtti_exceptions,
4912
+    [-fno-rtti -fno-exceptions], [],
4913
+    [_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)="$_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1) -fno-rtti -fno-exceptions"])
4914
+fi
4915
+])# AC_LIBTOOL_PROG_COMPILER_NO_RTTI
4916
+
4917
+
4918
+# AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE
4919
+# ---------------------------------
4920
+AC_DEFUN([AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE],
4921
+[AC_REQUIRE([AC_CANONICAL_HOST])
4922
+AC_REQUIRE([LT_AC_PROG_SED])
4923
+AC_REQUIRE([AC_PROG_NM])
4924
+AC_REQUIRE([AC_OBJEXT])
4925
+# Check for command to grab the raw symbol name followed by C symbol from nm.
4926
+AC_MSG_CHECKING([command to parse $NM output from $compiler object])
4927
+AC_CACHE_VAL([lt_cv_sys_global_symbol_pipe],
4928
+[
4929
+# These are sane defaults that work on at least a few old systems.
4930
+# [They come from Ultrix.  What could be older than Ultrix?!! ;)]
4931
+
4932
+# Character class describing NM global symbol codes.
4933
+symcode='[[BCDEGRST]]'
4934
+
4935
+# Regexp to match symbols that can be accessed directly from C.
4936
+sympat='\([[_A-Za-z]][[_A-Za-z0-9]]*\)'
4937
+
4938
+# Transform an extracted symbol line into a proper C declaration
4939
+lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^. .* \(.*\)$/extern int \1;/p'"
4940
+
4941
+# Transform an extracted symbol line into symbol name and symbol address
4942
+lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/  {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode \([[^ ]]*\) \([[^ ]]*\)$/  {\"\2\", (lt_ptr) \&\2},/p'"
4943
+
4944
+# Define system-specific variables.
4945
+case $host_os in
4946
+aix*)
4947
+  symcode='[[BCDT]]'
4948
+  ;;
4949
+cygwin* | mingw* | pw32*)
4950
+  symcode='[[ABCDGISTW]]'
4951
+  ;;
4952
+hpux*) # Its linker distinguishes data from code symbols
4953
+  if test "$host_cpu" = ia64; then
4954
+    symcode='[[ABCDEGRST]]'
4955
+  fi
4956
+  lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
4957
+  lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/  {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/  {\"\2\", (lt_ptr) \&\2},/p'"
4958
+  ;;
4959
+linux* | k*bsd*-gnu)
4960
+  if test "$host_cpu" = ia64; then
4961
+    symcode='[[ABCDGIRSTW]]'
4962
+    lt_cv_sys_global_symbol_to_cdecl="sed -n -e 's/^T .* \(.*\)$/extern int \1();/p' -e 's/^$symcode* .* \(.*\)$/extern char \1;/p'"
4963
+    lt_cv_sys_global_symbol_to_c_name_address="sed -n -e 's/^: \([[^ ]]*\) $/  {\\\"\1\\\", (lt_ptr) 0},/p' -e 's/^$symcode* \([[^ ]]*\) \([[^ ]]*\)$/  {\"\2\", (lt_ptr) \&\2},/p'"
4964
+  fi
4965
+  ;;
4966
+irix* | nonstopux*)
4967
+  symcode='[[BCDEGRST]]'
4968
+  ;;
4969
+osf*)
4970
+  symcode='[[BCDEGQRST]]'
4971
+  ;;
4972
+solaris*)
4973
+  symcode='[[BDRT]]'
4974
+  ;;
4975
+sco3.2v5*)
4976
+  symcode='[[DT]]'
4977
+  ;;
4978
+sysv4.2uw2*)
4979
+  symcode='[[DT]]'
4980
+  ;;
4981
+sysv5* | sco5v6* | unixware* | OpenUNIX*)
4982
+  symcode='[[ABDT]]'
4983
+  ;;
4984
+sysv4)
4985
+  symcode='[[DFNSTU]]'
4986
+  ;;
4987
+esac
4988
+
4989
+# Handle CRLF in mingw tool chain
4990
+opt_cr=
4991
+case $build_os in
4992
+mingw*)
4993
+  opt_cr=`echo 'x\{0,1\}' | tr x '\015'` # option cr in regexp
4994
+  ;;
4995
+esac
4996
+
4997
+# If we're using GNU nm, then use its standard symbol codes.
4998
+case `$NM -V 2>&1` in
4999
+*GNU* | *'with BFD'*)
5000
+  symcode='[[ABCDGIRSTW]]' ;;
5001
+esac
5002
+
5003
+# Try without a prefix undercore, then with it.
5004
+for ac_symprfx in "" "_"; do
5005
+
5006
+  # Transform symcode, sympat, and symprfx into a raw symbol and a C symbol.
5007
+  symxfrm="\\1 $ac_symprfx\\2 \\2"
5008
+
5009
+  # Write the raw and C identifiers.
5010
+  lt_cv_sys_global_symbol_pipe="sed -n -e 's/^.*[[ 	]]\($symcode$symcode*\)[[ 	]][[ 	]]*$ac_symprfx$sympat$opt_cr$/$symxfrm/p'"
5011
+
5012
+  # Check to see that the pipe works correctly.
5013
+  pipe_works=no
5014
+
5015
+  rm -f conftest*
5016
+  cat > conftest.$ac_ext <<EOF
5017
+#ifdef __cplusplus
5018
+extern "C" {
5019
+#endif
5020
+char nm_test_var;
5021
+void nm_test_func(){}
5022
+#ifdef __cplusplus
5023
+}
5024
+#endif
5025
+int main(){nm_test_var='a';nm_test_func();return(0);}
5026
+EOF
5027
+
5028
+  if AC_TRY_EVAL(ac_compile); then
5029
+    # Now try to grab the symbols.
5030
+    nlist=conftest.nm
5031
+    if AC_TRY_EVAL(NM conftest.$ac_objext \| $lt_cv_sys_global_symbol_pipe \> $nlist) && test -s "$nlist"; then
5032
+      # Try sorting and uniquifying the output.
5033
+      if sort "$nlist" | uniq > "$nlist"T; then
5034
+	mv -f "$nlist"T "$nlist"
5035
+      else
5036
+	rm -f "$nlist"T
5037
+      fi
5038
+
5039
+      # Make sure that we snagged all the symbols we need.
5040
+      if grep ' nm_test_var$' "$nlist" >/dev/null; then
5041
+	if grep ' nm_test_func$' "$nlist" >/dev/null; then
5042
+	  cat <<EOF > conftest.$ac_ext
5043
+#ifdef __cplusplus
5044
+extern "C" {
5045
+#endif
5046
+
5047
+EOF
5048
+	  # Now generate the symbol file.
5049
+	  eval "$lt_cv_sys_global_symbol_to_cdecl"' < "$nlist" | grep -v main >> conftest.$ac_ext'
5050
+
5051
+	  cat <<EOF >> conftest.$ac_ext
5052
+#if defined (__STDC__) && __STDC__
5053
+# define lt_ptr_t void *
5054
+#else
5055
+# define lt_ptr_t char *
5056
+# define const
5057
+#endif
5058
+
5059
+/* The mapping between symbol names and symbols. */
5060
+const struct {
5061
+  const char *name;
5062
+  lt_ptr_t address;
5063
+}
5064
+lt_preloaded_symbols[[]] =
5065
+{
5066
+EOF
5067
+	  $SED "s/^$symcode$symcode* \(.*\) \(.*\)$/  {\"\2\", (lt_ptr_t) \&\2},/" < "$nlist" | grep -v main >> conftest.$ac_ext
5068
+	  cat <<\EOF >> conftest.$ac_ext
5069
+  {0, (lt_ptr_t) 0}
5070
+};
5071
+
5072
+#ifdef __cplusplus
5073
+}
5074
+#endif
5075
+EOF
5076
+	  # Now try linking the two files.
5077
+	  mv conftest.$ac_objext conftstm.$ac_objext
5078
+	  lt_save_LIBS="$LIBS"
5079
+	  lt_save_CFLAGS="$CFLAGS"
5080
+	  LIBS="conftstm.$ac_objext"
5081
+	  CFLAGS="$CFLAGS$_LT_AC_TAGVAR(lt_prog_compiler_no_builtin_flag, $1)"
5082
+	  if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext}; then
5083
+	    pipe_works=yes
5084
+	  fi
5085
+	  LIBS="$lt_save_LIBS"
5086
+	  CFLAGS="$lt_save_CFLAGS"
5087
+	else
5088
+	  echo "cannot find nm_test_func in $nlist" >&AS_MESSAGE_LOG_FD
5089
+	fi
5090
+      else
5091
+	echo "cannot find nm_test_var in $nlist" >&AS_MESSAGE_LOG_FD
5092
+      fi
5093
+    else
5094
+      echo "cannot run $lt_cv_sys_global_symbol_pipe" >&AS_MESSAGE_LOG_FD
5095
+    fi
5096
+  else
5097
+    echo "$progname: failed program was:" >&AS_MESSAGE_LOG_FD
5098
+    cat conftest.$ac_ext >&5
5099
+  fi
5100
+  rm -rf conftest* conftst*
5101
+
5102
+  # Do not use the global_symbol_pipe unless it works.
5103
+  if test "$pipe_works" = yes; then
5104
+    break
5105
+  else
5106
+    lt_cv_sys_global_symbol_pipe=
5107
+  fi
5108
+done
5109
+])
5110
+if test -z "$lt_cv_sys_global_symbol_pipe"; then
5111
+  lt_cv_sys_global_symbol_to_cdecl=
5112
+fi
5113
+if test -z "$lt_cv_sys_global_symbol_pipe$lt_cv_sys_global_symbol_to_cdecl"; then
5114
+  AC_MSG_RESULT(failed)
5115
+else
5116
+  AC_MSG_RESULT(ok)
5117
+fi
5118
+]) # AC_LIBTOOL_SYS_GLOBAL_SYMBOL_PIPE
5119
+
5120
+
5121
+# AC_LIBTOOL_PROG_COMPILER_PIC([TAGNAME])
5122
+# ---------------------------------------
5123
+AC_DEFUN([AC_LIBTOOL_PROG_COMPILER_PIC],
5124
+[_LT_AC_TAGVAR(lt_prog_compiler_wl, $1)=
5125
+_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=
5126
+_LT_AC_TAGVAR(lt_prog_compiler_static, $1)=
5127
+
5128
+AC_MSG_CHECKING([for $compiler option to produce PIC])
5129
+ ifelse([$1],[CXX],[
5130
+  # C++ specific cases for pic, static, wl, etc.
5131
+  if test "$GXX" = yes; then
5132
+    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5133
+    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static'
5134
+
5135
+    case $host_os in
5136
+    aix*)
5137
+      # All AIX code is PIC.
5138
+      if test "$host_cpu" = ia64; then
5139
+	# AIX 5 now supports IA64 processor
5140
+	_LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
5141
+      fi
5142
+      ;;
5143
+    amigaos*)
5144
+      # FIXME: we need at least 68020 code to build shared libraries, but
5145
+      # adding the `-m68020' flag to GCC prevents building anything better,
5146
+      # like `-m68040'.
5147
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4'
5148
+      ;;
5149
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
5150
+      # PIC is the default for these OSes.
5151
+      ;;
5152
+    mingw* | cygwin* | os2* | pw32*)
5153
+      # This hack is so that the source file can tell whether it is being
5154
+      # built for inclusion in a dll (and should export symbols for example).
5155
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
5156
+      # (--disable-auto-import) libraries
5157
+      m4_if([$1], [GCJ], [],
5158
+	[_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
5159
+      ;;
5160
+    darwin* | rhapsody*)
5161
+      # PIC is the default on this platform
5162
+      # Common symbols not allowed in MH_DYLIB files
5163
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common'
5164
+      ;;
5165
+    *djgpp*)
5166
+      # DJGPP does not support shared libraries at all
5167
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=
5168
+      ;;
5169
+    interix[[3-9]]*)
5170
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
5171
+      # Instead, we relocate shared libraries at runtime.
5172
+      ;;
5173
+    sysv4*MP*)
5174
+      if test -d /usr/nec; then
5175
+	_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic
5176
+      fi
5177
+      ;;
5178
+    hpux*)
5179
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
5180
+      # not for PA HP-UX.
5181
+      case $host_cpu in
5182
+      hppa*64*|ia64*)
5183
+	;;
5184
+      *)
5185
+	_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
5186
+	;;
5187
+      esac
5188
+      ;;
5189
+    *)
5190
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
5191
+      ;;
5192
+    esac
5193
+  else
5194
+    case $host_os in
5195
+      aix[[4-9]]*)
5196
+	# All AIX code is PIC.
5197
+	if test "$host_cpu" = ia64; then
5198
+	  # AIX 5 now supports IA64 processor
5199
+	  _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
5200
+	else
5201
+	  _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
5202
+	fi
5203
+	;;
5204
+      chorus*)
5205
+	case $cc_basename in
5206
+	cxch68*)
5207
+	  # Green Hills C++ Compiler
5208
+	  # _LT_AC_TAGVAR(lt_prog_compiler_static, $1)="--no_auto_instantiation -u __main -u __premain -u _abort -r $COOL_DIR/lib/libOrb.a $MVME_DIR/lib/CC/libC.a $MVME_DIR/lib/classix/libcx.s.a"
5209
+	  ;;
5210
+	esac
5211
+	;;
5212
+       darwin*)
5213
+         # PIC is the default on this platform
5214
+         # Common symbols not allowed in MH_DYLIB files
5215
+         case $cc_basename in
5216
+           xlc*)
5217
+           _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-qnocommon'
5218
+           _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5219
+           ;;
5220
+         esac
5221
+       ;;
5222
+      dgux*)
5223
+	case $cc_basename in
5224
+	  ec++*)
5225
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
5226
+	    ;;
5227
+	  ghcx*)
5228
+	    # Green Hills C++ Compiler
5229
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
5230
+	    ;;
5231
+	  *)
5232
+	    ;;
5233
+	esac
5234
+	;;
5235
+      freebsd* | dragonfly*)
5236
+	# FreeBSD uses GNU C++
5237
+	;;
5238
+      hpux9* | hpux10* | hpux11*)
5239
+	case $cc_basename in
5240
+	  CC*)
5241
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5242
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
5243
+	    if test "$host_cpu" != ia64; then
5244
+	      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
5245
+	    fi
5246
+	    ;;
5247
+	  aCC*)
5248
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5249
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
5250
+	    case $host_cpu in
5251
+	    hppa*64*|ia64*)
5252
+	      # +Z the default
5253
+	      ;;
5254
+	    *)
5255
+	      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
5256
+	      ;;
5257
+	    esac
5258
+	    ;;
5259
+	  *)
5260
+	    ;;
5261
+	esac
5262
+	;;
5263
+      interix*)
5264
+	# This is c89, which is MS Visual C++ (no shared libs)
5265
+	# Anyone wants to do a port?
5266
+	;;
5267
+      irix5* | irix6* | nonstopux*)
5268
+	case $cc_basename in
5269
+	  CC*)
5270
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5271
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
5272
+	    # CC pic flag -KPIC is the default.
5273
+	    ;;
5274
+	  *)
5275
+	    ;;
5276
+	esac
5277
+	;;
5278
+      linux* | k*bsd*-gnu)
5279
+	case $cc_basename in
5280
+	  KCC*)
5281
+	    # KAI C++ Compiler
5282
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,'
5283
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
5284
+	    ;;
5285
+	  icpc* | ecpc*)
5286
+	    # Intel C++
5287
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5288
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
5289
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static'
5290
+	    ;;
5291
+	  pgCC* | pgcpp*)
5292
+	    # Portland Group C++ compiler.
5293
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5294
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
5295
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
5296
+	    ;;
5297
+	  cxx*)
5298
+	    # Compaq C++
5299
+	    # Make sure the PIC flag is empty.  It appears that all Alpha
5300
+	    # Linux and Compaq Tru64 Unix objects are PIC.
5301
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=
5302
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
5303
+	    ;;
5304
+	  *)
5305
+	    case `$CC -V 2>&1 | sed 5q` in
5306
+	    *Sun\ C*)
5307
+	      # Sun C++ 5.9
5308
+	      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
5309
+	      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
5310
+	      _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
5311
+	      ;;
5312
+	    esac
5313
+	    ;;
5314
+	esac
5315
+	;;
5316
+      lynxos*)
5317
+	;;
5318
+      m88k*)
5319
+	;;
5320
+      mvs*)
5321
+	case $cc_basename in
5322
+	  cxx*)
5323
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-W c,exportall'
5324
+	    ;;
5325
+	  *)
5326
+	    ;;
5327
+	esac
5328
+	;;
5329
+      netbsd* | netbsdelf*-gnu)
5330
+	;;
5331
+      osf3* | osf4* | osf5*)
5332
+	case $cc_basename in
5333
+	  KCC*)
5334
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='--backend -Wl,'
5335
+	    ;;
5336
+	  RCC*)
5337
+	    # Rational C++ 2.4.1
5338
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
5339
+	    ;;
5340
+	  cxx*)
5341
+	    # Digital/Compaq C++
5342
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5343
+	    # Make sure the PIC flag is empty.  It appears that all Alpha
5344
+	    # Linux and Compaq Tru64 Unix objects are PIC.
5345
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=
5346
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
5347
+	    ;;
5348
+	  *)
5349
+	    ;;
5350
+	esac
5351
+	;;
5352
+      psos*)
5353
+	;;
5354
+      solaris*)
5355
+	case $cc_basename in
5356
+	  CC*)
5357
+	    # Sun C++ 4.2, 5.x and Centerline C++
5358
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
5359
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
5360
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
5361
+	    ;;
5362
+	  gcx*)
5363
+	    # Green Hills C++ Compiler
5364
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
5365
+	    ;;
5366
+	  *)
5367
+	    ;;
5368
+	esac
5369
+	;;
5370
+      sunos4*)
5371
+	case $cc_basename in
5372
+	  CC*)
5373
+	    # Sun C++ 4.x
5374
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
5375
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
5376
+	    ;;
5377
+	  lcc*)
5378
+	    # Lucid
5379
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
5380
+	    ;;
5381
+	  *)
5382
+	    ;;
5383
+	esac
5384
+	;;
5385
+      tandem*)
5386
+	case $cc_basename in
5387
+	  NCC*)
5388
+	    # NonStop-UX NCC 3.20
5389
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
5390
+	    ;;
5391
+	  *)
5392
+	    ;;
5393
+	esac
5394
+	;;
5395
+      sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
5396
+	case $cc_basename in
5397
+	  CC*)
5398
+	    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5399
+	    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
5400
+	    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
5401
+	    ;;
5402
+	esac
5403
+	;;
5404
+      vxworks*)
5405
+	;;
5406
+      *)
5407
+	_LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
5408
+	;;
5409
+    esac
5410
+  fi
5411
+],
5412
+[
5413
+  if test "$GCC" = yes; then
5414
+    _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5415
+    _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static'
5416
+
5417
+    case $host_os in
5418
+      aix*)
5419
+      # All AIX code is PIC.
5420
+      if test "$host_cpu" = ia64; then
5421
+	# AIX 5 now supports IA64 processor
5422
+	_LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
5423
+      fi
5424
+      ;;
5425
+
5426
+    amigaos*)
5427
+      # FIXME: we need at least 68020 code to build shared libraries, but
5428
+      # adding the `-m68020' flag to GCC prevents building anything better,
5429
+      # like `-m68040'.
5430
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-m68020 -resident32 -malways-restore-a4'
5431
+      ;;
5432
+
5433
+    beos* | irix5* | irix6* | nonstopux* | osf3* | osf4* | osf5*)
5434
+      # PIC is the default for these OSes.
5435
+      ;;
5436
+
5437
+    mingw* | cygwin* | pw32* | os2*)
5438
+      # This hack is so that the source file can tell whether it is being
5439
+      # built for inclusion in a dll (and should export symbols for example).
5440
+      # Although the cygwin gcc ignores -fPIC, still need this for old-style
5441
+      # (--disable-auto-import) libraries
5442
+      m4_if([$1], [GCJ], [],
5443
+	[_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
5444
+      ;;
5445
+
5446
+    darwin* | rhapsody*)
5447
+      # PIC is the default on this platform
5448
+      # Common symbols not allowed in MH_DYLIB files
5449
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fno-common'
5450
+      ;;
5451
+
5452
+    interix[[3-9]]*)
5453
+      # Interix 3.x gcc -fpic/-fPIC options generate broken code.
5454
+      # Instead, we relocate shared libraries at runtime.
5455
+      ;;
5456
+
5457
+    msdosdjgpp*)
5458
+      # Just because we use GCC doesn't mean we suddenly get shared libraries
5459
+      # on systems that don't support them.
5460
+      _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
5461
+      enable_shared=no
5462
+      ;;
5463
+
5464
+    sysv4*MP*)
5465
+      if test -d /usr/nec; then
5466
+	_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=-Kconform_pic
5467
+      fi
5468
+      ;;
5469
+
5470
+    hpux*)
5471
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
5472
+      # not for PA HP-UX.
5473
+      case $host_cpu in
5474
+      hppa*64*|ia64*)
5475
+	# +Z the default
5476
+	;;
5477
+      *)
5478
+	_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
5479
+	;;
5480
+      esac
5481
+      ;;
5482
+
5483
+    *)
5484
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fPIC'
5485
+      ;;
5486
+    esac
5487
+  else
5488
+    # PORTME Check for flag to pass linker flags through the system compiler.
5489
+    case $host_os in
5490
+    aix*)
5491
+      _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5492
+      if test "$host_cpu" = ia64; then
5493
+	# AIX 5 now supports IA64 processor
5494
+	_LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
5495
+      else
5496
+	_LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-bnso -bI:/lib/syscalls.exp'
5497
+      fi
5498
+      ;;
5499
+      darwin*)
5500
+        # PIC is the default on this platform
5501
+        # Common symbols not allowed in MH_DYLIB files
5502
+       case $cc_basename in
5503
+         xlc*)
5504
+         _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-qnocommon'
5505
+         _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5506
+         ;;
5507
+       esac
5508
+       ;;
5509
+
5510
+    mingw* | cygwin* | pw32* | os2*)
5511
+      # This hack is so that the source file can tell whether it is being
5512
+      # built for inclusion in a dll (and should export symbols for example).
5513
+      m4_if([$1], [GCJ], [],
5514
+	[_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-DDLL_EXPORT'])
5515
+      ;;
5516
+
5517
+    hpux9* | hpux10* | hpux11*)
5518
+      _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5519
+      # PIC is the default for IA64 HP-UX and 64-bit HP-UX, but
5520
+      # not for PA HP-UX.
5521
+      case $host_cpu in
5522
+      hppa*64*|ia64*)
5523
+	# +Z the default
5524
+	;;
5525
+      *)
5526
+	_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='+Z'
5527
+	;;
5528
+      esac
5529
+      # Is there a better lt_prog_compiler_static that works with the bundled CC?
5530
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='${wl}-a ${wl}archive'
5531
+      ;;
5532
+
5533
+    irix5* | irix6* | nonstopux*)
5534
+      _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5535
+      # PIC (with -KPIC) is the default.
5536
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
5537
+      ;;
5538
+
5539
+    newsos6)
5540
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
5541
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
5542
+      ;;
5543
+
5544
+    linux* | k*bsd*-gnu)
5545
+      case $cc_basename in
5546
+      icc* | ecc*)
5547
+	_LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5548
+	_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
5549
+	_LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-static'
5550
+        ;;
5551
+      pgcc* | pgf77* | pgf90* | pgf95*)
5552
+        # Portland Group compilers (*not* the Pentium gcc compiler,
5553
+	# which looks to be a dead project)
5554
+	_LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5555
+	_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-fpic'
5556
+	_LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
5557
+        ;;
5558
+      ccc*)
5559
+        _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5560
+        # All Alpha code is PIC.
5561
+        _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
5562
+        ;;
5563
+      *)
5564
+        case `$CC -V 2>&1 | sed 5q` in
5565
+	*Sun\ C*)
5566
+	  # Sun C 5.9
5567
+	  _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
5568
+	  _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
5569
+	  _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5570
+	  ;;
5571
+	*Sun\ F*)
5572
+	  # Sun Fortran 8.3 passes all unrecognized flags to the linker
5573
+	  _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
5574
+	  _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
5575
+	  _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)=''
5576
+	  ;;
5577
+	esac
5578
+	;;
5579
+      esac
5580
+      ;;
5581
+
5582
+    osf3* | osf4* | osf5*)
5583
+      _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5584
+      # All OSF/1 code is PIC.
5585
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
5586
+      ;;
5587
+
5588
+    rdos*)
5589
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-non_shared'
5590
+      ;;
5591
+
5592
+    solaris*)
5593
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
5594
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
5595
+      case $cc_basename in
5596
+      f77* | f90* | f95*)
5597
+	_LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld ';;
5598
+      *)
5599
+	_LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,';;
5600
+      esac
5601
+      ;;
5602
+
5603
+    sunos4*)
5604
+      _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Qoption ld '
5605
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-PIC'
5606
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
5607
+      ;;
5608
+
5609
+    sysv4 | sysv4.2uw2* | sysv4.3*)
5610
+      _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5611
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
5612
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
5613
+      ;;
5614
+
5615
+    sysv4*MP*)
5616
+      if test -d /usr/nec ;then
5617
+	_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-Kconform_pic'
5618
+	_LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
5619
+      fi
5620
+      ;;
5621
+
5622
+    sysv5* | unixware* | sco3.2v5* | sco5v6* | OpenUNIX*)
5623
+      _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5624
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-KPIC'
5625
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
5626
+      ;;
5627
+
5628
+    unicos*)
5629
+      _LT_AC_TAGVAR(lt_prog_compiler_wl, $1)='-Wl,'
5630
+      _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
5631
+      ;;
5632
+
5633
+    uts4*)
5634
+      _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)='-pic'
5635
+      _LT_AC_TAGVAR(lt_prog_compiler_static, $1)='-Bstatic'
5636
+      ;;
5637
+
5638
+    *)
5639
+      _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no
5640
+      ;;
5641
+    esac
5642
+  fi
5643
+])
5644
+AC_MSG_RESULT([$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)])
5645
+
5646
+#
5647
+# Check to make sure the PIC flag actually works.
5648
+#
5649
+if test -n "$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)"; then
5650
+  AC_LIBTOOL_COMPILER_OPTION([if $compiler PIC flag $_LT_AC_TAGVAR(lt_prog_compiler_pic, $1) works],
5651
+    _LT_AC_TAGVAR(lt_cv_prog_compiler_pic_works, $1),
5652
+    [$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)ifelse([$1],[],[ -DPIC],[ifelse([$1],[CXX],[ -DPIC],[])])], [],
5653
+    [case $_LT_AC_TAGVAR(lt_prog_compiler_pic, $1) in
5654
+     "" | " "*) ;;
5655
+     *) _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=" $_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)" ;;
5656
+     esac],
5657
+    [_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=
5658
+     _LT_AC_TAGVAR(lt_prog_compiler_can_build_shared, $1)=no])
5659
+fi
5660
+case $host_os in
5661
+  # For platforms which do not support PIC, -DPIC is meaningless:
5662
+  *djgpp*)
5663
+    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)=
5664
+    ;;
5665
+  *)
5666
+    _LT_AC_TAGVAR(lt_prog_compiler_pic, $1)="$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)ifelse([$1],[],[ -DPIC],[ifelse([$1],[CXX],[ -DPIC],[])])"
5667
+    ;;
5668
+esac
5669
+
5670
+#
5671
+# Check to make sure the static flag actually works.
5672
+#
5673
+wl=$_LT_AC_TAGVAR(lt_prog_compiler_wl, $1) eval lt_tmp_static_flag=\"$_LT_AC_TAGVAR(lt_prog_compiler_static, $1)\"
5674
+AC_LIBTOOL_LINKER_OPTION([if $compiler static flag $lt_tmp_static_flag works],
5675
+  _LT_AC_TAGVAR(lt_cv_prog_compiler_static_works, $1),
5676
+  $lt_tmp_static_flag,
5677
+  [],
5678
+  [_LT_AC_TAGVAR(lt_prog_compiler_static, $1)=])
5679
+])
5680
+
5681
+
5682
+# AC_LIBTOOL_PROG_LD_SHLIBS([TAGNAME])
5683
+# ------------------------------------
5684
+# See if the linker supports building shared libraries.
5685
+AC_DEFUN([AC_LIBTOOL_PROG_LD_SHLIBS],
5686
+[AC_REQUIRE([LT_AC_PROG_SED])dnl
5687
+AC_MSG_CHECKING([whether the $compiler linker ($LD) supports shared libraries])
5688
+ifelse([$1],[CXX],[
5689
+  _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
5690
+  case $host_os in
5691
+  aix[[4-9]]*)
5692
+    # If we're using GNU nm, then we don't want the "-C" option.
5693
+    # -C means demangle to AIX nm, but means don't demangle with GNU nm
5694
+    if $NM -V 2>&1 | grep 'GNU' > /dev/null; then
5695
+      _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols'
5696
+    else
5697
+      _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols'
5698
+    fi
5699
+    ;;
5700
+  pw32*)
5701
+    _LT_AC_TAGVAR(export_symbols_cmds, $1)="$ltdll_cmds"
5702
+  ;;
5703
+  cygwin* | mingw*)
5704
+    _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/;/^.*[[ ]]__nm__/s/^.*[[ ]]__nm__\([[^ ]]*\)[[ ]][[^ ]]*/\1 DATA/;/^I[[ ]]/d;/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols'
5705
+  ;;
5706
+  linux* | k*bsd*-gnu)
5707
+    _LT_AC_TAGVAR(link_all_deplibs, $1)=no
5708
+  ;;
5709
+  *)
5710
+    _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
5711
+  ;;
5712
+  esac
5713
+  _LT_AC_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*']
5714
+],[
5715
+  runpath_var=
5716
+  _LT_AC_TAGVAR(allow_undefined_flag, $1)=
5717
+  _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=no
5718
+  _LT_AC_TAGVAR(archive_cmds, $1)=
5719
+  _LT_AC_TAGVAR(archive_expsym_cmds, $1)=
5720
+  _LT_AC_TAGVAR(old_archive_From_new_cmds, $1)=
5721
+  _LT_AC_TAGVAR(old_archive_from_expsyms_cmds, $1)=
5722
+  _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)=
5723
+  _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=
5724
+  _LT_AC_TAGVAR(thread_safe_flag_spec, $1)=
5725
+  _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)=
5726
+  _LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)=
5727
+  _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=
5728
+  _LT_AC_TAGVAR(hardcode_direct, $1)=no
5729
+  _LT_AC_TAGVAR(hardcode_minus_L, $1)=no
5730
+  _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
5731
+  _LT_AC_TAGVAR(link_all_deplibs, $1)=unknown
5732
+  _LT_AC_TAGVAR(hardcode_automatic, $1)=no
5733
+  _LT_AC_TAGVAR(module_cmds, $1)=
5734
+  _LT_AC_TAGVAR(module_expsym_cmds, $1)=
5735
+  _LT_AC_TAGVAR(always_export_symbols, $1)=no
5736
+  _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED '\''s/.* //'\'' | sort | uniq > $export_symbols'
5737
+  # include_expsyms should be a list of space-separated symbols to be *always*
5738
+  # included in the symbol list
5739
+  _LT_AC_TAGVAR(include_expsyms, $1)=
5740
+  # exclude_expsyms can be an extended regexp of symbols to exclude
5741
+  # it will be wrapped by ` (' and `)$', so one must not match beginning or
5742
+  # end of line.  Example: `a|bc|.*d.*' will exclude the symbols `a' and `bc',
5743
+  # as well as any symbol that contains `d'.
5744
+  _LT_AC_TAGVAR(exclude_expsyms, $1)=['_GLOBAL_OFFSET_TABLE_|_GLOBAL__F[ID]_.*']
5745
+  # Although _GLOBAL_OFFSET_TABLE_ is a valid symbol C name, most a.out
5746
+  # platforms (ab)use it in PIC code, but their linkers get confused if
5747
+  # the symbol is explicitly referenced.  Since portable code cannot
5748
+  # rely on this symbol name, it's probably fine to never include it in
5749
+  # preloaded symbol tables.
5750
+  # Exclude shared library initialization/finalization symbols.
5751
+dnl Note also adjust exclude_expsyms for C++ above.
5752
+  extract_expsyms_cmds=
5753
+  # Just being paranoid about ensuring that cc_basename is set.
5754
+  _LT_CC_BASENAME([$compiler])
5755
+  case $host_os in
5756
+  cygwin* | mingw* | pw32*)
5757
+    # FIXME: the MSVC++ port hasn't been tested in a loooong time
5758
+    # When not using gcc, we currently assume that we are using
5759
+    # Microsoft Visual C++.
5760
+    if test "$GCC" != yes; then
5761
+      with_gnu_ld=no
5762
+    fi
5763
+    ;;
5764
+  interix*)
5765
+    # we just hope/assume this is gcc and not c89 (= MSVC++)
5766
+    with_gnu_ld=yes
5767
+    ;;
5768
+  openbsd*)
5769
+    with_gnu_ld=no
5770
+    ;;
5771
+  esac
5772
+
5773
+  _LT_AC_TAGVAR(ld_shlibs, $1)=yes
5774
+  if test "$with_gnu_ld" = yes; then
5775
+    # If archive_cmds runs LD, not CC, wlarc should be empty
5776
+    wlarc='${wl}'
5777
+
5778
+    # Set some defaults for GNU ld with shared library support. These
5779
+    # are reset later if shared libraries are not supported. Putting them
5780
+    # here allows them to be overridden if necessary.
5781
+    runpath_var=LD_RUN_PATH
5782
+    _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}--rpath ${wl}$libdir'
5783
+    _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}--export-dynamic'
5784
+    # ancient GNU ld didn't support --whole-archive et. al.
5785
+    if $LD --help 2>&1 | grep 'no-whole-archive' > /dev/null; then
5786
+	_LT_AC_TAGVAR(whole_archive_flag_spec, $1)="$wlarc"'--whole-archive$convenience '"$wlarc"'--no-whole-archive'
5787
+      else
5788
+  	_LT_AC_TAGVAR(whole_archive_flag_spec, $1)=
5789
+    fi
5790
+    supports_anon_versioning=no
5791
+    case `$LD -v 2>/dev/null` in
5792
+      *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.10.*) ;; # catch versions < 2.11
5793
+      *\ 2.11.93.0.2\ *) supports_anon_versioning=yes ;; # RH7.3 ...
5794
+      *\ 2.11.92.0.12\ *) supports_anon_versioning=yes ;; # Mandrake 8.2 ...
5795
+      *\ 2.11.*) ;; # other 2.11 versions
5796
+      *) supports_anon_versioning=yes ;;
5797
+    esac
5798
+
5799
+    # See if GNU ld supports shared libraries.
5800
+    case $host_os in
5801
+    aix[[3-9]]*)
5802
+      # On AIX/PPC, the GNU linker is very broken
5803
+      if test "$host_cpu" != ia64; then
5804
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
5805
+	cat <<EOF 1>&2
5806
+
5807
+*** Warning: the GNU linker, at least up to release 2.9.1, is reported
5808
+*** to be unable to reliably create shared libraries on AIX.
5809
+*** Therefore, libtool is disabling shared libraries support.  If you
5810
+*** really care for shared libraries, you may want to modify your PATH
5811
+*** so that a non-GNU linker is found, and then restart.
5812
+
5813
+EOF
5814
+      fi
5815
+      ;;
5816
+
5817
+    amigaos*)
5818
+      _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
5819
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
5820
+      _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
5821
+
5822
+      # Samuel A. Falvo II <kc5tja@dolphin.openprojects.net> reports
5823
+      # that the semantics of dynamic libraries on AmigaOS, at least up
5824
+      # to version 4, is to share data among multiple programs linked
5825
+      # with the same dynamic library.  Since this doesn't match the
5826
+      # behavior of shared libraries on other platforms, we can't use
5827
+      # them.
5828
+      _LT_AC_TAGVAR(ld_shlibs, $1)=no
5829
+      ;;
5830
+
5831
+    beos*)
5832
+      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
5833
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
5834
+	# Joseph Beckenbach <jrb3@best.com> says some releases of gcc
5835
+	# support --undefined.  This deserves some investigation.  FIXME
5836
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -nostart $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
5837
+      else
5838
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
5839
+      fi
5840
+      ;;
5841
+
5842
+    cygwin* | mingw* | pw32*)
5843
+      # _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1) is actually meaningless,
5844
+      # as there is no search path for DLLs.
5845
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
5846
+      _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
5847
+      _LT_AC_TAGVAR(always_export_symbols, $1)=no
5848
+      _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
5849
+      _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM $libobjs $convenience | $global_symbol_pipe | $SED -e '\''/^[[BCDGRS]][[ ]]/s/.*[[ ]]\([[^ ]]*\)/\1 DATA/'\'' -e '\''/^[[AITW]][[ ]]/s/.*[[ ]]//'\'' | sort | uniq > $export_symbols'
5850
+
5851
+      if $LD --help 2>&1 | grep 'auto-import' > /dev/null; then
5852
+        _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
5853
+	# If the export-symbols file already is a .def file (1st line
5854
+	# is EXPORTS), use it as is; otherwise, prepend...
5855
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='if test "x`$SED 1q $export_symbols`" = xEXPORTS; then
5856
+	  cp $export_symbols $output_objdir/$soname.def;
5857
+	else
5858
+	  echo EXPORTS > $output_objdir/$soname.def;
5859
+	  cat $export_symbols >> $output_objdir/$soname.def;
5860
+	fi~
5861
+	$CC -shared $output_objdir/$soname.def $libobjs $deplibs $compiler_flags -o $output_objdir/$soname ${wl}--enable-auto-image-base -Xlinker --out-implib -Xlinker $lib'
5862
+      else
5863
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
5864
+      fi
5865
+      ;;
5866
+
5867
+    interix[[3-9]]*)
5868
+      _LT_AC_TAGVAR(hardcode_direct, $1)=no
5869
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
5870
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
5871
+      _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
5872
+      # Hack: On Interix 3.x, we cannot compile PIC because of a broken gcc.
5873
+      # Instead, shared libraries are loaded at an image base (0x10000000 by
5874
+      # default) and relocated if they conflict, which is a slow very memory
5875
+      # consuming and fragmenting process.  To avoid this, we pick a random,
5876
+      # 256 KiB-aligned image base between 0x50000000 and 0x6FFC0000 at link
5877
+      # time.  Moving up from 0x10000000 also allows more sbrk(2) space.
5878
+      _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
5879
+      _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed "s,^,_," $export_symbols >$output_objdir/$soname.expsym~$CC -shared $pic_flag $libobjs $deplibs $compiler_flags ${wl}-h,$soname ${wl}--retain-symbols-file,$output_objdir/$soname.expsym ${wl}--image-base,`expr ${RANDOM-$$} % 4096 / 2 \* 262144 + 1342177280` -o $lib'
5880
+      ;;
5881
+
5882
+    gnu* | linux* | k*bsd*-gnu)
5883
+      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
5884
+	tmp_addflag=
5885
+	case $cc_basename,$host_cpu in
5886
+	pgcc*)				# Portland Group C compiler
5887
+	  _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
5888
+	  tmp_addflag=' $pic_flag'
5889
+	  ;;
5890
+	pgf77* | pgf90* | pgf95*)	# Portland Group f77 and f90 compilers
5891
+	  _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`for conv in $convenience\"\"; do test  -n \"$conv\" && new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
5892
+	  tmp_addflag=' $pic_flag -Mnomain' ;;
5893
+	ecc*,ia64* | icc*,ia64*)		# Intel C compiler on ia64
5894
+	  tmp_addflag=' -i_dynamic' ;;
5895
+	efc*,ia64* | ifort*,ia64*)	# Intel Fortran compiler on ia64
5896
+	  tmp_addflag=' -i_dynamic -nofor_main' ;;
5897
+	ifc* | ifort*)			# Intel Fortran compiler
5898
+	  tmp_addflag=' -nofor_main' ;;
5899
+	esac
5900
+	case `$CC -V 2>&1 | sed 5q` in
5901
+	*Sun\ C*)			# Sun C 5.9
5902
+	  _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}--whole-archive`new_convenience=; for conv in $convenience\"\"; do test -z \"$conv\" || new_convenience=\"$new_convenience,$conv\"; done; $echo \"$new_convenience\"` ${wl}--no-whole-archive'
5903
+	  tmp_sharedflag='-G' ;;
5904
+	*Sun\ F*)			# Sun Fortran 8.3
5905
+	  tmp_sharedflag='-G' ;;
5906
+	*)
5907
+	  tmp_sharedflag='-shared' ;;
5908
+	esac
5909
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
5910
+
5911
+	if test $supports_anon_versioning = yes; then
5912
+	  _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $output_objdir/$libname.ver~
5913
+  cat $export_symbols | sed -e "s/\(.*\)/\1;/" >> $output_objdir/$libname.ver~
5914
+  $echo "local: *; };" >> $output_objdir/$libname.ver~
5915
+	  $CC '"$tmp_sharedflag""$tmp_addflag"' $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-version-script ${wl}$output_objdir/$libname.ver -o $lib'
5916
+	fi
5917
+	_LT_AC_TAGVAR(link_all_deplibs, $1)=no
5918
+      else
5919
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
5920
+      fi
5921
+      ;;
5922
+
5923
+    netbsd* | netbsdelf*-gnu)
5924
+      if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
5925
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable $libobjs $deplibs $linker_flags -o $lib'
5926
+	wlarc=
5927
+      else
5928
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
5929
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
5930
+      fi
5931
+      ;;
5932
+
5933
+    solaris*)
5934
+      if $LD -v 2>&1 | grep 'BFD 2\.8' > /dev/null; then
5935
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
5936
+	cat <<EOF 1>&2
5937
+
5938
+*** Warning: The releases 2.8.* of the GNU linker cannot reliably
5939
+*** create shared libraries on Solaris systems.  Therefore, libtool
5940
+*** is disabling shared libraries support.  We urge you to upgrade GNU
5941
+*** binutils to release 2.9.1 or newer.  Another option is to modify
5942
+*** your PATH or compiler configuration so that the native linker is
5943
+*** used, and then restart.
5944
+
5945
+EOF
5946
+      elif $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
5947
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
5948
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
5949
+      else
5950
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
5951
+      fi
5952
+      ;;
5953
+
5954
+    sysv5* | sco3.2v5* | sco5v6* | unixware* | OpenUNIX*)
5955
+      case `$LD -v 2>&1` in
5956
+        *\ [[01]].* | *\ 2.[[0-9]].* | *\ 2.1[[0-5]].*)
5957
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
5958
+	cat <<_LT_EOF 1>&2
5959
+
5960
+*** Warning: Releases of the GNU linker prior to 2.16.91.0.3 can not
5961
+*** reliably create shared libraries on SCO systems.  Therefore, libtool
5962
+*** is disabling shared libraries support.  We urge you to upgrade GNU
5963
+*** binutils to release 2.16.91.0.3 or newer.  Another option is to modify
5964
+*** your PATH or compiler configuration so that the native linker is
5965
+*** used, and then restart.
5966
+
5967
+_LT_EOF
5968
+	;;
5969
+	*)
5970
+	  if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
5971
+	    _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='`test -z "$SCOABSPATH" && echo ${wl}-rpath,$libdir`'
5972
+	    _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib'
5973
+	    _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname,\${SCOABSPATH:+${install_libdir}/}$soname,-retain-symbols-file,$export_symbols -o $lib'
5974
+	  else
5975
+	    _LT_AC_TAGVAR(ld_shlibs, $1)=no
5976
+	  fi
5977
+	;;
5978
+      esac
5979
+      ;;
5980
+
5981
+    sunos4*)
5982
+      _LT_AC_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bshareable -o $lib $libobjs $deplibs $linker_flags'
5983
+      wlarc=
5984
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
5985
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
5986
+      ;;
5987
+
5988
+    *)
5989
+      if $LD --help 2>&1 | grep ': supported targets:.* elf' > /dev/null; then
5990
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname -o $lib'
5991
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname $wl$soname ${wl}-retain-symbols-file $wl$export_symbols -o $lib'
5992
+      else
5993
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
5994
+      fi
5995
+      ;;
5996
+    esac
5997
+
5998
+    if test "$_LT_AC_TAGVAR(ld_shlibs, $1)" = no; then
5999
+      runpath_var=
6000
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)=
6001
+      _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)=
6002
+      _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=
6003
+    fi
6004
+  else
6005
+    # PORTME fill in a description of your system's linker (not GNU ld)
6006
+    case $host_os in
6007
+    aix3*)
6008
+      _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
6009
+      _LT_AC_TAGVAR(always_export_symbols, $1)=yes
6010
+      _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$LD -o $output_objdir/$soname $libobjs $deplibs $linker_flags -bE:$export_symbols -T512 -H512 -bM:SRE~$AR $AR_FLAGS $lib $output_objdir/$soname'
6011
+      # Note: this linker hardcodes the directories in LIBPATH if there
6012
+      # are no directories specified by -L.
6013
+      _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
6014
+      if test "$GCC" = yes && test -z "$lt_prog_compiler_static"; then
6015
+	# Neither direct hardcoding nor static linking is supported with a
6016
+	# broken collect2.
6017
+	_LT_AC_TAGVAR(hardcode_direct, $1)=unsupported
6018
+      fi
6019
+      ;;
6020
+
6021
+    aix[[4-9]]*)
6022
+      if test "$host_cpu" = ia64; then
6023
+	# On IA64, the linker does run time linking by default, so we don't
6024
+	# have to do anything special.
6025
+	aix_use_runtimelinking=no
6026
+	exp_sym_flag='-Bexport'
6027
+	no_entry_flag=""
6028
+      else
6029
+	# If we're using GNU nm, then we don't want the "-C" option.
6030
+	# -C means demangle to AIX nm, but means don't demangle with GNU nm
6031
+	if $NM -V 2>&1 | grep 'GNU' > /dev/null; then
6032
+	  _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -Bpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols'
6033
+	else
6034
+	  _LT_AC_TAGVAR(export_symbols_cmds, $1)='$NM -BCpg $libobjs $convenience | awk '\''{ if (((\[$]2 == "T") || (\[$]2 == "D") || (\[$]2 == "B")) && ([substr](\[$]3,1,1) != ".")) { print \[$]3 } }'\'' | sort -u > $export_symbols'
6035
+	fi
6036
+	aix_use_runtimelinking=no
6037
+
6038
+	# Test if we are trying to use run time linking or normal
6039
+	# AIX style linking. If -brtl is somewhere in LDFLAGS, we
6040
+	# need to do runtime linking.
6041
+	case $host_os in aix4.[[23]]|aix4.[[23]].*|aix[[5-9]]*)
6042
+	  for ld_flag in $LDFLAGS; do
6043
+  	  if (test $ld_flag = "-brtl" || test $ld_flag = "-Wl,-brtl"); then
6044
+  	    aix_use_runtimelinking=yes
6045
+  	    break
6046
+  	  fi
6047
+	  done
6048
+	  ;;
6049
+	esac
6050
+
6051
+	exp_sym_flag='-bexport'
6052
+	no_entry_flag='-bnoentry'
6053
+      fi
6054
+
6055
+      # When large executables or shared objects are built, AIX ld can
6056
+      # have problems creating the table of contents.  If linking a library
6057
+      # or program results in "error TOC overflow" add -mminimal-toc to
6058
+      # CXXFLAGS/CFLAGS for g++/gcc.  In the cases where that is not
6059
+      # enough to fix the problem, add -Wl,-bbigtoc to LDFLAGS.
6060
+
6061
+      _LT_AC_TAGVAR(archive_cmds, $1)=''
6062
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
6063
+      _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=':'
6064
+      _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
6065
+
6066
+      if test "$GCC" = yes; then
6067
+	case $host_os in aix4.[[012]]|aix4.[[012]].*)
6068
+	# We only want to do this on AIX 4.2 and lower, the check
6069
+	# below for broken collect2 doesn't work under 4.3+
6070
+	  collect2name=`${CC} -print-prog-name=collect2`
6071
+	  if test -f "$collect2name" && \
6072
+  	   strings "$collect2name" | grep resolve_lib_name >/dev/null
6073
+	  then
6074
+  	  # We have reworked collect2
6075
+  	  :
6076
+	  else
6077
+  	  # We have old collect2
6078
+  	  _LT_AC_TAGVAR(hardcode_direct, $1)=unsupported
6079
+  	  # It fails to find uninstalled libraries when the uninstalled
6080
+  	  # path is not listed in the libpath.  Setting hardcode_minus_L
6081
+  	  # to unsupported forces relinking
6082
+  	  _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
6083
+  	  _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
6084
+  	  _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=
6085
+	  fi
6086
+	  ;;
6087
+	esac
6088
+	shared_flag='-shared'
6089
+	if test "$aix_use_runtimelinking" = yes; then
6090
+	  shared_flag="$shared_flag "'${wl}-G'
6091
+	fi
6092
+      else
6093
+	# not using gcc
6094
+	if test "$host_cpu" = ia64; then
6095
+  	# VisualAge C++, Version 5.5 for AIX 5L for IA-64, Beta 3 Release
6096
+  	# chokes on -Wl,-G. The following line is correct:
6097
+	  shared_flag='-G'
6098
+	else
6099
+	  if test "$aix_use_runtimelinking" = yes; then
6100
+	    shared_flag='${wl}-G'
6101
+	  else
6102
+	    shared_flag='${wl}-bM:SRE'
6103
+	  fi
6104
+	fi
6105
+      fi
6106
+
6107
+      # It seems that -bexpall does not export symbols beginning with
6108
+      # underscore (_), so it is better to generate a list of symbols to export.
6109
+      _LT_AC_TAGVAR(always_export_symbols, $1)=yes
6110
+      if test "$aix_use_runtimelinking" = yes; then
6111
+	# Warning - without using the other runtime loading flags (-brtl),
6112
+	# -berok will link without error, but may produce a broken library.
6113
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)='-berok'
6114
+       # Determine the default libpath from the value encoded in an empty executable.
6115
+       _LT_AC_SYS_LIBPATH_AIX
6116
+       _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
6117
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags `if test "x${allow_undefined_flag}" != "x"; then echo "${wl}${allow_undefined_flag}"; else :; fi` '"\${wl}$exp_sym_flag:\$export_symbols $shared_flag"
6118
+       else
6119
+	if test "$host_cpu" = ia64; then
6120
+	  _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-R $libdir:/usr/lib:/lib'
6121
+	  _LT_AC_TAGVAR(allow_undefined_flag, $1)="-z nodefs"
6122
+	  _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs '"\${wl}$no_entry_flag"' $compiler_flags ${wl}${allow_undefined_flag} '"\${wl}$exp_sym_flag:\$export_symbols"
6123
+	else
6124
+	 # Determine the default libpath from the value encoded in an empty executable.
6125
+	 _LT_AC_SYS_LIBPATH_AIX
6126
+	 _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-blibpath:$libdir:'"$aix_libpath"
6127
+	  # Warning - without using the other run time loading flags,
6128
+	  # -berok will link without error, but may produce a broken library.
6129
+	  _LT_AC_TAGVAR(no_undefined_flag, $1)=' ${wl}-bernotok'
6130
+	  _LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-berok'
6131
+	  # Exported symbols can be pulled into shared objects from archives
6132
+	  _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='$convenience'
6133
+	  _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes
6134
+	  # This is similar to how AIX traditionally builds its shared libraries.
6135
+	  _LT_AC_TAGVAR(archive_expsym_cmds, $1)="\$CC $shared_flag"' -o $output_objdir/$soname $libobjs $deplibs ${wl}-bnoentry $compiler_flags ${wl}-bE:$export_symbols${allow_undefined_flag}~$AR $AR_FLAGS $output_objdir/$libname$release.a $output_objdir/$soname'
6136
+	fi
6137
+      fi
6138
+      ;;
6139
+
6140
+    amigaos*)
6141
+      _LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/a2ixlibrary.data~$echo "#define NAME $libname" > $output_objdir/a2ixlibrary.data~$echo "#define LIBRARY_ID 1" >> $output_objdir/a2ixlibrary.data~$echo "#define VERSION $major" >> $output_objdir/a2ixlibrary.data~$echo "#define REVISION $revision" >> $output_objdir/a2ixlibrary.data~$AR $AR_FLAGS $lib $libobjs~$RANLIB $lib~(cd $output_objdir && a2ixlibrary -32)'
6142
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
6143
+      _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
6144
+      # see comment about different semantics on the GNU ld section
6145
+      _LT_AC_TAGVAR(ld_shlibs, $1)=no
6146
+      ;;
6147
+
6148
+    bsdi[[45]]*)
6149
+      _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)=-rdynamic
6150
+      ;;
6151
+
6152
+    cygwin* | mingw* | pw32*)
6153
+      # When not using gcc, we currently assume that we are using
6154
+      # Microsoft Visual C++.
6155
+      # hardcode_libdir_flag_spec is actually meaningless, as there is
6156
+      # no search path for DLLs.
6157
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)=' '
6158
+      _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
6159
+      # Tell ltmain to make .lib files, not .a files.
6160
+      libext=lib
6161
+      # Tell ltmain to make .dll files, not .so files.
6162
+      shrext_cmds=".dll"
6163
+      # FIXME: Setting linknames here is a bad hack.
6164
+      _LT_AC_TAGVAR(archive_cmds, $1)='$CC -o $lib $libobjs $compiler_flags `echo "$deplibs" | $SED -e '\''s/ -lc$//'\''` -link -dll~linknames='
6165
+      # The linker will automatically build a .lib file if we build a DLL.
6166
+      _LT_AC_TAGVAR(old_archive_From_new_cmds, $1)='true'
6167
+      # FIXME: Should let the user specify the lib program.
6168
+      _LT_AC_TAGVAR(old_archive_cmds, $1)='lib -OUT:$oldlib$oldobjs$old_deplibs'
6169
+      _LT_AC_TAGVAR(fix_srcfile_path, $1)='`cygpath -w "$srcfile"`'
6170
+      _LT_AC_TAGVAR(enable_shared_with_static_runtimes, $1)=yes
6171
+      ;;
6172
+
6173
+    darwin* | rhapsody*)
6174
+      case $host_os in
6175
+        rhapsody* | darwin1.[[012]])
6176
+         _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-undefined ${wl}suppress'
6177
+         ;;
6178
+       *) # Darwin 1.3 on
6179
+         if test -z ${MACOSX_DEPLOYMENT_TARGET} ; then
6180
+           _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-flat_namespace ${wl}-undefined ${wl}suppress'
6181
+         else
6182
+           case ${MACOSX_DEPLOYMENT_TARGET} in
6183
+             10.[[012]])
6184
+               _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-flat_namespace ${wl}-undefined ${wl}suppress'
6185
+               ;;
6186
+             10.*)
6187
+               _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-undefined ${wl}dynamic_lookup'
6188
+               ;;
6189
+           esac
6190
+         fi
6191
+         ;;
6192
+      esac
6193
+      _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
6194
+      _LT_AC_TAGVAR(hardcode_direct, $1)=no
6195
+      _LT_AC_TAGVAR(hardcode_automatic, $1)=yes
6196
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=unsupported
6197
+      _LT_AC_TAGVAR(whole_archive_flag_spec, $1)=''
6198
+      _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
6199
+    if test "$GCC" = yes ; then
6200
+    	output_verbose_link_cmd='echo'
6201
+        _LT_AC_TAGVAR(archive_cmds, $1)="\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring $_lt_dar_single_mod${_lt_dsymutil}"
6202
+        _LT_AC_TAGVAR(module_cmds, $1)="\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dsymutil}"
6203
+        _LT_AC_TAGVAR(archive_expsym_cmds, $1)="sed 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC -dynamiclib \$allow_undefined_flag -o \$lib \$libobjs \$deplibs \$compiler_flags -install_name \$rpath/\$soname \$verstring ${_lt_dar_single_mod}${_lt_dar_export_syms}${_lt_dsymutil}"
6204
+        _LT_AC_TAGVAR(module_expsym_cmds, $1)="sed -e 's,^,_,' < \$export_symbols > \$output_objdir/\${libname}-symbols.expsym~\$CC \$allow_undefined_flag -o \$lib -bundle \$libobjs \$deplibs \$compiler_flags${_lt_dar_export_syms}${_lt_dsymutil}"
6205
+    else
6206
+      case $cc_basename in
6207
+        xlc*)
6208
+         output_verbose_link_cmd='echo'
6209
+         _LT_AC_TAGVAR(archive_cmds, $1)='$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}`echo $rpath/$soname` $xlcverstring'
6210
+         _LT_AC_TAGVAR(module_cmds, $1)='$CC $allow_undefined_flag -o $lib -bundle $libobjs $deplibs$compiler_flags'
6211
+          # Don't fix this by using the ld -exported_symbols_list flag, it doesn't exist in older darwin lds
6212
+         _LT_AC_TAGVAR(archive_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC -qmkshrobj $allow_undefined_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-install_name ${wl}$rpath/$soname $xlcverstring~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
6213
+          _LT_AC_TAGVAR(module_expsym_cmds, $1)='sed -e "s,#.*,," -e "s,^[    ]*,," -e "s,^\(..*\),_&," < $export_symbols > $output_objdir/${libname}-symbols.expsym~$CC $allow_undefined_flag  -o $lib -bundle $libobjs $deplibs$compiler_flags~nmedit -s $output_objdir/${libname}-symbols.expsym ${lib}'
6214
+          ;;
6215
+       *)
6216
+         _LT_AC_TAGVAR(ld_shlibs, $1)=no
6217
+          ;;
6218
+      esac
6219
+    fi
6220
+      ;;
6221
+
6222
+    dgux*)
6223
+      _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
6224
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
6225
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
6226
+      ;;
6227
+
6228
+    freebsd1*)
6229
+      _LT_AC_TAGVAR(ld_shlibs, $1)=no
6230
+      ;;
6231
+
6232
+    # FreeBSD 2.2.[012] allows us to include c++rt0.o to get C++ constructor
6233
+    # support.  Future versions do this automatically, but an explicit c++rt0.o
6234
+    # does not break anything, and helps significantly (at the cost of a little
6235
+    # extra space).
6236
+    freebsd2.2*)
6237
+      _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags /usr/lib/c++rt0.o'
6238
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
6239
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
6240
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
6241
+      ;;
6242
+
6243
+    # Unfortunately, older versions of FreeBSD 2 do not have this feature.
6244
+    freebsd2*)
6245
+      _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
6246
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
6247
+      _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
6248
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
6249
+      ;;
6250
+
6251
+    # FreeBSD 3 and greater uses gcc -shared to do shared libraries.
6252
+    freebsd* | dragonfly*)
6253
+      _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -o $lib $libobjs $deplibs $compiler_flags'
6254
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
6255
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
6256
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
6257
+      ;;
6258
+
6259
+    hpux9*)
6260
+      if test "$GCC" = yes; then
6261
+	_LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$CC -shared -fPIC ${wl}+b ${wl}$install_libdir -o $output_objdir/$soname $libobjs $deplibs $compiler_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
6262
+      else
6263
+	_LT_AC_TAGVAR(archive_cmds, $1)='$rm $output_objdir/$soname~$LD -b +b $install_libdir -o $output_objdir/$soname $libobjs $deplibs $linker_flags~test $output_objdir/$soname = $lib || mv $output_objdir/$soname $lib'
6264
+      fi
6265
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
6266
+      _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
6267
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
6268
+
6269
+      # hardcode_minus_L: Not really in the search PATH,
6270
+      # but as the default location of the library.
6271
+      _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
6272
+      _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
6273
+      ;;
6274
+
6275
+    hpux10*)
6276
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
6277
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
6278
+      else
6279
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -b +h $soname +b $install_libdir -o $lib $libobjs $deplibs $linker_flags'
6280
+      fi
6281
+      if test "$with_gnu_ld" = no; then
6282
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
6283
+	_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
6284
+
6285
+	_LT_AC_TAGVAR(hardcode_direct, $1)=yes
6286
+	_LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
6287
+
6288
+	# hardcode_minus_L: Not really in the search PATH,
6289
+	# but as the default location of the library.
6290
+	_LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
6291
+      fi
6292
+      ;;
6293
+
6294
+    hpux11*)
6295
+      if test "$GCC" = yes -a "$with_gnu_ld" = no; then
6296
+	case $host_cpu in
6297
+	hppa*64*)
6298
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
6299
+	  ;;
6300
+	ia64*)
6301
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
6302
+	  ;;
6303
+	*)
6304
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared -fPIC ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
6305
+	  ;;
6306
+	esac
6307
+      else
6308
+	case $host_cpu in
6309
+	hppa*64*)
6310
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
6311
+	  ;;
6312
+	ia64*)
6313
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+nodefaultrpath -o $lib $libobjs $deplibs $compiler_flags'
6314
+	  ;;
6315
+	*)
6316
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -b ${wl}+h ${wl}$soname ${wl}+b ${wl}$install_libdir -o $lib $libobjs $deplibs $compiler_flags'
6317
+	  ;;
6318
+	esac
6319
+      fi
6320
+      if test "$with_gnu_ld" = no; then
6321
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}+b ${wl}$libdir'
6322
+	_LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
6323
+
6324
+	case $host_cpu in
6325
+	hppa*64*|ia64*)
6326
+	  _LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='+b $libdir'
6327
+	  _LT_AC_TAGVAR(hardcode_direct, $1)=no
6328
+	  _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
6329
+	  ;;
6330
+	*)
6331
+	  _LT_AC_TAGVAR(hardcode_direct, $1)=yes
6332
+	  _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
6333
+
6334
+	  # hardcode_minus_L: Not really in the search PATH,
6335
+	  # but as the default location of the library.
6336
+	  _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
6337
+	  ;;
6338
+	esac
6339
+      fi
6340
+      ;;
6341
+
6342
+    irix5* | irix6* | nonstopux*)
6343
+      if test "$GCC" = yes; then
6344
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
6345
+      else
6346
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
6347
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec_ld, $1)='-rpath $libdir'
6348
+      fi
6349
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
6350
+      _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
6351
+      _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
6352
+      ;;
6353
+
6354
+    netbsd* | netbsdelf*-gnu)
6355
+      if echo __ELF__ | $CC -E - | grep __ELF__ >/dev/null; then
6356
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'  # a.out
6357
+      else
6358
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared -o $lib $libobjs $deplibs $linker_flags'      # ELF
6359
+      fi
6360
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
6361
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
6362
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
6363
+      ;;
6364
+
6365
+    newsos6)
6366
+      _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
6367
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
6368
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
6369
+      _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
6370
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
6371
+      ;;
6372
+
6373
+    openbsd*)
6374
+      if test -f /usr/libexec/ld.so; then
6375
+	_LT_AC_TAGVAR(hardcode_direct, $1)=yes
6376
+	_LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
6377
+	if test -z "`echo __ELF__ | $CC -E - | grep __ELF__`" || test "$host_os-$host_cpu" = "openbsd2.8-powerpc"; then
6378
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
6379
+	  _LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags ${wl}-retain-symbols-file,$export_symbols'
6380
+	  _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
6381
+	  _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-E'
6382
+	else
6383
+	  case $host_os in
6384
+	   openbsd[[01]].* | openbsd2.[[0-7]] | openbsd2.[[0-7]].*)
6385
+	     _LT_AC_TAGVAR(archive_cmds, $1)='$LD -Bshareable -o $lib $libobjs $deplibs $linker_flags'
6386
+	     _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
6387
+	     ;;
6388
+	   *)
6389
+	     _LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared $pic_flag -o $lib $libobjs $deplibs $compiler_flags'
6390
+	     _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath,$libdir'
6391
+	     ;;
6392
+	  esac
6393
+        fi
6394
+      else
6395
+	_LT_AC_TAGVAR(ld_shlibs, $1)=no
6396
+      fi
6397
+      ;;
6398
+
6399
+    os2*)
6400
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
6401
+      _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
6402
+      _LT_AC_TAGVAR(allow_undefined_flag, $1)=unsupported
6403
+      _LT_AC_TAGVAR(archive_cmds, $1)='$echo "LIBRARY $libname INITINSTANCE" > $output_objdir/$libname.def~$echo "DESCRIPTION \"$libname\"" >> $output_objdir/$libname.def~$echo DATA >> $output_objdir/$libname.def~$echo " SINGLE NONSHARED" >> $output_objdir/$libname.def~$echo EXPORTS >> $output_objdir/$libname.def~emxexp $libobjs >> $output_objdir/$libname.def~$CC -Zdll -Zcrtdll -o $lib $libobjs $deplibs $compiler_flags $output_objdir/$libname.def'
6404
+      _LT_AC_TAGVAR(old_archive_From_new_cmds, $1)='emximp -o $output_objdir/$libname.a $output_objdir/$libname.def'
6405
+      ;;
6406
+
6407
+    osf3*)
6408
+      if test "$GCC" = yes; then
6409
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
6410
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
6411
+      else
6412
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
6413
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
6414
+      fi
6415
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
6416
+      _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
6417
+      ;;
6418
+
6419
+    osf4* | osf5*)	# as osf3* with the addition of -msym flag
6420
+      if test "$GCC" = yes; then
6421
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)=' ${wl}-expect_unresolved ${wl}\*'
6422
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared${allow_undefined_flag} $libobjs $deplibs $compiler_flags ${wl}-msym ${wl}-soname ${wl}$soname `test -n "$verstring" && echo ${wl}-set_version ${wl}$verstring` ${wl}-update_registry ${wl}${output_objdir}/so_locations -o $lib'
6423
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='${wl}-rpath ${wl}$libdir'
6424
+      else
6425
+	_LT_AC_TAGVAR(allow_undefined_flag, $1)=' -expect_unresolved \*'
6426
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -shared${allow_undefined_flag} $libobjs $deplibs $linker_flags -msym -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib'
6427
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='for i in `cat $export_symbols`; do printf "%s %s\\n" -exported_symbol "\$i" >> $lib.exp; done; echo "-hidden">> $lib.exp~
6428
+	$LD -shared${allow_undefined_flag} -input $lib.exp $linker_flags $libobjs $deplibs -soname $soname `test -n "$verstring" && echo -set_version $verstring` -update_registry ${output_objdir}/so_locations -o $lib~$rm $lib.exp'
6429
+
6430
+	# Both c and cxx compiler support -rpath directly
6431
+	_LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-rpath $libdir'
6432
+      fi
6433
+      _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=:
6434
+      ;;
6435
+
6436
+    solaris*)
6437
+      _LT_AC_TAGVAR(no_undefined_flag, $1)=' -z text'
6438
+      if test "$GCC" = yes; then
6439
+	wlarc='${wl}'
6440
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags'
6441
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
6442
+	  $CC -shared ${wl}-M ${wl}$lib.exp ${wl}-h ${wl}$soname -o $lib $libobjs $deplibs $compiler_flags~$rm $lib.exp'
6443
+      else
6444
+	wlarc=''
6445
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -G${allow_undefined_flag} -h $soname -o $lib $libobjs $deplibs $linker_flags'
6446
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$echo "{ global:" > $lib.exp~cat $export_symbols | $SED -e "s/\(.*\)/\1;/" >> $lib.exp~$echo "local: *; };" >> $lib.exp~
6447
+  	$LD -G${allow_undefined_flag} -M $lib.exp -h $soname -o $lib $libobjs $deplibs $linker_flags~$rm $lib.exp'
6448
+      fi
6449
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-R$libdir'
6450
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
6451
+      case $host_os in
6452
+      solaris2.[[0-5]] | solaris2.[[0-5]].*) ;;
6453
+      *)
6454
+	# The compiler driver will combine and reorder linker options,
6455
+	# but understands `-z linker_flag'.  GCC discards it without `$wl',
6456
+	# but is careful enough not to reorder.
6457
+ 	# Supported since Solaris 2.6 (maybe 2.5.1?)
6458
+	if test "$GCC" = yes; then
6459
+	  _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='${wl}-z ${wl}allextract$convenience ${wl}-z ${wl}defaultextract'
6460
+	else
6461
+	  _LT_AC_TAGVAR(whole_archive_flag_spec, $1)='-z allextract$convenience -z defaultextract'
6462
+	fi
6463
+	;;
6464
+      esac
6465
+      _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
6466
+      ;;
6467
+
6468
+    sunos4*)
6469
+      if test "x$host_vendor" = xsequent; then
6470
+	# Use $CC to link under sequent, because it throws in some extra .o
6471
+	# files that make .init and .fini sections work.
6472
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h $soname -o $lib $libobjs $deplibs $compiler_flags'
6473
+      else
6474
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -assert pure-text -Bstatic -o $lib $libobjs $deplibs $linker_flags'
6475
+      fi
6476
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
6477
+      _LT_AC_TAGVAR(hardcode_direct, $1)=yes
6478
+      _LT_AC_TAGVAR(hardcode_minus_L, $1)=yes
6479
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
6480
+      ;;
6481
+
6482
+    sysv4)
6483
+      case $host_vendor in
6484
+	sni)
6485
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
6486
+	  _LT_AC_TAGVAR(hardcode_direct, $1)=yes # is this really true???
6487
+	;;
6488
+	siemens)
6489
+	  ## LD is ld it makes a PLAMLIB
6490
+	  ## CC just makes a GrossModule.
6491
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -o $lib $libobjs $deplibs $linker_flags'
6492
+	  _LT_AC_TAGVAR(reload_cmds, $1)='$CC -r -o $output$reload_objs'
6493
+	  _LT_AC_TAGVAR(hardcode_direct, $1)=no
6494
+        ;;
6495
+	motorola)
6496
+	  _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
6497
+	  _LT_AC_TAGVAR(hardcode_direct, $1)=no #Motorola manual says yes, but my tests say they lie
6498
+	;;
6499
+      esac
6500
+      runpath_var='LD_RUN_PATH'
6501
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
6502
+      ;;
6503
+
6504
+    sysv4.3*)
6505
+      _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
6506
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
6507
+      _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='-Bexport'
6508
+      ;;
6509
+
6510
+    sysv4*MP*)
6511
+      if test -d /usr/nec; then
6512
+	_LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
6513
+	_LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
6514
+	runpath_var=LD_RUN_PATH
6515
+	hardcode_runpath_var=yes
6516
+	_LT_AC_TAGVAR(ld_shlibs, $1)=yes
6517
+      fi
6518
+      ;;
6519
+
6520
+    sysv4*uw2* | sysv5OpenUNIX* | sysv5UnixWare7.[[01]].[[10]]* | unixware7* | sco3.2v5.0.[[024]]*)
6521
+      _LT_AC_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
6522
+      _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
6523
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
6524
+      runpath_var='LD_RUN_PATH'
6525
+
6526
+      if test "$GCC" = yes; then
6527
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
6528
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
6529
+      else
6530
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
6531
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,$soname -o $lib $libobjs $deplibs $compiler_flags'
6532
+      fi
6533
+      ;;
6534
+
6535
+    sysv5* | sco3.2v5* | sco5v6*)
6536
+      # Note: We can NOT use -z defs as we might desire, because we do not
6537
+      # link with -lc, and that would cause any symbols used from libc to
6538
+      # always be unresolved, which means just about no library would
6539
+      # ever link correctly.  If we're not using GNU ld we use -z text
6540
+      # though, which does catch some bad symbols but isn't as heavy-handed
6541
+      # as -z defs.
6542
+      _LT_AC_TAGVAR(no_undefined_flag, $1)='${wl}-z,text'
6543
+      _LT_AC_TAGVAR(allow_undefined_flag, $1)='${wl}-z,nodefs'
6544
+      _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
6545
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
6546
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='`test -z "$SCOABSPATH" && echo ${wl}-R,$libdir`'
6547
+      _LT_AC_TAGVAR(hardcode_libdir_separator, $1)=':'
6548
+      _LT_AC_TAGVAR(link_all_deplibs, $1)=yes
6549
+      _LT_AC_TAGVAR(export_dynamic_flag_spec, $1)='${wl}-Bexport'
6550
+      runpath_var='LD_RUN_PATH'
6551
+
6552
+      if test "$GCC" = yes; then
6553
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -shared ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
6554
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -shared ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
6555
+      else
6556
+	_LT_AC_TAGVAR(archive_cmds, $1)='$CC -G ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
6557
+	_LT_AC_TAGVAR(archive_expsym_cmds, $1)='$CC -G ${wl}-Bexport:$export_symbols ${wl}-h,\${SCOABSPATH:+${install_libdir}/}$soname -o $lib $libobjs $deplibs $compiler_flags'
6558
+      fi
6559
+      ;;
6560
+
6561
+    uts4*)
6562
+      _LT_AC_TAGVAR(archive_cmds, $1)='$LD -G -h $soname -o $lib $libobjs $deplibs $linker_flags'
6563
+      _LT_AC_TAGVAR(hardcode_libdir_flag_spec, $1)='-L$libdir'
6564
+      _LT_AC_TAGVAR(hardcode_shlibpath_var, $1)=no
6565
+      ;;
6566
+
6567
+    *)
6568
+      _LT_AC_TAGVAR(ld_shlibs, $1)=no
6569
+      ;;
6570
+    esac
6571
+  fi
6572
+])
6573
+AC_MSG_RESULT([$_LT_AC_TAGVAR(ld_shlibs, $1)])
6574
+test "$_LT_AC_TAGVAR(ld_shlibs, $1)" = no && can_build_shared=no
6575
+
6576
+#
6577
+# Do we need to explicitly link libc?
6578
+#
6579
+case "x$_LT_AC_TAGVAR(archive_cmds_need_lc, $1)" in
6580
+x|xyes)
6581
+  # Assume -lc should be added
6582
+  _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes
6583
+
6584
+  if test "$enable_shared" = yes && test "$GCC" = yes; then
6585
+    case $_LT_AC_TAGVAR(archive_cmds, $1) in
6586
+    *'~'*)
6587
+      # FIXME: we may have to deal with multi-command sequences.
6588
+      ;;
6589
+    '$CC '*)
6590
+      # Test whether the compiler implicitly links with -lc since on some
6591
+      # systems, -lgcc has to come before -lc. If gcc already passes -lc
6592
+      # to ld, don't add -lc before -lgcc.
6593
+      AC_MSG_CHECKING([whether -lc should be explicitly linked in])
6594
+      $rm conftest*
6595
+      echo "$lt_simple_compile_test_code" > conftest.$ac_ext
6596
+
6597
+      if AC_TRY_EVAL(ac_compile) 2>conftest.err; then
6598
+        soname=conftest
6599
+        lib=conftest
6600
+        libobjs=conftest.$ac_objext
6601
+        deplibs=
6602
+        wl=$_LT_AC_TAGVAR(lt_prog_compiler_wl, $1)
6603
+	pic_flag=$_LT_AC_TAGVAR(lt_prog_compiler_pic, $1)
6604
+        compiler_flags=-v
6605
+        linker_flags=-v
6606
+        verstring=
6607
+        output_objdir=.
6608
+        libname=conftest
6609
+        lt_save_allow_undefined_flag=$_LT_AC_TAGVAR(allow_undefined_flag, $1)
6610
+        _LT_AC_TAGVAR(allow_undefined_flag, $1)=
6611
+        if AC_TRY_EVAL(_LT_AC_TAGVAR(archive_cmds, $1) 2\>\&1 \| grep \" -lc \" \>/dev/null 2\>\&1)
6612
+        then
6613
+	  _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=no
6614
+        else
6615
+	  _LT_AC_TAGVAR(archive_cmds_need_lc, $1)=yes
6616
+        fi
6617
+        _LT_AC_TAGVAR(allow_undefined_flag, $1)=$lt_save_allow_undefined_flag
6618
+      else
6619
+        cat conftest.err 1>&5
6620
+      fi
6621
+      $rm conftest*
6622
+      AC_MSG_RESULT([$_LT_AC_TAGVAR(archive_cmds_need_lc, $1)])
6623
+      ;;
6624
+    esac
6625
+  fi
6626
+  ;;
6627
+esac
6628
+])# AC_LIBTOOL_PROG_LD_SHLIBS
6629
+
6630
+
6631
+# _LT_AC_FILE_LTDLL_C
6632
+# -------------------
6633
+# Be careful that the start marker always follows a newline.
6634
+AC_DEFUN([_LT_AC_FILE_LTDLL_C], [
6635
+# /* ltdll.c starts here */
6636
+# #define WIN32_LEAN_AND_MEAN
6637
+# #include <windows.h>
6638
+# #undef WIN32_LEAN_AND_MEAN
6639
+# #include <stdio.h>
6640
+#
6641
+# #ifndef __CYGWIN__
6642
+# #  ifdef __CYGWIN32__
6643
+# #    define __CYGWIN__ __CYGWIN32__
6644
+# #  endif
6645
+# #endif
6646
+#
6647
+# #ifdef __cplusplus
6648
+# extern "C" {
6649
+# #endif
6650
+# BOOL APIENTRY DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved);
6651
+# #ifdef __cplusplus
6652
+# }
6653
+# #endif
6654
+#
6655
+# #ifdef __CYGWIN__
6656
+# #include <cygwin/cygwin_dll.h>
6657
+# DECLARE_CYGWIN_DLL( DllMain );
6658
+# #endif
6659
+# HINSTANCE __hDllInstance_base;
6660
+#
6661
+# BOOL APIENTRY
6662
+# DllMain (HINSTANCE hInst, DWORD reason, LPVOID reserved)
6663
+# {
6664
+#   __hDllInstance_base = hInst;
6665
+#   return TRUE;
6666
+# }
6667
+# /* ltdll.c ends here */
6668
+])# _LT_AC_FILE_LTDLL_C
6669
+
6670
+
6671
+# _LT_AC_TAGVAR(VARNAME, [TAGNAME])
6672
+# ---------------------------------
6673
+AC_DEFUN([_LT_AC_TAGVAR], [ifelse([$2], [], [$1], [$1_$2])])
6674
+
6675
+
6676
+# old names
6677
+AC_DEFUN([AM_PROG_LIBTOOL],   [AC_PROG_LIBTOOL])
6678
+AC_DEFUN([AM_ENABLE_SHARED],  [AC_ENABLE_SHARED($@)])
6679
+AC_DEFUN([AM_ENABLE_STATIC],  [AC_ENABLE_STATIC($@)])
6680
+AC_DEFUN([AM_DISABLE_SHARED], [AC_DISABLE_SHARED($@)])
6681
+AC_DEFUN([AM_DISABLE_STATIC], [AC_DISABLE_STATIC($@)])
6682
+AC_DEFUN([AM_PROG_LD],        [AC_PROG_LD])
6683
+AC_DEFUN([AM_PROG_NM],        [AC_PROG_NM])
6684
+
6685
+# This is just to silence aclocal about the macro not being used
6686
+ifelse([AC_DISABLE_FAST_INSTALL])
6687
+
6688
+AC_DEFUN([LT_AC_PROG_GCJ],
6689
+[AC_CHECK_TOOL(GCJ, gcj, no)
6690
+  test "x${GCJFLAGS+set}" = xset || GCJFLAGS="-g -O2"
6691
+  AC_SUBST(GCJFLAGS)
6692
+])
6693
+
6694
+AC_DEFUN([LT_AC_PROG_RC],
6695
+[AC_CHECK_TOOL(RC, windres, no)
6696
+])
6697
+
6698
+
6699
+# Cheap backport of AS_EXECUTABLE_P and required macros
6700
+# from Autoconf 2.59; we should not use $as_executable_p directly.
6701
+
6702
+# _AS_TEST_PREPARE
6703
+# ----------------
6704
+m4_ifndef([_AS_TEST_PREPARE],
6705
+[m4_defun([_AS_TEST_PREPARE],
6706
+[if test -x / >/dev/null 2>&1; then
6707
+  as_executable_p='test -x'
6708
+else
6709
+  as_executable_p='test -f'
6710
+fi
6711
+])])# _AS_TEST_PREPARE
6712
+
6713
+# AS_EXECUTABLE_P
6714
+# ---------------
6715
+# Check whether a file is executable.
6716
+m4_ifndef([AS_EXECUTABLE_P],
6717
+[m4_defun([AS_EXECUTABLE_P],
6718
+[AS_REQUIRE([_AS_TEST_PREPARE])dnl
6719
+$as_executable_p $1[]dnl
6720
+])])# AS_EXECUTABLE_P
6721
+
6722
+# NOTE: This macro has been submitted for inclusion into   #
6723
+#  GNU Autoconf as AC_PROG_SED.  When it is available in   #
6724
+#  a released version of Autoconf we should remove this    #
6725
+#  macro and use it instead.                               #
6726
+# LT_AC_PROG_SED
6727
+# --------------
6728
+# Check for a fully-functional sed program, that truncates
6729
+# as few characters as possible.  Prefer GNU sed if found.
6730
+AC_DEFUN([LT_AC_PROG_SED],
6731
+[AC_MSG_CHECKING([for a sed that does not truncate output])
6732
+AC_CACHE_VAL(lt_cv_path_SED,
6733
+[# Loop through the user's path and test for sed and gsed.
6734
+# Then use that list of sed's as ones to test for truncation.
6735
+as_save_IFS=$IFS; IFS=$PATH_SEPARATOR
6736
+for as_dir in $PATH
6737
+do
6738
+  IFS=$as_save_IFS
6739
+  test -z "$as_dir" && as_dir=.
6740
+  for lt_ac_prog in sed gsed; do
6741
+    for ac_exec_ext in '' $ac_executable_extensions; do
6742
+      if AS_EXECUTABLE_P(["$as_dir/$lt_ac_prog$ac_exec_ext"]); then
6743
+        lt_ac_sed_list="$lt_ac_sed_list $as_dir/$lt_ac_prog$ac_exec_ext"
6744
+      fi
6745
+    done
6746
+  done
6747
+done
6748
+IFS=$as_save_IFS
6749
+lt_ac_max=0
6750
+lt_ac_count=0
6751
+# Add /usr/xpg4/bin/sed as it is typically found on Solaris
6752
+# along with /bin/sed that truncates output.
6753
+for lt_ac_sed in $lt_ac_sed_list /usr/xpg4/bin/sed; do
6754
+  test ! -f $lt_ac_sed && continue
6755
+  cat /dev/null > conftest.in
6756
+  lt_ac_count=0
6757
+  echo $ECHO_N "0123456789$ECHO_C" >conftest.in
6758
+  # Check for GNU sed and select it if it is found.
6759
+  if "$lt_ac_sed" --version 2>&1 < /dev/null | grep 'GNU' > /dev/null; then
6760
+    lt_cv_path_SED=$lt_ac_sed
6761
+    break
6762
+  fi
6763
+  while true; do
6764
+    cat conftest.in conftest.in >conftest.tmp
6765
+    mv conftest.tmp conftest.in
6766
+    cp conftest.in conftest.nl
6767
+    echo >>conftest.nl
6768
+    $lt_ac_sed -e 's/a$//' < conftest.nl >conftest.out || break
6769
+    cmp -s conftest.out conftest.nl || break
6770
+    # 10000 chars as input seems more than enough
6771
+    test $lt_ac_count -gt 10 && break
6772
+    lt_ac_count=`expr $lt_ac_count + 1`
6773
+    if test $lt_ac_count -gt $lt_ac_max; then
6774
+      lt_ac_max=$lt_ac_count
6775
+      lt_cv_path_SED=$lt_ac_sed
6776
+    fi
6777
+  done
6778
+done
6779
+])
6780
+SED=$lt_cv_path_SED
6781
+AC_SUBST([SED])
6782
+AC_MSG_RESULT([$SED])
6783
+])
6784
+
133 6785
 # Copyright (C) 2002, 2003, 2005, 2006, 2007  Free Software Foundation, Inc.
134 6786
 #
135 6787
 # This file is free software; the Free Software Foundation
... ...
@@ -220,9 +220,6 @@
220 220
 /* Define if libdlloader will be built on this platform */
221 221
 #undef HAVE_LIBDLLOADER
222 222
 
223
-/* Define if you have the gmp library. */
224
-#undef HAVE_LIBGMP
225
-
226 223
 /* Define to 1 if you have the <libmilter/mfapi.h> header file. */
227 224
 #undef HAVE_LIBMILTER_MFAPI_H
228 225
 
... ...
@@ -149,7 +149,6 @@ GENHTML = @GENHTML@
149 149
 GETENT = @GETENT@
150 150
 GPERF = @GPERF@
151 151
 GREP = @GREP@
152
-HAVE_LIBGMP = @HAVE_LIBGMP@
153 152
 INCLTDL = @INCLTDL@
154 153
 INSTALL = @INSTALL@
155 154
 INSTALL_DATA = @INSTALL_DATA@
... ...
@@ -167,8 +166,6 @@ LIBBZ2 = @LIBBZ2@
167 167
 LIBBZ2_PREFIX = @LIBBZ2_PREFIX@
168 168
 LIBCLAMAV_LIBS = @LIBCLAMAV_LIBS@
169 169
 LIBCLAMAV_VERSION = @LIBCLAMAV_VERSION@
170
-LIBGMP = @LIBGMP@
171
-LIBGMP_PREFIX = @LIBGMP_PREFIX@
172 170
 LIBLTDL = @LIBLTDL@
173 171
 LIBOBJS = @LIBOBJS@
174 172
 LIBS = $(top_builddir)/libclamav/libclamav.la @CLAMAV_MILTER_LIBS@ @THREAD_LIBS@
... ...
@@ -179,7 +176,6 @@ LTDLDEPS = @LTDLDEPS@
179 179
 LTDLINCL = @LTDLINCL@
180 180
 LTDLOPEN = @LTDLOPEN@
181 181
 LTLIBBZ2 = @LTLIBBZ2@
182
-LTLIBGMP = @LTLIBGMP@
183 182
 LTLIBOBJS = @LTLIBOBJS@
184 183
 LT_CONFIG_H = @LT_CONFIG_H@
185 184
 LT_DLLOADERS = @LT_DLLOADERS@
... ...
@@ -130,7 +130,6 @@ GENHTML = @GENHTML@
130 130
 GETENT = @GETENT@
131 131
 GPERF = @GPERF@
132 132
 GREP = @GREP@
133
-HAVE_LIBGMP = @HAVE_LIBGMP@
134 133
 INCLTDL = @INCLTDL@
135 134
 INSTALL = @INSTALL@
136 135
 INSTALL_DATA = @INSTALL_DATA@
... ...
@@ -148,8 +147,6 @@ LIBBZ2 = @LIBBZ2@
148 148
 LIBBZ2_PREFIX = @LIBBZ2_PREFIX@
149 149
 LIBCLAMAV_LIBS = @LIBCLAMAV_LIBS@
150 150
 LIBCLAMAV_VERSION = @LIBCLAMAV_VERSION@
151
-LIBGMP = @LIBGMP@
152
-LIBGMP_PREFIX = @LIBGMP_PREFIX@
153 151
 LIBLTDL = @LIBLTDL@
154 152
 LIBOBJS = @LIBOBJS@
155 153
 LIBS = $(top_builddir)/libclamav/libclamav_internal_utils.la
... ...
@@ -160,7 +157,6 @@ LTDLDEPS = @LTDLDEPS@
160 160
 LTDLINCL = @LTDLINCL@
161 161
 LTDLOPEN = @LTDLOPEN@
162 162
 LTLIBBZ2 = @LTLIBBZ2@
163
-LTLIBGMP = @LTLIBGMP@
164 163
 LTLIBOBJS = @LTLIBOBJS@
165 164
 LT_CONFIG_H = @LT_CONFIG_H@
166 165
 LT_DLLOADERS = @LT_DLLOADERS@
... ...
@@ -149,7 +149,6 @@ GENHTML = @GENHTML@
149 149
 GETENT = @GETENT@
150 150
 GPERF = @GPERF@
151 151
 GREP = @GREP@
152
-HAVE_LIBGMP = @HAVE_LIBGMP@
153 152
 INCLTDL = @INCLTDL@
154 153
 INSTALL = @INSTALL@
155 154
 INSTALL_DATA = @INSTALL_DATA@
... ...
@@ -167,8 +166,6 @@ LIBBZ2 = @LIBBZ2@
167 167
 LIBBZ2_PREFIX = @LIBBZ2_PREFIX@
168 168
 LIBCLAMAV_LIBS = @LIBCLAMAV_LIBS@
169 169
 LIBCLAMAV_VERSION = @LIBCLAMAV_VERSION@
170
-LIBGMP = @LIBGMP@
171
-LIBGMP_PREFIX = @LIBGMP_PREFIX@
172 170
 LIBLTDL = @LIBLTDL@
173 171
 LIBOBJS = @LIBOBJS@
174 172
 LIBS = $(top_builddir)/libclamav/libclamav.la @CLAMD_LIBS@ @THREAD_LIBS@
... ...
@@ -179,7 +176,6 @@ LTDLDEPS = @LTDLDEPS@
179 179
 LTDLINCL = @LTDLINCL@
180 180
 LTDLOPEN = @LTDLOPEN@
181 181
 LTLIBBZ2 = @LTLIBBZ2@
182
-LTLIBGMP = @LTLIBGMP@
183 182
 LTLIBOBJS = @LTLIBOBJS@
184 183
 LT_CONFIG_H = @LT_CONFIG_H@
185 184
 LT_DLLOADERS = @LT_DLLOADERS@
... ...
@@ -258,7 +258,7 @@ int thrmgr_printstats(int f)
258 258
 					seen = s;
259 259
 					seen[seen_cnt - 1] = task->engine;
260 260
 
261
-					if (mp_getstats(task->engine, &used, &total) != -1) {
261
+					if (mpool_getstats(task->engine, &used, &total) != -1) {
262 262
 						pool_used += used;
263 263
 						pool_total += total;
264 264
 						pool_cnt++;
... ...
@@ -140,7 +140,6 @@ GENHTML = @GENHTML@
140 140
 GETENT = @GETENT@
141 141
 GPERF = @GPERF@
142 142
 GREP = @GREP@
143
-HAVE_LIBGMP = @HAVE_LIBGMP@
144 143
 INCLTDL = @INCLTDL@
145 144
 INSTALL = @INSTALL@
146 145
 INSTALL_DATA = @INSTALL_DATA@
... ...
@@ -158,8 +157,6 @@ LIBBZ2 = @LIBBZ2@
158 158
 LIBBZ2_PREFIX = @LIBBZ2_PREFIX@
159 159
 LIBCLAMAV_LIBS = @LIBCLAMAV_LIBS@
160 160
 LIBCLAMAV_VERSION = @LIBCLAMAV_VERSION@
161
-LIBGMP = @LIBGMP@
162
-LIBGMP_PREFIX = @LIBGMP_PREFIX@
163 161
 LIBLTDL = @LIBLTDL@
164 162
 LIBOBJS = @LIBOBJS@
165 163
 LIBS = $(top_builddir)/libclamav/libclamav_internal_utils.la @FRESHCLAM_LIBS@
... ...
@@ -170,7 +167,6 @@ LTDLDEPS = @LTDLDEPS@
170 170
 LTDLINCL = @LTDLINCL@
171 171
 LTDLOPEN = @LTDLOPEN@
172 172
 LTLIBBZ2 = @LTLIBBZ2@
173
-LTLIBGMP = @LTLIBGMP@
174 173
 LTLIBOBJS = @LTLIBOBJS@
175 174
 LT_CONFIG_H = @LT_CONFIG_H@
176 175
 LT_DLLOADERS = @LT_DLLOADERS@
... ...
@@ -132,7 +132,6 @@ GENHTML = @GENHTML@
132 132
 GETENT = @GETENT@
133 133
 GPERF = @GPERF@
134 134
 GREP = @GREP@
135
-HAVE_LIBGMP = @HAVE_LIBGMP@
136 135
 INCLTDL = @INCLTDL@
137 136
 INSTALL = @INSTALL@
138 137
 INSTALL_DATA = @INSTALL_DATA@
... ...
@@ -150,8 +149,6 @@ LIBBZ2 = @LIBBZ2@
150 150
 LIBBZ2_PREFIX = @LIBBZ2_PREFIX@
151 151
 LIBCLAMAV_LIBS = @LIBCLAMAV_LIBS@
152 152
 LIBCLAMAV_VERSION = @LIBCLAMAV_VERSION@
153
-LIBGMP = @LIBGMP@
154
-LIBGMP_PREFIX = @LIBGMP_PREFIX@
155 153
 LIBLTDL = @LIBLTDL@
156 154
 LIBOBJS = @LIBOBJS@
157 155
 LIBS = $(top_builddir)/libclamav/libclamav.la @THREAD_LIBS@
... ...
@@ -162,7 +159,6 @@ LTDLDEPS = @LTDLDEPS@
162 162
 LTDLINCL = @LTDLINCL@
163 163
 LTDLOPEN = @LTDLOPEN@
164 164
 LTLIBBZ2 = @LTLIBBZ2@
165
-LTLIBGMP = @LTLIBGMP@
166 165
 LTLIBOBJS = @LTLIBOBJS@
167 166
 LT_CONFIG_H = @LT_CONFIG_H@
168 167
 LT_DLLOADERS = @LT_DLLOADERS@
... ...
@@ -915,10 +915,6 @@ LTLIBBZ2
915 915
 LIBBZ2_PREFIX
916 916
 ENABLE_UNRAR_TRUE
917 917
 ENABLE_UNRAR_FALSE
918
-HAVE_LIBGMP
919
-LIBGMP
920
-LTLIBGMP
921
-LIBGMP_PREFIX
922 918
 DBDIR
923 919
 CFGDIR
924 920
 LIBCLAMAV_LIBS
... ...
@@ -1553,7 +1549,6 @@ Optional Features:
1553 1553
                           DNS
1554 1554
   --disable-clamuko	  disable clamuko support (Linux, DragonFly and FreeBSD only)
1555 1555
   --enable-milter	  build clamav-milter
1556
-  --disable-dsig	  disable support for digital signatures
1557 1556
   --disable-pthreads      disable POSIX threads support
1558 1557
   --disable-cr		  don't link with C reentrant library (BSD)
1559 1558
   --enable-id-check	  use id utility instead of /etc/passwd parsing
... ...
@@ -1584,8 +1579,6 @@ Optional Packages:
1584 1584
 			  /usr/local or /usr if not found in /usr/local)
1585 1585
   --with-libbz2-prefix[=DIR]  search for libbz2 in DIR/include and DIR/lib
1586 1586
   --without-libbz2-prefix     don't search for libbz2 in includedir and libdir
1587
-  --with-libgmp-prefix[=DIR]  search for libgmp in DIR/include and DIR/lib
1588
-  --without-libgmp-prefix     don't search for libgmp in includedir and libdir
1589 1587
   --with-iconv supports iconv() (default=auto)
1590 1588
   --with-user=uid	  name of the clamav user (default=clamav)
1591 1589
   --with-group=gid	  name of the clamav group (default=clamav)
... ...
@@ -4785,13 +4778,13 @@ if test "${lt_cv_nm_interface+set}" = set; then
4785 4785
 else
4786 4786
   lt_cv_nm_interface="BSD nm"
4787 4787
   echo "int some_variable = 0;" > conftest.$ac_ext
4788
-  (eval echo "\"\$as_me:4788: $ac_compile\"" >&5)
4788
+  (eval echo "\"\$as_me:4781: $ac_compile\"" >&5)
4789 4789
   (eval "$ac_compile" 2>conftest.err)
4790 4790
   cat conftest.err >&5
4791
-  (eval echo "\"\$as_me:4791: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
4791
+  (eval echo "\"\$as_me:4784: $NM \\\"conftest.$ac_objext\\\"\"" >&5)
4792 4792
   (eval "$NM \"conftest.$ac_objext\"" 2>conftest.err > conftest.out)
4793 4793
   cat conftest.err >&5
4794
-  (eval echo "\"\$as_me:4794: output\"" >&5)
4794
+  (eval echo "\"\$as_me:4787: output\"" >&5)
4795 4795
   cat conftest.out >&5
4796 4796
   if $GREP 'External.*some_variable' conftest.out > /dev/null; then
4797 4797
     lt_cv_nm_interface="MS dumpbin"
... ...
@@ -6002,7 +5995,7 @@ ia64-*-hpux*)
6002 6002
   ;;
6003 6003
 *-*-irix6*)
6004 6004
   # Find out which ABI we are using.
6005
-  echo '#line 6005 "configure"' > conftest.$ac_ext
6005
+  echo '#line 5998 "configure"' > conftest.$ac_ext
6006 6006
   if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
6007 6007
   (eval $ac_compile) 2>&5
6008 6008
   ac_status=$?
... ...
@@ -7852,11 +7845,11 @@ else
7852 7852
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
7853 7853
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
7854 7854
    -e 's:$: $lt_compiler_flag:'`
7855
-   (eval echo "\"\$as_me:7855: $lt_compile\"" >&5)
7855
+   (eval echo "\"\$as_me:7848: $lt_compile\"" >&5)
7856 7856
    (eval "$lt_compile" 2>conftest.err)
7857 7857
    ac_status=$?
7858 7858
    cat conftest.err >&5
7859
-   echo "$as_me:7859: \$? = $ac_status" >&5
7859
+   echo "$as_me:7852: \$? = $ac_status" >&5
7860 7860
    if (exit $ac_status) && test -s "$ac_outfile"; then
7861 7861
      # The compiler can only warn and ignore the option if not recognized
7862 7862
      # So say no if there are warnings other than the usual output.
... ...
@@ -8191,11 +8184,11 @@ else
8191 8191
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
8192 8192
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
8193 8193
    -e 's:$: $lt_compiler_flag:'`
8194
-   (eval echo "\"\$as_me:8194: $lt_compile\"" >&5)
8194
+   (eval echo "\"\$as_me:8187: $lt_compile\"" >&5)
8195 8195
    (eval "$lt_compile" 2>conftest.err)
8196 8196
    ac_status=$?
8197 8197
    cat conftest.err >&5
8198
-   echo "$as_me:8198: \$? = $ac_status" >&5
8198
+   echo "$as_me:8191: \$? = $ac_status" >&5
8199 8199
    if (exit $ac_status) && test -s "$ac_outfile"; then
8200 8200
      # The compiler can only warn and ignore the option if not recognized
8201 8201
      # So say no if there are warnings other than the usual output.
... ...
@@ -8296,11 +8289,11 @@ else
8296 8296
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
8297 8297
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
8298 8298
    -e 's:$: $lt_compiler_flag:'`
8299
-   (eval echo "\"\$as_me:8299: $lt_compile\"" >&5)
8299
+   (eval echo "\"\$as_me:8292: $lt_compile\"" >&5)
8300 8300
    (eval "$lt_compile" 2>out/conftest.err)
8301 8301
    ac_status=$?
8302 8302
    cat out/conftest.err >&5
8303
-   echo "$as_me:8303: \$? = $ac_status" >&5
8303
+   echo "$as_me:8296: \$? = $ac_status" >&5
8304 8304
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
8305 8305
    then
8306 8306
      # The compiler can only warn and ignore the option if not recognized
... ...
@@ -8351,11 +8344,11 @@ else
8351 8351
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
8352 8352
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
8353 8353
    -e 's:$: $lt_compiler_flag:'`
8354
-   (eval echo "\"\$as_me:8354: $lt_compile\"" >&5)
8354
+   (eval echo "\"\$as_me:8347: $lt_compile\"" >&5)
8355 8355
    (eval "$lt_compile" 2>out/conftest.err)
8356 8356
    ac_status=$?
8357 8357
    cat out/conftest.err >&5
8358
-   echo "$as_me:8358: \$? = $ac_status" >&5
8358
+   echo "$as_me:8351: \$? = $ac_status" >&5
8359 8359
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
8360 8360
    then
8361 8361
      # The compiler can only warn and ignore the option if not recognized
... ...
@@ -11107,7 +11100,7 @@ else
11107 11107
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
11108 11108
   lt_status=$lt_dlunknown
11109 11109
   cat > conftest.$ac_ext <<_LT_EOF
11110
-#line 11110 "configure"
11110
+#line 11103 "configure"
11111 11111
 #include "confdefs.h"
11112 11112
 
11113 11113
 #if HAVE_DLFCN_H
... ...
@@ -11203,7 +11196,7 @@ else
11203 11203
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
11204 11204
   lt_status=$lt_dlunknown
11205 11205
   cat > conftest.$ac_ext <<_LT_EOF
11206
-#line 11206 "configure"
11206
+#line 11199 "configure"
11207 11207
 #include "confdefs.h"
11208 11208
 
11209 11209
 #if HAVE_DLFCN_H
... ...
@@ -12318,7 +12311,7 @@ else
12318 12318
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
12319 12319
   lt_status=$lt_dlunknown
12320 12320
   cat > conftest.$ac_ext <<_LT_EOF
12321
-#line 12321 "configure"
12321
+#line 12314 "configure"
12322 12322
 #include "confdefs.h"
12323 12323
 
12324 12324
 #if HAVE_DLFCN_H
... ...
@@ -19296,587 +19289,6 @@ else
19296 19296
 fi
19297 19297
 
19298 19298
 
19299
-# Check whether --enable-dsig was given.
19300
-if test "${enable_dsig+set}" = set; then
19301
-  enableval=$enable_dsig; want_dsig=$enableval
19302
-else
19303
-  want_dsig="yes"
19304
-fi
19305
-
19306
-
19307
-if test "$want_dsig" = "yes"
19308
-then
19309
-
19310
-
19311
-
19312
-
19313
-
19314
-
19315
-
19316
-
19317
-
19318
-
19319
-    use_additional=yes
19320
-
19321
-  acl_save_prefix="$prefix"
19322
-  prefix="$acl_final_prefix"
19323
-  acl_save_exec_prefix="$exec_prefix"
19324
-  exec_prefix="$acl_final_exec_prefix"
19325
-
19326
-    eval additional_includedir=\"$includedir\"
19327
-    eval additional_libdir=\"$libdir\"
19328
-
19329
-  exec_prefix="$acl_save_exec_prefix"
19330
-  prefix="$acl_save_prefix"
19331
-
19332
-
19333
-# Check whether --with-libgmp-prefix was given.
19334
-if test "${with_libgmp_prefix+set}" = set; then
19335
-  withval=$with_libgmp_prefix;
19336
-    if test "X$withval" = "Xno"; then
19337
-      use_additional=no
19338
-    else
19339
-      additional_compat_libdir=
19340
-      if test "X$withval" = "X"; then
19341
-
19342
-  acl_save_prefix="$prefix"
19343
-  prefix="$acl_final_prefix"
19344
-  acl_save_exec_prefix="$exec_prefix"
19345
-  exec_prefix="$acl_final_exec_prefix"
19346
-
19347
-          eval additional_includedir=\"$includedir\"
19348
-          eval additional_libdir=\"$libdir\"
19349
-
19350
-  exec_prefix="$acl_save_exec_prefix"
19351
-  prefix="$acl_save_prefix"
19352
-
19353
-      else
19354
-        additional_includedir="$withval/include"
19355
-        additional_libdir="$withval/$acl_libdirstem"
19356
-	if test "X$acl_libdirstem" != "Xlib"; then
19357
-		additional_compat_libdir="-L$withval/lib"
19358
-	fi
19359
-      fi
19360
-    fi
19361
-
19362
-fi
19363
-
19364
-      LIBGMP=
19365
-  LTLIBGMP=
19366
-  INCGMP=
19367
-  LIBGMP_PREFIX=
19368
-  rpathdirs=
19369
-  ltrpathdirs=
19370
-  names_already_handled=
19371
-  names_next_round='gmp '
19372
-  while test -n "$names_next_round"; do
19373
-    names_this_round="$names_next_round"
19374
-    names_next_round=
19375
-    for name in $names_this_round; do
19376
-      already_handled=
19377
-      for n in $names_already_handled; do
19378
-        if test "$n" = "$name"; then
19379
-          already_handled=yes
19380
-          break
19381
-        fi
19382
-      done
19383
-      if test -z "$already_handled"; then
19384
-        names_already_handled="$names_already_handled $name"
19385
-                        uppername=`echo "$name" | sed -e 'y|abcdefghijklmnopqrstuvwxyz./-|ABCDEFGHIJKLMNOPQRSTUVWXYZ___|'`
19386
-        eval value=\"\$HAVE_LIB$uppername\"
19387
-        if test -n "$value"; then
19388
-          if test "$value" = yes; then
19389
-            eval value=\"\$LIB$uppername\"
19390
-            test -z "$value" || LIBGMP="${LIBGMP}${LIBGMP:+ }$value"
19391
-            eval value=\"\$LTLIB$uppername\"
19392
-            test -z "$value" || LTLIBGMP="${LTLIBGMP}${LTLIBGMP:+ }$value"
19393
-          else
19394
-                                    :
19395
-          fi
19396
-        else
19397
-                              found_dir=
19398
-          found_la=
19399
-          found_so=
19400
-          found_a=
19401
-          eval libname=\"$acl_libname_spec\"    # typically: libname=lib$name
19402
-          if test -n "$acl_shlibext"; then
19403
-            shrext=".$acl_shlibext"             # typically: shrext=.so
19404
-          else
19405
-            shrext=
19406
-          fi
19407
-          if test $use_additional = yes; then
19408
-            dir="$additional_libdir"
19409
-                                    if test -n "$acl_shlibext"; then
19410
-              if test -f "$dir/$libname$shrext"; then
19411
-                found_dir="$dir"
19412
-                found_so="$dir/$libname$shrext"
19413
-              else
19414
-                if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then
19415
-                  ver=`(cd "$dir" && \
19416
-                        for f in "$libname$shrext".*; do echo "$f"; done \
19417
-                        | sed -e "s,^$libname$shrext\\\\.,," \
19418
-                        | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
19419
-                        | sed 1q ) 2>/dev/null`
19420
-                  if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then
19421
-                    found_dir="$dir"
19422
-                    found_so="$dir/$libname$shrext.$ver"
19423
-                  fi
19424
-                else
19425
-                  eval library_names=\"$acl_library_names_spec\"
19426
-                  for f in $library_names; do
19427
-                    if test -f "$dir/$f"; then
19428
-                      found_dir="$dir"
19429
-                      found_so="$dir/$f"
19430
-                      break
19431
-                    fi
19432
-                  done
19433
-                fi
19434
-              fi
19435
-            fi
19436
-                        if test "X$found_dir" = "X"; then
19437
-              if test -f "$dir/$libname.$acl_libext"; then
19438
-                found_dir="$dir"
19439
-                found_a="$dir/$libname.$acl_libext"
19440
-              fi
19441
-            fi
19442
-            if test "X$found_dir" != "X"; then
19443
-              if test -f "$dir/$libname.la"; then
19444
-                found_la="$dir/$libname.la"
19445
-              fi
19446
-            fi
19447
-          fi
19448
-          if test "X$found_dir" = "X"; then
19449
-            compat_libdir=
19450
-            if test "X$acl_libdirstem" != "Xlib"; then
19451
-		compat_libdir=-L'${exec_prefix}'/lib
19452
-	    fi
19453
-            for x in $LDFLAGS $LTLIBGMP $compat_libdir $additional_compat_libdir; do
19454
-
19455
-  acl_save_prefix="$prefix"
19456
-  prefix="$acl_final_prefix"
19457
-  acl_save_exec_prefix="$exec_prefix"
19458
-  exec_prefix="$acl_final_exec_prefix"
19459
-  eval x=\"$x\"
19460
-  exec_prefix="$acl_save_exec_prefix"
19461
-  prefix="$acl_save_prefix"
19462
-
19463
-              case "$x" in
19464
-                -L*)
19465
-                  dir=`echo "X$x" | sed -e 's/^X-L//'`
19466
-                                    if test -n "$acl_shlibext"; then
19467
-                    if test -f "$dir/$libname$shrext"; then
19468
-                      found_dir="$dir"
19469
-                      found_so="$dir/$libname$shrext"
19470
-                    else
19471
-                      if test "$acl_library_names_spec" = '$libname$shrext$versuffix'; then
19472
-                        ver=`(cd "$dir" && \
19473
-                              for f in "$libname$shrext".*; do echo "$f"; done \
19474
-                              | sed -e "s,^$libname$shrext\\\\.,," \
19475
-                              | sort -t '.' -n -r -k1,1 -k2,2 -k3,3 -k4,4 -k5,5 \
19476
-                              | sed 1q ) 2>/dev/null`
19477
-                        if test -n "$ver" && test -f "$dir/$libname$shrext.$ver"; then
19478
-                          found_dir="$dir"
19479
-                          found_so="$dir/$libname$shrext.$ver"
19480
-                        fi
19481
-                      else
19482
-                        eval library_names=\"$acl_library_names_spec\"
19483
-                        for f in $library_names; do
19484
-                          if test -f "$dir/$f"; then
19485
-                            found_dir="$dir"
19486
-                            found_so="$dir/$f"
19487
-                            break
19488
-                          fi
19489
-                        done
19490
-                      fi
19491
-                    fi
19492
-                  fi
19493
-                                    if test "X$found_dir" = "X"; then
19494
-                    if test -f "$dir/$libname.$acl_libext"; then
19495
-                      found_dir="$dir"
19496
-                      found_a="$dir/$libname.$acl_libext"
19497
-                    fi
19498
-                  fi
19499
-                  if test "X$found_dir" != "X"; then
19500
-                    if test -f "$dir/$libname.la"; then
19501
-                      found_la="$dir/$libname.la"
19502
-                    fi
19503
-                  fi
19504
-                  ;;
19505
-              esac
19506
-              if test "X$found_dir" != "X"; then
19507
-                break
19508
-              fi
19509
-            done
19510
-          fi
19511
-          if test "X$found_dir" != "X"; then
19512
-                        LTLIBGMP="${LTLIBGMP}${LTLIBGMP:+ }-L$found_dir -l$name"
19513
-            if test "X$found_so" != "X"; then
19514
-                                                        if test "$enable_rpath" = no || test "X$found_dir" = "X/usr/$acl_libdirstem"; then
19515
-                                LIBGMP="${LIBGMP}${LIBGMP:+ }$found_so"
19516
-              else
19517
-                                                                                haveit=
19518
-                for x in $ltrpathdirs; do
19519
-                  if test "X$x" = "X$found_dir"; then
19520
-                    haveit=yes
19521
-                    break
19522
-                  fi
19523
-                done
19524
-                if test -z "$haveit"; then
19525
-                  ltrpathdirs="$ltrpathdirs $found_dir"
19526
-                fi
19527
-                                if test "$acl_hardcode_direct" = yes; then
19528
-                                                      LIBGMP="${LIBGMP}${LIBGMP:+ }$found_so"
19529
-                else
19530
-                  if test -n "$acl_hardcode_libdir_flag_spec" && test "$acl_hardcode_minus_L" = no; then
19531
-                                                            LIBGMP="${LIBGMP}${LIBGMP:+ }$found_so"
19532
-                                                            haveit=
19533
-                    for x in $rpathdirs; do
19534
-                      if test "X$x" = "X$found_dir"; then
19535
-                        haveit=yes
19536
-                        break
19537
-                      fi
19538
-                    done
19539
-                    if test -z "$haveit"; then
19540
-                      rpathdirs="$rpathdirs $found_dir"
19541
-                    fi
19542
-                  else
19543
-                                                                                haveit=
19544
-                    for x in $LDFLAGS $LIBGMP; do
19545
-
19546
-  acl_save_prefix="$prefix"
19547
-  prefix="$acl_final_prefix"
19548
-  acl_save_exec_prefix="$exec_prefix"
19549
-  exec_prefix="$acl_final_exec_prefix"
19550
-  eval x=\"$x\"
19551
-  exec_prefix="$acl_save_exec_prefix"
19552
-  prefix="$acl_save_prefix"
19553
-
19554
-                      if test "X$x" = "X-L$found_dir"; then
19555
-                        haveit=yes
19556
-                        break
19557
-                      fi
19558
-                    done
19559
-                    if test -z "$haveit"; then
19560
-                      LIBGMP="${LIBGMP}${LIBGMP:+ }-L$found_dir"
19561
-                    fi
19562
-                    if test "$acl_hardcode_minus_L" != no; then
19563
-                                                                                        LIBGMP="${LIBGMP}${LIBGMP:+ }$found_so"
19564
-                    else
19565
-                                                                                                                                                                                LIBGMP="${LIBGMP}${LIBGMP:+ }-l$name"
19566
-                    fi
19567
-                  fi
19568
-                fi
19569
-              fi
19570
-            else
19571
-              if test "X$found_a" != "X"; then
19572
-                                LIBGMP="${LIBGMP}${LIBGMP:+ }$found_a"
19573
-              else
19574
-                                                LIBGMP="${LIBGMP}${LIBGMP:+ }-L$found_dir -l$name"
19575
-              fi
19576
-            fi
19577
-                        additional_includedir=
19578
-            case "$found_dir" in
19579
-              */$acl_libdirstem | */$acl_libdirstem/)
19580
-                basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/$acl_libdirstem/"'*$,,'`
19581
-                LIBGMP_PREFIX="$basedir"
19582
-                additional_includedir="$basedir/include"
19583
-                ;;
19584
-	     */lib | */lib/)
19585
-                basedir=`echo "X$found_dir" | sed -e 's,^X,,' -e "s,/lib/"'*$,,'`
19586
-                LIBGMP_PREFIX="$basedir"
19587
-                additional_includedir="$basedir/include"
19588
-                ;;
19589
-            esac
19590
-            if test "X$additional_includedir" != "X"; then
19591
-                                                                                                                if test "X$additional_includedir" != "X/usr/include"; then
19592
-                haveit=
19593
-                if test "X$additional_includedir" = "X/usr/local/include"; then
19594
-                  if test -n "$GCC"; then
19595
-                    case $host_os in
19596
-                      linux* | gnu* | k*bsd*-gnu) haveit=yes;;
19597
-                    esac
19598
-                  fi
19599
-                fi
19600
-                if test -z "$haveit"; then
19601
-                  for x in $CPPFLAGS $INCGMP; do
19602
-
19603
-  acl_save_prefix="$prefix"
19604
-  prefix="$acl_final_prefix"
19605
-  acl_save_exec_prefix="$exec_prefix"
19606
-  exec_prefix="$acl_final_exec_prefix"
19607
-  eval x=\"$x\"
19608
-  exec_prefix="$acl_save_exec_prefix"
19609
-  prefix="$acl_save_prefix"
19610
-
19611
-                    if test "X$x" = "X-I$additional_includedir"; then
19612
-                      haveit=yes
19613
-                      break
19614
-                    fi
19615
-                  done
19616
-                  if test -z "$haveit"; then
19617
-                    if test -d "$additional_includedir"; then
19618
-                                            INCGMP="${INCGMP}${INCGMP:+ }-I$additional_includedir"
19619
-                    fi
19620
-                  fi
19621
-                fi
19622
-              fi
19623
-            fi
19624
-                        if test -n "$found_la"; then
19625
-                                                        save_libdir="$libdir"
19626
-              case "$found_la" in
19627
-                */* | *\\*) . "$found_la" ;;
19628
-                *) . "./$found_la" ;;
19629
-              esac
19630
-              libdir="$save_libdir"
19631
-                            for dep in $dependency_libs; do
19632
-                case "$dep" in
19633
-                  -L*)
19634
-                    additional_libdir=`echo "X$dep" | sed -e 's/^X-L//'`
19635
-                                                                                                                                                                if test "X$additional_libdir" != "X/usr/$acl_libdirstem"; then
19636
-                      haveit=
19637
-                      if test "X$additional_libdir" = "X/usr/local/$acl_libdirstem"; then
19638
-                        if test -n "$GCC"; then
19639
-                          case $host_os in
19640
-                            linux* | gnu* | k*bsd*-gnu) haveit=yes;;
19641
-                          esac
19642
-                        fi
19643
-                      fi
19644
-                      if test -z "$haveit"; then
19645
-                        haveit=
19646
-                        for x in $LDFLAGS $LIBGMP; do
19647
-
19648
-  acl_save_prefix="$prefix"
19649
-  prefix="$acl_final_prefix"
19650
-  acl_save_exec_prefix="$exec_prefix"
19651
-  exec_prefix="$acl_final_exec_prefix"
19652
-  eval x=\"$x\"
19653
-  exec_prefix="$acl_save_exec_prefix"
19654
-  prefix="$acl_save_prefix"
19655
-
19656
-                          if test "X$x" = "X-L$additional_libdir"; then
19657
-                            haveit=yes
19658
-                            break
19659
-                          fi
19660
-                        done
19661
-                        if test -z "$haveit"; then
19662
-                          if test -d "$additional_libdir"; then
19663
-                                                        LIBGMP="${LIBGMP}${LIBGMP:+ }-L$additional_libdir"
19664
-                          fi
19665
-                        fi
19666
-                        haveit=
19667
-                        for x in $LDFLAGS $LTLIBGMP; do
19668
-
19669
-  acl_save_prefix="$prefix"
19670
-  prefix="$acl_final_prefix"
19671
-  acl_save_exec_prefix="$exec_prefix"
19672
-  exec_prefix="$acl_final_exec_prefix"
19673
-  eval x=\"$x\"
19674
-  exec_prefix="$acl_save_exec_prefix"
19675
-  prefix="$acl_save_prefix"
19676
-
19677
-                          if test "X$x" = "X-L$additional_libdir"; then
19678
-                            haveit=yes
19679
-                            break
19680
-                          fi
19681
-                        done
19682
-                        if test -z "$haveit"; then
19683
-                          if test -d "$additional_libdir"; then
19684
-                                                        LTLIBGMP="${LTLIBGMP}${LTLIBGMP:+ }-L$additional_libdir"
19685
-                          fi
19686
-                        fi
19687
-                      fi
19688
-                    fi
19689
-                    ;;
19690
-                  -R*)
19691
-                    dir=`echo "X$dep" | sed -e 's/^X-R//'`
19692
-                    if test "$enable_rpath" != no; then
19693
-                                                                  haveit=
19694
-                      for x in $rpathdirs; do
19695
-                        if test "X$x" = "X$dir"; then
19696
-                          haveit=yes
19697
-                          break
19698
-                        fi
19699
-                      done
19700
-                      if test -z "$haveit"; then
19701
-                        rpathdirs="$rpathdirs $dir"
19702
-                      fi
19703
-                                                                  haveit=
19704
-                      for x in $ltrpathdirs; do
19705
-                        if test "X$x" = "X$dir"; then
19706
-                          haveit=yes
19707
-                          break
19708
-                        fi
19709
-                      done
19710
-                      if test -z "$haveit"; then
19711
-                        ltrpathdirs="$ltrpathdirs $dir"
19712
-                      fi
19713
-                    fi
19714
-                    ;;
19715
-                  -l*)
19716
-                                        names_next_round="$names_next_round "`echo "X$dep" | sed -e 's/^X-l//'`
19717
-                    ;;
19718
-                  *.la)
19719
-                                                                                names_next_round="$names_next_round "`echo "X$dep" | sed -e 's,^X.*/,,' -e 's,^lib,,' -e 's,\.la$,,'`
19720
-                    ;;
19721
-                  *)
19722
-                                        LIBGMP="${LIBGMP}${LIBGMP:+ }$dep"
19723
-                    LTLIBGMP="${LTLIBGMP}${LTLIBGMP:+ }$dep"
19724
-                    ;;
19725
-                esac
19726
-              done
19727
-            fi
19728
-          else
19729
-                                                            LIBGMP="${LIBGMP}${LIBGMP:+ }-l$name"
19730
-            LTLIBGMP="${LTLIBGMP}${LTLIBGMP:+ }-l$name"
19731
-          fi
19732
-        fi
19733
-      fi
19734
-    done
19735
-  done
19736
-  if test "X$rpathdirs" != "X"; then
19737
-    if test -n "$acl_hardcode_libdir_separator"; then
19738
-                        alldirs=
19739
-      for found_dir in $rpathdirs; do
19740
-        alldirs="${alldirs}${alldirs:+$acl_hardcode_libdir_separator}$found_dir"
19741
-      done
19742
-            acl_save_libdir="$libdir"
19743
-      libdir="$alldirs"
19744
-      eval flag=\"$acl_hardcode_libdir_flag_spec\"
19745
-      libdir="$acl_save_libdir"
19746
-      LIBGMP="${LIBGMP}${LIBGMP:+ }$flag"
19747
-    else
19748
-            for found_dir in $rpathdirs; do
19749
-        acl_save_libdir="$libdir"
19750
-        libdir="$found_dir"
19751
-        eval flag=\"$acl_hardcode_libdir_flag_spec\"
19752
-        libdir="$acl_save_libdir"
19753
-        LIBGMP="${LIBGMP}${LIBGMP:+ }$flag"
19754
-      done
19755
-    fi
19756
-  fi
19757
-  if test "X$ltrpathdirs" != "X"; then
19758
-            for found_dir in $ltrpathdirs; do
19759
-      LTLIBGMP="${LTLIBGMP}${LTLIBGMP:+ }-R$found_dir"
19760
-    done
19761
-  fi
19762
-
19763
-
19764
-        ac_save_CPPFLAGS="$CPPFLAGS"
19765
-
19766
-  for element in $INCGMP; do
19767
-    haveit=
19768
-    for x in $CPPFLAGS; do
19769
-
19770
-  acl_save_prefix="$prefix"
19771
-  prefix="$acl_final_prefix"
19772
-  acl_save_exec_prefix="$exec_prefix"
19773
-  exec_prefix="$acl_final_exec_prefix"
19774
-  eval x=\"$x\"
19775
-  exec_prefix="$acl_save_exec_prefix"
19776
-  prefix="$acl_save_prefix"
19777
-
19778
-      if test "X$x" = "X$element"; then
19779
-        haveit=yes
19780
-        break
19781
-      fi
19782
-    done
19783
-    if test -z "$haveit"; then
19784
-      CPPFLAGS="${CPPFLAGS}${CPPFLAGS:+ }$element"
19785
-    fi
19786
-  done
19787
-
19788
-
19789
-  { echo "$as_me:$LINENO: checking for libgmp" >&5
19790
-echo $ECHO_N "checking for libgmp... $ECHO_C" >&6; }
19791
-if test "${ac_cv_libgmp+set}" = set; then
19792
-  echo $ECHO_N "(cached) $ECHO_C" >&6
19793
-else
19794
-
19795
-    ac_save_LIBS="$LIBS"
19796
-    LIBS="$LIBS $LIBGMP"
19797
-    cat >conftest.$ac_ext <<_ACEOF
19798
-/* confdefs.h.  */
19799
-_ACEOF
19800
-cat confdefs.h >>conftest.$ac_ext
19801
-cat >>conftest.$ac_ext <<_ACEOF
19802
-/* end confdefs.h.  */
19803
-#include <gmp.h>
19804
-
19805
-int
19806
-main ()
19807
-{
19808
-mpz_init(0);
19809
-  ;
19810
-  return 0;
19811
-}
19812
-_ACEOF
19813
-rm -f conftest.$ac_objext conftest$ac_exeext
19814
-if { (ac_try="$ac_link"
19815
-case "(($ac_try" in
19816
-  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
19817
-  *) ac_try_echo=$ac_try;;
19818
-esac
19819
-eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
19820
-  (eval "$ac_link") 2>conftest.er1
19821
-  ac_status=$?
19822
-  grep -v '^ *+' conftest.er1 >conftest.err
19823
-  rm -f conftest.er1
19824
-  cat conftest.err >&5
19825
-  echo "$as_me:$LINENO: \$? = $ac_status" >&5
19826
-  (exit $ac_status); } && {
19827
-	 test -z "$ac_c_werror_flag" ||
19828
-	 test ! -s conftest.err
19829
-       } && test -s conftest$ac_exeext &&
19830
-       $as_test_x conftest$ac_exeext; then
19831
-  ac_cv_libgmp=yes
19832
-else
19833
-  echo "$as_me: failed program was:" >&5
19834
-sed 's/^/| /' conftest.$ac_ext >&5
19835
-
19836
-	ac_cv_libgmp=no
19837
-fi
19838
-
19839
-rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
19840
-      conftest$ac_exeext conftest.$ac_ext
19841
-    LIBS="$ac_save_LIBS"
19842
-
19843
-fi
19844
-{ echo "$as_me:$LINENO: result: $ac_cv_libgmp" >&5
19845
-echo "${ECHO_T}$ac_cv_libgmp" >&6; }
19846
-  if test "$ac_cv_libgmp" = yes; then
19847
-    HAVE_LIBGMP=yes
19848
-
19849
-cat >>confdefs.h <<\_ACEOF
19850
-#define HAVE_LIBGMP 1
19851
-_ACEOF
19852
-
19853
-    { echo "$as_me:$LINENO: checking how to link with libgmp" >&5
19854
-echo $ECHO_N "checking how to link with libgmp... $ECHO_C" >&6; }
19855
-    { echo "$as_me:$LINENO: result: $LIBGMP" >&5
19856
-echo "${ECHO_T}$LIBGMP" >&6; }
19857
-  else
19858
-    HAVE_LIBGMP=no
19859
-            CPPFLAGS="$ac_save_CPPFLAGS"
19860
-    LIBGMP=
19861
-    LTLIBGMP=
19862
-    LIBGMP_PREFIX=
19863
-  fi
19864
-
19865
-
19866
-
19867
-
19868
-
19869
-
19870
-
19871
-            if test "$HAVE_LIBGMP" = "yes"; then
19872
-	    LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS $LTLIBGMP";
19873
-    else
19874
-	    { echo "$as_me:$LINENO: WARNING: ****** GNU MP 2 or newer NOT FOUND - digital signature support will be disabled !" >&5
19875
-echo "$as_me: WARNING: ****** GNU MP 2 or newer NOT FOUND - digital signature support will be disabled !" >&2;};
19876
-	    want_dsig="no";
19877
-    fi
19878
-fi
19879
-
19880 19299
 
19881 19300
 # Check whether --with-iconv was given.
19882 19301
 if test "${with_iconv+set}" = set; then
... ...
@@ -24225,10 +23637,6 @@ LTLIBBZ2!$LTLIBBZ2$ac_delim
24225 24225
 LIBBZ2_PREFIX!$LIBBZ2_PREFIX$ac_delim
24226 24226
 ENABLE_UNRAR_TRUE!$ENABLE_UNRAR_TRUE$ac_delim
24227 24227
 ENABLE_UNRAR_FALSE!$ENABLE_UNRAR_FALSE$ac_delim
24228
-HAVE_LIBGMP!$HAVE_LIBGMP$ac_delim
24229
-LIBGMP!$LIBGMP$ac_delim
24230
-LTLIBGMP!$LTLIBGMP$ac_delim
24231
-LIBGMP_PREFIX!$LIBGMP_PREFIX$ac_delim
24232 24228
 DBDIR!$DBDIR$ac_delim
24233 24229
 CFGDIR!$CFGDIR$ac_delim
24234 24230
 LIBCLAMAV_LIBS!$LIBCLAMAV_LIBS$ac_delim
... ...
@@ -24250,7 +23658,7 @@ ltdl_LIBOBJS!$ltdl_LIBOBJS$ac_delim
24250 24250
 ltdl_LTLIBOBJS!$ltdl_LTLIBOBJS$ac_delim
24251 24251
 _ACEOF
24252 24252
 
24253
-  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 75; then
24253
+  if test `sed -n "s/.*$ac_delim\$/X/p" conf$$subs.sed | grep -c X` = 71; then
24254 24254
     break
24255 24255
   elif $ac_last_try; then
24256 24256
     { { echo "$as_me:$LINENO: error: could not make $CONFIG_STATUS" >&5
... ...
@@ -700,28 +700,6 @@ AC_ARG_ENABLE([milter],
700 700
 [  --enable-milter	  build clamav-milter],
701 701
 have_milter=$enableval, have_milter="no")
702 702
 
703
-AC_ARG_ENABLE([dsig],
704
-[  --disable-dsig	  disable support for digital signatures],
705
-want_dsig=$enableval, want_dsig="yes")
706
-
707
-if test "$want_dsig" = "yes"
708
-then
709
-    dnl defines HAVE_LIBGMP, LIBGMP, and LTLIBGMP
710
-    dnl also adds option --with-libgmp-prefix to configure
711
-    AC_LIB_HAVE_LINKFLAGS([gmp],,
712
-	[#include <gmp.h>
713
-	],
714
-	[mpz_init(0);])
715
-    dnl we don't need to check for __gmpz_init and mpz_init,
716
-    dnl since we are not checking directly for symbols
717
-    if test "$HAVE_LIBGMP" = "yes"; then
718
-	    LIBCLAMAV_LIBS="$LIBCLAMAV_LIBS $LTLIBGMP";
719
-    else
720
-	    AC_MSG_WARN([****** GNU MP 2 or newer NOT FOUND - digital signature support will be disabled !]);
721
-	    want_dsig="no";
722
-    fi
723
-fi
724
-
725 703
 dnl we need to try to link with iconv, otherwise there could be a 
726 704
 dnl mismatch between a 32-bit and 64-bit lib. Detect this at configure time.
727 705
 dnl we need to check after zlib/bzip2, because they can change the include path
... ...
@@ -108,7 +108,6 @@ GENHTML = @GENHTML@
108 108
 GETENT = @GETENT@
109 109
 GPERF = @GPERF@
110 110
 GREP = @GREP@
111
-HAVE_LIBGMP = @HAVE_LIBGMP@
112 111
 INCLTDL = @INCLTDL@
113 112
 INSTALL = @INSTALL@
114 113
 INSTALL_DATA = @INSTALL_DATA@
... ...
@@ -126,8 +125,6 @@ LIBBZ2 = @LIBBZ2@
126 126
 LIBBZ2_PREFIX = @LIBBZ2_PREFIX@
127 127
 LIBCLAMAV_LIBS = @LIBCLAMAV_LIBS@
128 128
 LIBCLAMAV_VERSION = @LIBCLAMAV_VERSION@
129
-LIBGMP = @LIBGMP@
130
-LIBGMP_PREFIX = @LIBGMP_PREFIX@
131 129
 LIBLTDL = @LIBLTDL@
132 130
 LIBOBJS = @LIBOBJS@
133 131
 LIBS = @LIBS@
... ...
@@ -138,7 +135,6 @@ LTDLDEPS = @LTDLDEPS@
138 138
 LTDLINCL = @LTDLINCL@
139 139
 LTDLOPEN = @LTDLOPEN@
140 140
 LTLIBBZ2 = @LTLIBBZ2@
141
-LTLIBGMP = @LTLIBGMP@
142 141
 LTLIBOBJS = @LTLIBOBJS@
143 142
 LT_CONFIG_H = @LT_CONFIG_H@
144 143
 LT_DLLOADERS = @LT_DLLOADERS@
... ...
@@ -114,7 +114,6 @@ GENHTML = @GENHTML@
114 114
 GETENT = @GETENT@
115 115
 GPERF = @GPERF@
116 116
 GREP = @GREP@
117
-HAVE_LIBGMP = @HAVE_LIBGMP@
118 117
 INCLTDL = @INCLTDL@
119 118
 INSTALL = @INSTALL@
120 119
 INSTALL_DATA = @INSTALL_DATA@
... ...
@@ -132,8 +131,6 @@ LIBBZ2 = @LIBBZ2@
132 132
 LIBBZ2_PREFIX = @LIBBZ2_PREFIX@
133 133
 LIBCLAMAV_LIBS = @LIBCLAMAV_LIBS@
134 134
 LIBCLAMAV_VERSION = @LIBCLAMAV_VERSION@
135
-LIBGMP = @LIBGMP@
136
-LIBGMP_PREFIX = @LIBGMP_PREFIX@
137 135
 LIBLTDL = @LIBLTDL@
138 136
 LIBOBJS = @LIBOBJS@
139 137
 LIBS = @LIBS@
... ...
@@ -144,7 +141,6 @@ LTDLDEPS = @LTDLDEPS@
144 144
 LTDLINCL = @LTDLINCL@
145 145
 LTDLOPEN = @LTDLOPEN@
146 146
 LTLIBBZ2 = @LTLIBBZ2@
147
-LTLIBGMP = @LTLIBGMP@
148 147
 LTLIBOBJS = @LTLIBOBJS@
149 148
 LT_CONFIG_H = @LT_CONFIG_H@
150 149
 LT_DLLOADERS = @LT_DLLOADERS@
... ...
@@ -107,7 +107,6 @@ GENHTML = @GENHTML@
107 107
 GETENT = @GETENT@
108 108
 GPERF = @GPERF@
109 109
 GREP = @GREP@
110
-HAVE_LIBGMP = @HAVE_LIBGMP@
111 110
 INCLTDL = @INCLTDL@
112 111
 INSTALL = @INSTALL@
113 112
 INSTALL_DATA = @INSTALL_DATA@
... ...
@@ -125,8 +124,6 @@ LIBBZ2 = @LIBBZ2@
125 125
 LIBBZ2_PREFIX = @LIBBZ2_PREFIX@
126 126
 LIBCLAMAV_LIBS = @LIBCLAMAV_LIBS@
127 127
 LIBCLAMAV_VERSION = @LIBCLAMAV_VERSION@
128
-LIBGMP = @LIBGMP@
129
-LIBGMP_PREFIX = @LIBGMP_PREFIX@
130 128
 LIBLTDL = @LIBLTDL@
131 129
 LIBOBJS = @LIBOBJS@
132 130
 LIBS = @LIBS@
... ...
@@ -137,7 +134,6 @@ LTDLDEPS = @LTDLDEPS@
137 137
 LTDLINCL = @LTDLINCL@
138 138
 LTDLOPEN = @LTDLOPEN@
139 139
 LTLIBBZ2 = @LTLIBBZ2@
140
-LTLIBGMP = @LTLIBGMP@
141 140
 LTLIBOBJS = @LTLIBOBJS@
142 141
 LT_CONFIG_H = @LT_CONFIG_H@
143 142
 LT_DLLOADERS = @LT_DLLOADERS@
... ...
@@ -134,7 +134,6 @@ GENHTML = @GENHTML@
134 134
 GETENT = @GETENT@
135 135
 GPERF = @GPERF@
136 136
 GREP = @GREP@
137
-HAVE_LIBGMP = @HAVE_LIBGMP@
138 137
 INCLTDL = @INCLTDL@
139 138
 INSTALL = @INSTALL@
140 139
 INSTALL_DATA = @INSTALL_DATA@
... ...
@@ -152,8 +151,6 @@ LIBBZ2 = @LIBBZ2@
152 152
 LIBBZ2_PREFIX = @LIBBZ2_PREFIX@
153 153
 LIBCLAMAV_LIBS = @LIBCLAMAV_LIBS@
154 154
 LIBCLAMAV_VERSION = @LIBCLAMAV_VERSION@
155
-LIBGMP = @LIBGMP@
156
-LIBGMP_PREFIX = @LIBGMP_PREFIX@
157 155
 LIBLTDL = @LIBLTDL@
158 156
 LIBOBJS = @LIBOBJS@
159 157
 LIBS = $(top_builddir)/libclamav/libclamav.la @FRESHCLAM_LIBS@ @THREAD_LIBS@
... ...
@@ -164,7 +161,6 @@ LTDLDEPS = @LTDLDEPS@
164 164
 LTDLINCL = @LTDLINCL@
165 165
 LTDLOPEN = @LTDLOPEN@
166 166
 LTLIBBZ2 = @LTLIBBZ2@
167
-LTLIBGMP = @LTLIBGMP@
168 167
 LTLIBOBJS = @LTLIBOBJS@
169 168
 LT_CONFIG_H = @LT_CONFIG_H@
170 169
 LT_DLLOADERS = @LT_DLLOADERS@
... ...
@@ -1728,11 +1728,6 @@ int downloadmanager(const struct optstruct *opts, const char *hostname, const ch
1728 1728
     logg("*Using IPv6 aware code\n");
1729 1729
 #endif
1730 1730
 
1731
-#ifndef HAVE_LIBGMP
1732
-    logg("SECURITY WARNING: NO SUPPORT FOR DIGITAL SIGNATURES\n");
1733
-    logg("See the FAQ at http://www.clamav.net/support/faq for an explanation.\n");
1734
-#endif
1735
-
1736 1731
 #ifdef HAVE_RESOLV_H
1737 1732
     dnsdbinfo = optget(opts, "DNSDatabaseInfo")->strarg;
1738 1733
 
... ...
@@ -87,7 +87,10 @@ libclamav_internal_utils_la_SOURCES=str.c \
87 87
 				    regex/cname.h \
88 88
 				    regex/regex.h \
89 89
 				    regex/regex2.h \
90
-				    regex/utils.h
90
+				    regex/utils.h \
91
+				    bignum.c \
92
+				    bignum.h \
93
+				    bignum_class.h
91 94
 
92 95
 libclamav_internal_utils_la_LDFLAGS=-static
93 96
 libclamav_internal_utils_la_CFLAGS=  -fPIC -DPIC
... ...
@@ -113,7 +113,8 @@ am_libclamav_internal_utils_la_OBJECTS =  \
113 113
 	libclamav_internal_utils_la-regcomp.lo \
114 114
 	libclamav_internal_utils_la-regerror.lo \
115 115
 	libclamav_internal_utils_la-regexec.lo \
116
-	libclamav_internal_utils_la-regfree.lo
116
+	libclamav_internal_utils_la-regfree.lo \
117
+	libclamav_internal_utils_la-bignum.lo
117 118
 libclamav_internal_utils_la_OBJECTS =  \
118 119
 	$(am_libclamav_internal_utils_la_OBJECTS)
119 120
 libclamav_internal_utils_la_LINK = $(LIBTOOL) --tag=CC \
... ...
@@ -221,7 +222,6 @@ GENHTML = @GENHTML@
221 221
 GETENT = @GETENT@
222 222
 GPERF = @GPERF@
223 223
 GREP = @GREP@
224
-HAVE_LIBGMP = @HAVE_LIBGMP@
225 224
 INCLTDL = @INCLTDL@
226 225
 INSTALL = @INSTALL@
227 226
 INSTALL_DATA = @INSTALL_DATA@
... ...
@@ -239,8 +239,6 @@ LIBBZ2 = @LIBBZ2@
239 239
 LIBBZ2_PREFIX = @LIBBZ2_PREFIX@
240 240
 LIBCLAMAV_LIBS = @LIBCLAMAV_LIBS@
241 241
 LIBCLAMAV_VERSION = @LIBCLAMAV_VERSION@
242
-LIBGMP = @LIBGMP@
243
-LIBGMP_PREFIX = @LIBGMP_PREFIX@
244 242
 LIBLTDL = @LIBLTDL@
245 243
 LIBOBJS = @LIBOBJS@
246 244
 LIBS = @LIBS@
... ...
@@ -251,7 +249,6 @@ LTDLDEPS = @LTDLDEPS@
251 251
 LTDLINCL = @LTDLINCL@
252 252
 LTDLOPEN = @LTDLOPEN@
253 253
 LTLIBBZ2 = @LTLIBBZ2@
254
-LTLIBGMP = @LTLIBGMP@
255 254
 LTLIBOBJS = @LTLIBOBJS@
256 255
 LT_CONFIG_H = @LT_CONFIG_H@
257 256
 LT_DLLOADERS = @LT_DLLOADERS@
... ...
@@ -392,7 +389,10 @@ libclamav_internal_utils_la_SOURCES = str.c \
392 392
 				    regex/cname.h \
393 393
 				    regex/regex.h \
394 394
 				    regex/regex2.h \
395
-				    regex/utils.h
395
+				    regex/utils.h \
396
+				    bignum.c \
397
+				    bignum.h \
398
+				    bignum_class.h
396 399
 
397 400
 libclamav_internal_utils_la_LDFLAGS = -static
398 401
 libclamav_internal_utils_la_CFLAGS = -fPIC -DPIC
... ...
@@ -676,6 +676,7 @@ distclean-compile:
676 676
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/inflate64.Plo@am__quote@
677 677
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/is_tar.Plo@am__quote@
678 678
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/js-norm.Plo@am__quote@
679
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_la-bignum.Plo@am__quote@
679 680
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_la-others_common.Plo@am__quote@
680 681
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_la-regcomp.Plo@am__quote@
681 682
 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libclamav_internal_utils_la-regerror.Plo@am__quote@
... ...
@@ -839,6 +840,13 @@ libclamav_internal_utils_la-regfree.lo: regex/regfree.c
839 839
 @AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
840 840
 @am__fastdepCC_FALSE@	$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libclamav_internal_utils_la_CFLAGS) $(CFLAGS) -c -o libclamav_internal_utils_la-regfree.lo `test -f 'regex/regfree.c' || echo '$(srcdir)/'`regex/regfree.c
841 841
 
842
+libclamav_internal_utils_la-bignum.lo: bignum.c
843
+@am__fastdepCC_TRUE@	$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libclamav_internal_utils_la_CFLAGS) $(CFLAGS) -MT libclamav_internal_utils_la-bignum.lo -MD -MP -MF $(DEPDIR)/libclamav_internal_utils_la-bignum.Tpo -c -o libclamav_internal_utils_la-bignum.lo `test -f 'bignum.c' || echo '$(srcdir)/'`bignum.c
844
+@am__fastdepCC_TRUE@	mv -f $(DEPDIR)/libclamav_internal_utils_la-bignum.Tpo $(DEPDIR)/libclamav_internal_utils_la-bignum.Plo
845
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	source='bignum.c' object='libclamav_internal_utils_la-bignum.lo' libtool=yes @AMDEPBACKSLASH@
846
+@AMDEP_TRUE@@am__fastdepCC_FALSE@	DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
847
+@am__fastdepCC_FALSE@	$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libclamav_internal_utils_la_CFLAGS) $(CFLAGS) -c -o libclamav_internal_utils_la-bignum.lo `test -f 'bignum.c' || echo '$(srcdir)/'`bignum.c
848
+
842 849
 unrar15.lo: ../libclamunrar/unrar15.c
843 850
 @am__fastdepCC_TRUE@	$(LIBTOOL) --tag=CC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) -MT unrar15.lo -MD -MP -MF $(DEPDIR)/unrar15.Tpo -c -o unrar15.lo `test -f '../libclamunrar/unrar15.c' || echo '$(srcdir)/'`../libclamunrar/unrar15.c
844 851
 @am__fastdepCC_TRUE@	mv -f $(DEPDIR)/unrar15.Tpo $(DEPDIR)/unrar15.Plo
845 852
new file mode 100644
... ...
@@ -0,0 +1,9516 @@
0
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
1
+ *
2
+ * LibTomMath is a library that provides multiple-precision
3
+ * integer arithmetic as well as number theoretic functionality.
4
+ *
5
+ * The library was designed directly after the MPI library by
6
+ * Michael Fromberger but has been written from scratch with
7
+ * additional optimizations in place.
8
+ *
9
+ * The library is free for all purposes without any express
10
+ * guarantee it works.
11
+ *
12
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
13
+ */
14
+
15
+/* Start: bn_error.c */
16
+#include <bignum.h>
17
+#include "others.h"
18
+
19
+#ifdef BN_ERROR_C
20
+static const struct {
21
+     int code;
22
+     const char *msg;
23
+} msgs[] = {
24
+     { MP_OKAY, "Successful" },
25
+     { MP_MEM,  "Out of heap" },
26
+     { MP_VAL,  "Value out of range" }
27
+};
28
+
29
+/* return a char * string for a given code */
30
+const char *mp_error_to_string(int code)
31
+{
32
+   int x;
33
+
34
+   /* scan the lookup table for the given message */
35
+   for (x = 0; x < (int)(sizeof(msgs) / sizeof(msgs[0])); x++) {
36
+       if (msgs[x].code == code) {
37
+          return msgs[x].msg;
38
+       }
39
+   }
40
+
41
+   /* generic reply for invalid code */
42
+   return "Invalid error code";
43
+}
44
+
45
+#endif
46
+
47
+/* $Source: /cvs/libtom/libtommath/bn_error.c,v $ */
48
+/* $Revision: 1.3 $ */
49
+/* $Date: 2006/03/31 14:18:44 $ */
50
+
51
+/* End: bn_error.c */
52
+
53
+/* Start: bn_fast_mp_invmod.c */
54
+#include <bignum.h>
55
+#ifdef BN_FAST_MP_INVMOD_C
56
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
57
+ *
58
+ * LibTomMath is a library that provides multiple-precision
59
+ * integer arithmetic as well as number theoretic functionality.
60
+ *
61
+ * The library was designed directly after the MPI library by
62
+ * Michael Fromberger but has been written from scratch with
63
+ * additional optimizations in place.
64
+ *
65
+ * The library is free for all purposes without any express
66
+ * guarantee it works.
67
+ *
68
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
69
+ */
70
+
71
+/* computes the modular inverse via binary extended euclidean algorithm, 
72
+ * that is c = 1/a mod b 
73
+ *
74
+ * Based on slow invmod except this is optimized for the case where b is 
75
+ * odd as per HAC Note 14.64 on pp. 610
76
+ */
77
+int fast_mp_invmod (mp_int * a, mp_int * b, mp_int * c)
78
+{
79
+  mp_int  x, y, u, v, B, D;
80
+  int     res, neg;
81
+
82
+  /* 2. [modified] b must be odd   */
83
+  if (mp_iseven (b) == 1) {
84
+    return MP_VAL;
85
+  }
86
+
87
+  /* init all our temps */
88
+  if ((res = mp_init_multi(&x, &y, &u, &v, &B, &D, NULL)) != MP_OKAY) {
89
+     return res;
90
+  }
91
+
92
+  /* x == modulus, y == value to invert */
93
+  if ((res = mp_copy (b, &x)) != MP_OKAY) {
94
+    goto LBL_ERR;
95
+  }
96
+
97
+  /* we need y = |a| */
98
+  if ((res = mp_mod (a, b, &y)) != MP_OKAY) {
99
+    goto LBL_ERR;
100
+  }
101
+
102
+  /* 3. u=x, v=y, A=1, B=0, C=0,D=1 */
103
+  if ((res = mp_copy (&x, &u)) != MP_OKAY) {
104
+    goto LBL_ERR;
105
+  }
106
+  if ((res = mp_copy (&y, &v)) != MP_OKAY) {
107
+    goto LBL_ERR;
108
+  }
109
+  mp_set (&D, 1);
110
+
111
+top:
112
+  /* 4.  while u is even do */
113
+  while (mp_iseven (&u) == 1) {
114
+    /* 4.1 u = u/2 */
115
+    if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
116
+      goto LBL_ERR;
117
+    }
118
+    /* 4.2 if B is odd then */
119
+    if (mp_isodd (&B) == 1) {
120
+      if ((res = mp_sub (&B, &x, &B)) != MP_OKAY) {
121
+        goto LBL_ERR;
122
+      }
123
+    }
124
+    /* B = B/2 */
125
+    if ((res = mp_div_2 (&B, &B)) != MP_OKAY) {
126
+      goto LBL_ERR;
127
+    }
128
+  }
129
+
130
+  /* 5.  while v is even do */
131
+  while (mp_iseven (&v) == 1) {
132
+    /* 5.1 v = v/2 */
133
+    if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
134
+      goto LBL_ERR;
135
+    }
136
+    /* 5.2 if D is odd then */
137
+    if (mp_isodd (&D) == 1) {
138
+      /* D = (D-x)/2 */
139
+      if ((res = mp_sub (&D, &x, &D)) != MP_OKAY) {
140
+        goto LBL_ERR;
141
+      }
142
+    }
143
+    /* D = D/2 */
144
+    if ((res = mp_div_2 (&D, &D)) != MP_OKAY) {
145
+      goto LBL_ERR;
146
+    }
147
+  }
148
+
149
+  /* 6.  if u >= v then */
150
+  if (mp_cmp (&u, &v) != MP_LT) {
151
+    /* u = u - v, B = B - D */
152
+    if ((res = mp_sub (&u, &v, &u)) != MP_OKAY) {
153
+      goto LBL_ERR;
154
+    }
155
+
156
+    if ((res = mp_sub (&B, &D, &B)) != MP_OKAY) {
157
+      goto LBL_ERR;
158
+    }
159
+  } else {
160
+    /* v - v - u, D = D - B */
161
+    if ((res = mp_sub (&v, &u, &v)) != MP_OKAY) {
162
+      goto LBL_ERR;
163
+    }
164
+
165
+    if ((res = mp_sub (&D, &B, &D)) != MP_OKAY) {
166
+      goto LBL_ERR;
167
+    }
168
+  }
169
+
170
+  /* if not zero goto step 4 */
171
+  if (mp_iszero (&u) == 0) {
172
+    goto top;
173
+  }
174
+
175
+  /* now a = C, b = D, gcd == g*v */
176
+
177
+  /* if v != 1 then there is no inverse */
178
+  if (mp_cmp_d (&v, 1) != MP_EQ) {
179
+    res = MP_VAL;
180
+    goto LBL_ERR;
181
+  }
182
+
183
+  /* b is now the inverse */
184
+  neg = a->sign;
185
+  while (D.sign == MP_NEG) {
186
+    if ((res = mp_add (&D, b, &D)) != MP_OKAY) {
187
+      goto LBL_ERR;
188
+    }
189
+  }
190
+  mp_exch (&D, c);
191
+  c->sign = neg;
192
+  res = MP_OKAY;
193
+
194
+LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &B, &D, NULL);
195
+  return res;
196
+}
197
+#endif
198
+
199
+/* $Source: /cvs/libtom/libtommath/bn_fast_mp_invmod.c,v $ */
200
+/* $Revision: 1.3 $ */
201
+/* $Date: 2006/03/31 14:18:44 $ */
202
+
203
+/* End: bn_fast_mp_invmod.c */
204
+
205
+/* Start: bn_fast_mp_montgomery_reduce.c */
206
+#include <bignum.h>
207
+#ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C
208
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
209
+ *
210
+ * LibTomMath is a library that provides multiple-precision
211
+ * integer arithmetic as well as number theoretic functionality.
212
+ *
213
+ * The library was designed directly after the MPI library by
214
+ * Michael Fromberger but has been written from scratch with
215
+ * additional optimizations in place.
216
+ *
217
+ * The library is free for all purposes without any express
218
+ * guarantee it works.
219
+ *
220
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
221
+ */
222
+
223
+/* computes xR**-1 == x (mod N) via Montgomery Reduction
224
+ *
225
+ * This is an optimized implementation of montgomery_reduce
226
+ * which uses the comba method to quickly calculate the columns of the
227
+ * reduction.
228
+ *
229
+ * Based on Algorithm 14.32 on pp.601 of HAC.
230
+*/
231
+int fast_mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
232
+{
233
+  int     ix, res, olduse;
234
+  mp_word W[MP_WARRAY];
235
+
236
+  /* get old used count */
237
+  olduse = x->used;
238
+
239
+  /* grow a as required */
240
+  if (x->alloc < n->used + 1) {
241
+    if ((res = mp_grow (x, n->used + 1)) != MP_OKAY) {
242
+      return res;
243
+    }
244
+  }
245
+
246
+  /* first we have to get the digits of the input into
247
+   * an array of double precision words W[...]
248
+   */
249
+  {
250
+    register mp_word *_W;
251
+    register mp_digit *tmpx;
252
+
253
+    /* alias for the W[] array */
254
+    _W   = W;
255
+
256
+    /* alias for the digits of  x*/
257
+    tmpx = x->dp;
258
+
259
+    /* copy the digits of a into W[0..a->used-1] */
260
+    for (ix = 0; ix < x->used; ix++) {
261
+      *_W++ = *tmpx++;
262
+    }
263
+
264
+    /* zero the high words of W[a->used..m->used*2] */
265
+    for (; ix < n->used * 2 + 1; ix++) {
266
+      *_W++ = 0;
267
+    }
268
+  }
269
+
270
+  /* now we proceed to zero successive digits
271
+   * from the least significant upwards
272
+   */
273
+  for (ix = 0; ix < n->used; ix++) {
274
+    /* mu = ai * m' mod b
275
+     *
276
+     * We avoid a double precision multiplication (which isn't required)
277
+     * by casting the value down to a mp_digit.  Note this requires
278
+     * that W[ix-1] have  the carry cleared (see after the inner loop)
279
+     */
280
+    register mp_digit mu;
281
+    mu = (mp_digit) (((W[ix] & MP_MASK) * rho) & MP_MASK);
282
+
283
+    /* a = a + mu * m * b**i
284
+     *
285
+     * This is computed in place and on the fly.  The multiplication
286
+     * by b**i is handled by offseting which columns the results
287
+     * are added to.
288
+     *
289
+     * Note the comba method normally doesn't handle carries in the
290
+     * inner loop In this case we fix the carry from the previous
291
+     * column since the Montgomery reduction requires digits of the
292
+     * result (so far) [see above] to work.  This is
293
+     * handled by fixing up one carry after the inner loop.  The
294
+     * carry fixups are done in order so after these loops the
295
+     * first m->used words of W[] have the carries fixed
296
+     */
297
+    {
298
+      register int iy;
299
+      register mp_digit *tmpn;
300
+      register mp_word *_W;
301
+
302
+      /* alias for the digits of the modulus */
303
+      tmpn = n->dp;
304
+
305
+      /* Alias for the columns set by an offset of ix */
306
+      _W = W + ix;
307
+
308
+      /* inner loop */
309
+      for (iy = 0; iy < n->used; iy++) {
310
+          *_W++ += ((mp_word)mu) * ((mp_word)*tmpn++);
311
+      }
312
+    }
313
+
314
+    /* now fix carry for next digit, W[ix+1] */
315
+    W[ix + 1] += W[ix] >> ((mp_word) DIGIT_BIT);
316
+  }
317
+
318
+  /* now we have to propagate the carries and
319
+   * shift the words downward [all those least
320
+   * significant digits we zeroed].
321
+   */
322
+  {
323
+    register mp_digit *tmpx;
324
+    register mp_word *_W, *_W1;
325
+
326
+    /* nox fix rest of carries */
327
+
328
+    /* alias for current word */
329
+    _W1 = W + ix;
330
+
331
+    /* alias for next word, where the carry goes */
332
+    _W = W + ++ix;
333
+
334
+    for (; ix <= n->used * 2 + 1; ix++) {
335
+      *_W++ += *_W1++ >> ((mp_word) DIGIT_BIT);
336
+    }
337
+
338
+    /* copy out, A = A/b**n
339
+     *
340
+     * The result is A/b**n but instead of converting from an
341
+     * array of mp_word to mp_digit than calling mp_rshd
342
+     * we just copy them in the right order
343
+     */
344
+
345
+    /* alias for destination word */
346
+    tmpx = x->dp;
347
+
348
+    /* alias for shifted double precision result */
349
+    _W = W + n->used;
350
+
351
+    for (ix = 0; ix < n->used + 1; ix++) {
352
+      *tmpx++ = (mp_digit)(*_W++ & ((mp_word) MP_MASK));
353
+    }
354
+
355
+    /* zero oldused digits, if the input a was larger than
356
+     * m->used+1 we'll have to clear the digits
357
+     */
358
+    for (; ix < olduse; ix++) {
359
+      *tmpx++ = 0;
360
+    }
361
+  }
362
+
363
+  /* set the max used and clamp */
364
+  x->used = n->used + 1;
365
+  mp_clamp (x);
366
+
367
+  /* if A >= m then A = A - m */
368
+  if (mp_cmp_mag (x, n) != MP_LT) {
369
+    return s_mp_sub (x, n, x);
370
+  }
371
+  return MP_OKAY;
372
+}
373
+#endif
374
+
375
+/* $Source: /cvs/libtom/libtommath/bn_fast_mp_montgomery_reduce.c,v $ */
376
+/* $Revision: 1.3 $ */
377
+/* $Date: 2006/03/31 14:18:44 $ */
378
+
379
+/* End: bn_fast_mp_montgomery_reduce.c */
380
+
381
+/* Start: bn_fast_s_mp_mul_digs.c */
382
+#include <bignum.h>
383
+#ifdef BN_FAST_S_MP_MUL_DIGS_C
384
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
385
+ *
386
+ * LibTomMath is a library that provides multiple-precision
387
+ * integer arithmetic as well as number theoretic functionality.
388
+ *
389
+ * The library was designed directly after the MPI library by
390
+ * Michael Fromberger but has been written from scratch with
391
+ * additional optimizations in place.
392
+ *
393
+ * The library is free for all purposes without any express
394
+ * guarantee it works.
395
+ *
396
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
397
+ */
398
+
399
+/* Fast (comba) multiplier
400
+ *
401
+ * This is the fast column-array [comba] multiplier.  It is 
402
+ * designed to compute the columns of the product first 
403
+ * then handle the carries afterwards.  This has the effect 
404
+ * of making the nested loops that compute the columns very
405
+ * simple and schedulable on super-scalar processors.
406
+ *
407
+ * This has been modified to produce a variable number of 
408
+ * digits of output so if say only a half-product is required 
409
+ * you don't have to compute the upper half (a feature 
410
+ * required for fast Barrett reduction).
411
+ *
412
+ * Based on Algorithm 14.12 on pp.595 of HAC.
413
+ *
414
+ */
415
+int fast_s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
416
+{
417
+  int     olduse, res, pa, ix, iz;
418
+  mp_digit W[MP_WARRAY];
419
+  register mp_word  _W;
420
+
421
+  /* grow the destination as required */
422
+  if (c->alloc < digs) {
423
+    if ((res = mp_grow (c, digs)) != MP_OKAY) {
424
+      return res;
425
+    }
426
+  }
427
+
428
+  /* number of output digits to produce */
429
+  pa = MIN(digs, a->used + b->used);
430
+
431
+  /* clear the carry */
432
+  _W = 0;
433
+  for (ix = 0; ix < pa; ix++) { 
434
+      int      tx, ty;
435
+      int      iy;
436
+      mp_digit *tmpx, *tmpy;
437
+
438
+      /* get offsets into the two bignums */
439
+      ty = MIN(b->used-1, ix);
440
+      tx = ix - ty;
441
+
442
+      /* setup temp aliases */
443
+      tmpx = a->dp + tx;
444
+      tmpy = b->dp + ty;
445
+
446
+      /* this is the number of times the loop will iterrate, essentially 
447
+         while (tx++ < a->used && ty-- >= 0) { ... }
448
+       */
449
+      iy = MIN(a->used-tx, ty+1);
450
+
451
+      /* execute loop */
452
+      for (iz = 0; iz < iy; ++iz) {
453
+         _W += ((mp_word)*tmpx++)*((mp_word)*tmpy--);
454
+
455
+      }
456
+
457
+      /* store term */
458
+      W[ix] = ((mp_digit)_W) & MP_MASK;
459
+
460
+      /* make next carry */
461
+      _W = _W >> ((mp_word)DIGIT_BIT);
462
+ }
463
+
464
+  /* setup dest */
465
+  olduse  = c->used;
466
+  c->used = pa;
467
+
468
+  {
469
+    register mp_digit *tmpc;
470
+    tmpc = c->dp;
471
+    for (ix = 0; ix < pa+1; ix++) {
472
+      /* now extract the previous digit [below the carry] */
473
+      *tmpc++ = W[ix];
474
+    }
475
+
476
+    /* clear unused digits [that existed in the old copy of c] */
477
+    for (; ix < olduse; ix++) {
478
+      *tmpc++ = 0;
479
+    }
480
+  }
481
+  mp_clamp (c);
482
+  return MP_OKAY;
483
+}
484
+#endif
485
+
486
+/* $Source: /cvs/libtom/libtommath/bn_fast_s_mp_mul_digs.c,v $ */
487
+/* $Revision: 1.7 $ */
488
+/* $Date: 2006/03/31 14:18:44 $ */
489
+
490
+/* End: bn_fast_s_mp_mul_digs.c */
491
+
492
+/* Start: bn_fast_s_mp_mul_high_digs.c */
493
+#include <bignum.h>
494
+#ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C
495
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
496
+ *
497
+ * LibTomMath is a library that provides multiple-precision
498
+ * integer arithmetic as well as number theoretic functionality.
499
+ *
500
+ * The library was designed directly after the MPI library by
501
+ * Michael Fromberger but has been written from scratch with
502
+ * additional optimizations in place.
503
+ *
504
+ * The library is free for all purposes without any express
505
+ * guarantee it works.
506
+ *
507
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
508
+ */
509
+
510
+/* this is a modified version of fast_s_mul_digs that only produces
511
+ * output digits *above* digs.  See the comments for fast_s_mul_digs
512
+ * to see how it works.
513
+ *
514
+ * This is used in the Barrett reduction since for one of the multiplications
515
+ * only the higher digits were needed.  This essentially halves the work.
516
+ *
517
+ * Based on Algorithm 14.12 on pp.595 of HAC.
518
+ */
519
+int fast_s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
520
+{
521
+  int     olduse, res, pa, ix, iz;
522
+  mp_digit W[MP_WARRAY];
523
+  mp_word  _W;
524
+
525
+  /* grow the destination as required */
526
+  pa = a->used + b->used;
527
+  if (c->alloc < pa) {
528
+    if ((res = mp_grow (c, pa)) != MP_OKAY) {
529
+      return res;
530
+    }
531
+  }
532
+
533
+  /* number of output digits to produce */
534
+  pa = a->used + b->used;
535
+  _W = 0;
536
+  for (ix = digs; ix < pa; ix++) { 
537
+      int      tx, ty, iy;
538
+      mp_digit *tmpx, *tmpy;
539
+
540
+      /* get offsets into the two bignums */
541
+      ty = MIN(b->used-1, ix);
542
+      tx = ix - ty;
543
+
544
+      /* setup temp aliases */
545
+      tmpx = a->dp + tx;
546
+      tmpy = b->dp + ty;
547
+
548
+      /* this is the number of times the loop will iterrate, essentially its 
549
+         while (tx++ < a->used && ty-- >= 0) { ... }
550
+       */
551
+      iy = MIN(a->used-tx, ty+1);
552
+
553
+      /* execute loop */
554
+      for (iz = 0; iz < iy; iz++) {
555
+         _W += ((mp_word)*tmpx++)*((mp_word)*tmpy--);
556
+      }
557
+
558
+      /* store term */
559
+      W[ix] = ((mp_digit)_W) & MP_MASK;
560
+
561
+      /* make next carry */
562
+      _W = _W >> ((mp_word)DIGIT_BIT);
563
+  }
564
+  
565
+  /* setup dest */
566
+  olduse  = c->used;
567
+  c->used = pa;
568
+
569
+  {
570
+    register mp_digit *tmpc;
571
+
572
+    tmpc = c->dp + digs;
573
+    for (ix = digs; ix <= pa; ix++) {
574
+      /* now extract the previous digit [below the carry] */
575
+      *tmpc++ = W[ix];
576
+    }
577
+
578
+    /* clear unused digits [that existed in the old copy of c] */
579
+    for (; ix < olduse; ix++) {
580
+      *tmpc++ = 0;
581
+    }
582
+  }
583
+  mp_clamp (c);
584
+  return MP_OKAY;
585
+}
586
+#endif
587
+
588
+/* $Source: /cvs/libtom/libtommath/bn_fast_s_mp_mul_high_digs.c,v $ */
589
+/* $Revision: 1.4 $ */
590
+/* $Date: 2006/03/31 14:18:44 $ */
591
+
592
+/* End: bn_fast_s_mp_mul_high_digs.c */
593
+
594
+/* Start: bn_fast_s_mp_sqr.c */
595
+#include <bignum.h>
596
+#ifdef BN_FAST_S_MP_SQR_C
597
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
598
+ *
599
+ * LibTomMath is a library that provides multiple-precision
600
+ * integer arithmetic as well as number theoretic functionality.
601
+ *
602
+ * The library was designed directly after the MPI library by
603
+ * Michael Fromberger but has been written from scratch with
604
+ * additional optimizations in place.
605
+ *
606
+ * The library is free for all purposes without any express
607
+ * guarantee it works.
608
+ *
609
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
610
+ */
611
+
612
+/* the jist of squaring...
613
+ * you do like mult except the offset of the tmpx [one that 
614
+ * starts closer to zero] can't equal the offset of tmpy.  
615
+ * So basically you set up iy like before then you min it with
616
+ * (ty-tx) so that it never happens.  You double all those 
617
+ * you add in the inner loop
618
+
619
+After that loop you do the squares and add them in.
620
+*/
621
+
622
+int fast_s_mp_sqr (mp_int * a, mp_int * b)
623
+{
624
+  int       olduse, res, pa, ix, iz;
625
+  mp_digit   W[MP_WARRAY], *tmpx;
626
+  mp_word   W1;
627
+
628
+  /* grow the destination as required */
629
+  pa = a->used + a->used;
630
+  if (b->alloc < pa) {
631
+    if ((res = mp_grow (b, pa)) != MP_OKAY) {
632
+      return res;
633
+    }
634
+  }
635
+
636
+  /* number of output digits to produce */
637
+  W1 = 0;
638
+  for (ix = 0; ix < pa; ix++) { 
639
+      int      tx, ty, iy;
640
+      mp_word  _W;
641
+      mp_digit *tmpy;
642
+
643
+      /* clear counter */
644
+      _W = 0;
645
+
646
+      /* get offsets into the two bignums */
647
+      ty = MIN(a->used-1, ix);
648
+      tx = ix - ty;
649
+
650
+      /* setup temp aliases */
651
+      tmpx = a->dp + tx;
652
+      tmpy = a->dp + ty;
653
+
654
+      /* this is the number of times the loop will iterrate, essentially
655
+         while (tx++ < a->used && ty-- >= 0) { ... }
656
+       */
657
+      iy = MIN(a->used-tx, ty+1);
658
+
659
+      /* now for squaring tx can never equal ty 
660
+       * we halve the distance since they approach at a rate of 2x
661
+       * and we have to round because odd cases need to be executed
662
+       */
663
+      iy = MIN(iy, (ty-tx+1)>>1);
664
+
665
+      /* execute loop */
666
+      for (iz = 0; iz < iy; iz++) {
667
+         _W += ((mp_word)*tmpx++)*((mp_word)*tmpy--);
668
+      }
669
+
670
+      /* double the inner product and add carry */
671
+      _W = _W + _W + W1;
672
+
673
+      /* even columns have the square term in them */
674
+      if ((ix&1) == 0) {
675
+         _W += ((mp_word)a->dp[ix>>1])*((mp_word)a->dp[ix>>1]);
676
+      }
677
+
678
+      /* store it */
679
+      W[ix] = (mp_digit)(_W & MP_MASK);
680
+
681
+      /* make next carry */
682
+      W1 = _W >> ((mp_word)DIGIT_BIT);
683
+  }
684
+
685
+  /* setup dest */
686
+  olduse  = b->used;
687
+  b->used = a->used+a->used;
688
+
689
+  {
690
+    mp_digit *tmpb;
691
+    tmpb = b->dp;
692
+    for (ix = 0; ix < pa; ix++) {
693
+      *tmpb++ = W[ix] & MP_MASK;
694
+    }
695
+
696
+    /* clear unused digits [that existed in the old copy of c] */
697
+    for (; ix < olduse; ix++) {
698
+      *tmpb++ = 0;
699
+    }
700
+  }
701
+  mp_clamp (b);
702
+  return MP_OKAY;
703
+}
704
+#endif
705
+
706
+/* $Source: /cvs/libtom/libtommath/bn_fast_s_mp_sqr.c,v $ */
707
+/* $Revision: 1.3 $ */
708
+/* $Date: 2006/03/31 14:18:44 $ */
709
+
710
+/* End: bn_fast_s_mp_sqr.c */
711
+
712
+/* Start: bn_mp_2expt.c */
713
+#include <bignum.h>
714
+#ifdef BN_MP_2EXPT_C
715
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
716
+ *
717
+ * LibTomMath is a library that provides multiple-precision
718
+ * integer arithmetic as well as number theoretic functionality.
719
+ *
720
+ * The library was designed directly after the MPI library by
721
+ * Michael Fromberger but has been written from scratch with
722
+ * additional optimizations in place.
723
+ *
724
+ * The library is free for all purposes without any express
725
+ * guarantee it works.
726
+ *
727
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
728
+ */
729
+
730
+/* computes a = 2**b 
731
+ *
732
+ * Simple algorithm which zeroes the int, grows it then just sets one bit
733
+ * as required.
734
+ */
735
+int
736
+mp_2expt (mp_int * a, int b)
737
+{
738
+  int     res;
739
+
740
+  /* zero a as per default */
741
+  mp_zero (a);
742
+
743
+  /* grow a to accomodate the single bit */
744
+  if ((res = mp_grow (a, b / DIGIT_BIT + 1)) != MP_OKAY) {
745
+    return res;
746
+  }
747
+
748
+  /* set the used count of where the bit will go */
749
+  a->used = b / DIGIT_BIT + 1;
750
+
751
+  /* put the single bit in its place */
752
+  a->dp[b / DIGIT_BIT] = ((mp_digit)1) << (b % DIGIT_BIT);
753
+
754
+  return MP_OKAY;
755
+}
756
+#endif
757
+
758
+/* $Source: /cvs/libtom/libtommath/bn_mp_2expt.c,v $ */
759
+/* $Revision: 1.3 $ */
760
+/* $Date: 2006/03/31 14:18:44 $ */
761
+
762
+/* End: bn_mp_2expt.c */
763
+
764
+/* Start: bn_mp_abs.c */
765
+#include <bignum.h>
766
+#ifdef BN_MP_ABS_C
767
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
768
+ *
769
+ * LibTomMath is a library that provides multiple-precision
770
+ * integer arithmetic as well as number theoretic functionality.
771
+ *
772
+ * The library was designed directly after the MPI library by
773
+ * Michael Fromberger but has been written from scratch with
774
+ * additional optimizations in place.
775
+ *
776
+ * The library is free for all purposes without any express
777
+ * guarantee it works.
778
+ *
779
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
780
+ */
781
+
782
+/* b = |a| 
783
+ *
784
+ * Simple function copies the input and fixes the sign to positive
785
+ */
786
+int
787
+mp_abs (mp_int * a, mp_int * b)
788
+{
789
+  int     res;
790
+
791
+  /* copy a to b */
792
+  if (a != b) {
793
+     if ((res = mp_copy (a, b)) != MP_OKAY) {
794
+       return res;
795
+     }
796
+  }
797
+
798
+  /* force the sign of b to positive */
799
+  b->sign = MP_ZPOS;
800
+
801
+  return MP_OKAY;
802
+}
803
+#endif
804
+
805
+/* $Source: /cvs/libtom/libtommath/bn_mp_abs.c,v $ */
806
+/* $Revision: 1.3 $ */
807
+/* $Date: 2006/03/31 14:18:44 $ */
808
+
809
+/* End: bn_mp_abs.c */
810
+
811
+/* Start: bn_mp_add.c */
812
+#include <bignum.h>
813
+#ifdef BN_MP_ADD_C
814
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
815
+ *
816
+ * LibTomMath is a library that provides multiple-precision
817
+ * integer arithmetic as well as number theoretic functionality.
818
+ *
819
+ * The library was designed directly after the MPI library by
820
+ * Michael Fromberger but has been written from scratch with
821
+ * additional optimizations in place.
822
+ *
823
+ * The library is free for all purposes without any express
824
+ * guarantee it works.
825
+ *
826
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
827
+ */
828
+
829
+/* high level addition (handles signs) */
830
+int mp_add (mp_int * a, mp_int * b, mp_int * c)
831
+{
832
+  int     sa, sb, res;
833
+
834
+  /* get sign of both inputs */
835
+  sa = a->sign;
836
+  sb = b->sign;
837
+
838
+  /* handle two cases, not four */
839
+  if (sa == sb) {
840
+    /* both positive or both negative */
841
+    /* add their magnitudes, copy the sign */
842
+    c->sign = sa;
843
+    res = s_mp_add (a, b, c);
844
+  } else {
845
+    /* one positive, the other negative */
846
+    /* subtract the one with the greater magnitude from */
847
+    /* the one of the lesser magnitude.  The result gets */
848
+    /* the sign of the one with the greater magnitude. */
849
+    if (mp_cmp_mag (a, b) == MP_LT) {
850
+      c->sign = sb;
851
+      res = s_mp_sub (b, a, c);
852
+    } else {
853
+      c->sign = sa;
854
+      res = s_mp_sub (a, b, c);
855
+    }
856
+  }
857
+  return res;
858
+}
859
+
860
+#endif
861
+
862
+/* $Source: /cvs/libtom/libtommath/bn_mp_add.c,v $ */
863
+/* $Revision: 1.3 $ */
864
+/* $Date: 2006/03/31 14:18:44 $ */
865
+
866
+/* End: bn_mp_add.c */
867
+
868
+/* Start: bn_mp_add_d.c */
869
+#include <bignum.h>
870
+#ifdef BN_MP_ADD_D_C
871
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
872
+ *
873
+ * LibTomMath is a library that provides multiple-precision
874
+ * integer arithmetic as well as number theoretic functionality.
875
+ *
876
+ * The library was designed directly after the MPI library by
877
+ * Michael Fromberger but has been written from scratch with
878
+ * additional optimizations in place.
879
+ *
880
+ * The library is free for all purposes without any express
881
+ * guarantee it works.
882
+ *
883
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
884
+ */
885
+
886
+/* single digit addition */
887
+int
888
+mp_add_d (mp_int * a, mp_digit b, mp_int * c)
889
+{
890
+  int     res, ix, oldused;
891
+  mp_digit *tmpa, *tmpc, mu;
892
+
893
+  /* grow c as required */
894
+  if (c->alloc < a->used + 1) {
895
+     if ((res = mp_grow(c, a->used + 1)) != MP_OKAY) {
896
+        return res;
897
+     }
898
+  }
899
+
900
+  /* if a is negative and |a| >= b, call c = |a| - b */
901
+  if (a->sign == MP_NEG && (a->used > 1 || a->dp[0] >= b)) {
902
+     /* temporarily fix sign of a */
903
+     a->sign = MP_ZPOS;
904
+
905
+     /* c = |a| - b */
906
+     res = mp_sub_d(a, b, c);
907
+
908
+     /* fix sign  */
909
+     a->sign = c->sign = MP_NEG;
910
+
911
+     /* clamp */
912
+     mp_clamp(c);
913
+
914
+     return res;
915
+  }
916
+
917
+  /* old number of used digits in c */
918
+  oldused = c->used;
919
+
920
+  /* sign always positive */
921
+  c->sign = MP_ZPOS;
922
+
923
+  /* source alias */
924
+  tmpa    = a->dp;
925
+
926
+  /* destination alias */
927
+  tmpc    = c->dp;
928
+
929
+  /* if a is positive */
930
+  if (a->sign == MP_ZPOS) {
931
+     /* add digit, after this we're propagating
932
+      * the carry.
933
+      */
934
+     *tmpc   = *tmpa++ + b;
935
+     mu      = *tmpc >> DIGIT_BIT;
936
+     *tmpc++ &= MP_MASK;
937
+
938
+     /* now handle rest of the digits */
939
+     for (ix = 1; ix < a->used; ix++) {
940
+        *tmpc   = *tmpa++ + mu;
941
+        mu      = *tmpc >> DIGIT_BIT;
942
+        *tmpc++ &= MP_MASK;
943
+     }
944
+     /* set final carry */
945
+     ix++;
946
+     *tmpc++  = mu;
947
+
948
+     /* setup size */
949
+     c->used = a->used + 1;
950
+  } else {
951
+     /* a was negative and |a| < b */
952
+     c->used  = 1;
953
+
954
+     /* the result is a single digit */
955
+     if (a->used == 1) {
956
+        *tmpc++  =  b - a->dp[0];
957
+     } else {
958
+        *tmpc++  =  b;
959
+     }
960
+
961
+     /* setup count so the clearing of oldused
962
+      * can fall through correctly
963
+      */
964
+     ix       = 1;
965
+  }
966
+
967
+  /* now zero to oldused */
968
+  while (ix++ < oldused) {
969
+     *tmpc++ = 0;
970
+  }
971
+  mp_clamp(c);
972
+
973
+  return MP_OKAY;
974
+}
975
+
976
+#endif
977
+
978
+/* $Source: /cvs/libtom/libtommath/bn_mp_add_d.c,v $ */
979
+/* $Revision: 1.4 $ */
980
+/* $Date: 2006/03/31 14:18:44 $ */
981
+
982
+/* End: bn_mp_add_d.c */
983
+
984
+/* Start: bn_mp_addmod.c */
985
+#include <bignum.h>
986
+#ifdef BN_MP_ADDMOD_C
987
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
988
+ *
989
+ * LibTomMath is a library that provides multiple-precision
990
+ * integer arithmetic as well as number theoretic functionality.
991
+ *
992
+ * The library was designed directly after the MPI library by
993
+ * Michael Fromberger but has been written from scratch with
994
+ * additional optimizations in place.
995
+ *
996
+ * The library is free for all purposes without any express
997
+ * guarantee it works.
998
+ *
999
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1000
+ */
1001
+
1002
+/* d = a + b (mod c) */
1003
+int
1004
+mp_addmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
1005
+{
1006
+  int     res;
1007
+  mp_int  t;
1008
+
1009
+  if ((res = mp_init (&t)) != MP_OKAY) {
1010
+    return res;
1011
+  }
1012
+
1013
+  if ((res = mp_add (a, b, &t)) != MP_OKAY) {
1014
+    mp_clear (&t);
1015
+    return res;
1016
+  }
1017
+  res = mp_mod (&t, c, d);
1018
+  mp_clear (&t);
1019
+  return res;
1020
+}
1021
+#endif
1022
+
1023
+/* $Source: /cvs/libtom/libtommath/bn_mp_addmod.c,v $ */
1024
+/* $Revision: 1.3 $ */
1025
+/* $Date: 2006/03/31 14:18:44 $ */
1026
+
1027
+/* End: bn_mp_addmod.c */
1028
+
1029
+/* Start: bn_mp_and.c */
1030
+#include <bignum.h>
1031
+#ifdef BN_MP_AND_C
1032
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
1033
+ *
1034
+ * LibTomMath is a library that provides multiple-precision
1035
+ * integer arithmetic as well as number theoretic functionality.
1036
+ *
1037
+ * The library was designed directly after the MPI library by
1038
+ * Michael Fromberger but has been written from scratch with
1039
+ * additional optimizations in place.
1040
+ *
1041
+ * The library is free for all purposes without any express
1042
+ * guarantee it works.
1043
+ *
1044
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1045
+ */
1046
+
1047
+/* AND two ints together */
1048
+int
1049
+mp_and (mp_int * a, mp_int * b, mp_int * c)
1050
+{
1051
+  int     res, ix, px;
1052
+  mp_int  t, *x;
1053
+
1054
+  if (a->used > b->used) {
1055
+    if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
1056
+      return res;
1057
+    }
1058
+    px = b->used;
1059
+    x = b;
1060
+  } else {
1061
+    if ((res = mp_init_copy (&t, b)) != MP_OKAY) {
1062
+      return res;
1063
+    }
1064
+    px = a->used;
1065
+    x = a;
1066
+  }
1067
+
1068
+  for (ix = 0; ix < px; ix++) {
1069
+    t.dp[ix] &= x->dp[ix];
1070
+  }
1071
+
1072
+  /* zero digits above the last from the smallest mp_int */
1073
+  for (; ix < t.used; ix++) {
1074
+    t.dp[ix] = 0;
1075
+  }
1076
+
1077
+  mp_clamp (&t);
1078
+  mp_exch (c, &t);
1079
+  mp_clear (&t);
1080
+  return MP_OKAY;
1081
+}
1082
+#endif
1083
+
1084
+/* $Source: /cvs/libtom/libtommath/bn_mp_and.c,v $ */
1085
+/* $Revision: 1.3 $ */
1086
+/* $Date: 2006/03/31 14:18:44 $ */
1087
+
1088
+/* End: bn_mp_and.c */
1089
+
1090
+/* Start: bn_mp_clamp.c */
1091
+#include <bignum.h>
1092
+#ifdef BN_MP_CLAMP_C
1093
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
1094
+ *
1095
+ * LibTomMath is a library that provides multiple-precision
1096
+ * integer arithmetic as well as number theoretic functionality.
1097
+ *
1098
+ * The library was designed directly after the MPI library by
1099
+ * Michael Fromberger but has been written from scratch with
1100
+ * additional optimizations in place.
1101
+ *
1102
+ * The library is free for all purposes without any express
1103
+ * guarantee it works.
1104
+ *
1105
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1106
+ */
1107
+
1108
+/* trim unused digits 
1109
+ *
1110
+ * This is used to ensure that leading zero digits are
1111
+ * trimed and the leading "used" digit will be non-zero
1112
+ * Typically very fast.  Also fixes the sign if there
1113
+ * are no more leading digits
1114
+ */
1115
+void
1116
+mp_clamp (mp_int * a)
1117
+{
1118
+  /* decrease used while the most significant digit is
1119
+   * zero.
1120
+   */
1121
+  while (a->used > 0 && a->dp[a->used - 1] == 0) {
1122
+    --(a->used);
1123
+  }
1124
+
1125
+  /* reset the sign flag if used == 0 */
1126
+  if (a->used == 0) {
1127
+    a->sign = MP_ZPOS;
1128
+  }
1129
+}
1130
+#endif
1131
+
1132
+/* $Source: /cvs/libtom/libtommath/bn_mp_clamp.c,v $ */
1133
+/* $Revision: 1.3 $ */
1134
+/* $Date: 2006/03/31 14:18:44 $ */
1135
+
1136
+/* End: bn_mp_clamp.c */
1137
+
1138
+/* Start: bn_mp_clear.c */
1139
+#include <bignum.h>
1140
+#ifdef BN_MP_CLEAR_C
1141
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
1142
+ *
1143
+ * LibTomMath is a library that provides multiple-precision
1144
+ * integer arithmetic as well as number theoretic functionality.
1145
+ *
1146
+ * The library was designed directly after the MPI library by
1147
+ * Michael Fromberger but has been written from scratch with
1148
+ * additional optimizations in place.
1149
+ *
1150
+ * The library is free for all purposes without any express
1151
+ * guarantee it works.
1152
+ *
1153
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1154
+ */
1155
+
1156
+/* clear one (frees)  */
1157
+void
1158
+mp_clear (mp_int * a)
1159
+{
1160
+  int i;
1161
+
1162
+  /* only do anything if a hasn't been freed previously */
1163
+  if (a->dp != NULL) {
1164
+    /* first zero the digits */
1165
+    for (i = 0; i < a->used; i++) {
1166
+        a->dp[i] = 0;
1167
+    }
1168
+
1169
+    /* free ram */
1170
+    free(a->dp);
1171
+
1172
+    /* reset members to make debugging easier */
1173
+    a->dp    = NULL;
1174
+    a->alloc = a->used = 0;
1175
+    a->sign  = MP_ZPOS;
1176
+  }
1177
+}
1178
+#endif
1179
+
1180
+/* $Source: /cvs/libtom/libtommath/bn_mp_clear.c,v $ */
1181
+/* $Revision: 1.3 $ */
1182
+/* $Date: 2006/03/31 14:18:44 $ */
1183
+
1184
+/* End: bn_mp_clear.c */
1185
+
1186
+/* Start: bn_mp_clear_multi.c */
1187
+#include <bignum.h>
1188
+#ifdef BN_MP_CLEAR_MULTI_C
1189
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
1190
+ *
1191
+ * LibTomMath is a library that provides multiple-precision
1192
+ * integer arithmetic as well as number theoretic functionality.
1193
+ *
1194
+ * The library was designed directly after the MPI library by
1195
+ * Michael Fromberger but has been written from scratch with
1196
+ * additional optimizations in place.
1197
+ *
1198
+ * The library is free for all purposes without any express
1199
+ * guarantee it works.
1200
+ *
1201
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1202
+ */
1203
+#include <stdarg.h>
1204
+
1205
+void mp_clear_multi(mp_int *mp, ...) 
1206
+{
1207
+    mp_int* next_mp = mp;
1208
+    va_list args;
1209
+    va_start(args, mp);
1210
+    while (next_mp != NULL) {
1211
+        mp_clear(next_mp);
1212
+        next_mp = va_arg(args, mp_int*);
1213
+    }
1214
+    va_end(args);
1215
+}
1216
+#endif
1217
+
1218
+/* $Source: /cvs/libtom/libtommath/bn_mp_clear_multi.c,v $ */
1219
+/* $Revision: 1.3 $ */
1220
+/* $Date: 2006/03/31 14:18:44 $ */
1221
+
1222
+/* End: bn_mp_clear_multi.c */
1223
+
1224
+/* Start: bn_mp_cmp.c */
1225
+#include <bignum.h>
1226
+#ifdef BN_MP_CMP_C
1227
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
1228
+ *
1229
+ * LibTomMath is a library that provides multiple-precision
1230
+ * integer arithmetic as well as number theoretic functionality.
1231
+ *
1232
+ * The library was designed directly after the MPI library by
1233
+ * Michael Fromberger but has been written from scratch with
1234
+ * additional optimizations in place.
1235
+ *
1236
+ * The library is free for all purposes without any express
1237
+ * guarantee it works.
1238
+ *
1239
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1240
+ */
1241
+
1242
+/* compare two ints (signed)*/
1243
+int
1244
+mp_cmp (mp_int * a, mp_int * b)
1245
+{
1246
+  /* compare based on sign */
1247
+  if (a->sign != b->sign) {
1248
+     if (a->sign == MP_NEG) {
1249
+        return MP_LT;
1250
+     } else {
1251
+        return MP_GT;
1252
+     }
1253
+  }
1254
+  
1255
+  /* compare digits */
1256
+  if (a->sign == MP_NEG) {
1257
+     /* if negative compare opposite direction */
1258
+     return mp_cmp_mag(b, a);
1259
+  } else {
1260
+     return mp_cmp_mag(a, b);
1261
+  }
1262
+}
1263
+#endif
1264
+
1265
+/* $Source: /cvs/libtom/libtommath/bn_mp_cmp.c,v $ */
1266
+/* $Revision: 1.3 $ */
1267
+/* $Date: 2006/03/31 14:18:44 $ */
1268
+
1269
+/* End: bn_mp_cmp.c */
1270
+
1271
+/* Start: bn_mp_cmp_d.c */
1272
+#include <bignum.h>
1273
+#ifdef BN_MP_CMP_D_C
1274
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
1275
+ *
1276
+ * LibTomMath is a library that provides multiple-precision
1277
+ * integer arithmetic as well as number theoretic functionality.
1278
+ *
1279
+ * The library was designed directly after the MPI library by
1280
+ * Michael Fromberger but has been written from scratch with
1281
+ * additional optimizations in place.
1282
+ *
1283
+ * The library is free for all purposes without any express
1284
+ * guarantee it works.
1285
+ *
1286
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1287
+ */
1288
+
1289
+/* compare a digit */
1290
+int mp_cmp_d(mp_int * a, mp_digit b)
1291
+{
1292
+  /* compare based on sign */
1293
+  if (a->sign == MP_NEG) {
1294
+    return MP_LT;
1295
+  }
1296
+
1297
+  /* compare based on magnitude */
1298
+  if (a->used > 1) {
1299
+    return MP_GT;
1300
+  }
1301
+
1302
+  /* compare the only digit of a to b */
1303
+  if (a->dp[0] > b) {
1304
+    return MP_GT;
1305
+  } else if (a->dp[0] < b) {
1306
+    return MP_LT;
1307
+  } else {
1308
+    return MP_EQ;
1309
+  }
1310
+}
1311
+#endif
1312
+
1313
+/* $Source: /cvs/libtom/libtommath/bn_mp_cmp_d.c,v $ */
1314
+/* $Revision: 1.3 $ */
1315
+/* $Date: 2006/03/31 14:18:44 $ */
1316
+
1317
+/* End: bn_mp_cmp_d.c */
1318
+
1319
+/* Start: bn_mp_cmp_mag.c */
1320
+#include <bignum.h>
1321
+#ifdef BN_MP_CMP_MAG_C
1322
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
1323
+ *
1324
+ * LibTomMath is a library that provides multiple-precision
1325
+ * integer arithmetic as well as number theoretic functionality.
1326
+ *
1327
+ * The library was designed directly after the MPI library by
1328
+ * Michael Fromberger but has been written from scratch with
1329
+ * additional optimizations in place.
1330
+ *
1331
+ * The library is free for all purposes without any express
1332
+ * guarantee it works.
1333
+ *
1334
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1335
+ */
1336
+
1337
+/* compare maginitude of two ints (unsigned) */
1338
+int mp_cmp_mag (mp_int * a, mp_int * b)
1339
+{
1340
+  int     n;
1341
+  mp_digit *tmpa, *tmpb;
1342
+
1343
+  /* compare based on # of non-zero digits */
1344
+  if (a->used > b->used) {
1345
+    return MP_GT;
1346
+  }
1347
+  
1348
+  if (a->used < b->used) {
1349
+    return MP_LT;
1350
+  }
1351
+
1352
+  /* alias for a */
1353
+  tmpa = a->dp + (a->used - 1);
1354
+
1355
+  /* alias for b */
1356
+  tmpb = b->dp + (a->used - 1);
1357
+
1358
+  /* compare based on digits  */
1359
+  for (n = 0; n < a->used; ++n, --tmpa, --tmpb) {
1360
+    if (*tmpa > *tmpb) {
1361
+      return MP_GT;
1362
+    }
1363
+
1364
+    if (*tmpa < *tmpb) {
1365
+      return MP_LT;
1366
+    }
1367
+  }
1368
+  return MP_EQ;
1369
+}
1370
+#endif
1371
+
1372
+/* $Source: /cvs/libtom/libtommath/bn_mp_cmp_mag.c,v $ */
1373
+/* $Revision: 1.3 $ */
1374
+/* $Date: 2006/03/31 14:18:44 $ */
1375
+
1376
+/* End: bn_mp_cmp_mag.c */
1377
+
1378
+/* Start: bn_mp_cnt_lsb.c */
1379
+#include <bignum.h>
1380
+#ifdef BN_MP_CNT_LSB_C
1381
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
1382
+ *
1383
+ * LibTomMath is a library that provides multiple-precision
1384
+ * integer arithmetic as well as number theoretic functionality.
1385
+ *
1386
+ * The library was designed directly after the MPI library by
1387
+ * Michael Fromberger but has been written from scratch with
1388
+ * additional optimizations in place.
1389
+ *
1390
+ * The library is free for all purposes without any express
1391
+ * guarantee it works.
1392
+ *
1393
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1394
+ */
1395
+
1396
+static const int lnz[16] = { 
1397
+   4, 0, 1, 0, 2, 0, 1, 0, 3, 0, 1, 0, 2, 0, 1, 0
1398
+};
1399
+
1400
+/* Counts the number of lsbs which are zero before the first zero bit */
1401
+int mp_cnt_lsb(mp_int *a)
1402
+{
1403
+   int x;
1404
+   mp_digit q, qq;
1405
+
1406
+   /* easy out */
1407
+   if (mp_iszero(a) == 1) {
1408
+      return 0;
1409
+   }
1410
+
1411
+   /* scan lower digits until non-zero */
1412
+   for (x = 0; x < a->used && a->dp[x] == 0; x++);
1413
+   q = a->dp[x];
1414
+   x *= DIGIT_BIT;
1415
+
1416
+   /* now scan this digit until a 1 is found */
1417
+   if ((q & 1) == 0) {
1418
+      do {
1419
+         qq  = q & 15;
1420
+         x  += lnz[qq];
1421
+         q >>= 4;
1422
+      } while (qq == 0);
1423
+   }
1424
+   return x;
1425
+}
1426
+
1427
+#endif
1428
+
1429
+/* $Source: /cvs/libtom/libtommath/bn_mp_cnt_lsb.c,v $ */
1430
+/* $Revision: 1.3 $ */
1431
+/* $Date: 2006/03/31 14:18:44 $ */
1432
+
1433
+/* End: bn_mp_cnt_lsb.c */
1434
+
1435
+/* Start: bn_mp_copy.c */
1436
+#include <bignum.h>
1437
+#ifdef BN_MP_COPY_C
1438
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
1439
+ *
1440
+ * LibTomMath is a library that provides multiple-precision
1441
+ * integer arithmetic as well as number theoretic functionality.
1442
+ *
1443
+ * The library was designed directly after the MPI library by
1444
+ * Michael Fromberger but has been written from scratch with
1445
+ * additional optimizations in place.
1446
+ *
1447
+ * The library is free for all purposes without any express
1448
+ * guarantee it works.
1449
+ *
1450
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1451
+ */
1452
+
1453
+/* copy, b = a */
1454
+int
1455
+mp_copy (mp_int * a, mp_int * b)
1456
+{
1457
+  int     res, n;
1458
+
1459
+  /* if dst == src do nothing */
1460
+  if (a == b) {
1461
+    return MP_OKAY;
1462
+  }
1463
+
1464
+  /* grow dest */
1465
+  if (b->alloc < a->used) {
1466
+     if ((res = mp_grow (b, a->used)) != MP_OKAY) {
1467
+        return res;
1468
+     }
1469
+  }
1470
+
1471
+  /* zero b and copy the parameters over */
1472
+  {
1473
+    register mp_digit *tmpa, *tmpb;
1474
+
1475
+    /* pointer aliases */
1476
+
1477
+    /* source */
1478
+    tmpa = a->dp;
1479
+
1480
+    /* destination */
1481
+    tmpb = b->dp;
1482
+
1483
+    /* copy all the digits */
1484
+    for (n = 0; n < a->used; n++) {
1485
+      *tmpb++ = *tmpa++;
1486
+    }
1487
+
1488
+    /* clear high digits */
1489
+    for (; n < b->used; n++) {
1490
+      *tmpb++ = 0;
1491
+    }
1492
+  }
1493
+
1494
+  /* copy used count and sign */
1495
+  b->used = a->used;
1496
+  b->sign = a->sign;
1497
+  return MP_OKAY;
1498
+}
1499
+#endif
1500
+
1501
+/* $Source: /cvs/libtom/libtommath/bn_mp_copy.c,v $ */
1502
+/* $Revision: 1.3 $ */
1503
+/* $Date: 2006/03/31 14:18:44 $ */
1504
+
1505
+/* End: bn_mp_copy.c */
1506
+
1507
+/* Start: bn_mp_count_bits.c */
1508
+#include <bignum.h>
1509
+#ifdef BN_MP_COUNT_BITS_C
1510
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
1511
+ *
1512
+ * LibTomMath is a library that provides multiple-precision
1513
+ * integer arithmetic as well as number theoretic functionality.
1514
+ *
1515
+ * The library was designed directly after the MPI library by
1516
+ * Michael Fromberger but has been written from scratch with
1517
+ * additional optimizations in place.
1518
+ *
1519
+ * The library is free for all purposes without any express
1520
+ * guarantee it works.
1521
+ *
1522
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1523
+ */
1524
+
1525
+/* returns the number of bits in an int */
1526
+int
1527
+mp_count_bits (mp_int * a)
1528
+{
1529
+  int     r;
1530
+  mp_digit q;
1531
+
1532
+  /* shortcut */
1533
+  if (a->used == 0) {
1534
+    return 0;
1535
+  }
1536
+
1537
+  /* get number of digits and add that */
1538
+  r = (a->used - 1) * DIGIT_BIT;
1539
+  
1540
+  /* take the last digit and count the bits in it */
1541
+  q = a->dp[a->used - 1];
1542
+  while (q > ((mp_digit) 0)) {
1543
+    ++r;
1544
+    q >>= ((mp_digit) 1);
1545
+  }
1546
+  return r;
1547
+}
1548
+#endif
1549
+
1550
+/* $Source: /cvs/libtom/libtommath/bn_mp_count_bits.c,v $ */
1551
+/* $Revision: 1.3 $ */
1552
+/* $Date: 2006/03/31 14:18:44 $ */
1553
+
1554
+/* End: bn_mp_count_bits.c */
1555
+
1556
+/* Start: bn_mp_div.c */
1557
+#include <bignum.h>
1558
+#ifdef BN_MP_DIV_C
1559
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
1560
+ *
1561
+ * LibTomMath is a library that provides multiple-precision
1562
+ * integer arithmetic as well as number theoretic functionality.
1563
+ *
1564
+ * The library was designed directly after the MPI library by
1565
+ * Michael Fromberger but has been written from scratch with
1566
+ * additional optimizations in place.
1567
+ *
1568
+ * The library is free for all purposes without any express
1569
+ * guarantee it works.
1570
+ *
1571
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1572
+ */
1573
+
1574
+#ifdef BN_MP_DIV_SMALL
1575
+
1576
+/* slower bit-bang division... also smaller */
1577
+int mp_div(mp_int * a, mp_int * b, mp_int * c, mp_int * d)
1578
+{
1579
+   mp_int ta, tb, tq, q;
1580
+   int    res, n, n2;
1581
+
1582
+  /* is divisor zero ? */
1583
+  if (mp_iszero (b) == 1) {
1584
+    return MP_VAL;
1585
+  }
1586
+
1587
+  /* if a < b then q=0, r = a */
1588
+  if (mp_cmp_mag (a, b) == MP_LT) {
1589
+    if (d != NULL) {
1590
+      res = mp_copy (a, d);
1591
+    } else {
1592
+      res = MP_OKAY;
1593
+    }
1594
+    if (c != NULL) {
1595
+      mp_zero (c);
1596
+    }
1597
+    return res;
1598
+  }
1599
+	
1600
+  /* init our temps */
1601
+  if ((res = mp_init_multi(&ta, &tb, &tq, &q, NULL) != MP_OKAY)) {
1602
+     return res;
1603
+  }
1604
+
1605
+
1606
+  mp_set(&tq, 1);
1607
+  n = mp_count_bits(a) - mp_count_bits(b);
1608
+  if (((res = mp_abs(a, &ta)) != MP_OKAY) ||
1609
+      ((res = mp_abs(b, &tb)) != MP_OKAY) || 
1610
+      ((res = mp_mul_2d(&tb, n, &tb)) != MP_OKAY) ||
1611
+      ((res = mp_mul_2d(&tq, n, &tq)) != MP_OKAY)) {
1612
+      goto LBL_ERR;
1613
+  }
1614
+
1615
+  while (n-- >= 0) {
1616
+     if (mp_cmp(&tb, &ta) != MP_GT) {
1617
+        if (((res = mp_sub(&ta, &tb, &ta)) != MP_OKAY) ||
1618
+            ((res = mp_add(&q, &tq, &q)) != MP_OKAY)) {
1619
+           goto LBL_ERR;
1620
+        }
1621
+     }
1622
+     if (((res = mp_div_2d(&tb, 1, &tb, NULL)) != MP_OKAY) ||
1623
+         ((res = mp_div_2d(&tq, 1, &tq, NULL)) != MP_OKAY)) {
1624
+           goto LBL_ERR;
1625
+     }
1626
+  }
1627
+
1628
+  /* now q == quotient and ta == remainder */
1629
+  n  = a->sign;
1630
+  n2 = (a->sign == b->sign ? MP_ZPOS : MP_NEG);
1631
+  if (c != NULL) {
1632
+     mp_exch(c, &q);
1633
+     c->sign  = (mp_iszero(c) == MP_YES) ? MP_ZPOS : n2;
1634
+  }
1635
+  if (d != NULL) {
1636
+     mp_exch(d, &ta);
1637
+     d->sign = (mp_iszero(d) == MP_YES) ? MP_ZPOS : n;
1638
+  }
1639
+LBL_ERR:
1640
+   mp_clear_multi(&ta, &tb, &tq, &q, NULL);
1641
+   return res;
1642
+}
1643
+
1644
+#else
1645
+
1646
+/* integer signed division. 
1647
+ * c*b + d == a [e.g. a/b, c=quotient, d=remainder]
1648
+ * HAC pp.598 Algorithm 14.20
1649
+ *
1650
+ * Note that the description in HAC is horribly 
1651
+ * incomplete.  For example, it doesn't consider 
1652
+ * the case where digits are removed from 'x' in 
1653
+ * the inner loop.  It also doesn't consider the 
1654
+ * case that y has fewer than three digits, etc..
1655
+ *
1656
+ * The overall algorithm is as described as 
1657
+ * 14.20 from HAC but fixed to treat these cases.
1658
+*/
1659
+int mp_div (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
1660
+{
1661
+  mp_int  q, x, y, t1, t2;
1662
+  int     res, n, t, i, norm, neg;
1663
+
1664
+  /* is divisor zero ? */
1665
+  if (mp_iszero (b) == 1) {
1666
+    return MP_VAL;
1667
+  }
1668
+
1669
+  /* if a < b then q=0, r = a */
1670
+  if (mp_cmp_mag (a, b) == MP_LT) {
1671
+    if (d != NULL) {
1672
+      res = mp_copy (a, d);
1673
+    } else {
1674
+      res = MP_OKAY;
1675
+    }
1676
+    if (c != NULL) {
1677
+      mp_zero (c);
1678
+    }
1679
+    return res;
1680
+  }
1681
+
1682
+  if ((res = mp_init_size (&q, a->used + 2)) != MP_OKAY) {
1683
+    return res;
1684
+  }
1685
+  q.used = a->used + 2;
1686
+
1687
+  if ((res = mp_init (&t1)) != MP_OKAY) {
1688
+    goto LBL_Q;
1689
+  }
1690
+
1691
+  if ((res = mp_init (&t2)) != MP_OKAY) {
1692
+    goto LBL_T1;
1693
+  }
1694
+
1695
+  if ((res = mp_init_copy (&x, a)) != MP_OKAY) {
1696
+    goto LBL_T2;
1697
+  }
1698
+
1699
+  if ((res = mp_init_copy (&y, b)) != MP_OKAY) {
1700
+    goto LBL_X;
1701
+  }
1702
+
1703
+  /* fix the sign */
1704
+  neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
1705
+  x.sign = y.sign = MP_ZPOS;
1706
+
1707
+  /* normalize both x and y, ensure that y >= b/2, [b == 2**DIGIT_BIT] */
1708
+  norm = mp_count_bits(&y) % DIGIT_BIT;
1709
+  if (norm < (int)(DIGIT_BIT-1)) {
1710
+     norm = (DIGIT_BIT-1) - norm;
1711
+     if ((res = mp_mul_2d (&x, norm, &x)) != MP_OKAY) {
1712
+       goto LBL_Y;
1713
+     }
1714
+     if ((res = mp_mul_2d (&y, norm, &y)) != MP_OKAY) {
1715
+       goto LBL_Y;
1716
+     }
1717
+  } else {
1718
+     norm = 0;
1719
+  }
1720
+
1721
+  /* note hac does 0 based, so if used==5 then its 0,1,2,3,4, e.g. use 4 */
1722
+  n = x.used - 1;
1723
+  t = y.used - 1;
1724
+
1725
+  /* while (x >= y*b**n-t) do { q[n-t] += 1; x -= y*b**{n-t} } */
1726
+  if ((res = mp_lshd (&y, n - t)) != MP_OKAY) { /* y = y*b**{n-t} */
1727
+    goto LBL_Y;
1728
+  }
1729
+
1730
+  while (mp_cmp (&x, &y) != MP_LT) {
1731
+    ++(q.dp[n - t]);
1732
+    if ((res = mp_sub (&x, &y, &x)) != MP_OKAY) {
1733
+      goto LBL_Y;
1734
+    }
1735
+  }
1736
+
1737
+  /* reset y by shifting it back down */
1738
+  mp_rshd (&y, n - t);
1739
+
1740
+  /* step 3. for i from n down to (t + 1) */
1741
+  for (i = n; i >= (t + 1); i--) {
1742
+    if (i > x.used) {
1743
+      continue;
1744
+    }
1745
+
1746
+    /* step 3.1 if xi == yt then set q{i-t-1} to b-1, 
1747
+     * otherwise set q{i-t-1} to (xi*b + x{i-1})/yt */
1748
+    if (x.dp[i] == y.dp[t]) {
1749
+      q.dp[i - t - 1] = ((((mp_digit)1) << DIGIT_BIT) - 1);
1750
+    } else {
1751
+      mp_word tmp;
1752
+      tmp = ((mp_word) x.dp[i]) << ((mp_word) DIGIT_BIT);
1753
+      tmp |= ((mp_word) x.dp[i - 1]);
1754
+      tmp /= ((mp_word) y.dp[t]);
1755
+      if (tmp > (mp_word) MP_MASK)
1756
+        tmp = MP_MASK;
1757
+      q.dp[i - t - 1] = (mp_digit) (tmp & (mp_word) (MP_MASK));
1758
+    }
1759
+
1760
+    /* while (q{i-t-1} * (yt * b + y{t-1})) > 
1761
+             xi * b**2 + xi-1 * b + xi-2 
1762
+     
1763
+       do q{i-t-1} -= 1; 
1764
+    */
1765
+    q.dp[i - t - 1] = (q.dp[i - t - 1] + 1) & MP_MASK;
1766
+    do {
1767
+      q.dp[i - t - 1] = (q.dp[i - t - 1] - 1) & MP_MASK;
1768
+
1769
+      /* find left hand */
1770
+      mp_zero (&t1);
1771
+      t1.dp[0] = (t - 1 < 0) ? 0 : y.dp[t - 1];
1772
+      t1.dp[1] = y.dp[t];
1773
+      t1.used = 2;
1774
+      if ((res = mp_mul_d (&t1, q.dp[i - t - 1], &t1)) != MP_OKAY) {
1775
+        goto LBL_Y;
1776
+      }
1777
+
1778
+      /* find right hand */
1779
+      t2.dp[0] = (i - 2 < 0) ? 0 : x.dp[i - 2];
1780
+      t2.dp[1] = (i - 1 < 0) ? 0 : x.dp[i - 1];
1781
+      t2.dp[2] = x.dp[i];
1782
+      t2.used = 3;
1783
+    } while (mp_cmp_mag(&t1, &t2) == MP_GT);
1784
+
1785
+    /* step 3.3 x = x - q{i-t-1} * y * b**{i-t-1} */
1786
+    if ((res = mp_mul_d (&y, q.dp[i - t - 1], &t1)) != MP_OKAY) {
1787
+      goto LBL_Y;
1788
+    }
1789
+
1790
+    if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) {
1791
+      goto LBL_Y;
1792
+    }
1793
+
1794
+    if ((res = mp_sub (&x, &t1, &x)) != MP_OKAY) {
1795
+      goto LBL_Y;
1796
+    }
1797
+
1798
+    /* if x < 0 then { x = x + y*b**{i-t-1}; q{i-t-1} -= 1; } */
1799
+    if (x.sign == MP_NEG) {
1800
+      if ((res = mp_copy (&y, &t1)) != MP_OKAY) {
1801
+        goto LBL_Y;
1802
+      }
1803
+      if ((res = mp_lshd (&t1, i - t - 1)) != MP_OKAY) {
1804
+        goto LBL_Y;
1805
+      }
1806
+      if ((res = mp_add (&x, &t1, &x)) != MP_OKAY) {
1807
+        goto LBL_Y;
1808
+      }
1809
+
1810
+      q.dp[i - t - 1] = (q.dp[i - t - 1] - 1UL) & MP_MASK;
1811
+    }
1812
+  }
1813
+
1814
+  /* now q is the quotient and x is the remainder 
1815
+   * [which we have to normalize] 
1816
+   */
1817
+  
1818
+  /* get sign before writing to c */
1819
+  x.sign = x.used == 0 ? MP_ZPOS : a->sign;
1820
+
1821
+  if (c != NULL) {
1822
+    mp_clamp (&q);
1823
+    mp_exch (&q, c);
1824
+    c->sign = neg;
1825
+  }
1826
+
1827
+  if (d != NULL) {
1828
+    mp_div_2d (&x, norm, &x, NULL);
1829
+    mp_exch (&x, d);
1830
+  }
1831
+
1832
+  res = MP_OKAY;
1833
+
1834
+LBL_Y:mp_clear (&y);
1835
+LBL_X:mp_clear (&x);
1836
+LBL_T2:mp_clear (&t2);
1837
+LBL_T1:mp_clear (&t1);
1838
+LBL_Q:mp_clear (&q);
1839
+  return res;
1840
+}
1841
+
1842
+#endif
1843
+
1844
+#endif
1845
+
1846
+/* $Source: /cvs/libtom/libtommath/bn_mp_div.c,v $ */
1847
+/* $Revision: 1.3 $ */
1848
+/* $Date: 2006/03/31 14:18:44 $ */
1849
+
1850
+/* End: bn_mp_div.c */
1851
+
1852
+/* Start: bn_mp_div_2.c */
1853
+#include <bignum.h>
1854
+#ifdef BN_MP_DIV_2_C
1855
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
1856
+ *
1857
+ * LibTomMath is a library that provides multiple-precision
1858
+ * integer arithmetic as well as number theoretic functionality.
1859
+ *
1860
+ * The library was designed directly after the MPI library by
1861
+ * Michael Fromberger but has been written from scratch with
1862
+ * additional optimizations in place.
1863
+ *
1864
+ * The library is free for all purposes without any express
1865
+ * guarantee it works.
1866
+ *
1867
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1868
+ */
1869
+
1870
+/* b = a/2 */
1871
+int mp_div_2(mp_int * a, mp_int * b)
1872
+{
1873
+  int     x, res, oldused;
1874
+
1875
+  /* copy */
1876
+  if (b->alloc < a->used) {
1877
+    if ((res = mp_grow (b, a->used)) != MP_OKAY) {
1878
+      return res;
1879
+    }
1880
+  }
1881
+
1882
+  oldused = b->used;
1883
+  b->used = a->used;
1884
+  {
1885
+    register mp_digit r, rr, *tmpa, *tmpb;
1886
+
1887
+    /* source alias */
1888
+    tmpa = a->dp + b->used - 1;
1889
+
1890
+    /* dest alias */
1891
+    tmpb = b->dp + b->used - 1;
1892
+
1893
+    /* carry */
1894
+    r = 0;
1895
+    for (x = b->used - 1; x >= 0; x--) {
1896
+      /* get the carry for the next iteration */
1897
+      rr = *tmpa & 1;
1898
+
1899
+      /* shift the current digit, add in carry and store */
1900
+      *tmpb-- = (*tmpa-- >> 1) | (r << (DIGIT_BIT - 1));
1901
+
1902
+      /* forward carry to next iteration */
1903
+      r = rr;
1904
+    }
1905
+
1906
+    /* zero excess digits */
1907
+    tmpb = b->dp + b->used;
1908
+    for (x = b->used; x < oldused; x++) {
1909
+      *tmpb++ = 0;
1910
+    }
1911
+  }
1912
+  b->sign = a->sign;
1913
+  mp_clamp (b);
1914
+  return MP_OKAY;
1915
+}
1916
+#endif
1917
+
1918
+/* $Source: /cvs/libtom/libtommath/bn_mp_div_2.c,v $ */
1919
+/* $Revision: 1.3 $ */
1920
+/* $Date: 2006/03/31 14:18:44 $ */
1921
+
1922
+/* End: bn_mp_div_2.c */
1923
+
1924
+/* Start: bn_mp_div_2d.c */
1925
+#include <bignum.h>
1926
+#ifdef BN_MP_DIV_2D_C
1927
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
1928
+ *
1929
+ * LibTomMath is a library that provides multiple-precision
1930
+ * integer arithmetic as well as number theoretic functionality.
1931
+ *
1932
+ * The library was designed directly after the MPI library by
1933
+ * Michael Fromberger but has been written from scratch with
1934
+ * additional optimizations in place.
1935
+ *
1936
+ * The library is free for all purposes without any express
1937
+ * guarantee it works.
1938
+ *
1939
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
1940
+ */
1941
+
1942
+/* shift right by a certain bit count (store quotient in c, optional remainder in d) */
1943
+int mp_div_2d (mp_int * a, int b, mp_int * c, mp_int * d)
1944
+{
1945
+  mp_digit D, r, rr;
1946
+  int     x, res;
1947
+  mp_int  t;
1948
+
1949
+
1950
+  /* if the shift count is <= 0 then we do no work */
1951
+  if (b <= 0) {
1952
+    res = mp_copy (a, c);
1953
+    if (d != NULL) {
1954
+      mp_zero (d);
1955
+    }
1956
+    return res;
1957
+  }
1958
+
1959
+  if ((res = mp_init (&t)) != MP_OKAY) {
1960
+    return res;
1961
+  }
1962
+
1963
+  /* get the remainder */
1964
+  if (d != NULL) {
1965
+    if ((res = mp_mod_2d (a, b, &t)) != MP_OKAY) {
1966
+      mp_clear (&t);
1967
+      return res;
1968
+    }
1969
+  }
1970
+
1971
+  /* copy */
1972
+  if ((res = mp_copy (a, c)) != MP_OKAY) {
1973
+    mp_clear (&t);
1974
+    return res;
1975
+  }
1976
+
1977
+  /* shift by as many digits in the bit count */
1978
+  if (b >= (int)DIGIT_BIT) {
1979
+    mp_rshd (c, b / DIGIT_BIT);
1980
+  }
1981
+
1982
+  /* shift any bit count < DIGIT_BIT */
1983
+  D = (mp_digit) (b % DIGIT_BIT);
1984
+  if (D != 0) {
1985
+    register mp_digit *tmpc, mask, shift;
1986
+
1987
+    /* mask */
1988
+    mask = (((mp_digit)1) << D) - 1;
1989
+
1990
+    /* shift for lsb */
1991
+    shift = DIGIT_BIT - D;
1992
+
1993
+    /* alias */
1994
+    tmpc = c->dp + (c->used - 1);
1995
+
1996
+    /* carry */
1997
+    r = 0;
1998
+    for (x = c->used - 1; x >= 0; x--) {
1999
+      /* get the lower  bits of this word in a temp */
2000
+      rr = *tmpc & mask;
2001
+
2002
+      /* shift the current word and mix in the carry bits from the previous word */
2003
+      *tmpc = (*tmpc >> D) | (r << shift);
2004
+      --tmpc;
2005
+
2006
+      /* set the carry to the carry bits of the current word found above */
2007
+      r = rr;
2008
+    }
2009
+  }
2010
+  mp_clamp (c);
2011
+  if (d != NULL) {
2012
+    mp_exch (&t, d);
2013
+  }
2014
+  mp_clear (&t);
2015
+  return MP_OKAY;
2016
+}
2017
+#endif
2018
+
2019
+/* $Source: /cvs/libtom/libtommath/bn_mp_div_2d.c,v $ */
2020
+/* $Revision: 1.3 $ */
2021
+/* $Date: 2006/03/31 14:18:44 $ */
2022
+
2023
+/* End: bn_mp_div_2d.c */
2024
+
2025
+/* Start: bn_mp_div_3.c */
2026
+#include <bignum.h>
2027
+#ifdef BN_MP_DIV_3_C
2028
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
2029
+ *
2030
+ * LibTomMath is a library that provides multiple-precision
2031
+ * integer arithmetic as well as number theoretic functionality.
2032
+ *
2033
+ * The library was designed directly after the MPI library by
2034
+ * Michael Fromberger but has been written from scratch with
2035
+ * additional optimizations in place.
2036
+ *
2037
+ * The library is free for all purposes without any express
2038
+ * guarantee it works.
2039
+ *
2040
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
2041
+ */
2042
+
2043
+/* divide by three (based on routine from MPI and the GMP manual) */
2044
+int
2045
+mp_div_3 (mp_int * a, mp_int *c, mp_digit * d)
2046
+{
2047
+  mp_int   q;
2048
+  mp_word  w, t;
2049
+  mp_digit b;
2050
+  int      res, ix;
2051
+  
2052
+  /* b = 2**DIGIT_BIT / 3 */
2053
+  b = (((mp_word)1) << ((mp_word)DIGIT_BIT)) / ((mp_word)3);
2054
+
2055
+  if ((res = mp_init_size(&q, a->used)) != MP_OKAY) {
2056
+     return res;
2057
+  }
2058
+  
2059
+  q.used = a->used;
2060
+  q.sign = a->sign;
2061
+  w = 0;
2062
+  for (ix = a->used - 1; ix >= 0; ix--) {
2063
+     w = (w << ((mp_word)DIGIT_BIT)) | ((mp_word)a->dp[ix]);
2064
+
2065
+     if (w >= 3) {
2066
+        /* multiply w by [1/3] */
2067
+        t = (w * ((mp_word)b)) >> ((mp_word)DIGIT_BIT);
2068
+
2069
+        /* now subtract 3 * [w/3] from w, to get the remainder */
2070
+        w -= t+t+t;
2071
+
2072
+        /* fixup the remainder as required since
2073
+         * the optimization is not exact.
2074
+         */
2075
+        while (w >= 3) {
2076
+           t += 1;
2077
+           w -= 3;
2078
+        }
2079
+      } else {
2080
+        t = 0;
2081
+      }
2082
+      q.dp[ix] = (mp_digit)t;
2083
+  }
2084
+
2085
+  /* [optional] store the remainder */
2086
+  if (d != NULL) {
2087
+     *d = (mp_digit)w;
2088
+  }
2089
+
2090
+  /* [optional] store the quotient */
2091
+  if (c != NULL) {
2092
+     mp_clamp(&q);
2093
+     mp_exch(&q, c);
2094
+  }
2095
+  mp_clear(&q);
2096
+  
2097
+  return res;
2098
+}
2099
+
2100
+#endif
2101
+
2102
+/* $Source: /cvs/libtom/libtommath/bn_mp_div_3.c,v $ */
2103
+/* $Revision: 1.3 $ */
2104
+/* $Date: 2006/03/31 14:18:44 $ */
2105
+
2106
+/* End: bn_mp_div_3.c */
2107
+
2108
+/* Start: bn_mp_div_d.c */
2109
+#include <bignum.h>
2110
+#ifdef BN_MP_DIV_D_C
2111
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
2112
+ *
2113
+ * LibTomMath is a library that provides multiple-precision
2114
+ * integer arithmetic as well as number theoretic functionality.
2115
+ *
2116
+ * The library was designed directly after the MPI library by
2117
+ * Michael Fromberger but has been written from scratch with
2118
+ * additional optimizations in place.
2119
+ *
2120
+ * The library is free for all purposes without any express
2121
+ * guarantee it works.
2122
+ *
2123
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
2124
+ */
2125
+
2126
+static int s_is_power_of_two(mp_digit b, int *p)
2127
+{
2128
+   int x;
2129
+
2130
+   for (x = 1; x < DIGIT_BIT; x++) {
2131
+      if (b == (((mp_digit)1)<<x)) {
2132
+         *p = x;
2133
+         return 1;
2134
+      }
2135
+   }
2136
+   return 0;
2137
+}
2138
+
2139
+/* single digit division (based on routine from MPI) */
2140
+int mp_div_d (mp_int * a, mp_digit b, mp_int * c, mp_digit * d)
2141
+{
2142
+  mp_int  q;
2143
+  mp_word w;
2144
+  mp_digit t;
2145
+  int     res, ix;
2146
+
2147
+  /* cannot divide by zero */
2148
+  if (b == 0) {
2149
+     return MP_VAL;
2150
+  }
2151
+
2152
+  /* quick outs */
2153
+  if (b == 1 || mp_iszero(a) == 1) {
2154
+     if (d != NULL) {
2155
+        *d = 0;
2156
+     }
2157
+     if (c != NULL) {
2158
+        return mp_copy(a, c);
2159
+     }
2160
+     return MP_OKAY;
2161
+  }
2162
+
2163
+  /* power of two ? */
2164
+  if (s_is_power_of_two(b, &ix) == 1) {
2165
+     if (d != NULL) {
2166
+        *d = a->dp[0] & ((((mp_digit)1)<<ix) - 1);
2167
+     }
2168
+     if (c != NULL) {
2169
+        return mp_div_2d(a, ix, c, NULL);
2170
+     }
2171
+     return MP_OKAY;
2172
+  }
2173
+
2174
+#ifdef BN_MP_DIV_3_C
2175
+  /* three? */
2176
+  if (b == 3) {
2177
+     return mp_div_3(a, c, d);
2178
+  }
2179
+#endif
2180
+
2181
+  /* no easy answer [c'est la vie].  Just division */
2182
+  if ((res = mp_init_size(&q, a->used)) != MP_OKAY) {
2183
+     return res;
2184
+  }
2185
+  
2186
+  q.used = a->used;
2187
+  q.sign = a->sign;
2188
+  w = 0;
2189
+  for (ix = a->used - 1; ix >= 0; ix--) {
2190
+     w = (w << ((mp_word)DIGIT_BIT)) | ((mp_word)a->dp[ix]);
2191
+     
2192
+     if (w >= b) {
2193
+        t = (mp_digit)(w / b);
2194
+        w -= ((mp_word)t) * ((mp_word)b);
2195
+      } else {
2196
+        t = 0;
2197
+      }
2198
+      q.dp[ix] = (mp_digit)t;
2199
+  }
2200
+  
2201
+  if (d != NULL) {
2202
+     *d = (mp_digit)w;
2203
+  }
2204
+  
2205
+  if (c != NULL) {
2206
+     mp_clamp(&q);
2207
+     mp_exch(&q, c);
2208
+  }
2209
+  mp_clear(&q);
2210
+  
2211
+  return res;
2212
+}
2213
+
2214
+#endif
2215
+
2216
+/* $Source: /cvs/libtom/libtommath/bn_mp_div_d.c,v $ */
2217
+/* $Revision: 1.3 $ */
2218
+/* $Date: 2006/03/31 14:18:44 $ */
2219
+
2220
+/* End: bn_mp_div_d.c */
2221
+
2222
+/* Start: bn_mp_dr_is_modulus.c */
2223
+#include <bignum.h>
2224
+#ifdef BN_MP_DR_IS_MODULUS_C
2225
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
2226
+ *
2227
+ * LibTomMath is a library that provides multiple-precision
2228
+ * integer arithmetic as well as number theoretic functionality.
2229
+ *
2230
+ * The library was designed directly after the MPI library by
2231
+ * Michael Fromberger but has been written from scratch with
2232
+ * additional optimizations in place.
2233
+ *
2234
+ * The library is free for all purposes without any express
2235
+ * guarantee it works.
2236
+ *
2237
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
2238
+ */
2239
+
2240
+/* determines if a number is a valid DR modulus */
2241
+int mp_dr_is_modulus(mp_int *a)
2242
+{
2243
+   int ix;
2244
+
2245
+   /* must be at least two digits */
2246
+   if (a->used < 2) {
2247
+      return 0;
2248
+   }
2249
+
2250
+   /* must be of the form b**k - a [a <= b] so all
2251
+    * but the first digit must be equal to -1 (mod b).
2252
+    */
2253
+   for (ix = 1; ix < a->used; ix++) {
2254
+       if (a->dp[ix] != MP_MASK) {
2255
+          return 0;
2256
+       }
2257
+   }
2258
+   return 1;
2259
+}
2260
+
2261
+#endif
2262
+
2263
+/* $Source: /cvs/libtom/libtommath/bn_mp_dr_is_modulus.c,v $ */
2264
+/* $Revision: 1.3 $ */
2265
+/* $Date: 2006/03/31 14:18:44 $ */
2266
+
2267
+/* End: bn_mp_dr_is_modulus.c */
2268
+
2269
+/* Start: bn_mp_dr_reduce.c */
2270
+#include <bignum.h>
2271
+#ifdef BN_MP_DR_REDUCE_C
2272
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
2273
+ *
2274
+ * LibTomMath is a library that provides multiple-precision
2275
+ * integer arithmetic as well as number theoretic functionality.
2276
+ *
2277
+ * The library was designed directly after the MPI library by
2278
+ * Michael Fromberger but has been written from scratch with
2279
+ * additional optimizations in place.
2280
+ *
2281
+ * The library is free for all purposes without any express
2282
+ * guarantee it works.
2283
+ *
2284
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
2285
+ */
2286
+
2287
+/* reduce "x" in place modulo "n" using the Diminished Radix algorithm.
2288
+ *
2289
+ * Based on algorithm from the paper
2290
+ *
2291
+ * "Generating Efficient Primes for Discrete Log Cryptosystems"
2292
+ *                 Chae Hoon Lim, Pil Joong Lee,
2293
+ *          POSTECH Information Research Laboratories
2294
+ *
2295
+ * The modulus must be of a special format [see manual]
2296
+ *
2297
+ * Has been modified to use algorithm 7.10 from the LTM book instead
2298
+ *
2299
+ * Input x must be in the range 0 <= x <= (n-1)**2
2300
+ */
2301
+int
2302
+mp_dr_reduce (mp_int * x, mp_int * n, mp_digit k)
2303
+{
2304
+  int      err, i, m;
2305
+  mp_word  r;
2306
+  mp_digit mu, *tmpx1, *tmpx2;
2307
+
2308
+  /* m = digits in modulus */
2309
+  m = n->used;
2310
+
2311
+  /* ensure that "x" has at least 2m digits */
2312
+  if (x->alloc < m + m) {
2313
+    if ((err = mp_grow (x, m + m)) != MP_OKAY) {
2314
+      return err;
2315
+    }
2316
+  }
2317
+
2318
+/* top of loop, this is where the code resumes if
2319
+ * another reduction pass is required.
2320
+ */
2321
+top:
2322
+  /* aliases for digits */
2323
+  /* alias for lower half of x */
2324
+  tmpx1 = x->dp;
2325
+
2326
+  /* alias for upper half of x, or x/B**m */
2327
+  tmpx2 = x->dp + m;
2328
+
2329
+  /* set carry to zero */
2330
+  mu = 0;
2331
+
2332
+  /* compute (x mod B**m) + k * [x/B**m] inline and inplace */
2333
+  for (i = 0; i < m; i++) {
2334
+      r         = ((mp_word)*tmpx2++) * ((mp_word)k) + *tmpx1 + mu;
2335
+      *tmpx1++  = (mp_digit)(r & MP_MASK);
2336
+      mu        = (mp_digit)(r >> ((mp_word)DIGIT_BIT));
2337
+  }
2338
+
2339
+  /* set final carry */
2340
+  *tmpx1++ = mu;
2341
+
2342
+  /* zero words above m */
2343
+  for (i = m + 1; i < x->used; i++) {
2344
+      *tmpx1++ = 0;
2345
+  }
2346
+
2347
+  /* clamp, sub and return */
2348
+  mp_clamp (x);
2349
+
2350
+  /* if x >= n then subtract and reduce again
2351
+   * Each successive "recursion" makes the input smaller and smaller.
2352
+   */
2353
+  if (mp_cmp_mag (x, n) != MP_LT) {
2354
+    s_mp_sub(x, n, x);
2355
+    goto top;
2356
+  }
2357
+  return MP_OKAY;
2358
+}
2359
+#endif
2360
+
2361
+/* $Source: /cvs/libtom/libtommath/bn_mp_dr_reduce.c,v $ */
2362
+/* $Revision: 1.3 $ */
2363
+/* $Date: 2006/03/31 14:18:44 $ */
2364
+
2365
+/* End: bn_mp_dr_reduce.c */
2366
+
2367
+/* Start: bn_mp_dr_setup.c */
2368
+#include <bignum.h>
2369
+#ifdef BN_MP_DR_SETUP_C
2370
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
2371
+ *
2372
+ * LibTomMath is a library that provides multiple-precision
2373
+ * integer arithmetic as well as number theoretic functionality.
2374
+ *
2375
+ * The library was designed directly after the MPI library by
2376
+ * Michael Fromberger but has been written from scratch with
2377
+ * additional optimizations in place.
2378
+ *
2379
+ * The library is free for all purposes without any express
2380
+ * guarantee it works.
2381
+ *
2382
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
2383
+ */
2384
+
2385
+/* determines the setup value */
2386
+void mp_dr_setup(mp_int *a, mp_digit *d)
2387
+{
2388
+   /* the casts are required if DIGIT_BIT is one less than
2389
+    * the number of bits in a mp_digit [e.g. DIGIT_BIT==31]
2390
+    */
2391
+   *d = (mp_digit)((((mp_word)1) << ((mp_word)DIGIT_BIT)) - 
2392
+        ((mp_word)a->dp[0]));
2393
+}
2394
+
2395
+#endif
2396
+
2397
+/* $Source: /cvs/libtom/libtommath/bn_mp_dr_setup.c,v $ */
2398
+/* $Revision: 1.3 $ */
2399
+/* $Date: 2006/03/31 14:18:44 $ */
2400
+
2401
+/* End: bn_mp_dr_setup.c */
2402
+
2403
+/* Start: bn_mp_exch.c */
2404
+#include <bignum.h>
2405
+#ifdef BN_MP_EXCH_C
2406
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
2407
+ *
2408
+ * LibTomMath is a library that provides multiple-precision
2409
+ * integer arithmetic as well as number theoretic functionality.
2410
+ *
2411
+ * The library was designed directly after the MPI library by
2412
+ * Michael Fromberger but has been written from scratch with
2413
+ * additional optimizations in place.
2414
+ *
2415
+ * The library is free for all purposes without any express
2416
+ * guarantee it works.
2417
+ *
2418
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
2419
+ */
2420
+
2421
+/* swap the elements of two integers, for cases where you can't simply swap the 
2422
+ * mp_int pointers around
2423
+ */
2424
+void
2425
+mp_exch (mp_int * a, mp_int * b)
2426
+{
2427
+  mp_int  t;
2428
+
2429
+  t  = *a;
2430
+  *a = *b;
2431
+  *b = t;
2432
+}
2433
+#endif
2434
+
2435
+/* $Source: /cvs/libtom/libtommath/bn_mp_exch.c,v $ */
2436
+/* $Revision: 1.3 $ */
2437
+/* $Date: 2006/03/31 14:18:44 $ */
2438
+
2439
+/* End: bn_mp_exch.c */
2440
+
2441
+/* Start: bn_mp_expt_d.c */
2442
+#include <bignum.h>
2443
+#ifdef BN_MP_EXPT_D_C
2444
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
2445
+ *
2446
+ * LibTomMath is a library that provides multiple-precision
2447
+ * integer arithmetic as well as number theoretic functionality.
2448
+ *
2449
+ * The library was designed directly after the MPI library by
2450
+ * Michael Fromberger but has been written from scratch with
2451
+ * additional optimizations in place.
2452
+ *
2453
+ * The library is free for all purposes without any express
2454
+ * guarantee it works.
2455
+ *
2456
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
2457
+ */
2458
+
2459
+/* calculate c = a**b  using a square-multiply algorithm */
2460
+int mp_expt_d (mp_int * a, mp_digit b, mp_int * c)
2461
+{
2462
+  int     res, x;
2463
+  mp_int  g;
2464
+
2465
+  if ((res = mp_init_copy (&g, a)) != MP_OKAY) {
2466
+    return res;
2467
+  }
2468
+
2469
+  /* set initial result */
2470
+  mp_set (c, 1);
2471
+
2472
+  for (x = 0; x < (int) DIGIT_BIT; x++) {
2473
+    /* square */
2474
+    if ((res = mp_sqr (c, c)) != MP_OKAY) {
2475
+      mp_clear (&g);
2476
+      return res;
2477
+    }
2478
+
2479
+    /* if the bit is set multiply */
2480
+    if ((b & (mp_digit) (((mp_digit)1) << (DIGIT_BIT - 1))) != 0) {
2481
+      if ((res = mp_mul (c, &g, c)) != MP_OKAY) {
2482
+         mp_clear (&g);
2483
+         return res;
2484
+      }
2485
+    }
2486
+
2487
+    /* shift to next bit */
2488
+    b <<= 1;
2489
+  }
2490
+
2491
+  mp_clear (&g);
2492
+  return MP_OKAY;
2493
+}
2494
+#endif
2495
+
2496
+/* $Source: /cvs/libtom/libtommath/bn_mp_expt_d.c,v $ */
2497
+/* $Revision: 1.3 $ */
2498
+/* $Date: 2006/03/31 14:18:44 $ */
2499
+
2500
+/* End: bn_mp_expt_d.c */
2501
+
2502
+/* Start: bn_mp_exptmod.c */
2503
+#include <bignum.h>
2504
+#ifdef BN_MP_EXPTMOD_C
2505
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
2506
+ *
2507
+ * LibTomMath is a library that provides multiple-precision
2508
+ * integer arithmetic as well as number theoretic functionality.
2509
+ *
2510
+ * The library was designed directly after the MPI library by
2511
+ * Michael Fromberger but has been written from scratch with
2512
+ * additional optimizations in place.
2513
+ *
2514
+ * The library is free for all purposes without any express
2515
+ * guarantee it works.
2516
+ *
2517
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
2518
+ */
2519
+
2520
+
2521
+/* this is a shell function that calls either the normal or Montgomery
2522
+ * exptmod functions.  Originally the call to the montgomery code was
2523
+ * embedded in the normal function but that wasted alot of stack space
2524
+ * for nothing (since 99% of the time the Montgomery code would be called)
2525
+ */
2526
+int mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y)
2527
+{
2528
+  int dr;
2529
+
2530
+  /* modulus P must be positive */
2531
+  if (P->sign == MP_NEG) {
2532
+     return MP_VAL;
2533
+  }
2534
+
2535
+  /* if exponent X is negative we have to recurse */
2536
+  if (X->sign == MP_NEG) {
2537
+#ifdef BN_MP_INVMOD_C
2538
+     mp_int tmpG, tmpX;
2539
+     int err;
2540
+
2541
+     /* first compute 1/G mod P */
2542
+     if ((err = mp_init(&tmpG)) != MP_OKAY) {
2543
+        return err;
2544
+     }
2545
+     if ((err = mp_invmod(G, P, &tmpG)) != MP_OKAY) {
2546
+        mp_clear(&tmpG);
2547
+        return err;
2548
+     }
2549
+
2550
+     /* now get |X| */
2551
+     if ((err = mp_init(&tmpX)) != MP_OKAY) {
2552
+        mp_clear(&tmpG);
2553
+        return err;
2554
+     }
2555
+     if ((err = mp_abs(X, &tmpX)) != MP_OKAY) {
2556
+        mp_clear_multi(&tmpG, &tmpX, NULL);
2557
+        return err;
2558
+     }
2559
+
2560
+     /* and now compute (1/G)**|X| instead of G**X [X < 0] */
2561
+     err = mp_exptmod(&tmpG, &tmpX, P, Y);
2562
+     mp_clear_multi(&tmpG, &tmpX, NULL);
2563
+     return err;
2564
+#else 
2565
+     /* no invmod */
2566
+     return MP_VAL;
2567
+#endif
2568
+  }
2569
+
2570
+/* modified diminished radix reduction */
2571
+#if defined(BN_MP_REDUCE_IS_2K_L_C) && defined(BN_MP_REDUCE_2K_L_C) && defined(BN_S_MP_EXPTMOD_C)
2572
+  if (mp_reduce_is_2k_l(P) == MP_YES) {
2573
+     return s_mp_exptmod(G, X, P, Y, 1);
2574
+  }
2575
+#endif
2576
+
2577
+#ifdef BN_MP_DR_IS_MODULUS_C
2578
+  /* is it a DR modulus? */
2579
+  dr = mp_dr_is_modulus(P);
2580
+#else
2581
+  /* default to no */
2582
+  dr = 0;
2583
+#endif
2584
+
2585
+#ifdef BN_MP_REDUCE_IS_2K_C
2586
+  /* if not, is it a unrestricted DR modulus? */
2587
+  if (dr == 0) {
2588
+     dr = mp_reduce_is_2k(P) << 1;
2589
+  }
2590
+#endif
2591
+    
2592
+  /* if the modulus is odd or dr != 0 use the montgomery method */
2593
+#ifdef BN_MP_EXPTMOD_FAST_C
2594
+  if (mp_isodd (P) == 1 || dr !=  0) {
2595
+    return mp_exptmod_fast (G, X, P, Y, dr);
2596
+  } else {
2597
+#endif
2598
+#ifdef BN_S_MP_EXPTMOD_C
2599
+    /* otherwise use the generic Barrett reduction technique */
2600
+    return s_mp_exptmod (G, X, P, Y, 0);
2601
+#else
2602
+    /* no exptmod for evens */
2603
+    return MP_VAL;
2604
+#endif
2605
+#ifdef BN_MP_EXPTMOD_FAST_C
2606
+  }
2607
+#endif
2608
+}
2609
+
2610
+#endif
2611
+
2612
+/* $Source: /cvs/libtom/libtommath/bn_mp_exptmod.c,v $ */
2613
+/* $Revision: 1.4 $ */
2614
+/* $Date: 2006/03/31 14:18:44 $ */
2615
+
2616
+/* End: bn_mp_exptmod.c */
2617
+
2618
+/* Start: bn_mp_exptmod_fast.c */
2619
+#include <bignum.h>
2620
+#ifdef BN_MP_EXPTMOD_FAST_C
2621
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
2622
+ *
2623
+ * LibTomMath is a library that provides multiple-precision
2624
+ * integer arithmetic as well as number theoretic functionality.
2625
+ *
2626
+ * The library was designed directly after the MPI library by
2627
+ * Michael Fromberger but has been written from scratch with
2628
+ * additional optimizations in place.
2629
+ *
2630
+ * The library is free for all purposes without any express
2631
+ * guarantee it works.
2632
+ *
2633
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
2634
+ */
2635
+
2636
+/* computes Y == G**X mod P, HAC pp.616, Algorithm 14.85
2637
+ *
2638
+ * Uses a left-to-right k-ary sliding window to compute the modular exponentiation.
2639
+ * The value of k changes based on the size of the exponent.
2640
+ *
2641
+ * Uses Montgomery or Diminished Radix reduction [whichever appropriate]
2642
+ */
2643
+
2644
+#ifdef MP_LOW_MEM
2645
+   #define TAB_SIZE 32
2646
+#else
2647
+   #define TAB_SIZE 256
2648
+#endif
2649
+
2650
+int mp_exptmod_fast (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
2651
+{
2652
+  mp_int  M[TAB_SIZE], res;
2653
+  mp_digit buf, mp;
2654
+  int     err, bitbuf, bitcpy, bitcnt, mode, digidx, x, y, winsize;
2655
+
2656
+  /* use a pointer to the reduction algorithm.  This allows us to use
2657
+   * one of many reduction algorithms without modding the guts of
2658
+   * the code with if statements everywhere.
2659
+   */
2660
+  int     (*redux)(mp_int*,mp_int*,mp_digit);
2661
+
2662
+  /* find window size */
2663
+  x = mp_count_bits (X);
2664
+  if (x <= 7) {
2665
+    winsize = 2;
2666
+  } else if (x <= 36) {
2667
+    winsize = 3;
2668
+  } else if (x <= 140) {
2669
+    winsize = 4;
2670
+  } else if (x <= 450) {
2671
+    winsize = 5;
2672
+  } else if (x <= 1303) {
2673
+    winsize = 6;
2674
+  } else if (x <= 3529) {
2675
+    winsize = 7;
2676
+  } else {
2677
+    winsize = 8;
2678
+  }
2679
+
2680
+#ifdef MP_LOW_MEM
2681
+  if (winsize > 5) {
2682
+     winsize = 5;
2683
+  }
2684
+#endif
2685
+
2686
+  /* init M array */
2687
+  /* init first cell */
2688
+  if ((err = mp_init(&M[1])) != MP_OKAY) {
2689
+     return err;
2690
+  }
2691
+
2692
+  /* now init the second half of the array */
2693
+  for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
2694
+    if ((err = mp_init(&M[x])) != MP_OKAY) {
2695
+      for (y = 1<<(winsize-1); y < x; y++) {
2696
+        mp_clear (&M[y]);
2697
+      }
2698
+      mp_clear(&M[1]);
2699
+      return err;
2700
+    }
2701
+  }
2702
+
2703
+  /* determine and setup reduction code */
2704
+  if (redmode == 0) {
2705
+#ifdef BN_MP_MONTGOMERY_SETUP_C     
2706
+     /* now setup montgomery  */
2707
+     if ((err = mp_montgomery_setup (P, &mp)) != MP_OKAY) {
2708
+        goto LBL_M;
2709
+     }
2710
+#else
2711
+     err = MP_VAL;
2712
+     goto LBL_M;
2713
+#endif
2714
+
2715
+     /* automatically pick the comba one if available (saves quite a few calls/ifs) */
2716
+#ifdef BN_FAST_MP_MONTGOMERY_REDUCE_C
2717
+     if (((P->used * 2 + 1) < MP_WARRAY) &&
2718
+          P->used < (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
2719
+        redux = fast_mp_montgomery_reduce;
2720
+     } else 
2721
+#endif
2722
+     {
2723
+#ifdef BN_MP_MONTGOMERY_REDUCE_C
2724
+        /* use slower baseline Montgomery method */
2725
+        redux = mp_montgomery_reduce;
2726
+#else
2727
+        err = MP_VAL;
2728
+        goto LBL_M;
2729
+#endif
2730
+     }
2731
+  } else if (redmode == 1) {
2732
+#if defined(BN_MP_DR_SETUP_C) && defined(BN_MP_DR_REDUCE_C)
2733
+     /* setup DR reduction for moduli of the form B**k - b */
2734
+     mp_dr_setup(P, &mp);
2735
+     redux = mp_dr_reduce;
2736
+#else
2737
+     err = MP_VAL;
2738
+     goto LBL_M;
2739
+#endif
2740
+  } else {
2741
+#if defined(BN_MP_REDUCE_2K_SETUP_C) && defined(BN_MP_REDUCE_2K_C)
2742
+     /* setup DR reduction for moduli of the form 2**k - b */
2743
+     if ((err = mp_reduce_2k_setup(P, &mp)) != MP_OKAY) {
2744
+        goto LBL_M;
2745
+     }
2746
+     redux = mp_reduce_2k;
2747
+#else
2748
+     err = MP_VAL;
2749
+     goto LBL_M;
2750
+#endif
2751
+  }
2752
+
2753
+  /* setup result */
2754
+  if ((err = mp_init (&res)) != MP_OKAY) {
2755
+    goto LBL_M;
2756
+  }
2757
+
2758
+  /* create M table
2759
+   *
2760
+
2761
+   *
2762
+   * The first half of the table is not computed though accept for M[0] and M[1]
2763
+   */
2764
+
2765
+  if (redmode == 0) {
2766
+#ifdef BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
2767
+     /* now we need R mod m */
2768
+     if ((err = mp_montgomery_calc_normalization (&res, P)) != MP_OKAY) {
2769
+       goto LBL_RES;
2770
+     }
2771
+#else 
2772
+     err = MP_VAL;
2773
+     goto LBL_RES;
2774
+#endif
2775
+
2776
+     /* now set M[1] to G * R mod m */
2777
+     if ((err = mp_mulmod (G, &res, P, &M[1])) != MP_OKAY) {
2778
+       goto LBL_RES;
2779
+     }
2780
+  } else {
2781
+     mp_set(&res, 1);
2782
+     if ((err = mp_mod(G, P, &M[1])) != MP_OKAY) {
2783
+        goto LBL_RES;
2784
+     }
2785
+  }
2786
+
2787
+  /* compute the value at M[1<<(winsize-1)] by squaring M[1] (winsize-1) times */
2788
+  if ((err = mp_copy (&M[1], &M[1 << (winsize - 1)])) != MP_OKAY) {
2789
+    goto LBL_RES;
2790
+  }
2791
+
2792
+  for (x = 0; x < (winsize - 1); x++) {
2793
+    if ((err = mp_sqr (&M[1 << (winsize - 1)], &M[1 << (winsize - 1)])) != MP_OKAY) {
2794
+      goto LBL_RES;
2795
+    }
2796
+    if ((err = redux (&M[1 << (winsize - 1)], P, mp)) != MP_OKAY) {
2797
+      goto LBL_RES;
2798
+    }
2799
+  }
2800
+
2801
+  /* create upper table */
2802
+  for (x = (1 << (winsize - 1)) + 1; x < (1 << winsize); x++) {
2803
+    if ((err = mp_mul (&M[x - 1], &M[1], &M[x])) != MP_OKAY) {
2804
+      goto LBL_RES;
2805
+    }
2806
+    if ((err = redux (&M[x], P, mp)) != MP_OKAY) {
2807
+      goto LBL_RES;
2808
+    }
2809
+  }
2810
+
2811
+  /* set initial mode and bit cnt */
2812
+  mode   = 0;
2813
+  bitcnt = 1;
2814
+  buf    = 0;
2815
+  digidx = X->used - 1;
2816
+  bitcpy = 0;
2817
+  bitbuf = 0;
2818
+
2819
+  for (;;) {
2820
+    /* grab next digit as required */
2821
+    if (--bitcnt == 0) {
2822
+      /* if digidx == -1 we are out of digits so break */
2823
+      if (digidx == -1) {
2824
+        break;
2825
+      }
2826
+      /* read next digit and reset bitcnt */
2827
+      buf    = X->dp[digidx--];
2828
+      bitcnt = (int)DIGIT_BIT;
2829
+    }
2830
+
2831
+    /* grab the next msb from the exponent */
2832
+    y     = (mp_digit)(buf >> (DIGIT_BIT - 1)) & 1;
2833
+    buf <<= (mp_digit)1;
2834
+
2835
+    /* if the bit is zero and mode == 0 then we ignore it
2836
+     * These represent the leading zero bits before the first 1 bit
2837
+     * in the exponent.  Technically this opt is not required but it
2838
+     * does lower the # of trivial squaring/reductions used
2839
+     */
2840
+    if (mode == 0 && y == 0) {
2841
+      continue;
2842
+    }
2843
+
2844
+    /* if the bit is zero and mode == 1 then we square */
2845
+    if (mode == 1 && y == 0) {
2846
+      if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
2847
+        goto LBL_RES;
2848
+      }
2849
+      if ((err = redux (&res, P, mp)) != MP_OKAY) {
2850
+        goto LBL_RES;
2851
+      }
2852
+      continue;
2853
+    }
2854
+
2855
+    /* else we add it to the window */
2856
+    bitbuf |= (y << (winsize - ++bitcpy));
2857
+    mode    = 2;
2858
+
2859
+    if (bitcpy == winsize) {
2860
+      /* ok window is filled so square as required and multiply  */
2861
+      /* square first */
2862
+      for (x = 0; x < winsize; x++) {
2863
+        if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
2864
+          goto LBL_RES;
2865
+        }
2866
+        if ((err = redux (&res, P, mp)) != MP_OKAY) {
2867
+          goto LBL_RES;
2868
+        }
2869
+      }
2870
+
2871
+      /* then multiply */
2872
+      if ((err = mp_mul (&res, &M[bitbuf], &res)) != MP_OKAY) {
2873
+        goto LBL_RES;
2874
+      }
2875
+      if ((err = redux (&res, P, mp)) != MP_OKAY) {
2876
+        goto LBL_RES;
2877
+      }
2878
+
2879
+      /* empty window and reset */
2880
+      bitcpy = 0;
2881
+      bitbuf = 0;
2882
+      mode   = 1;
2883
+    }
2884
+  }
2885
+
2886
+  /* if bits remain then square/multiply */
2887
+  if (mode == 2 && bitcpy > 0) {
2888
+    /* square then multiply if the bit is set */
2889
+    for (x = 0; x < bitcpy; x++) {
2890
+      if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
2891
+        goto LBL_RES;
2892
+      }
2893
+      if ((err = redux (&res, P, mp)) != MP_OKAY) {
2894
+        goto LBL_RES;
2895
+      }
2896
+
2897
+      /* get next bit of the window */
2898
+      bitbuf <<= 1;
2899
+      if ((bitbuf & (1 << winsize)) != 0) {
2900
+        /* then multiply */
2901
+        if ((err = mp_mul (&res, &M[1], &res)) != MP_OKAY) {
2902
+          goto LBL_RES;
2903
+        }
2904
+        if ((err = redux (&res, P, mp)) != MP_OKAY) {
2905
+          goto LBL_RES;
2906
+        }
2907
+      }
2908
+    }
2909
+  }
2910
+
2911
+  if (redmode == 0) {
2912
+     /* fixup result if Montgomery reduction is used
2913
+      * recall that any value in a Montgomery system is
2914
+      * actually multiplied by R mod n.  So we have
2915
+      * to reduce one more time to cancel out the factor
2916
+      * of R.
2917
+      */
2918
+     if ((err = redux(&res, P, mp)) != MP_OKAY) {
2919
+       goto LBL_RES;
2920
+     }
2921
+  }
2922
+
2923
+  /* swap res with Y */
2924
+  mp_exch (&res, Y);
2925
+  err = MP_OKAY;
2926
+LBL_RES:mp_clear (&res);
2927
+LBL_M:
2928
+  mp_clear(&M[1]);
2929
+  for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
2930
+    mp_clear (&M[x]);
2931
+  }
2932
+  return err;
2933
+}
2934
+#endif
2935
+
2936
+
2937
+/* $Source: /cvs/libtom/libtommath/bn_mp_exptmod_fast.c,v $ */
2938
+/* $Revision: 1.3 $ */
2939
+/* $Date: 2006/03/31 14:18:44 $ */
2940
+
2941
+/* End: bn_mp_exptmod_fast.c */
2942
+
2943
+/* Start: bn_mp_exteuclid.c */
2944
+#include <bignum.h>
2945
+#ifdef BN_MP_EXTEUCLID_C
2946
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
2947
+ *
2948
+ * LibTomMath is a library that provides multiple-precision
2949
+ * integer arithmetic as well as number theoretic functionality.
2950
+ *
2951
+ * The library was designed directly after the MPI library by
2952
+ * Michael Fromberger but has been written from scratch with
2953
+ * additional optimizations in place.
2954
+ *
2955
+ * The library is free for all purposes without any express
2956
+ * guarantee it works.
2957
+ *
2958
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
2959
+ */
2960
+
2961
+/* Extended euclidean algorithm of (a, b) produces 
2962
+   a*u1 + b*u2 = u3
2963
+ */
2964
+int mp_exteuclid(mp_int *a, mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3)
2965
+{
2966
+   mp_int u1,u2,u3,v1,v2,v3,t1,t2,t3,q,tmp;
2967
+   int err;
2968
+
2969
+   if ((err = mp_init_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL)) != MP_OKAY) {
2970
+      return err;
2971
+   }
2972
+
2973
+   /* initialize, (u1,u2,u3) = (1,0,a) */
2974
+   mp_set(&u1, 1);
2975
+   if ((err = mp_copy(a, &u3)) != MP_OKAY)                                        { goto _ERR; }
2976
+
2977
+   /* initialize, (v1,v2,v3) = (0,1,b) */
2978
+   mp_set(&v2, 1);
2979
+   if ((err = mp_copy(b, &v3)) != MP_OKAY)                                        { goto _ERR; }
2980
+
2981
+   /* loop while v3 != 0 */
2982
+   while (mp_iszero(&v3) == MP_NO) {
2983
+       /* q = u3/v3 */
2984
+       if ((err = mp_div(&u3, &v3, &q, NULL)) != MP_OKAY)                         { goto _ERR; }
2985
+
2986
+       /* (t1,t2,t3) = (u1,u2,u3) - (v1,v2,v3)q */
2987
+       if ((err = mp_mul(&v1, &q, &tmp)) != MP_OKAY)                              { goto _ERR; }
2988
+       if ((err = mp_sub(&u1, &tmp, &t1)) != MP_OKAY)                             { goto _ERR; }
2989
+       if ((err = mp_mul(&v2, &q, &tmp)) != MP_OKAY)                              { goto _ERR; }
2990
+       if ((err = mp_sub(&u2, &tmp, &t2)) != MP_OKAY)                             { goto _ERR; }
2991
+       if ((err = mp_mul(&v3, &q, &tmp)) != MP_OKAY)                              { goto _ERR; }
2992
+       if ((err = mp_sub(&u3, &tmp, &t3)) != MP_OKAY)                             { goto _ERR; }
2993
+
2994
+       /* (u1,u2,u3) = (v1,v2,v3) */
2995
+       if ((err = mp_copy(&v1, &u1)) != MP_OKAY)                                  { goto _ERR; }
2996
+       if ((err = mp_copy(&v2, &u2)) != MP_OKAY)                                  { goto _ERR; }
2997
+       if ((err = mp_copy(&v3, &u3)) != MP_OKAY)                                  { goto _ERR; }
2998
+
2999
+       /* (v1,v2,v3) = (t1,t2,t3) */
3000
+       if ((err = mp_copy(&t1, &v1)) != MP_OKAY)                                  { goto _ERR; }
3001
+       if ((err = mp_copy(&t2, &v2)) != MP_OKAY)                                  { goto _ERR; }
3002
+       if ((err = mp_copy(&t3, &v3)) != MP_OKAY)                                  { goto _ERR; }
3003
+   }
3004
+
3005
+   /* make sure U3 >= 0 */
3006
+   if (u3.sign == MP_NEG) {
3007
+      mp_neg(&u1, &u1);
3008
+      mp_neg(&u2, &u2);
3009
+      mp_neg(&u3, &u3);
3010
+   }
3011
+
3012
+   /* copy result out */
3013
+   if (U1 != NULL) { mp_exch(U1, &u1); }
3014
+   if (U2 != NULL) { mp_exch(U2, &u2); }
3015
+   if (U3 != NULL) { mp_exch(U3, &u3); }
3016
+
3017
+   err = MP_OKAY;
3018
+_ERR: mp_clear_multi(&u1, &u2, &u3, &v1, &v2, &v3, &t1, &t2, &t3, &q, &tmp, NULL);
3019
+   return err;
3020
+}
3021
+#endif
3022
+
3023
+/* $Source: /cvs/libtom/libtommath/bn_mp_exteuclid.c,v $ */
3024
+/* $Revision: 1.3 $ */
3025
+/* $Date: 2006/03/31 14:18:44 $ */
3026
+
3027
+/* End: bn_mp_exteuclid.c */
3028
+
3029
+/* Start: bn_mp_fread.c */
3030
+#include <bignum.h>
3031
+#ifdef BN_MP_FREAD_C
3032
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
3033
+ *
3034
+ * LibTomMath is a library that provides multiple-precision
3035
+ * integer arithmetic as well as number theoretic functionality.
3036
+ *
3037
+ * The library was designed directly after the MPI library by
3038
+ * Michael Fromberger but has been written from scratch with
3039
+ * additional optimizations in place.
3040
+ *
3041
+ * The library is free for all purposes without any express
3042
+ * guarantee it works.
3043
+ *
3044
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
3045
+ */
3046
+
3047
+/* read a bigint from a file stream in ASCII */
3048
+int mp_fread(mp_int *a, int radix, FILE *stream)
3049
+{
3050
+   int err, ch, neg, y;
3051
+   
3052
+   /* clear a */
3053
+   mp_zero(a);
3054
+   
3055
+   /* if first digit is - then set negative */
3056
+   ch = fgetc(stream);
3057
+   if (ch == '-') {
3058
+      neg = MP_NEG;
3059
+      ch = fgetc(stream);
3060
+   } else {
3061
+      neg = MP_ZPOS;
3062
+   }
3063
+   
3064
+   for (;;) {
3065
+      /* find y in the radix map */
3066
+      for (y = 0; y < radix; y++) {
3067
+          if (mp_s_rmap[y] == ch) {
3068
+             break;
3069
+          }
3070
+      }
3071
+      if (y == radix) {
3072
+         break;
3073
+      }
3074
+      
3075
+      /* shift up and add */
3076
+      if ((err = mp_mul_d(a, radix, a)) != MP_OKAY) {
3077
+         return err;
3078
+      }
3079
+      if ((err = mp_add_d(a, y, a)) != MP_OKAY) {
3080
+         return err;
3081
+      }
3082
+      
3083
+      ch = fgetc(stream);
3084
+   }
3085
+   if (mp_cmp_d(a, 0) != MP_EQ) {
3086
+      a->sign = neg;
3087
+   }
3088
+   
3089
+   return MP_OKAY;
3090
+}
3091
+
3092
+#endif
3093
+
3094
+/* $Source: /cvs/libtom/libtommath/bn_mp_fread.c,v $ */
3095
+/* $Revision: 1.3 $ */
3096
+/* $Date: 2006/03/31 14:18:44 $ */
3097
+
3098
+/* End: bn_mp_fread.c */
3099
+
3100
+/* Start: bn_mp_fwrite.c */
3101
+#include <bignum.h>
3102
+#ifdef BN_MP_FWRITE_C
3103
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
3104
+ *
3105
+ * LibTomMath is a library that provides multiple-precision
3106
+ * integer arithmetic as well as number theoretic functionality.
3107
+ *
3108
+ * The library was designed directly after the MPI library by
3109
+ * Michael Fromberger but has been written from scratch with
3110
+ * additional optimizations in place.
3111
+ *
3112
+ * The library is free for all purposes without any express
3113
+ * guarantee it works.
3114
+ *
3115
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
3116
+ */
3117
+
3118
+int mp_fwrite(mp_int *a, int radix, FILE *stream)
3119
+{
3120
+   char *buf;
3121
+   int err, len, x;
3122
+   
3123
+   if ((err = mp_radix_size(a, radix, &len)) != MP_OKAY) {
3124
+      return err;
3125
+   }
3126
+
3127
+   buf = OPT_CAST(char) cli_malloc (len);
3128
+   if (buf == NULL) {
3129
+      return MP_MEM;
3130
+   }
3131
+   
3132
+   if ((err = mp_toradix(a, buf, radix)) != MP_OKAY) {
3133
+      free (buf);
3134
+      return err;
3135
+   }
3136
+   
3137
+   for (x = 0; x < len; x++) {
3138
+       if (fputc(buf[x], stream) == EOF) {
3139
+          free (buf);
3140
+          return MP_VAL;
3141
+       }
3142
+   }
3143
+   
3144
+   free (buf);
3145
+   return MP_OKAY;
3146
+}
3147
+
3148
+#endif
3149
+
3150
+/* $Source: /cvs/libtom/libtommath/bn_mp_fwrite.c,v $ */
3151
+/* $Revision: 1.3 $ */
3152
+/* $Date: 2006/03/31 14:18:44 $ */
3153
+
3154
+/* End: bn_mp_fwrite.c */
3155
+
3156
+/* Start: bn_mp_gcd.c */
3157
+#include <bignum.h>
3158
+#ifdef BN_MP_GCD_C
3159
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
3160
+ *
3161
+ * LibTomMath is a library that provides multiple-precision
3162
+ * integer arithmetic as well as number theoretic functionality.
3163
+ *
3164
+ * The library was designed directly after the MPI library by
3165
+ * Michael Fromberger but has been written from scratch with
3166
+ * additional optimizations in place.
3167
+ *
3168
+ * The library is free for all purposes without any express
3169
+ * guarantee it works.
3170
+ *
3171
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
3172
+ */
3173
+
3174
+/* Greatest Common Divisor using the binary method */
3175
+int mp_gcd (mp_int * a, mp_int * b, mp_int * c)
3176
+{
3177
+  mp_int  u, v;
3178
+  int     k, u_lsb, v_lsb, res;
3179
+
3180
+  /* either zero than gcd is the largest */
3181
+  if (mp_iszero (a) == MP_YES) {
3182
+    return mp_abs (b, c);
3183
+  }
3184
+  if (mp_iszero (b) == MP_YES) {
3185
+    return mp_abs (a, c);
3186
+  }
3187
+
3188
+  /* get copies of a and b we can modify */
3189
+  if ((res = mp_init_copy (&u, a)) != MP_OKAY) {
3190
+    return res;
3191
+  }
3192
+
3193
+  if ((res = mp_init_copy (&v, b)) != MP_OKAY) {
3194
+    goto LBL_U;
3195
+  }
3196
+
3197
+  /* must be positive for the remainder of the algorithm */
3198
+  u.sign = v.sign = MP_ZPOS;
3199
+
3200
+  /* B1.  Find the common power of two for u and v */
3201
+  u_lsb = mp_cnt_lsb(&u);
3202
+  v_lsb = mp_cnt_lsb(&v);
3203
+  k     = MIN(u_lsb, v_lsb);
3204
+
3205
+  if (k > 0) {
3206
+     /* divide the power of two out */
3207
+     if ((res = mp_div_2d(&u, k, &u, NULL)) != MP_OKAY) {
3208
+        goto LBL_V;
3209
+     }
3210
+
3211
+     if ((res = mp_div_2d(&v, k, &v, NULL)) != MP_OKAY) {
3212
+        goto LBL_V;
3213
+     }
3214
+  }
3215
+
3216
+  /* divide any remaining factors of two out */
3217
+  if (u_lsb != k) {
3218
+     if ((res = mp_div_2d(&u, u_lsb - k, &u, NULL)) != MP_OKAY) {
3219
+        goto LBL_V;
3220
+     }
3221
+  }
3222
+
3223
+  if (v_lsb != k) {
3224
+     if ((res = mp_div_2d(&v, v_lsb - k, &v, NULL)) != MP_OKAY) {
3225
+        goto LBL_V;
3226
+     }
3227
+  }
3228
+
3229
+  while (mp_iszero(&v) == 0) {
3230
+     /* make sure v is the largest */
3231
+     if (mp_cmp_mag(&u, &v) == MP_GT) {
3232
+        /* swap u and v to make sure v is >= u */
3233
+        mp_exch(&u, &v);
3234
+     }
3235
+     
3236
+     /* subtract smallest from largest */
3237
+     if ((res = s_mp_sub(&v, &u, &v)) != MP_OKAY) {
3238
+        goto LBL_V;
3239
+     }
3240
+     
3241
+     /* Divide out all factors of two */
3242
+     if ((res = mp_div_2d(&v, mp_cnt_lsb(&v), &v, NULL)) != MP_OKAY) {
3243
+        goto LBL_V;
3244
+     } 
3245
+  } 
3246
+
3247
+  /* multiply by 2**k which we divided out at the beginning */
3248
+  if ((res = mp_mul_2d (&u, k, c)) != MP_OKAY) {
3249
+     goto LBL_V;
3250
+  }
3251
+  c->sign = MP_ZPOS;
3252
+  res = MP_OKAY;
3253
+LBL_V:mp_clear (&u);
3254
+LBL_U:mp_clear (&v);
3255
+  return res;
3256
+}
3257
+#endif
3258
+
3259
+/* $Source: /cvs/libtom/libtommath/bn_mp_gcd.c,v $ */
3260
+/* $Revision: 1.4 $ */
3261
+/* $Date: 2006/03/31 14:18:44 $ */
3262
+
3263
+/* End: bn_mp_gcd.c */
3264
+
3265
+/* Start: bn_mp_get_int.c */
3266
+#include <bignum.h>
3267
+#ifdef BN_MP_GET_INT_C
3268
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
3269
+ *
3270
+ * LibTomMath is a library that provides multiple-precision
3271
+ * integer arithmetic as well as number theoretic functionality.
3272
+ *
3273
+ * The library was designed directly after the MPI library by
3274
+ * Michael Fromberger but has been written from scratch with
3275
+ * additional optimizations in place.
3276
+ *
3277
+ * The library is free for all purposes without any express
3278
+ * guarantee it works.
3279
+ *
3280
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
3281
+ */
3282
+
3283
+/* get the lower 32-bits of an mp_int */
3284
+unsigned long mp_get_int(mp_int * a) 
3285
+{
3286
+  int i;
3287
+  unsigned long res;
3288
+
3289
+  if (a->used == 0) {
3290
+     return 0;
3291
+  }
3292
+
3293
+  /* get number of digits of the lsb we have to read */
3294
+  i = MIN(a->used,(int)((sizeof(unsigned long)*CHAR_BIT+DIGIT_BIT-1)/DIGIT_BIT))-1;
3295
+
3296
+  /* get most significant digit of result */
3297
+  res = DIGIT(a,i);
3298
+   
3299
+  while (--i >= 0) {
3300
+    res = (res << DIGIT_BIT) | DIGIT(a,i);
3301
+  }
3302
+
3303
+  /* force result to 32-bits always so it is consistent on non 32-bit platforms */
3304
+  return res & 0xFFFFFFFFUL;
3305
+}
3306
+#endif
3307
+
3308
+/* $Source: /cvs/libtom/libtommath/bn_mp_get_int.c,v $ */
3309
+/* $Revision: 1.3 $ */
3310
+/* $Date: 2006/03/31 14:18:44 $ */
3311
+
3312
+/* End: bn_mp_get_int.c */
3313
+
3314
+/* Start: bn_mp_grow.c */
3315
+#include <bignum.h>
3316
+#ifdef BN_MP_GROW_C
3317
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
3318
+ *
3319
+ * LibTomMath is a library that provides multiple-precision
3320
+ * integer arithmetic as well as number theoretic functionality.
3321
+ *
3322
+ * The library was designed directly after the MPI library by
3323
+ * Michael Fromberger but has been written from scratch with
3324
+ * additional optimizations in place.
3325
+ *
3326
+ * The library is free for all purposes without any express
3327
+ * guarantee it works.
3328
+ *
3329
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
3330
+ */
3331
+
3332
+/* grow as required */
3333
+int mp_grow (mp_int * a, int size)
3334
+{
3335
+  int     i;
3336
+  mp_digit *tmp;
3337
+
3338
+  /* if the alloc size is smaller alloc more ram */
3339
+  if (a->alloc < size) {
3340
+    /* ensure there are always at least MP_PREC digits extra on top */
3341
+    size += (MP_PREC * 2) - (size % MP_PREC);
3342
+
3343
+    /* reallocate the array a->dp
3344
+     *
3345
+     * We store the return in a temporary variable
3346
+     * in case the operation failed we don't want
3347
+     * to overwrite the dp member of a.
3348
+     */
3349
+    tmp = OPT_CAST(mp_digit) cli_realloc (a->dp, sizeof (mp_digit) * size);
3350
+    if (tmp == NULL) {
3351
+      /* reallocation failed but "a" is still valid [can be freed] */
3352
+      return MP_MEM;
3353
+    }
3354
+
3355
+    /* reallocation succeeded so set a->dp */
3356
+    a->dp = tmp;
3357
+
3358
+    /* zero excess digits */
3359
+    i        = a->alloc;
3360
+    a->alloc = size;
3361
+    for (; i < a->alloc; i++) {
3362
+      a->dp[i] = 0;
3363
+    }
3364
+  }
3365
+  return MP_OKAY;
3366
+}
3367
+#endif
3368
+
3369
+/* $Source: /cvs/libtom/libtommath/bn_mp_grow.c,v $ */
3370
+/* $Revision: 1.3 $ */
3371
+/* $Date: 2006/03/31 14:18:44 $ */
3372
+
3373
+/* End: bn_mp_grow.c */
3374
+
3375
+/* Start: bn_mp_init.c */
3376
+#include <bignum.h>
3377
+#ifdef BN_MP_INIT_C
3378
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
3379
+ *
3380
+ * LibTomMath is a library that provides multiple-precision
3381
+ * integer arithmetic as well as number theoretic functionality.
3382
+ *
3383
+ * The library was designed directly after the MPI library by
3384
+ * Michael Fromberger but has been written from scratch with
3385
+ * additional optimizations in place.
3386
+ *
3387
+ * The library is free for all purposes without any express
3388
+ * guarantee it works.
3389
+ *
3390
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
3391
+ */
3392
+
3393
+/* init a new mp_int */
3394
+int mp_init (mp_int * a)
3395
+{
3396
+  int i;
3397
+
3398
+  /* allocate memory required and clear it */
3399
+  a->dp = OPT_CAST(mp_digit) cli_malloc (sizeof (mp_digit) * MP_PREC);
3400
+  if (a->dp == NULL) {
3401
+    return MP_MEM;
3402
+  }
3403
+
3404
+  /* set the digits to zero */
3405
+  for (i = 0; i < MP_PREC; i++) {
3406
+      a->dp[i] = 0;
3407
+  }
3408
+
3409
+  /* set the used to zero, allocated digits to the default precision
3410
+   * and sign to positive */
3411
+  a->used  = 0;
3412
+  a->alloc = MP_PREC;
3413
+  a->sign  = MP_ZPOS;
3414
+
3415
+  return MP_OKAY;
3416
+}
3417
+#endif
3418
+
3419
+/* $Source: /cvs/libtom/libtommath/bn_mp_init.c,v $ */
3420
+/* $Revision: 1.3 $ */
3421
+/* $Date: 2006/03/31 14:18:44 $ */
3422
+
3423
+/* End: bn_mp_init.c */
3424
+
3425
+/* Start: bn_mp_init_copy.c */
3426
+#include <bignum.h>
3427
+#ifdef BN_MP_INIT_COPY_C
3428
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
3429
+ *
3430
+ * LibTomMath is a library that provides multiple-precision
3431
+ * integer arithmetic as well as number theoretic functionality.
3432
+ *
3433
+ * The library was designed directly after the MPI library by
3434
+ * Michael Fromberger but has been written from scratch with
3435
+ * additional optimizations in place.
3436
+ *
3437
+ * The library is free for all purposes without any express
3438
+ * guarantee it works.
3439
+ *
3440
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
3441
+ */
3442
+
3443
+/* creates "a" then copies b into it */
3444
+int mp_init_copy (mp_int * a, mp_int * b)
3445
+{
3446
+  int     res;
3447
+
3448
+  if ((res = mp_init (a)) != MP_OKAY) {
3449
+    return res;
3450
+  }
3451
+  return mp_copy (b, a);
3452
+}
3453
+#endif
3454
+
3455
+/* $Source: /cvs/libtom/libtommath/bn_mp_init_copy.c,v $ */
3456
+/* $Revision: 1.3 $ */
3457
+/* $Date: 2006/03/31 14:18:44 $ */
3458
+
3459
+/* End: bn_mp_init_copy.c */
3460
+
3461
+/* Start: bn_mp_init_multi.c */
3462
+#include <bignum.h>
3463
+#ifdef BN_MP_INIT_MULTI_C
3464
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
3465
+ *
3466
+ * LibTomMath is a library that provides multiple-precision
3467
+ * integer arithmetic as well as number theoretic functionality.
3468
+ *
3469
+ * The library was designed directly after the MPI library by
3470
+ * Michael Fromberger but has been written from scratch with
3471
+ * additional optimizations in place.
3472
+ *
3473
+ * The library is free for all purposes without any express
3474
+ * guarantee it works.
3475
+ *
3476
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
3477
+ */
3478
+#include <stdarg.h>
3479
+
3480
+int mp_init_multi(mp_int *mp, ...) 
3481
+{
3482
+    mp_err res = MP_OKAY;      /* Assume ok until proven otherwise */
3483
+    int n = 0;                 /* Number of ok inits */
3484
+    mp_int* cur_arg = mp;
3485
+    va_list args;
3486
+
3487
+    va_start(args, mp);        /* init args to next argument from caller */
3488
+    while (cur_arg != NULL) {
3489
+        if (mp_init(cur_arg) != MP_OKAY) {
3490
+            /* Oops - error! Back-track and mp_clear what we already
3491
+               succeeded in init-ing, then return error.
3492
+            */
3493
+            va_list clean_args;
3494
+            
3495
+            /* end the current list */
3496
+            va_end(args);
3497
+            
3498
+            /* now start cleaning up */            
3499
+            cur_arg = mp;
3500
+            va_start(clean_args, mp);
3501
+            while (n--) {
3502
+                mp_clear(cur_arg);
3503
+                cur_arg = va_arg(clean_args, mp_int*);
3504
+            }
3505
+            va_end(clean_args);
3506
+            res = MP_MEM;
3507
+            break;
3508
+        }
3509
+        n++;
3510
+        cur_arg = va_arg(args, mp_int*);
3511
+    }
3512
+    va_end(args);
3513
+    return res;                /* Assumed ok, if error flagged above. */
3514
+}
3515
+
3516
+#endif
3517
+
3518
+/* $Source: /cvs/libtom/libtommath/bn_mp_init_multi.c,v $ */
3519
+/* $Revision: 1.3 $ */
3520
+/* $Date: 2006/03/31 14:18:44 $ */
3521
+
3522
+/* End: bn_mp_init_multi.c */
3523
+
3524
+/* Start: bn_mp_init_set.c */
3525
+#include <bignum.h>
3526
+#ifdef BN_MP_INIT_SET_C
3527
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
3528
+ *
3529
+ * LibTomMath is a library that provides multiple-precision
3530
+ * integer arithmetic as well as number theoretic functionality.
3531
+ *
3532
+ * The library was designed directly after the MPI library by
3533
+ * Michael Fromberger but has been written from scratch with
3534
+ * additional optimizations in place.
3535
+ *
3536
+ * The library is free for all purposes without any express
3537
+ * guarantee it works.
3538
+ *
3539
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
3540
+ */
3541
+
3542
+/* initialize and set a digit */
3543
+int mp_init_set (mp_int * a, mp_digit b)
3544
+{
3545
+  int err;
3546
+  if ((err = mp_init(a)) != MP_OKAY) {
3547
+     return err;
3548
+  }
3549
+  mp_set(a, b);
3550
+  return err;
3551
+}
3552
+#endif
3553
+
3554
+/* $Source: /cvs/libtom/libtommath/bn_mp_init_set.c,v $ */
3555
+/* $Revision: 1.3 $ */
3556
+/* $Date: 2006/03/31 14:18:44 $ */
3557
+
3558
+/* End: bn_mp_init_set.c */
3559
+
3560
+/* Start: bn_mp_init_set_int.c */
3561
+#include <bignum.h>
3562
+#ifdef BN_MP_INIT_SET_INT_C
3563
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
3564
+ *
3565
+ * LibTomMath is a library that provides multiple-precision
3566
+ * integer arithmetic as well as number theoretic functionality.
3567
+ *
3568
+ * The library was designed directly after the MPI library by
3569
+ * Michael Fromberger but has been written from scratch with
3570
+ * additional optimizations in place.
3571
+ *
3572
+ * The library is free for all purposes without any express
3573
+ * guarantee it works.
3574
+ *
3575
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
3576
+ */
3577
+
3578
+/* initialize and set a digit */
3579
+int mp_init_set_int (mp_int * a, unsigned long b)
3580
+{
3581
+  int err;
3582
+  if ((err = mp_init(a)) != MP_OKAY) {
3583
+     return err;
3584
+  }
3585
+  return mp_set_int(a, b);
3586
+}
3587
+#endif
3588
+
3589
+/* $Source: /cvs/libtom/libtommath/bn_mp_init_set_int.c,v $ */
3590
+/* $Revision: 1.3 $ */
3591
+/* $Date: 2006/03/31 14:18:44 $ */
3592
+
3593
+/* End: bn_mp_init_set_int.c */
3594
+
3595
+/* Start: bn_mp_init_size.c */
3596
+#include <bignum.h>
3597
+#ifdef BN_MP_INIT_SIZE_C
3598
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
3599
+ *
3600
+ * LibTomMath is a library that provides multiple-precision
3601
+ * integer arithmetic as well as number theoretic functionality.
3602
+ *
3603
+ * The library was designed directly after the MPI library by
3604
+ * Michael Fromberger but has been written from scratch with
3605
+ * additional optimizations in place.
3606
+ *
3607
+ * The library is free for all purposes without any express
3608
+ * guarantee it works.
3609
+ *
3610
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
3611
+ */
3612
+
3613
+/* init an mp_init for a given size */
3614
+int mp_init_size (mp_int * a, int size)
3615
+{
3616
+  int x;
3617
+
3618
+  /* pad size so there are always extra digits */
3619
+  size += (MP_PREC * 2) - (size % MP_PREC);	
3620
+  
3621
+  /* alloc mem */
3622
+  a->dp = OPT_CAST(mp_digit) cli_malloc (sizeof (mp_digit) * size);
3623
+  if (a->dp == NULL) {
3624
+    return MP_MEM;
3625
+  }
3626
+
3627
+  /* set the members */
3628
+  a->used  = 0;
3629
+  a->alloc = size;
3630
+  a->sign  = MP_ZPOS;
3631
+
3632
+  /* zero the digits */
3633
+  for (x = 0; x < size; x++) {
3634
+      a->dp[x] = 0;
3635
+  }
3636
+
3637
+  return MP_OKAY;
3638
+}
3639
+#endif
3640
+
3641
+/* $Source: /cvs/libtom/libtommath/bn_mp_init_size.c,v $ */
3642
+/* $Revision: 1.3 $ */
3643
+/* $Date: 2006/03/31 14:18:44 $ */
3644
+
3645
+/* End: bn_mp_init_size.c */
3646
+
3647
+/* Start: bn_mp_invmod.c */
3648
+#include <bignum.h>
3649
+#ifdef BN_MP_INVMOD_C
3650
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
3651
+ *
3652
+ * LibTomMath is a library that provides multiple-precision
3653
+ * integer arithmetic as well as number theoretic functionality.
3654
+ *
3655
+ * The library was designed directly after the MPI library by
3656
+ * Michael Fromberger but has been written from scratch with
3657
+ * additional optimizations in place.
3658
+ *
3659
+ * The library is free for all purposes without any express
3660
+ * guarantee it works.
3661
+ *
3662
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
3663
+ */
3664
+
3665
+/* hac 14.61, pp608 */
3666
+int mp_invmod (mp_int * a, mp_int * b, mp_int * c)
3667
+{
3668
+  /* b cannot be negative */
3669
+  if (b->sign == MP_NEG || mp_iszero(b) == 1) {
3670
+    return MP_VAL;
3671
+  }
3672
+
3673
+#ifdef BN_FAST_MP_INVMOD_C
3674
+  /* if the modulus is odd we can use a faster routine instead */
3675
+  if (mp_isodd (b) == 1) {
3676
+    return fast_mp_invmod (a, b, c);
3677
+  }
3678
+#endif
3679
+
3680
+#ifdef BN_MP_INVMOD_SLOW_C
3681
+  return mp_invmod_slow(a, b, c);
3682
+#endif
3683
+
3684
+  return MP_VAL;
3685
+}
3686
+#endif
3687
+
3688
+/* $Source: /cvs/libtom/libtommath/bn_mp_invmod.c,v $ */
3689
+/* $Revision: 1.3 $ */
3690
+/* $Date: 2006/03/31 14:18:44 $ */
3691
+
3692
+/* End: bn_mp_invmod.c */
3693
+
3694
+/* Start: bn_mp_invmod_slow.c */
3695
+#include <bignum.h>
3696
+#ifdef BN_MP_INVMOD_SLOW_C
3697
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
3698
+ *
3699
+ * LibTomMath is a library that provides multiple-precision
3700
+ * integer arithmetic as well as number theoretic functionality.
3701
+ *
3702
+ * The library was designed directly after the MPI library by
3703
+ * Michael Fromberger but has been written from scratch with
3704
+ * additional optimizations in place.
3705
+ *
3706
+ * The library is free for all purposes without any express
3707
+ * guarantee it works.
3708
+ *
3709
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
3710
+ */
3711
+
3712
+/* hac 14.61, pp608 */
3713
+int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c)
3714
+{
3715
+  mp_int  x, y, u, v, A, B, C, D;
3716
+  int     res;
3717
+
3718
+  /* b cannot be negative */
3719
+  if (b->sign == MP_NEG || mp_iszero(b) == 1) {
3720
+    return MP_VAL;
3721
+  }
3722
+
3723
+  /* init temps */
3724
+  if ((res = mp_init_multi(&x, &y, &u, &v, 
3725
+                           &A, &B, &C, &D, NULL)) != MP_OKAY) {
3726
+     return res;
3727
+  }
3728
+
3729
+  /* x = a, y = b */
3730
+  if ((res = mp_mod(a, b, &x)) != MP_OKAY) {
3731
+      goto LBL_ERR;
3732
+  }
3733
+  if ((res = mp_copy (b, &y)) != MP_OKAY) {
3734
+    goto LBL_ERR;
3735
+  }
3736
+
3737
+  /* 2. [modified] if x,y are both even then return an error! */
3738
+  if (mp_iseven (&x) == 1 && mp_iseven (&y) == 1) {
3739
+    res = MP_VAL;
3740
+    goto LBL_ERR;
3741
+  }
3742
+
3743
+  /* 3. u=x, v=y, A=1, B=0, C=0,D=1 */
3744
+  if ((res = mp_copy (&x, &u)) != MP_OKAY) {
3745
+    goto LBL_ERR;
3746
+  }
3747
+  if ((res = mp_copy (&y, &v)) != MP_OKAY) {
3748
+    goto LBL_ERR;
3749
+  }
3750
+  mp_set (&A, 1);
3751
+  mp_set (&D, 1);
3752
+
3753
+top:
3754
+  /* 4.  while u is even do */
3755
+  while (mp_iseven (&u) == 1) {
3756
+    /* 4.1 u = u/2 */
3757
+    if ((res = mp_div_2 (&u, &u)) != MP_OKAY) {
3758
+      goto LBL_ERR;
3759
+    }
3760
+    /* 4.2 if A or B is odd then */
3761
+    if (mp_isodd (&A) == 1 || mp_isodd (&B) == 1) {
3762
+      /* A = (A+y)/2, B = (B-x)/2 */
3763
+      if ((res = mp_add (&A, &y, &A)) != MP_OKAY) {
3764
+         goto LBL_ERR;
3765
+      }
3766
+      if ((res = mp_sub (&B, &x, &B)) != MP_OKAY) {
3767
+         goto LBL_ERR;
3768
+      }
3769
+    }
3770
+    /* A = A/2, B = B/2 */
3771
+    if ((res = mp_div_2 (&A, &A)) != MP_OKAY) {
3772
+      goto LBL_ERR;
3773
+    }
3774
+    if ((res = mp_div_2 (&B, &B)) != MP_OKAY) {
3775
+      goto LBL_ERR;
3776
+    }
3777
+  }
3778
+
3779
+  /* 5.  while v is even do */
3780
+  while (mp_iseven (&v) == 1) {
3781
+    /* 5.1 v = v/2 */
3782
+    if ((res = mp_div_2 (&v, &v)) != MP_OKAY) {
3783
+      goto LBL_ERR;
3784
+    }
3785
+    /* 5.2 if C or D is odd then */
3786
+    if (mp_isodd (&C) == 1 || mp_isodd (&D) == 1) {
3787
+      /* C = (C+y)/2, D = (D-x)/2 */
3788
+      if ((res = mp_add (&C, &y, &C)) != MP_OKAY) {
3789
+         goto LBL_ERR;
3790
+      }
3791
+      if ((res = mp_sub (&D, &x, &D)) != MP_OKAY) {
3792
+         goto LBL_ERR;
3793
+      }
3794
+    }
3795
+    /* C = C/2, D = D/2 */
3796
+    if ((res = mp_div_2 (&C, &C)) != MP_OKAY) {
3797
+      goto LBL_ERR;
3798
+    }
3799
+    if ((res = mp_div_2 (&D, &D)) != MP_OKAY) {
3800
+      goto LBL_ERR;
3801
+    }
3802
+  }
3803
+
3804
+  /* 6.  if u >= v then */
3805
+  if (mp_cmp (&u, &v) != MP_LT) {
3806
+    /* u = u - v, A = A - C, B = B - D */
3807
+    if ((res = mp_sub (&u, &v, &u)) != MP_OKAY) {
3808
+      goto LBL_ERR;
3809
+    }
3810
+
3811
+    if ((res = mp_sub (&A, &C, &A)) != MP_OKAY) {
3812
+      goto LBL_ERR;
3813
+    }
3814
+
3815
+    if ((res = mp_sub (&B, &D, &B)) != MP_OKAY) {
3816
+      goto LBL_ERR;
3817
+    }
3818
+  } else {
3819
+    /* v - v - u, C = C - A, D = D - B */
3820
+    if ((res = mp_sub (&v, &u, &v)) != MP_OKAY) {
3821
+      goto LBL_ERR;
3822
+    }
3823
+
3824
+    if ((res = mp_sub (&C, &A, &C)) != MP_OKAY) {
3825
+      goto LBL_ERR;
3826
+    }
3827
+
3828
+    if ((res = mp_sub (&D, &B, &D)) != MP_OKAY) {
3829
+      goto LBL_ERR;
3830
+    }
3831
+  }
3832
+
3833
+  /* if not zero goto step 4 */
3834
+  if (mp_iszero (&u) == 0)
3835
+    goto top;
3836
+
3837
+  /* now a = C, b = D, gcd == g*v */
3838
+
3839
+  /* if v != 1 then there is no inverse */
3840
+  if (mp_cmp_d (&v, 1) != MP_EQ) {
3841
+    res = MP_VAL;
3842
+    goto LBL_ERR;
3843
+  }
3844
+
3845
+  /* if its too low */
3846
+  while (mp_cmp_d(&C, 0) == MP_LT) {
3847
+      if ((res = mp_add(&C, b, &C)) != MP_OKAY) {
3848
+         goto LBL_ERR;
3849
+      }
3850
+  }
3851
+  
3852
+  /* too big */
3853
+  while (mp_cmp_mag(&C, b) != MP_LT) {
3854
+      if ((res = mp_sub(&C, b, &C)) != MP_OKAY) {
3855
+         goto LBL_ERR;
3856
+      }
3857
+  }
3858
+  
3859
+  /* C is now the inverse */
3860
+  mp_exch (&C, c);
3861
+  res = MP_OKAY;
3862
+LBL_ERR:mp_clear_multi (&x, &y, &u, &v, &A, &B, &C, &D, NULL);
3863
+  return res;
3864
+}
3865
+#endif
3866
+
3867
+/* $Source: /cvs/libtom/libtommath/bn_mp_invmod_slow.c,v $ */
3868
+/* $Revision: 1.3 $ */
3869
+/* $Date: 2006/03/31 14:18:44 $ */
3870
+
3871
+/* End: bn_mp_invmod_slow.c */
3872
+
3873
+/* Start: bn_mp_is_square.c */
3874
+#include <bignum.h>
3875
+#ifdef BN_MP_IS_SQUARE_C
3876
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
3877
+ *
3878
+ * LibTomMath is a library that provides multiple-precision
3879
+ * integer arithmetic as well as number theoretic functionality.
3880
+ *
3881
+ * The library was designed directly after the MPI library by
3882
+ * Michael Fromberger but has been written from scratch with
3883
+ * additional optimizations in place.
3884
+ *
3885
+ * The library is free for all purposes without any express
3886
+ * guarantee it works.
3887
+ *
3888
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
3889
+ */
3890
+
3891
+/* Check if remainders are possible squares - fast exclude non-squares */
3892
+static const char rem_128[128] = {
3893
+ 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
3894
+ 0, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
3895
+ 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
3896
+ 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
3897
+ 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
3898
+ 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
3899
+ 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1,
3900
+ 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1
3901
+};
3902
+
3903
+static const char rem_105[105] = {
3904
+ 0, 0, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1,
3905
+ 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1,
3906
+ 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1,
3907
+ 1, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 1,
3908
+ 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1,
3909
+ 1, 1, 1, 1, 0, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1,
3910
+ 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1
3911
+};
3912
+
3913
+/* Store non-zero to ret if arg is square, and zero if not */
3914
+int mp_is_square(mp_int *arg,int *ret) 
3915
+{
3916
+  int           res;
3917
+  mp_digit      c;
3918
+  mp_int        t;
3919
+  unsigned long r;
3920
+
3921
+  /* Default to Non-square :) */
3922
+  *ret = MP_NO; 
3923
+
3924
+  if (arg->sign == MP_NEG) {
3925
+    return MP_VAL;
3926
+  }
3927
+
3928
+  /* digits used?  (TSD) */
3929
+  if (arg->used == 0) {
3930
+     return MP_OKAY;
3931
+  }
3932
+
3933
+  /* First check mod 128 (suppose that DIGIT_BIT is at least 7) */
3934
+  if (rem_128[127 & DIGIT(arg,0)] == 1) {
3935
+     return MP_OKAY;
3936
+  }
3937
+
3938
+  /* Next check mod 105 (3*5*7) */
3939
+  if ((res = mp_mod_d(arg,105,&c)) != MP_OKAY) {
3940
+     return res;
3941
+  }
3942
+  if (rem_105[c] == 1) {
3943
+     return MP_OKAY;
3944
+  }
3945
+
3946
+
3947
+  if ((res = mp_init_set_int(&t,11L*13L*17L*19L*23L*29L*31L)) != MP_OKAY) {
3948
+     return res;
3949
+  }
3950
+  if ((res = mp_mod(arg,&t,&t)) != MP_OKAY) {
3951
+     goto ERR;
3952
+  }
3953
+  r = mp_get_int(&t);
3954
+  /* Check for other prime modules, note it's not an ERROR but we must
3955
+   * free "t" so the easiest way is to goto ERR.  We know that res
3956
+   * is already equal to MP_OKAY from the mp_mod call 
3957
+   */ 
3958
+  if ( (1L<<(r%11)) & 0x5C4L )             goto ERR;
3959
+  if ( (1L<<(r%13)) & 0x9E4L )             goto ERR;
3960
+  if ( (1L<<(r%17)) & 0x5CE8L )            goto ERR;
3961
+  if ( (1L<<(r%19)) & 0x4F50CL )           goto ERR;
3962
+  if ( (1L<<(r%23)) & 0x7ACCA0L )          goto ERR;
3963
+  if ( (1L<<(r%29)) & 0xC2EDD0CL )         goto ERR;
3964
+  if ( (1L<<(r%31)) & 0x6DE2B848L )        goto ERR;
3965
+
3966
+  /* Final check - is sqr(sqrt(arg)) == arg ? */
3967
+  if ((res = mp_sqrt(arg,&t)) != MP_OKAY) {
3968
+     goto ERR;
3969
+  }
3970
+  if ((res = mp_sqr(&t,&t)) != MP_OKAY) {
3971
+     goto ERR;
3972
+  }
3973
+
3974
+  *ret = (mp_cmp_mag(&t,arg) == MP_EQ) ? MP_YES : MP_NO;
3975
+ERR:mp_clear(&t);
3976
+  return res;
3977
+}
3978
+#endif
3979
+
3980
+/* $Source: /cvs/libtom/libtommath/bn_mp_is_square.c,v $ */
3981
+/* $Revision: 1.3 $ */
3982
+/* $Date: 2006/03/31 14:18:44 $ */
3983
+
3984
+/* End: bn_mp_is_square.c */
3985
+
3986
+/* Start: bn_mp_jacobi.c */
3987
+#include <bignum.h>
3988
+#ifdef BN_MP_JACOBI_C
3989
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
3990
+ *
3991
+ * LibTomMath is a library that provides multiple-precision
3992
+ * integer arithmetic as well as number theoretic functionality.
3993
+ *
3994
+ * The library was designed directly after the MPI library by
3995
+ * Michael Fromberger but has been written from scratch with
3996
+ * additional optimizations in place.
3997
+ *
3998
+ * The library is free for all purposes without any express
3999
+ * guarantee it works.
4000
+ *
4001
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
4002
+ */
4003
+
4004
+/* computes the jacobi c = (a | n) (or Legendre if n is prime)
4005
+ * HAC pp. 73 Algorithm 2.149
4006
+ */
4007
+int mp_jacobi (mp_int * a, mp_int * p, int *c)
4008
+{
4009
+  mp_int  a1, p1;
4010
+  int     k, s, r, res;
4011
+  mp_digit residue;
4012
+
4013
+  /* if p <= 0 return MP_VAL */
4014
+  if (mp_cmp_d(p, 0) != MP_GT) {
4015
+     return MP_VAL;
4016
+  }
4017
+
4018
+  /* step 1.  if a == 0, return 0 */
4019
+  if (mp_iszero (a) == 1) {
4020
+    *c = 0;
4021
+    return MP_OKAY;
4022
+  }
4023
+
4024
+  /* step 2.  if a == 1, return 1 */
4025
+  if (mp_cmp_d (a, 1) == MP_EQ) {
4026
+    *c = 1;
4027
+    return MP_OKAY;
4028
+  }
4029
+
4030
+  /* default */
4031
+  s = 0;
4032
+
4033
+  /* step 3.  write a = a1 * 2**k  */
4034
+  if ((res = mp_init_copy (&a1, a)) != MP_OKAY) {
4035
+    return res;
4036
+  }
4037
+
4038
+  if ((res = mp_init (&p1)) != MP_OKAY) {
4039
+    goto LBL_A1;
4040
+  }
4041
+
4042
+  /* divide out larger power of two */
4043
+  k = mp_cnt_lsb(&a1);
4044
+  if ((res = mp_div_2d(&a1, k, &a1, NULL)) != MP_OKAY) {
4045
+     goto LBL_P1;
4046
+  }
4047
+
4048
+  /* step 4.  if e is even set s=1 */
4049
+  if ((k & 1) == 0) {
4050
+    s = 1;
4051
+  } else {
4052
+    /* else set s=1 if p = 1/7 (mod 8) or s=-1 if p = 3/5 (mod 8) */
4053
+    residue = p->dp[0] & 7;
4054
+
4055
+    if (residue == 1 || residue == 7) {
4056
+      s = 1;
4057
+    } else if (residue == 3 || residue == 5) {
4058
+      s = -1;
4059
+    }
4060
+  }
4061
+
4062
+  /* step 5.  if p == 3 (mod 4) *and* a1 == 3 (mod 4) then s = -s */
4063
+  if ( ((p->dp[0] & 3) == 3) && ((a1.dp[0] & 3) == 3)) {
4064
+    s = -s;
4065
+  }
4066
+
4067
+  /* if a1 == 1 we're done */
4068
+  if (mp_cmp_d (&a1, 1) == MP_EQ) {
4069
+    *c = s;
4070
+  } else {
4071
+    /* n1 = n mod a1 */
4072
+    if ((res = mp_mod (p, &a1, &p1)) != MP_OKAY) {
4073
+      goto LBL_P1;
4074
+    }
4075
+    if ((res = mp_jacobi (&p1, &a1, &r)) != MP_OKAY) {
4076
+      goto LBL_P1;
4077
+    }
4078
+    *c = s * r;
4079
+  }
4080
+
4081
+  /* done */
4082
+  res = MP_OKAY;
4083
+LBL_P1:mp_clear (&p1);
4084
+LBL_A1:mp_clear (&a1);
4085
+  return res;
4086
+}
4087
+#endif
4088
+
4089
+/* $Source: /cvs/libtom/libtommath/bn_mp_jacobi.c,v $ */
4090
+/* $Revision: 1.3 $ */
4091
+/* $Date: 2006/03/31 14:18:44 $ */
4092
+
4093
+/* End: bn_mp_jacobi.c */
4094
+
4095
+/* Start: bn_mp_karatsuba_mul.c */
4096
+#include <bignum.h>
4097
+#ifdef BN_MP_KARATSUBA_MUL_C
4098
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
4099
+ *
4100
+ * LibTomMath is a library that provides multiple-precision
4101
+ * integer arithmetic as well as number theoretic functionality.
4102
+ *
4103
+ * The library was designed directly after the MPI library by
4104
+ * Michael Fromberger but has been written from scratch with
4105
+ * additional optimizations in place.
4106
+ *
4107
+ * The library is free for all purposes without any express
4108
+ * guarantee it works.
4109
+ *
4110
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
4111
+ */
4112
+
4113
+/* c = |a| * |b| using Karatsuba Multiplication using 
4114
+ * three half size multiplications
4115
+ *
4116
+ * Let B represent the radix [e.g. 2**DIGIT_BIT] and 
4117
+ * let n represent half of the number of digits in 
4118
+ * the min(a,b)
4119
+ *
4120
+ * a = a1 * B**n + a0
4121
+ * b = b1 * B**n + b0
4122
+ *
4123
+ * Then, a * b => 
4124
+   a1b1 * B**2n + ((a1 + a0)(b1 + b0) - (a0b0 + a1b1)) * B + a0b0
4125
+ *
4126
+ * Note that a1b1 and a0b0 are used twice and only need to be 
4127
+ * computed once.  So in total three half size (half # of 
4128
+ * digit) multiplications are performed, a0b0, a1b1 and 
4129
+ * (a1+b1)(a0+b0)
4130
+ *
4131
+ * Note that a multiplication of half the digits requires
4132
+ * 1/4th the number of single precision multiplications so in 
4133
+ * total after one call 25% of the single precision multiplications 
4134
+ * are saved.  Note also that the call to mp_mul can end up back 
4135
+ * in this function if the a0, a1, b0, or b1 are above the threshold.  
4136
+ * This is known as divide-and-conquer and leads to the famous 
4137
+ * O(N**lg(3)) or O(N**1.584) work which is asymptopically lower than 
4138
+ * the standard O(N**2) that the baseline/comba methods use.  
4139
+ * Generally though the overhead of this method doesn't pay off 
4140
+ * until a certain size (N ~ 80) is reached.
4141
+ */
4142
+int mp_karatsuba_mul (mp_int * a, mp_int * b, mp_int * c)
4143
+{
4144
+  mp_int  x0, x1, y0, y1, t1, x0y0, x1y1;
4145
+  int     B, err;
4146
+
4147
+  /* default the return code to an error */
4148
+  err = MP_MEM;
4149
+
4150
+  /* min # of digits */
4151
+  B = MIN (a->used, b->used);
4152
+
4153
+  /* now divide in two */
4154
+  B = B >> 1;
4155
+
4156
+  /* init copy all the temps */
4157
+  if (mp_init_size (&x0, B) != MP_OKAY)
4158
+    goto ERR;
4159
+  if (mp_init_size (&x1, a->used - B) != MP_OKAY)
4160
+    goto X0;
4161
+  if (mp_init_size (&y0, B) != MP_OKAY)
4162
+    goto X1;
4163
+  if (mp_init_size (&y1, b->used - B) != MP_OKAY)
4164
+    goto Y0;
4165
+
4166
+  /* init temps */
4167
+  if (mp_init_size (&t1, B * 2) != MP_OKAY)
4168
+    goto Y1;
4169
+  if (mp_init_size (&x0y0, B * 2) != MP_OKAY)
4170
+    goto T1;
4171
+  if (mp_init_size (&x1y1, B * 2) != MP_OKAY)
4172
+    goto X0Y0;
4173
+
4174
+  /* now shift the digits */
4175
+  x0.used = y0.used = B;
4176
+  x1.used = a->used - B;
4177
+  y1.used = b->used - B;
4178
+
4179
+  {
4180
+    register int x;
4181
+    register mp_digit *tmpa, *tmpb, *tmpx, *tmpy;
4182
+
4183
+    /* we copy the digits directly instead of using higher level functions
4184
+     * since we also need to shift the digits
4185
+     */
4186
+    tmpa = a->dp;
4187
+    tmpb = b->dp;
4188
+
4189
+    tmpx = x0.dp;
4190
+    tmpy = y0.dp;
4191
+    for (x = 0; x < B; x++) {
4192
+      *tmpx++ = *tmpa++;
4193
+      *tmpy++ = *tmpb++;
4194
+    }
4195
+
4196
+    tmpx = x1.dp;
4197
+    for (x = B; x < a->used; x++) {
4198
+      *tmpx++ = *tmpa++;
4199
+    }
4200
+
4201
+    tmpy = y1.dp;
4202
+    for (x = B; x < b->used; x++) {
4203
+      *tmpy++ = *tmpb++;
4204
+    }
4205
+  }
4206
+
4207
+  /* only need to clamp the lower words since by definition the 
4208
+   * upper words x1/y1 must have a known number of digits
4209
+   */
4210
+  mp_clamp (&x0);
4211
+  mp_clamp (&y0);
4212
+
4213
+  /* now calc the products x0y0 and x1y1 */
4214
+  /* after this x0 is no longer required, free temp [x0==t2]! */
4215
+  if (mp_mul (&x0, &y0, &x0y0) != MP_OKAY)  
4216
+    goto X1Y1;          /* x0y0 = x0*y0 */
4217
+  if (mp_mul (&x1, &y1, &x1y1) != MP_OKAY)
4218
+    goto X1Y1;          /* x1y1 = x1*y1 */
4219
+
4220
+  /* now calc x1+x0 and y1+y0 */
4221
+  if (s_mp_add (&x1, &x0, &t1) != MP_OKAY)
4222
+    goto X1Y1;          /* t1 = x1 - x0 */
4223
+  if (s_mp_add (&y1, &y0, &x0) != MP_OKAY)
4224
+    goto X1Y1;          /* t2 = y1 - y0 */
4225
+  if (mp_mul (&t1, &x0, &t1) != MP_OKAY)
4226
+    goto X1Y1;          /* t1 = (x1 + x0) * (y1 + y0) */
4227
+
4228
+  /* add x0y0 */
4229
+  if (mp_add (&x0y0, &x1y1, &x0) != MP_OKAY)
4230
+    goto X1Y1;          /* t2 = x0y0 + x1y1 */
4231
+  if (s_mp_sub (&t1, &x0, &t1) != MP_OKAY)
4232
+    goto X1Y1;          /* t1 = (x1+x0)*(y1+y0) - (x1y1 + x0y0) */
4233
+
4234
+  /* shift by B */
4235
+  if (mp_lshd (&t1, B) != MP_OKAY)
4236
+    goto X1Y1;          /* t1 = (x0y0 + x1y1 - (x1-x0)*(y1-y0))<<B */
4237
+  if (mp_lshd (&x1y1, B * 2) != MP_OKAY)
4238
+    goto X1Y1;          /* x1y1 = x1y1 << 2*B */
4239
+
4240
+  if (mp_add (&x0y0, &t1, &t1) != MP_OKAY)
4241
+    goto X1Y1;          /* t1 = x0y0 + t1 */
4242
+  if (mp_add (&t1, &x1y1, c) != MP_OKAY)
4243
+    goto X1Y1;          /* t1 = x0y0 + t1 + x1y1 */
4244
+
4245
+  /* Algorithm succeeded set the return code to MP_OKAY */
4246
+  err = MP_OKAY;
4247
+
4248
+X1Y1:mp_clear (&x1y1);
4249
+X0Y0:mp_clear (&x0y0);
4250
+T1:mp_clear (&t1);
4251
+Y1:mp_clear (&y1);
4252
+Y0:mp_clear (&y0);
4253
+X1:mp_clear (&x1);
4254
+X0:mp_clear (&x0);
4255
+ERR:
4256
+  return err;
4257
+}
4258
+#endif
4259
+
4260
+/* $Source: /cvs/libtom/libtommath/bn_mp_karatsuba_mul.c,v $ */
4261
+/* $Revision: 1.5 $ */
4262
+/* $Date: 2006/03/31 14:18:44 $ */
4263
+
4264
+/* End: bn_mp_karatsuba_mul.c */
4265
+
4266
+/* Start: bn_mp_karatsuba_sqr.c */
4267
+#include <bignum.h>
4268
+#ifdef BN_MP_KARATSUBA_SQR_C
4269
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
4270
+ *
4271
+ * LibTomMath is a library that provides multiple-precision
4272
+ * integer arithmetic as well as number theoretic functionality.
4273
+ *
4274
+ * The library was designed directly after the MPI library by
4275
+ * Michael Fromberger but has been written from scratch with
4276
+ * additional optimizations in place.
4277
+ *
4278
+ * The library is free for all purposes without any express
4279
+ * guarantee it works.
4280
+ *
4281
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
4282
+ */
4283
+
4284
+/* Karatsuba squaring, computes b = a*a using three 
4285
+ * half size squarings
4286
+ *
4287
+ * See comments of karatsuba_mul for details.  It 
4288
+ * is essentially the same algorithm but merely 
4289
+ * tuned to perform recursive squarings.
4290
+ */
4291
+int mp_karatsuba_sqr (mp_int * a, mp_int * b)
4292
+{
4293
+  mp_int  x0, x1, t1, t2, x0x0, x1x1;
4294
+  int     B, err;
4295
+
4296
+  err = MP_MEM;
4297
+
4298
+  /* min # of digits */
4299
+  B = a->used;
4300
+
4301
+  /* now divide in two */
4302
+  B = B >> 1;
4303
+
4304
+  /* init copy all the temps */
4305
+  if (mp_init_size (&x0, B) != MP_OKAY)
4306
+    goto ERR;
4307
+  if (mp_init_size (&x1, a->used - B) != MP_OKAY)
4308
+    goto X0;
4309
+
4310
+  /* init temps */
4311
+  if (mp_init_size (&t1, a->used * 2) != MP_OKAY)
4312
+    goto X1;
4313
+  if (mp_init_size (&t2, a->used * 2) != MP_OKAY)
4314
+    goto T1;
4315
+  if (mp_init_size (&x0x0, B * 2) != MP_OKAY)
4316
+    goto T2;
4317
+  if (mp_init_size (&x1x1, (a->used - B) * 2) != MP_OKAY)
4318
+    goto X0X0;
4319
+
4320
+  {
4321
+    register int x;
4322
+    register mp_digit *dst, *src;
4323
+
4324
+    src = a->dp;
4325
+
4326
+    /* now shift the digits */
4327
+    dst = x0.dp;
4328
+    for (x = 0; x < B; x++) {
4329
+      *dst++ = *src++;
4330
+    }
4331
+
4332
+    dst = x1.dp;
4333
+    for (x = B; x < a->used; x++) {
4334
+      *dst++ = *src++;
4335
+    }
4336
+  }
4337
+
4338
+  x0.used = B;
4339
+  x1.used = a->used - B;
4340
+
4341
+  mp_clamp (&x0);
4342
+
4343
+  /* now calc the products x0*x0 and x1*x1 */
4344
+  if (mp_sqr (&x0, &x0x0) != MP_OKAY)
4345
+    goto X1X1;           /* x0x0 = x0*x0 */
4346
+  if (mp_sqr (&x1, &x1x1) != MP_OKAY)
4347
+    goto X1X1;           /* x1x1 = x1*x1 */
4348
+
4349
+  /* now calc (x1+x0)**2 */
4350
+  if (s_mp_add (&x1, &x0, &t1) != MP_OKAY)
4351
+    goto X1X1;           /* t1 = x1 - x0 */
4352
+  if (mp_sqr (&t1, &t1) != MP_OKAY)
4353
+    goto X1X1;           /* t1 = (x1 - x0) * (x1 - x0) */
4354
+
4355
+  /* add x0y0 */
4356
+  if (s_mp_add (&x0x0, &x1x1, &t2) != MP_OKAY)
4357
+    goto X1X1;           /* t2 = x0x0 + x1x1 */
4358
+  if (s_mp_sub (&t1, &t2, &t1) != MP_OKAY)
4359
+    goto X1X1;           /* t1 = (x1+x0)**2 - (x0x0 + x1x1) */
4360
+
4361
+  /* shift by B */
4362
+  if (mp_lshd (&t1, B) != MP_OKAY)
4363
+    goto X1X1;           /* t1 = (x0x0 + x1x1 - (x1-x0)*(x1-x0))<<B */
4364
+  if (mp_lshd (&x1x1, B * 2) != MP_OKAY)
4365
+    goto X1X1;           /* x1x1 = x1x1 << 2*B */
4366
+
4367
+  if (mp_add (&x0x0, &t1, &t1) != MP_OKAY)
4368
+    goto X1X1;           /* t1 = x0x0 + t1 */
4369
+  if (mp_add (&t1, &x1x1, b) != MP_OKAY)
4370
+    goto X1X1;           /* t1 = x0x0 + t1 + x1x1 */
4371
+
4372
+  err = MP_OKAY;
4373
+
4374
+X1X1:mp_clear (&x1x1);
4375
+X0X0:mp_clear (&x0x0);
4376
+T2:mp_clear (&t2);
4377
+T1:mp_clear (&t1);
4378
+X1:mp_clear (&x1);
4379
+X0:mp_clear (&x0);
4380
+ERR:
4381
+  return err;
4382
+}
4383
+#endif
4384
+
4385
+/* $Source: /cvs/libtom/libtommath/bn_mp_karatsuba_sqr.c,v $ */
4386
+/* $Revision: 1.5 $ */
4387
+/* $Date: 2006/03/31 14:18:44 $ */
4388
+
4389
+/* End: bn_mp_karatsuba_sqr.c */
4390
+
4391
+/* Start: bn_mp_lcm.c */
4392
+#include <bignum.h>
4393
+#ifdef BN_MP_LCM_C
4394
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
4395
+ *
4396
+ * LibTomMath is a library that provides multiple-precision
4397
+ * integer arithmetic as well as number theoretic functionality.
4398
+ *
4399
+ * The library was designed directly after the MPI library by
4400
+ * Michael Fromberger but has been written from scratch with
4401
+ * additional optimizations in place.
4402
+ *
4403
+ * The library is free for all purposes without any express
4404
+ * guarantee it works.
4405
+ *
4406
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
4407
+ */
4408
+
4409
+/* computes least common multiple as |a*b|/(a, b) */
4410
+int mp_lcm (mp_int * a, mp_int * b, mp_int * c)
4411
+{
4412
+  int     res;
4413
+  mp_int  t1, t2;
4414
+
4415
+
4416
+  if ((res = mp_init_multi (&t1, &t2, NULL)) != MP_OKAY) {
4417
+    return res;
4418
+  }
4419
+
4420
+  /* t1 = get the GCD of the two inputs */
4421
+  if ((res = mp_gcd (a, b, &t1)) != MP_OKAY) {
4422
+    goto LBL_T;
4423
+  }
4424
+
4425
+  /* divide the smallest by the GCD */
4426
+  if (mp_cmp_mag(a, b) == MP_LT) {
4427
+     /* store quotient in t2 such that t2 * b is the LCM */
4428
+     if ((res = mp_div(a, &t1, &t2, NULL)) != MP_OKAY) {
4429
+        goto LBL_T;
4430
+     }
4431
+     res = mp_mul(b, &t2, c);
4432
+  } else {
4433
+     /* store quotient in t2 such that t2 * a is the LCM */
4434
+     if ((res = mp_div(b, &t1, &t2, NULL)) != MP_OKAY) {
4435
+        goto LBL_T;
4436
+     }
4437
+     res = mp_mul(a, &t2, c);
4438
+  }
4439
+
4440
+  /* fix the sign to positive */
4441
+  c->sign = MP_ZPOS;
4442
+
4443
+LBL_T:
4444
+  mp_clear_multi (&t1, &t2, NULL);
4445
+  return res;
4446
+}
4447
+#endif
4448
+
4449
+/* $Source: /cvs/libtom/libtommath/bn_mp_lcm.c,v $ */
4450
+/* $Revision: 1.3 $ */
4451
+/* $Date: 2006/03/31 14:18:44 $ */
4452
+
4453
+/* End: bn_mp_lcm.c */
4454
+
4455
+/* Start: bn_mp_lshd.c */
4456
+#include <bignum.h>
4457
+#ifdef BN_MP_LSHD_C
4458
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
4459
+ *
4460
+ * LibTomMath is a library that provides multiple-precision
4461
+ * integer arithmetic as well as number theoretic functionality.
4462
+ *
4463
+ * The library was designed directly after the MPI library by
4464
+ * Michael Fromberger but has been written from scratch with
4465
+ * additional optimizations in place.
4466
+ *
4467
+ * The library is free for all purposes without any express
4468
+ * guarantee it works.
4469
+ *
4470
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
4471
+ */
4472
+
4473
+/* shift left a certain amount of digits */
4474
+int mp_lshd (mp_int * a, int b)
4475
+{
4476
+  int     x, res;
4477
+
4478
+  /* if its less than zero return */
4479
+  if (b <= 0) {
4480
+    return MP_OKAY;
4481
+  }
4482
+
4483
+  /* grow to fit the new digits */
4484
+  if (a->alloc < a->used + b) {
4485
+     if ((res = mp_grow (a, a->used + b)) != MP_OKAY) {
4486
+       return res;
4487
+     }
4488
+  }
4489
+
4490
+  {
4491
+    register mp_digit *top, *bottom;
4492
+
4493
+    /* increment the used by the shift amount then copy upwards */
4494
+    a->used += b;
4495
+
4496
+    /* top */
4497
+    top = a->dp + a->used - 1;
4498
+
4499
+    /* base */
4500
+    bottom = a->dp + a->used - 1 - b;
4501
+
4502
+    /* much like mp_rshd this is implemented using a sliding window
4503
+     * except the window goes the otherway around.  Copying from
4504
+     * the bottom to the top.  see bn_mp_rshd.c for more info.
4505
+     */
4506
+    for (x = a->used - 1; x >= b; x--) {
4507
+      *top-- = *bottom--;
4508
+    }
4509
+
4510
+    /* zero the lower digits */
4511
+    top = a->dp;
4512
+    for (x = 0; x < b; x++) {
4513
+      *top++ = 0;
4514
+    }
4515
+  }
4516
+  return MP_OKAY;
4517
+}
4518
+#endif
4519
+
4520
+/* $Source: /cvs/libtom/libtommath/bn_mp_lshd.c,v $ */
4521
+/* $Revision: 1.3 $ */
4522
+/* $Date: 2006/03/31 14:18:44 $ */
4523
+
4524
+/* End: bn_mp_lshd.c */
4525
+
4526
+/* Start: bn_mp_mod.c */
4527
+#include <bignum.h>
4528
+#ifdef BN_MP_MOD_C
4529
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
4530
+ *
4531
+ * LibTomMath is a library that provides multiple-precision
4532
+ * integer arithmetic as well as number theoretic functionality.
4533
+ *
4534
+ * The library was designed directly after the MPI library by
4535
+ * Michael Fromberger but has been written from scratch with
4536
+ * additional optimizations in place.
4537
+ *
4538
+ * The library is free for all purposes without any express
4539
+ * guarantee it works.
4540
+ *
4541
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
4542
+ */
4543
+
4544
+/* c = a mod b, 0 <= c < b */
4545
+int
4546
+mp_mod (mp_int * a, mp_int * b, mp_int * c)
4547
+{
4548
+  mp_int  t;
4549
+  int     res;
4550
+
4551
+  if ((res = mp_init (&t)) != MP_OKAY) {
4552
+    return res;
4553
+  }
4554
+
4555
+  if ((res = mp_div (a, b, NULL, &t)) != MP_OKAY) {
4556
+    mp_clear (&t);
4557
+    return res;
4558
+  }
4559
+
4560
+  if (t.sign != b->sign) {
4561
+    res = mp_add (b, &t, c);
4562
+  } else {
4563
+    res = MP_OKAY;
4564
+    mp_exch (&t, c);
4565
+  }
4566
+
4567
+  mp_clear (&t);
4568
+  return res;
4569
+}
4570
+#endif
4571
+
4572
+/* $Source: /cvs/libtom/libtommath/bn_mp_mod.c,v $ */
4573
+/* $Revision: 1.3 $ */
4574
+/* $Date: 2006/03/31 14:18:44 $ */
4575
+
4576
+/* End: bn_mp_mod.c */
4577
+
4578
+/* Start: bn_mp_mod_2d.c */
4579
+#include <bignum.h>
4580
+#ifdef BN_MP_MOD_2D_C
4581
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
4582
+ *
4583
+ * LibTomMath is a library that provides multiple-precision
4584
+ * integer arithmetic as well as number theoretic functionality.
4585
+ *
4586
+ * The library was designed directly after the MPI library by
4587
+ * Michael Fromberger but has been written from scratch with
4588
+ * additional optimizations in place.
4589
+ *
4590
+ * The library is free for all purposes without any express
4591
+ * guarantee it works.
4592
+ *
4593
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
4594
+ */
4595
+
4596
+/* calc a value mod 2**b */
4597
+int
4598
+mp_mod_2d (mp_int * a, int b, mp_int * c)
4599
+{
4600
+  int     x, res;
4601
+
4602
+  /* if b is <= 0 then zero the int */
4603
+  if (b <= 0) {
4604
+    mp_zero (c);
4605
+    return MP_OKAY;
4606
+  }
4607
+
4608
+  /* if the modulus is larger than the value than return */
4609
+  if (b >= (int) (a->used * DIGIT_BIT)) {
4610
+    res = mp_copy (a, c);
4611
+    return res;
4612
+  }
4613
+
4614
+  /* copy */
4615
+  if ((res = mp_copy (a, c)) != MP_OKAY) {
4616
+    return res;
4617
+  }
4618
+
4619
+  /* zero digits above the last digit of the modulus */
4620
+  for (x = (b / DIGIT_BIT) + ((b % DIGIT_BIT) == 0 ? 0 : 1); x < c->used; x++) {
4621
+    c->dp[x] = 0;
4622
+  }
4623
+  /* clear the digit that is not completely outside/inside the modulus */
4624
+  c->dp[b / DIGIT_BIT] &=
4625
+    (mp_digit) ((((mp_digit) 1) << (((mp_digit) b) % DIGIT_BIT)) - ((mp_digit) 1));
4626
+  mp_clamp (c);
4627
+  return MP_OKAY;
4628
+}
4629
+#endif
4630
+
4631
+/* $Source: /cvs/libtom/libtommath/bn_mp_mod_2d.c,v $ */
4632
+/* $Revision: 1.3 $ */
4633
+/* $Date: 2006/03/31 14:18:44 $ */
4634
+
4635
+/* End: bn_mp_mod_2d.c */
4636
+
4637
+/* Start: bn_mp_mod_d.c */
4638
+#include <bignum.h>
4639
+#ifdef BN_MP_MOD_D_C
4640
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
4641
+ *
4642
+ * LibTomMath is a library that provides multiple-precision
4643
+ * integer arithmetic as well as number theoretic functionality.
4644
+ *
4645
+ * The library was designed directly after the MPI library by
4646
+ * Michael Fromberger but has been written from scratch with
4647
+ * additional optimizations in place.
4648
+ *
4649
+ * The library is free for all purposes without any express
4650
+ * guarantee it works.
4651
+ *
4652
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
4653
+ */
4654
+
4655
+int
4656
+mp_mod_d (mp_int * a, mp_digit b, mp_digit * c)
4657
+{
4658
+  return mp_div_d(a, b, NULL, c);
4659
+}
4660
+#endif
4661
+
4662
+/* $Source: /cvs/libtom/libtommath/bn_mp_mod_d.c,v $ */
4663
+/* $Revision: 1.3 $ */
4664
+/* $Date: 2006/03/31 14:18:44 $ */
4665
+
4666
+/* End: bn_mp_mod_d.c */
4667
+
4668
+/* Start: bn_mp_montgomery_calc_normalization.c */
4669
+#include <bignum.h>
4670
+#ifdef BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
4671
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
4672
+ *
4673
+ * LibTomMath is a library that provides multiple-precision
4674
+ * integer arithmetic as well as number theoretic functionality.
4675
+ *
4676
+ * The library was designed directly after the MPI library by
4677
+ * Michael Fromberger but has been written from scratch with
4678
+ * additional optimizations in place.
4679
+ *
4680
+ * The library is free for all purposes without any express
4681
+ * guarantee it works.
4682
+ *
4683
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
4684
+ */
4685
+
4686
+/*
4687
+ * shifts with subtractions when the result is greater than b.
4688
+ *
4689
+ * The method is slightly modified to shift B unconditionally upto just under
4690
+ * the leading bit of b.  This saves alot of multiple precision shifting.
4691
+ */
4692
+int mp_montgomery_calc_normalization (mp_int * a, mp_int * b)
4693
+{
4694
+  int     x, bits, res;
4695
+
4696
+  /* how many bits of last digit does b use */
4697
+  bits = mp_count_bits (b) % DIGIT_BIT;
4698
+
4699
+  if (b->used > 1) {
4700
+     if ((res = mp_2expt (a, (b->used - 1) * DIGIT_BIT + bits - 1)) != MP_OKAY) {
4701
+        return res;
4702
+     }
4703
+  } else {
4704
+     mp_set(a, 1);
4705
+     bits = 1;
4706
+  }
4707
+
4708
+
4709
+  /* now compute C = A * B mod b */
4710
+  for (x = bits - 1; x < (int)DIGIT_BIT; x++) {
4711
+    if ((res = mp_mul_2 (a, a)) != MP_OKAY) {
4712
+      return res;
4713
+    }
4714
+    if (mp_cmp_mag (a, b) != MP_LT) {
4715
+      if ((res = s_mp_sub (a, b, a)) != MP_OKAY) {
4716
+        return res;
4717
+      }
4718
+    }
4719
+  }
4720
+
4721
+  return MP_OKAY;
4722
+}
4723
+#endif
4724
+
4725
+/* $Source: /cvs/libtom/libtommath/bn_mp_montgomery_calc_normalization.c,v $ */
4726
+/* $Revision: 1.3 $ */
4727
+/* $Date: 2006/03/31 14:18:44 $ */
4728
+
4729
+/* End: bn_mp_montgomery_calc_normalization.c */
4730
+
4731
+/* Start: bn_mp_montgomery_reduce.c */
4732
+#include <bignum.h>
4733
+#ifdef BN_MP_MONTGOMERY_REDUCE_C
4734
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
4735
+ *
4736
+ * LibTomMath is a library that provides multiple-precision
4737
+ * integer arithmetic as well as number theoretic functionality.
4738
+ *
4739
+ * The library was designed directly after the MPI library by
4740
+ * Michael Fromberger but has been written from scratch with
4741
+ * additional optimizations in place.
4742
+ *
4743
+ * The library is free for all purposes without any express
4744
+ * guarantee it works.
4745
+ *
4746
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
4747
+ */
4748
+
4749
+/* computes xR**-1 == x (mod N) via Montgomery Reduction */
4750
+int
4751
+mp_montgomery_reduce (mp_int * x, mp_int * n, mp_digit rho)
4752
+{
4753
+  int     ix, res, digs;
4754
+  mp_digit mu;
4755
+
4756
+  /* can the fast reduction [comba] method be used?
4757
+   *
4758
+   * Note that unlike in mul you're safely allowed *less*
4759
+   * than the available columns [255 per default] since carries
4760
+   * are fixed up in the inner loop.
4761
+   */
4762
+  digs = n->used * 2 + 1;
4763
+  if ((digs < MP_WARRAY) &&
4764
+      n->used <
4765
+      (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
4766
+    return fast_mp_montgomery_reduce (x, n, rho);
4767
+  }
4768
+
4769
+  /* grow the input as required */
4770
+  if (x->alloc < digs) {
4771
+    if ((res = mp_grow (x, digs)) != MP_OKAY) {
4772
+      return res;
4773
+    }
4774
+  }
4775
+  x->used = digs;
4776
+
4777
+  for (ix = 0; ix < n->used; ix++) {
4778
+    /* mu = ai * rho mod b
4779
+     *
4780
+     * The value of rho must be precalculated via
4781
+     * montgomery_setup() such that
4782
+     * it equals -1/n0 mod b this allows the
4783
+     * following inner loop to reduce the
4784
+     * input one digit at a time
4785
+     */
4786
+    mu = (mp_digit) (((mp_word)x->dp[ix]) * ((mp_word)rho) & MP_MASK);
4787
+
4788
+    /* a = a + mu * m * b**i */
4789
+    {
4790
+      register int iy;
4791
+      register mp_digit *tmpn, *tmpx, u;
4792
+      register mp_word r;
4793
+
4794
+      /* alias for digits of the modulus */
4795
+      tmpn = n->dp;
4796
+
4797
+      /* alias for the digits of x [the input] */
4798
+      tmpx = x->dp + ix;
4799
+
4800
+      /* set the carry to zero */
4801
+      u = 0;
4802
+
4803
+      /* Multiply and add in place */
4804
+      for (iy = 0; iy < n->used; iy++) {
4805
+        /* compute product and sum */
4806
+        r       = ((mp_word)mu) * ((mp_word)*tmpn++) +
4807
+                  ((mp_word) u) + ((mp_word) * tmpx);
4808
+
4809
+        /* get carry */
4810
+        u       = (mp_digit)(r >> ((mp_word) DIGIT_BIT));
4811
+
4812
+        /* fix digit */
4813
+        *tmpx++ = (mp_digit)(r & ((mp_word) MP_MASK));
4814
+      }
4815
+      /* At this point the ix'th digit of x should be zero */
4816
+
4817
+
4818
+      /* propagate carries upwards as required*/
4819
+      while (u) {
4820
+        *tmpx   += u;
4821
+        u        = *tmpx >> DIGIT_BIT;
4822
+        *tmpx++ &= MP_MASK;
4823
+      }
4824
+    }
4825
+  }
4826
+
4827
+  /* at this point the n.used'th least
4828
+   * significant digits of x are all zero
4829
+   * which means we can shift x to the
4830
+   * right by n.used digits and the
4831
+   * residue is unchanged.
4832
+   */
4833
+
4834
+  /* x = x/b**n.used */
4835
+  mp_clamp(x);
4836
+  mp_rshd (x, n->used);
4837
+
4838
+  /* if x >= n then x = x - n */
4839
+  if (mp_cmp_mag (x, n) != MP_LT) {
4840
+    return s_mp_sub (x, n, x);
4841
+  }
4842
+
4843
+  return MP_OKAY;
4844
+}
4845
+#endif
4846
+
4847
+/* $Source: /cvs/libtom/libtommath/bn_mp_montgomery_reduce.c,v $ */
4848
+/* $Revision: 1.3 $ */
4849
+/* $Date: 2006/03/31 14:18:44 $ */
4850
+
4851
+/* End: bn_mp_montgomery_reduce.c */
4852
+
4853
+/* Start: bn_mp_montgomery_setup.c */
4854
+#include <bignum.h>
4855
+#ifdef BN_MP_MONTGOMERY_SETUP_C
4856
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
4857
+ *
4858
+ * LibTomMath is a library that provides multiple-precision
4859
+ * integer arithmetic as well as number theoretic functionality.
4860
+ *
4861
+ * The library was designed directly after the MPI library by
4862
+ * Michael Fromberger but has been written from scratch with
4863
+ * additional optimizations in place.
4864
+ *
4865
+ * The library is free for all purposes without any express
4866
+ * guarantee it works.
4867
+ *
4868
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
4869
+ */
4870
+
4871
+/* setups the montgomery reduction stuff */
4872
+int
4873
+mp_montgomery_setup (mp_int * n, mp_digit * rho)
4874
+{
4875
+  mp_digit x, b;
4876
+
4877
+/* fast inversion mod 2**k
4878
+ *
4879
+ * Based on the fact that
4880
+ *
4881
+ * XA = 1 (mod 2**n)  =>  (X(2-XA)) A = 1 (mod 2**2n)
4882
+ *                    =>  2*X*A - X*X*A*A = 1
4883
+ *                    =>  2*(1) - (1)     = 1
4884
+ */
4885
+  b = n->dp[0];
4886
+
4887
+  if ((b & 1) == 0) {
4888
+    return MP_VAL;
4889
+  }
4890
+
4891
+  x = (((b + 2) & 4) << 1) + b; /* here x*a==1 mod 2**4 */
4892
+  x *= 2 - b * x;               /* here x*a==1 mod 2**8 */
4893
+#if !defined(MP_8BIT)
4894
+  x *= 2 - b * x;               /* here x*a==1 mod 2**16 */
4895
+#endif
4896
+#if defined(MP_64BIT) || !(defined(MP_8BIT) || defined(MP_16BIT))
4897
+  x *= 2 - b * x;               /* here x*a==1 mod 2**32 */
4898
+#endif
4899
+#ifdef MP_64BIT
4900
+  x *= 2 - b * x;               /* here x*a==1 mod 2**64 */
4901
+#endif
4902
+
4903
+  /* rho = -1/m mod b */
4904
+  *rho = (((mp_word)1 << ((mp_word) DIGIT_BIT)) - x) & MP_MASK;
4905
+
4906
+  return MP_OKAY;
4907
+}
4908
+#endif
4909
+
4910
+/* $Source: /cvs/libtom/libtommath/bn_mp_montgomery_setup.c,v $ */
4911
+/* $Revision: 1.3 $ */
4912
+/* $Date: 2006/03/31 14:18:44 $ */
4913
+
4914
+/* End: bn_mp_montgomery_setup.c */
4915
+
4916
+/* Start: bn_mp_mul.c */
4917
+#include <bignum.h>
4918
+#ifdef BN_MP_MUL_C
4919
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
4920
+ *
4921
+ * LibTomMath is a library that provides multiple-precision
4922
+ * integer arithmetic as well as number theoretic functionality.
4923
+ *
4924
+ * The library was designed directly after the MPI library by
4925
+ * Michael Fromberger but has been written from scratch with
4926
+ * additional optimizations in place.
4927
+ *
4928
+ * The library is free for all purposes without any express
4929
+ * guarantee it works.
4930
+ *
4931
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
4932
+ */
4933
+
4934
+/* high level multiplication (handles sign) */
4935
+int mp_mul (mp_int * a, mp_int * b, mp_int * c)
4936
+{
4937
+  int     res, neg;
4938
+  neg = (a->sign == b->sign) ? MP_ZPOS : MP_NEG;
4939
+
4940
+  /* use Toom-Cook? */
4941
+#ifdef BN_MP_TOOM_MUL_C
4942
+  if (MIN (a->used, b->used) >= TOOM_MUL_CUTOFF) {
4943
+    res = mp_toom_mul(a, b, c);
4944
+  } else 
4945
+#endif
4946
+#ifdef BN_MP_KARATSUBA_MUL_C
4947
+  /* use Karatsuba? */
4948
+  if (MIN (a->used, b->used) >= KARATSUBA_MUL_CUTOFF) {
4949
+    res = mp_karatsuba_mul (a, b, c);
4950
+  } else 
4951
+#endif
4952
+  {
4953
+    /* can we use the fast multiplier?
4954
+     *
4955
+     * The fast multiplier can be used if the output will 
4956
+     * have less than MP_WARRAY digits and the number of 
4957
+     * digits won't affect carry propagation
4958
+     */
4959
+    int     digs = a->used + b->used + 1;
4960
+
4961
+#ifdef BN_FAST_S_MP_MUL_DIGS_C
4962
+    if ((digs < MP_WARRAY) &&
4963
+        MIN(a->used, b->used) <= 
4964
+        (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
4965
+      res = fast_s_mp_mul_digs (a, b, c, digs);
4966
+    } else 
4967
+#endif
4968
+#ifdef BN_S_MP_MUL_DIGS_C
4969
+      res = s_mp_mul (a, b, c); /* uses s_mp_mul_digs */
4970
+#else
4971
+      res = MP_VAL;
4972
+#endif
4973
+
4974
+  }
4975
+  c->sign = (c->used > 0) ? neg : MP_ZPOS;
4976
+  return res;
4977
+}
4978
+#endif
4979
+
4980
+/* $Source: /cvs/libtom/libtommath/bn_mp_mul.c,v $ */
4981
+/* $Revision: 1.3 $ */
4982
+/* $Date: 2006/03/31 14:18:44 $ */
4983
+
4984
+/* End: bn_mp_mul.c */
4985
+
4986
+/* Start: bn_mp_mul_2.c */
4987
+#include <bignum.h>
4988
+#ifdef BN_MP_MUL_2_C
4989
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
4990
+ *
4991
+ * LibTomMath is a library that provides multiple-precision
4992
+ * integer arithmetic as well as number theoretic functionality.
4993
+ *
4994
+ * The library was designed directly after the MPI library by
4995
+ * Michael Fromberger but has been written from scratch with
4996
+ * additional optimizations in place.
4997
+ *
4998
+ * The library is free for all purposes without any express
4999
+ * guarantee it works.
5000
+ *
5001
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
5002
+ */
5003
+
5004
+/* b = a*2 */
5005
+int mp_mul_2(mp_int * a, mp_int * b)
5006
+{
5007
+  int     x, res, oldused;
5008
+
5009
+  /* grow to accomodate result */
5010
+  if (b->alloc < a->used + 1) {
5011
+    if ((res = mp_grow (b, a->used + 1)) != MP_OKAY) {
5012
+      return res;
5013
+    }
5014
+  }
5015
+
5016
+  oldused = b->used;
5017
+  b->used = a->used;
5018
+
5019
+  {
5020
+    register mp_digit r, rr, *tmpa, *tmpb;
5021
+
5022
+    /* alias for source */
5023
+    tmpa = a->dp;
5024
+    
5025
+    /* alias for dest */
5026
+    tmpb = b->dp;
5027
+
5028
+    /* carry */
5029
+    r = 0;
5030
+    for (x = 0; x < a->used; x++) {
5031
+    
5032
+      /* get what will be the *next* carry bit from the 
5033
+       * MSB of the current digit 
5034
+       */
5035
+      rr = *tmpa >> ((mp_digit)(DIGIT_BIT - 1));
5036
+      
5037
+      /* now shift up this digit, add in the carry [from the previous] */
5038
+      *tmpb++ = ((*tmpa++ << ((mp_digit)1)) | r) & MP_MASK;
5039
+      
5040
+      /* copy the carry that would be from the source 
5041
+       * digit into the next iteration 
5042
+       */
5043
+      r = rr;
5044
+    }
5045
+
5046
+    /* new leading digit? */
5047
+    if (r != 0) {
5048
+      /* add a MSB which is always 1 at this point */
5049
+      *tmpb = 1;
5050
+      ++(b->used);
5051
+    }
5052
+
5053
+    /* now zero any excess digits on the destination 
5054
+     * that we didn't write to 
5055
+     */
5056
+    tmpb = b->dp + b->used;
5057
+    for (x = b->used; x < oldused; x++) {
5058
+      *tmpb++ = 0;
5059
+    }
5060
+  }
5061
+  b->sign = a->sign;
5062
+  return MP_OKAY;
5063
+}
5064
+#endif
5065
+
5066
+/* $Source: /cvs/libtom/libtommath/bn_mp_mul_2.c,v $ */
5067
+/* $Revision: 1.3 $ */
5068
+/* $Date: 2006/03/31 14:18:44 $ */
5069
+
5070
+/* End: bn_mp_mul_2.c */
5071
+
5072
+/* Start: bn_mp_mul_2d.c */
5073
+#include <bignum.h>
5074
+#ifdef BN_MP_MUL_2D_C
5075
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
5076
+ *
5077
+ * LibTomMath is a library that provides multiple-precision
5078
+ * integer arithmetic as well as number theoretic functionality.
5079
+ *
5080
+ * The library was designed directly after the MPI library by
5081
+ * Michael Fromberger but has been written from scratch with
5082
+ * additional optimizations in place.
5083
+ *
5084
+ * The library is free for all purposes without any express
5085
+ * guarantee it works.
5086
+ *
5087
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
5088
+ */
5089
+
5090
+/* shift left by a certain bit count */
5091
+int mp_mul_2d (mp_int * a, int b, mp_int * c)
5092
+{
5093
+  mp_digit d;
5094
+  int      res;
5095
+
5096
+  /* copy */
5097
+  if (a != c) {
5098
+     if ((res = mp_copy (a, c)) != MP_OKAY) {
5099
+       return res;
5100
+     }
5101
+  }
5102
+
5103
+  if (c->alloc < (int)(c->used + b/DIGIT_BIT + 1)) {
5104
+     if ((res = mp_grow (c, c->used + b / DIGIT_BIT + 1)) != MP_OKAY) {
5105
+       return res;
5106
+     }
5107
+  }
5108
+
5109
+  /* shift by as many digits in the bit count */
5110
+  if (b >= (int)DIGIT_BIT) {
5111
+    if ((res = mp_lshd (c, b / DIGIT_BIT)) != MP_OKAY) {
5112
+      return res;
5113
+    }
5114
+  }
5115
+
5116
+  /* shift any bit count < DIGIT_BIT */
5117
+  d = (mp_digit) (b % DIGIT_BIT);
5118
+  if (d != 0) {
5119
+    register mp_digit *tmpc, shift, mask, r, rr;
5120
+    register int x;
5121
+
5122
+    /* bitmask for carries */
5123
+    mask = (((mp_digit)1) << d) - 1;
5124
+
5125
+    /* shift for msbs */
5126
+    shift = DIGIT_BIT - d;
5127
+
5128
+    /* alias */
5129
+    tmpc = c->dp;
5130
+
5131
+    /* carry */
5132
+    r    = 0;
5133
+    for (x = 0; x < c->used; x++) {
5134
+      /* get the higher bits of the current word */
5135
+      rr = (*tmpc >> shift) & mask;
5136
+
5137
+      /* shift the current word and OR in the carry */
5138
+      *tmpc = ((*tmpc << d) | r) & MP_MASK;
5139
+      ++tmpc;
5140
+
5141
+      /* set the carry to the carry bits of the current word */
5142
+      r = rr;
5143
+    }
5144
+    
5145
+    /* set final carry */
5146
+    if (r != 0) {
5147
+       c->dp[(c->used)++] = r;
5148
+    }
5149
+  }
5150
+  mp_clamp (c);
5151
+  return MP_OKAY;
5152
+}
5153
+#endif
5154
+
5155
+/* $Source: /cvs/libtom/libtommath/bn_mp_mul_2d.c,v $ */
5156
+/* $Revision: 1.3 $ */
5157
+/* $Date: 2006/03/31 14:18:44 $ */
5158
+
5159
+/* End: bn_mp_mul_2d.c */
5160
+
5161
+/* Start: bn_mp_mul_d.c */
5162
+#include <bignum.h>
5163
+#ifdef BN_MP_MUL_D_C
5164
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
5165
+ *
5166
+ * LibTomMath is a library that provides multiple-precision
5167
+ * integer arithmetic as well as number theoretic functionality.
5168
+ *
5169
+ * The library was designed directly after the MPI library by
5170
+ * Michael Fromberger but has been written from scratch with
5171
+ * additional optimizations in place.
5172
+ *
5173
+ * The library is free for all purposes without any express
5174
+ * guarantee it works.
5175
+ *
5176
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
5177
+ */
5178
+
5179
+/* multiply by a digit */
5180
+int
5181
+mp_mul_d (mp_int * a, mp_digit b, mp_int * c)
5182
+{
5183
+  mp_digit u, *tmpa, *tmpc;
5184
+  mp_word  r;
5185
+  int      ix, res, olduse;
5186
+
5187
+  /* make sure c is big enough to hold a*b */
5188
+  if (c->alloc < a->used + 1) {
5189
+    if ((res = mp_grow (c, a->used + 1)) != MP_OKAY) {
5190
+      return res;
5191
+    }
5192
+  }
5193
+
5194
+  /* get the original destinations used count */
5195
+  olduse = c->used;
5196
+
5197
+  /* set the sign */
5198
+  c->sign = a->sign;
5199
+
5200
+  /* alias for a->dp [source] */
5201
+  tmpa = a->dp;
5202
+
5203
+  /* alias for c->dp [dest] */
5204
+  tmpc = c->dp;
5205
+
5206
+  /* zero carry */
5207
+  u = 0;
5208
+
5209
+  /* compute columns */
5210
+  for (ix = 0; ix < a->used; ix++) {
5211
+    /* compute product and carry sum for this term */
5212
+    r       = ((mp_word) u) + ((mp_word)*tmpa++) * ((mp_word)b);
5213
+
5214
+    /* mask off higher bits to get a single digit */
5215
+    *tmpc++ = (mp_digit) (r & ((mp_word) MP_MASK));
5216
+
5217
+    /* send carry into next iteration */
5218
+    u       = (mp_digit) (r >> ((mp_word) DIGIT_BIT));
5219
+  }
5220
+
5221
+  /* store final carry [if any] and increment ix offset  */
5222
+  *tmpc++ = u;
5223
+  ++ix;
5224
+
5225
+  /* now zero digits above the top */
5226
+  while (ix++ < olduse) {
5227
+     *tmpc++ = 0;
5228
+  }
5229
+
5230
+  /* set used count */
5231
+  c->used = a->used + 1;
5232
+  mp_clamp(c);
5233
+
5234
+  return MP_OKAY;
5235
+}
5236
+#endif
5237
+
5238
+/* $Source: /cvs/libtom/libtommath/bn_mp_mul_d.c,v $ */
5239
+/* $Revision: 1.3 $ */
5240
+/* $Date: 2006/03/31 14:18:44 $ */
5241
+
5242
+/* End: bn_mp_mul_d.c */
5243
+
5244
+/* Start: bn_mp_mulmod.c */
5245
+#include <bignum.h>
5246
+#ifdef BN_MP_MULMOD_C
5247
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
5248
+ *
5249
+ * LibTomMath is a library that provides multiple-precision
5250
+ * integer arithmetic as well as number theoretic functionality.
5251
+ *
5252
+ * The library was designed directly after the MPI library by
5253
+ * Michael Fromberger but has been written from scratch with
5254
+ * additional optimizations in place.
5255
+ *
5256
+ * The library is free for all purposes without any express
5257
+ * guarantee it works.
5258
+ *
5259
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
5260
+ */
5261
+
5262
+/* d = a * b (mod c) */
5263
+int mp_mulmod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
5264
+{
5265
+  int     res;
5266
+  mp_int  t;
5267
+
5268
+  if ((res = mp_init (&t)) != MP_OKAY) {
5269
+    return res;
5270
+  }
5271
+
5272
+  if ((res = mp_mul (a, b, &t)) != MP_OKAY) {
5273
+    mp_clear (&t);
5274
+    return res;
5275
+  }
5276
+  res = mp_mod (&t, c, d);
5277
+  mp_clear (&t);
5278
+  return res;
5279
+}
5280
+#endif
5281
+
5282
+/* $Source: /cvs/libtom/libtommath/bn_mp_mulmod.c,v $ */
5283
+/* $Revision: 1.4 $ */
5284
+/* $Date: 2006/03/31 14:18:44 $ */
5285
+
5286
+/* End: bn_mp_mulmod.c */
5287
+
5288
+/* Start: bn_mp_n_root.c */
5289
+#include <bignum.h>
5290
+#ifdef BN_MP_N_ROOT_C
5291
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
5292
+ *
5293
+ * LibTomMath is a library that provides multiple-precision
5294
+ * integer arithmetic as well as number theoretic functionality.
5295
+ *
5296
+ * The library was designed directly after the MPI library by
5297
+ * Michael Fromberger but has been written from scratch with
5298
+ * additional optimizations in place.
5299
+ *
5300
+ * The library is free for all purposes without any express
5301
+ * guarantee it works.
5302
+ *
5303
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
5304
+ */
5305
+
5306
+/* find the n'th root of an integer 
5307
+ *
5308
+ * Result found such that (c)**b <= a and (c+1)**b > a 
5309
+ *
5310
+ * This algorithm uses Newton's approximation 
5311
+ * x[i+1] = x[i] - f(x[i])/f'(x[i]) 
5312
+ * which will find the root in log(N) time where 
5313
+ * each step involves a fair bit.  This is not meant to 
5314
+ * find huge roots [square and cube, etc].
5315
+ */
5316
+int mp_n_root (mp_int * a, mp_digit b, mp_int * c)
5317
+{
5318
+  mp_int  t1, t2, t3;
5319
+  int     res, neg;
5320
+
5321
+  /* input must be positive if b is even */
5322
+  if ((b & 1) == 0 && a->sign == MP_NEG) {
5323
+    return MP_VAL;
5324
+  }
5325
+
5326
+  if ((res = mp_init (&t1)) != MP_OKAY) {
5327
+    return res;
5328
+  }
5329
+
5330
+  if ((res = mp_init (&t2)) != MP_OKAY) {
5331
+    goto LBL_T1;
5332
+  }
5333
+
5334
+  if ((res = mp_init (&t3)) != MP_OKAY) {
5335
+    goto LBL_T2;
5336
+  }
5337
+
5338
+  /* if a is negative fudge the sign but keep track */
5339
+  neg     = a->sign;
5340
+  a->sign = MP_ZPOS;
5341
+
5342
+  /* t2 = 2 */
5343
+  mp_set (&t2, 2);
5344
+
5345
+  do {
5346
+    /* t1 = t2 */
5347
+    if ((res = mp_copy (&t2, &t1)) != MP_OKAY) {
5348
+      goto LBL_T3;
5349
+    }
5350
+
5351
+    /* t2 = t1 - ((t1**b - a) / (b * t1**(b-1))) */
5352
+    
5353
+    /* t3 = t1**(b-1) */
5354
+    if ((res = mp_expt_d (&t1, b - 1, &t3)) != MP_OKAY) {   
5355
+      goto LBL_T3;
5356
+    }
5357
+
5358
+    /* numerator */
5359
+    /* t2 = t1**b */
5360
+    if ((res = mp_mul (&t3, &t1, &t2)) != MP_OKAY) {    
5361
+      goto LBL_T3;
5362
+    }
5363
+
5364
+    /* t2 = t1**b - a */
5365
+    if ((res = mp_sub (&t2, a, &t2)) != MP_OKAY) {  
5366
+      goto LBL_T3;
5367
+    }
5368
+
5369
+    /* denominator */
5370
+    /* t3 = t1**(b-1) * b  */
5371
+    if ((res = mp_mul_d (&t3, b, &t3)) != MP_OKAY) {    
5372
+      goto LBL_T3;
5373
+    }
5374
+
5375
+    /* t3 = (t1**b - a)/(b * t1**(b-1)) */
5376
+    if ((res = mp_div (&t2, &t3, &t3, NULL)) != MP_OKAY) {  
5377
+      goto LBL_T3;
5378
+    }
5379
+
5380
+    if ((res = mp_sub (&t1, &t3, &t2)) != MP_OKAY) {
5381
+      goto LBL_T3;
5382
+    }
5383
+  }  while (mp_cmp (&t1, &t2) != MP_EQ);
5384
+
5385
+  /* result can be off by a few so check */
5386
+  for (;;) {
5387
+    if ((res = mp_expt_d (&t1, b, &t2)) != MP_OKAY) {
5388
+      goto LBL_T3;
5389
+    }
5390
+
5391
+    if (mp_cmp (&t2, a) == MP_GT) {
5392
+      if ((res = mp_sub_d (&t1, 1, &t1)) != MP_OKAY) {
5393
+         goto LBL_T3;
5394
+      }
5395
+    } else {
5396
+      break;
5397
+    }
5398
+  }
5399
+
5400
+  /* reset the sign of a first */
5401
+  a->sign = neg;
5402
+
5403
+  /* set the result */
5404
+  mp_exch (&t1, c);
5405
+
5406
+  /* set the sign of the result */
5407
+  c->sign = neg;
5408
+
5409
+  res = MP_OKAY;
5410
+
5411
+LBL_T3:mp_clear (&t3);
5412
+LBL_T2:mp_clear (&t2);
5413
+LBL_T1:mp_clear (&t1);
5414
+  return res;
5415
+}
5416
+#endif
5417
+
5418
+/* $Source: /cvs/libtom/libtommath/bn_mp_n_root.c,v $ */
5419
+/* $Revision: 1.3 $ */
5420
+/* $Date: 2006/03/31 14:18:44 $ */
5421
+
5422
+/* End: bn_mp_n_root.c */
5423
+
5424
+/* Start: bn_mp_neg.c */
5425
+#include <bignum.h>
5426
+#ifdef BN_MP_NEG_C
5427
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
5428
+ *
5429
+ * LibTomMath is a library that provides multiple-precision
5430
+ * integer arithmetic as well as number theoretic functionality.
5431
+ *
5432
+ * The library was designed directly after the MPI library by
5433
+ * Michael Fromberger but has been written from scratch with
5434
+ * additional optimizations in place.
5435
+ *
5436
+ * The library is free for all purposes without any express
5437
+ * guarantee it works.
5438
+ *
5439
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
5440
+ */
5441
+
5442
+/* b = -a */
5443
+int mp_neg (mp_int * a, mp_int * b)
5444
+{
5445
+  int     res;
5446
+  if (a != b) {
5447
+     if ((res = mp_copy (a, b)) != MP_OKAY) {
5448
+        return res;
5449
+     }
5450
+  }
5451
+
5452
+  if (mp_iszero(b) != MP_YES) {
5453
+     b->sign = (a->sign == MP_ZPOS) ? MP_NEG : MP_ZPOS;
5454
+  } else {
5455
+     b->sign = MP_ZPOS;
5456
+  }
5457
+
5458
+  return MP_OKAY;
5459
+}
5460
+#endif
5461
+
5462
+/* $Source: /cvs/libtom/libtommath/bn_mp_neg.c,v $ */
5463
+/* $Revision: 1.3 $ */
5464
+/* $Date: 2006/03/31 14:18:44 $ */
5465
+
5466
+/* End: bn_mp_neg.c */
5467
+
5468
+/* Start: bn_mp_or.c */
5469
+#include <bignum.h>
5470
+#ifdef BN_MP_OR_C
5471
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
5472
+ *
5473
+ * LibTomMath is a library that provides multiple-precision
5474
+ * integer arithmetic as well as number theoretic functionality.
5475
+ *
5476
+ * The library was designed directly after the MPI library by
5477
+ * Michael Fromberger but has been written from scratch with
5478
+ * additional optimizations in place.
5479
+ *
5480
+ * The library is free for all purposes without any express
5481
+ * guarantee it works.
5482
+ *
5483
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
5484
+ */
5485
+
5486
+/* OR two ints together */
5487
+int mp_or (mp_int * a, mp_int * b, mp_int * c)
5488
+{
5489
+  int     res, ix, px;
5490
+  mp_int  t, *x;
5491
+
5492
+  if (a->used > b->used) {
5493
+    if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
5494
+      return res;
5495
+    }
5496
+    px = b->used;
5497
+    x = b;
5498
+  } else {
5499
+    if ((res = mp_init_copy (&t, b)) != MP_OKAY) {
5500
+      return res;
5501
+    }
5502
+    px = a->used;
5503
+    x = a;
5504
+  }
5505
+
5506
+  for (ix = 0; ix < px; ix++) {
5507
+    t.dp[ix] |= x->dp[ix];
5508
+  }
5509
+  mp_clamp (&t);
5510
+  mp_exch (c, &t);
5511
+  mp_clear (&t);
5512
+  return MP_OKAY;
5513
+}
5514
+#endif
5515
+
5516
+/* $Source: /cvs/libtom/libtommath/bn_mp_or.c,v $ */
5517
+/* $Revision: 1.3 $ */
5518
+/* $Date: 2006/03/31 14:18:44 $ */
5519
+
5520
+/* End: bn_mp_or.c */
5521
+
5522
+/* Start: bn_mp_prime_fermat.c */
5523
+#include <bignum.h>
5524
+#ifdef BN_MP_PRIME_FERMAT_C
5525
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
5526
+ *
5527
+ * LibTomMath is a library that provides multiple-precision
5528
+ * integer arithmetic as well as number theoretic functionality.
5529
+ *
5530
+ * The library was designed directly after the MPI library by
5531
+ * Michael Fromberger but has been written from scratch with
5532
+ * additional optimizations in place.
5533
+ *
5534
+ * The library is free for all purposes without any express
5535
+ * guarantee it works.
5536
+ *
5537
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
5538
+ */
5539
+
5540
+/* performs one Fermat test.
5541
+ * 
5542
+ * If "a" were prime then b**a == b (mod a) since the order of
5543
+ * the multiplicative sub-group would be phi(a) = a-1.  That means
5544
+ * it would be the same as b**(a mod (a-1)) == b**1 == b (mod a).
5545
+ *
5546
+ * Sets result to 1 if the congruence holds, or zero otherwise.
5547
+ */
5548
+int mp_prime_fermat (mp_int * a, mp_int * b, int *result)
5549
+{
5550
+  mp_int  t;
5551
+  int     err;
5552
+
5553
+  /* default to composite  */
5554
+  *result = MP_NO;
5555
+
5556
+  /* ensure b > 1 */
5557
+  if (mp_cmp_d(b, 1) != MP_GT) {
5558
+     return MP_VAL;
5559
+  }
5560
+
5561
+  /* init t */
5562
+  if ((err = mp_init (&t)) != MP_OKAY) {
5563
+    return err;
5564
+  }
5565
+
5566
+  /* compute t = b**a mod a */
5567
+  if ((err = mp_exptmod (b, a, a, &t)) != MP_OKAY) {
5568
+    goto LBL_T;
5569
+  }
5570
+
5571
+  /* is it equal to b? */
5572
+  if (mp_cmp (&t, b) == MP_EQ) {
5573
+    *result = MP_YES;
5574
+  }
5575
+
5576
+  err = MP_OKAY;
5577
+LBL_T:mp_clear (&t);
5578
+  return err;
5579
+}
5580
+#endif
5581
+
5582
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_fermat.c,v $ */
5583
+/* $Revision: 1.3 $ */
5584
+/* $Date: 2006/03/31 14:18:44 $ */
5585
+
5586
+/* End: bn_mp_prime_fermat.c */
5587
+
5588
+/* Start: bn_mp_prime_is_divisible.c */
5589
+#include <bignum.h>
5590
+#ifdef BN_MP_PRIME_IS_DIVISIBLE_C
5591
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
5592
+ *
5593
+ * LibTomMath is a library that provides multiple-precision
5594
+ * integer arithmetic as well as number theoretic functionality.
5595
+ *
5596
+ * The library was designed directly after the MPI library by
5597
+ * Michael Fromberger but has been written from scratch with
5598
+ * additional optimizations in place.
5599
+ *
5600
+ * The library is free for all purposes without any express
5601
+ * guarantee it works.
5602
+ *
5603
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
5604
+ */
5605
+
5606
+/* determines if an integers is divisible by one 
5607
+ * of the first PRIME_SIZE primes or not
5608
+ *
5609
+ * sets result to 0 if not, 1 if yes
5610
+ */
5611
+int mp_prime_is_divisible (mp_int * a, int *result)
5612
+{
5613
+  int     err, ix;
5614
+  mp_digit res;
5615
+
5616
+  /* default to not */
5617
+  *result = MP_NO;
5618
+
5619
+  for (ix = 0; ix < PRIME_SIZE; ix++) {
5620
+    /* what is a mod LBL_prime_tab[ix] */
5621
+    if ((err = mp_mod_d (a, ltm_prime_tab[ix], &res)) != MP_OKAY) {
5622
+      return err;
5623
+    }
5624
+
5625
+    /* is the residue zero? */
5626
+    if (res == 0) {
5627
+      *result = MP_YES;
5628
+      return MP_OKAY;
5629
+    }
5630
+  }
5631
+
5632
+  return MP_OKAY;
5633
+}
5634
+#endif
5635
+
5636
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_is_divisible.c,v $ */
5637
+/* $Revision: 1.3 $ */
5638
+/* $Date: 2006/03/31 14:18:44 $ */
5639
+
5640
+/* End: bn_mp_prime_is_divisible.c */
5641
+
5642
+/* Start: bn_mp_prime_is_prime.c */
5643
+#include <bignum.h>
5644
+#ifdef BN_MP_PRIME_IS_PRIME_C
5645
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
5646
+ *
5647
+ * LibTomMath is a library that provides multiple-precision
5648
+ * integer arithmetic as well as number theoretic functionality.
5649
+ *
5650
+ * The library was designed directly after the MPI library by
5651
+ * Michael Fromberger but has been written from scratch with
5652
+ * additional optimizations in place.
5653
+ *
5654
+ * The library is free for all purposes without any express
5655
+ * guarantee it works.
5656
+ *
5657
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
5658
+ */
5659
+
5660
+/* performs a variable number of rounds of Miller-Rabin
5661
+ *
5662
+ * Probability of error after t rounds is no more than
5663
+
5664
+ *
5665
+ * Sets result to 1 if probably prime, 0 otherwise
5666
+ */
5667
+int mp_prime_is_prime (mp_int * a, int t, int *result)
5668
+{
5669
+  mp_int  b;
5670
+  int     ix, err, res;
5671
+
5672
+  /* default to no */
5673
+  *result = MP_NO;
5674
+
5675
+  /* valid value of t? */
5676
+  if (t <= 0 || t > PRIME_SIZE) {
5677
+    return MP_VAL;
5678
+  }
5679
+
5680
+  /* is the input equal to one of the primes in the table? */
5681
+  for (ix = 0; ix < PRIME_SIZE; ix++) {
5682
+      if (mp_cmp_d(a, ltm_prime_tab[ix]) == MP_EQ) {
5683
+         *result = 1;
5684
+         return MP_OKAY;
5685
+      }
5686
+  }
5687
+
5688
+  /* first perform trial division */
5689
+  if ((err = mp_prime_is_divisible (a, &res)) != MP_OKAY) {
5690
+    return err;
5691
+  }
5692
+
5693
+  /* return if it was trivially divisible */
5694
+  if (res == MP_YES) {
5695
+    return MP_OKAY;
5696
+  }
5697
+
5698
+  /* now perform the miller-rabin rounds */
5699
+  if ((err = mp_init (&b)) != MP_OKAY) {
5700
+    return err;
5701
+  }
5702
+
5703
+  for (ix = 0; ix < t; ix++) {
5704
+    /* set the prime */
5705
+    mp_set (&b, ltm_prime_tab[ix]);
5706
+
5707
+    if ((err = mp_prime_miller_rabin (a, &b, &res)) != MP_OKAY) {
5708
+      goto LBL_B;
5709
+    }
5710
+
5711
+    if (res == MP_NO) {
5712
+      goto LBL_B;
5713
+    }
5714
+  }
5715
+
5716
+  /* passed the test */
5717
+  *result = MP_YES;
5718
+LBL_B:mp_clear (&b);
5719
+  return err;
5720
+}
5721
+#endif
5722
+
5723
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_is_prime.c,v $ */
5724
+/* $Revision: 1.3 $ */
5725
+/* $Date: 2006/03/31 14:18:44 $ */
5726
+
5727
+/* End: bn_mp_prime_is_prime.c */
5728
+
5729
+/* Start: bn_mp_prime_miller_rabin.c */
5730
+#include <bignum.h>
5731
+#ifdef BN_MP_PRIME_MILLER_RABIN_C
5732
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
5733
+ *
5734
+ * LibTomMath is a library that provides multiple-precision
5735
+ * integer arithmetic as well as number theoretic functionality.
5736
+ *
5737
+ * The library was designed directly after the MPI library by
5738
+ * Michael Fromberger but has been written from scratch with
5739
+ * additional optimizations in place.
5740
+ *
5741
+ * The library is free for all purposes without any express
5742
+ * guarantee it works.
5743
+ *
5744
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
5745
+ */
5746
+
5747
+/* Miller-Rabin test of "a" to the base of "b" as described in 
5748
+ * HAC pp. 139 Algorithm 4.24
5749
+ *
5750
+ * Sets result to 0 if definitely composite or 1 if probably prime.
5751
+ * Randomly the chance of error is no more than 1/4 and often 
5752
+ * very much lower.
5753
+ */
5754
+int mp_prime_miller_rabin (mp_int * a, mp_int * b, int *result)
5755
+{
5756
+  mp_int  n1, y, r;
5757
+  int     s, j, err;
5758
+
5759
+  /* default */
5760
+  *result = MP_NO;
5761
+
5762
+  /* ensure b > 1 */
5763
+  if (mp_cmp_d(b, 1) != MP_GT) {
5764
+     return MP_VAL;
5765
+  }     
5766
+
5767
+  /* get n1 = a - 1 */
5768
+  if ((err = mp_init_copy (&n1, a)) != MP_OKAY) {
5769
+    return err;
5770
+  }
5771
+  if ((err = mp_sub_d (&n1, 1, &n1)) != MP_OKAY) {
5772
+    goto LBL_N1;
5773
+  }
5774
+
5775
+  /* set 2**s * r = n1 */
5776
+  if ((err = mp_init_copy (&r, &n1)) != MP_OKAY) {
5777
+    goto LBL_N1;
5778
+  }
5779
+
5780
+  /* count the number of least significant bits
5781
+   * which are zero
5782
+   */
5783
+  s = mp_cnt_lsb(&r);
5784
+
5785
+  /* now divide n - 1 by 2**s */
5786
+  if ((err = mp_div_2d (&r, s, &r, NULL)) != MP_OKAY) {
5787
+    goto LBL_R;
5788
+  }
5789
+
5790
+  /* compute y = b**r mod a */
5791
+  if ((err = mp_init (&y)) != MP_OKAY) {
5792
+    goto LBL_R;
5793
+  }
5794
+  if ((err = mp_exptmod (b, &r, a, &y)) != MP_OKAY) {
5795
+    goto LBL_Y;
5796
+  }
5797
+
5798
+  /* if y != 1 and y != n1 do */
5799
+  if (mp_cmp_d (&y, 1) != MP_EQ && mp_cmp (&y, &n1) != MP_EQ) {
5800
+    j = 1;
5801
+    /* while j <= s-1 and y != n1 */
5802
+    while ((j <= (s - 1)) && mp_cmp (&y, &n1) != MP_EQ) {
5803
+      if ((err = mp_sqrmod (&y, a, &y)) != MP_OKAY) {
5804
+         goto LBL_Y;
5805
+      }
5806
+
5807
+      /* if y == 1 then composite */
5808
+      if (mp_cmp_d (&y, 1) == MP_EQ) {
5809
+         goto LBL_Y;
5810
+      }
5811
+
5812
+      ++j;
5813
+    }
5814
+
5815
+    /* if y != n1 then composite */
5816
+    if (mp_cmp (&y, &n1) != MP_EQ) {
5817
+      goto LBL_Y;
5818
+    }
5819
+  }
5820
+
5821
+  /* probably prime now */
5822
+  *result = MP_YES;
5823
+LBL_Y:mp_clear (&y);
5824
+LBL_R:mp_clear (&r);
5825
+LBL_N1:mp_clear (&n1);
5826
+  return err;
5827
+}
5828
+#endif
5829
+
5830
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_miller_rabin.c,v $ */
5831
+/* $Revision: 1.3 $ */
5832
+/* $Date: 2006/03/31 14:18:44 $ */
5833
+
5834
+/* End: bn_mp_prime_miller_rabin.c */
5835
+
5836
+/* Start: bn_mp_prime_next_prime.c */
5837
+#include <bignum.h>
5838
+#ifdef BN_MP_PRIME_NEXT_PRIME_C
5839
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
5840
+ *
5841
+ * LibTomMath is a library that provides multiple-precision
5842
+ * integer arithmetic as well as number theoretic functionality.
5843
+ *
5844
+ * The library was designed directly after the MPI library by
5845
+ * Michael Fromberger but has been written from scratch with
5846
+ * additional optimizations in place.
5847
+ *
5848
+ * The library is free for all purposes without any express
5849
+ * guarantee it works.
5850
+ *
5851
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
5852
+ */
5853
+
5854
+/* finds the next prime after the number "a" using "t" trials
5855
+ * of Miller-Rabin.
5856
+ *
5857
+ * bbs_style = 1 means the prime must be congruent to 3 mod 4
5858
+ */
5859
+int mp_prime_next_prime(mp_int *a, int t, int bbs_style)
5860
+{
5861
+   int      err, res, x, y;
5862
+   mp_digit res_tab[PRIME_SIZE], step, kstep;
5863
+   mp_int   b;
5864
+
5865
+   /* ensure t is valid */
5866
+   if (t <= 0 || t > PRIME_SIZE) {
5867
+      return MP_VAL;
5868
+   }
5869
+
5870
+   /* force positive */
5871
+   a->sign = MP_ZPOS;
5872
+
5873
+   /* simple algo if a is less than the largest prime in the table */
5874
+   if (mp_cmp_d(a, ltm_prime_tab[PRIME_SIZE-1]) == MP_LT) {
5875
+      /* find which prime it is bigger than */
5876
+      for (x = PRIME_SIZE - 2; x >= 0; x--) {
5877
+          if (mp_cmp_d(a, ltm_prime_tab[x]) != MP_LT) {
5878
+             if (bbs_style == 1) {
5879
+                /* ok we found a prime smaller or
5880
+                 * equal [so the next is larger]
5881
+                 *
5882
+                 * however, the prime must be
5883
+                 * congruent to 3 mod 4
5884
+                 */
5885
+                if ((ltm_prime_tab[x + 1] & 3) != 3) {
5886
+                   /* scan upwards for a prime congruent to 3 mod 4 */
5887
+                   for (y = x + 1; y < PRIME_SIZE; y++) {
5888
+                       if ((ltm_prime_tab[y] & 3) == 3) {
5889
+                          mp_set(a, ltm_prime_tab[y]);
5890
+                          return MP_OKAY;
5891
+                       }
5892
+                   }
5893
+                }
5894
+             } else {
5895
+                mp_set(a, ltm_prime_tab[x + 1]);
5896
+                return MP_OKAY;
5897
+             }
5898
+          }
5899
+      }
5900
+      /* at this point a maybe 1 */
5901
+      if (mp_cmp_d(a, 1) == MP_EQ) {
5902
+         mp_set(a, 2);
5903
+         return MP_OKAY;
5904
+      }
5905
+      /* fall through to the sieve */
5906
+   }
5907
+
5908
+   /* generate a prime congruent to 3 mod 4 or 1/3 mod 4? */
5909
+   if (bbs_style == 1) {
5910
+      kstep   = 4;
5911
+   } else {
5912
+      kstep   = 2;
5913
+   }
5914
+
5915
+   /* at this point we will use a combination of a sieve and Miller-Rabin */
5916
+
5917
+   if (bbs_style == 1) {
5918
+      /* if a mod 4 != 3 subtract the correct value to make it so */
5919
+      if ((a->dp[0] & 3) != 3) {
5920
+         if ((err = mp_sub_d(a, (a->dp[0] & 3) + 1, a)) != MP_OKAY) { return err; };
5921
+      }
5922
+   } else {
5923
+      if (mp_iseven(a) == 1) {
5924
+         /* force odd */
5925
+         if ((err = mp_sub_d(a, 1, a)) != MP_OKAY) {
5926
+            return err;
5927
+         }
5928
+      }
5929
+   }
5930
+
5931
+   /* generate the restable */
5932
+   for (x = 1; x < PRIME_SIZE; x++) {
5933
+      if ((err = mp_mod_d(a, ltm_prime_tab[x], res_tab + x)) != MP_OKAY) {
5934
+         return err;
5935
+      }
5936
+   }
5937
+
5938
+   /* init temp used for Miller-Rabin Testing */
5939
+   if ((err = mp_init(&b)) != MP_OKAY) {
5940
+      return err;
5941
+   }
5942
+
5943
+   for (;;) {
5944
+      /* skip to the next non-trivially divisible candidate */
5945
+      step = 0;
5946
+      do {
5947
+         /* y == 1 if any residue was zero [e.g. cannot be prime] */
5948
+         y     =  0;
5949
+
5950
+         /* increase step to next candidate */
5951
+         step += kstep;
5952
+
5953
+         /* compute the new residue without using division */
5954
+         for (x = 1; x < PRIME_SIZE; x++) {
5955
+             /* add the step to each residue */
5956
+             res_tab[x] += kstep;
5957
+
5958
+             /* subtract the modulus [instead of using division] */
5959
+             if (res_tab[x] >= ltm_prime_tab[x]) {
5960
+                res_tab[x]  -= ltm_prime_tab[x];
5961
+             }
5962
+
5963
+             /* set flag if zero */
5964
+             if (res_tab[x] == 0) {
5965
+                y = 1;
5966
+             }
5967
+         }
5968
+      } while (y == 1 && step < ((((mp_digit)1)<<DIGIT_BIT) - kstep));
5969
+
5970
+      /* add the step */
5971
+      if ((err = mp_add_d(a, step, a)) != MP_OKAY) {
5972
+         goto LBL_ERR;
5973
+      }
5974
+
5975
+      /* if didn't pass sieve and step == MAX then skip test */
5976
+      if (y == 1 && step >= ((((mp_digit)1)<<DIGIT_BIT) - kstep)) {
5977
+         continue;
5978
+      }
5979
+
5980
+      /* is this prime? */
5981
+      for (x = 0; x < t; x++) {
5982
+          mp_set(&b, ltm_prime_tab[t]);
5983
+          if ((err = mp_prime_miller_rabin(a, &b, &res)) != MP_OKAY) {
5984
+             goto LBL_ERR;
5985
+          }
5986
+          if (res == MP_NO) {
5987
+             break;
5988
+          }
5989
+      }
5990
+
5991
+      if (res == MP_YES) {
5992
+         break;
5993
+      }
5994
+   }
5995
+
5996
+   err = MP_OKAY;
5997
+LBL_ERR:
5998
+   mp_clear(&b);
5999
+   return err;
6000
+}
6001
+
6002
+#endif
6003
+
6004
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_next_prime.c,v $ */
6005
+/* $Revision: 1.3 $ */
6006
+/* $Date: 2006/03/31 14:18:44 $ */
6007
+
6008
+/* End: bn_mp_prime_next_prime.c */
6009
+
6010
+/* Start: bn_mp_prime_rabin_miller_trials.c */
6011
+#include <bignum.h>
6012
+#ifdef BN_MP_PRIME_RABIN_MILLER_TRIALS_C
6013
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
6014
+ *
6015
+ * LibTomMath is a library that provides multiple-precision
6016
+ * integer arithmetic as well as number theoretic functionality.
6017
+ *
6018
+ * The library was designed directly after the MPI library by
6019
+ * Michael Fromberger but has been written from scratch with
6020
+ * additional optimizations in place.
6021
+ *
6022
+ * The library is free for all purposes without any express
6023
+ * guarantee it works.
6024
+ *
6025
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
6026
+ */
6027
+
6028
+
6029
+static const struct {
6030
+   int k, t;
6031
+} sizes[] = {
6032
+{   128,    28 },
6033
+{   256,    16 },
6034
+{   384,    10 },
6035
+{   512,     7 },
6036
+{   640,     6 },
6037
+{   768,     5 },
6038
+{   896,     4 },
6039
+{  1024,     4 }
6040
+};
6041
+
6042
+/* returns # of RM trials required for a given bit size */
6043
+int mp_prime_rabin_miller_trials(int size)
6044
+{
6045
+   int x;
6046
+
6047
+   for (x = 0; x < (int)(sizeof(sizes)/(sizeof(sizes[0]))); x++) {
6048
+       if (sizes[x].k == size) {
6049
+          return sizes[x].t;
6050
+       } else if (sizes[x].k > size) {
6051
+          return (x == 0) ? sizes[0].t : sizes[x - 1].t;
6052
+       }
6053
+   }
6054
+   return sizes[x-1].t + 1;
6055
+}
6056
+
6057
+
6058
+#endif
6059
+
6060
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_rabin_miller_trials.c,v $ */
6061
+/* $Revision: 1.3 $ */
6062
+/* $Date: 2006/03/31 14:18:44 $ */
6063
+
6064
+/* End: bn_mp_prime_rabin_miller_trials.c */
6065
+
6066
+/* Start: bn_mp_prime_random_ex.c */
6067
+#include <bignum.h>
6068
+#ifdef BN_MP_PRIME_RANDOM_EX_C
6069
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
6070
+ *
6071
+ * LibTomMath is a library that provides multiple-precision
6072
+ * integer arithmetic as well as number theoretic functionality.
6073
+ *
6074
+ * The library was designed directly after the MPI library by
6075
+ * Michael Fromberger but has been written from scratch with
6076
+ * additional optimizations in place.
6077
+ *
6078
+ * The library is free for all purposes without any express
6079
+ * guarantee it works.
6080
+ *
6081
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
6082
+ */
6083
+
6084
+/* makes a truly random prime of a given size (bits),
6085
+ *
6086
+ * Flags are as follows:
6087
+ * 
6088
+ *   LTM_PRIME_BBS      - make prime congruent to 3 mod 4
6089
+ *   LTM_PRIME_SAFE     - make sure (p-1)/2 is prime as well (implies LTM_PRIME_BBS)
6090
+ *   LTM_PRIME_2MSB_OFF - make the 2nd highest bit zero
6091
+ *   LTM_PRIME_2MSB_ON  - make the 2nd highest bit one
6092
+ *
6093
+ * You have to supply a callback which fills in a buffer with random bytes.  "dat" is a parameter you can
6094
+ * have passed to the callback (e.g. a state or something).  This function doesn't use "dat" itself
6095
+ * so it can be NULL
6096
+ *
6097
+ */
6098
+
6099
+/* This is possibly the mother of all prime generation functions, muahahahahaha! */
6100
+int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback cb, void *dat)
6101
+{
6102
+   unsigned char *tmp, maskAND, maskOR_msb, maskOR_lsb;
6103
+   int res, err, bsize, maskOR_msb_offset;
6104
+
6105
+   /* sanity check the input */
6106
+   if (size <= 1 || t <= 0) {
6107
+      return MP_VAL;
6108
+   }
6109
+
6110
+   /* LTM_PRIME_SAFE implies LTM_PRIME_BBS */
6111
+   if (flags & LTM_PRIME_SAFE) {
6112
+      flags |= LTM_PRIME_BBS;
6113
+   }
6114
+
6115
+   /* calc the byte size */
6116
+   bsize = (size>>3) + ((size&7)?1:0);
6117
+
6118
+   /* we need a buffer of bsize bytes */
6119
+   tmp = OPT_CAST(unsigned char) cli_malloc(bsize);
6120
+   if (tmp == NULL) {
6121
+      return MP_MEM;
6122
+   }
6123
+
6124
+   /* calc the maskAND value for the MSbyte*/
6125
+   maskAND = ((size&7) == 0) ? 0xFF : (0xFF >> (8 - (size & 7)));
6126
+
6127
+   /* calc the maskOR_msb */
6128
+   maskOR_msb        = 0;
6129
+   maskOR_msb_offset = ((size & 7) == 1) ? 1 : 0;
6130
+   if (flags & LTM_PRIME_2MSB_ON) {
6131
+      maskOR_msb       |= 0x80 >> ((9 - size) & 7);
6132
+   }  
6133
+
6134
+   /* get the maskOR_lsb */
6135
+   maskOR_lsb         = 1;
6136
+   if (flags & LTM_PRIME_BBS) {
6137
+      maskOR_lsb     |= 3;
6138
+   }
6139
+
6140
+   do {
6141
+      /* read the bytes */
6142
+      if (cb(tmp, bsize, dat) != bsize) {
6143
+         err = MP_VAL;
6144
+         goto error;
6145
+      }
6146
+ 
6147
+      /* work over the MSbyte */
6148
+      tmp[0]    &= maskAND;
6149
+      tmp[0]    |= 1 << ((size - 1) & 7);
6150
+
6151
+      /* mix in the maskORs */
6152
+      tmp[maskOR_msb_offset]   |= maskOR_msb;
6153
+      tmp[bsize-1]             |= maskOR_lsb;
6154
+
6155
+      /* read it in */
6156
+      if ((err = mp_read_unsigned_bin(a, tmp, bsize)) != MP_OKAY)     { goto error; }
6157
+
6158
+      /* is it prime? */
6159
+      if ((err = mp_prime_is_prime(a, t, &res)) != MP_OKAY)           { goto error; }
6160
+      if (res == MP_NO) {  
6161
+         continue;
6162
+      }
6163
+
6164
+      if (flags & LTM_PRIME_SAFE) {
6165
+         /* see if (a-1)/2 is prime */
6166
+         if ((err = mp_sub_d(a, 1, a)) != MP_OKAY)                    { goto error; }
6167
+         if ((err = mp_div_2(a, a)) != MP_OKAY)                       { goto error; }
6168
+ 
6169
+         /* is it prime? */
6170
+         if ((err = mp_prime_is_prime(a, t, &res)) != MP_OKAY)        { goto error; }
6171
+      }
6172
+   } while (res == MP_NO);
6173
+
6174
+   if (flags & LTM_PRIME_SAFE) {
6175
+      /* restore a to the original value */
6176
+      if ((err = mp_mul_2(a, a)) != MP_OKAY)                          { goto error; }
6177
+      if ((err = mp_add_d(a, 1, a)) != MP_OKAY)                       { goto error; }
6178
+   }
6179
+
6180
+   err = MP_OKAY;
6181
+error:
6182
+   free(tmp);
6183
+   return err;
6184
+}
6185
+
6186
+
6187
+#endif
6188
+
6189
+/* $Source: /cvs/libtom/libtommath/bn_mp_prime_random_ex.c,v $ */
6190
+/* $Revision: 1.4 $ */
6191
+/* $Date: 2006/03/31 14:18:44 $ */
6192
+
6193
+/* End: bn_mp_prime_random_ex.c */
6194
+
6195
+/* Start: bn_mp_radix_size.c */
6196
+#include <bignum.h>
6197
+#ifdef BN_MP_RADIX_SIZE_C
6198
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
6199
+ *
6200
+ * LibTomMath is a library that provides multiple-precision
6201
+ * integer arithmetic as well as number theoretic functionality.
6202
+ *
6203
+ * The library was designed directly after the MPI library by
6204
+ * Michael Fromberger but has been written from scratch with
6205
+ * additional optimizations in place.
6206
+ *
6207
+ * The library is free for all purposes without any express
6208
+ * guarantee it works.
6209
+ *
6210
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
6211
+ */
6212
+
6213
+/* returns size of ASCII reprensentation */
6214
+int mp_radix_size (mp_int * a, int radix, int *size)
6215
+{
6216
+  int     res, digs;
6217
+  mp_int  t;
6218
+  mp_digit d;
6219
+
6220
+  *size = 0;
6221
+
6222
+  /* special case for binary */
6223
+  if (radix == 2) {
6224
+    *size = mp_count_bits (a) + (a->sign == MP_NEG ? 1 : 0) + 1;
6225
+    return MP_OKAY;
6226
+  }
6227
+
6228
+  /* make sure the radix is in range */
6229
+  if (radix < 2 || radix > 64) {
6230
+    return MP_VAL;
6231
+  }
6232
+
6233
+  if (mp_iszero(a) == MP_YES) {
6234
+    *size = 2;
6235
+    return MP_OKAY;
6236
+  }
6237
+
6238
+  /* digs is the digit count */
6239
+  digs = 0;
6240
+
6241
+  /* if it's negative add one for the sign */
6242
+  if (a->sign == MP_NEG) {
6243
+    ++digs;
6244
+  }
6245
+
6246
+  /* init a copy of the input */
6247
+  if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
6248
+    return res;
6249
+  }
6250
+
6251
+  /* force temp to positive */
6252
+  t.sign = MP_ZPOS; 
6253
+
6254
+  /* fetch out all of the digits */
6255
+  while (mp_iszero (&t) == MP_NO) {
6256
+    if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
6257
+      mp_clear (&t);
6258
+      return res;
6259
+    }
6260
+    ++digs;
6261
+  }
6262
+  mp_clear (&t);
6263
+
6264
+  /* return digs + 1, the 1 is for the NULL byte that would be required. */
6265
+  *size = digs + 1;
6266
+  return MP_OKAY;
6267
+}
6268
+
6269
+#endif
6270
+
6271
+/* $Source: /cvs/libtom/libtommath/bn_mp_radix_size.c,v $ */
6272
+/* $Revision: 1.4 $ */
6273
+/* $Date: 2006/03/31 14:18:44 $ */
6274
+
6275
+/* End: bn_mp_radix_size.c */
6276
+
6277
+/* Start: bn_mp_radix_smap.c */
6278
+#include <bignum.h>
6279
+#ifdef BN_MP_RADIX_SMAP_C
6280
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
6281
+ *
6282
+ * LibTomMath is a library that provides multiple-precision
6283
+ * integer arithmetic as well as number theoretic functionality.
6284
+ *
6285
+ * The library was designed directly after the MPI library by
6286
+ * Michael Fromberger but has been written from scratch with
6287
+ * additional optimizations in place.
6288
+ *
6289
+ * The library is free for all purposes without any express
6290
+ * guarantee it works.
6291
+ *
6292
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
6293
+ */
6294
+
6295
+/* chars used in radix conversions */
6296
+const char *mp_s_rmap = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz+/";
6297
+#endif
6298
+
6299
+/* $Source: /cvs/libtom/libtommath/bn_mp_radix_smap.c,v $ */
6300
+/* $Revision: 1.3 $ */
6301
+/* $Date: 2006/03/31 14:18:44 $ */
6302
+
6303
+/* End: bn_mp_radix_smap.c */
6304
+
6305
+/* Start: bn_mp_rand.c */
6306
+#include <bignum.h>
6307
+#ifdef BN_MP_RAND_C
6308
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
6309
+ *
6310
+ * LibTomMath is a library that provides multiple-precision
6311
+ * integer arithmetic as well as number theoretic functionality.
6312
+ *
6313
+ * The library was designed directly after the MPI library by
6314
+ * Michael Fromberger but has been written from scratch with
6315
+ * additional optimizations in place.
6316
+ *
6317
+ * The library is free for all purposes without any express
6318
+ * guarantee it works.
6319
+ *
6320
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
6321
+ */
6322
+
6323
+/* makes a pseudo-random int of a given size */
6324
+int
6325
+mp_rand (mp_int * a, int digits)
6326
+{
6327
+  int     res;
6328
+  mp_digit d;
6329
+
6330
+  mp_zero (a);
6331
+  if (digits <= 0) {
6332
+    return MP_OKAY;
6333
+  }
6334
+
6335
+  /* first place a random non-zero digit */
6336
+  do {
6337
+    d = ((mp_digit) abs (rand ())) & MP_MASK;
6338
+  } while (d == 0);
6339
+
6340
+  if ((res = mp_add_d (a, d, a)) != MP_OKAY) {
6341
+    return res;
6342
+  }
6343
+
6344
+  while (--digits > 0) {
6345
+    if ((res = mp_lshd (a, 1)) != MP_OKAY) {
6346
+      return res;
6347
+    }
6348
+
6349
+    if ((res = mp_add_d (a, ((mp_digit) abs (rand ())), a)) != MP_OKAY) {
6350
+      return res;
6351
+    }
6352
+  }
6353
+
6354
+  return MP_OKAY;
6355
+}
6356
+#endif
6357
+
6358
+/* $Source: /cvs/libtom/libtommath/bn_mp_rand.c,v $ */
6359
+/* $Revision: 1.3 $ */
6360
+/* $Date: 2006/03/31 14:18:44 $ */
6361
+
6362
+/* End: bn_mp_rand.c */
6363
+
6364
+/* Start: bn_mp_read_radix.c */
6365
+#include <bignum.h>
6366
+#ifdef BN_MP_READ_RADIX_C
6367
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
6368
+ *
6369
+ * LibTomMath is a library that provides multiple-precision
6370
+ * integer arithmetic as well as number theoretic functionality.
6371
+ *
6372
+ * The library was designed directly after the MPI library by
6373
+ * Michael Fromberger but has been written from scratch with
6374
+ * additional optimizations in place.
6375
+ *
6376
+ * The library is free for all purposes without any express
6377
+ * guarantee it works.
6378
+ *
6379
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
6380
+ */
6381
+
6382
+/* read a string [ASCII] in a given radix */
6383
+int mp_read_radix (mp_int * a, const char *str, int radix)
6384
+{
6385
+  int     y, res, neg;
6386
+  char    ch;
6387
+
6388
+  /* zero the digit bignum */
6389
+  mp_zero(a);
6390
+
6391
+  /* make sure the radix is ok */
6392
+  if (radix < 2 || radix > 64) {
6393
+    return MP_VAL;
6394
+  }
6395
+
6396
+  /* if the leading digit is a 
6397
+   * minus set the sign to negative. 
6398
+   */
6399
+  if (*str == '-') {
6400
+    ++str;
6401
+    neg = MP_NEG;
6402
+  } else {
6403
+    neg = MP_ZPOS;
6404
+  }
6405
+
6406
+  /* set the integer to the default of zero */
6407
+  mp_zero (a);
6408
+  
6409
+  /* process each digit of the string */
6410
+  while (*str) {
6411
+    /* if the radix < 36 the conversion is case insensitive
6412
+     * this allows numbers like 1AB and 1ab to represent the same  value
6413
+     * [e.g. in hex]
6414
+     */
6415
+    ch = (char) ((radix < 36) ? toupper (*str) : *str);
6416
+    for (y = 0; y < 64; y++) {
6417
+      if (ch == mp_s_rmap[y]) {
6418
+         break;
6419
+      }
6420
+    }
6421
+
6422
+    /* if the char was found in the map 
6423
+     * and is less than the given radix add it
6424
+     * to the number, otherwise exit the loop. 
6425
+     */
6426
+    if (y < radix) {
6427
+      if ((res = mp_mul_d (a, (mp_digit) radix, a)) != MP_OKAY) {
6428
+         return res;
6429
+      }
6430
+      if ((res = mp_add_d (a, (mp_digit) y, a)) != MP_OKAY) {
6431
+         return res;
6432
+      }
6433
+    } else {
6434
+      break;
6435
+    }
6436
+    ++str;
6437
+  }
6438
+  
6439
+  /* set the sign only if a != 0 */
6440
+  if (mp_iszero(a) != 1) {
6441
+     a->sign = neg;
6442
+  }
6443
+  return MP_OKAY;
6444
+}
6445
+#endif
6446
+
6447
+/* $Source: /cvs/libtom/libtommath/bn_mp_read_radix.c,v $ */
6448
+/* $Revision: 1.4 $ */
6449
+/* $Date: 2006/03/31 14:18:44 $ */
6450
+
6451
+/* End: bn_mp_read_radix.c */
6452
+
6453
+/* Start: bn_mp_read_signed_bin.c */
6454
+#include <bignum.h>
6455
+#ifdef BN_MP_READ_SIGNED_BIN_C
6456
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
6457
+ *
6458
+ * LibTomMath is a library that provides multiple-precision
6459
+ * integer arithmetic as well as number theoretic functionality.
6460
+ *
6461
+ * The library was designed directly after the MPI library by
6462
+ * Michael Fromberger but has been written from scratch with
6463
+ * additional optimizations in place.
6464
+ *
6465
+ * The library is free for all purposes without any express
6466
+ * guarantee it works.
6467
+ *
6468
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
6469
+ */
6470
+
6471
+/* read signed bin, big endian, first byte is 0==positive or 1==negative */
6472
+int mp_read_signed_bin (mp_int * a, const unsigned char *b, int c)
6473
+{
6474
+  int     res;
6475
+
6476
+  /* read magnitude */
6477
+  if ((res = mp_read_unsigned_bin (a, b + 1, c - 1)) != MP_OKAY) {
6478
+    return res;
6479
+  }
6480
+
6481
+  /* first byte is 0 for positive, non-zero for negative */
6482
+  if (b[0] == 0) {
6483
+     a->sign = MP_ZPOS;
6484
+  } else {
6485
+     a->sign = MP_NEG;
6486
+  }
6487
+
6488
+  return MP_OKAY;
6489
+}
6490
+#endif
6491
+
6492
+/* $Source: /cvs/libtom/libtommath/bn_mp_read_signed_bin.c,v $ */
6493
+/* $Revision: 1.4 $ */
6494
+/* $Date: 2006/03/31 14:18:44 $ */
6495
+
6496
+/* End: bn_mp_read_signed_bin.c */
6497
+
6498
+/* Start: bn_mp_read_unsigned_bin.c */
6499
+#include <bignum.h>
6500
+#ifdef BN_MP_READ_UNSIGNED_BIN_C
6501
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
6502
+ *
6503
+ * LibTomMath is a library that provides multiple-precision
6504
+ * integer arithmetic as well as number theoretic functionality.
6505
+ *
6506
+ * The library was designed directly after the MPI library by
6507
+ * Michael Fromberger but has been written from scratch with
6508
+ * additional optimizations in place.
6509
+ *
6510
+ * The library is free for all purposes without any express
6511
+ * guarantee it works.
6512
+ *
6513
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
6514
+ */
6515
+
6516
+/* reads a unsigned char array, assumes the msb is stored first [big endian] */
6517
+int mp_read_unsigned_bin (mp_int * a, const unsigned char *b, int c)
6518
+{
6519
+  int     res;
6520
+
6521
+  /* make sure there are at least two digits */
6522
+  if (a->alloc < 2) {
6523
+     if ((res = mp_grow(a, 2)) != MP_OKAY) {
6524
+        return res;
6525
+     }
6526
+  }
6527
+
6528
+  /* zero the int */
6529
+  mp_zero (a);
6530
+
6531
+  /* read the bytes in */
6532
+  while (c-- > 0) {
6533
+    if ((res = mp_mul_2d (a, 8, a)) != MP_OKAY) {
6534
+      return res;
6535
+    }
6536
+
6537
+#ifndef MP_8BIT
6538
+      a->dp[0] |= *b++;
6539
+      a->used += 1;
6540
+#else
6541
+      a->dp[0] = (*b & MP_MASK);
6542
+      a->dp[1] |= ((*b++ >> 7U) & 1);
6543
+      a->used += 2;
6544
+#endif
6545
+  }
6546
+  mp_clamp (a);
6547
+  return MP_OKAY;
6548
+}
6549
+#endif
6550
+
6551
+/* $Source: /cvs/libtom/libtommath/bn_mp_read_unsigned_bin.c,v $ */
6552
+/* $Revision: 1.4 $ */
6553
+/* $Date: 2006/03/31 14:18:44 $ */
6554
+
6555
+/* End: bn_mp_read_unsigned_bin.c */
6556
+
6557
+/* Start: bn_mp_reduce.c */
6558
+#include <bignum.h>
6559
+#ifdef BN_MP_REDUCE_C
6560
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
6561
+ *
6562
+ * LibTomMath is a library that provides multiple-precision
6563
+ * integer arithmetic as well as number theoretic functionality.
6564
+ *
6565
+ * The library was designed directly after the MPI library by
6566
+ * Michael Fromberger but has been written from scratch with
6567
+ * additional optimizations in place.
6568
+ *
6569
+ * The library is free for all purposes without any express
6570
+ * guarantee it works.
6571
+ *
6572
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
6573
+ */
6574
+
6575
+/* reduces x mod m, assumes 0 < x < m**2, mu is 
6576
+ * precomputed via mp_reduce_setup.
6577
+ * From HAC pp.604 Algorithm 14.42
6578
+ */
6579
+int mp_reduce (mp_int * x, mp_int * m, mp_int * mu)
6580
+{
6581
+  mp_int  q;
6582
+  int     res, um = m->used;
6583
+
6584
+  /* q = x */
6585
+  if ((res = mp_init_copy (&q, x)) != MP_OKAY) {
6586
+    return res;
6587
+  }
6588
+
6589
+  /* q1 = x / b**(k-1)  */
6590
+  mp_rshd (&q, um - 1);         
6591
+
6592
+  /* according to HAC this optimization is ok */
6593
+  if (((unsigned long) um) > (((mp_digit)1) << (DIGIT_BIT - 1))) {
6594
+    if ((res = mp_mul (&q, mu, &q)) != MP_OKAY) {
6595
+      goto CLEANUP;
6596
+    }
6597
+  } else {
6598
+#ifdef BN_S_MP_MUL_HIGH_DIGS_C
6599
+    if ((res = s_mp_mul_high_digs (&q, mu, &q, um)) != MP_OKAY) {
6600
+      goto CLEANUP;
6601
+    }
6602
+#elif defined(BN_FAST_S_MP_MUL_HIGH_DIGS_C)
6603
+    if ((res = fast_s_mp_mul_high_digs (&q, mu, &q, um)) != MP_OKAY) {
6604
+      goto CLEANUP;
6605
+    }
6606
+#else 
6607
+    { 
6608
+      res = MP_VAL;
6609
+      goto CLEANUP;
6610
+    }
6611
+#endif
6612
+  }
6613
+
6614
+  /* q3 = q2 / b**(k+1) */
6615
+  mp_rshd (&q, um + 1);         
6616
+
6617
+  /* x = x mod b**(k+1), quick (no division) */
6618
+  if ((res = mp_mod_2d (x, DIGIT_BIT * (um + 1), x)) != MP_OKAY) {
6619
+    goto CLEANUP;
6620
+  }
6621
+
6622
+  /* q = q * m mod b**(k+1), quick (no division) */
6623
+  if ((res = s_mp_mul_digs (&q, m, &q, um + 1)) != MP_OKAY) {
6624
+    goto CLEANUP;
6625
+  }
6626
+
6627
+  /* x = x - q */
6628
+  if ((res = mp_sub (x, &q, x)) != MP_OKAY) {
6629
+    goto CLEANUP;
6630
+  }
6631
+
6632
+  /* If x < 0, add b**(k+1) to it */
6633
+  if (mp_cmp_d (x, 0) == MP_LT) {
6634
+    mp_set (&q, 1);
6635
+    if ((res = mp_lshd (&q, um + 1)) != MP_OKAY)
6636
+      goto CLEANUP;
6637
+    if ((res = mp_add (x, &q, x)) != MP_OKAY)
6638
+      goto CLEANUP;
6639
+  }
6640
+
6641
+  /* Back off if it's too big */
6642
+  while (mp_cmp (x, m) != MP_LT) {
6643
+    if ((res = s_mp_sub (x, m, x)) != MP_OKAY) {
6644
+      goto CLEANUP;
6645
+    }
6646
+  }
6647
+  
6648
+CLEANUP:
6649
+  mp_clear (&q);
6650
+
6651
+  return res;
6652
+}
6653
+#endif
6654
+
6655
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce.c,v $ */
6656
+/* $Revision: 1.3 $ */
6657
+/* $Date: 2006/03/31 14:18:44 $ */
6658
+
6659
+/* End: bn_mp_reduce.c */
6660
+
6661
+/* Start: bn_mp_reduce_2k.c */
6662
+#include <bignum.h>
6663
+#ifdef BN_MP_REDUCE_2K_C
6664
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
6665
+ *
6666
+ * LibTomMath is a library that provides multiple-precision
6667
+ * integer arithmetic as well as number theoretic functionality.
6668
+ *
6669
+ * The library was designed directly after the MPI library by
6670
+ * Michael Fromberger but has been written from scratch with
6671
+ * additional optimizations in place.
6672
+ *
6673
+ * The library is free for all purposes without any express
6674
+ * guarantee it works.
6675
+ *
6676
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
6677
+ */
6678
+
6679
+/* reduces a modulo n where n is of the form 2**p - d */
6680
+int mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d)
6681
+{
6682
+   mp_int q;
6683
+   int    p, res;
6684
+   
6685
+   if ((res = mp_init(&q)) != MP_OKAY) {
6686
+      return res;
6687
+   }
6688
+   
6689
+   p = mp_count_bits(n);    
6690
+top:
6691
+   /* q = a/2**p, a = a mod 2**p */
6692
+   if ((res = mp_div_2d(a, p, &q, a)) != MP_OKAY) {
6693
+      goto ERR;
6694
+   }
6695
+   
6696
+   if (d != 1) {
6697
+      /* q = q * d */
6698
+      if ((res = mp_mul_d(&q, d, &q)) != MP_OKAY) { 
6699
+         goto ERR;
6700
+      }
6701
+   }
6702
+   
6703
+   /* a = a + q */
6704
+   if ((res = s_mp_add(a, &q, a)) != MP_OKAY) {
6705
+      goto ERR;
6706
+   }
6707
+   
6708
+   if (mp_cmp_mag(a, n) != MP_LT) {
6709
+      s_mp_sub(a, n, a);
6710
+      goto top;
6711
+   }
6712
+   
6713
+ERR:
6714
+   mp_clear(&q);
6715
+   return res;
6716
+}
6717
+
6718
+#endif
6719
+
6720
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k.c,v $ */
6721
+/* $Revision: 1.3 $ */
6722
+/* $Date: 2006/03/31 14:18:44 $ */
6723
+
6724
+/* End: bn_mp_reduce_2k.c */
6725
+
6726
+/* Start: bn_mp_reduce_2k_l.c */
6727
+#include <bignum.h>
6728
+#ifdef BN_MP_REDUCE_2K_L_C
6729
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
6730
+ *
6731
+ * LibTomMath is a library that provides multiple-precision
6732
+ * integer arithmetic as well as number theoretic functionality.
6733
+ *
6734
+ * The library was designed directly after the MPI library by
6735
+ * Michael Fromberger but has been written from scratch with
6736
+ * additional optimizations in place.
6737
+ *
6738
+ * The library is free for all purposes without any express
6739
+ * guarantee it works.
6740
+ *
6741
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
6742
+ */
6743
+
6744
+/* reduces a modulo n where n is of the form 2**p - d 
6745
+   This differs from reduce_2k since "d" can be larger
6746
+   than a single digit.
6747
+*/
6748
+int mp_reduce_2k_l(mp_int *a, mp_int *n, mp_int *d)
6749
+{
6750
+   mp_int q;
6751
+   int    p, res;
6752
+   
6753
+   if ((res = mp_init(&q)) != MP_OKAY) {
6754
+      return res;
6755
+   }
6756
+   
6757
+   p = mp_count_bits(n);    
6758
+top:
6759
+   /* q = a/2**p, a = a mod 2**p */
6760
+   if ((res = mp_div_2d(a, p, &q, a)) != MP_OKAY) {
6761
+      goto ERR;
6762
+   }
6763
+   
6764
+   /* q = q * d */
6765
+   if ((res = mp_mul(&q, d, &q)) != MP_OKAY) { 
6766
+      goto ERR;
6767
+   }
6768
+   
6769
+   /* a = a + q */
6770
+   if ((res = s_mp_add(a, &q, a)) != MP_OKAY) {
6771
+      goto ERR;
6772
+   }
6773
+   
6774
+   if (mp_cmp_mag(a, n) != MP_LT) {
6775
+      s_mp_sub(a, n, a);
6776
+      goto top;
6777
+   }
6778
+   
6779
+ERR:
6780
+   mp_clear(&q);
6781
+   return res;
6782
+}
6783
+
6784
+#endif
6785
+
6786
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k_l.c,v $ */
6787
+/* $Revision: 1.3 $ */
6788
+/* $Date: 2006/03/31 14:18:44 $ */
6789
+
6790
+/* End: bn_mp_reduce_2k_l.c */
6791
+
6792
+/* Start: bn_mp_reduce_2k_setup.c */
6793
+#include <bignum.h>
6794
+#ifdef BN_MP_REDUCE_2K_SETUP_C
6795
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
6796
+ *
6797
+ * LibTomMath is a library that provides multiple-precision
6798
+ * integer arithmetic as well as number theoretic functionality.
6799
+ *
6800
+ * The library was designed directly after the MPI library by
6801
+ * Michael Fromberger but has been written from scratch with
6802
+ * additional optimizations in place.
6803
+ *
6804
+ * The library is free for all purposes without any express
6805
+ * guarantee it works.
6806
+ *
6807
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
6808
+ */
6809
+
6810
+/* determines the setup value */
6811
+int mp_reduce_2k_setup(mp_int *a, mp_digit *d)
6812
+{
6813
+   int res, p;
6814
+   mp_int tmp;
6815
+   
6816
+   if ((res = mp_init(&tmp)) != MP_OKAY) {
6817
+      return res;
6818
+   }
6819
+   
6820
+   p = mp_count_bits(a);
6821
+   if ((res = mp_2expt(&tmp, p)) != MP_OKAY) {
6822
+      mp_clear(&tmp);
6823
+      return res;
6824
+   }
6825
+   
6826
+   if ((res = s_mp_sub(&tmp, a, &tmp)) != MP_OKAY) {
6827
+      mp_clear(&tmp);
6828
+      return res;
6829
+   }
6830
+   
6831
+   *d = tmp.dp[0];
6832
+   mp_clear(&tmp);
6833
+   return MP_OKAY;
6834
+}
6835
+#endif
6836
+
6837
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k_setup.c,v $ */
6838
+/* $Revision: 1.3 $ */
6839
+/* $Date: 2006/03/31 14:18:44 $ */
6840
+
6841
+/* End: bn_mp_reduce_2k_setup.c */
6842
+
6843
+/* Start: bn_mp_reduce_2k_setup_l.c */
6844
+#include <bignum.h>
6845
+#ifdef BN_MP_REDUCE_2K_SETUP_L_C
6846
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
6847
+ *
6848
+ * LibTomMath is a library that provides multiple-precision
6849
+ * integer arithmetic as well as number theoretic functionality.
6850
+ *
6851
+ * The library was designed directly after the MPI library by
6852
+ * Michael Fromberger but has been written from scratch with
6853
+ * additional optimizations in place.
6854
+ *
6855
+ * The library is free for all purposes without any express
6856
+ * guarantee it works.
6857
+ *
6858
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
6859
+ */
6860
+
6861
+/* determines the setup value */
6862
+int mp_reduce_2k_setup_l(mp_int *a, mp_int *d)
6863
+{
6864
+   int    res;
6865
+   mp_int tmp;
6866
+   
6867
+   if ((res = mp_init(&tmp)) != MP_OKAY) {
6868
+      return res;
6869
+   }
6870
+   
6871
+   if ((res = mp_2expt(&tmp, mp_count_bits(a))) != MP_OKAY) {
6872
+      goto ERR;
6873
+   }
6874
+   
6875
+   if ((res = s_mp_sub(&tmp, a, d)) != MP_OKAY) {
6876
+      goto ERR;
6877
+   }
6878
+   
6879
+ERR:
6880
+   mp_clear(&tmp);
6881
+   return res;
6882
+}
6883
+#endif
6884
+
6885
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_2k_setup_l.c,v $ */
6886
+/* $Revision: 1.3 $ */
6887
+/* $Date: 2006/03/31 14:18:44 $ */
6888
+
6889
+/* End: bn_mp_reduce_2k_setup_l.c */
6890
+
6891
+/* Start: bn_mp_reduce_is_2k.c */
6892
+#include <bignum.h>
6893
+#ifdef BN_MP_REDUCE_IS_2K_C
6894
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
6895
+ *
6896
+ * LibTomMath is a library that provides multiple-precision
6897
+ * integer arithmetic as well as number theoretic functionality.
6898
+ *
6899
+ * The library was designed directly after the MPI library by
6900
+ * Michael Fromberger but has been written from scratch with
6901
+ * additional optimizations in place.
6902
+ *
6903
+ * The library is free for all purposes without any express
6904
+ * guarantee it works.
6905
+ *
6906
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
6907
+ */
6908
+
6909
+/* determines if mp_reduce_2k can be used */
6910
+int mp_reduce_is_2k(mp_int *a)
6911
+{
6912
+   int ix, iy, iw;
6913
+   mp_digit iz;
6914
+   
6915
+   if (a->used == 0) {
6916
+      return MP_NO;
6917
+   } else if (a->used == 1) {
6918
+      return MP_YES;
6919
+   } else if (a->used > 1) {
6920
+      iy = mp_count_bits(a);
6921
+      iz = 1;
6922
+      iw = 1;
6923
+    
6924
+      /* Test every bit from the second digit up, must be 1 */
6925
+      for (ix = DIGIT_BIT; ix < iy; ix++) {
6926
+          if ((a->dp[iw] & iz) == 0) {
6927
+             return MP_NO;
6928
+          }
6929
+          iz <<= 1;
6930
+          if (iz > (mp_digit)MP_MASK) {
6931
+             ++iw;
6932
+             iz = 1;
6933
+          }
6934
+      }
6935
+   }
6936
+   return MP_YES;
6937
+}
6938
+
6939
+#endif
6940
+
6941
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_is_2k.c,v $ */
6942
+/* $Revision: 1.3 $ */
6943
+/* $Date: 2006/03/31 14:18:44 $ */
6944
+
6945
+/* End: bn_mp_reduce_is_2k.c */
6946
+
6947
+/* Start: bn_mp_reduce_is_2k_l.c */
6948
+#include <bignum.h>
6949
+#ifdef BN_MP_REDUCE_IS_2K_L_C
6950
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
6951
+ *
6952
+ * LibTomMath is a library that provides multiple-precision
6953
+ * integer arithmetic as well as number theoretic functionality.
6954
+ *
6955
+ * The library was designed directly after the MPI library by
6956
+ * Michael Fromberger but has been written from scratch with
6957
+ * additional optimizations in place.
6958
+ *
6959
+ * The library is free for all purposes without any express
6960
+ * guarantee it works.
6961
+ *
6962
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
6963
+ */
6964
+
6965
+/* determines if reduce_2k_l can be used */
6966
+int mp_reduce_is_2k_l(mp_int *a)
6967
+{
6968
+   int ix, iy;
6969
+   
6970
+   if (a->used == 0) {
6971
+      return MP_NO;
6972
+   } else if (a->used == 1) {
6973
+      return MP_YES;
6974
+   } else if (a->used > 1) {
6975
+      /* if more than half of the digits are -1 we're sold */
6976
+      for (iy = ix = 0; ix < a->used; ix++) {
6977
+          if (a->dp[ix] == MP_MASK) {
6978
+              ++iy;
6979
+          }
6980
+      }
6981
+      return (iy >= (a->used/2)) ? MP_YES : MP_NO;
6982
+      
6983
+   }
6984
+   return MP_NO;
6985
+}
6986
+
6987
+#endif
6988
+
6989
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_is_2k_l.c,v $ */
6990
+/* $Revision: 1.3 $ */
6991
+/* $Date: 2006/03/31 14:18:44 $ */
6992
+
6993
+/* End: bn_mp_reduce_is_2k_l.c */
6994
+
6995
+/* Start: bn_mp_reduce_setup.c */
6996
+#include <bignum.h>
6997
+#ifdef BN_MP_REDUCE_SETUP_C
6998
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
6999
+ *
7000
+ * LibTomMath is a library that provides multiple-precision
7001
+ * integer arithmetic as well as number theoretic functionality.
7002
+ *
7003
+ * The library was designed directly after the MPI library by
7004
+ * Michael Fromberger but has been written from scratch with
7005
+ * additional optimizations in place.
7006
+ *
7007
+ * The library is free for all purposes without any express
7008
+ * guarantee it works.
7009
+ *
7010
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
7011
+ */
7012
+
7013
+/* pre-calculate the value required for Barrett reduction
7014
+ * For a given modulus "b" it calulates the value required in "a"
7015
+ */
7016
+int mp_reduce_setup (mp_int * a, mp_int * b)
7017
+{
7018
+  int     res;
7019
+  
7020
+  if ((res = mp_2expt (a, b->used * 2 * DIGIT_BIT)) != MP_OKAY) {
7021
+    return res;
7022
+  }
7023
+  return mp_div (a, b, a, NULL);
7024
+}
7025
+#endif
7026
+
7027
+/* $Source: /cvs/libtom/libtommath/bn_mp_reduce_setup.c,v $ */
7028
+/* $Revision: 1.3 $ */
7029
+/* $Date: 2006/03/31 14:18:44 $ */
7030
+
7031
+/* End: bn_mp_reduce_setup.c */
7032
+
7033
+/* Start: bn_mp_rshd.c */
7034
+#include <bignum.h>
7035
+#ifdef BN_MP_RSHD_C
7036
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
7037
+ *
7038
+ * LibTomMath is a library that provides multiple-precision
7039
+ * integer arithmetic as well as number theoretic functionality.
7040
+ *
7041
+ * The library was designed directly after the MPI library by
7042
+ * Michael Fromberger but has been written from scratch with
7043
+ * additional optimizations in place.
7044
+ *
7045
+ * The library is free for all purposes without any express
7046
+ * guarantee it works.
7047
+ *
7048
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
7049
+ */
7050
+
7051
+/* shift right a certain amount of digits */
7052
+void mp_rshd (mp_int * a, int b)
7053
+{
7054
+  int     x;
7055
+
7056
+  /* if b <= 0 then ignore it */
7057
+  if (b <= 0) {
7058
+    return;
7059
+  }
7060
+
7061
+  /* if b > used then simply zero it and return */
7062
+  if (a->used <= b) {
7063
+    mp_zero (a);
7064
+    return;
7065
+  }
7066
+
7067
+  {
7068
+    register mp_digit *bottom, *top;
7069
+
7070
+    /* shift the digits down */
7071
+
7072
+    /* bottom */
7073
+    bottom = a->dp;
7074
+
7075
+    /* top [offset into digits] */
7076
+    top = a->dp + b;
7077
+
7078
+    /* this is implemented as a sliding window where 
7079
+     * the window is b-digits long and digits from 
7080
+     * the top of the window are copied to the bottom
7081
+     *
7082
+     * e.g.
7083
+
7084
+     b-2 | b-1 | b0 | b1 | b2 | ... | bb |   ---->
7085
+                 /\                   |      ---->
7086
+                  \-------------------/      ---->
7087
+     */
7088
+    for (x = 0; x < (a->used - b); x++) {
7089
+      *bottom++ = *top++;
7090
+    }
7091
+
7092
+    /* zero the top digits */
7093
+    for (; x < a->used; x++) {
7094
+      *bottom++ = 0;
7095
+    }
7096
+  }
7097
+  
7098
+  /* remove excess digits */
7099
+  a->used -= b;
7100
+}
7101
+#endif
7102
+
7103
+/* $Source: /cvs/libtom/libtommath/bn_mp_rshd.c,v $ */
7104
+/* $Revision: 1.3 $ */
7105
+/* $Date: 2006/03/31 14:18:44 $ */
7106
+
7107
+/* End: bn_mp_rshd.c */
7108
+
7109
+/* Start: bn_mp_set.c */
7110
+#include <bignum.h>
7111
+#ifdef BN_MP_SET_C
7112
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
7113
+ *
7114
+ * LibTomMath is a library that provides multiple-precision
7115
+ * integer arithmetic as well as number theoretic functionality.
7116
+ *
7117
+ * The library was designed directly after the MPI library by
7118
+ * Michael Fromberger but has been written from scratch with
7119
+ * additional optimizations in place.
7120
+ *
7121
+ * The library is free for all purposes without any express
7122
+ * guarantee it works.
7123
+ *
7124
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
7125
+ */
7126
+
7127
+/* set to a digit */
7128
+void mp_set (mp_int * a, mp_digit b)
7129
+{
7130
+  mp_zero (a);
7131
+  a->dp[0] = b & MP_MASK;
7132
+  a->used  = (a->dp[0] != 0) ? 1 : 0;
7133
+}
7134
+#endif
7135
+
7136
+/* $Source: /cvs/libtom/libtommath/bn_mp_set.c,v $ */
7137
+/* $Revision: 1.3 $ */
7138
+/* $Date: 2006/03/31 14:18:44 $ */
7139
+
7140
+/* End: bn_mp_set.c */
7141
+
7142
+/* Start: bn_mp_set_int.c */
7143
+#include <bignum.h>
7144
+#ifdef BN_MP_SET_INT_C
7145
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
7146
+ *
7147
+ * LibTomMath is a library that provides multiple-precision
7148
+ * integer arithmetic as well as number theoretic functionality.
7149
+ *
7150
+ * The library was designed directly after the MPI library by
7151
+ * Michael Fromberger but has been written from scratch with
7152
+ * additional optimizations in place.
7153
+ *
7154
+ * The library is free for all purposes without any express
7155
+ * guarantee it works.
7156
+ *
7157
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
7158
+ */
7159
+
7160
+/* set a 32-bit const */
7161
+int mp_set_int (mp_int * a, unsigned long b)
7162
+{
7163
+  int     x, res;
7164
+
7165
+  mp_zero (a);
7166
+  
7167
+  /* set four bits at a time */
7168
+  for (x = 0; x < 8; x++) {
7169
+    /* shift the number up four bits */
7170
+    if ((res = mp_mul_2d (a, 4, a)) != MP_OKAY) {
7171
+      return res;
7172
+    }
7173
+
7174
+    /* OR in the top four bits of the source */
7175
+    a->dp[0] |= (b >> 28) & 15;
7176
+
7177
+    /* shift the source up to the next four bits */
7178
+    b <<= 4;
7179
+
7180
+    /* ensure that digits are not clamped off */
7181
+    a->used += 1;
7182
+  }
7183
+  mp_clamp (a);
7184
+  return MP_OKAY;
7185
+}
7186
+#endif
7187
+
7188
+/* $Source: /cvs/libtom/libtommath/bn_mp_set_int.c,v $ */
7189
+/* $Revision: 1.3 $ */
7190
+/* $Date: 2006/03/31 14:18:44 $ */
7191
+
7192
+/* End: bn_mp_set_int.c */
7193
+
7194
+/* Start: bn_mp_shrink.c */
7195
+#include <bignum.h>
7196
+#ifdef BN_MP_SHRINK_C
7197
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
7198
+ *
7199
+ * LibTomMath is a library that provides multiple-precision
7200
+ * integer arithmetic as well as number theoretic functionality.
7201
+ *
7202
+ * The library was designed directly after the MPI library by
7203
+ * Michael Fromberger but has been written from scratch with
7204
+ * additional optimizations in place.
7205
+ *
7206
+ * The library is free for all purposes without any express
7207
+ * guarantee it works.
7208
+ *
7209
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
7210
+ */
7211
+
7212
+/* shrink a bignum */
7213
+int mp_shrink (mp_int * a)
7214
+{
7215
+  mp_digit *tmp;
7216
+  if (a->alloc != a->used && a->used > 0) {
7217
+    if ((tmp = OPT_CAST(mp_digit) cli_realloc (a->dp, sizeof (mp_digit) * a->used)) == NULL) {
7218
+      return MP_MEM;
7219
+    }
7220
+    a->dp    = tmp;
7221
+    a->alloc = a->used;
7222
+  }
7223
+  return MP_OKAY;
7224
+}
7225
+#endif
7226
+
7227
+/* $Source: /cvs/libtom/libtommath/bn_mp_shrink.c,v $ */
7228
+/* $Revision: 1.3 $ */
7229
+/* $Date: 2006/03/31 14:18:44 $ */
7230
+
7231
+/* End: bn_mp_shrink.c */
7232
+
7233
+/* Start: bn_mp_signed_bin_size.c */
7234
+#include <bignum.h>
7235
+#ifdef BN_MP_SIGNED_BIN_SIZE_C
7236
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
7237
+ *
7238
+ * LibTomMath is a library that provides multiple-precision
7239
+ * integer arithmetic as well as number theoretic functionality.
7240
+ *
7241
+ * The library was designed directly after the MPI library by
7242
+ * Michael Fromberger but has been written from scratch with
7243
+ * additional optimizations in place.
7244
+ *
7245
+ * The library is free for all purposes without any express
7246
+ * guarantee it works.
7247
+ *
7248
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
7249
+ */
7250
+
7251
+/* get the size for an signed equivalent */
7252
+int mp_signed_bin_size (mp_int * a)
7253
+{
7254
+  return 1 + mp_unsigned_bin_size (a);
7255
+}
7256
+#endif
7257
+
7258
+/* $Source: /cvs/libtom/libtommath/bn_mp_signed_bin_size.c,v $ */
7259
+/* $Revision: 1.3 $ */
7260
+/* $Date: 2006/03/31 14:18:44 $ */
7261
+
7262
+/* End: bn_mp_signed_bin_size.c */
7263
+
7264
+/* Start: bn_mp_sqr.c */
7265
+#include <bignum.h>
7266
+#ifdef BN_MP_SQR_C
7267
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
7268
+ *
7269
+ * LibTomMath is a library that provides multiple-precision
7270
+ * integer arithmetic as well as number theoretic functionality.
7271
+ *
7272
+ * The library was designed directly after the MPI library by
7273
+ * Michael Fromberger but has been written from scratch with
7274
+ * additional optimizations in place.
7275
+ *
7276
+ * The library is free for all purposes without any express
7277
+ * guarantee it works.
7278
+ *
7279
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
7280
+ */
7281
+
7282
+/* computes b = a*a */
7283
+int
7284
+mp_sqr (mp_int * a, mp_int * b)
7285
+{
7286
+  int     res;
7287
+
7288
+#ifdef BN_MP_TOOM_SQR_C
7289
+  /* use Toom-Cook? */
7290
+  if (a->used >= TOOM_SQR_CUTOFF) {
7291
+    res = mp_toom_sqr(a, b);
7292
+  /* Karatsuba? */
7293
+  } else 
7294
+#endif
7295
+#ifdef BN_MP_KARATSUBA_SQR_C
7296
+if (a->used >= KARATSUBA_SQR_CUTOFF) {
7297
+    res = mp_karatsuba_sqr (a, b);
7298
+  } else 
7299
+#endif
7300
+  {
7301
+#ifdef BN_FAST_S_MP_SQR_C
7302
+    /* can we use the fast comba multiplier? */
7303
+    if ((a->used * 2 + 1) < MP_WARRAY && 
7304
+         a->used < 
7305
+         (1 << (sizeof(mp_word) * CHAR_BIT - 2*DIGIT_BIT - 1))) {
7306
+      res = fast_s_mp_sqr (a, b);
7307
+    } else
7308
+#endif
7309
+#ifdef BN_S_MP_SQR_C
7310
+      res = s_mp_sqr (a, b);
7311
+#else
7312
+      res = MP_VAL;
7313
+#endif
7314
+  }
7315
+  b->sign = MP_ZPOS;
7316
+  return res;
7317
+}
7318
+#endif
7319
+
7320
+/* $Source: /cvs/libtom/libtommath/bn_mp_sqr.c,v $ */
7321
+/* $Revision: 1.3 $ */
7322
+/* $Date: 2006/03/31 14:18:44 $ */
7323
+
7324
+/* End: bn_mp_sqr.c */
7325
+
7326
+/* Start: bn_mp_sqrmod.c */
7327
+#include <bignum.h>
7328
+#ifdef BN_MP_SQRMOD_C
7329
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
7330
+ *
7331
+ * LibTomMath is a library that provides multiple-precision
7332
+ * integer arithmetic as well as number theoretic functionality.
7333
+ *
7334
+ * The library was designed directly after the MPI library by
7335
+ * Michael Fromberger but has been written from scratch with
7336
+ * additional optimizations in place.
7337
+ *
7338
+ * The library is free for all purposes without any express
7339
+ * guarantee it works.
7340
+ *
7341
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
7342
+ */
7343
+
7344
+/* c = a * a (mod b) */
7345
+int
7346
+mp_sqrmod (mp_int * a, mp_int * b, mp_int * c)
7347
+{
7348
+  int     res;
7349
+  mp_int  t;
7350
+
7351
+  if ((res = mp_init (&t)) != MP_OKAY) {
7352
+    return res;
7353
+  }
7354
+
7355
+  if ((res = mp_sqr (a, &t)) != MP_OKAY) {
7356
+    mp_clear (&t);
7357
+    return res;
7358
+  }
7359
+  res = mp_mod (&t, b, c);
7360
+  mp_clear (&t);
7361
+  return res;
7362
+}
7363
+#endif
7364
+
7365
+/* $Source: /cvs/libtom/libtommath/bn_mp_sqrmod.c,v $ */
7366
+/* $Revision: 1.3 $ */
7367
+/* $Date: 2006/03/31 14:18:44 $ */
7368
+
7369
+/* End: bn_mp_sqrmod.c */
7370
+
7371
+/* Start: bn_mp_sqrt.c */
7372
+#include <bignum.h>
7373
+#ifdef BN_MP_SQRT_C
7374
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
7375
+ *
7376
+ * LibTomMath is a library that provides multiple-precision
7377
+ * integer arithmetic as well as number theoretic functionality.
7378
+ *
7379
+ * The library was designed directly after the MPI library by
7380
+ * Michael Fromberger but has been written from scratch with
7381
+ * additional optimizations in place.
7382
+ *
7383
+ * The library is free for all purposes without any express
7384
+ * guarantee it works.
7385
+ *
7386
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
7387
+ */
7388
+
7389
+/* this function is less generic than mp_n_root, simpler and faster */
7390
+int mp_sqrt(mp_int *arg, mp_int *ret) 
7391
+{
7392
+  int res;
7393
+  mp_int t1,t2;
7394
+
7395
+  /* must be positive */
7396
+  if (arg->sign == MP_NEG) {
7397
+    return MP_VAL;
7398
+  }
7399
+
7400
+  /* easy out */
7401
+  if (mp_iszero(arg) == MP_YES) {
7402
+    mp_zero(ret);
7403
+    return MP_OKAY;
7404
+  }
7405
+
7406
+  if ((res = mp_init_copy(&t1, arg)) != MP_OKAY) {
7407
+    return res;
7408
+  }
7409
+
7410
+  if ((res = mp_init(&t2)) != MP_OKAY) {
7411
+    goto E2;
7412
+  }
7413
+
7414
+  /* First approx. (not very bad for large arg) */
7415
+  mp_rshd (&t1,t1.used/2);
7416
+
7417
+  /* t1 > 0  */ 
7418
+  if ((res = mp_div(arg,&t1,&t2,NULL)) != MP_OKAY) {
7419
+    goto E1;
7420
+  }
7421
+  if ((res = mp_add(&t1,&t2,&t1)) != MP_OKAY) {
7422
+    goto E1;
7423
+  }
7424
+  if ((res = mp_div_2(&t1,&t1)) != MP_OKAY) {
7425
+    goto E1;
7426
+  }
7427
+  /* And now t1 > sqrt(arg) */
7428
+  do { 
7429
+    if ((res = mp_div(arg,&t1,&t2,NULL)) != MP_OKAY) {
7430
+      goto E1;
7431
+    }
7432
+    if ((res = mp_add(&t1,&t2,&t1)) != MP_OKAY) {
7433
+      goto E1;
7434
+    }
7435
+    if ((res = mp_div_2(&t1,&t1)) != MP_OKAY) {
7436
+      goto E1;
7437
+    }
7438
+    /* t1 >= sqrt(arg) >= t2 at this point */
7439
+  } while (mp_cmp_mag(&t1,&t2) == MP_GT);
7440
+
7441
+  mp_exch(&t1,ret);
7442
+
7443
+E1: mp_clear(&t2);
7444
+E2: mp_clear(&t1);
7445
+  return res;
7446
+}
7447
+
7448
+#endif
7449
+
7450
+/* $Source: /cvs/libtom/libtommath/bn_mp_sqrt.c,v $ */
7451
+/* $Revision: 1.3 $ */
7452
+/* $Date: 2006/03/31 14:18:44 $ */
7453
+
7454
+/* End: bn_mp_sqrt.c */
7455
+
7456
+/* Start: bn_mp_sub.c */
7457
+#include <bignum.h>
7458
+#ifdef BN_MP_SUB_C
7459
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
7460
+ *
7461
+ * LibTomMath is a library that provides multiple-precision
7462
+ * integer arithmetic as well as number theoretic functionality.
7463
+ *
7464
+ * The library was designed directly after the MPI library by
7465
+ * Michael Fromberger but has been written from scratch with
7466
+ * additional optimizations in place.
7467
+ *
7468
+ * The library is free for all purposes without any express
7469
+ * guarantee it works.
7470
+ *
7471
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
7472
+ */
7473
+
7474
+/* high level subtraction (handles signs) */
7475
+int
7476
+mp_sub (mp_int * a, mp_int * b, mp_int * c)
7477
+{
7478
+  int     sa, sb, res;
7479
+
7480
+  sa = a->sign;
7481
+  sb = b->sign;
7482
+
7483
+  if (sa != sb) {
7484
+    /* subtract a negative from a positive, OR */
7485
+    /* subtract a positive from a negative. */
7486
+    /* In either case, ADD their magnitudes, */
7487
+    /* and use the sign of the first number. */
7488
+    c->sign = sa;
7489
+    res = s_mp_add (a, b, c);
7490
+  } else {
7491
+    /* subtract a positive from a positive, OR */
7492
+    /* subtract a negative from a negative. */
7493
+    /* First, take the difference between their */
7494
+    /* magnitudes, then... */
7495
+    if (mp_cmp_mag (a, b) != MP_LT) {
7496
+      /* Copy the sign from the first */
7497
+      c->sign = sa;
7498
+      /* The first has a larger or equal magnitude */
7499
+      res = s_mp_sub (a, b, c);
7500
+    } else {
7501
+      /* The result has the *opposite* sign from */
7502
+      /* the first number. */
7503
+      c->sign = (sa == MP_ZPOS) ? MP_NEG : MP_ZPOS;
7504
+      /* The second has a larger magnitude */
7505
+      res = s_mp_sub (b, a, c);
7506
+    }
7507
+  }
7508
+  return res;
7509
+}
7510
+
7511
+#endif
7512
+
7513
+/* $Source: /cvs/libtom/libtommath/bn_mp_sub.c,v $ */
7514
+/* $Revision: 1.3 $ */
7515
+/* $Date: 2006/03/31 14:18:44 $ */
7516
+
7517
+/* End: bn_mp_sub.c */
7518
+
7519
+/* Start: bn_mp_sub_d.c */
7520
+#include <bignum.h>
7521
+#ifdef BN_MP_SUB_D_C
7522
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
7523
+ *
7524
+ * LibTomMath is a library that provides multiple-precision
7525
+ * integer arithmetic as well as number theoretic functionality.
7526
+ *
7527
+ * The library was designed directly after the MPI library by
7528
+ * Michael Fromberger but has been written from scratch with
7529
+ * additional optimizations in place.
7530
+ *
7531
+ * The library is free for all purposes without any express
7532
+ * guarantee it works.
7533
+ *
7534
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
7535
+ */
7536
+
7537
+/* single digit subtraction */
7538
+int
7539
+mp_sub_d (mp_int * a, mp_digit b, mp_int * c)
7540
+{
7541
+  mp_digit *tmpa, *tmpc, mu;
7542
+  int       res, ix, oldused;
7543
+
7544
+  /* grow c as required */
7545
+  if (c->alloc < a->used + 1) {
7546
+     if ((res = mp_grow(c, a->used + 1)) != MP_OKAY) {
7547
+        return res;
7548
+     }
7549
+  }
7550
+
7551
+  /* if a is negative just do an unsigned
7552
+   * addition [with fudged signs]
7553
+   */
7554
+  if (a->sign == MP_NEG) {
7555
+     a->sign = MP_ZPOS;
7556
+     res     = mp_add_d(a, b, c);
7557
+     a->sign = c->sign = MP_NEG;
7558
+
7559
+     /* clamp */
7560
+     mp_clamp(c);
7561
+
7562
+     return res;
7563
+  }
7564
+
7565
+  /* setup regs */
7566
+  oldused = c->used;
7567
+  tmpa    = a->dp;
7568
+  tmpc    = c->dp;
7569
+
7570
+  /* if a <= b simply fix the single digit */
7571
+  if ((a->used == 1 && a->dp[0] <= b) || a->used == 0) {
7572
+     if (a->used == 1) {
7573
+        *tmpc++ = b - *tmpa;
7574
+     } else {
7575
+        *tmpc++ = b;
7576
+     }
7577
+     ix      = 1;
7578
+
7579
+     /* negative/1digit */
7580
+     c->sign = MP_NEG;
7581
+     c->used = 1;
7582
+  } else {
7583
+     /* positive/size */
7584
+     c->sign = MP_ZPOS;
7585
+     c->used = a->used;
7586
+
7587
+     /* subtract first digit */
7588
+     *tmpc    = *tmpa++ - b;
7589
+     mu       = *tmpc >> (sizeof(mp_digit) * CHAR_BIT - 1);
7590
+     *tmpc++ &= MP_MASK;
7591
+
7592
+     /* handle rest of the digits */
7593
+     for (ix = 1; ix < a->used; ix++) {
7594
+        *tmpc    = *tmpa++ - mu;
7595
+        mu       = *tmpc >> (sizeof(mp_digit) * CHAR_BIT - 1);
7596
+        *tmpc++ &= MP_MASK;
7597
+     }
7598
+  }
7599
+
7600
+  /* zero excess digits */
7601
+  while (ix++ < oldused) {
7602
+     *tmpc++ = 0;
7603
+  }
7604
+  mp_clamp(c);
7605
+  return MP_OKAY;
7606
+}
7607
+
7608
+#endif
7609
+
7610
+/* $Source: /cvs/libtom/libtommath/bn_mp_sub_d.c,v $ */
7611
+/* $Revision: 1.5 $ */
7612
+/* $Date: 2006/03/31 14:18:44 $ */
7613
+
7614
+/* End: bn_mp_sub_d.c */
7615
+
7616
+/* Start: bn_mp_submod.c */
7617
+#include <bignum.h>
7618
+#ifdef BN_MP_SUBMOD_C
7619
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
7620
+ *
7621
+ * LibTomMath is a library that provides multiple-precision
7622
+ * integer arithmetic as well as number theoretic functionality.
7623
+ *
7624
+ * The library was designed directly after the MPI library by
7625
+ * Michael Fromberger but has been written from scratch with
7626
+ * additional optimizations in place.
7627
+ *
7628
+ * The library is free for all purposes without any express
7629
+ * guarantee it works.
7630
+ *
7631
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
7632
+ */
7633
+
7634
+/* d = a - b (mod c) */
7635
+int
7636
+mp_submod (mp_int * a, mp_int * b, mp_int * c, mp_int * d)
7637
+{
7638
+  int     res;
7639
+  mp_int  t;
7640
+
7641
+
7642
+  if ((res = mp_init (&t)) != MP_OKAY) {
7643
+    return res;
7644
+  }
7645
+
7646
+  if ((res = mp_sub (a, b, &t)) != MP_OKAY) {
7647
+    mp_clear (&t);
7648
+    return res;
7649
+  }
7650
+  res = mp_mod (&t, c, d);
7651
+  mp_clear (&t);
7652
+  return res;
7653
+}
7654
+#endif
7655
+
7656
+/* $Source: /cvs/libtom/libtommath/bn_mp_submod.c,v $ */
7657
+/* $Revision: 1.3 $ */
7658
+/* $Date: 2006/03/31 14:18:44 $ */
7659
+
7660
+/* End: bn_mp_submod.c */
7661
+
7662
+/* Start: bn_mp_to_signed_bin.c */
7663
+#include <bignum.h>
7664
+#ifdef BN_MP_TO_SIGNED_BIN_C
7665
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
7666
+ *
7667
+ * LibTomMath is a library that provides multiple-precision
7668
+ * integer arithmetic as well as number theoretic functionality.
7669
+ *
7670
+ * The library was designed directly after the MPI library by
7671
+ * Michael Fromberger but has been written from scratch with
7672
+ * additional optimizations in place.
7673
+ *
7674
+ * The library is free for all purposes without any express
7675
+ * guarantee it works.
7676
+ *
7677
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
7678
+ */
7679
+
7680
+/* store in signed [big endian] format */
7681
+int mp_to_signed_bin (mp_int * a, unsigned char *b)
7682
+{
7683
+  int     res;
7684
+
7685
+  if ((res = mp_to_unsigned_bin (a, b + 1)) != MP_OKAY) {
7686
+    return res;
7687
+  }
7688
+  b[0] = (unsigned char) ((a->sign == MP_ZPOS) ? 0 : 1);
7689
+  return MP_OKAY;
7690
+}
7691
+#endif
7692
+
7693
+/* $Source: /cvs/libtom/libtommath/bn_mp_to_signed_bin.c,v $ */
7694
+/* $Revision: 1.3 $ */
7695
+/* $Date: 2006/03/31 14:18:44 $ */
7696
+
7697
+/* End: bn_mp_to_signed_bin.c */
7698
+
7699
+/* Start: bn_mp_to_signed_bin_n.c */
7700
+#include <bignum.h>
7701
+#ifdef BN_MP_TO_SIGNED_BIN_N_C
7702
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
7703
+ *
7704
+ * LibTomMath is a library that provides multiple-precision
7705
+ * integer arithmetic as well as number theoretic functionality.
7706
+ *
7707
+ * The library was designed directly after the MPI library by
7708
+ * Michael Fromberger but has been written from scratch with
7709
+ * additional optimizations in place.
7710
+ *
7711
+ * The library is free for all purposes without any express
7712
+ * guarantee it works.
7713
+ *
7714
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
7715
+ */
7716
+
7717
+/* store in signed [big endian] format */
7718
+int mp_to_signed_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen)
7719
+{
7720
+   if (*outlen < (unsigned long)mp_signed_bin_size(a)) {
7721
+      return MP_VAL;
7722
+   }
7723
+   *outlen = mp_signed_bin_size(a);
7724
+   return mp_to_signed_bin(a, b);
7725
+}
7726
+#endif
7727
+
7728
+/* $Source: /cvs/libtom/libtommath/bn_mp_to_signed_bin_n.c,v $ */
7729
+/* $Revision: 1.3 $ */
7730
+/* $Date: 2006/03/31 14:18:44 $ */
7731
+
7732
+/* End: bn_mp_to_signed_bin_n.c */
7733
+
7734
+/* Start: bn_mp_to_unsigned_bin.c */
7735
+#include <bignum.h>
7736
+#ifdef BN_MP_TO_UNSIGNED_BIN_C
7737
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
7738
+ *
7739
+ * LibTomMath is a library that provides multiple-precision
7740
+ * integer arithmetic as well as number theoretic functionality.
7741
+ *
7742
+ * The library was designed directly after the MPI library by
7743
+ * Michael Fromberger but has been written from scratch with
7744
+ * additional optimizations in place.
7745
+ *
7746
+ * The library is free for all purposes without any express
7747
+ * guarantee it works.
7748
+ *
7749
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
7750
+ */
7751
+
7752
+/* store in unsigned [big endian] format */
7753
+int mp_to_unsigned_bin (mp_int * a, unsigned char *b)
7754
+{
7755
+  int     x, res;
7756
+  mp_int  t;
7757
+
7758
+  if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
7759
+    return res;
7760
+  }
7761
+
7762
+  x = 0;
7763
+  while (mp_iszero (&t) == 0) {
7764
+#ifndef MP_8BIT
7765
+      b[x++] = (unsigned char) (t.dp[0] & 255);
7766
+#else
7767
+      b[x++] = (unsigned char) (t.dp[0] | ((t.dp[1] & 0x01) << 7));
7768
+#endif
7769
+    if ((res = mp_div_2d (&t, 8, &t, NULL)) != MP_OKAY) {
7770
+      mp_clear (&t);
7771
+      return res;
7772
+    }
7773
+  }
7774
+  bn_reverse (b, x);
7775
+  mp_clear (&t);
7776
+  return MP_OKAY;
7777
+}
7778
+#endif
7779
+
7780
+/* $Source: /cvs/libtom/libtommath/bn_mp_to_unsigned_bin.c,v $ */
7781
+/* $Revision: 1.3 $ */
7782
+/* $Date: 2006/03/31 14:18:44 $ */
7783
+
7784
+/* End: bn_mp_to_unsigned_bin.c */
7785
+
7786
+/* Start: bn_mp_to_unsigned_bin_n.c */
7787
+#include <bignum.h>
7788
+#ifdef BN_MP_TO_UNSIGNED_BIN_N_C
7789
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
7790
+ *
7791
+ * LibTomMath is a library that provides multiple-precision
7792
+ * integer arithmetic as well as number theoretic functionality.
7793
+ *
7794
+ * The library was designed directly after the MPI library by
7795
+ * Michael Fromberger but has been written from scratch with
7796
+ * additional optimizations in place.
7797
+ *
7798
+ * The library is free for all purposes without any express
7799
+ * guarantee it works.
7800
+ *
7801
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
7802
+ */
7803
+
7804
+/* store in unsigned [big endian] format */
7805
+int mp_to_unsigned_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen)
7806
+{
7807
+   if (*outlen < (unsigned long)mp_unsigned_bin_size(a)) {
7808
+      return MP_VAL;
7809
+   }
7810
+   *outlen = mp_unsigned_bin_size(a);
7811
+   return mp_to_unsigned_bin(a, b);
7812
+}
7813
+#endif
7814
+
7815
+/* $Source: /cvs/libtom/libtommath/bn_mp_to_unsigned_bin_n.c,v $ */
7816
+/* $Revision: 1.3 $ */
7817
+/* $Date: 2006/03/31 14:18:44 $ */
7818
+
7819
+/* End: bn_mp_to_unsigned_bin_n.c */
7820
+
7821
+/* Start: bn_mp_toom_mul.c */
7822
+#include <bignum.h>
7823
+#ifdef BN_MP_TOOM_MUL_C
7824
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
7825
+ *
7826
+ * LibTomMath is a library that provides multiple-precision
7827
+ * integer arithmetic as well as number theoretic functionality.
7828
+ *
7829
+ * The library was designed directly after the MPI library by
7830
+ * Michael Fromberger but has been written from scratch with
7831
+ * additional optimizations in place.
7832
+ *
7833
+ * The library is free for all purposes without any express
7834
+ * guarantee it works.
7835
+ *
7836
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
7837
+ */
7838
+
7839
+/* multiplication using the Toom-Cook 3-way algorithm 
7840
+ *
7841
+ * Much more complicated than Karatsuba but has a lower 
7842
+ * asymptotic running time of O(N**1.464).  This algorithm is 
7843
+ * only particularly useful on VERY large inputs 
7844
+ * (we're talking 1000s of digits here...).
7845
+*/
7846
+int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c)
7847
+{
7848
+    mp_int w0, w1, w2, w3, w4, tmp1, tmp2, a0, a1, a2, b0, b1, b2;
7849
+    int res, B;
7850
+        
7851
+    /* init temps */
7852
+    if ((res = mp_init_multi(&w0, &w1, &w2, &w3, &w4, 
7853
+                             &a0, &a1, &a2, &b0, &b1, 
7854
+                             &b2, &tmp1, &tmp2, NULL)) != MP_OKAY) {
7855
+       return res;
7856
+    }
7857
+    
7858
+    /* B */
7859
+    B = MIN(a->used, b->used) / 3;
7860
+    
7861
+    /* a = a2 * B**2 + a1 * B + a0 */
7862
+    if ((res = mp_mod_2d(a, DIGIT_BIT * B, &a0)) != MP_OKAY) {
7863
+       goto ERR;
7864
+    }
7865
+
7866
+    if ((res = mp_copy(a, &a1)) != MP_OKAY) {
7867
+       goto ERR;
7868
+    }
7869
+    mp_rshd(&a1, B);
7870
+    mp_mod_2d(&a1, DIGIT_BIT * B, &a1);
7871
+
7872
+    if ((res = mp_copy(a, &a2)) != MP_OKAY) {
7873
+       goto ERR;
7874
+    }
7875
+    mp_rshd(&a2, B*2);
7876
+    
7877
+    /* b = b2 * B**2 + b1 * B + b0 */
7878
+    if ((res = mp_mod_2d(b, DIGIT_BIT * B, &b0)) != MP_OKAY) {
7879
+       goto ERR;
7880
+    }
7881
+
7882
+    if ((res = mp_copy(b, &b1)) != MP_OKAY) {
7883
+       goto ERR;
7884
+    }
7885
+    mp_rshd(&b1, B);
7886
+    mp_mod_2d(&b1, DIGIT_BIT * B, &b1);
7887
+
7888
+    if ((res = mp_copy(b, &b2)) != MP_OKAY) {
7889
+       goto ERR;
7890
+    }
7891
+    mp_rshd(&b2, B*2);
7892
+    
7893
+    /* w0 = a0*b0 */
7894
+    if ((res = mp_mul(&a0, &b0, &w0)) != MP_OKAY) {
7895
+       goto ERR;
7896
+    }
7897
+    
7898
+    /* w4 = a2 * b2 */
7899
+    if ((res = mp_mul(&a2, &b2, &w4)) != MP_OKAY) {
7900
+       goto ERR;
7901
+    }
7902
+    
7903
+    /* w1 = (a2 + 2(a1 + 2a0))(b2 + 2(b1 + 2b0)) */
7904
+    if ((res = mp_mul_2(&a0, &tmp1)) != MP_OKAY) {
7905
+       goto ERR;
7906
+    }
7907
+    if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) {
7908
+       goto ERR;
7909
+    }
7910
+    if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) {
7911
+       goto ERR;
7912
+    }
7913
+    if ((res = mp_add(&tmp1, &a2, &tmp1)) != MP_OKAY) {
7914
+       goto ERR;
7915
+    }
7916
+    
7917
+    if ((res = mp_mul_2(&b0, &tmp2)) != MP_OKAY) {
7918
+       goto ERR;
7919
+    }
7920
+    if ((res = mp_add(&tmp2, &b1, &tmp2)) != MP_OKAY) {
7921
+       goto ERR;
7922
+    }
7923
+    if ((res = mp_mul_2(&tmp2, &tmp2)) != MP_OKAY) {
7924
+       goto ERR;
7925
+    }
7926
+    if ((res = mp_add(&tmp2, &b2, &tmp2)) != MP_OKAY) {
7927
+       goto ERR;
7928
+    }
7929
+    
7930
+    if ((res = mp_mul(&tmp1, &tmp2, &w1)) != MP_OKAY) {
7931
+       goto ERR;
7932
+    }
7933
+    
7934
+    /* w3 = (a0 + 2(a1 + 2a2))(b0 + 2(b1 + 2b2)) */
7935
+    if ((res = mp_mul_2(&a2, &tmp1)) != MP_OKAY) {
7936
+       goto ERR;
7937
+    }
7938
+    if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) {
7939
+       goto ERR;
7940
+    }
7941
+    if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) {
7942
+       goto ERR;
7943
+    }
7944
+    if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) {
7945
+       goto ERR;
7946
+    }
7947
+    
7948
+    if ((res = mp_mul_2(&b2, &tmp2)) != MP_OKAY) {
7949
+       goto ERR;
7950
+    }
7951
+    if ((res = mp_add(&tmp2, &b1, &tmp2)) != MP_OKAY) {
7952
+       goto ERR;
7953
+    }
7954
+    if ((res = mp_mul_2(&tmp2, &tmp2)) != MP_OKAY) {
7955
+       goto ERR;
7956
+    }
7957
+    if ((res = mp_add(&tmp2, &b0, &tmp2)) != MP_OKAY) {
7958
+       goto ERR;
7959
+    }
7960
+    
7961
+    if ((res = mp_mul(&tmp1, &tmp2, &w3)) != MP_OKAY) {
7962
+       goto ERR;
7963
+    }
7964
+    
7965
+
7966
+    /* w2 = (a2 + a1 + a0)(b2 + b1 + b0) */
7967
+    if ((res = mp_add(&a2, &a1, &tmp1)) != MP_OKAY) {
7968
+       goto ERR;
7969
+    }
7970
+    if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) {
7971
+       goto ERR;
7972
+    }
7973
+    if ((res = mp_add(&b2, &b1, &tmp2)) != MP_OKAY) {
7974
+       goto ERR;
7975
+    }
7976
+    if ((res = mp_add(&tmp2, &b0, &tmp2)) != MP_OKAY) {
7977
+       goto ERR;
7978
+    }
7979
+    if ((res = mp_mul(&tmp1, &tmp2, &w2)) != MP_OKAY) {
7980
+       goto ERR;
7981
+    }
7982
+    
7983
+    /* now solve the matrix 
7984
+    
7985
+       0  0  0  0  1
7986
+       1  2  4  8  16
7987
+       1  1  1  1  1
7988
+       16 8  4  2  1
7989
+       1  0  0  0  0
7990
+       
7991
+       using 12 subtractions, 4 shifts, 
7992
+              2 small divisions and 1 small multiplication 
7993
+     */
7994
+     
7995
+     /* r1 - r4 */
7996
+     if ((res = mp_sub(&w1, &w4, &w1)) != MP_OKAY) {
7997
+        goto ERR;
7998
+     }
7999
+     /* r3 - r0 */
8000
+     if ((res = mp_sub(&w3, &w0, &w3)) != MP_OKAY) {
8001
+        goto ERR;
8002
+     }
8003
+     /* r1/2 */
8004
+     if ((res = mp_div_2(&w1, &w1)) != MP_OKAY) {
8005
+        goto ERR;
8006
+     }
8007
+     /* r3/2 */
8008
+     if ((res = mp_div_2(&w3, &w3)) != MP_OKAY) {
8009
+        goto ERR;
8010
+     }
8011
+     /* r2 - r0 - r4 */
8012
+     if ((res = mp_sub(&w2, &w0, &w2)) != MP_OKAY) {
8013
+        goto ERR;
8014
+     }
8015
+     if ((res = mp_sub(&w2, &w4, &w2)) != MP_OKAY) {
8016
+        goto ERR;
8017
+     }
8018
+     /* r1 - r2 */
8019
+     if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) {
8020
+        goto ERR;
8021
+     }
8022
+     /* r3 - r2 */
8023
+     if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) {
8024
+        goto ERR;
8025
+     }
8026
+     /* r1 - 8r0 */
8027
+     if ((res = mp_mul_2d(&w0, 3, &tmp1)) != MP_OKAY) {
8028
+        goto ERR;
8029
+     }
8030
+     if ((res = mp_sub(&w1, &tmp1, &w1)) != MP_OKAY) {
8031
+        goto ERR;
8032
+     }
8033
+     /* r3 - 8r4 */
8034
+     if ((res = mp_mul_2d(&w4, 3, &tmp1)) != MP_OKAY) {
8035
+        goto ERR;
8036
+     }
8037
+     if ((res = mp_sub(&w3, &tmp1, &w3)) != MP_OKAY) {
8038
+        goto ERR;
8039
+     }
8040
+     /* 3r2 - r1 - r3 */
8041
+     if ((res = mp_mul_d(&w2, 3, &w2)) != MP_OKAY) {
8042
+        goto ERR;
8043
+     }
8044
+     if ((res = mp_sub(&w2, &w1, &w2)) != MP_OKAY) {
8045
+        goto ERR;
8046
+     }
8047
+     if ((res = mp_sub(&w2, &w3, &w2)) != MP_OKAY) {
8048
+        goto ERR;
8049
+     }
8050
+     /* r1 - r2 */
8051
+     if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) {
8052
+        goto ERR;
8053
+     }
8054
+     /* r3 - r2 */
8055
+     if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) {
8056
+        goto ERR;
8057
+     }
8058
+     /* r1/3 */
8059
+     if ((res = mp_div_3(&w1, &w1, NULL)) != MP_OKAY) {
8060
+        goto ERR;
8061
+     }
8062
+     /* r3/3 */
8063
+     if ((res = mp_div_3(&w3, &w3, NULL)) != MP_OKAY) {
8064
+        goto ERR;
8065
+     }
8066
+     
8067
+     /* at this point shift W[n] by B*n */
8068
+     if ((res = mp_lshd(&w1, 1*B)) != MP_OKAY) {
8069
+        goto ERR;
8070
+     }
8071
+     if ((res = mp_lshd(&w2, 2*B)) != MP_OKAY) {
8072
+        goto ERR;
8073
+     }
8074
+     if ((res = mp_lshd(&w3, 3*B)) != MP_OKAY) {
8075
+        goto ERR;
8076
+     }
8077
+     if ((res = mp_lshd(&w4, 4*B)) != MP_OKAY) {
8078
+        goto ERR;
8079
+     }     
8080
+     
8081
+     if ((res = mp_add(&w0, &w1, c)) != MP_OKAY) {
8082
+        goto ERR;
8083
+     }
8084
+     if ((res = mp_add(&w2, &w3, &tmp1)) != MP_OKAY) {
8085
+        goto ERR;
8086
+     }
8087
+     if ((res = mp_add(&w4, &tmp1, &tmp1)) != MP_OKAY) {
8088
+        goto ERR;
8089
+     }
8090
+     if ((res = mp_add(&tmp1, c, c)) != MP_OKAY) {
8091
+        goto ERR;
8092
+     }     
8093
+     
8094
+ERR:
8095
+     mp_clear_multi(&w0, &w1, &w2, &w3, &w4, 
8096
+                    &a0, &a1, &a2, &b0, &b1, 
8097
+                    &b2, &tmp1, &tmp2, NULL);
8098
+     return res;
8099
+}     
8100
+     
8101
+#endif
8102
+
8103
+/* $Source: /cvs/libtom/libtommath/bn_mp_toom_mul.c,v $ */
8104
+/* $Revision: 1.3 $ */
8105
+/* $Date: 2006/03/31 14:18:44 $ */
8106
+
8107
+/* End: bn_mp_toom_mul.c */
8108
+
8109
+/* Start: bn_mp_toom_sqr.c */
8110
+#include <bignum.h>
8111
+#ifdef BN_MP_TOOM_SQR_C
8112
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
8113
+ *
8114
+ * LibTomMath is a library that provides multiple-precision
8115
+ * integer arithmetic as well as number theoretic functionality.
8116
+ *
8117
+ * The library was designed directly after the MPI library by
8118
+ * Michael Fromberger but has been written from scratch with
8119
+ * additional optimizations in place.
8120
+ *
8121
+ * The library is free for all purposes without any express
8122
+ * guarantee it works.
8123
+ *
8124
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
8125
+ */
8126
+
8127
+/* squaring using Toom-Cook 3-way algorithm */
8128
+int
8129
+mp_toom_sqr(mp_int *a, mp_int *b)
8130
+{
8131
+    mp_int w0, w1, w2, w3, w4, tmp1, a0, a1, a2;
8132
+    int res, B;
8133
+
8134
+    /* init temps */
8135
+    if ((res = mp_init_multi(&w0, &w1, &w2, &w3, &w4, &a0, &a1, &a2, &tmp1, NULL)) != MP_OKAY) {
8136
+       return res;
8137
+    }
8138
+
8139
+    /* B */
8140
+    B = a->used / 3;
8141
+
8142
+    /* a = a2 * B**2 + a1 * B + a0 */
8143
+    if ((res = mp_mod_2d(a, DIGIT_BIT * B, &a0)) != MP_OKAY) {
8144
+       goto ERR;
8145
+    }
8146
+
8147
+    if ((res = mp_copy(a, &a1)) != MP_OKAY) {
8148
+       goto ERR;
8149
+    }
8150
+    mp_rshd(&a1, B);
8151
+    mp_mod_2d(&a1, DIGIT_BIT * B, &a1);
8152
+
8153
+    if ((res = mp_copy(a, &a2)) != MP_OKAY) {
8154
+       goto ERR;
8155
+    }
8156
+    mp_rshd(&a2, B*2);
8157
+
8158
+    /* w0 = a0*a0 */
8159
+    if ((res = mp_sqr(&a0, &w0)) != MP_OKAY) {
8160
+       goto ERR;
8161
+    }
8162
+
8163
+    /* w4 = a2 * a2 */
8164
+    if ((res = mp_sqr(&a2, &w4)) != MP_OKAY) {
8165
+       goto ERR;
8166
+    }
8167
+
8168
+    /* w1 = (a2 + 2(a1 + 2a0))**2 */
8169
+    if ((res = mp_mul_2(&a0, &tmp1)) != MP_OKAY) {
8170
+       goto ERR;
8171
+    }
8172
+    if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) {
8173
+       goto ERR;
8174
+    }
8175
+    if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) {
8176
+       goto ERR;
8177
+    }
8178
+    if ((res = mp_add(&tmp1, &a2, &tmp1)) != MP_OKAY) {
8179
+       goto ERR;
8180
+    }
8181
+
8182
+    if ((res = mp_sqr(&tmp1, &w1)) != MP_OKAY) {
8183
+       goto ERR;
8184
+    }
8185
+
8186
+    /* w3 = (a0 + 2(a1 + 2a2))**2 */
8187
+    if ((res = mp_mul_2(&a2, &tmp1)) != MP_OKAY) {
8188
+       goto ERR;
8189
+    }
8190
+    if ((res = mp_add(&tmp1, &a1, &tmp1)) != MP_OKAY) {
8191
+       goto ERR;
8192
+    }
8193
+    if ((res = mp_mul_2(&tmp1, &tmp1)) != MP_OKAY) {
8194
+       goto ERR;
8195
+    }
8196
+    if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) {
8197
+       goto ERR;
8198
+    }
8199
+
8200
+    if ((res = mp_sqr(&tmp1, &w3)) != MP_OKAY) {
8201
+       goto ERR;
8202
+    }
8203
+
8204
+
8205
+    /* w2 = (a2 + a1 + a0)**2 */
8206
+    if ((res = mp_add(&a2, &a1, &tmp1)) != MP_OKAY) {
8207
+       goto ERR;
8208
+    }
8209
+    if ((res = mp_add(&tmp1, &a0, &tmp1)) != MP_OKAY) {
8210
+       goto ERR;
8211
+    }
8212
+    if ((res = mp_sqr(&tmp1, &w2)) != MP_OKAY) {
8213
+       goto ERR;
8214
+    }
8215
+
8216
+    /* now solve the matrix
8217
+
8218
+       0  0  0  0  1
8219
+       1  2  4  8  16
8220
+       1  1  1  1  1
8221
+       16 8  4  2  1
8222
+       1  0  0  0  0
8223
+
8224
+       using 12 subtractions, 4 shifts, 2 small divisions and 1 small multiplication.
8225
+     */
8226
+
8227
+     /* r1 - r4 */
8228
+     if ((res = mp_sub(&w1, &w4, &w1)) != MP_OKAY) {
8229
+        goto ERR;
8230
+     }
8231
+     /* r3 - r0 */
8232
+     if ((res = mp_sub(&w3, &w0, &w3)) != MP_OKAY) {
8233
+        goto ERR;
8234
+     }
8235
+     /* r1/2 */
8236
+     if ((res = mp_div_2(&w1, &w1)) != MP_OKAY) {
8237
+        goto ERR;
8238
+     }
8239
+     /* r3/2 */
8240
+     if ((res = mp_div_2(&w3, &w3)) != MP_OKAY) {
8241
+        goto ERR;
8242
+     }
8243
+     /* r2 - r0 - r4 */
8244
+     if ((res = mp_sub(&w2, &w0, &w2)) != MP_OKAY) {
8245
+        goto ERR;
8246
+     }
8247
+     if ((res = mp_sub(&w2, &w4, &w2)) != MP_OKAY) {
8248
+        goto ERR;
8249
+     }
8250
+     /* r1 - r2 */
8251
+     if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) {
8252
+        goto ERR;
8253
+     }
8254
+     /* r3 - r2 */
8255
+     if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) {
8256
+        goto ERR;
8257
+     }
8258
+     /* r1 - 8r0 */
8259
+     if ((res = mp_mul_2d(&w0, 3, &tmp1)) != MP_OKAY) {
8260
+        goto ERR;
8261
+     }
8262
+     if ((res = mp_sub(&w1, &tmp1, &w1)) != MP_OKAY) {
8263
+        goto ERR;
8264
+     }
8265
+     /* r3 - 8r4 */
8266
+     if ((res = mp_mul_2d(&w4, 3, &tmp1)) != MP_OKAY) {
8267
+        goto ERR;
8268
+     }
8269
+     if ((res = mp_sub(&w3, &tmp1, &w3)) != MP_OKAY) {
8270
+        goto ERR;
8271
+     }
8272
+     /* 3r2 - r1 - r3 */
8273
+     if ((res = mp_mul_d(&w2, 3, &w2)) != MP_OKAY) {
8274
+        goto ERR;
8275
+     }
8276
+     if ((res = mp_sub(&w2, &w1, &w2)) != MP_OKAY) {
8277
+        goto ERR;
8278
+     }
8279
+     if ((res = mp_sub(&w2, &w3, &w2)) != MP_OKAY) {
8280
+        goto ERR;
8281
+     }
8282
+     /* r1 - r2 */
8283
+     if ((res = mp_sub(&w1, &w2, &w1)) != MP_OKAY) {
8284
+        goto ERR;
8285
+     }
8286
+     /* r3 - r2 */
8287
+     if ((res = mp_sub(&w3, &w2, &w3)) != MP_OKAY) {
8288
+        goto ERR;
8289
+     }
8290
+     /* r1/3 */
8291
+     if ((res = mp_div_3(&w1, &w1, NULL)) != MP_OKAY) {
8292
+        goto ERR;
8293
+     }
8294
+     /* r3/3 */
8295
+     if ((res = mp_div_3(&w3, &w3, NULL)) != MP_OKAY) {
8296
+        goto ERR;
8297
+     }
8298
+
8299
+     /* at this point shift W[n] by B*n */
8300
+     if ((res = mp_lshd(&w1, 1*B)) != MP_OKAY) {
8301
+        goto ERR;
8302
+     }
8303
+     if ((res = mp_lshd(&w2, 2*B)) != MP_OKAY) {
8304
+        goto ERR;
8305
+     }
8306
+     if ((res = mp_lshd(&w3, 3*B)) != MP_OKAY) {
8307
+        goto ERR;
8308
+     }
8309
+     if ((res = mp_lshd(&w4, 4*B)) != MP_OKAY) {
8310
+        goto ERR;
8311
+     }
8312
+
8313
+     if ((res = mp_add(&w0, &w1, b)) != MP_OKAY) {
8314
+        goto ERR;
8315
+     }
8316
+     if ((res = mp_add(&w2, &w3, &tmp1)) != MP_OKAY) {
8317
+        goto ERR;
8318
+     }
8319
+     if ((res = mp_add(&w4, &tmp1, &tmp1)) != MP_OKAY) {
8320
+        goto ERR;
8321
+     }
8322
+     if ((res = mp_add(&tmp1, b, b)) != MP_OKAY) {
8323
+        goto ERR;
8324
+     }
8325
+
8326
+ERR:
8327
+     mp_clear_multi(&w0, &w1, &w2, &w3, &w4, &a0, &a1, &a2, &tmp1, NULL);
8328
+     return res;
8329
+}
8330
+
8331
+#endif
8332
+
8333
+/* $Source: /cvs/libtom/libtommath/bn_mp_toom_sqr.c,v $ */
8334
+/* $Revision: 1.3 $ */
8335
+/* $Date: 2006/03/31 14:18:44 $ */
8336
+
8337
+/* End: bn_mp_toom_sqr.c */
8338
+
8339
+/* Start: bn_mp_toradix.c */
8340
+#include <bignum.h>
8341
+#ifdef BN_MP_TORADIX_C
8342
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
8343
+ *
8344
+ * LibTomMath is a library that provides multiple-precision
8345
+ * integer arithmetic as well as number theoretic functionality.
8346
+ *
8347
+ * The library was designed directly after the MPI library by
8348
+ * Michael Fromberger but has been written from scratch with
8349
+ * additional optimizations in place.
8350
+ *
8351
+ * The library is free for all purposes without any express
8352
+ * guarantee it works.
8353
+ *
8354
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
8355
+ */
8356
+
8357
+/* stores a bignum as a ASCII string in a given radix (2..64) */
8358
+int mp_toradix (mp_int * a, char *str, int radix)
8359
+{
8360
+  int     res, digs;
8361
+  mp_int  t;
8362
+  mp_digit d;
8363
+  char   *_s = str;
8364
+
8365
+  /* check range of the radix */
8366
+  if (radix < 2 || radix > 64) {
8367
+    return MP_VAL;
8368
+  }
8369
+
8370
+  /* quick out if its zero */
8371
+  if (mp_iszero(a) == 1) {
8372
+     *str++ = '0';
8373
+     *str = '\0';
8374
+     return MP_OKAY;
8375
+  }
8376
+
8377
+  if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
8378
+    return res;
8379
+  }
8380
+
8381
+  /* if it is negative output a - */
8382
+  if (t.sign == MP_NEG) {
8383
+    ++_s;
8384
+    *str++ = '-';
8385
+    t.sign = MP_ZPOS;
8386
+  }
8387
+
8388
+  digs = 0;
8389
+  while (mp_iszero (&t) == 0) {
8390
+    if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
8391
+      mp_clear (&t);
8392
+      return res;
8393
+    }
8394
+    *str++ = mp_s_rmap[d];
8395
+    ++digs;
8396
+  }
8397
+
8398
+  /* reverse the digits of the string.  In this case _s points
8399
+   * to the first digit [exluding the sign] of the number]
8400
+   */
8401
+  bn_reverse ((unsigned char *)_s, digs);
8402
+
8403
+  /* append a NULL so the string is properly terminated */
8404
+  *str = '\0';
8405
+
8406
+  mp_clear (&t);
8407
+  return MP_OKAY;
8408
+}
8409
+
8410
+#endif
8411
+
8412
+/* $Source: /cvs/libtom/libtommath/bn_mp_toradix.c,v $ */
8413
+/* $Revision: 1.3 $ */
8414
+/* $Date: 2006/03/31 14:18:44 $ */
8415
+
8416
+/* End: bn_mp_toradix.c */
8417
+
8418
+/* Start: bn_mp_toradix_n.c */
8419
+#include <bignum.h>
8420
+#ifdef BN_MP_TORADIX_N_C
8421
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
8422
+ *
8423
+ * LibTomMath is a library that provides multiple-precision
8424
+ * integer arithmetic as well as number theoretic functionality.
8425
+ *
8426
+ * The library was designed directly after the MPI library by
8427
+ * Michael Fromberger but has been written from scratch with
8428
+ * additional optimizations in place.
8429
+ *
8430
+ * The library is free for all purposes without any express
8431
+ * guarantee it works.
8432
+ *
8433
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
8434
+ */
8435
+
8436
+/* stores a bignum as a ASCII string in a given radix (2..64) 
8437
+ *
8438
+ * Stores upto maxlen-1 chars and always a NULL byte 
8439
+ */
8440
+int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen)
8441
+{
8442
+  int     res, digs;
8443
+  mp_int  t;
8444
+  mp_digit d;
8445
+  char   *_s = str;
8446
+
8447
+  /* check range of the maxlen, radix */
8448
+  if (maxlen < 2 || radix < 2 || radix > 64) {
8449
+    return MP_VAL;
8450
+  }
8451
+
8452
+  /* quick out if its zero */
8453
+  if (mp_iszero(a) == MP_YES) {
8454
+     *str++ = '0';
8455
+     *str = '\0';
8456
+     return MP_OKAY;
8457
+  }
8458
+
8459
+  if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
8460
+    return res;
8461
+  }
8462
+
8463
+  /* if it is negative output a - */
8464
+  if (t.sign == MP_NEG) {
8465
+    /* we have to reverse our digits later... but not the - sign!! */
8466
+    ++_s;
8467
+
8468
+    /* store the flag and mark the number as positive */
8469
+    *str++ = '-';
8470
+    t.sign = MP_ZPOS;
8471
+ 
8472
+    /* subtract a char */
8473
+    --maxlen;
8474
+  }
8475
+
8476
+  digs = 0;
8477
+  while (mp_iszero (&t) == 0) {
8478
+    if (--maxlen < 1) {
8479
+       /* no more room */
8480
+       break;
8481
+    }
8482
+    if ((res = mp_div_d (&t, (mp_digit) radix, &t, &d)) != MP_OKAY) {
8483
+      mp_clear (&t);
8484
+      return res;
8485
+    }
8486
+    *str++ = mp_s_rmap[d];
8487
+    ++digs;
8488
+  }
8489
+
8490
+  /* reverse the digits of the string.  In this case _s points
8491
+   * to the first digit [exluding the sign] of the number
8492
+   */
8493
+  bn_reverse ((unsigned char *)_s, digs);
8494
+
8495
+  /* append a NULL so the string is properly terminated */
8496
+  *str = '\0';
8497
+
8498
+  mp_clear (&t);
8499
+  return MP_OKAY;
8500
+}
8501
+
8502
+#endif
8503
+
8504
+/* $Source: /cvs/libtom/libtommath/bn_mp_toradix_n.c,v $ */
8505
+/* $Revision: 1.4 $ */
8506
+/* $Date: 2006/03/31 14:18:44 $ */
8507
+
8508
+/* End: bn_mp_toradix_n.c */
8509
+
8510
+/* Start: bn_mp_unsigned_bin_size.c */
8511
+#include <bignum.h>
8512
+#ifdef BN_MP_UNSIGNED_BIN_SIZE_C
8513
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
8514
+ *
8515
+ * LibTomMath is a library that provides multiple-precision
8516
+ * integer arithmetic as well as number theoretic functionality.
8517
+ *
8518
+ * The library was designed directly after the MPI library by
8519
+ * Michael Fromberger but has been written from scratch with
8520
+ * additional optimizations in place.
8521
+ *
8522
+ * The library is free for all purposes without any express
8523
+ * guarantee it works.
8524
+ *
8525
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
8526
+ */
8527
+
8528
+/* get the size for an unsigned equivalent */
8529
+int mp_unsigned_bin_size (mp_int * a)
8530
+{
8531
+  int     size = mp_count_bits (a);
8532
+  return (size / 8 + ((size & 7) != 0 ? 1 : 0));
8533
+}
8534
+#endif
8535
+
8536
+/* $Source: /cvs/libtom/libtommath/bn_mp_unsigned_bin_size.c,v $ */
8537
+/* $Revision: 1.3 $ */
8538
+/* $Date: 2006/03/31 14:18:44 $ */
8539
+
8540
+/* End: bn_mp_unsigned_bin_size.c */
8541
+
8542
+/* Start: bn_mp_xor.c */
8543
+#include <bignum.h>
8544
+#ifdef BN_MP_XOR_C
8545
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
8546
+ *
8547
+ * LibTomMath is a library that provides multiple-precision
8548
+ * integer arithmetic as well as number theoretic functionality.
8549
+ *
8550
+ * The library was designed directly after the MPI library by
8551
+ * Michael Fromberger but has been written from scratch with
8552
+ * additional optimizations in place.
8553
+ *
8554
+ * The library is free for all purposes without any express
8555
+ * guarantee it works.
8556
+ *
8557
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
8558
+ */
8559
+
8560
+/* XOR two ints together */
8561
+int
8562
+mp_xor (mp_int * a, mp_int * b, mp_int * c)
8563
+{
8564
+  int     res, ix, px;
8565
+  mp_int  t, *x;
8566
+
8567
+  if (a->used > b->used) {
8568
+    if ((res = mp_init_copy (&t, a)) != MP_OKAY) {
8569
+      return res;
8570
+    }
8571
+    px = b->used;
8572
+    x = b;
8573
+  } else {
8574
+    if ((res = mp_init_copy (&t, b)) != MP_OKAY) {
8575
+      return res;
8576
+    }
8577
+    px = a->used;
8578
+    x = a;
8579
+  }
8580
+
8581
+  for (ix = 0; ix < px; ix++) {
8582
+     t.dp[ix] ^= x->dp[ix];
8583
+  }
8584
+  mp_clamp (&t);
8585
+  mp_exch (c, &t);
8586
+  mp_clear (&t);
8587
+  return MP_OKAY;
8588
+}
8589
+#endif
8590
+
8591
+/* $Source: /cvs/libtom/libtommath/bn_mp_xor.c,v $ */
8592
+/* $Revision: 1.3 $ */
8593
+/* $Date: 2006/03/31 14:18:44 $ */
8594
+
8595
+/* End: bn_mp_xor.c */
8596
+
8597
+/* Start: bn_mp_zero.c */
8598
+#include <bignum.h>
8599
+#ifdef BN_MP_ZERO_C
8600
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
8601
+ *
8602
+ * LibTomMath is a library that provides multiple-precision
8603
+ * integer arithmetic as well as number theoretic functionality.
8604
+ *
8605
+ * The library was designed directly after the MPI library by
8606
+ * Michael Fromberger but has been written from scratch with
8607
+ * additional optimizations in place.
8608
+ *
8609
+ * The library is free for all purposes without any express
8610
+ * guarantee it works.
8611
+ *
8612
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
8613
+ */
8614
+
8615
+/* set to zero */
8616
+void mp_zero (mp_int * a)
8617
+{
8618
+  int       n;
8619
+  mp_digit *tmp;
8620
+
8621
+  a->sign = MP_ZPOS;
8622
+  a->used = 0;
8623
+
8624
+  tmp = a->dp;
8625
+  for (n = 0; n < a->alloc; n++) {
8626
+     *tmp++ = 0;
8627
+  }
8628
+}
8629
+#endif
8630
+
8631
+/* $Source: /cvs/libtom/libtommath/bn_mp_zero.c,v $ */
8632
+/* $Revision: 1.3 $ */
8633
+/* $Date: 2006/03/31 14:18:44 $ */
8634
+
8635
+/* End: bn_mp_zero.c */
8636
+
8637
+/* Start: bn_prime_tab.c */
8638
+#include <bignum.h>
8639
+#ifdef BN_PRIME_TAB_C
8640
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
8641
+ *
8642
+ * LibTomMath is a library that provides multiple-precision
8643
+ * integer arithmetic as well as number theoretic functionality.
8644
+ *
8645
+ * The library was designed directly after the MPI library by
8646
+ * Michael Fromberger but has been written from scratch with
8647
+ * additional optimizations in place.
8648
+ *
8649
+ * The library is free for all purposes without any express
8650
+ * guarantee it works.
8651
+ *
8652
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
8653
+ */
8654
+const mp_digit ltm_prime_tab[] = {
8655
+  0x0002, 0x0003, 0x0005, 0x0007, 0x000B, 0x000D, 0x0011, 0x0013,
8656
+  0x0017, 0x001D, 0x001F, 0x0025, 0x0029, 0x002B, 0x002F, 0x0035,
8657
+  0x003B, 0x003D, 0x0043, 0x0047, 0x0049, 0x004F, 0x0053, 0x0059,
8658
+  0x0061, 0x0065, 0x0067, 0x006B, 0x006D, 0x0071, 0x007F,
8659
+#ifndef MP_8BIT
8660
+  0x0083,
8661
+  0x0089, 0x008B, 0x0095, 0x0097, 0x009D, 0x00A3, 0x00A7, 0x00AD,
8662
+  0x00B3, 0x00B5, 0x00BF, 0x00C1, 0x00C5, 0x00C7, 0x00D3, 0x00DF,
8663
+  0x00E3, 0x00E5, 0x00E9, 0x00EF, 0x00F1, 0x00FB, 0x0101, 0x0107,
8664
+  0x010D, 0x010F, 0x0115, 0x0119, 0x011B, 0x0125, 0x0133, 0x0137,
8665
+
8666
+  0x0139, 0x013D, 0x014B, 0x0151, 0x015B, 0x015D, 0x0161, 0x0167,
8667
+  0x016F, 0x0175, 0x017B, 0x017F, 0x0185, 0x018D, 0x0191, 0x0199,
8668
+  0x01A3, 0x01A5, 0x01AF, 0x01B1, 0x01B7, 0x01BB, 0x01C1, 0x01C9,
8669
+  0x01CD, 0x01CF, 0x01D3, 0x01DF, 0x01E7, 0x01EB, 0x01F3, 0x01F7,
8670
+  0x01FD, 0x0209, 0x020B, 0x021D, 0x0223, 0x022D, 0x0233, 0x0239,
8671
+  0x023B, 0x0241, 0x024B, 0x0251, 0x0257, 0x0259, 0x025F, 0x0265,
8672
+  0x0269, 0x026B, 0x0277, 0x0281, 0x0283, 0x0287, 0x028D, 0x0293,
8673
+  0x0295, 0x02A1, 0x02A5, 0x02AB, 0x02B3, 0x02BD, 0x02C5, 0x02CF,
8674
+
8675
+  0x02D7, 0x02DD, 0x02E3, 0x02E7, 0x02EF, 0x02F5, 0x02F9, 0x0301,
8676
+  0x0305, 0x0313, 0x031D, 0x0329, 0x032B, 0x0335, 0x0337, 0x033B,
8677
+  0x033D, 0x0347, 0x0355, 0x0359, 0x035B, 0x035F, 0x036D, 0x0371,
8678
+  0x0373, 0x0377, 0x038B, 0x038F, 0x0397, 0x03A1, 0x03A9, 0x03AD,
8679
+  0x03B3, 0x03B9, 0x03C7, 0x03CB, 0x03D1, 0x03D7, 0x03DF, 0x03E5,
8680
+  0x03F1, 0x03F5, 0x03FB, 0x03FD, 0x0407, 0x0409, 0x040F, 0x0419,
8681
+  0x041B, 0x0425, 0x0427, 0x042D, 0x043F, 0x0443, 0x0445, 0x0449,
8682
+  0x044F, 0x0455, 0x045D, 0x0463, 0x0469, 0x047F, 0x0481, 0x048B,
8683
+
8684
+  0x0493, 0x049D, 0x04A3, 0x04A9, 0x04B1, 0x04BD, 0x04C1, 0x04C7,
8685
+  0x04CD, 0x04CF, 0x04D5, 0x04E1, 0x04EB, 0x04FD, 0x04FF, 0x0503,
8686
+  0x0509, 0x050B, 0x0511, 0x0515, 0x0517, 0x051B, 0x0527, 0x0529,
8687
+  0x052F, 0x0551, 0x0557, 0x055D, 0x0565, 0x0577, 0x0581, 0x058F,
8688
+  0x0593, 0x0595, 0x0599, 0x059F, 0x05A7, 0x05AB, 0x05AD, 0x05B3,
8689
+  0x05BF, 0x05C9, 0x05CB, 0x05CF, 0x05D1, 0x05D5, 0x05DB, 0x05E7,
8690
+  0x05F3, 0x05FB, 0x0607, 0x060D, 0x0611, 0x0617, 0x061F, 0x0623,
8691
+  0x062B, 0x062F, 0x063D, 0x0641, 0x0647, 0x0649, 0x064D, 0x0653
8692
+#endif
8693
+};
8694
+#endif
8695
+
8696
+/* $Source: /cvs/libtom/libtommath/bn_prime_tab.c,v $ */
8697
+/* $Revision: 1.3 $ */
8698
+/* $Date: 2006/03/31 14:18:44 $ */
8699
+
8700
+/* End: bn_prime_tab.c */
8701
+
8702
+/* Start: bn_reverse.c */
8703
+#include <bignum.h>
8704
+#ifdef BN_REVERSE_C
8705
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
8706
+ *
8707
+ * LibTomMath is a library that provides multiple-precision
8708
+ * integer arithmetic as well as number theoretic functionality.
8709
+ *
8710
+ * The library was designed directly after the MPI library by
8711
+ * Michael Fromberger but has been written from scratch with
8712
+ * additional optimizations in place.
8713
+ *
8714
+ * The library is free for all purposes without any express
8715
+ * guarantee it works.
8716
+ *
8717
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
8718
+ */
8719
+
8720
+/* reverse an array, used for radix code */
8721
+void
8722
+bn_reverse (unsigned char *s, int len)
8723
+{
8724
+  int     ix, iy;
8725
+  unsigned char t;
8726
+
8727
+  ix = 0;
8728
+  iy = len - 1;
8729
+  while (ix < iy) {
8730
+    t     = s[ix];
8731
+    s[ix] = s[iy];
8732
+    s[iy] = t;
8733
+    ++ix;
8734
+    --iy;
8735
+  }
8736
+}
8737
+#endif
8738
+
8739
+/* $Source: /cvs/libtom/libtommath/bn_reverse.c,v $ */
8740
+/* $Revision: 1.3 $ */
8741
+/* $Date: 2006/03/31 14:18:44 $ */
8742
+
8743
+/* End: bn_reverse.c */
8744
+
8745
+/* Start: bn_s_mp_add.c */
8746
+#include <bignum.h>
8747
+#ifdef BN_S_MP_ADD_C
8748
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
8749
+ *
8750
+ * LibTomMath is a library that provides multiple-precision
8751
+ * integer arithmetic as well as number theoretic functionality.
8752
+ *
8753
+ * The library was designed directly after the MPI library by
8754
+ * Michael Fromberger but has been written from scratch with
8755
+ * additional optimizations in place.
8756
+ *
8757
+ * The library is free for all purposes without any express
8758
+ * guarantee it works.
8759
+ *
8760
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
8761
+ */
8762
+
8763
+/* low level addition, based on HAC pp.594, Algorithm 14.7 */
8764
+int
8765
+s_mp_add (mp_int * a, mp_int * b, mp_int * c)
8766
+{
8767
+  mp_int *x;
8768
+  int     olduse, res, min, max;
8769
+
8770
+  /* find sizes, we let |a| <= |b| which means we have to sort
8771
+   * them.  "x" will point to the input with the most digits
8772
+   */
8773
+  if (a->used > b->used) {
8774
+    min = b->used;
8775
+    max = a->used;
8776
+    x = a;
8777
+  } else {
8778
+    min = a->used;
8779
+    max = b->used;
8780
+    x = b;
8781
+  }
8782
+
8783
+  /* init result */
8784
+  if (c->alloc < max + 1) {
8785
+    if ((res = mp_grow (c, max + 1)) != MP_OKAY) {
8786
+      return res;
8787
+    }
8788
+  }
8789
+
8790
+  /* get old used digit count and set new one */
8791
+  olduse = c->used;
8792
+  c->used = max + 1;
8793
+
8794
+  {
8795
+    register mp_digit u, *tmpa, *tmpb, *tmpc;
8796
+    register int i;
8797
+
8798
+    /* alias for digit pointers */
8799
+
8800
+    /* first input */
8801
+    tmpa = a->dp;
8802
+
8803
+    /* second input */
8804
+    tmpb = b->dp;
8805
+
8806
+    /* destination */
8807
+    tmpc = c->dp;
8808
+
8809
+    /* zero the carry */
8810
+    u = 0;
8811
+    for (i = 0; i < min; i++) {
8812
+      /* Compute the sum at one digit, T[i] = A[i] + B[i] + U */
8813
+      *tmpc = *tmpa++ + *tmpb++ + u;
8814
+
8815
+      /* U = carry bit of T[i] */
8816
+      u = *tmpc >> ((mp_digit)DIGIT_BIT);
8817
+
8818
+      /* take away carry bit from T[i] */
8819
+      *tmpc++ &= MP_MASK;
8820
+    }
8821
+
8822
+    /* now copy higher words if any, that is in A+B 
8823
+     * if A or B has more digits add those in 
8824
+     */
8825
+    if (min != max) {
8826
+      for (; i < max; i++) {
8827
+        /* T[i] = X[i] + U */
8828
+        *tmpc = x->dp[i] + u;
8829
+
8830
+        /* U = carry bit of T[i] */
8831
+        u = *tmpc >> ((mp_digit)DIGIT_BIT);
8832
+
8833
+        /* take away carry bit from T[i] */
8834
+        *tmpc++ &= MP_MASK;
8835
+      }
8836
+    }
8837
+
8838
+    /* add carry */
8839
+    *tmpc++ = u;
8840
+
8841
+    /* clear digits above oldused */
8842
+    for (i = c->used; i < olduse; i++) {
8843
+      *tmpc++ = 0;
8844
+    }
8845
+  }
8846
+
8847
+  mp_clamp (c);
8848
+  return MP_OKAY;
8849
+}
8850
+#endif
8851
+
8852
+/* $Source: /cvs/libtom/libtommath/bn_s_mp_add.c,v $ */
8853
+/* $Revision: 1.3 $ */
8854
+/* $Date: 2006/03/31 14:18:44 $ */
8855
+
8856
+/* End: bn_s_mp_add.c */
8857
+
8858
+/* Start: bn_s_mp_exptmod.c */
8859
+#include <bignum.h>
8860
+#ifdef BN_S_MP_EXPTMOD_C
8861
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
8862
+ *
8863
+ * LibTomMath is a library that provides multiple-precision
8864
+ * integer arithmetic as well as number theoretic functionality.
8865
+ *
8866
+ * The library was designed directly after the MPI library by
8867
+ * Michael Fromberger but has been written from scratch with
8868
+ * additional optimizations in place.
8869
+ *
8870
+ * The library is free for all purposes without any express
8871
+ * guarantee it works.
8872
+ *
8873
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
8874
+ */
8875
+#ifdef MP_LOW_MEM
8876
+   #define TAB_SIZE 32
8877
+#else
8878
+   #define TAB_SIZE 256
8879
+#endif
8880
+
8881
+int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int redmode)
8882
+{
8883
+  mp_int  M[TAB_SIZE], res, mu;
8884
+  mp_digit buf;
8885
+  int     err, bitbuf, bitcpy, bitcnt, mode, digidx, x, y, winsize;
8886
+  int (*redux)(mp_int*,mp_int*,mp_int*);
8887
+
8888
+  /* find window size */
8889
+  x = mp_count_bits (X);
8890
+  if (x <= 7) {
8891
+    winsize = 2;
8892
+  } else if (x <= 36) {
8893
+    winsize = 3;
8894
+  } else if (x <= 140) {
8895
+    winsize = 4;
8896
+  } else if (x <= 450) {
8897
+    winsize = 5;
8898
+  } else if (x <= 1303) {
8899
+    winsize = 6;
8900
+  } else if (x <= 3529) {
8901
+    winsize = 7;
8902
+  } else {
8903
+    winsize = 8;
8904
+  }
8905
+
8906
+#ifdef MP_LOW_MEM
8907
+    if (winsize > 5) {
8908
+       winsize = 5;
8909
+    }
8910
+#endif
8911
+
8912
+  /* init M array */
8913
+  /* init first cell */
8914
+  if ((err = mp_init(&M[1])) != MP_OKAY) {
8915
+     return err; 
8916
+  }
8917
+
8918
+  /* now init the second half of the array */
8919
+  for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
8920
+    if ((err = mp_init(&M[x])) != MP_OKAY) {
8921
+      for (y = 1<<(winsize-1); y < x; y++) {
8922
+        mp_clear (&M[y]);
8923
+      }
8924
+      mp_clear(&M[1]);
8925
+      return err;
8926
+    }
8927
+  }
8928
+
8929
+  /* create mu, used for Barrett reduction */
8930
+  if ((err = mp_init (&mu)) != MP_OKAY) {
8931
+    goto LBL_M;
8932
+  }
8933
+  
8934
+  if (redmode == 0) {
8935
+     if ((err = mp_reduce_setup (&mu, P)) != MP_OKAY) {
8936
+        goto LBL_MU;
8937
+     }
8938
+     redux = mp_reduce;
8939
+  } else {
8940
+     if ((err = mp_reduce_2k_setup_l (P, &mu)) != MP_OKAY) {
8941
+        goto LBL_MU;
8942
+     }
8943
+     redux = mp_reduce_2k_l;
8944
+  }    
8945
+
8946
+  /* create M table
8947
+   *
8948
+   * The M table contains powers of the base, 
8949
+   * e.g. M[x] = G**x mod P
8950
+   *
8951
+   * The first half of the table is not 
8952
+   * computed though accept for M[0] and M[1]
8953
+   */
8954
+  if ((err = mp_mod (G, P, &M[1])) != MP_OKAY) {
8955
+    goto LBL_MU;
8956
+  }
8957
+
8958
+  /* compute the value at M[1<<(winsize-1)] by squaring 
8959
+   * M[1] (winsize-1) times 
8960
+   */
8961
+  if ((err = mp_copy (&M[1], &M[1 << (winsize - 1)])) != MP_OKAY) {
8962
+    goto LBL_MU;
8963
+  }
8964
+
8965
+  for (x = 0; x < (winsize - 1); x++) {
8966
+    /* square it */
8967
+    if ((err = mp_sqr (&M[1 << (winsize - 1)], 
8968
+                       &M[1 << (winsize - 1)])) != MP_OKAY) {
8969
+      goto LBL_MU;
8970
+    }
8971
+
8972
+    /* reduce modulo P */
8973
+    if ((err = redux (&M[1 << (winsize - 1)], P, &mu)) != MP_OKAY) {
8974
+      goto LBL_MU;
8975
+    }
8976
+  }
8977
+
8978
+  /* create upper table, that is M[x] = M[x-1] * M[1] (mod P)
8979
+   * for x = (2**(winsize - 1) + 1) to (2**winsize - 1)
8980
+   */
8981
+  for (x = (1 << (winsize - 1)) + 1; x < (1 << winsize); x++) {
8982
+    if ((err = mp_mul (&M[x - 1], &M[1], &M[x])) != MP_OKAY) {
8983
+      goto LBL_MU;
8984
+    }
8985
+    if ((err = redux (&M[x], P, &mu)) != MP_OKAY) {
8986
+      goto LBL_MU;
8987
+    }
8988
+  }
8989
+
8990
+  /* setup result */
8991
+  if ((err = mp_init (&res)) != MP_OKAY) {
8992
+    goto LBL_MU;
8993
+  }
8994
+  mp_set (&res, 1);
8995
+
8996
+  /* set initial mode and bit cnt */
8997
+  mode   = 0;
8998
+  bitcnt = 1;
8999
+  buf    = 0;
9000
+  digidx = X->used - 1;
9001
+  bitcpy = 0;
9002
+  bitbuf = 0;
9003
+
9004
+  for (;;) {
9005
+    /* grab next digit as required */
9006
+    if (--bitcnt == 0) {
9007
+      /* if digidx == -1 we are out of digits */
9008
+      if (digidx == -1) {
9009
+        break;
9010
+      }
9011
+      /* read next digit and reset the bitcnt */
9012
+      buf    = X->dp[digidx--];
9013
+      bitcnt = (int) DIGIT_BIT;
9014
+    }
9015
+
9016
+    /* grab the next msb from the exponent */
9017
+    y     = (buf >> (mp_digit)(DIGIT_BIT - 1)) & 1;
9018
+    buf <<= (mp_digit)1;
9019
+
9020
+    /* if the bit is zero and mode == 0 then we ignore it
9021
+     * These represent the leading zero bits before the first 1 bit
9022
+     * in the exponent.  Technically this opt is not required but it
9023
+     * does lower the # of trivial squaring/reductions used
9024
+     */
9025
+    if (mode == 0 && y == 0) {
9026
+      continue;
9027
+    }
9028
+
9029
+    /* if the bit is zero and mode == 1 then we square */
9030
+    if (mode == 1 && y == 0) {
9031
+      if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
9032
+        goto LBL_RES;
9033
+      }
9034
+      if ((err = redux (&res, P, &mu)) != MP_OKAY) {
9035
+        goto LBL_RES;
9036
+      }
9037
+      continue;
9038
+    }
9039
+
9040
+    /* else we add it to the window */
9041
+    bitbuf |= (y << (winsize - ++bitcpy));
9042
+    mode    = 2;
9043
+
9044
+    if (bitcpy == winsize) {
9045
+      /* ok window is filled so square as required and multiply  */
9046
+      /* square first */
9047
+      for (x = 0; x < winsize; x++) {
9048
+        if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
9049
+          goto LBL_RES;
9050
+        }
9051
+        if ((err = redux (&res, P, &mu)) != MP_OKAY) {
9052
+          goto LBL_RES;
9053
+        }
9054
+      }
9055
+
9056
+      /* then multiply */
9057
+      if ((err = mp_mul (&res, &M[bitbuf], &res)) != MP_OKAY) {
9058
+        goto LBL_RES;
9059
+      }
9060
+      if ((err = redux (&res, P, &mu)) != MP_OKAY) {
9061
+        goto LBL_RES;
9062
+      }
9063
+
9064
+      /* empty window and reset */
9065
+      bitcpy = 0;
9066
+      bitbuf = 0;
9067
+      mode   = 1;
9068
+    }
9069
+  }
9070
+
9071
+  /* if bits remain then square/multiply */
9072
+  if (mode == 2 && bitcpy > 0) {
9073
+    /* square then multiply if the bit is set */
9074
+    for (x = 0; x < bitcpy; x++) {
9075
+      if ((err = mp_sqr (&res, &res)) != MP_OKAY) {
9076
+        goto LBL_RES;
9077
+      }
9078
+      if ((err = redux (&res, P, &mu)) != MP_OKAY) {
9079
+        goto LBL_RES;
9080
+      }
9081
+
9082
+      bitbuf <<= 1;
9083
+      if ((bitbuf & (1 << winsize)) != 0) {
9084
+        /* then multiply */
9085
+        if ((err = mp_mul (&res, &M[1], &res)) != MP_OKAY) {
9086
+          goto LBL_RES;
9087
+        }
9088
+        if ((err = redux (&res, P, &mu)) != MP_OKAY) {
9089
+          goto LBL_RES;
9090
+        }
9091
+      }
9092
+    }
9093
+  }
9094
+
9095
+  mp_exch (&res, Y);
9096
+  err = MP_OKAY;
9097
+LBL_RES:mp_clear (&res);
9098
+LBL_MU:mp_clear (&mu);
9099
+LBL_M:
9100
+  mp_clear(&M[1]);
9101
+  for (x = 1<<(winsize-1); x < (1 << winsize); x++) {
9102
+    mp_clear (&M[x]);
9103
+  }
9104
+  return err;
9105
+}
9106
+#endif
9107
+
9108
+/* $Source: /cvs/libtom/libtommath/bn_s_mp_exptmod.c,v $ */
9109
+/* $Revision: 1.4 $ */
9110
+/* $Date: 2006/03/31 14:18:44 $ */
9111
+
9112
+/* End: bn_s_mp_exptmod.c */
9113
+
9114
+/* Start: bn_s_mp_mul_digs.c */
9115
+#include <bignum.h>
9116
+#ifdef BN_S_MP_MUL_DIGS_C
9117
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
9118
+ *
9119
+ * LibTomMath is a library that provides multiple-precision
9120
+ * integer arithmetic as well as number theoretic functionality.
9121
+ *
9122
+ * The library was designed directly after the MPI library by
9123
+ * Michael Fromberger but has been written from scratch with
9124
+ * additional optimizations in place.
9125
+ *
9126
+ * The library is free for all purposes without any express
9127
+ * guarantee it works.
9128
+ *
9129
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
9130
+ */
9131
+
9132
+/* multiplies |a| * |b| and only computes upto digs digits of result
9133
+ * HAC pp. 595, Algorithm 14.12  Modified so you can control how 
9134
+ * many digits of output are created.
9135
+ */
9136
+int s_mp_mul_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
9137
+{
9138
+  mp_int  t;
9139
+  int     res, pa, pb, ix, iy;
9140
+  mp_digit u;
9141
+  mp_word r;
9142
+  mp_digit tmpx, *tmpt, *tmpy;
9143
+
9144
+  /* can we use the fast multiplier? */
9145
+  if (((digs) < MP_WARRAY) &&
9146
+      MIN (a->used, b->used) < 
9147
+          (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
9148
+    return fast_s_mp_mul_digs (a, b, c, digs);
9149
+  }
9150
+
9151
+  if ((res = mp_init_size (&t, digs)) != MP_OKAY) {
9152
+    return res;
9153
+  }
9154
+  t.used = digs;
9155
+
9156
+  /* compute the digits of the product directly */
9157
+  pa = a->used;
9158
+  for (ix = 0; ix < pa; ix++) {
9159
+    /* set the carry to zero */
9160
+    u = 0;
9161
+
9162
+    /* limit ourselves to making digs digits of output */
9163
+    pb = MIN (b->used, digs - ix);
9164
+
9165
+    /* setup some aliases */
9166
+    /* copy of the digit from a used within the nested loop */
9167
+    tmpx = a->dp[ix];
9168
+    
9169
+    /* an alias for the destination shifted ix places */
9170
+    tmpt = t.dp + ix;
9171
+    
9172
+    /* an alias for the digits of b */
9173
+    tmpy = b->dp;
9174
+
9175
+    /* compute the columns of the output and propagate the carry */
9176
+    for (iy = 0; iy < pb; iy++) {
9177
+      /* compute the column as a mp_word */
9178
+      r       = ((mp_word)*tmpt) +
9179
+                ((mp_word)tmpx) * ((mp_word)*tmpy++) +
9180
+                ((mp_word) u);
9181
+
9182
+      /* the new column is the lower part of the result */
9183
+      *tmpt++ = (mp_digit) (r & ((mp_word) MP_MASK));
9184
+
9185
+      /* get the carry word from the result */
9186
+      u       = (mp_digit) (r >> ((mp_word) DIGIT_BIT));
9187
+    }
9188
+    /* set carry if it is placed below digs */
9189
+    if (ix + iy < digs) {
9190
+      *tmpt = u;
9191
+    }
9192
+  }
9193
+
9194
+  mp_clamp (&t);
9195
+  mp_exch (&t, c);
9196
+
9197
+  mp_clear (&t);
9198
+  return MP_OKAY;
9199
+}
9200
+#endif
9201
+
9202
+/* $Source: /cvs/libtom/libtommath/bn_s_mp_mul_digs.c,v $ */
9203
+/* $Revision: 1.3 $ */
9204
+/* $Date: 2006/03/31 14:18:44 $ */
9205
+
9206
+/* End: bn_s_mp_mul_digs.c */
9207
+
9208
+/* Start: bn_s_mp_mul_high_digs.c */
9209
+#include <bignum.h>
9210
+#ifdef BN_S_MP_MUL_HIGH_DIGS_C
9211
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
9212
+ *
9213
+ * LibTomMath is a library that provides multiple-precision
9214
+ * integer arithmetic as well as number theoretic functionality.
9215
+ *
9216
+ * The library was designed directly after the MPI library by
9217
+ * Michael Fromberger but has been written from scratch with
9218
+ * additional optimizations in place.
9219
+ *
9220
+ * The library is free for all purposes without any express
9221
+ * guarantee it works.
9222
+ *
9223
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
9224
+ */
9225
+
9226
+/* multiplies |a| * |b| and does not compute the lower digs digits
9227
+ * [meant to get the higher part of the product]
9228
+ */
9229
+int
9230
+s_mp_mul_high_digs (mp_int * a, mp_int * b, mp_int * c, int digs)
9231
+{
9232
+  mp_int  t;
9233
+  int     res, pa, pb, ix, iy;
9234
+  mp_digit u;
9235
+  mp_word r;
9236
+  mp_digit tmpx, *tmpt, *tmpy;
9237
+
9238
+  /* can we use the fast multiplier? */
9239
+#ifdef BN_FAST_S_MP_MUL_HIGH_DIGS_C
9240
+  if (((a->used + b->used + 1) < MP_WARRAY)
9241
+      && MIN (a->used, b->used) < (1 << ((CHAR_BIT * sizeof (mp_word)) - (2 * DIGIT_BIT)))) {
9242
+    return fast_s_mp_mul_high_digs (a, b, c, digs);
9243
+  }
9244
+#endif
9245
+
9246
+  if ((res = mp_init_size (&t, a->used + b->used + 1)) != MP_OKAY) {
9247
+    return res;
9248
+  }
9249
+  t.used = a->used + b->used + 1;
9250
+
9251
+  pa = a->used;
9252
+  pb = b->used;
9253
+  for (ix = 0; ix < pa; ix++) {
9254
+    /* clear the carry */
9255
+    u = 0;
9256
+
9257
+    /* left hand side of A[ix] * B[iy] */
9258
+    tmpx = a->dp[ix];
9259
+
9260
+    /* alias to the address of where the digits will be stored */
9261
+    tmpt = &(t.dp[digs]);
9262
+
9263
+    /* alias for where to read the right hand side from */
9264
+    tmpy = b->dp + (digs - ix);
9265
+
9266
+    for (iy = digs - ix; iy < pb; iy++) {
9267
+      /* calculate the double precision result */
9268
+      r       = ((mp_word)*tmpt) +
9269
+                ((mp_word)tmpx) * ((mp_word)*tmpy++) +
9270
+                ((mp_word) u);
9271
+
9272
+      /* get the lower part */
9273
+      *tmpt++ = (mp_digit) (r & ((mp_word) MP_MASK));
9274
+
9275
+      /* carry the carry */
9276
+      u       = (mp_digit) (r >> ((mp_word) DIGIT_BIT));
9277
+    }
9278
+    *tmpt = u;
9279
+  }
9280
+  mp_clamp (&t);
9281
+  mp_exch (&t, c);
9282
+  mp_clear (&t);
9283
+  return MP_OKAY;
9284
+}
9285
+#endif
9286
+
9287
+/* $Source: /cvs/libtom/libtommath/bn_s_mp_mul_high_digs.c,v $ */
9288
+/* $Revision: 1.3 $ */
9289
+/* $Date: 2006/03/31 14:18:44 $ */
9290
+
9291
+/* End: bn_s_mp_mul_high_digs.c */
9292
+
9293
+/* Start: bn_s_mp_sqr.c */
9294
+#include <bignum.h>
9295
+#ifdef BN_S_MP_SQR_C
9296
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
9297
+ *
9298
+ * LibTomMath is a library that provides multiple-precision
9299
+ * integer arithmetic as well as number theoretic functionality.
9300
+ *
9301
+ * The library was designed directly after the MPI library by
9302
+ * Michael Fromberger but has been written from scratch with
9303
+ * additional optimizations in place.
9304
+ *
9305
+ * The library is free for all purposes without any express
9306
+ * guarantee it works.
9307
+ *
9308
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
9309
+ */
9310
+
9311
+/* low level squaring, b = a*a, HAC pp.596-597, Algorithm 14.16 */
9312
+int s_mp_sqr (mp_int * a, mp_int * b)
9313
+{
9314
+  mp_int  t;
9315
+  int     res, ix, iy, pa;
9316
+  mp_word r;
9317
+  mp_digit u, tmpx, *tmpt;
9318
+
9319
+  pa = a->used;
9320
+  if ((res = mp_init_size (&t, 2*pa + 1)) != MP_OKAY) {
9321
+    return res;
9322
+  }
9323
+
9324
+  /* default used is maximum possible size */
9325
+  t.used = 2*pa + 1;
9326
+
9327
+  for (ix = 0; ix < pa; ix++) {
9328
+    /* first calculate the digit at 2*ix */
9329
+    /* calculate double precision result */
9330
+    r = ((mp_word) t.dp[2*ix]) +
9331
+        ((mp_word)a->dp[ix])*((mp_word)a->dp[ix]);
9332
+
9333
+    /* store lower part in result */
9334
+    t.dp[ix+ix] = (mp_digit) (r & ((mp_word) MP_MASK));
9335
+
9336
+    /* get the carry */
9337
+    u           = (mp_digit)(r >> ((mp_word) DIGIT_BIT));
9338
+
9339
+    /* left hand side of A[ix] * A[iy] */
9340
+    tmpx        = a->dp[ix];
9341
+
9342
+    /* alias for where to store the results */
9343
+    tmpt        = t.dp + (2*ix + 1);
9344
+    
9345
+    for (iy = ix + 1; iy < pa; iy++) {
9346
+      /* first calculate the product */
9347
+      r       = ((mp_word)tmpx) * ((mp_word)a->dp[iy]);
9348
+
9349
+      /* now calculate the double precision result, note we use
9350
+       * addition instead of *2 since it's easier to optimize
9351
+       */
9352
+      r       = ((mp_word) *tmpt) + r + r + ((mp_word) u);
9353
+
9354
+      /* store lower part */
9355
+      *tmpt++ = (mp_digit) (r & ((mp_word) MP_MASK));
9356
+
9357
+      /* get carry */
9358
+      u       = (mp_digit)(r >> ((mp_word) DIGIT_BIT));
9359
+    }
9360
+    /* propagate upwards */
9361
+    while (u != ((mp_digit) 0)) {
9362
+      r       = ((mp_word) *tmpt) + ((mp_word) u);
9363
+      *tmpt++ = (mp_digit) (r & ((mp_word) MP_MASK));
9364
+      u       = (mp_digit)(r >> ((mp_word) DIGIT_BIT));
9365
+    }
9366
+  }
9367
+
9368
+  mp_clamp (&t);
9369
+  mp_exch (&t, b);
9370
+  mp_clear (&t);
9371
+  return MP_OKAY;
9372
+}
9373
+#endif
9374
+
9375
+/* $Source: /cvs/libtom/libtommath/bn_s_mp_sqr.c,v $ */
9376
+/* $Revision: 1.3 $ */
9377
+/* $Date: 2006/03/31 14:18:44 $ */
9378
+
9379
+/* End: bn_s_mp_sqr.c */
9380
+
9381
+/* Start: bn_s_mp_sub.c */
9382
+#include <bignum.h>
9383
+#ifdef BN_S_MP_SUB_C
9384
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
9385
+ *
9386
+ * LibTomMath is a library that provides multiple-precision
9387
+ * integer arithmetic as well as number theoretic functionality.
9388
+ *
9389
+ * The library was designed directly after the MPI library by
9390
+ * Michael Fromberger but has been written from scratch with
9391
+ * additional optimizations in place.
9392
+ *
9393
+ * The library is free for all purposes without any express
9394
+ * guarantee it works.
9395
+ *
9396
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
9397
+ */
9398
+
9399
+/* low level subtraction (assumes |a| > |b|), HAC pp.595 Algorithm 14.9 */
9400
+int
9401
+s_mp_sub (mp_int * a, mp_int * b, mp_int * c)
9402
+{
9403
+  int     olduse, res, min, max;
9404
+
9405
+  /* find sizes */
9406
+  min = b->used;
9407
+  max = a->used;
9408
+
9409
+  /* init result */
9410
+  if (c->alloc < max) {
9411
+    if ((res = mp_grow (c, max)) != MP_OKAY) {
9412
+      return res;
9413
+    }
9414
+  }
9415
+  olduse = c->used;
9416
+  c->used = max;
9417
+
9418
+  {
9419
+    register mp_digit u, *tmpa, *tmpb, *tmpc;
9420
+    register int i;
9421
+
9422
+    /* alias for digit pointers */
9423
+    tmpa = a->dp;
9424
+    tmpb = b->dp;
9425
+    tmpc = c->dp;
9426
+
9427
+    /* set carry to zero */
9428
+    u = 0;
9429
+    for (i = 0; i < min; i++) {
9430
+      /* T[i] = A[i] - B[i] - U */
9431
+      *tmpc = *tmpa++ - *tmpb++ - u;
9432
+
9433
+      /* U = carry bit of T[i]
9434
+       * Note this saves performing an AND operation since
9435
+       * if a carry does occur it will propagate all the way to the
9436
+       * MSB.  As a result a single shift is enough to get the carry
9437
+       */
9438
+      u = *tmpc >> ((mp_digit)(CHAR_BIT * sizeof (mp_digit) - 1));
9439
+
9440
+      /* Clear carry from T[i] */
9441
+      *tmpc++ &= MP_MASK;
9442
+    }
9443
+
9444
+    /* now copy higher words if any, e.g. if A has more digits than B  */
9445
+    for (; i < max; i++) {
9446
+      /* T[i] = A[i] - U */
9447
+      *tmpc = *tmpa++ - u;
9448
+
9449
+      /* U = carry bit of T[i] */
9450
+      u = *tmpc >> ((mp_digit)(CHAR_BIT * sizeof (mp_digit) - 1));
9451
+
9452
+      /* Clear carry from T[i] */
9453
+      *tmpc++ &= MP_MASK;
9454
+    }
9455
+
9456
+    /* clear digits above used (since we may not have grown result above) */
9457
+    for (i = c->used; i < olduse; i++) {
9458
+      *tmpc++ = 0;
9459
+    }
9460
+  }
9461
+
9462
+  mp_clamp (c);
9463
+  return MP_OKAY;
9464
+}
9465
+
9466
+#endif
9467
+
9468
+/* $Source: /cvs/libtom/libtommath/bn_s_mp_sub.c,v $ */
9469
+/* $Revision: 1.3 $ */
9470
+/* $Date: 2006/03/31 14:18:44 $ */
9471
+
9472
+/* End: bn_s_mp_sub.c */
9473
+
9474
+/* Start: bncore.c */
9475
+#include <bignum.h>
9476
+#ifdef BNCORE_C
9477
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
9478
+ *
9479
+ * LibTomMath is a library that provides multiple-precision
9480
+ * integer arithmetic as well as number theoretic functionality.
9481
+ *
9482
+ * The library was designed directly after the MPI library by
9483
+ * Michael Fromberger but has been written from scratch with
9484
+ * additional optimizations in place.
9485
+ *
9486
+ * The library is free for all purposes without any express
9487
+ * guarantee it works.
9488
+ *
9489
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
9490
+ */
9491
+
9492
+/* Known optimal configurations
9493
+
9494
+ CPU                    /Compiler     /MUL CUTOFF/SQR CUTOFF
9495
+-------------------------------------------------------------
9496
+ Intel P4 Northwood     /GCC v3.4.1   /        88/       128/LTM 0.32 ;-)
9497
+ AMD Athlon64           /GCC v3.4.4   /        80/       120/LTM 0.35
9498
+ 
9499
+*/
9500
+
9501
+int     KARATSUBA_MUL_CUTOFF = 80,      /* Min. number of digits before Karatsuba multiplication is used. */
9502
+        KARATSUBA_SQR_CUTOFF = 120,     /* Min. number of digits before Karatsuba squaring is used. */
9503
+        
9504
+        TOOM_MUL_CUTOFF      = 350,      /* no optimal values of these are known yet so set em high */
9505
+        TOOM_SQR_CUTOFF      = 400; 
9506
+#endif
9507
+
9508
+/* $Source: /cvs/libtom/libtommath/bncore.c,v $ */
9509
+/* $Revision: 1.4 $ */
9510
+/* $Date: 2006/03/31 14:18:44 $ */
9511
+
9512
+/* End: bncore.c */
9513
+
9514
+
9515
+/* EOF */
0 9516
new file mode 100644
... ...
@@ -0,0 +1,584 @@
0
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
1
+ *
2
+ * LibTomMath is a library that provides multiple-precision
3
+ * integer arithmetic as well as number theoretic functionality.
4
+ *
5
+ * The library was designed directly after the MPI library by
6
+ * Michael Fromberger but has been written from scratch with
7
+ * additional optimizations in place.
8
+ *
9
+ * The library is free for all purposes without any express
10
+ * guarantee it works.
11
+ *
12
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
13
+ */
14
+#ifndef __BIGNUM_H
15
+#define __BIGNUM_H
16
+
17
+#include <stdio.h>
18
+#include <string.h>
19
+#include <stdlib.h>
20
+#include <ctype.h>
21
+#include <limits.h>
22
+
23
+/*
24
+#define BN_MP_INIT_C
25
+#define BN_MP_ZERO_C
26
+#define BN_MP_READ_RADIX_C
27
+#define BN_MP_RADIX_SMAP_C
28
+#define BN_MP_SET_INT_C
29
+#define BN_MP_MUL_2D_C
30
+#define BN_MP_MUL_D_C
31
+#define BN_MP_CLAMP_C
32
+#define BN_MP_ADD_D_C
33
+#define BN_S_MP_ADD_C
34
+#define BN_MP_LSHD_C
35
+#define BN_MP_GROW_C
36
+#define BN_MP_CMP_MAG_C
37
+#define BN_MP_COPY_C
38
+*/
39
+
40
+#define LTM_ALL /* FIXME: tk: limit to the above class */
41
+#include "bignum_class.h"
42
+
43
+#ifndef MIN
44
+   #define MIN(x,y) ((x)<(y)?(x):(y))
45
+#endif
46
+
47
+#ifndef MAX
48
+   #define MAX(x,y) ((x)>(y)?(x):(y))
49
+#endif
50
+
51
+#ifdef __cplusplus
52
+extern "C" {
53
+
54
+/* C++ compilers don't like assigning void * to mp_digit * */
55
+#define  OPT_CAST(x)  (x *)
56
+
57
+#else
58
+
59
+/* C on the other hand doesn't care */
60
+#define  OPT_CAST(x)
61
+
62
+#endif
63
+
64
+/* detect 64-bit mode if possible */
65
+#if defined(__x86_64__) 
66
+   #if !(defined(MP_64BIT) && defined(MP_16BIT) && defined(MP_8BIT))
67
+      #define MP_64BIT
68
+   #endif
69
+#endif
70
+
71
+/* some default configurations.
72
+ *
73
+ * A "mp_digit" must be able to hold DIGIT_BIT + 1 bits
74
+ * A "mp_word" must be able to hold 2*DIGIT_BIT + 1 bits
75
+ *
76
+ * At the very least a mp_digit must be able to hold 7 bits
77
+ * [any size beyond that is ok provided it doesn't overflow the data type]
78
+ */
79
+#ifdef MP_8BIT
80
+   typedef unsigned char      mp_digit;
81
+   typedef unsigned short     mp_word;
82
+#elif defined(MP_16BIT)
83
+   typedef unsigned short     mp_digit;
84
+   typedef unsigned long      mp_word;
85
+#elif defined(MP_64BIT)
86
+   /* for GCC only on supported platforms */
87
+#ifndef CRYPT
88
+   typedef unsigned long long ulong64;
89
+   typedef signed long long   long64;
90
+#endif
91
+
92
+   typedef unsigned long      mp_digit;
93
+   typedef unsigned long      mp_word __attribute__ ((mode(TI)));
94
+
95
+   #define DIGIT_BIT          60
96
+#else
97
+   /* this is the default case, 28-bit digits */
98
+   
99
+   /* this is to make porting into LibTomCrypt easier :-) */
100
+#ifndef CRYPT
101
+   #if defined(_MSC_VER) || defined(__BORLANDC__) 
102
+      typedef unsigned __int64   ulong64;
103
+      typedef signed __int64     long64;
104
+   #else
105
+      typedef unsigned long long ulong64;
106
+      typedef signed long long   long64;
107
+   #endif
108
+#endif
109
+
110
+   typedef unsigned long      mp_digit;
111
+   typedef ulong64            mp_word;
112
+
113
+#ifdef MP_31BIT   
114
+   /* this is an extension that uses 31-bit digits */
115
+   #define DIGIT_BIT          31
116
+#else
117
+   /* default case is 28-bit digits, defines MP_28BIT as a handy macro to test */
118
+   #define DIGIT_BIT          28
119
+   #define MP_28BIT
120
+#endif   
121
+#endif
122
+
123
+
124
+/* otherwise the bits per digit is calculated automatically from the size of a mp_digit */
125
+#ifndef DIGIT_BIT
126
+   #define DIGIT_BIT     ((int)((CHAR_BIT * sizeof(mp_digit) - 1)))  /* bits per digit */
127
+#endif
128
+
129
+#define MP_DIGIT_BIT     DIGIT_BIT
130
+#define MP_MASK          ((((mp_digit)1)<<((mp_digit)DIGIT_BIT))-((mp_digit)1))
131
+#define MP_DIGIT_MAX     MP_MASK
132
+
133
+/* equalities */
134
+#define MP_LT        -1   /* less than */
135
+#define MP_EQ         0   /* equal to */
136
+#define MP_GT         1   /* greater than */
137
+
138
+#define MP_ZPOS       0   /* positive integer */
139
+#define MP_NEG        1   /* negative */
140
+
141
+#define MP_OKAY       0   /* ok result */
142
+#define MP_MEM        -2  /* out of mem */
143
+#define MP_VAL        -3  /* invalid input */
144
+#define MP_RANGE      MP_VAL
145
+
146
+#define MP_YES        1   /* yes response */
147
+#define MP_NO         0   /* no response */
148
+
149
+/* Primality generation flags */
150
+#define LTM_PRIME_BBS      0x0001 /* BBS style prime */
151
+#define LTM_PRIME_SAFE     0x0002 /* Safe prime (p-1)/2 == prime */
152
+#define LTM_PRIME_2MSB_ON  0x0008 /* force 2nd MSB to 1 */
153
+
154
+typedef int           mp_err;
155
+
156
+/* you'll have to tune these... */
157
+extern int KARATSUBA_MUL_CUTOFF,
158
+           KARATSUBA_SQR_CUTOFF,
159
+           TOOM_MUL_CUTOFF,
160
+           TOOM_SQR_CUTOFF;
161
+
162
+/* define this to use lower memory usage routines (exptmods mostly) */
163
+/* #define MP_LOW_MEM */
164
+
165
+/* default precision */
166
+#ifndef MP_PREC
167
+   #ifndef MP_LOW_MEM
168
+      #define MP_PREC                 32     /* default digits of precision */
169
+   #else
170
+      #define MP_PREC                 8      /* default digits of precision */
171
+   #endif   
172
+#endif
173
+
174
+/* size of comba arrays, should be at least 2 * 2**(BITS_PER_WORD - BITS_PER_DIGIT*2) */
175
+#define MP_WARRAY               (1 << (sizeof(mp_word) * CHAR_BIT - 2 * DIGIT_BIT + 1))
176
+
177
+/* the infamous mp_int structure */
178
+typedef struct  {
179
+    int used, alloc, sign;
180
+    mp_digit *dp;
181
+} mp_int;
182
+
183
+/* callback for mp_prime_random, should fill dst with random bytes and return how many read [upto len] */
184
+typedef int ltm_prime_callback(unsigned char *dst, int len, void *dat);
185
+
186
+
187
+#define USED(m)    ((m)->used)
188
+#define DIGIT(m,k) ((m)->dp[(k)])
189
+#define SIGN(m)    ((m)->sign)
190
+
191
+/* error code to char* string */
192
+const char *mp_error_to_string(int code);
193
+
194
+/* ---> init and deinit bignum functions <--- */
195
+/* init a bignum */
196
+int mp_init(mp_int *a);
197
+
198
+/* free a bignum */
199
+void mp_clear(mp_int *a);
200
+
201
+/* init a null terminated series of arguments */
202
+int mp_init_multi(mp_int *mp, ...);
203
+
204
+/* clear a null terminated series of arguments */
205
+void mp_clear_multi(mp_int *mp, ...);
206
+
207
+/* exchange two ints */
208
+void mp_exch(mp_int *a, mp_int *b);
209
+
210
+/* shrink ram required for a bignum */
211
+int mp_shrink(mp_int *a);
212
+
213
+/* grow an int to a given size */
214
+int mp_grow(mp_int *a, int size);
215
+
216
+/* init to a given number of digits */
217
+int mp_init_size(mp_int *a, int size);
218
+
219
+/* ---> Basic Manipulations <--- */
220
+#define mp_iszero(a) (((a)->used == 0) ? MP_YES : MP_NO)
221
+#define mp_iseven(a) (((a)->used > 0 && (((a)->dp[0] & 1) == 0)) ? MP_YES : MP_NO)
222
+#define mp_isodd(a)  (((a)->used > 0 && (((a)->dp[0] & 1) == 1)) ? MP_YES : MP_NO)
223
+
224
+/* set to zero */
225
+void mp_zero(mp_int *a);
226
+
227
+/* set to a digit */
228
+void mp_set(mp_int *a, mp_digit b);
229
+
230
+/* set a 32-bit const */
231
+int mp_set_int(mp_int *a, unsigned long b);
232
+
233
+/* get a 32-bit value */
234
+unsigned long mp_get_int(mp_int * a);
235
+
236
+/* initialize and set a digit */
237
+int mp_init_set (mp_int * a, mp_digit b);
238
+
239
+/* initialize and set 32-bit value */
240
+int mp_init_set_int (mp_int * a, unsigned long b);
241
+
242
+/* copy, b = a */
243
+int mp_copy(mp_int *a, mp_int *b);
244
+
245
+/* inits and copies, a = b */
246
+int mp_init_copy(mp_int *a, mp_int *b);
247
+
248
+/* trim unused digits */
249
+void mp_clamp(mp_int *a);
250
+
251
+/* ---> digit manipulation <--- */
252
+
253
+/* right shift by "b" digits */
254
+void mp_rshd(mp_int *a, int b);
255
+
256
+/* left shift by "b" digits */
257
+int mp_lshd(mp_int *a, int b);
258
+
259
+/* c = a / 2**b */
260
+int mp_div_2d(mp_int *a, int b, mp_int *c, mp_int *d);
261
+
262
+/* b = a/2 */
263
+int mp_div_2(mp_int *a, mp_int *b);
264
+
265
+/* c = a * 2**b */
266
+int mp_mul_2d(mp_int *a, int b, mp_int *c);
267
+
268
+/* b = a*2 */
269
+int mp_mul_2(mp_int *a, mp_int *b);
270
+
271
+/* c = a mod 2**d */
272
+int mp_mod_2d(mp_int *a, int b, mp_int *c);
273
+
274
+/* computes a = 2**b */
275
+int mp_2expt(mp_int *a, int b);
276
+
277
+/* Counts the number of lsbs which are zero before the first zero bit */
278
+int mp_cnt_lsb(mp_int *a);
279
+
280
+/* I Love Earth! */
281
+
282
+/* makes a pseudo-random int of a given size */
283
+int mp_rand(mp_int *a, int digits);
284
+
285
+/* ---> binary operations <--- */
286
+/* c = a XOR b  */
287
+int mp_xor(mp_int *a, mp_int *b, mp_int *c);
288
+
289
+/* c = a OR b */
290
+int mp_or(mp_int *a, mp_int *b, mp_int *c);
291
+
292
+/* c = a AND b */
293
+int mp_and(mp_int *a, mp_int *b, mp_int *c);
294
+
295
+/* ---> Basic arithmetic <--- */
296
+
297
+/* b = -a */
298
+int mp_neg(mp_int *a, mp_int *b);
299
+
300
+/* b = |a| */
301
+int mp_abs(mp_int *a, mp_int *b);
302
+
303
+/* compare a to b */
304
+int mp_cmp(mp_int *a, mp_int *b);
305
+
306
+/* compare |a| to |b| */
307
+int mp_cmp_mag(mp_int *a, mp_int *b);
308
+
309
+/* c = a + b */
310
+int mp_add(mp_int *a, mp_int *b, mp_int *c);
311
+
312
+/* c = a - b */
313
+int mp_sub(mp_int *a, mp_int *b, mp_int *c);
314
+
315
+/* c = a * b */
316
+int mp_mul(mp_int *a, mp_int *b, mp_int *c);
317
+
318
+/* b = a*a  */
319
+int mp_sqr(mp_int *a, mp_int *b);
320
+
321
+/* a/b => cb + d == a */
322
+int mp_div(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
323
+
324
+/* c = a mod b, 0 <= c < b  */
325
+int mp_mod(mp_int *a, mp_int *b, mp_int *c);
326
+
327
+/* ---> single digit functions <--- */
328
+
329
+/* compare against a single digit */
330
+int mp_cmp_d(mp_int *a, mp_digit b);
331
+
332
+/* c = a + b */
333
+int mp_add_d(mp_int *a, mp_digit b, mp_int *c);
334
+
335
+/* c = a - b */
336
+int mp_sub_d(mp_int *a, mp_digit b, mp_int *c);
337
+
338
+/* c = a * b */
339
+int mp_mul_d(mp_int *a, mp_digit b, mp_int *c);
340
+
341
+/* a/b => cb + d == a */
342
+int mp_div_d(mp_int *a, mp_digit b, mp_int *c, mp_digit *d);
343
+
344
+/* a/3 => 3c + d == a */
345
+int mp_div_3(mp_int *a, mp_int *c, mp_digit *d);
346
+
347
+/* c = a**b */
348
+int mp_expt_d(mp_int *a, mp_digit b, mp_int *c);
349
+
350
+/* c = a mod b, 0 <= c < b  */
351
+int mp_mod_d(mp_int *a, mp_digit b, mp_digit *c);
352
+
353
+/* ---> number theory <--- */
354
+
355
+/* d = a + b (mod c) */
356
+int mp_addmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
357
+
358
+/* d = a - b (mod c) */
359
+int mp_submod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
360
+
361
+/* d = a * b (mod c) */
362
+int mp_mulmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
363
+
364
+/* c = a * a (mod b) */
365
+int mp_sqrmod(mp_int *a, mp_int *b, mp_int *c);
366
+
367
+/* c = 1/a (mod b) */
368
+int mp_invmod(mp_int *a, mp_int *b, mp_int *c);
369
+
370
+/* c = (a, b) */
371
+int mp_gcd(mp_int *a, mp_int *b, mp_int *c);
372
+
373
+/* produces value such that U1*a + U2*b = U3 */
374
+int mp_exteuclid(mp_int *a, mp_int *b, mp_int *U1, mp_int *U2, mp_int *U3);
375
+
376
+/* c = [a, b] or (a*b)/(a, b) */
377
+int mp_lcm(mp_int *a, mp_int *b, mp_int *c);
378
+
379
+/* finds one of the b'th root of a, such that |c|**b <= |a|
380
+ *
381
+ * returns error if a < 0 and b is even
382
+ */
383
+int mp_n_root(mp_int *a, mp_digit b, mp_int *c);
384
+
385
+/* special sqrt algo */
386
+int mp_sqrt(mp_int *arg, mp_int *ret);
387
+
388
+/* is number a square? */
389
+int mp_is_square(mp_int *arg, int *ret);
390
+
391
+/* computes the jacobi c = (a | n) (or Legendre if b is prime)  */
392
+int mp_jacobi(mp_int *a, mp_int *n, int *c);
393
+
394
+/* used to setup the Barrett reduction for a given modulus b */
395
+int mp_reduce_setup(mp_int *a, mp_int *b);
396
+
397
+/* Barrett Reduction, computes a (mod b) with a precomputed value c
398
+ *
399
+ * Assumes that 0 < a <= b*b, note if 0 > a > -(b*b) then you can merely
400
+ * compute the reduction as -1 * mp_reduce(mp_abs(a)) [pseudo code].
401
+ */
402
+int mp_reduce(mp_int *a, mp_int *b, mp_int *c);
403
+
404
+/* setups the montgomery reduction */
405
+int mp_montgomery_setup(mp_int *a, mp_digit *mp);
406
+
407
+/* computes a = B**n mod b without division or multiplication useful for
408
+ * normalizing numbers in a Montgomery system.
409
+ */
410
+int mp_montgomery_calc_normalization(mp_int *a, mp_int *b);
411
+
412
+/* computes x/R == x (mod N) via Montgomery Reduction */
413
+int mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
414
+
415
+/* returns 1 if a is a valid DR modulus */
416
+int mp_dr_is_modulus(mp_int *a);
417
+
418
+/* sets the value of "d" required for mp_dr_reduce */
419
+void mp_dr_setup(mp_int *a, mp_digit *d);
420
+
421
+/* reduces a modulo b using the Diminished Radix method */
422
+int mp_dr_reduce(mp_int *a, mp_int *b, mp_digit mp);
423
+
424
+/* returns true if a can be reduced with mp_reduce_2k */
425
+int mp_reduce_is_2k(mp_int *a);
426
+
427
+/* determines k value for 2k reduction */
428
+int mp_reduce_2k_setup(mp_int *a, mp_digit *d);
429
+
430
+/* reduces a modulo b where b is of the form 2**p - k [0 <= a] */
431
+int mp_reduce_2k(mp_int *a, mp_int *n, mp_digit d);
432
+
433
+/* returns true if a can be reduced with mp_reduce_2k_l */
434
+int mp_reduce_is_2k_l(mp_int *a);
435
+
436
+/* determines k value for 2k reduction */
437
+int mp_reduce_2k_setup_l(mp_int *a, mp_int *d);
438
+
439
+/* reduces a modulo b where b is of the form 2**p - k [0 <= a] */
440
+int mp_reduce_2k_l(mp_int *a, mp_int *n, mp_int *d);
441
+
442
+/* d = a**b (mod c) */
443
+int mp_exptmod(mp_int *a, mp_int *b, mp_int *c, mp_int *d);
444
+
445
+/* ---> Primes <--- */
446
+
447
+/* number of primes */
448
+#ifdef MP_8BIT
449
+   #define PRIME_SIZE      31
450
+#else
451
+   #define PRIME_SIZE      256
452
+#endif
453
+
454
+/* table of first PRIME_SIZE primes */
455
+extern const mp_digit ltm_prime_tab[];
456
+
457
+/* result=1 if a is divisible by one of the first PRIME_SIZE primes */
458
+int mp_prime_is_divisible(mp_int *a, int *result);
459
+
460
+/* performs one Fermat test of "a" using base "b".
461
+ * Sets result to 0 if composite or 1 if probable prime
462
+ */
463
+int mp_prime_fermat(mp_int *a, mp_int *b, int *result);
464
+
465
+/* performs one Miller-Rabin test of "a" using base "b".
466
+ * Sets result to 0 if composite or 1 if probable prime
467
+ */
468
+int mp_prime_miller_rabin(mp_int *a, mp_int *b, int *result);
469
+
470
+/* This gives [for a given bit size] the number of trials required
471
+ * such that Miller-Rabin gives a prob of failure lower than 2^-96 
472
+ */
473
+int mp_prime_rabin_miller_trials(int size);
474
+
475
+/* performs t rounds of Miller-Rabin on "a" using the first
476
+ * t prime bases.  Also performs an initial sieve of trial
477
+ * division.  Determines if "a" is prime with probability
478
+ * of error no more than (1/4)**t.
479
+ *
480
+ * Sets result to 1 if probably prime, 0 otherwise
481
+ */
482
+int mp_prime_is_prime(mp_int *a, int t, int *result);
483
+
484
+/* finds the next prime after the number "a" using "t" trials
485
+ * of Miller-Rabin.
486
+ *
487
+ * bbs_style = 1 means the prime must be congruent to 3 mod 4
488
+ */
489
+int mp_prime_next_prime(mp_int *a, int t, int bbs_style);
490
+
491
+/* makes a truly random prime of a given size (bytes),
492
+ * call with bbs = 1 if you want it to be congruent to 3 mod 4 
493
+ *
494
+ * You have to supply a callback which fills in a buffer with random bytes.  "dat" is a parameter you can
495
+ * have passed to the callback (e.g. a state or something).  This function doesn't use "dat" itself
496
+ * so it can be NULL
497
+ *
498
+ * The prime generated will be larger than 2^(8*size).
499
+ */
500
+#define mp_prime_random(a, t, size, bbs, cb, dat) mp_prime_random_ex(a, t, ((size) * 8) + 1, (bbs==1)?LTM_PRIME_BBS:0, cb, dat)
501
+
502
+/* makes a truly random prime of a given size (bits),
503
+ *
504
+ * Flags are as follows:
505
+ * 
506
+ *   LTM_PRIME_BBS      - make prime congruent to 3 mod 4
507
+ *   LTM_PRIME_SAFE     - make sure (p-1)/2 is prime as well (implies LTM_PRIME_BBS)
508
+ *   LTM_PRIME_2MSB_OFF - make the 2nd highest bit zero
509
+ *   LTM_PRIME_2MSB_ON  - make the 2nd highest bit one
510
+ *
511
+ * You have to supply a callback which fills in a buffer with random bytes.  "dat" is a parameter you can
512
+ * have passed to the callback (e.g. a state or something).  This function doesn't use "dat" itself
513
+ * so it can be NULL
514
+ *
515
+ */
516
+int mp_prime_random_ex(mp_int *a, int t, int size, int flags, ltm_prime_callback cb, void *dat);
517
+
518
+/* ---> radix conversion <--- */
519
+int mp_count_bits(mp_int *a);
520
+
521
+int mp_unsigned_bin_size(mp_int *a);
522
+int mp_read_unsigned_bin(mp_int *a, const unsigned char *b, int c);
523
+int mp_to_unsigned_bin(mp_int *a, unsigned char *b);
524
+int mp_to_unsigned_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen);
525
+
526
+int mp_signed_bin_size(mp_int *a);
527
+int mp_read_signed_bin(mp_int *a, const unsigned char *b, int c);
528
+int mp_to_signed_bin(mp_int *a,  unsigned char *b);
529
+int mp_to_signed_bin_n (mp_int * a, unsigned char *b, unsigned long *outlen);
530
+
531
+int mp_read_radix(mp_int *a, const char *str, int radix);
532
+int mp_toradix(mp_int *a, char *str, int radix);
533
+int mp_toradix_n(mp_int * a, char *str, int radix, int maxlen);
534
+int mp_radix_size(mp_int *a, int radix, int *size);
535
+
536
+int mp_fread(mp_int *a, int radix, FILE *stream);
537
+int mp_fwrite(mp_int *a, int radix, FILE *stream);
538
+
539
+#define mp_read_raw(mp, str, len) mp_read_signed_bin((mp), (str), (len))
540
+#define mp_raw_size(mp)           mp_signed_bin_size(mp)
541
+#define mp_toraw(mp, str)         mp_to_signed_bin((mp), (str))
542
+#define mp_read_mag(mp, str, len) mp_read_unsigned_bin((mp), (str), (len))
543
+#define mp_mag_size(mp)           mp_unsigned_bin_size(mp)
544
+#define mp_tomag(mp, str)         mp_to_unsigned_bin((mp), (str))
545
+
546
+#define mp_tobinary(M, S)  mp_toradix((M), (S), 2)
547
+#define mp_tooctal(M, S)   mp_toradix((M), (S), 8)
548
+#define mp_todecimal(M, S) mp_toradix((M), (S), 10)
549
+#define mp_tohex(M, S)     mp_toradix((M), (S), 16)
550
+
551
+/* lowlevel functions, do not call! */
552
+int s_mp_add(mp_int *a, mp_int *b, mp_int *c);
553
+int s_mp_sub(mp_int *a, mp_int *b, mp_int *c);
554
+#define s_mp_mul(a, b, c) s_mp_mul_digs(a, b, c, (a)->used + (b)->used + 1)
555
+int fast_s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
556
+int s_mp_mul_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
557
+int fast_s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
558
+int s_mp_mul_high_digs(mp_int *a, mp_int *b, mp_int *c, int digs);
559
+int fast_s_mp_sqr(mp_int *a, mp_int *b);
560
+int s_mp_sqr(mp_int *a, mp_int *b);
561
+int mp_karatsuba_mul(mp_int *a, mp_int *b, mp_int *c);
562
+int mp_toom_mul(mp_int *a, mp_int *b, mp_int *c);
563
+int mp_karatsuba_sqr(mp_int *a, mp_int *b);
564
+int mp_toom_sqr(mp_int *a, mp_int *b);
565
+int fast_mp_invmod(mp_int *a, mp_int *b, mp_int *c);
566
+int mp_invmod_slow (mp_int * a, mp_int * b, mp_int * c);
567
+int fast_mp_montgomery_reduce(mp_int *a, mp_int *m, mp_digit mp);
568
+int mp_exptmod_fast(mp_int *G, mp_int *X, mp_int *P, mp_int *Y, int mode);
569
+int s_mp_exptmod (mp_int * G, mp_int * X, mp_int * P, mp_int * Y, int mode);
570
+void bn_reverse(unsigned char *s, int len);
571
+
572
+extern const char *mp_s_rmap;
573
+
574
+#ifdef __cplusplus
575
+   }
576
+#endif
577
+
578
+#endif
579
+
580
+
581
+/* $Source: /cvs/libtom/libtommath/tommath.h,v $ */
582
+/* $Revision: 1.8 $ */
583
+/* $Date: 2006/03/31 14:18:44 $ */
0 584
new file mode 100644
... ...
@@ -0,0 +1,1006 @@
0
+/* LibTomMath, multiple-precision integer library -- Tom St Denis
1
+ *
2
+ * LibTomMath is a library that provides multiple-precision
3
+ * integer arithmetic as well as number theoretic functionality.
4
+ *
5
+ * The library was designed directly after the MPI library by
6
+ * Michael Fromberger but has been written from scratch with
7
+ * additional optimizations in place.
8
+ *
9
+ * The library is free for all purposes without any express
10
+ * guarantee it works.
11
+ *
12
+ * Tom St Denis, tomstdenis@gmail.com, http://math.libtomcrypt.com
13
+ */
14
+
15
+#if !(defined(LTM1) && defined(LTM2) && defined(LTM3))
16
+#if defined(LTM2)
17
+#define LTM3
18
+#endif
19
+#if defined(LTM1)
20
+#define LTM2
21
+#endif
22
+#define LTM1
23
+
24
+#if defined(LTM_ALL)
25
+#define BN_ERROR_C
26
+#define BN_FAST_MP_INVMOD_C
27
+#define BN_FAST_MP_MONTGOMERY_REDUCE_C
28
+#define BN_FAST_S_MP_MUL_DIGS_C
29
+#define BN_FAST_S_MP_MUL_HIGH_DIGS_C
30
+#define BN_FAST_S_MP_SQR_C
31
+#define BN_MP_2EXPT_C
32
+#define BN_MP_ABS_C
33
+#define BN_MP_ADD_C
34
+#define BN_MP_ADD_D_C
35
+#define BN_MP_ADDMOD_C
36
+#define BN_MP_AND_C
37
+#define BN_MP_CLAMP_C
38
+#define BN_MP_CLEAR_C
39
+#define BN_MP_CLEAR_MULTI_C
40
+#define BN_MP_CMP_C
41
+#define BN_MP_CMP_D_C
42
+#define BN_MP_CMP_MAG_C
43
+#define BN_MP_CNT_LSB_C
44
+#define BN_MP_COPY_C
45
+#define BN_MP_COUNT_BITS_C
46
+#define BN_MP_DIV_C
47
+#define BN_MP_DIV_2_C
48
+#define BN_MP_DIV_2D_C
49
+#define BN_MP_DIV_3_C
50
+#define BN_MP_DIV_D_C
51
+#define BN_MP_DR_IS_MODULUS_C
52
+#define BN_MP_DR_REDUCE_C
53
+#define BN_MP_DR_SETUP_C
54
+#define BN_MP_EXCH_C
55
+#define BN_MP_EXPT_D_C
56
+#define BN_MP_EXPTMOD_C
57
+#define BN_MP_EXPTMOD_FAST_C
58
+#define BN_MP_EXTEUCLID_C
59
+#define BN_MP_FREAD_C
60
+#define BN_MP_FWRITE_C
61
+#define BN_MP_GCD_C
62
+#define BN_MP_GET_INT_C
63
+#define BN_MP_GROW_C
64
+#define BN_MP_INIT_C
65
+#define BN_MP_INIT_COPY_C
66
+#define BN_MP_INIT_MULTI_C
67
+#define BN_MP_INIT_SET_C
68
+#define BN_MP_INIT_SET_INT_C
69
+#define BN_MP_INIT_SIZE_C
70
+#define BN_MP_INVMOD_C
71
+#define BN_MP_INVMOD_SLOW_C
72
+#define BN_MP_IS_SQUARE_C
73
+#define BN_MP_JACOBI_C
74
+#define BN_MP_KARATSUBA_MUL_C
75
+#define BN_MP_KARATSUBA_SQR_C
76
+#define BN_MP_LCM_C
77
+#define BN_MP_LSHD_C
78
+#define BN_MP_MOD_C
79
+#define BN_MP_MOD_2D_C
80
+#define BN_MP_MOD_D_C
81
+#define BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
82
+#define BN_MP_MONTGOMERY_REDUCE_C
83
+#define BN_MP_MONTGOMERY_SETUP_C
84
+#define BN_MP_MUL_C
85
+#define BN_MP_MUL_2_C
86
+#define BN_MP_MUL_2D_C
87
+#define BN_MP_MUL_D_C
88
+#define BN_MP_MULMOD_C
89
+#define BN_MP_N_ROOT_C
90
+#define BN_MP_NEG_C
91
+#define BN_MP_OR_C
92
+#define BN_MP_PRIME_FERMAT_C
93
+#define BN_MP_PRIME_IS_DIVISIBLE_C
94
+#define BN_MP_PRIME_IS_PRIME_C
95
+#define BN_MP_PRIME_MILLER_RABIN_C
96
+#define BN_MP_PRIME_NEXT_PRIME_C
97
+#define BN_MP_PRIME_RABIN_MILLER_TRIALS_C
98
+#define BN_MP_PRIME_RANDOM_EX_C
99
+#define BN_MP_RADIX_SIZE_C
100
+#define BN_MP_RADIX_SMAP_C
101
+#define BN_MP_RAND_C
102
+#define BN_MP_READ_RADIX_C
103
+#define BN_MP_READ_SIGNED_BIN_C
104
+#define BN_MP_READ_UNSIGNED_BIN_C
105
+#define BN_MP_REDUCE_C
106
+#define BN_MP_REDUCE_2K_C
107
+#define BN_MP_REDUCE_2K_L_C
108
+#define BN_MP_REDUCE_2K_SETUP_C
109
+#define BN_MP_REDUCE_2K_SETUP_L_C
110
+#define BN_MP_REDUCE_IS_2K_C
111
+#define BN_MP_REDUCE_IS_2K_L_C
112
+#define BN_MP_REDUCE_SETUP_C
113
+#define BN_MP_RSHD_C
114
+#define BN_MP_SET_C
115
+#define BN_MP_SET_INT_C
116
+#define BN_MP_SHRINK_C
117
+#define BN_MP_SIGNED_BIN_SIZE_C
118
+#define BN_MP_SQR_C
119
+#define BN_MP_SQRMOD_C
120
+#define BN_MP_SQRT_C
121
+#define BN_MP_SUB_C
122
+#define BN_MP_SUB_D_C
123
+#define BN_MP_SUBMOD_C
124
+#define BN_MP_TO_SIGNED_BIN_C
125
+#define BN_MP_TO_SIGNED_BIN_N_C
126
+#define BN_MP_TO_UNSIGNED_BIN_C
127
+#define BN_MP_TO_UNSIGNED_BIN_N_C
128
+#define BN_MP_TOOM_MUL_C
129
+#define BN_MP_TOOM_SQR_C
130
+#define BN_MP_TORADIX_C
131
+#define BN_MP_TORADIX_N_C
132
+#define BN_MP_UNSIGNED_BIN_SIZE_C
133
+#define BN_MP_XOR_C
134
+#define BN_MP_ZERO_C
135
+#define BN_PRIME_TAB_C
136
+#define BN_REVERSE_C
137
+#define BN_S_MP_ADD_C
138
+#define BN_S_MP_EXPTMOD_C
139
+#define BN_S_MP_MUL_DIGS_C
140
+#define BN_S_MP_MUL_HIGH_DIGS_C
141
+#define BN_S_MP_SQR_C
142
+#define BN_S_MP_SUB_C
143
+#define BNCORE_C
144
+#endif
145
+
146
+#if defined(BN_ERROR_C)
147
+   #define BN_MP_ERROR_TO_STRING_C
148
+#endif
149
+
150
+#if defined(BN_FAST_MP_INVMOD_C)
151
+   #define BN_MP_ISEVEN_C
152
+   #define BN_MP_INIT_MULTI_C
153
+   #define BN_MP_COPY_C
154
+   #define BN_MP_MOD_C
155
+   #define BN_MP_SET_C
156
+   #define BN_MP_DIV_2_C
157
+   #define BN_MP_ISODD_C
158
+   #define BN_MP_SUB_C
159
+   #define BN_MP_CMP_C
160
+   #define BN_MP_ISZERO_C
161
+   #define BN_MP_CMP_D_C
162
+   #define BN_MP_ADD_C
163
+   #define BN_MP_EXCH_C
164
+   #define BN_MP_CLEAR_MULTI_C
165
+#endif
166
+
167
+#if defined(BN_FAST_MP_MONTGOMERY_REDUCE_C)
168
+   #define BN_MP_GROW_C
169
+   #define BN_MP_RSHD_C
170
+   #define BN_MP_CLAMP_C
171
+   #define BN_MP_CMP_MAG_C
172
+   #define BN_S_MP_SUB_C
173
+#endif
174
+
175
+#if defined(BN_FAST_S_MP_MUL_DIGS_C)
176
+   #define BN_MP_GROW_C
177
+   #define BN_MP_CLAMP_C
178
+#endif
179
+
180
+#if defined(BN_FAST_S_MP_MUL_HIGH_DIGS_C)
181
+   #define BN_MP_GROW_C
182
+   #define BN_MP_CLAMP_C
183
+#endif
184
+
185
+#if defined(BN_FAST_S_MP_SQR_C)
186
+   #define BN_MP_GROW_C
187
+   #define BN_MP_CLAMP_C
188
+#endif
189
+
190
+#if defined(BN_MP_2EXPT_C)
191
+   #define BN_MP_ZERO_C
192
+   #define BN_MP_GROW_C
193
+#endif
194
+
195
+#if defined(BN_MP_ABS_C)
196
+   #define BN_MP_COPY_C
197
+#endif
198
+
199
+#if defined(BN_MP_ADD_C)
200
+   #define BN_S_MP_ADD_C
201
+   #define BN_MP_CMP_MAG_C
202
+   #define BN_S_MP_SUB_C
203
+#endif
204
+
205
+#if defined(BN_MP_ADD_D_C)
206
+   #define BN_MP_GROW_C
207
+   #define BN_MP_SUB_D_C
208
+   #define BN_MP_CLAMP_C
209
+#endif
210
+
211
+#if defined(BN_MP_ADDMOD_C)
212
+   #define BN_MP_INIT_C
213
+   #define BN_MP_ADD_C
214
+   #define BN_MP_CLEAR_C
215
+   #define BN_MP_MOD_C
216
+#endif
217
+
218
+#if defined(BN_MP_AND_C)
219
+   #define BN_MP_INIT_COPY_C
220
+   #define BN_MP_CLAMP_C
221
+   #define BN_MP_EXCH_C
222
+   #define BN_MP_CLEAR_C
223
+#endif
224
+
225
+#if defined(BN_MP_CLAMP_C)
226
+#endif
227
+
228
+#if defined(BN_MP_CLEAR_C)
229
+#endif
230
+
231
+#if defined(BN_MP_CLEAR_MULTI_C)
232
+   #define BN_MP_CLEAR_C
233
+#endif
234
+
235
+#if defined(BN_MP_CMP_C)
236
+   #define BN_MP_CMP_MAG_C
237
+#endif
238
+
239
+#if defined(BN_MP_CMP_D_C)
240
+#endif
241
+
242
+#if defined(BN_MP_CMP_MAG_C)
243
+#endif
244
+
245
+#if defined(BN_MP_CNT_LSB_C)
246
+   #define BN_MP_ISZERO_C
247
+#endif
248
+
249
+#if defined(BN_MP_COPY_C)
250
+   #define BN_MP_GROW_C
251
+#endif
252
+
253
+#if defined(BN_MP_COUNT_BITS_C)
254
+#endif
255
+
256
+#if defined(BN_MP_DIV_C)
257
+   #define BN_MP_ISZERO_C
258
+   #define BN_MP_CMP_MAG_C
259
+   #define BN_MP_COPY_C
260
+   #define BN_MP_ZERO_C
261
+   #define BN_MP_INIT_MULTI_C
262
+   #define BN_MP_SET_C
263
+   #define BN_MP_COUNT_BITS_C
264
+   #define BN_MP_ABS_C
265
+   #define BN_MP_MUL_2D_C
266
+   #define BN_MP_CMP_C
267
+   #define BN_MP_SUB_C
268
+   #define BN_MP_ADD_C
269
+   #define BN_MP_DIV_2D_C
270
+   #define BN_MP_EXCH_C
271
+   #define BN_MP_CLEAR_MULTI_C
272
+   #define BN_MP_INIT_SIZE_C
273
+   #define BN_MP_INIT_C
274
+   #define BN_MP_INIT_COPY_C
275
+   #define BN_MP_LSHD_C
276
+   #define BN_MP_RSHD_C
277
+   #define BN_MP_MUL_D_C
278
+   #define BN_MP_CLAMP_C
279
+   #define BN_MP_CLEAR_C
280
+#endif
281
+
282
+#if defined(BN_MP_DIV_2_C)
283
+   #define BN_MP_GROW_C
284
+   #define BN_MP_CLAMP_C
285
+#endif
286
+
287
+#if defined(BN_MP_DIV_2D_C)
288
+   #define BN_MP_COPY_C
289
+   #define BN_MP_ZERO_C
290
+   #define BN_MP_INIT_C
291
+   #define BN_MP_MOD_2D_C
292
+   #define BN_MP_CLEAR_C
293
+   #define BN_MP_RSHD_C
294
+   #define BN_MP_CLAMP_C
295
+   #define BN_MP_EXCH_C
296
+#endif
297
+
298
+#if defined(BN_MP_DIV_3_C)
299
+   #define BN_MP_INIT_SIZE_C
300
+   #define BN_MP_CLAMP_C
301
+   #define BN_MP_EXCH_C
302
+   #define BN_MP_CLEAR_C
303
+#endif
304
+
305
+#if defined(BN_MP_DIV_D_C)
306
+   #define BN_MP_ISZERO_C
307
+   #define BN_MP_COPY_C
308
+   #define BN_MP_DIV_2D_C
309
+   #define BN_MP_DIV_3_C
310
+   #define BN_MP_INIT_SIZE_C
311
+   #define BN_MP_CLAMP_C
312
+   #define BN_MP_EXCH_C
313
+   #define BN_MP_CLEAR_C
314
+#endif
315
+
316
+#if defined(BN_MP_DR_IS_MODULUS_C)
317
+#endif
318
+
319
+#if defined(BN_MP_DR_REDUCE_C)
320
+   #define BN_MP_GROW_C
321
+   #define BN_MP_CLAMP_C
322
+   #define BN_MP_CMP_MAG_C
323
+   #define BN_S_MP_SUB_C
324
+#endif
325
+
326
+#if defined(BN_MP_DR_SETUP_C)
327
+#endif
328
+
329
+#if defined(BN_MP_EXCH_C)
330
+#endif
331
+
332
+#if defined(BN_MP_EXPT_D_C)
333
+   #define BN_MP_INIT_COPY_C
334
+   #define BN_MP_SET_C
335
+   #define BN_MP_SQR_C
336
+   #define BN_MP_CLEAR_C
337
+   #define BN_MP_MUL_C
338
+#endif
339
+
340
+#if defined(BN_MP_EXPTMOD_C)
341
+   #define BN_MP_INIT_C
342
+   #define BN_MP_INVMOD_C
343
+   #define BN_MP_CLEAR_C
344
+   #define BN_MP_ABS_C
345
+   #define BN_MP_CLEAR_MULTI_C
346
+   #define BN_MP_REDUCE_IS_2K_L_C
347
+   #define BN_S_MP_EXPTMOD_C
348
+   #define BN_MP_DR_IS_MODULUS_C
349
+   #define BN_MP_REDUCE_IS_2K_C
350
+   #define BN_MP_ISODD_C
351
+   #define BN_MP_EXPTMOD_FAST_C
352
+#endif
353
+
354
+#if defined(BN_MP_EXPTMOD_FAST_C)
355
+   #define BN_MP_COUNT_BITS_C
356
+   #define BN_MP_INIT_C
357
+   #define BN_MP_CLEAR_C
358
+   #define BN_MP_MONTGOMERY_SETUP_C
359
+   #define BN_FAST_MP_MONTGOMERY_REDUCE_C
360
+   #define BN_MP_MONTGOMERY_REDUCE_C
361
+   #define BN_MP_DR_SETUP_C
362
+   #define BN_MP_DR_REDUCE_C
363
+   #define BN_MP_REDUCE_2K_SETUP_C
364
+   #define BN_MP_REDUCE_2K_C
365
+   #define BN_MP_MONTGOMERY_CALC_NORMALIZATION_C
366
+   #define BN_MP_MULMOD_C
367
+   #define BN_MP_SET_C
368
+   #define BN_MP_MOD_C
369
+   #define BN_MP_COPY_C
370
+   #define BN_MP_SQR_C
371
+   #define BN_MP_MUL_C
372
+   #define BN_MP_EXCH_C
373
+#endif
374
+
375
+#if defined(BN_MP_EXTEUCLID_C)
376
+   #define BN_MP_INIT_MULTI_C
377
+   #define BN_MP_SET_C
378
+   #define BN_MP_COPY_C
379
+   #define BN_MP_ISZERO_C
380
+   #define BN_MP_DIV_C
381
+   #define BN_MP_MUL_C
382
+   #define BN_MP_SUB_C
383
+   #define BN_MP_NEG_C
384
+   #define BN_MP_EXCH_C
385
+   #define BN_MP_CLEAR_MULTI_C
386
+#endif
387
+
388
+#if defined(BN_MP_FREAD_C)
389
+   #define BN_MP_ZERO_C
390
+   #define BN_MP_S_RMAP_C
391
+   #define BN_MP_MUL_D_C
392
+   #define BN_MP_ADD_D_C
393
+   #define BN_MP_CMP_D_C
394
+#endif
395
+
396
+#if defined(BN_MP_FWRITE_C)
397
+   #define BN_MP_RADIX_SIZE_C
398
+   #define BN_MP_TORADIX_C
399
+#endif
400
+
401
+#if defined(BN_MP_GCD_C)
402
+   #define BN_MP_ISZERO_C
403
+   #define BN_MP_ABS_C
404
+   #define BN_MP_ZERO_C
405
+   #define BN_MP_INIT_COPY_C
406
+   #define BN_MP_CNT_LSB_C
407
+   #define BN_MP_DIV_2D_C
408
+   #define BN_MP_CMP_MAG_C
409
+   #define BN_MP_EXCH_C
410
+   #define BN_S_MP_SUB_C
411
+   #define BN_MP_MUL_2D_C
412
+   #define BN_MP_CLEAR_C
413
+#endif
414
+
415
+#if defined(BN_MP_GET_INT_C)
416
+#endif
417
+
418
+#if defined(BN_MP_GROW_C)
419
+#endif
420
+
421
+#if defined(BN_MP_INIT_C)
422
+#endif
423
+
424
+#if defined(BN_MP_INIT_COPY_C)
425
+   #define BN_MP_COPY_C
426
+#endif
427
+
428
+#if defined(BN_MP_INIT_MULTI_C)
429
+   #define BN_MP_ERR_C
430
+   #define BN_MP_INIT_C
431
+   #define BN_MP_CLEAR_C
432
+#endif
433
+
434
+#if defined(BN_MP_INIT_SET_C)
435
+   #define BN_MP_INIT_C
436
+   #define BN_MP_SET_C
437
+#endif
438
+
439
+#if defined(BN_MP_INIT_SET_INT_C)
440
+   #define BN_MP_INIT_C
441
+   #define BN_MP_SET_INT_C
442
+#endif
443
+
444
+#if defined(BN_MP_INIT_SIZE_C)
445
+   #define BN_MP_INIT_C
446
+#endif
447
+
448
+#if defined(BN_MP_INVMOD_C)
449
+   #define BN_MP_ISZERO_C
450
+   #define BN_MP_ISODD_C
451
+   #define BN_FAST_MP_INVMOD_C
452
+   #define BN_MP_INVMOD_SLOW_C
453
+#endif
454
+
455
+#if defined(BN_MP_INVMOD_SLOW_C)
456
+   #define BN_MP_ISZERO_C
457
+   #define BN_MP_INIT_MULTI_C
458
+   #define BN_MP_MOD_C
459
+   #define BN_MP_COPY_C
460
+   #define BN_MP_ISEVEN_C
461
+   #define BN_MP_SET_C
462
+   #define BN_MP_DIV_2_C
463
+   #define BN_MP_ISODD_C
464
+   #define BN_MP_ADD_C
465
+   #define BN_MP_SUB_C
466
+   #define BN_MP_CMP_C
467
+   #define BN_MP_CMP_D_C
468
+   #define BN_MP_CMP_MAG_C
469
+   #define BN_MP_EXCH_C
470
+   #define BN_MP_CLEAR_MULTI_C
471
+#endif
472
+
473
+#if defined(BN_MP_IS_SQUARE_C)
474
+   #define BN_MP_MOD_D_C
475
+   #define BN_MP_INIT_SET_INT_C
476
+   #define BN_MP_MOD_C
477
+   #define BN_MP_GET_INT_C
478
+   #define BN_MP_SQRT_C
479
+   #define BN_MP_SQR_C
480
+   #define BN_MP_CMP_MAG_C
481
+   #define BN_MP_CLEAR_C
482
+#endif
483
+
484
+#if defined(BN_MP_JACOBI_C)
485
+   #define BN_MP_CMP_D_C
486
+   #define BN_MP_ISZERO_C
487
+   #define BN_MP_INIT_COPY_C
488
+   #define BN_MP_CNT_LSB_C
489
+   #define BN_MP_DIV_2D_C
490
+   #define BN_MP_MOD_C
491
+   #define BN_MP_CLEAR_C
492
+#endif
493
+
494
+#if defined(BN_MP_KARATSUBA_MUL_C)
495
+   #define BN_MP_MUL_C
496
+   #define BN_MP_INIT_SIZE_C
497
+   #define BN_MP_CLAMP_C
498
+   #define BN_MP_SUB_C
499
+   #define BN_MP_ADD_C
500
+   #define BN_MP_LSHD_C
501
+   #define BN_MP_CLEAR_C
502
+#endif
503
+
504
+#if defined(BN_MP_KARATSUBA_SQR_C)
505
+   #define BN_MP_INIT_SIZE_C
506
+   #define BN_MP_CLAMP_C
507
+   #define BN_MP_SQR_C
508
+   #define BN_MP_SUB_C
509
+   #define BN_S_MP_ADD_C
510
+   #define BN_MP_LSHD_C
511
+   #define BN_MP_ADD_C
512
+   #define BN_MP_CLEAR_C
513
+#endif
514
+
515
+#if defined(BN_MP_LCM_C)
516
+   #define BN_MP_INIT_MULTI_C
517
+   #define BN_MP_GCD_C
518
+   #define BN_MP_CMP_MAG_C
519
+   #define BN_MP_DIV_C
520
+   #define BN_MP_MUL_C
521
+   #define BN_MP_CLEAR_MULTI_C
522
+#endif
523
+
524
+#if defined(BN_MP_LSHD_C)
525
+   #define BN_MP_GROW_C
526
+   #define BN_MP_RSHD_C
527
+#endif
528
+
529
+#if defined(BN_MP_MOD_C)
530
+   #define BN_MP_INIT_C
531
+   #define BN_MP_DIV_C
532
+   #define BN_MP_CLEAR_C
533
+   #define BN_MP_ADD_C
534
+   #define BN_MP_EXCH_C
535
+#endif
536
+
537
+#if defined(BN_MP_MOD_2D_C)
538
+   #define BN_MP_ZERO_C
539
+   #define BN_MP_COPY_C
540
+   #define BN_MP_CLAMP_C
541
+#endif
542
+
543
+#if defined(BN_MP_MOD_D_C)
544
+   #define BN_MP_DIV_D_C
545
+#endif
546
+
547
+#if defined(BN_MP_MONTGOMERY_CALC_NORMALIZATION_C)
548
+   #define BN_MP_COUNT_BITS_C
549
+   #define BN_MP_2EXPT_C
550
+   #define BN_MP_SET_C
551
+   #define BN_MP_MUL_2_C
552
+   #define BN_MP_CMP_MAG_C
553
+   #define BN_S_MP_SUB_C
554
+#endif
555
+
556
+#if defined(BN_MP_MONTGOMERY_REDUCE_C)
557
+   #define BN_FAST_MP_MONTGOMERY_REDUCE_C
558
+   #define BN_MP_GROW_C
559
+   #define BN_MP_CLAMP_C
560
+   #define BN_MP_RSHD_C
561
+   #define BN_MP_CMP_MAG_C
562
+   #define BN_S_MP_SUB_C
563
+#endif
564
+
565
+#if defined(BN_MP_MONTGOMERY_SETUP_C)
566
+#endif
567
+
568
+#if defined(BN_MP_MUL_C)
569
+   #define BN_MP_TOOM_MUL_C
570
+   #define BN_MP_KARATSUBA_MUL_C
571
+   #define BN_FAST_S_MP_MUL_DIGS_C
572
+   #define BN_S_MP_MUL_C
573
+   #define BN_S_MP_MUL_DIGS_C
574
+#endif
575
+
576
+#if defined(BN_MP_MUL_2_C)
577
+   #define BN_MP_GROW_C
578
+#endif
579
+
580
+#if defined(BN_MP_MUL_2D_C)
581
+   #define BN_MP_COPY_C
582
+   #define BN_MP_GROW_C
583
+   #define BN_MP_LSHD_C
584
+   #define BN_MP_CLAMP_C
585
+#endif
586
+
587
+#if defined(BN_MP_MUL_D_C)
588
+   #define BN_MP_GROW_C
589
+   #define BN_MP_CLAMP_C
590
+#endif
591
+
592
+#if defined(BN_MP_MULMOD_C)
593
+   #define BN_MP_INIT_C
594
+   #define BN_MP_MUL_C
595
+   #define BN_MP_CLEAR_C
596
+   #define BN_MP_MOD_C
597
+#endif
598
+
599
+#if defined(BN_MP_N_ROOT_C)
600
+   #define BN_MP_INIT_C
601
+   #define BN_MP_SET_C
602
+   #define BN_MP_COPY_C
603
+   #define BN_MP_EXPT_D_C
604
+   #define BN_MP_MUL_C
605
+   #define BN_MP_SUB_C
606
+   #define BN_MP_MUL_D_C
607
+   #define BN_MP_DIV_C
608
+   #define BN_MP_CMP_C
609
+   #define BN_MP_SUB_D_C
610
+   #define BN_MP_EXCH_C
611
+   #define BN_MP_CLEAR_C
612
+#endif
613
+
614
+#if defined(BN_MP_NEG_C)
615
+   #define BN_MP_COPY_C
616
+   #define BN_MP_ISZERO_C
617
+#endif
618
+
619
+#if defined(BN_MP_OR_C)
620
+   #define BN_MP_INIT_COPY_C
621
+   #define BN_MP_CLAMP_C
622
+   #define BN_MP_EXCH_C
623
+   #define BN_MP_CLEAR_C
624
+#endif
625
+
626
+#if defined(BN_MP_PRIME_FERMAT_C)
627
+   #define BN_MP_CMP_D_C
628
+   #define BN_MP_INIT_C
629
+   #define BN_MP_EXPTMOD_C
630
+   #define BN_MP_CMP_C
631
+   #define BN_MP_CLEAR_C
632
+#endif
633
+
634
+#if defined(BN_MP_PRIME_IS_DIVISIBLE_C)
635
+   #define BN_MP_MOD_D_C
636
+#endif
637
+
638
+#if defined(BN_MP_PRIME_IS_PRIME_C)
639
+   #define BN_MP_CMP_D_C
640
+   #define BN_MP_PRIME_IS_DIVISIBLE_C
641
+   #define BN_MP_INIT_C
642
+   #define BN_MP_SET_C
643
+   #define BN_MP_PRIME_MILLER_RABIN_C
644
+   #define BN_MP_CLEAR_C
645
+#endif
646
+
647
+#if defined(BN_MP_PRIME_MILLER_RABIN_C)
648
+   #define BN_MP_CMP_D_C
649
+   #define BN_MP_INIT_COPY_C
650
+   #define BN_MP_SUB_D_C
651
+   #define BN_MP_CNT_LSB_C
652
+   #define BN_MP_DIV_2D_C
653
+   #define BN_MP_EXPTMOD_C
654
+   #define BN_MP_CMP_C
655
+   #define BN_MP_SQRMOD_C
656
+   #define BN_MP_CLEAR_C
657
+#endif
658
+
659
+#if defined(BN_MP_PRIME_NEXT_PRIME_C)
660
+   #define BN_MP_CMP_D_C
661
+   #define BN_MP_SET_C
662
+   #define BN_MP_SUB_D_C
663
+   #define BN_MP_ISEVEN_C
664
+   #define BN_MP_MOD_D_C
665
+   #define BN_MP_INIT_C
666
+   #define BN_MP_ADD_D_C
667
+   #define BN_MP_PRIME_MILLER_RABIN_C
668
+   #define BN_MP_CLEAR_C
669
+#endif
670
+
671
+#if defined(BN_MP_PRIME_RABIN_MILLER_TRIALS_C)
672
+#endif
673
+
674
+#if defined(BN_MP_PRIME_RANDOM_EX_C)
675
+   #define BN_MP_READ_UNSIGNED_BIN_C
676
+   #define BN_MP_PRIME_IS_PRIME_C
677
+   #define BN_MP_SUB_D_C
678
+   #define BN_MP_DIV_2_C
679
+   #define BN_MP_MUL_2_C
680
+   #define BN_MP_ADD_D_C
681
+#endif
682
+
683
+#if defined(BN_MP_RADIX_SIZE_C)
684
+   #define BN_MP_COUNT_BITS_C
685
+   #define BN_MP_INIT_COPY_C
686
+   #define BN_MP_ISZERO_C
687
+   #define BN_MP_DIV_D_C
688
+   #define BN_MP_CLEAR_C
689
+#endif
690
+
691
+#if defined(BN_MP_RADIX_SMAP_C)
692
+   #define BN_MP_S_RMAP_C
693
+#endif
694
+
695
+#if defined(BN_MP_RAND_C)
696
+   #define BN_MP_ZERO_C
697
+   #define BN_MP_ADD_D_C
698
+   #define BN_MP_LSHD_C
699
+#endif
700
+
701
+#if defined(BN_MP_READ_RADIX_C)
702
+   #define BN_MP_ZERO_C
703
+   #define BN_MP_S_RMAP_C
704
+   #define BN_MP_RADIX_SMAP_C
705
+   #define BN_MP_MUL_D_C
706
+   #define BN_MP_ADD_D_C
707
+   #define BN_MP_ISZERO_C
708
+#endif
709
+
710
+#if defined(BN_MP_READ_SIGNED_BIN_C)
711
+   #define BN_MP_READ_UNSIGNED_BIN_C
712
+#endif
713
+
714
+#if defined(BN_MP_READ_UNSIGNED_BIN_C)
715
+   #define BN_MP_GROW_C
716
+   #define BN_MP_ZERO_C
717
+   #define BN_MP_MUL_2D_C
718
+   #define BN_MP_CLAMP_C
719
+#endif
720
+
721
+#if defined(BN_MP_REDUCE_C)
722
+   #define BN_MP_REDUCE_SETUP_C
723
+   #define BN_MP_INIT_COPY_C
724
+   #define BN_MP_RSHD_C
725
+   #define BN_MP_MUL_C
726
+   #define BN_S_MP_MUL_HIGH_DIGS_C
727
+   #define BN_FAST_S_MP_MUL_HIGH_DIGS_C
728
+   #define BN_MP_MOD_2D_C
729
+   #define BN_S_MP_MUL_DIGS_C
730
+   #define BN_MP_SUB_C
731
+   #define BN_MP_CMP_D_C
732
+   #define BN_MP_SET_C
733
+   #define BN_MP_LSHD_C
734
+   #define BN_MP_ADD_C
735
+   #define BN_MP_CMP_C
736
+   #define BN_S_MP_SUB_C
737
+   #define BN_MP_CLEAR_C
738
+#endif
739
+
740
+#if defined(BN_MP_REDUCE_2K_C)
741
+   #define BN_MP_INIT_C
742
+   #define BN_MP_COUNT_BITS_C
743
+   #define BN_MP_DIV_2D_C
744
+   #define BN_MP_MUL_D_C
745
+   #define BN_S_MP_ADD_C
746
+   #define BN_MP_CMP_MAG_C
747
+   #define BN_S_MP_SUB_C
748
+   #define BN_MP_CLEAR_C
749
+#endif
750
+
751
+#if defined(BN_MP_REDUCE_2K_L_C)
752
+   #define BN_MP_INIT_C
753
+   #define BN_MP_COUNT_BITS_C
754
+   #define BN_MP_DIV_2D_C
755
+   #define BN_MP_MUL_C
756
+   #define BN_S_MP_ADD_C
757
+   #define BN_MP_CMP_MAG_C
758
+   #define BN_S_MP_SUB_C
759
+   #define BN_MP_CLEAR_C
760
+#endif
761
+
762
+#if defined(BN_MP_REDUCE_2K_SETUP_C)
763
+   #define BN_MP_INIT_C
764
+   #define BN_MP_COUNT_BITS_C
765
+   #define BN_MP_2EXPT_C
766
+   #define BN_MP_CLEAR_C
767
+   #define BN_S_MP_SUB_C
768
+#endif
769
+
770
+#if defined(BN_MP_REDUCE_2K_SETUP_L_C)
771
+   #define BN_MP_INIT_C
772
+   #define BN_MP_2EXPT_C
773
+   #define BN_MP_COUNT_BITS_C
774
+   #define BN_S_MP_SUB_C
775
+   #define BN_MP_CLEAR_C
776
+#endif
777
+
778
+#if defined(BN_MP_REDUCE_IS_2K_C)
779
+   #define BN_MP_REDUCE_2K_C
780
+   #define BN_MP_COUNT_BITS_C
781
+#endif
782
+
783
+#if defined(BN_MP_REDUCE_IS_2K_L_C)
784
+#endif
785
+
786
+#if defined(BN_MP_REDUCE_SETUP_C)
787
+   #define BN_MP_2EXPT_C
788
+   #define BN_MP_DIV_C
789
+#endif
790
+
791
+#if defined(BN_MP_RSHD_C)
792
+   #define BN_MP_ZERO_C
793
+#endif
794
+
795
+#if defined(BN_MP_SET_C)
796
+   #define BN_MP_ZERO_C
797
+#endif
798
+
799
+#if defined(BN_MP_SET_INT_C)
800
+   #define BN_MP_ZERO_C
801
+   #define BN_MP_MUL_2D_C
802
+   #define BN_MP_CLAMP_C
803
+#endif
804
+
805
+#if defined(BN_MP_SHRINK_C)
806
+#endif
807
+
808
+#if defined(BN_MP_SIGNED_BIN_SIZE_C)
809
+   #define BN_MP_UNSIGNED_BIN_SIZE_C
810
+#endif
811
+
812
+#if defined(BN_MP_SQR_C)
813
+   #define BN_MP_TOOM_SQR_C
814
+   #define BN_MP_KARATSUBA_SQR_C
815
+   #define BN_FAST_S_MP_SQR_C
816
+   #define BN_S_MP_SQR_C
817
+#endif
818
+
819
+#if defined(BN_MP_SQRMOD_C)
820
+   #define BN_MP_INIT_C
821
+   #define BN_MP_SQR_C
822
+   #define BN_MP_CLEAR_C
823
+   #define BN_MP_MOD_C
824
+#endif
825
+
826
+#if defined(BN_MP_SQRT_C)
827
+   #define BN_MP_N_ROOT_C
828
+   #define BN_MP_ISZERO_C
829
+   #define BN_MP_ZERO_C
830
+   #define BN_MP_INIT_COPY_C
831
+   #define BN_MP_RSHD_C
832
+   #define BN_MP_DIV_C
833
+   #define BN_MP_ADD_C
834
+   #define BN_MP_DIV_2_C
835
+   #define BN_MP_CMP_MAG_C
836
+   #define BN_MP_EXCH_C
837
+   #define BN_MP_CLEAR_C
838
+#endif
839
+
840
+#if defined(BN_MP_SUB_C)
841
+   #define BN_S_MP_ADD_C
842
+   #define BN_MP_CMP_MAG_C
843
+   #define BN_S_MP_SUB_C
844
+#endif
845
+
846
+#if defined(BN_MP_SUB_D_C)
847
+   #define BN_MP_GROW_C
848
+   #define BN_MP_ADD_D_C
849
+   #define BN_MP_CLAMP_C
850
+#endif
851
+
852
+#if defined(BN_MP_SUBMOD_C)
853
+   #define BN_MP_INIT_C
854
+   #define BN_MP_SUB_C
855
+   #define BN_MP_CLEAR_C
856
+   #define BN_MP_MOD_C
857
+#endif
858
+
859
+#if defined(BN_MP_TO_SIGNED_BIN_C)
860
+   #define BN_MP_TO_UNSIGNED_BIN_C
861
+#endif
862
+
863
+#if defined(BN_MP_TO_SIGNED_BIN_N_C)
864
+   #define BN_MP_SIGNED_BIN_SIZE_C
865
+   #define BN_MP_TO_SIGNED_BIN_C
866
+#endif
867
+
868
+#if defined(BN_MP_TO_UNSIGNED_BIN_C)
869
+   #define BN_MP_INIT_COPY_C
870
+   #define BN_MP_ISZERO_C
871
+   #define BN_MP_DIV_2D_C
872
+   #define BN_MP_CLEAR_C
873
+#endif
874
+
875
+#if defined(BN_MP_TO_UNSIGNED_BIN_N_C)
876
+   #define BN_MP_UNSIGNED_BIN_SIZE_C
877
+   #define BN_MP_TO_UNSIGNED_BIN_C
878
+#endif
879
+
880
+#if defined(BN_MP_TOOM_MUL_C)
881
+   #define BN_MP_INIT_MULTI_C
882
+   #define BN_MP_MOD_2D_C
883
+   #define BN_MP_COPY_C
884
+   #define BN_MP_RSHD_C
885
+   #define BN_MP_MUL_C
886
+   #define BN_MP_MUL_2_C
887
+   #define BN_MP_ADD_C
888
+   #define BN_MP_SUB_C
889
+   #define BN_MP_DIV_2_C
890
+   #define BN_MP_MUL_2D_C
891
+   #define BN_MP_MUL_D_C
892
+   #define BN_MP_DIV_3_C
893
+   #define BN_MP_LSHD_C
894
+   #define BN_MP_CLEAR_MULTI_C
895
+#endif
896
+
897
+#if defined(BN_MP_TOOM_SQR_C)
898
+   #define BN_MP_INIT_MULTI_C
899
+   #define BN_MP_MOD_2D_C
900
+   #define BN_MP_COPY_C
901
+   #define BN_MP_RSHD_C
902
+   #define BN_MP_SQR_C
903
+   #define BN_MP_MUL_2_C
904
+   #define BN_MP_ADD_C
905
+   #define BN_MP_SUB_C
906
+   #define BN_MP_DIV_2_C
907
+   #define BN_MP_MUL_2D_C
908
+   #define BN_MP_MUL_D_C
909
+   #define BN_MP_DIV_3_C
910
+   #define BN_MP_LSHD_C
911
+   #define BN_MP_CLEAR_MULTI_C
912
+#endif
913
+
914
+#if defined(BN_MP_TORADIX_C)
915
+   #define BN_MP_ISZERO_C
916
+   #define BN_MP_INIT_COPY_C
917
+   #define BN_MP_DIV_D_C
918
+   #define BN_MP_CLEAR_C
919
+   #define BN_MP_S_RMAP_C
920
+#endif
921
+
922
+#if defined(BN_MP_TORADIX_N_C)
923
+   #define BN_MP_ISZERO_C
924
+   #define BN_MP_INIT_COPY_C
925
+   #define BN_MP_DIV_D_C
926
+   #define BN_MP_CLEAR_C
927
+   #define BN_MP_S_RMAP_C
928
+#endif
929
+
930
+#if defined(BN_MP_UNSIGNED_BIN_SIZE_C)
931
+   #define BN_MP_COUNT_BITS_C
932
+#endif
933
+
934
+#if defined(BN_MP_XOR_C)
935
+   #define BN_MP_INIT_COPY_C
936
+   #define BN_MP_CLAMP_C
937
+   #define BN_MP_EXCH_C
938
+   #define BN_MP_CLEAR_C
939
+#endif
940
+
941
+#if defined(BN_MP_ZERO_C)
942
+#endif
943
+
944
+#if defined(BN_PRIME_TAB_C)
945
+#endif
946
+
947
+#if defined(BN_REVERSE_C)
948
+#endif
949
+
950
+#if defined(BN_S_MP_ADD_C)
951
+   #define BN_MP_GROW_C
952
+   #define BN_MP_CLAMP_C
953
+#endif
954
+
955
+#if defined(BN_S_MP_EXPTMOD_C)
956
+   #define BN_MP_COUNT_BITS_C
957
+   #define BN_MP_INIT_C
958
+   #define BN_MP_CLEAR_C
959
+   #define BN_MP_REDUCE_SETUP_C
960
+   #define BN_MP_REDUCE_C
961
+   #define BN_MP_REDUCE_2K_SETUP_L_C
962
+   #define BN_MP_REDUCE_2K_L_C
963
+   #define BN_MP_MOD_C
964
+   #define BN_MP_COPY_C
965
+   #define BN_MP_SQR_C
966
+   #define BN_MP_MUL_C
967
+   #define BN_MP_SET_C
968
+   #define BN_MP_EXCH_C
969
+#endif
970
+
971
+#if defined(BN_S_MP_MUL_DIGS_C)
972
+   #define BN_FAST_S_MP_MUL_DIGS_C
973
+   #define BN_MP_INIT_SIZE_C
974
+   #define BN_MP_CLAMP_C
975
+   #define BN_MP_EXCH_C
976
+   #define BN_MP_CLEAR_C
977
+#endif
978
+
979
+#if defined(BN_S_MP_MUL_HIGH_DIGS_C)
980
+   #define BN_FAST_S_MP_MUL_HIGH_DIGS_C
981
+   #define BN_MP_INIT_SIZE_C
982
+   #define BN_MP_CLAMP_C
983
+   #define BN_MP_EXCH_C
984
+   #define BN_MP_CLEAR_C
985
+#endif
986
+
987
+#if defined(BN_S_MP_SQR_C)
988
+   #define BN_MP_INIT_SIZE_C
989
+   #define BN_MP_CLAMP_C
990
+   #define BN_MP_EXCH_C
991
+   #define BN_MP_CLEAR_C
992
+#endif
993
+
994
+#if defined(BN_S_MP_SUB_C)
995
+   #define BN_MP_GROW_C
996
+   #define BN_MP_CLAMP_C
997
+#endif
998
+
999
+#if defined(BNCORE_C)
1000
+#endif
1001
+
1002
+/* $Source: /cvs/libtom/libtommath/tommath_class.h,v $ */
1003
+/* $Revision: 1.3 $ */
1004
+/* $Date: 2005/07/28 11:59:32 $ */
1005
+#endif
... ...
@@ -469,14 +469,12 @@ static int cli_cvdverify(FILE *fs, struct cl_cvd *cvdpt, unsigned int cld)
469 469
 	return CL_EMD5;
470 470
     }
471 471
 
472
-#ifdef HAVE_LIBGMP
473 472
     if(cli_versig(md5, cvd->dsig)) {
474 473
 	cli_dbgmsg("cli_cvdverify: Digital signature verification error\n");
475 474
 	free(md5);
476 475
 	cl_cvdfree(cvd);
477 476
 	return CL_EDSIG;
478 477
     }
479
-#endif
480 478
 
481 479
     free(md5);
482 480
     cl_cvdfree(cvd);
... ...
@@ -113,7 +113,7 @@ static struct dconf_module modules[] = {
113 113
 };
114 114
 
115 115
 #ifdef USE_MPOOL 
116
-struct cli_dconf *cli_dconf_init(mp_t *mempool)
116
+struct cli_dconf *cli_dconf_init(mpool_t *mempool)
117 117
 #else
118 118
 struct cli_dconf *cli_dconf_init(void)
119 119
 #endif
... ...
@@ -121,7 +121,7 @@ struct cli_dconf *cli_dconf_init(void)
121 121
 	unsigned int i;
122 122
 	struct cli_dconf *dconf;
123 123
 
124
-    dconf = (struct cli_dconf *) mp_calloc(mempool, sizeof(struct cli_dconf), 1);
124
+    dconf = (struct cli_dconf *) mpool_calloc(mempool, sizeof(struct cli_dconf), 1);
125 125
     if(!dconf)
126 126
 	return NULL;
127 127
 
... ...
@@ -100,11 +100,11 @@ struct cli_dconf {
100 100
 #define PHISHING_CONF_ENTCONV  0x2
101 101
 
102 102
 #ifdef USE_MPOOL
103
-struct cli_dconf *cli_dconf_init(mp_t *);
104
-#define cli_mp_dconf_init(a) cli_dconf_init(a)
103
+struct cli_dconf *cli_dconf_init(mpool_t *);
104
+#define cli_mpool_dconf_init(a) cli_dconf_init(a)
105 105
 #else
106 106
 struct cli_dconf *cli_dconf_init(void);
107
-#define cli_mp_dconf_init(a) cli_dconf_init()
107
+#define cli_mpool_dconf_init(a) cli_dconf_init()
108 108
 #endif
109 109
 void cli_dconf_print(struct cli_dconf *dconf);
110 110
 int cli_dconf_load(FILE *fs, struct cl_engine *engine, unsigned int options, struct cli_dbio *dbio);
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 2007-2008 Sourcefire, Inc.
2
+ *  Copyright (C) 2007-2009 Sourcefire, Inc.
3 3
  *
4 4
  *  Authors: Tomasz Kojm
5 5
  *
... ...
@@ -22,18 +22,16 @@
22 22
 #include "clamav-config.h"
23 23
 #endif
24 24
 
25
-#ifdef HAVE_LIBGMP
26
-
27 25
 #include <stdio.h>
28 26
 #include <string.h>
29 27
 #include <stdlib.h>
30 28
 #include <ctype.h>
31
-#include <gmp.h>
32 29
 
33 30
 #include "clamav.h"
34 31
 #include "others.h"
35 32
 #include "dsig.h"
36 33
 #include "str.h"
34
+#include "bignum.h"
37 35
 
38 36
 #define CLI_NSTR "118640995551645342603070001658453189751527774412027743746599405743243142607464144767361060640655844749760788890022283424922762488917565551002467771109669598189410434699034532232228621591089508178591428456220796841621637175567590476666928698770143328137383952820383197532047771780196576957695822641224262693037"
39 37
 
... ...
@@ -62,54 +60,51 @@ static unsigned char cli_ndecode(unsigned char value)
62 62
     return -1;
63 63
 }
64 64
 
65
-unsigned char *cli_decodesig(const char *sig, unsigned int plen, mpz_t e, mpz_t n)
65
+unsigned char *cli_decodesig(const char *sig, unsigned int plen, mp_int e, mp_int n)
66 66
 {
67 67
 	int i, slen = strlen(sig), dec;
68 68
 	unsigned char *plain;
69
-	mpz_t r, p, c;
70
-
69
+	mp_int r, p, c;
71 70
 
72
-    mpz_init(r);
73
-    mpz_init(c);
74 71
 
72
+    mp_init(&r);
73
+    mp_init(&c);
75 74
     for(i = 0; i < slen; i++) {
76 75
 	if((dec = cli_ndecode(sig[i])) < 0) {
77
-	    mpz_clear(r);
78
-	    mpz_clear(c);
76
+	    mp_clear(&r);
77
+	    mp_clear(&c);
79 78
 	    return NULL;
80 79
 	}
81
-
82
-	mpz_set_ui(r, dec);
83
-	mpz_mul_2exp(r, r, 6 * i);
84
-	mpz_add(c, c, r);
80
+	mp_set_int(&r, dec);
81
+	mp_mul_2d(&r, 6 * i, &r);
82
+	mp_add(&r, &c, &c);
85 83
     }
86 84
 
87 85
     plain = (unsigned char *) cli_calloc(plen + 1, sizeof(unsigned char));
88 86
     if(!plain) {
89 87
 	cli_errmsg("cli_decodesig: Can't allocate memory for 'plain'\n");
90
-	mpz_clear(r);
91
-	mpz_clear(c);
88
+	mp_clear(&r);
89
+	mp_clear(&c);
92 90
 	return NULL;
93 91
     }
94
-
95
-    mpz_init(p);
96
-    mpz_powm(p, c, e, n); /* plain = cipher^e mod n */
97
-    mpz_clear(c);
98
-
92
+    mp_init(&p);
93
+    mp_exptmod(&c, &e, &n, &p); /* plain = cipher^e mod n */
94
+    mp_clear(&c);
95
+    mp_set_int(&c, 256);
99 96
     for(i = plen - 1; i >= 0; i--) { /* reverse */
100
-	mpz_tdiv_qr_ui(p, r, p, 256);
101
-	plain[i] = mpz_get_ui(r);
97
+	mp_div(&p, &c, &p, &r);
98
+	plain[i] = mp_get_int(&r);
102 99
     }
103
-
104
-    mpz_clear(p);
105
-    mpz_clear(r);
100
+    mp_clear(&c);
101
+    mp_clear(&p);
102
+    mp_clear(&r);
106 103
 
107 104
     return plain;
108 105
 }
109 106
 
110 107
 int cli_versig(const char *md5, const char *dsig)
111 108
 {
112
-	mpz_t n, e;
109
+	mp_int n, e;
113 110
 	char *pt, *pt2;
114 111
 
115 112
 
... ...
@@ -119,12 +114,14 @@ int cli_versig(const char *md5, const char *dsig)
119 119
 	return CL_EMD5;
120 120
     }
121 121
 
122
-    mpz_init_set_str(n, CLI_NSTR, 10);
123
-    mpz_init_set_str(e, CLI_ESTR, 10);
122
+    mp_init(&n);
123
+    mp_read_radix(&n, CLI_NSTR, 10);
124
+    mp_init(&e);
125
+    mp_read_radix(&e, CLI_ESTR, 10);
124 126
 
125 127
     if(!(pt = (char *) cli_decodesig(dsig, 16, e, n))) {
126
-	mpz_clear(n);
127
-	mpz_clear(e);
128
+	mp_clear(&n);
129
+	mp_clear(&e);
128 130
 	return CL_EDSIG;
129 131
     }
130 132
 
... ...
@@ -136,21 +133,15 @@ int cli_versig(const char *md5, const char *dsig)
136 136
     if(strncmp(md5, pt2, 32)) {
137 137
 	cli_dbgmsg("cli_versig: Signature doesn't match.\n");
138 138
 	free(pt2);
139
-	mpz_clear(n);
140
-	mpz_clear(e);
139
+	mp_clear(&n);
140
+	mp_clear(&e);
141 141
 	return CL_EDSIG;
142 142
     }
143 143
 
144 144
     free(pt2);
145
-    mpz_clear(n);
146
-    mpz_clear(e);
145
+    mp_clear(&n);
146
+    mp_clear(&e);
147 147
 
148 148
     cli_dbgmsg("cli_versig: Digital signature is correct.\n");
149 149
     return CL_SUCCESS;
150 150
 }
151
-#else
152
-/* since we are using linker version scripts, we must define all symbols listed in the .map,
153
- * otherwise linking will fail (at least on Solaris).
154
- * So here is a dummy definition for cli_decodesig.*/
155
-unsigned char *cli_decodesig() {}
156
-#endif
... ...
@@ -1,5 +1,5 @@
1 1
 /*
2
- *  Copyright (C) 2007-2008 Sourcefire, Inc.
2
+ *  Copyright (C) 2007-2009 Sourcefire, Inc.
3 3
  *
4 4
  *  Authors: Tomasz Kojm
5 5
  *
... ...
@@ -25,11 +25,9 @@
25 25
 #include "clamav-config.h"
26 26
 #endif
27 27
 
28
-#ifdef HAVE_LIBGMP
29
-#include <gmp.h>
28
+#include "bignum.h"
30 29
 
31 30
 int cli_versig(const char *md5, const char *dsig);
32
-unsigned char *cli_decodesig(const char *sig, unsigned int plen, mpz_t e, mpz_t n);
31
+unsigned char *cli_decodesig(const char *sig, unsigned int plen, mp_int e, mp_int n);
33 32
 
34
-#endif /* HAVE_LIBGMP */
35 33
 #endif
... ...
@@ -109,9 +109,9 @@ void cli_ftfree(const struct cl_engine *engine)
109 109
     while(ftypes) {
110 110
 	pt = ftypes;
111 111
 	ftypes = ftypes->next;
112
-	mp_free(engine->mempool, pt->magic);
113
-	mp_free(engine->mempool, pt->tname);
114
-	mp_free(engine->mempool, pt);
112
+	mpool_free(engine->mempool, pt->magic);
113
+	mpool_free(engine->mempool, pt->tname);
114
+	mpool_free(engine->mempool, pt);
115 115
     }
116 116
 }
117 117
 
... ...
@@ -116,10 +116,13 @@ CLAMAV_PRIVATE {
116 116
     cli_bm_scanbuff;
117 117
     cli_bm_free;
118 118
     html_screnc_decode;
119
-    mp_create;
120
-    mp_destroy;
121
-    mp_free;
122
-    mp_getstats;
119
+    mpool_create;
120
+    mpool_destroy;
121
+    mpool_free;
122
+    mpool_getstats;
123
+    mp_init;
124
+    mp_read_radix;
125
+    mp_clear;
123 126
   local:
124 127
     *;
125 128
 };
... ...
@@ -127,7 +127,6 @@ GENHTML = @GENHTML@
127 127
 GETENT = @GETENT@
128 128
 GPERF = @GPERF@
129 129
 GREP = @GREP@
130
-HAVE_LIBGMP = @HAVE_LIBGMP@
131 130
 INCLTDL = @INCLTDL@
132 131
 INSTALL = @INSTALL@
133 132
 INSTALL_DATA = @INSTALL_DATA@
... ...
@@ -145,8 +144,6 @@ LIBBZ2 = @LIBBZ2@
145 145
 LIBBZ2_PREFIX = @LIBBZ2_PREFIX@
146 146
 LIBCLAMAV_LIBS = @LIBCLAMAV_LIBS@
147 147
 LIBCLAMAV_VERSION = @LIBCLAMAV_VERSION@
148
-LIBGMP = @LIBGMP@
149
-LIBGMP_PREFIX = @LIBGMP_PREFIX@
150 148
 LIBLTDL = @LIBLTDL@
151 149
 LIBOBJS = @LIBOBJS@
152 150
 LIBS = @LIBS@
... ...
@@ -157,7 +154,6 @@ LTDLDEPS = @LTDLDEPS@
157 157
 LTDLINCL = @LTDLINCL@
158 158
 LTDLOPEN = @LTDLOPEN@
159 159
 LTLIBBZ2 = @LTLIBBZ2@
160
-LTLIBGMP = @LTLIBGMP@
161 160
 LTLIBOBJS = @LTLIBOBJS@
162 161
 LT_CONFIG_H = @LT_CONFIG_H@
163 162
 LT_DLLOADERS = @LT_DLLOADERS@
... ...
@@ -68,7 +68,7 @@ int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern)
68 68
 
69 69
     for(i = 0; i < len; i++) {
70 70
 	if(!pt->trans) {
71
-	    pt->trans = (struct cli_ac_node **) mp_calloc(root->mempool, 256, sizeof(struct cli_ac_node *));
71
+	    pt->trans = (struct cli_ac_node **) mpool_calloc(root->mempool, 256, sizeof(struct cli_ac_node *));
72 72
 	    if(!pt->trans) {
73 73
 		cli_errmsg("cli_ac_addpatt: Can't allocate memory for pt->trans\n");
74 74
 		return CL_EMEM;
... ...
@@ -78,29 +78,29 @@ int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern)
78 78
 	next = pt->trans[(unsigned char) (pattern->pattern[i] & 0xff)]; 
79 79
 
80 80
 	if(!next) {
81
-	    next = (struct cli_ac_node *) mp_calloc(root->mempool, 1, sizeof(struct cli_ac_node));
81
+	    next = (struct cli_ac_node *) mpool_calloc(root->mempool, 1, sizeof(struct cli_ac_node));
82 82
 	    if(!next) {
83 83
 		cli_errmsg("cli_ac_addpatt: Can't allocate memory for AC node\n");
84 84
 		return CL_EMEM;
85 85
 	    }
86 86
 
87 87
 	    if(i != len - 1) {
88
-		next->trans = (struct cli_ac_node **) mp_calloc(root->mempool, 256, sizeof(struct cli_ac_node *));
88
+		next->trans = (struct cli_ac_node **) mpool_calloc(root->mempool, 256, sizeof(struct cli_ac_node *));
89 89
 		if(!next->trans) {
90 90
 		    cli_errmsg("cli_ac_addpatt: Can't allocate memory for next->trans\n");
91
-		    mp_free(root->mempool, next);
91
+		    mpool_free(root->mempool, next);
92 92
 		    return CL_EMEM;
93 93
 		}
94 94
 	    }
95 95
 
96 96
 	    root->ac_nodes++;
97
-	    newtable = mp_realloc(root->mempool, root->ac_nodetable, root->ac_nodes * sizeof(struct cli_ac_node *));
97
+	    newtable = mpool_realloc(root->mempool, root->ac_nodetable, root->ac_nodes * sizeof(struct cli_ac_node *));
98 98
 	    if(!newtable) {
99 99
 		root->ac_nodes--;
100 100
 		cli_errmsg("cli_ac_addpatt: Can't realloc ac_nodetable\n");
101 101
 		if(next->trans)
102
-		    mp_free(root->mempool, next->trans);
103
-		mp_free(root->mempool, next);
102
+		    mpool_free(root->mempool, next->trans);
103
+		mpool_free(root->mempool, next);
104 104
 		return CL_EMEM;
105 105
 	    }
106 106
 	    root->ac_nodetable = (struct cli_ac_node **) newtable;
... ...
@@ -113,7 +113,7 @@ int cli_ac_addpatt(struct cli_matcher *root, struct cli_ac_patt *pattern)
113 113
     }
114 114
 
115 115
     root->ac_patterns++;
116
-    newtable = mp_realloc(root->mempool, root->ac_pattable, root->ac_patterns * sizeof(struct cli_ac_patt *));
116
+    newtable = mpool_realloc(root->mempool, root->ac_pattable, root->ac_patterns * sizeof(struct cli_ac_patt *));
117 117
     if(!newtable) {
118 118
 	root->ac_patterns--;
119 119
 	cli_errmsg("cli_ac_addpatt: Can't realloc ac_pattable\n");
... ...
@@ -327,16 +327,16 @@ int cli_ac_init(struct cli_matcher *root, uint8_t mindepth, uint8_t maxdepth)
327 327
     assert(root->mempool && "mempool must be initialized");
328 328
 #endif
329 329
 
330
-    root->ac_root = (struct cli_ac_node *) mp_calloc(root->mempool, 1, sizeof(struct cli_ac_node));
330
+    root->ac_root = (struct cli_ac_node *) mpool_calloc(root->mempool, 1, sizeof(struct cli_ac_node));
331 331
     if(!root->ac_root) {
332 332
 	cli_errmsg("cli_ac_init: Can't allocate memory for ac_root\n");
333 333
 	return CL_EMEM;
334 334
     }
335 335
 
336
-    root->ac_root->trans = (struct cli_ac_node **) mp_calloc(root->mempool, 256, sizeof(struct cli_ac_node *));
336
+    root->ac_root->trans = (struct cli_ac_node **) mpool_calloc(root->mempool, 256, sizeof(struct cli_ac_node *));
337 337
     if(!root->ac_root->trans) {
338 338
 	cli_errmsg("cli_ac_init: Can't allocate memory for ac_root->trans\n");
339
-	mp_free(root->mempool, root->ac_root);
339
+	mpool_free(root->mempool, root->ac_root);
340 340
 	return CL_EMEM;
341 341
     }
342 342
 
... ...
@@ -347,10 +347,10 @@ int cli_ac_init(struct cli_matcher *root, uint8_t mindepth, uint8_t maxdepth)
347 347
 }
348 348
 
349 349
 #ifdef USE_MPOOL
350
-#define mp_ac_free_alt(a, b) ac_free_alt(a, b)
351
-static void ac_free_alt(mp_t *mempool, struct cli_ac_patt *p)
350
+#define mpool_ac_free_alt(a, b) ac_free_alt(a, b)
351
+static void ac_free_alt(mpool_t *mempool, struct cli_ac_patt *p)
352 352
 #else
353
-#define mp_ac_free_alt(a, b) ac_free_alt(b)
353
+#define mpool_ac_free_alt(a, b) ac_free_alt(b)
354 354
 static void ac_free_alt(struct cli_ac_patt *p)
355 355
 #endif
356 356
 {
... ...
@@ -367,11 +367,11 @@ static void ac_free_alt(struct cli_ac_patt *p)
367 367
 	    a2 = a1;
368 368
 	    a1 = a1->next;
369 369
 	    if(a2->str)
370
-		mp_free(mempool, a2->str);
371
-	    mp_free(mempool, a2);
370
+		mpool_free(mempool, a2->str);
371
+	    mpool_free(mempool, a2);
372 372
 	}
373 373
     }
374
-    mp_free(mempool, p->alttable);
374
+    mpool_free(mempool, p->alttable);
375 375
 }
376 376
 
377 377
 void cli_ac_free(struct cli_matcher *root)
... ...
@@ -382,28 +382,28 @@ void cli_ac_free(struct cli_matcher *root)
382 382
 
383 383
     for(i = 0; i < root->ac_patterns; i++) {
384 384
 	patt = root->ac_pattable[i];
385
-	mp_free(root->mempool, patt->prefix ? patt->prefix : patt->pattern);
386
-	mp_free(root->mempool, patt->virname);
385
+	mpool_free(root->mempool, patt->prefix ? patt->prefix : patt->pattern);
386
+	mpool_free(root->mempool, patt->virname);
387 387
 	if(patt->offset)
388
-	    mp_free(root->mempool, patt->offset);
388
+	    mpool_free(root->mempool, patt->offset);
389 389
 	if(patt->alt)
390
-	    mp_ac_free_alt(root->mempool, patt);
391
-	mp_free(root->mempool, patt);
390
+	    mpool_ac_free_alt(root->mempool, patt);
391
+	mpool_free(root->mempool, patt);
392 392
     }
393 393
     if(root->ac_pattable)
394
-	mp_free(root->mempool, root->ac_pattable);
394
+	mpool_free(root->mempool, root->ac_pattable);
395 395
 
396 396
     for(i = 0; i < root->ac_nodes; i++) {
397 397
 	if(!IS_LEAF(root->ac_nodetable[i]))
398
-	    mp_free(root->mempool, root->ac_nodetable[i]->trans);
399
-	mp_free(root->mempool, root->ac_nodetable[i]);
398
+	    mpool_free(root->mempool, root->ac_nodetable[i]->trans);
399
+	mpool_free(root->mempool, root->ac_nodetable[i]);
400 400
     }
401 401
 
402 402
     if(root->ac_nodetable)
403
-	mp_free(root->mempool, root->ac_nodetable);
403
+	mpool_free(root->mempool, root->ac_nodetable);
404 404
     if(root->ac_root) {
405
-	mp_free(root->mempool, root->ac_root->trans);
406
-	mp_free(root->mempool, root->ac_root);
405
+	mpool_free(root->mempool, root->ac_root->trans);
406
+	mpool_free(root->mempool, root->ac_root);
407 407
     }
408 408
 }
409 409
 
... ...
@@ -1126,7 +1126,7 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1126 1126
 
1127 1127
     if(strlen(hexsig) / 2 < root->ac_mindepth)
1128 1128
 	return CL_EPATSHORT;
1129
-    if((new = (struct cli_ac_patt *) mp_calloc(root->mempool, 1, sizeof(struct cli_ac_patt))) == NULL)
1129
+    if((new = (struct cli_ac_patt *) mpool_calloc(root->mempool, 1, sizeof(struct cli_ac_patt))) == NULL)
1130 1130
 	return CL_EMEM;
1131 1131
 
1132 1132
     new->rtype = rtype;
... ...
@@ -1146,7 +1146,7 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1146 1146
 
1147 1147
     if(strchr(hexsig, '[')) {
1148 1148
 	if(!(hexcpy = cli_strdup(hexsig))) {
1149
-	    mp_free(root->mempool, new);
1149
+	    mpool_free(root->mempool, new);
1150 1150
 	    return CL_EMEM;
1151 1151
 	}
1152 1152
 
... ...
@@ -1211,14 +1211,14 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1211 1211
 
1212 1212
 	if(error) {
1213 1213
 	    free(hexcpy);
1214
-	    mp_free(root->mempool, new);
1214
+	    mpool_free(root->mempool, new);
1215 1215
 	    return error;
1216 1216
 	}
1217 1217
 
1218 1218
 	hex = cli_strdup(hex);
1219 1219
 	free(hexcpy);
1220 1220
 	if(!hex) {
1221
-	    mp_free(root->mempool, new);
1221
+	    mpool_free(root->mempool, new);
1222 1222
 	    return CL_EMEM;
1223 1223
 	}
1224 1224
     }
... ...
@@ -1229,7 +1229,7 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1229 1229
 	if(hex) {
1230 1230
 	    hexcpy = hex;
1231 1231
 	} else if(!(hexcpy = cli_strdup(hexsig))) {
1232
-	    mp_free(root->mempool, new);
1232
+	    mpool_free(root->mempool, new);
1233 1233
 	    return CL_EMEM;
1234 1234
 	}
1235 1235
 
... ...
@@ -1257,7 +1257,7 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1257 1257
 	    }
1258 1258
 	    *start++ = 0;
1259 1259
 
1260
-	    newalt = (struct cli_ac_alt *) mp_calloc(root->mempool, 1, sizeof(struct cli_ac_alt));
1260
+	    newalt = (struct cli_ac_alt *) mpool_calloc(root->mempool, 1, sizeof(struct cli_ac_alt));
1261 1261
 	    if(!newalt) {
1262 1262
 		cli_errmsg("cli_ac_addsig: Can't allocate newalt\n");
1263 1263
 		error = CL_EMEM;
... ...
@@ -1266,10 +1266,10 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1266 1266
 
1267 1267
 	    new->alt++;
1268 1268
 
1269
-	    newtable = (struct cli_ac_alt **) mp_realloc(root->mempool, new->alttable, new->alt * sizeof(struct cli_ac_alt *));
1269
+	    newtable = (struct cli_ac_alt **) mpool_realloc(root->mempool, new->alttable, new->alt * sizeof(struct cli_ac_alt *));
1270 1270
 	    if(!newtable) {
1271 1271
 		new->alt--;
1272
-		mp_free(root->mempool, newalt);
1272
+		mpool_free(root->mempool, newalt);
1273 1273
 		cli_errmsg("cli_ac_addsig: Can't realloc new->alttable\n");
1274 1274
 		error = CL_EMEM;
1275 1275
 		break;
... ...
@@ -1289,7 +1289,7 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1289 1289
 
1290 1290
 	    if(3 * newalt->num - 1 == (uint16_t) strlen(pt)) {
1291 1291
 		newalt->chmode = 1;
1292
-		newalt->str = (unsigned char *) mp_malloc(root->mempool, newalt->num);
1292
+		newalt->str = (unsigned char *) mpool_malloc(root->mempool, newalt->num);
1293 1293
 		if(!newalt->str) {
1294 1294
 		    cli_errmsg("cli_ac_addsig: Can't allocate newalt->str\n");
1295 1295
 		    error = CL_EMEM;
... ...
@@ -1303,7 +1303,7 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1303 1303
 		    break;
1304 1304
 		}
1305 1305
 
1306
-		if(!(c = cli_mp_hex2str(root->mempool, h))) {
1306
+		if(!(c = cli_mpool_hex2str(root->mempool, h))) {
1307 1307
 		    free(h);
1308 1308
 		    error = CL_EMALFDB;
1309 1309
 		    break;
... ...
@@ -1311,14 +1311,14 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1311 1311
 
1312 1312
 		if(newalt->chmode) {
1313 1313
 		    newalt->str[i] = *c;
1314
-		    mp_free(root->mempool, c);
1314
+		    mpool_free(root->mempool, c);
1315 1315
 		} else {
1316 1316
 		    if(i) {
1317 1317
 			altpt = newalt;
1318 1318
 			while(altpt->next)
1319 1319
 			    altpt = altpt->next;
1320 1320
 
1321
-			altpt->next = (struct cli_ac_alt *) mp_calloc(root->mempool, 1, sizeof(struct cli_ac_alt));
1321
+			altpt->next = (struct cli_ac_alt *) mpool_calloc(root->mempool, 1, sizeof(struct cli_ac_alt));
1322 1322
 			if(!altpt->next) {
1323 1323
 			    cli_errmsg("cli_ac_addsig: Can't allocate altpt->next\n");
1324 1324
 			    error = CL_EMEM;
... ...
@@ -1351,18 +1351,18 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1351 1351
 	if(error) {
1352 1352
 	    if(new->alt) {
1353 1353
 		free(hex);
1354
-		mp_ac_free_alt(root->mempool, new);
1354
+		mpool_ac_free_alt(root->mempool, new);
1355 1355
 	    }
1356
-	    mp_free(root->mempool, new);
1356
+	    mpool_free(root->mempool, new);
1357 1357
 	    return error;
1358 1358
 	}
1359 1359
     }
1360 1360
 
1361
-    new->pattern = cli_mp_hex2ui(root->mempool, hex ? hex : hexsig);
1361
+    new->pattern = cli_mpool_hex2ui(root->mempool, hex ? hex : hexsig);
1362 1362
     if(new->pattern == NULL) {
1363 1363
 	if(new->alt)
1364
-	    mp_ac_free_alt(root->mempool, new);
1365
-	mp_free(root->mempool, new);
1364
+	    mpool_ac_free_alt(root->mempool, new);
1365
+	mpool_free(root->mempool, new);
1366 1366
 	free(hex);
1367 1367
 	return CL_EMALFDB;
1368 1368
     }
... ...
@@ -1410,9 +1410,9 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1410 1410
 
1411 1411
 	if(plen < root->ac_mindepth) {
1412 1412
 	    cli_errmsg("cli_ac_addsig: Can't find a static subpattern of length %u\n", root->ac_mindepth);
1413
-	    mp_ac_free_alt(root->mempool, new);
1414
-	    mp_free(root->mempool, new->pattern);
1415
-	    mp_free(root->mempool, new);
1413
+	    mpool_ac_free_alt(root->mempool, new);
1414
+	    mpool_free(root->mempool, new->pattern);
1415
+	    mpool_free(root->mempool, new);
1416 1416
 	    return CL_EMALFDB;
1417 1417
 	}
1418 1418
 
... ...
@@ -1429,11 +1429,11 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1429 1429
     if(new->length > root->maxpatlen)
1430 1430
 	root->maxpatlen = new->length;
1431 1431
 
1432
-    new->virname = cli_mp_virname(root->mempool, (char *) virname, options & CL_DB_OFFICIAL);
1432
+    new->virname = cli_mpool_virname(root->mempool, (char *) virname, options & CL_DB_OFFICIAL);
1433 1433
     if(!new->virname) {
1434
-	mp_free(root->mempool, new->prefix ? new->prefix : new->pattern);
1435
-	mp_ac_free_alt(root->mempool, new);
1436
-	mp_free(root->mempool, new);
1434
+	mpool_free(root->mempool, new->prefix ? new->prefix : new->pattern);
1435
+	mpool_ac_free_alt(root->mempool, new);
1436
+	mpool_free(root->mempool, new);
1437 1437
 	return CL_EMEM;
1438 1438
     }
1439 1439
 
... ...
@@ -1441,23 +1441,23 @@ int cli_ac_addsig(struct cli_matcher *root, const char *virname, const char *hex
1441 1441
 	root->ac_lsigtable[new->lsigid[1]]->virname = new->virname;
1442 1442
 
1443 1443
     if(offset) {
1444
-	new->offset = cli_mp_strdup(root->mempool, offset);
1444
+	new->offset = cli_mpool_strdup(root->mempool, offset);
1445 1445
 	if(!new->offset) {
1446
-	    mp_free(root->mempool, new->prefix ? new->prefix : new->pattern);
1447
-	    mp_ac_free_alt(root->mempool, new);
1448
-	    mp_free(root->mempool, new->virname);
1449
-	    mp_free(root->mempool, new);
1446
+	    mpool_free(root->mempool, new->prefix ? new->prefix : new->pattern);
1447
+	    mpool_ac_free_alt(root->mempool, new);
1448
+	    mpool_free(root->mempool, new->virname);
1449
+	    mpool_free(root->mempool, new);
1450 1450
 	    return CL_EMEM;
1451 1451
 	}
1452 1452
     }
1453 1453
 
1454 1454
     if((ret = cli_ac_addpatt(root, new))) {
1455
-	mp_free(root->mempool, new->prefix ? new->prefix : new->pattern);
1456
-	mp_free(root->mempool, new->virname);
1457
-	mp_ac_free_alt(root->mempool, new);
1455
+	mpool_free(root->mempool, new->prefix ? new->prefix : new->pattern);
1456
+	mpool_free(root->mempool, new->virname);
1457
+	mpool_ac_free_alt(root->mempool, new);
1458 1458
 	if(new->offset)
1459
-	    mp_free(root->mempool, new->offset);
1460
-	mp_free(root->mempool, new);
1459
+	    mpool_free(root->mempool, new->offset);
1460
+	mpool_free(root->mempool, new);
1461 1461
 	return ret;
1462 1462
     }
1463 1463
 
... ...
@@ -101,11 +101,11 @@ int cli_bm_init(struct cli_matcher *root)
101 101
 #ifdef USE_MPOOL
102 102
     assert (root->mempool && "mempool must be initialized");
103 103
 #endif
104
-    if(!(root->bm_shift = (uint8_t *) mp_calloc(root->mempool, size, sizeof(uint8_t))))
104
+    if(!(root->bm_shift = (uint8_t *) mpool_calloc(root->mempool, size, sizeof(uint8_t))))
105 105
 	return CL_EMEM;
106 106
 
107
-    if(!(root->bm_suffix = (struct cli_bm_patt **) mp_calloc(root->mempool, size, sizeof(struct cli_bm_patt *)))) {
108
-	mp_free(root->mempool, root->bm_shift);
107
+    if(!(root->bm_suffix = (struct cli_bm_patt **) mpool_calloc(root->mempool, size, sizeof(struct cli_bm_patt *)))) {
108
+	mpool_free(root->mempool, root->bm_shift);
109 109
 	return CL_EMEM;
110 110
     }
111 111
 
... ...
@@ -122,7 +122,7 @@ void cli_bm_free(struct cli_matcher *root)
122 122
 
123 123
 
124 124
     if(root->bm_shift)
125
-	mp_free(root->mempool, root->bm_shift);
125
+	mpool_free(root->mempool, root->bm_shift);
126 126
 
127 127
     if(root->bm_suffix) {
128 128
 	for(i = 0; i < size; i++) {
... ...
@@ -131,17 +131,17 @@ void cli_bm_free(struct cli_matcher *root)
131 131
 		prev = patt;
132 132
 		patt = patt->next;
133 133
 		if(prev->prefix)
134
-		    mp_free(root->mempool, prev->prefix);
134
+		    mpool_free(root->mempool, prev->prefix);
135 135
 		else
136
-		    mp_free(root->mempool, prev->pattern);
136
+		    mpool_free(root->mempool, prev->pattern);
137 137
 		if(prev->virname)
138
-		    mp_free(root->mempool, prev->virname);
138
+		    mpool_free(root->mempool, prev->virname);
139 139
 		if(prev->offset)
140
-		    mp_free(root->mempool, prev->offset);
141
-		mp_free(root->mempool, prev);
140
+		    mpool_free(root->mempool, prev->offset);
141
+		mpool_free(root->mempool, prev);
142 142
 	    }
143 143
 	}
144
-	mp_free(root->mempool, root->bm_suffix);
144
+	mpool_free(root->mempool, root->bm_suffix);
145 145
     }
146 146
 }
147 147
 
... ...
@@ -57,7 +57,7 @@ struct cli_lsig_tdb {
57 57
     const uint32_t *sectoff, *sectrva, *sectvsz, *sectraw, *sectrsz,
58 58
 		   *secturva, *sectuvsz, *secturaw, *sectursz;
59 59
 #ifdef USE_MPOOL
60
-    mp_t *mempool;
60
+    mpool_t *mempool;
61 61
 #endif
62 62
 };
63 63
 
... ...
@@ -86,7 +86,7 @@ struct cli_matcher {
86 86
     uint16_t maxpatlen;
87 87
     uint8_t ac_only;
88 88
 #ifdef USE_MPOOL
89
-    mp_t *mempool;
89
+    mpool_t *mempool;
90 90
 #endif
91 91
 };
92 92
 
... ...
@@ -336,7 +336,7 @@ struct FRAG {
336 336
 #define FRAG_OVERHEAD (offsetof(struct FRAG, fake))
337 337
 
338 338
 #define align_to_voidptr(size) (((size) / sizeof(void *) + ((size) % sizeof(void *) != 0)) * sizeof(void *))
339
-#define mp_roundup(size) (FRAG_OVERHEAD + align_to_voidptr(size))
339
+#define mpool_roundup(size) (FRAG_OVERHEAD + align_to_voidptr(size))
340 340
 
341 341
 static unsigned int align_to_pagesize(struct MP *mp, unsigned int size) {
342 342
   return (size / mp->psize + (size % mp->psize != 0)) * mp->psize;
... ...
@@ -353,22 +353,22 @@ static unsigned int from_bits(unsigned int bits) {
353 353
   return fragsz[bits];
354 354
 }
355 355
 
356
-struct MP *mp_create() {
357
-  struct MP mp, *mp_p;
356
+struct MP *mpool_create() {
357
+  struct MP mp, *mpool_p;
358 358
   unsigned int sz;
359 359
   memset(&mp, 0, sizeof(mp));
360 360
   mp.psize = getpagesize();
361 361
   sz = align_to_pagesize(&mp, MIN_FRAGSIZE);
362 362
   mp.mpm.usize = align_to_voidptr(sizeof(struct MPMAP));
363 363
   mp.mpm.size = sz - align_to_voidptr(sizeof(mp));
364
-  if ((mp_p = (struct MP *)mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE|ANONYMOUS_MAP, -1, 0)) == MAP_FAILED)
364
+  if ((mpool_p = (struct MP *)mmap(NULL, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE|ANONYMOUS_MAP, -1, 0)) == MAP_FAILED)
365 365
     return NULL;
366
-  memcpy(mp_p, &mp, sizeof(mp));
367
-  spam("Map created @ %p->%p - size %u out of %u\n", mp_p, (char *)mp_p + mp.mpm.size, mp.mpm.usize, mp.mpm.size);
368
-  return mp_p;
366
+  memcpy(mpool_p, &mp, sizeof(mp));
367
+  spam("Map created @ %p->%p - size %u out of %u\n", mpool_p, (char *)mpool_p + mp.mpm.size, mp.mpm.usize, mp.mpm.size);
368
+  return mpool_p;
369 369
 }
370 370
 
371
-void mp_destroy(struct MP *mp) {
371
+void mpool_destroy(struct MP *mp) {
372 372
   struct MPMAP *mpm_next = mp->mpm.next, *mpm;
373 373
   while((mpm = mpm_next)) {
374 374
     mpm_next = mpm->next;
... ...
@@ -378,7 +378,7 @@ void mp_destroy(struct MP *mp) {
378 378
   spam("Map destroyed @ %p\n", mp);
379 379
 }
380 380
 
381
-void mp_flush(struct MP *mp) {
381
+void mpool_flush(struct MP *mp) {
382 382
   size_t used = 0, mused;
383 383
   struct MPMAP *mpm_next = mp->mpm.next, *mpm;
384 384
   while((mpm = mpm_next)) {
... ...
@@ -396,11 +396,11 @@ void mp_flush(struct MP *mp) {
396 396
   spam("Map flushed @ %p, in use: %lu\n", mp, used);
397 397
 }
398 398
 
399
-int mp_getstats(const struct cl_engine *eng, size_t *used, size_t *total)
399
+int mpool_getstats(const struct cl_engine *eng, size_t *used, size_t *total)
400 400
 {
401 401
 	size_t sum_used = 0, sum_total = 0;
402 402
 	const struct MPMAP *mpm;
403
-	const mp_t *mp;
403
+	const mpool_t *mp;
404 404
 	/* checking refcount is not necessary, but safer */
405 405
 	if (!eng || !eng->refcount)
406 406
 		return -1;
... ...
@@ -416,7 +416,7 @@ int mp_getstats(const struct cl_engine *eng, size_t *used, size_t *total)
416 416
 	return 0;
417 417
 }
418 418
 
419
-void *mp_malloc(struct MP *mp, size_t size) {
419
+void *mpool_malloc(struct MP *mp, size_t size) {
420 420
   unsigned int i, j, needed = align_to_voidptr(size + FRAG_OVERHEAD);
421 421
   const unsigned int sbits = to_bits(needed);
422 422
   struct FRAG *f = NULL;
... ...
@@ -424,13 +424,13 @@ void *mp_malloc(struct MP *mp, size_t size) {
424 424
 
425 425
   /*  check_all(mp); */
426 426
   if (!size || sbits == FRAGSBITS) {
427
-    cli_errmsg("mp_malloc(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", (unsigned long int) size);
427
+    cli_errmsg("mpool_malloc(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", (unsigned long int) size);
428 428
     return NULL;
429 429
   }
430 430
 
431 431
   /* Case 1: We have a free'd frag */
432 432
   if((f = mp->avail[sbits])) {
433
-    spam("malloc %p size %u (freed)\n", f, mp_roundup(size));
433
+    spam("malloc %p size %u (freed)\n", f, mpool_roundup(size));
434 434
     mp->avail[sbits] = f->u.next;
435 435
     f->u.sbits = sbits;
436 436
 #ifdef CL_DEBUG
... ...
@@ -440,7 +440,7 @@ void *mp_malloc(struct MP *mp, size_t size) {
440 440
   }
441 441
 
442 442
   if (!(needed = from_bits(sbits))) {
443
-    cli_errmsg("mp_malloc(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", (unsigned long int) size);
443
+    cli_errmsg("mpool_malloc(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", (unsigned long int) size);
444 444
     return NULL;
445 445
   }
446 446
 
... ...
@@ -448,7 +448,7 @@ void *mp_malloc(struct MP *mp, size_t size) {
448 448
   while(mpm) {
449 449
     if(mpm->size - mpm->usize >= needed) {
450 450
       f = (struct FRAG *)((char *)mpm + mpm->usize);
451
-      spam("malloc %p size %u (hole)\n", f, mp_roundup(size));
451
+      spam("malloc %p size %u (hole)\n", f, mpool_roundup(size));
452 452
       mpm->usize += needed;
453 453
       f->u.sbits = sbits;
454 454
 #ifdef CL_DEBUG
... ...
@@ -466,7 +466,7 @@ void *mp_malloc(struct MP *mp, size_t size) {
466 466
   i = align_to_pagesize(mp, MIN_FRAGSIZE);
467 467
   
468 468
   if ((mpm = (struct MPMAP *)mmap(NULL, i, PROT_READ | PROT_WRITE, MAP_PRIVATE|ANONYMOUS_MAP, -1, 0)) == MAP_FAILED) {
469
-    cli_errmsg("mp_malloc(): Can't allocate memory (%lu bytes).\n", (unsigned long int)i);
469
+    cli_errmsg("mpool_malloc(): Can't allocate memory (%lu bytes).\n", (unsigned long int)i);
470 470
     spam("failed to alloc %u bytes (%u requested)\n", i, size);
471 471
     return NULL;
472 472
   }
... ...
@@ -475,7 +475,7 @@ void *mp_malloc(struct MP *mp, size_t size) {
475 475
   mpm->next = mp->mpm.next;
476 476
   mp->mpm.next = mpm;
477 477
   f = (struct FRAG *)((char *)mpm + align_to_voidptr(sizeof(*mpm)));
478
-  spam("malloc %p size %u (new map)\n", f, mp_roundup(size));
478
+  spam("malloc %p size %u (new map)\n", f, mpool_roundup(size));
479 479
   f->u.sbits = sbits;
480 480
 #ifdef CL_DEBUG
481 481
       f->magic = MPOOLMAGIC;
... ...
@@ -483,13 +483,13 @@ void *mp_malloc(struct MP *mp, size_t size) {
483 483
   return &f->fake;
484 484
 }
485 485
 
486
-void mp_free(struct MP *mp, void *ptr) {
486
+void mpool_free(struct MP *mp, void *ptr) {
487 487
   struct FRAG *f = (struct FRAG *)((char *)ptr - FRAG_OVERHEAD);
488 488
   unsigned int sbits;
489 489
   if (!ptr) return;
490 490
 
491 491
 #ifdef CL_DEBUG
492
-  assert(f->magic == MPOOLMAGIC && "Attempt to mp_free a pointer we did not allocate!");
492
+  assert(f->magic == MPOOLMAGIC && "Attempt to mpool_free a pointer we did not allocate!");
493 493
 #endif
494 494
 
495 495
   sbits = f->u.sbits;
... ...
@@ -498,65 +498,65 @@ void mp_free(struct MP *mp, void *ptr) {
498 498
   spam("free @ %p\n", f);
499 499
 }
500 500
 
501
-void *mp_calloc(struct MP *mp, size_t nmemb, size_t size) {
501
+void *mpool_calloc(struct MP *mp, size_t nmemb, size_t size) {
502 502
   unsigned int needed = nmemb*size;
503 503
   void *ptr;
504 504
 
505 505
   if(!needed) return NULL;
506
-  if((ptr = mp_malloc(mp, needed)))
506
+  if((ptr = mpool_malloc(mp, needed)))
507 507
     memset(ptr, 0, needed);
508 508
   return ptr;
509 509
 }
510 510
 
511
-void *mp_realloc(struct MP *mp, void *ptr, size_t size) {
511
+void *mpool_realloc(struct MP *mp, void *ptr, size_t size) {
512 512
   struct FRAG *f = (struct FRAG *)((char *)ptr - FRAG_OVERHEAD);
513 513
   unsigned int csize, sbits;
514 514
   void *new_ptr;
515
-  if (!ptr) return mp_malloc(mp, size);
515
+  if (!ptr) return mpool_malloc(mp, size);
516 516
 
517 517
   spam("realloc @ %p (size %u -> %u))\n", f, from_bits(f->u.sbits), size);
518 518
   if(!size || !(csize = from_bits(f->u.sbits))) {
519
-    cli_errmsg("mp_realloc(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", (unsigned long int) size);
519
+    cli_errmsg("mpool_realloc(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", (unsigned long int) size);
520 520
     return NULL;
521 521
   }
522 522
   csize -= FRAG_OVERHEAD;
523 523
   if (csize >= size && (!f->u.sbits || from_bits(f->u.sbits-1)-FRAG_OVERHEAD < size))
524 524
     return ptr;
525
-  if (!(new_ptr = mp_malloc(mp, size)))
525
+  if (!(new_ptr = mpool_malloc(mp, size)))
526 526
     return NULL;
527 527
   memcpy(new_ptr, ptr, csize);
528
-  mp_free(mp, ptr);
528
+  mpool_free(mp, ptr);
529 529
   return new_ptr;
530 530
 }
531 531
 
532
-void *mp_realloc2(struct MP *mp, void *ptr, size_t size) {
532
+void *mpool_realloc2(struct MP *mp, void *ptr, size_t size) {
533 533
   struct FRAG *f = (struct FRAG *)((char *)ptr - FRAG_OVERHEAD);
534 534
   unsigned int csize;
535 535
   void *new_ptr;
536
-  if (!ptr) return mp_malloc(mp, size);
536
+  if (!ptr) return mpool_malloc(mp, size);
537 537
 
538 538
   spam("realloc @ %p (size %u -> %u))\n", f, from_bits(f->u.sbits), size);
539 539
   if(!size || !(csize = from_bits(f->u.sbits))) {
540
-    cli_errmsg("mp_realloc2(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", (unsigned long int) size);
541
-    mp_free(mp, ptr);
540
+    cli_errmsg("mpool_realloc2(): Attempt to allocate %lu bytes. Please report to http://bugs.clamav.net\n", (unsigned long int) size);
541
+    mpool_free(mp, ptr);
542 542
     return NULL;
543 543
   }
544 544
   csize -= FRAG_OVERHEAD;
545 545
   if (csize >= size && (!f->u.sbits || from_bits(f->u.sbits-1)-FRAG_OVERHEAD < size))
546 546
     return ptr;
547
-  if ((new_ptr = mp_malloc(mp, size)))
547
+  if ((new_ptr = mpool_malloc(mp, size)))
548 548
     memcpy(new_ptr, ptr, csize);
549
-  mp_free(mp, ptr);
549
+  mpool_free(mp, ptr);
550 550
   return new_ptr;
551 551
 }
552 552
 
553
-unsigned char *cli_mp_hex2str(mp_t *mp, const unsigned char *str)
553
+unsigned char *cli_mpool_hex2str(mpool_t *mp, const unsigned char *str)
554 554
 {
555 555
 	unsigned char *tmp = cli_hex2str(str);
556 556
 	if(tmp) {
557 557
 		unsigned char *res;
558 558
 		unsigned int tmpsz = strlen(str) / 2 + 1;
559
-		if((res = mp_malloc(mp, tmpsz)))
559
+		if((res = mpool_malloc(mp, tmpsz)))
560 560
 			memcpy(res, tmp, tmpsz);
561 561
 		free(tmp);
562 562
 		return res;
... ...
@@ -564,25 +564,25 @@ unsigned char *cli_mp_hex2str(mp_t *mp, const unsigned char *str)
564 564
 	return NULL;
565 565
 }
566 566
 
567
-char *cli_mp_strdup(mp_t *mp, const char *s) {
567
+char *cli_mpool_strdup(mpool_t *mp, const char *s) {
568 568
   char *alloc;
569 569
   unsigned int strsz;
570 570
 
571 571
   if(s == NULL) {
572
-    cli_errmsg("cli_mp_strdup(): s == NULL. Please report to http://bugs.clamav.net\n");
572
+    cli_errmsg("cli_mpool_strdup(): s == NULL. Please report to http://bugs.clamav.net\n");
573 573
     return NULL;
574 574
   }
575 575
 
576 576
   strsz = strlen(s) + 1;
577
-  alloc = mp_malloc(mp, strsz);
577
+  alloc = mpool_malloc(mp, strsz);
578 578
   if(!alloc)
579
-    cli_errmsg("cli_mp_strdup(): Can't allocate memory (%u bytes).\n", (unsigned int) strsz);
579
+    cli_errmsg("cli_mpool_strdup(): Can't allocate memory (%u bytes).\n", (unsigned int) strsz);
580 580
   else
581 581
     memcpy(alloc, s, strsz);
582 582
   return alloc;
583 583
 }
584 584
 
585
-char *cli_mp_virname(mp_t *mp, const char *virname, unsigned int official) {
585
+char *cli_mpool_virname(mpool_t *mp, const char *virname, unsigned int official) {
586 586
   char *newname, *pt;
587 587
   if(!virname)
588 588
     return NULL;
... ...
@@ -596,9 +596,9 @@ char *cli_mp_virname(mp_t *mp, const char *virname, unsigned int official) {
596 596
   }
597 597
 
598 598
   if(official)
599
-    return cli_mp_strdup(mp, virname);
599
+    return cli_mpool_strdup(mp, virname);
600 600
 
601
-  newname = (char *)mp_malloc(mp, strlen(virname) + 11 + 1);
601
+  newname = (char *)mpool_malloc(mp, strlen(virname) + 11 + 1);
602 602
   if(!newname) {
603 603
     cli_errmsg("cli_virname: Can't allocate memory for newname\n");
604 604
     return NULL;
... ...
@@ -608,7 +608,7 @@ char *cli_mp_virname(mp_t *mp, const char *virname, unsigned int official) {
608 608
 }
609 609
 
610 610
 
611
-uint16_t *cli_mp_hex2ui(mp_t *mp, const char *hex) {
611
+uint16_t *cli_mpool_hex2ui(mpool_t *mp, const char *hex) {
612 612
   uint16_t *str;
613 613
   unsigned int len;
614 614
   
... ...
@@ -619,20 +619,20 @@ uint16_t *cli_mp_hex2ui(mp_t *mp, const char *hex) {
619 619
     return NULL;
620 620
   }
621 621
 
622
-  str = mp_calloc(mp, (len / 2) + 1, sizeof(uint16_t));
622
+  str = mpool_calloc(mp, (len / 2) + 1, sizeof(uint16_t));
623 623
   if(!str)
624 624
     return NULL;
625 625
 
626 626
   if(cli_realhex2ui(hex, str, len))
627 627
     return str;
628 628
     
629
-  mp_free(mp, str);
629
+  mpool_free(mp, str);
630 630
   return NULL;
631 631
 }
632 632
 
633 633
 
634 634
 #ifdef DEBUGMPOOL
635
-void mp_stats(struct MP *mp) {
635
+void mpool_stats(struct MP *mp) {
636 636
   unsigned int i=0, ta=0, tu=0;
637 637
   struct MPMAP *mpm = &mp->mpm;
638 638
 
... ...
@@ -665,10 +665,10 @@ void check_all(struct MP *mp) {
665 665
 #else
666 666
 /* dummy definitions to make Solaris linker happy.
667 667
  * these symbols are declared in libclamav.map */
668
-void mp_free() {}
669
-void mp_create() {}
670
-void mp_destroy() {}
671
-void mp_getstats() {}
668
+void mpool_free() {}
669
+void mpool_create() {}
670
+void mpool_destroy() {}
671
+void mpool_getstats() {}
672 672
 
673 673
 #endif /* USE_MPOOL */
674 674
 
... ...
@@ -23,35 +23,35 @@
23 23
 
24 24
 #ifdef USE_MPOOL
25 25
 #include "cltypes.h"
26
-typedef struct MP mp_t;
26
+typedef struct MP mpool_t;
27 27
 
28
-mp_t *mp_create(void);
29
-void mp_destroy(mp_t *mp);
30
-void *mp_malloc(mp_t *mp, size_t size);
31
-void mp_free(mp_t *mp, void *ptr);
32
-void *mp_calloc(mp_t *mp, size_t nmemb, size_t size);
33
-void *mp_realloc(mp_t *mp, void *ptr, size_t size);
34
-void *mp_realloc2(mp_t *mp, void *ptr, size_t size);
35
-unsigned char *cli_mp_hex2str(mp_t* mp, const unsigned char *src);
36
-char *cli_mp_strdup(mp_t *mp, const char *s);
37
-char *cli_mp_virname(mp_t *mp, const char *virname, unsigned int official);
38
-uint16_t *cli_mp_hex2ui(mp_t *mp, const char *hex);
39
-void mp_flush(mp_t *mp);
40
-int mp_getstats(const struct cl_engine *engine, size_t *used, size_t *total);
28
+mpool_t *mpool_create(void);
29
+void mpool_destroy(mpool_t *mpool);
30
+void *mpool_malloc(mpool_t *mpool, size_t size);
31
+void mpool_free(mpool_t *mpool, void *ptr);
32
+void *mpool_calloc(mpool_t *mpool, size_t nmemb, size_t size);
33
+void *mpool_realloc(mpool_t *mpool, void *ptr, size_t size);
34
+void *mpool_realloc2(mpool_t *mpool, void *ptr, size_t size);
35
+unsigned char *cli_mpool_hex2str(mpool_t* mpool, const unsigned char *src);
36
+char *cli_mpool_strdup(mpool_t *mpool, const char *s);
37
+char *cli_mpool_virname(mpool_t *mpool, const char *virname, unsigned int official);
38
+uint16_t *cli_mpool_hex2ui(mpool_t *mpool, const char *hex);
39
+void mpool_flush(mpool_t *mpool);
40
+int mpool_getstats(const struct cl_engine *engine, size_t *used, size_t *total);
41 41
 #else /* USE_MPOOL */
42 42
 
43
-typedef void mp_t;
44
-#define mp_malloc(a, b) cli_malloc(b)
45
-#define mp_free(a, b) free(b)
46
-#define mp_calloc(a, b, c) cli_calloc(b, c)
47
-#define mp_realloc(a, b, c) cli_realloc(b, c)
48
-#define mp_realloc2(a, b, c) cli_realloc2(b, c)
49
-#define cli_mp_hex2str(mp, src) cli_hex2str(src)
50
-#define cli_mp_strdup(mp, s) cli_strdup(s)
51
-#define cli_mp_virname(mp, a, b) cli_virname(a, b)
52
-#define cli_mp_hex2ui(mp, hex) cli_hex2ui(hex)
53
-#define mp_flush(val)
54
-#define mp_getstats(mp,used,total) -1
43
+typedef void mpool_t;
44
+#define mpool_malloc(a, b) cli_malloc(b)
45
+#define mpool_free(a, b) free(b)
46
+#define mpool_calloc(a, b, c) cli_calloc(b, c)
47
+#define mpool_realloc(a, b, c) cli_realloc(b, c)
48
+#define mpool_realloc2(a, b, c) cli_realloc2(b, c)
49
+#define cli_mpool_hex2str(mpool, src) cli_hex2str(src)
50
+#define cli_mpool_strdup(mpool, s) cli_strdup(s)
51
+#define cli_mpool_virname(mpool, a, b) cli_virname(a, b)
52
+#define cli_mpool_hex2ui(mpool, hex) cli_hex2ui(hex)
53
+#define mpool_flush(val)
54
+#define mpool_getstats(mpool,used,total) -1
55 55
 #endif /* USE_MPOOL */
56 56
 
57 57
 #endif
... ...
@@ -228,29 +228,29 @@ struct cl_engine *cl_engine_new(void)
228 228
     new->ac_maxdepth = CLI_DEFAULT_AC_MAXDEPTH;
229 229
 
230 230
 #ifdef USE_MPOOL
231
-    if(!(new->mempool = mp_create())) {
231
+    if(!(new->mempool = mpool_create())) {
232 232
 	cli_errmsg("cl_engine_new: Can't allocate memory for memory pool\n");
233 233
 	free(new);
234 234
 	return NULL;
235 235
     }
236 236
 #endif
237 237
 
238
-    new->root = mp_calloc(new->mempool, CLI_MTARGETS, sizeof(struct cli_matcher *));
238
+    new->root = mpool_calloc(new->mempool, CLI_MTARGETS, sizeof(struct cli_matcher *));
239 239
     if(!new->root) {
240 240
 	cli_errmsg("cl_engine_new: Can't allocate memory for roots\n");
241 241
 #ifdef USE_MPOOL
242
-	mp_destroy(new->mempool);
242
+	mpool_destroy(new->mempool);
243 243
 #endif
244 244
 	free(new);
245 245
 	return NULL;
246 246
     }
247 247
 
248
-    new->dconf = cli_mp_dconf_init(new->mempool);
248
+    new->dconf = cli_mpool_dconf_init(new->mempool);
249 249
     if(!new->dconf) {
250 250
 	cli_errmsg("cl_engine_new: Can't initialize dynamic configuration\n");
251
-	mp_free(new->mempool, new->root);
251
+	mpool_free(new->mempool, new->root);
252 252
 #ifdef USE_MPOOL
253
-	mp_destroy(new->mempool);
253
+	mpool_destroy(new->mempool);
254 254
 #endif
255 255
 	free(new);
256 256
 	return NULL;
... ...
@@ -285,7 +285,7 @@ int cl_engine_set(struct cl_engine *engine, enum cl_engine_field field, const vo
285 285
 	    engine->min_ssn_count = *((const uint32_t *) val);
286 286
 	    break;
287 287
 	case CL_ENGINE_PUA_CATEGORIES:
288
-	    engine->pua_cats = cli_mp_strdup(engine->mempool, (const char *) val);
288
+	    engine->pua_cats = cli_mpool_strdup(engine->mempool, (const char *) val);
289 289
 	    if(!engine->pua_cats)
290 290
 		return CL_EMEM;
291 291
 	    break;
... ...
@@ -303,7 +303,7 @@ int cl_engine_set(struct cl_engine *engine, enum cl_engine_field field, const vo
303 303
 	    engine->ac_maxdepth = *((const uint32_t *) val);
304 304
 	    break;
305 305
 	case CL_ENGINE_TMPDIR:
306
-	    engine->tmpdir = cli_mp_strdup(engine->mempool, (const char *) val);
306
+	    engine->tmpdir = cli_mpool_strdup(engine->mempool, (const char *) val);
307 307
 	    if(!engine->tmpdir)
308 308
 		return CL_EMEM;
309 309
 	    break;
... ...
@@ -169,7 +169,7 @@ struct cl_engine {
169 169
     char *pua_cats;
170 170
 
171 171
     /* Used for memory pools */
172
-    mp_t *mempool;
172
+    mpool_t *mempool;
173 173
 };
174 174
 
175 175
 extern int (*cli_unrar_open)(int fd, const char *dirname, unrar_state_t *state);
... ...
@@ -51,7 +51,7 @@ int whitelist_match(const struct cl_engine* engine,char* real_url,const char* di
51 51
 int init_whitelist(struct cl_engine* engine)
52 52
 {
53 53
 	if(engine) {
54
-		engine->whitelist_matcher = (struct regex_matcher *) mp_malloc(engine->mempool, sizeof(struct regex_matcher));
54
+		engine->whitelist_matcher = (struct regex_matcher *) mpool_malloc(engine->mempool, sizeof(struct regex_matcher));
55 55
 #ifdef USE_MPOOL
56 56
 		((struct regex_matcher *)(engine->whitelist_matcher))->mempool = engine->mempool;
57 57
 #endif
... ...
@@ -72,7 +72,7 @@ void whitelist_done(struct cl_engine* engine)
72 72
 {
73 73
 	if(engine && engine->whitelist_matcher) {
74 74
 		regex_list_done(engine->whitelist_matcher);
75
-		mp_free(engine->mempool, engine->whitelist_matcher);
75
+		mpool_free(engine->mempool, engine->whitelist_matcher);
76 76
 		engine->whitelist_matcher = NULL;
77 77
 	}
78 78
 }
... ...
@@ -855,7 +855,7 @@ int phishing_init(struct cl_engine* engine)
855 855
 {
856 856
 	struct phishcheck* pchk;
857 857
 	if(!engine->phishcheck) {
858
-		pchk = engine->phishcheck = mp_malloc(engine->mempool, sizeof(struct phishcheck));
858
+		pchk = engine->phishcheck = mpool_malloc(engine->mempool, sizeof(struct phishcheck));
859 859
 		if(!pchk)
860 860
 			return CL_EMEM;
861 861
 		pchk->is_disabled=1;
... ...
@@ -873,7 +873,7 @@ int phishing_init(struct cl_engine* engine)
873 873
 	cli_dbgmsg("Initializing phishcheck module\n");
874 874
 
875 875
 	if(build_regex(&pchk->preg_numeric,numeric_url_regex,1)) {
876
-		mp_free(engine->mempool, pchk);
876
+		mpool_free(engine->mempool, pchk);
877 877
 		engine->phishcheck = NULL;
878 878
 		return CL_EFORMAT;
879 879
 	}
... ...
@@ -893,7 +893,7 @@ void phishing_done(struct cl_engine* engine)
893 893
 	domainlist_done(engine);
894 894
 	if(pchk) {
895 895
 		cli_dbgmsg("Freeing phishcheck struct\n");
896
-		mp_free(engine->mempool, pchk);
896
+		mpool_free(engine->mempool, pchk);
897 897
 	}
898 898
 	cli_dbgmsg("Phishcheck cleaned up\n");
899 899
 }
... ...
@@ -252,29 +252,29 @@ int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hex
252 252
 	}
253 253
 
254 254
     } else {
255
-	bm_new = (struct cli_bm_patt *) mp_calloc(root->mempool, 1, sizeof(struct cli_bm_patt));
255
+	bm_new = (struct cli_bm_patt *) mpool_calloc(root->mempool, 1, sizeof(struct cli_bm_patt));
256 256
 	if(!bm_new)
257 257
 	    return CL_EMEM;
258
-        bm_new->pattern = (unsigned char *) cli_mp_hex2str(root->mempool, hexsig);
258
+        bm_new->pattern = (unsigned char *) cli_mpool_hex2str(root->mempool, hexsig);
259 259
 	if(!bm_new->pattern) {
260
-	    mp_free(root->mempool, bm_new);
260
+	    mpool_free(root->mempool, bm_new);
261 261
 	    return CL_EMALFDB;
262 262
 	}
263 263
 	bm_new->length = strlen(hexsig) / 2;
264 264
 
265
-	bm_new->virname = cli_mp_virname(root->mempool, (char *) virname, options & CL_DB_OFFICIAL);
265
+	bm_new->virname = cli_mpool_virname(root->mempool, (char *) virname, options & CL_DB_OFFICIAL);
266 266
 	if(!bm_new->virname) {
267
-	    mp_free(root->mempool, bm_new->pattern);
268
-	    mp_free(root->mempool, bm_new);
267
+	    mpool_free(root->mempool, bm_new->pattern);
268
+	    mpool_free(root->mempool, bm_new);
269 269
 	    return CL_EMEM;
270 270
 	}
271 271
 
272 272
 	if(offset) {
273
-	    bm_new->offset = cli_mp_strdup(root->mempool, offset);
273
+	    bm_new->offset = cli_mpool_strdup(root->mempool, offset);
274 274
 	    if(!bm_new->offset) {
275
-	        mp_free(root->mempool, bm_new->pattern);
276
-		mp_free(root->mempool, bm_new->virname);
277
-		mp_free(root->mempool, bm_new);
275
+	        mpool_free(root->mempool, bm_new->pattern);
276
+		mpool_free(root->mempool, bm_new->virname);
277
+		mpool_free(root->mempool, bm_new);
278 278
 		return CL_EMEM;
279 279
 	    }
280 280
 	}
... ...
@@ -286,9 +286,9 @@ int cli_parse_add(struct cli_matcher *root, const char *virname, const char *hex
286 286
 
287 287
 	if((ret = cli_bm_addpatt(root, bm_new))) {
288 288
 	    cli_errmsg("cli_parse_add(): Problem adding signature (4).\n");
289
-	    mp_free(root->mempool, bm_new->pattern);
290
-	    mp_free(root->mempool, bm_new->virname);
291
-	    mp_free(root->mempool, bm_new);
289
+	    mpool_free(root->mempool, bm_new->pattern);
290
+	    mpool_free(root->mempool, bm_new->virname);
291
+	    mpool_free(root->mempool, bm_new);
292 292
 	    return ret;
293 293
 	}
294 294
     }
... ...
@@ -305,7 +305,7 @@ static int cli_initroots(struct cl_engine *engine, unsigned int options)
305 305
     for(i = 0; i < CLI_MTARGETS; i++) {
306 306
 	if(!engine->root[i]) {
307 307
 	    cli_dbgmsg("Initializing engine->root[%d]\n", i);
308
-	    root = engine->root[i] = (struct cli_matcher *) mp_calloc(engine->mempool, 1, sizeof(struct cli_matcher));
308
+	    root = engine->root[i] = (struct cli_matcher *) mpool_calloc(engine->mempool, 1, sizeof(struct cli_matcher));
309 309
 #ifdef USE_MPOOL
310 310
 	    root->mempool = engine->mempool;
311 311
 #endif
... ...
@@ -690,7 +690,7 @@ static int lsigattribs(char *attribs, struct cli_lsig_tdb *tdb)
690 690
 	switch(apt->type) {
691 691
 	    case CLI_TDB_UINT:
692 692
 		off[i] = cnt = tdb->cnt[CLI_TDB_UINT]++;
693
-		tdb->val = (uint32_t *) mp_realloc2(tdb->mempool, tdb->val, tdb->cnt[CLI_TDB_UINT] * sizeof(uint32_t));
693
+		tdb->val = (uint32_t *) mpool_realloc2(tdb->mempool, tdb->val, tdb->cnt[CLI_TDB_UINT] * sizeof(uint32_t));
694 694
 		if(!tdb->val) {
695 695
 		    tdb->cnt[CLI_TDB_UINT] = 0;
696 696
 		    return -1;
... ...
@@ -706,7 +706,7 @@ static int lsigattribs(char *attribs, struct cli_lsig_tdb *tdb)
706 706
 		*pt2++ = 0;
707 707
 		off[i] = cnt = tdb->cnt[CLI_TDB_RANGE];
708 708
 		tdb->cnt[CLI_TDB_RANGE] += 2;
709
-		tdb->range = (uint32_t *) mp_realloc2(tdb->mempool, tdb->range, tdb->cnt[CLI_TDB_RANGE] * sizeof(uint32_t));
709
+		tdb->range = (uint32_t *) mpool_realloc2(tdb->mempool, tdb->range, tdb->cnt[CLI_TDB_RANGE] * sizeof(uint32_t));
710 710
 		if(!tdb->range) {
711 711
 		    tdb->cnt[CLI_TDB_RANGE] = 0;
712 712
 		    return -1;
... ...
@@ -722,7 +722,7 @@ static int lsigattribs(char *attribs, struct cli_lsig_tdb *tdb)
722 722
 		}
723 723
 		off[i] = cnt = tdb->cnt[CLI_TDB_RANGE];
724 724
 		tdb->cnt[CLI_TDB_RANGE] += 3;
725
-		tdb->range = (uint32_t *) mp_realloc2(tdb->mempool, tdb->range, tdb->cnt[CLI_TDB_RANGE] * sizeof(uint32_t));
725
+		tdb->range = (uint32_t *) mpool_realloc2(tdb->mempool, tdb->range, tdb->cnt[CLI_TDB_RANGE] * sizeof(uint32_t));
726 726
 		if(!tdb->range) {
727 727
 		    tdb->cnt[CLI_TDB_RANGE] = 0;
728 728
 		    return -1;
... ...
@@ -739,7 +739,7 @@ static int lsigattribs(char *attribs, struct cli_lsig_tdb *tdb)
739 739
 	    case CLI_TDB_STR:
740 740
 		off[i] = cnt = tdb->cnt[CLI_TDB_STR];
741 741
 		tdb->cnt[CLI_TDB_STR] += strlen(pt) + 1;
742
-		tdb->str = (char *) mp_realloc2(tdb->mempool, tdb->str, tdb->cnt[CLI_TDB_STR] * sizeof(char));
742
+		tdb->str = (char *) mpool_realloc2(tdb->mempool, tdb->str, tdb->cnt[CLI_TDB_STR] * sizeof(char));
743 743
 		if(!tdb->str) {
744 744
 		    cli_errmsg("lsigattribs: Can't allocate memory for tdb->str\n");
745 745
 		    return -1;
... ...
@@ -785,11 +785,11 @@ static int lsigattribs(char *attribs, struct cli_lsig_tdb *tdb)
785 785
 
786 786
 #define FREE_TDB(x) do {		\
787 787
   if(x.cnt[CLI_TDB_UINT])		\
788
-    mp_free(x.mempool, x.val);		\
788
+    mpool_free(x.mempool, x.val);		\
789 789
   if(x.cnt[CLI_TDB_RANGE])		\
790
-    mp_free(x.mempool, x.range);	\
790
+    mpool_free(x.mempool, x.range);	\
791 791
   if(x.cnt[CLI_TDB_STR])		\
792
-    mp_free(x.mempool, x.str);		\
792
+    mpool_free(x.mempool, x.str);		\
793 793
   } while(0);
794 794
 
795 795
 #define LDB_TOKENS 67
... ...
@@ -883,7 +883,7 @@ static int cli_loadldb(FILE *fs, struct cl_engine *engine, unsigned int *signo,
883 883
 
884 884
 	root = engine->root[tdb.target[0]];
885 885
 
886
-	lsig = (struct cli_ac_lsig *) mp_calloc(engine->mempool, 1, sizeof(struct cli_ac_lsig));
886
+	lsig = (struct cli_ac_lsig *) mpool_calloc(engine->mempool, 1, sizeof(struct cli_ac_lsig));
887 887
 	if(!lsig) {
888 888
 	    cli_errmsg("cli_loadldb: Can't allocate memory for lsig\n");
889 889
 	    FREE_TDB(tdb);
... ...
@@ -891,12 +891,12 @@ static int cli_loadldb(FILE *fs, struct cl_engine *engine, unsigned int *signo,
891 891
 	    break;
892 892
 	}
893 893
 
894
-	lsig->logic = cli_mp_strdup(engine->mempool, logic);
894
+	lsig->logic = cli_mpool_strdup(engine->mempool, logic);
895 895
 	if(!lsig->logic) {
896 896
 	    cli_errmsg("cli_loadldb: Can't allocate memory for lsig->logic\n");
897 897
 	    FREE_TDB(tdb);
898 898
 	    ret = CL_EMEM;
899
-	    mp_free(engine->mempool, lsig);
899
+	    mpool_free(engine->mempool, lsig);
900 900
 	    break;
901 901
 	}
902 902
 
... ...
@@ -904,12 +904,12 @@ static int cli_loadldb(FILE *fs, struct cl_engine *engine, unsigned int *signo,
904 904
 	memcpy(&lsig->tdb, &tdb, sizeof(tdb));
905 905
 
906 906
 	root->ac_lsigs++;
907
-	newtable = (struct cli_ac_lsig **) mp_realloc(engine->mempool, root->ac_lsigtable, root->ac_lsigs * sizeof(struct cli_ac_lsig *));
907
+	newtable = (struct cli_ac_lsig **) mpool_realloc(engine->mempool, root->ac_lsigtable, root->ac_lsigs * sizeof(struct cli_ac_lsig *));
908 908
 	if(!newtable) {
909 909
 	    root->ac_lsigs--;
910 910
 	    cli_errmsg("cli_loadldb: Can't realloc root->ac_lsigtable\n");
911 911
 	    FREE_TDB(tdb);
912
-	    mp_free(engine->mempool, lsig);
912
+	    mpool_free(engine->mempool, lsig);
913 913
 	    ret = CL_EMEM;
914 914
 	    break;
915 915
 	}
... ...
@@ -1027,25 +1027,25 @@ static int cli_loadftm(FILE *fs, struct cl_engine *engine, unsigned int options,
1027 1027
 		break;
1028 1028
 
1029 1029
 	} else if(atoi(tokens[0]) == 0) { /* memcmp() */
1030
-	    new = (struct cli_ftype *) mp_malloc(engine->mempool, sizeof(struct cli_ftype));
1030
+	    new = (struct cli_ftype *) mpool_malloc(engine->mempool, sizeof(struct cli_ftype));
1031 1031
 	    if(!new) {
1032 1032
 		ret = CL_EMEM;
1033 1033
 		break;
1034 1034
 	    }
1035 1035
 	    new->type = type;
1036 1036
 	    new->offset = atoi(tokens[1]);
1037
-	    new->magic = (unsigned char *) cli_mp_hex2str(engine->mempool, tokens[2]);
1037
+	    new->magic = (unsigned char *) cli_mpool_hex2str(engine->mempool, tokens[2]);
1038 1038
 	    if(!new->magic) {
1039 1039
 		cli_errmsg("cli_loadftm: Can't decode the hex string\n");
1040 1040
 		ret = CL_EMALFDB;
1041
-		mp_free(engine->mempool, new);
1041
+		mpool_free(engine->mempool, new);
1042 1042
 		break;
1043 1043
 	    }
1044 1044
 	    new->length = strlen(tokens[2]) / 2;
1045
-	    new->tname = cli_mp_strdup(engine->mempool, tokens[3]);
1045
+	    new->tname = cli_mpool_strdup(engine->mempool, tokens[3]);
1046 1046
 	    if(!new->tname) {
1047
-		mp_free(engine->mempool, new->magic);
1048
-		mp_free(engine->mempool, new);
1047
+		mpool_free(engine->mempool, new->magic);
1048
+		mpool_free(engine->mempool, new);
1049 1049
 		ret = CL_EMEM;
1050 1050
 		break;
1051 1051
 	    }
... ...
@@ -1098,16 +1098,16 @@ static int cli_loadign(FILE *fs, struct cl_engine *engine, unsigned int options,
1098 1098
 	    break;
1099 1099
 	}
1100 1100
 
1101
-	new = (struct cli_ignsig *) mp_calloc(engine->mempool, 1, sizeof(struct cli_ignsig));
1101
+	new = (struct cli_ignsig *) mpool_calloc(engine->mempool, 1, sizeof(struct cli_ignsig));
1102 1102
 	if(!new) {
1103 1103
 	    ret = CL_EMEM;
1104 1104
 	    break;
1105 1105
 	}
1106 1106
 
1107
-	new->dbname = cli_mp_strdup(engine->mempool, tokens[0]);
1107
+	new->dbname = cli_mpool_strdup(engine->mempool, tokens[0]);
1108 1108
 
1109 1109
 	if(!new->dbname) {
1110
-	    mp_free(engine->mempool, new);
1110
+	    mpool_free(engine->mempool, new);
1111 1111
 	    ret = CL_EMALFDB;
1112 1112
 	    break;
1113 1113
 	}
... ...
@@ -1117,10 +1117,10 @@ static int cli_loadign(FILE *fs, struct cl_engine *engine, unsigned int options,
1117 1117
 	if((ret = hashset_addkey(&engine->ignored->hs, new->line)))
1118 1118
 	    break;
1119 1119
 
1120
-	new->signame = cli_mp_strdup(engine->mempool, tokens[2]);
1120
+	new->signame = cli_mpool_strdup(engine->mempool, tokens[2]);
1121 1121
 	if(!new->signame) {
1122
-	    mp_free(engine->mempool, new->dbname);
1123
-	    mp_free(engine->mempool, new);
1122
+	    mpool_free(engine->mempool, new->dbname);
1123
+	    mpool_free(engine->mempool, new);
1124 1124
 	    ret = CL_EMALFDB;
1125 1125
 	    break;
1126 1126
 	}
... ...
@@ -1146,9 +1146,9 @@ static void cli_freeign(struct cl_engine *engine)
1146 1146
 	while(ignored->list) {
1147 1147
 	    pt = ignored->list;
1148 1148
 	    ignored->list = ignored->list->next;
1149
-	    mp_free(engine->mempool, pt->dbname);
1150
-	    mp_free(engine->mempool, pt->signame);
1151
-	    mp_free(engine->mempool,pt);
1149
+	    mpool_free(engine->mempool, pt->dbname);
1150
+	    mpool_free(engine->mempool, pt->signame);
1151
+	    mpool_free(engine->mempool,pt);
1152 1152
 	}
1153 1153
 	hashset_destroy(&ignored->hs);
1154 1154
 	free(engine->ignored);
... ...
@@ -1172,11 +1172,11 @@ static int cli_md5db_init(struct cl_engine *engine, unsigned int mode)
1172 1172
 
1173 1173
 
1174 1174
     if(mode == MD5_HDB) {
1175
-	bm = engine->md5_hdb = (struct cli_matcher *) mp_calloc(engine->mempool, sizeof(struct cli_matcher), 1);
1175
+	bm = engine->md5_hdb = (struct cli_matcher *) mpool_calloc(engine->mempool, sizeof(struct cli_matcher), 1);
1176 1176
     } else if(mode == MD5_MDB) {
1177
-	bm = engine->md5_mdb = (struct cli_matcher *) mp_calloc(engine->mempool, sizeof(struct cli_matcher), 1);
1177
+	bm = engine->md5_mdb = (struct cli_matcher *) mpool_calloc(engine->mempool, sizeof(struct cli_matcher), 1);
1178 1178
     } else {
1179
-	bm = engine->md5_fp = (struct cli_matcher *) mp_calloc(engine->mempool, sizeof(struct cli_matcher), 1);
1179
+	bm = engine->md5_fp = (struct cli_matcher *) mpool_calloc(engine->mempool, sizeof(struct cli_matcher), 1);
1180 1180
     }
1181 1181
 
1182 1182
     if(!bm)
... ...
@@ -1235,16 +1235,16 @@ static int cli_loadmd5(FILE *fs, struct cl_engine *engine, unsigned int *signo,
1235 1235
 	if(engine->ignored && cli_chkign(engine->ignored, dbname, line, pt))
1236 1236
 	    continue;
1237 1237
 
1238
-	new = (struct cli_bm_patt *) mp_calloc(engine->mempool, 1, sizeof(struct cli_bm_patt));
1238
+	new = (struct cli_bm_patt *) mpool_calloc(engine->mempool, 1, sizeof(struct cli_bm_patt));
1239 1239
 	if(!new) {
1240 1240
 	    ret = CL_EMEM;
1241 1241
 	    break;
1242 1242
 	}
1243 1243
 
1244 1244
 	pt = tokens[md5_field]; /* md5 */
1245
-	if(strlen(pt) != 32 || !(new->pattern = (unsigned char *) cli_mp_hex2str(engine->mempool, pt))) {
1245
+	if(strlen(pt) != 32 || !(new->pattern = (unsigned char *) cli_mpool_hex2str(engine->mempool, pt))) {
1246 1246
 	    cli_errmsg("cli_loadmd5: Malformed MD5 string at line %u\n", line);
1247
-	    mp_free(engine->mempool, new);
1247
+	    mpool_free(engine->mempool, new);
1248 1248
 	    ret = CL_EMALFDB;
1249 1249
 	    break;
1250 1250
 	}
... ...
@@ -1252,19 +1252,19 @@ static int cli_loadmd5(FILE *fs, struct cl_engine *engine, unsigned int *signo,
1252 1252
 
1253 1253
 	size = atoi(tokens[size_field]);
1254 1254
 
1255
-	new->virname = cli_mp_virname(engine->mempool, (char *) tokens[2], options & CL_DB_OFFICIAL);
1255
+	new->virname = cli_mpool_virname(engine->mempool, (char *) tokens[2], options & CL_DB_OFFICIAL);
1256 1256
 	if(!new->virname) {
1257
-	    mp_free(engine->mempool, new->pattern);
1258
-	    mp_free(engine->mempool, new);
1257
+	    mpool_free(engine->mempool, new->pattern);
1258
+	    mpool_free(engine->mempool, new);
1259 1259
 	    ret = CL_EMALFDB;
1260 1260
 	    break;
1261 1261
 	}
1262 1262
 
1263 1263
 	MD5_DB;
1264 1264
 	if(!db && (ret = cli_md5db_init(engine, mode))) {
1265
-	    mp_free(engine->mempool, new->pattern);
1266
-	    mp_free(engine->mempool, new->virname);
1267
-	    mp_free(engine->mempool, new);
1265
+	    mpool_free(engine->mempool, new->pattern);
1266
+	    mpool_free(engine->mempool, new->virname);
1267
+	    mpool_free(engine->mempool, new);
1268 1268
 	    break;
1269 1269
 	} else {
1270 1270
 	    MD5_DB;
... ...
@@ -1272,9 +1272,9 @@ static int cli_loadmd5(FILE *fs, struct cl_engine *engine, unsigned int *signo,
1272 1272
 
1273 1273
 	if((ret = cli_bm_addpatt(db, new))) {
1274 1274
 	    cli_errmsg("cli_loadmd5: Error adding BM pattern\n");
1275
-	    mp_free(engine->mempool, new->pattern);
1276
-	    mp_free(engine->mempool, new->virname);
1277
-	    mp_free(engine->mempool, new);
1275
+	    mpool_free(engine->mempool, new->pattern);
1276
+	    mpool_free(engine->mempool, new->virname);
1277
+	    mpool_free(engine->mempool, new);
1278 1278
 	    break;
1279 1279
 	}
1280 1280
 
... ...
@@ -1326,35 +1326,35 @@ static int cli_loadmd(FILE *fs, struct cl_engine *engine, unsigned int *signo, i
1326 1326
 	    break;
1327 1327
 	}
1328 1328
 
1329
-	new = (struct cli_meta_node *) mp_calloc(engine->mempool, 1, sizeof(struct cli_meta_node));
1329
+	new = (struct cli_meta_node *) mpool_calloc(engine->mempool, 1, sizeof(struct cli_meta_node));
1330 1330
 	if(!new) {
1331 1331
 	    ret = CL_EMEM;
1332 1332
 	    break;
1333 1333
 	}
1334 1334
 
1335
-	new->virname = cli_mp_virname(engine->mempool, (char *)tokens[0], options & CL_DB_OFFICIAL);
1335
+	new->virname = cli_mpool_virname(engine->mempool, (char *)tokens[0], options & CL_DB_OFFICIAL);
1336 1336
 	if(!new->virname) {
1337
-	    mp_free(engine->mempool, new);
1337
+	    mpool_free(engine->mempool, new);
1338 1338
 	    ret = CL_EMEM;
1339 1339
 	    break;
1340 1340
 	}
1341 1341
 
1342 1342
 	if(engine->ignored && cli_chkign(engine->ignored, dbname, line, new->virname)) {
1343
-	    mp_free(engine->mempool, new->virname);
1344
-	    mp_free(engine->mempool, new);
1343
+	    mpool_free(engine->mempool, new->virname);
1344
+	    mpool_free(engine->mempool, new);
1345 1345
 	    continue;
1346 1346
 	}
1347 1347
 
1348 1348
 	new->encrypted = atoi(tokens[1]);
1349
-	new->filename = cli_mp_strdup(engine->mempool, tokens[2]);
1349
+	new->filename = cli_mpool_strdup(engine->mempool, tokens[2]);
1350 1350
 	if(!new->filename) {
1351
-	    mp_free(engine->mempool, new->virname);
1352
-	    mp_free(engine->mempool, new);
1351
+	    mpool_free(engine->mempool, new->virname);
1352
+	    mpool_free(engine->mempool, new);
1353 1353
 	    ret = CL_EMALFDB;
1354 1354
 	    break;
1355 1355
 	} else {
1356 1356
 	    if(!strcmp(new->filename, "*")) {
1357
-	        mp_free(engine->mempool, new->filename);
1357
+	        mpool_free(engine->mempool, new->filename);
1358 1358
 		new->filename = NULL;
1359 1359
 	    }
1360 1360
 	}
... ...
@@ -1916,72 +1916,72 @@ int cl_engine_free(struct cl_engine *engine)
1916 1916
 		cli_ac_free(root);
1917 1917
 		if(root->ac_lsigtable) {
1918 1918
 		    for(j = 0; j < root->ac_lsigs; j++) {
1919
-			mp_free(engine->mempool, root->ac_lsigtable[j]->logic);
1919
+			mpool_free(engine->mempool, root->ac_lsigtable[j]->logic);
1920 1920
 			FREE_TDB(root->ac_lsigtable[j]->tdb);
1921
-			mp_free(engine->mempool, root->ac_lsigtable[j]);
1921
+			mpool_free(engine->mempool, root->ac_lsigtable[j]);
1922 1922
 		    }
1923
-		    mp_free(engine->mempool, root->ac_lsigtable);
1923
+		    mpool_free(engine->mempool, root->ac_lsigtable);
1924 1924
 		}
1925
-		mp_free(engine->mempool, root);
1925
+		mpool_free(engine->mempool, root);
1926 1926
 	    }
1927 1927
 	}
1928
-	mp_free(engine->mempool, engine->root);
1928
+	mpool_free(engine->mempool, engine->root);
1929 1929
     }
1930 1930
 
1931 1931
     if((root = engine->md5_hdb)) {
1932 1932
 	cli_bm_free(root);
1933
-	mp_free(engine->mempool, root);
1933
+	mpool_free(engine->mempool, root);
1934 1934
     }
1935 1935
 
1936 1936
     if((root = engine->md5_mdb)) {
1937 1937
 	cli_bm_free(root);
1938
-	mp_free(engine->mempool, root->soff);
1938
+	mpool_free(engine->mempool, root->soff);
1939 1939
 	if(root->md5_sizes_hs.capacity) {
1940 1940
 		hashset_destroy(&root->md5_sizes_hs);
1941 1941
 	}
1942
-	mp_free(engine->mempool, root);
1942
+	mpool_free(engine->mempool, root);
1943 1943
     }
1944 1944
 
1945 1945
     if((root = engine->md5_fp)) {
1946 1946
 	cli_bm_free(root);
1947
-	mp_free(engine->mempool, root);
1947
+	mpool_free(engine->mempool, root);
1948 1948
     }
1949 1949
 
1950 1950
     metapt = engine->zip_mlist;
1951 1951
     while(metapt) {
1952 1952
 	metah = metapt;
1953 1953
 	metapt = metapt->next;
1954
-	mp_free(engine->mempool, metah->virname);
1954
+	mpool_free(engine->mempool, metah->virname);
1955 1955
 	if(metah->filename)
1956
-	    mp_free(engine->mempool, metah->filename);
1957
-	mp_free(engine->mempool, metah);
1956
+	    mpool_free(engine->mempool, metah->filename);
1957
+	mpool_free(engine->mempool, metah);
1958 1958
     }
1959 1959
 
1960 1960
     metapt = engine->rar_mlist;
1961 1961
     while(metapt) {
1962 1962
 	metah = metapt;
1963 1963
 	metapt = metapt->next;
1964
-	mp_free(engine->mempool, metah->virname);
1964
+	mpool_free(engine->mempool, metah->virname);
1965 1965
 	if(metah->filename)
1966
-	    mp_free(engine->mempool, metah->filename);
1967
-	mp_free(engine->mempool, metah);
1966
+	    mpool_free(engine->mempool, metah->filename);
1967
+	mpool_free(engine->mempool, metah);
1968 1968
     }
1969 1969
 
1970 1970
     if(engine->dconf->phishing & PHISHING_CONF_ENGINE)
1971 1971
 	phishing_done(engine);
1972 1972
     if(engine->dconf)
1973
-	mp_free(engine->mempool, engine->dconf);
1973
+	mpool_free(engine->mempool, engine->dconf);
1974 1974
 
1975 1975
     if(engine->pua_cats)
1976
-	mp_free(engine->mempool, engine->pua_cats);
1976
+	mpool_free(engine->mempool, engine->pua_cats);
1977 1977
 
1978 1978
     if(engine->tmpdir)
1979
-	mp_free(engine->mempool, engine->tmpdir);
1979
+	mpool_free(engine->mempool, engine->tmpdir);
1980 1980
 
1981 1981
     cli_ftfree(engine);
1982 1982
     cli_freeign(engine);
1983 1983
 #ifdef USE_MPOOL
1984
-    if(engine->mempool) mp_destroy(engine->mempool);
1984
+    if(engine->mempool) mpool_destroy(engine->mempool);
1985 1985
 #endif
1986 1986
     free(engine);
1987 1987
     return CL_SUCCESS;
... ...
@@ -1997,7 +1997,7 @@ static void cli_md5db_build(struct cli_matcher* root)
1997 1997
 		{
1998 1998
 		uint32_t *mpoolht;
1999 1999
 		unsigned int mpoolhtsz = root->md5_sizes_hs.count * sizeof(*mpoolht);
2000
-		root->soff = mp_malloc(root->mempool, mpoolhtsz);
2000
+		root->soff = mpool_malloc(root->mempool, mpoolhtsz);
2001 2001
 		root->soff_len = hashset_toarray(&root->md5_sizes_hs, &mpoolht);
2002 2002
 		memcpy(root->soff, mpoolht, mpoolhtsz);
2003 2003
 		free(mpoolht);
... ...
@@ -2041,7 +2041,7 @@ int cl_engine_compile(struct cl_engine *engine)
2041 2041
     cli_md5db_build(engine->md5_mdb);
2042 2042
     cli_freeign(engine);
2043 2043
     cli_dconf_print(engine->dconf);
2044
-    mp_flush(engine->mempool);
2044
+    mpool_flush(engine->mempool);
2045 2045
 
2046 2046
     return CL_SUCCESS;
2047 2047
 }
... ...
@@ -343,7 +343,7 @@ int regex_list_match(struct regex_matcher* matcher,char* real_url,const char* di
343 343
 int init_regex_list(struct regex_matcher* matcher)
344 344
 {
345 345
 #ifdef USE_MPOOL
346
-	mp_t *mp = matcher->mempool;
346
+	mpool_t *mp = matcher->mempool;
347 347
 #endif
348 348
 	int rc;
349 349
 
... ...
@@ -419,14 +419,14 @@ static int functionality_level_check(char* line)
419 419
 static int add_hash(struct regex_matcher *matcher, char* pattern, const char fl)
420 420
 {
421 421
 	int rc;
422
-	struct cli_bm_patt *pat = mp_calloc(matcher->mempool, 1, sizeof(*pat));
422
+	struct cli_bm_patt *pat = mpool_calloc(matcher->mempool, 1, sizeof(*pat));
423 423
 	if(!pat)
424 424
 		return CL_EMEM;
425
-	pat->pattern = (unsigned char*)cli_mp_hex2str(matcher->mempool, pattern);
425
+	pat->pattern = (unsigned char*)cli_mpool_hex2str(matcher->mempool, pattern);
426 426
 	if(!pat->pattern)
427 427
 		return CL_EMALFDB;
428 428
 	pat->length = 16;
429
-	pat->virname = mp_malloc(matcher->mempool, 1);
429
+	pat->virname = mpool_malloc(matcher->mempool, 1);
430 430
 	if(!pat->virname) {
431 431
 		free(pat);
432 432
 		return CL_EMEM;
... ...
@@ -591,9 +591,9 @@ void regex_list_done(struct regex_matcher* matcher)
591 591
 			for(i=0;i<matcher->regex_cnt;i++) {
592 592
 				regex_t *r = matcher->all_pregs[i];
593 593
 				cli_regfree(r);
594
-				mp_free(matcher->mempool, r);
594
+				mpool_free(matcher->mempool, r);
595 595
 			}
596
-			mp_free(matcher->mempool, matcher->all_pregs);
596
+			mpool_free(matcher->mempool, matcher->all_pregs);
597 597
 		}
598 598
 		hashtab_free(&matcher->suffix_hash);
599 599
 		cli_bm_free(&matcher->md5_hashes);
... ...
@@ -609,7 +609,7 @@ int is_regex_ok(struct regex_matcher* matcher)
609 609
 static int add_newsuffix(struct regex_matcher *matcher, struct regex_list *info, const char *suffix, size_t len)
610 610
 {
611 611
 	struct cli_matcher *root = &matcher->suffixes;
612
-	struct cli_ac_patt *new = mp_calloc(matcher->mempool,1,sizeof(*new));
612
+	struct cli_ac_patt *new = mpool_calloc(matcher->mempool,1,sizeof(*new));
613 613
 	size_t i;
614 614
 	int ret;
615 615
 
... ...
@@ -631,9 +631,9 @@ static int add_newsuffix(struct regex_matcher *matcher, struct regex_list *info,
631 631
 	if(new->length > root->maxpatlen)
632 632
 		root->maxpatlen = new->length;
633 633
 
634
-	new->pattern = mp_malloc(matcher->mempool, sizeof(new->pattern[0])*len);
634
+	new->pattern = mpool_malloc(matcher->mempool, sizeof(new->pattern[0])*len);
635 635
 	if(!new->pattern) {
636
-		mp_free(matcher->mempool, new);
636
+		mpool_free(matcher->mempool, new);
637 637
 		return CL_EMEM;
638 638
 	}
639 639
 	for(i=0;i<len;i++)
... ...
@@ -642,8 +642,8 @@ static int add_newsuffix(struct regex_matcher *matcher, struct regex_list *info,
642 642
 	new->customdata = info;
643 643
 	new->virname = NULL;
644 644
 	if((ret = cli_ac_addpatt(root,new))) {
645
-		mp_free(matcher->mempool, new->pattern);
646
-		mp_free(matcher->mempool, new);
645
+		mpool_free(matcher->mempool, new->pattern);
646
+		mpool_free(matcher->mempool, new);
647 647
 		return ret;
648 648
 	}
649 649
 	SO_preprocess_add(&matcher->filter, (const unsigned char*)suffix, len);
... ...
@@ -714,10 +714,10 @@ static size_t reverse_string(char *pattern)
714 714
 static regex_t *new_preg(struct regex_matcher *matcher)
715 715
 {
716 716
 	regex_t *r;
717
-	matcher->all_pregs = mp_realloc(matcher->mempool, matcher->all_pregs, ++matcher->regex_cnt * sizeof(*matcher->all_pregs));
717
+	matcher->all_pregs = mpool_realloc(matcher->mempool, matcher->all_pregs, ++matcher->regex_cnt * sizeof(*matcher->all_pregs));
718 718
 	if(!matcher->all_pregs)
719 719
 		return NULL;
720
-	r = mp_malloc(matcher->mempool, sizeof(*r));
720
+	r = mpool_malloc(matcher->mempool, sizeof(*r));
721 721
 	if(!r)
722 722
 		return NULL;
723 723
 	matcher->all_pregs[matcher->regex_cnt-1] = r;
... ...
@@ -54,7 +54,7 @@ struct regex_matcher {
54 54
 	struct filter md5_filter;
55 55
 	struct filter filter;
56 56
 #ifdef USE_MPOOL
57
-	mp_t *mempool;
57
+	mpool_t *mempool;
58 58
 #endif
59 59
 	int list_inited:2;
60 60
 	int list_loaded:2;
... ...
@@ -191,7 +191,6 @@ GENHTML = @GENHTML@
191 191
 GETENT = @GETENT@
192 192
 GPERF = @GPERF@
193 193
 GREP = @GREP@
194
-HAVE_LIBGMP = @HAVE_LIBGMP@
195 194
 INCLTDL = @INCLTDL@
196 195
 INSTALL = @INSTALL@
197 196
 INSTALL_DATA = @INSTALL_DATA@
... ...
@@ -209,8 +208,6 @@ LIBBZ2 = @LIBBZ2@
209 209
 LIBBZ2_PREFIX = @LIBBZ2_PREFIX@
210 210
 LIBCLAMAV_LIBS = @LIBCLAMAV_LIBS@
211 211
 LIBCLAMAV_VERSION = @LIBCLAMAV_VERSION@
212
-LIBGMP = @LIBGMP@
213
-LIBGMP_PREFIX = @LIBGMP_PREFIX@
214 212
 LIBLTDL = @LIBLTDL@
215 213
 LIBOBJS = @LIBOBJS@
216 214
 LIBS = @LIBS@
... ...
@@ -221,7 +218,6 @@ LTDLDEPS = @LTDLDEPS@
221 221
 LTDLINCL = @LTDLINCL@
222 222
 LTDLOPEN = @LTDLOPEN@
223 223
 LTLIBBZ2 = @LTLIBBZ2@
224
-LTLIBGMP = @LTLIBGMP@
225 224
 LTLIBOBJS = @LTLIBOBJS@
226 225
 LT_CONFIG_H = @LT_CONFIG_H@
227 226
 LT_DLLOADERS = @LT_DLLOADERS@
... ...
@@ -43,14 +43,12 @@
43 43
 
44 44
 #include "zlib.h"
45 45
 
46
-#ifdef HAVE_LIBGMP
47 46
 #include "libclamav/dsig.h"
48 47
 
49 48
 #define PSS_NSTR "14783905874077467090262228516557917570254599638376203532031989214105552847269687489771975792123442185817287694951949800908791527542017115600501303394778618535864845235700041590056318230102449612217458549016089313306591388590790796515819654102320725712300822356348724011232654837503241736177907784198700834440681124727060540035754699658105895050096576226753008596881698828185652424901921668758326578462003247906470982092298106789657211905488986281078346361469524484829559560886227198091995498440676639639830463593211386055065360288422394053998134458623712540683294034953818412458362198117811990006021989844180721010947"
50 49
 #define PSS_ESTR "100002053"
51 50
 #define PSS_NBITS 2048
52 51
 #define PSS_DIGEST_LENGTH 32
53
-#endif /* HAVE_LIBGMP */
54 52
 
55 53
 struct cdiff_node {
56 54
     unsigned int lineno;
... ...
@@ -766,7 +764,6 @@ static int cdiff_execute(const char *cmdstr, struct cdiff_ctx *ctx)
766 766
     return 0;
767 767
 }
768 768
 
769
-#ifdef HAVE_LIBGMP
770 769
 static void pss_mgf(unsigned char *in, unsigned int inlen, unsigned char *out, unsigned int outlen)
771 770
 {
772 771
 	SHA256_CTX ctx;
... ...
@@ -797,7 +794,7 @@ static void pss_mgf(unsigned char *in, unsigned int inlen, unsigned char *out, u
797 797
 
798 798
 static int pss_versig(const unsigned char *sha256, const char *dsig)
799 799
 {
800
-	mpz_t n, e;
800
+	mp_int n, e;
801 801
 	SHA256_CTX ctx;
802 802
 	unsigned char *pt, digest1[PSS_DIGEST_LENGTH], digest2[PSS_DIGEST_LENGTH], *salt;
803 803
 	unsigned int plen = PSS_NBITS / 8, hlen, slen, i;
... ...
@@ -807,17 +804,17 @@ static int pss_versig(const unsigned char *sha256, const char *dsig)
807 807
 
808 808
 
809 809
     hlen = slen = PSS_DIGEST_LENGTH;
810
-    mpz_init_set_str(n, PSS_NSTR, 10);
811
-    mpz_init_set_str(e, PSS_ESTR, 10);
812
-
810
+    mp_init(&n);
811
+    mp_read_radix(&n, PSS_NSTR, 10);
812
+    mp_init(&e);
813
+    mp_read_radix(&e, PSS_ESTR, 10);
813 814
     if(!(pt = cli_decodesig(dsig, plen, e, n))) {
814
-	mpz_clear(n);
815
-	mpz_clear(e);
815
+	mp_clear(&n);
816
+	mp_clear(&e);
816 817
 	return -1;
817 818
     }
818
-
819
-    mpz_clear(n);
820
-    mpz_clear(e);
819
+    mp_clear(&n);
820
+    mp_clear(&e);
821 821
 
822 822
     if(pt[plen - 1] != 0xbc) {
823 823
 	/* cli_dbgmsg("cli_versigpss: Incorrect signature syntax (0xbc)\n"); */
... ...
@@ -864,7 +861,6 @@ static int pss_versig(const unsigned char *sha256, const char *dsig)
864 864
 
865 865
     return 0;
866 866
 }
867
-#endif /* HAVE_LIBGMP */
868 867
 
869 868
 int cdiff_apply(int fd, unsigned short mode)
870 869
 {
... ...
@@ -877,11 +873,9 @@ int cdiff_apply(int fd, unsigned short mode)
877 877
 	int end, i, n;
878 878
 	struct stat sb;
879 879
 	int desc;
880
-#ifdef HAVE_LIBGMP
881 880
 	SHA256_CTX sha256ctx;
882 881
 	unsigned char digest[32];
883 882
 	int sum, bread;
884
-#endif
885 883
 #define DSIGBUFF 350
886 884
 
887 885
     memset(&ctx, 0, sizeof(ctx));
... ...
@@ -938,7 +932,6 @@ int cdiff_apply(int fd, unsigned short mode)
938 938
 	    return -1;
939 939
 	}
940 940
 
941
-#ifdef HAVE_LIBGMP
942 941
 	sha256_init(&sha256ctx);
943 942
 	sum = 0;
944 943
 	while((bread = read(desc, buff, FILEBUFF)) > 0) {
... ...
@@ -958,7 +951,6 @@ int cdiff_apply(int fd, unsigned short mode)
958 958
 	    close(desc);
959 959
 	    return -1;
960 960
 	}
961
-#endif
962 961
 
963 962
 	if(lseek(desc, 0, SEEK_SET) == -1) {
964 963
 	    logg("!cdiff_apply: lseek(desc, 0, SEEK_SET) failed\n");
... ...
@@ -131,7 +131,6 @@ GENHTML = @GENHTML@
131 131
 GETENT = @GETENT@
132 132
 GPERF = @GPERF@
133 133
 GREP = @GREP@
134
-HAVE_LIBGMP = @HAVE_LIBGMP@
135 134
 INCLTDL = @INCLTDL@
136 135
 INSTALL = @INSTALL@
137 136
 INSTALL_DATA = @INSTALL_DATA@
... ...
@@ -149,8 +148,6 @@ LIBBZ2 = @LIBBZ2@
149 149
 LIBBZ2_PREFIX = @LIBBZ2_PREFIX@
150 150
 LIBCLAMAV_LIBS = @LIBCLAMAV_LIBS@
151 151
 LIBCLAMAV_VERSION = @LIBCLAMAV_VERSION@
152
-LIBGMP = @LIBGMP@
153
-LIBGMP_PREFIX = @LIBGMP_PREFIX@
154 152
 LIBLTDL = @LIBLTDL@
155 153
 LIBOBJS = @LIBOBJS@
156 154
 LIBS = $(top_builddir)/libclamav/libclamav.la @FRESHCLAM_LIBS@ @THREAD_LIBS@
... ...
@@ -161,7 +158,6 @@ LTDLDEPS = @LTDLDEPS@
161 161
 LTDLINCL = @LTDLINCL@
162 162
 LTDLOPEN = @LTDLOPEN@
163 163
 LTLIBBZ2 = @LTLIBBZ2@
164
-LTLIBGMP = @LTLIBGMP@
165 164
 LTLIBOBJS = @LTLIBOBJS@
166 165
 LT_CONFIG_H = @LT_CONFIG_H@
167 166
 LT_DLLOADERS = @LT_DLLOADERS@
... ...
@@ -939,11 +939,6 @@ static int cvdinfo(const struct optstruct *opts)
939 939
 	mprintf("MD5: %s\n", cvd->md5);
940 940
 	mprintf("Digital signature: %s\n", cvd->dsig);
941 941
 	cl_cvdfree(cvd);
942
-
943
-#ifndef HAVE_LIBGMP
944
-	mprintf("^Digital signature support not compiled in.\n");
945
-#endif
946
-
947 942
 	if((ret = cl_cvdverify(pt))) {
948 943
 	    mprintf("!cvdinfo: Verification: %s\n", cl_strerror(ret));
949 944
 	    return -1;
... ...
@@ -89,7 +89,6 @@ GENHTML = @GENHTML@
89 89
 GETENT = @GETENT@
90 90
 GPERF = @GPERF@
91 91
 GREP = @GREP@
92
-HAVE_LIBGMP = @HAVE_LIBGMP@
93 92
 INCLTDL = @INCLTDL@
94 93
 INSTALL = @INSTALL@
95 94
 INSTALL_DATA = @INSTALL_DATA@
... ...
@@ -107,8 +106,6 @@ LIBBZ2 = @LIBBZ2@
107 107
 LIBBZ2_PREFIX = @LIBBZ2_PREFIX@
108 108
 LIBCLAMAV_LIBS = @LIBCLAMAV_LIBS@
109 109
 LIBCLAMAV_VERSION = @LIBCLAMAV_VERSION@
110
-LIBGMP = @LIBGMP@
111
-LIBGMP_PREFIX = @LIBGMP_PREFIX@
112 110
 LIBLTDL = @LIBLTDL@
113 111
 LIBOBJS = @LIBOBJS@
114 112
 LIBS = @LIBS@
... ...
@@ -119,7 +116,6 @@ LTDLDEPS = @LTDLDEPS@
119 119
 LTDLINCL = @LTDLINCL@
120 120
 LTDLOPEN = @LTDLOPEN@
121 121
 LTLIBBZ2 = @LTLIBBZ2@
122
-LTLIBGMP = @LTLIBGMP@
123 122
 LTLIBOBJS = @LTLIBOBJS@
124 123
 LT_CONFIG_H = @LT_CONFIG_H@
125 124
 LT_DLLOADERS = @LT_DLLOADERS@
... ...
@@ -125,7 +125,6 @@ GENHTML = @GENHTML@
125 125
 GETENT = @GETENT@
126 126
 GPERF = @GPERF@
127 127
 GREP = @GREP@
128
-HAVE_LIBGMP = @HAVE_LIBGMP@
129 128
 INCLTDL = @INCLTDL@
130 129
 INSTALL = @INSTALL@
131 130
 INSTALL_DATA = @INSTALL_DATA@
... ...
@@ -143,8 +142,6 @@ LIBBZ2 = @LIBBZ2@
143 143
 LIBBZ2_PREFIX = @LIBBZ2_PREFIX@
144 144
 LIBCLAMAV_LIBS = @LIBCLAMAV_LIBS@
145 145
 LIBCLAMAV_VERSION = @LIBCLAMAV_VERSION@
146
-LIBGMP = @LIBGMP@
147
-LIBGMP_PREFIX = @LIBGMP_PREFIX@
148 146
 LIBLTDL = @LIBLTDL@
149 147
 LIBOBJS = @LIBOBJS@
150 148
 LIBS = @LIBS@
... ...
@@ -155,7 +152,6 @@ LTDLDEPS = @LTDLDEPS@
155 155
 LTDLINCL = @LTDLINCL@
156 156
 LTDLOPEN = @LTDLOPEN@
157 157
 LTLIBBZ2 = @LTLIBBZ2@
158
-LTLIBGMP = @LTLIBGMP@
159 158
 LTLIBOBJS = @LTLIBOBJS@
160 159
 LT_CONFIG_H = @LT_CONFIG_H@
161 160
 LT_DLLOADERS = @LT_DLLOADERS@
... ...
@@ -376,7 +376,7 @@ void diff_files(int fd, int ref_fd)
376 376
 }
377 377
 
378 378
 #ifdef USE_MPOOL
379
-static mp_t *pool;
379
+static mpool_t *pool;
380 380
 #else
381 381
 static void *pool;
382 382
 #endif
... ...
@@ -387,19 +387,19 @@ void dconf_setup(void)
387 387
 	pool = NULL;
388 388
 	dconf = NULL;
389 389
 #ifdef USE_MPOOL
390
-	pool = mp_create();
390
+	pool = mpool_create();
391 391
 	fail_unless(!!pool, "unable to create pool");
392 392
 #endif
393
-	dconf = cli_mp_dconf_init(pool);
393
+	dconf = cli_mpool_dconf_init(pool);
394 394
 	fail_unless(!!dconf, "failed to init dconf");
395 395
 }
396 396
 
397 397
 void dconf_teardown(void)
398 398
 {
399
-	mp_free(pool, dconf);
399
+	mpool_free(pool, dconf);
400 400
 #ifdef USE_MPOOL
401 401
 	if (pool)
402
-		mp_destroy(pool);
402
+		mpool_destroy(pool);
403 403
 #endif
404 404
 }
405 405
 
... ...
@@ -63,7 +63,7 @@ START_TEST (test_ac_scanbuff) {
63 63
     root->ac_only = 1;
64 64
 
65 65
 #ifdef USE_MPOOL
66
-    root->mempool = mp_create();
66
+    root->mempool = mpool_create();
67 67
 #endif
68 68
     ret = cli_ac_init(root, CLI_DEFAULT_AC_MINDEPTH, CLI_DEFAULT_AC_MAXDEPTH);
69 69
     fail_unless(ret == CL_SUCCESS, "cli_ac_init() failed");
... ...
@@ -88,7 +88,7 @@ START_TEST (test_ac_scanbuff) {
88 88
     cli_ac_freedata(&mdata);
89 89
     cli_ac_free(root);
90 90
 #ifdef USE_MPOOL
91
-    mp_destroy(root->mempool);
91
+    mpool_destroy(root->mempool);
92 92
 #endif
93 93
     free(root);
94 94
 }
... ...
@@ -104,7 +104,7 @@ START_TEST (test_bm_scanbuff) {
104 104
     fail_unless(root != NULL, "root == NULL");
105 105
 
106 106
 #ifdef USE_MPOOL
107
-    root->mempool = mp_create();
107
+    root->mempool = mpool_create();
108 108
 #endif
109 109
     ret = cli_bm_init(root);
110 110
     fail_unless(ret == CL_SUCCESS, "cli_bm_init() failed");
... ...
@@ -121,7 +121,7 @@ START_TEST (test_bm_scanbuff) {
121 121
     fail_unless(!strncmp(virname, "Sig2", 4), "Incorrect signature matched in cli_bm_scanbuff()\n");
122 122
     cli_bm_free(root);
123 123
 #ifdef USE_MPOOL
124
-    mp_destroy(root->mempool);
124
+    mpool_destroy(root->mempool);
125 125
 #endif
126 126
     free(root);
127 127
 }
... ...
@@ -155,7 +155,7 @@ static void rsetup(void)
155 155
 {
156 156
 	int rc;
157 157
 #ifdef USE_MPOOL
158
-	matcher.mempool = mp_create();
158
+	matcher.mempool = mpool_create();
159 159
 #endif
160 160
 	rc = init_regex_list(&matcher);
161 161
 	fail_unless(rc == 0, "init_regex_list");
... ...
@@ -165,7 +165,7 @@ static void rteardown(void)
165 165
 {
166 166
 	regex_list_done(&matcher);
167 167
 #ifdef USE_MPOOL
168
-	mp_destroy(matcher.mempool);
168
+	mpool_destroy(matcher.mempool);
169 169
 #endif
170 170
 }
171 171