Merge NSS trunk to NSS_TLS13_DRAFT19_BRANCH, a=merge NSS_TLS13_DRAFT19_BRANCH
authorMartin Thomson <martin.thomson@gmail.com>
Thu, 06 Jul 2017 10:06:34 +1000
branchNSS_TLS13_DRAFT19_BRANCH
changeset 13453 487757061622e440078e0b90cd46ce7d1611574e
parent 13428 a3c077a153caa13c71ae5835b72595b202786481 (current diff)
parent 13452 7a6a93296c5294c9f32bf25e98ed12ccd5294940 (diff)
child 13456 c50689be15fc86fd1461f09cefd02c6c88a6f333
push id2264
push usermartin.thomson@gmail.com
push dateThu, 06 Jul 2017 00:31:37 +0000
reviewersmerge
Merge NSS trunk to NSS_TLS13_DRAFT19_BRANCH, a=merge Hg: changed gtests/nss_bogo_shim/nss_bogo_shim.gyp
automation/taskcluster/scripts/run_clang_format.sh
gtests/ssl_gtest/tls_agent.cc
lib/freebl/mpi/Makefile
lib/freebl/mpi/Makefile.os2
lib/freebl/mpi/Makefile.win
lib/freebl/mpi/all-tests
lib/freebl/mpi/hppatch.adb
lib/freebl/mpi/make-logtab
lib/freebl/mpi/make-test-arrays
lib/freebl/mpi/mdxptest.c
lib/freebl/mpi/multest
lib/freebl/mpi/stats
lib/freebl/mpi/target.mk
lib/freebl/mpi/test-arrays.txt
lib/freebl/mpi/tests/LICENSE
lib/freebl/mpi/tests/LICENSE-MPL
lib/freebl/mpi/tests/mptest-1.c
lib/freebl/mpi/tests/mptest-2.c
lib/freebl/mpi/tests/mptest-3.c
lib/freebl/mpi/tests/mptest-3a.c
lib/freebl/mpi/tests/mptest-4.c
lib/freebl/mpi/tests/mptest-4a.c
lib/freebl/mpi/tests/mptest-4b.c
lib/freebl/mpi/tests/mptest-5.c
lib/freebl/mpi/tests/mptest-5a.c
lib/freebl/mpi/tests/mptest-6.c
lib/freebl/mpi/tests/mptest-7.c
lib/freebl/mpi/tests/mptest-8.c
lib/freebl/mpi/tests/mptest-9.c
lib/freebl/mpi/tests/mptest-b.c
lib/freebl/mpi/tests/pi1k.txt
lib/freebl/mpi/tests/pi2k.txt
lib/freebl/mpi/tests/pi5k.txt
lib/freebl/mpi/timetest
lib/freebl/mpi/types.pl
lib/freebl/mpi/utils/LICENSE
lib/freebl/mpi/utils/LICENSE-MPL
lib/freebl/mpi/utils/PRIMES
lib/freebl/mpi/utils/README
lib/freebl/mpi/utils/basecvt.c
lib/freebl/mpi/utils/bbs_rand.c
lib/freebl/mpi/utils/bbs_rand.h
lib/freebl/mpi/utils/bbsrand.c
lib/freebl/mpi/utils/dec2hex.c
lib/freebl/mpi/utils/exptmod.c
lib/freebl/mpi/utils/fact.c
lib/freebl/mpi/utils/gcd.c
lib/freebl/mpi/utils/hex2dec.c
lib/freebl/mpi/utils/identest.c
lib/freebl/mpi/utils/invmod.c
lib/freebl/mpi/utils/isprime.c
lib/freebl/mpi/utils/lap.c
lib/freebl/mpi/utils/makeprime.c
lib/freebl/mpi/utils/metime.c
lib/freebl/mpi/utils/pi.c
lib/freebl/mpi/utils/primegen.c
lib/freebl/mpi/utils/prng.c
lib/freebl/mpi/utils/ptab.pl
lib/freebl/mpi/utils/sieve.c
lib/ssl/ssl3con.c
--- a/.gitignore
+++ b/.gitignore
@@ -13,8 +13,9 @@ GPATH
 GRTAGS
 GTAGS
 #*
 .#*
 .ycm_extra_conf.py*
 fuzz/libFuzzer/*
 fuzz/corpus
 fuzz/out
+.chk
--- a/.hgignore
+++ b/.hgignore
@@ -13,8 +13,9 @@ GPATH
 GRTAGS
 GTAGS
 #*
 .#*
 .ycm_extra_conf.py*
 fuzz/libFuzzer/*
 fuzz/corpus
 fuzz/out
+.chk
--- a/Makefile
+++ b/Makefile
@@ -23,16 +23,17 @@ include $(CORE_DEPTH)/coreconf/config.mk
 
 
 #######################################################################
 # (4) Include "local" platform-dependent assignments (OPTIONAL).      #
 #######################################################################
 
 ifdef NSS_DISABLE_GTESTS
 DIRS := $(filter-out gtests,$(DIRS))
+DIRS := $(filter-out cpputil,$(DIRS))
 endif
 
 #######################################################################
 # (5) Execute "global" rules. (OPTIONAL)                              #
 #######################################################################
 
 include $(CORE_DEPTH)/coreconf/rules.mk
 
new file mode 100644
--- /dev/null
+++ b/automation/clang-format/Dockerfile
@@ -0,0 +1,26 @@
+FROM ubuntu:16.04
+MAINTAINER Franziskus Kiefer <franziskuskiefer@gmail.com>
+
+RUN useradd -d /home/worker -s /bin/bash -m worker
+WORKDIR /home/worker
+
+# Install dependencies.
+ADD setup.sh /tmp/setup.sh
+RUN bash /tmp/setup.sh
+
+# Change user.
+USER worker
+
+# Env variables.
+ENV HOME /home/worker
+ENV SHELL /bin/bash
+ENV USER worker
+ENV LOGNAME worker
+ENV HOSTNAME taskcluster-worker
+ENV LANG en_US.UTF-8
+ENV LC_ALL en_US.UTF-8
+ENV HOST localhost
+ENV DOMSUF localdomain
+
+# Entrypoint.
+ENTRYPOINT ["/home/worker/nss/automation/clang-format/run_clang_format.sh"]
new file mode 100755
--- /dev/null
+++ b/automation/clang-format/run_clang_format.sh
@@ -0,0 +1,67 @@
+#!/usr/bin/env bash
+
+if [[ $(id -u) -eq 0 ]]; then
+    # Drop privileges by re-running this script.
+    # Note: this mangles arguments, better to avoid running scripts as root.
+    exec su worker -c "$0 $*"
+fi
+
+# Apply clang-format on the provided folder and verify that this doesn't change any file.
+# If any file differs after formatting, the script eventually exits with 1.
+# Any differences between formatted and unformatted files is printed to stdout to give a hint what's wrong.
+
+# Includes a default set of directories NOT to clang-format on.
+blacklist=(
+     "./automation" \
+     "./coreconf" \
+     "./doc" \
+     "./pkg" \
+     "./tests" \
+     "./lib/libpkix" \
+     "./lib/zlib" \
+     "./lib/sqlite" \
+     "./gtests/google_test" \
+     "./.hg" \
+     "./out" \
+)
+
+top="$(dirname $0)/../.."
+cd "$top"
+
+if [ $# -gt 0 ]; then
+    dirs=("$@")
+else
+    dirs=($(find . -maxdepth 2 -mindepth 1 -type d ! -path . \( ! -regex '.*/' \)))
+fi
+
+format_folder()
+{
+    for black in "${blacklist[@]}"; do
+        if [[ "$1" == "$black"* ]]; then
+            echo "skip $1"
+            return 1
+        fi
+    done
+    return 0
+}
+
+for dir in "${dirs[@]}"; do
+    if format_folder "$dir" ; then
+        c="${dir//[^\/]}"
+        echo "formatting $dir ..."
+        depth=""
+        if [ "${#c}" == "1" ]; then
+            depth="-maxdepth 1"
+        fi
+        find "$dir" $depth -type f \( -name '*.[ch]' -o -name '*.cc' \) -exec clang-format -i {} \+
+    fi
+done
+
+TMPFILE=$(mktemp /tmp/$(basename $0).XXXXXX)
+trap 'rm $TMPFILE' exit
+if (cd $(dirname $0); hg root >/dev/null 2>&1); then
+    hg diff --git "$top" | tee $TMPFILE
+else
+    git -C "$top" diff | tee $TMPFILE
+fi
+[[ ! -s $TMPFILE ]]
new file mode 100644
--- /dev/null
+++ b/automation/clang-format/setup.sh
@@ -0,0 +1,44 @@
+#!/usr/bin/env bash
+
+set -v -e -x
+
+# Update packages.
+export DEBIAN_FRONTEND=noninteractive
+apt-get -y update && apt-get -y upgrade
+
+# Install packages.
+apt_packages=()
+apt_packages+=('ca-certificates')
+apt_packages+=('curl')
+apt_packages+=('xz-utils')
+apt_packages+=('mercurial')
+apt_packages+=('git')
+apt_packages+=('locales')
+apt-get install -y --no-install-recommends ${apt_packages[@]}
+
+# Download clang.
+curl -L http://releases.llvm.org/3.9.1/clang+llvm-3.9.1-x86_64-linux-gnu-ubuntu-16.04.tar.xz -o clang.tar.xz
+curl -L http://releases.llvm.org/3.9.1/clang+llvm-3.9.1-x86_64-linux-gnu-ubuntu-16.04.tar.xz.sig -o clang.tar.xz.sig
+# Verify the signature.
+gpg --keyserver pool.sks-keyservers.net --recv-keys B6C8F98282B944E3B0D5C2530FC3042E345AD05D
+gpg --verify clang.tar.xz.sig
+# Install into /usr/local/.
+tar xJvf *.tar.xz -C /usr/local --strip-components=1
+
+# Cleanup.
+function cleanup() {
+  rm -f clang.tar.xz clang.tar.xz.sig
+}
+trap cleanup ERR EXIT
+
+locale-gen en_US.UTF-8
+dpkg-reconfigure locales
+
+# Cleanup.
+rm -rf ~/.ccache ~/.cache
+apt-get autoremove -y
+apt-get clean
+apt-get autoclean
+
+# We're done. Remove this script.
+rm $0
--- a/automation/taskcluster/graph/src/extend.js
+++ b/automation/taskcluster/graph/src/extend.js
@@ -741,17 +741,17 @@ async function scheduleTools() {
 
   queue.scheduleTask(merge(base, {
     symbol: "clang-format-3.9",
     name: "clang-format-3.9",
     image: LINUX_CLANG39_IMAGE,
     command: [
       "/bin/bash",
       "-c",
-      "bin/checkout.sh && nss/automation/taskcluster/scripts/run_clang_format.sh"
+      "bin/checkout.sh && nss/automation/clang-format/run_clang_format.sh"
     ]
   }));
 
   queue.scheduleTask(merge(base, {
     symbol: "scan-build-4.0",
     name: "scan-build-4.0",
     image: LINUX_IMAGE,
     env: {
--- a/automation/taskcluster/graph/src/queue.js
+++ b/automation/taskcluster/graph/src/queue.js
@@ -20,20 +20,28 @@ let queue = new taskcluster.Queue({
 
 function fromNow(hours) {
   let d = new Date();
   d.setHours(d.getHours() + (hours|0));
   return d.toJSON();
 }
 
 function parseRoutes(routes) {
-  return [
+  let rv = [
     `tc-treeherder.v2.${process.env.TC_PROJECT}.${process.env.NSS_HEAD_REVISION}.${process.env.NSS_PUSHLOG_ID}`,
     ...routes
   ];
+
+  // Notify about failures (except on try).
+  if (process.env.TC_PROJECT != "nss-try") {
+    rv.push(`notify.email.${process.env.TC_OWNER}.on-failed`,
+            `notify.email.${process.env.TC_OWNER}.on-exception`);
+  }
+
+  return rv;
 }
 
 function parseFeatures(list) {
   return list.reduce((map, feature) => {
     map[feature] = true;
     return map;
   }, {});
 }
deleted file mode 100755
--- a/automation/taskcluster/scripts/run_clang_format.sh
+++ /dev/null
@@ -1,64 +0,0 @@
-#!/usr/bin/env bash
-
-source $(dirname "$0")/tools.sh
-
-set +x
-
-# Apply clang-format on the provided folder and verify that this doesn't change any file.
-# If any file differs after formatting, the script eventually exits with 1.
-# Any differences between formatted and unformatted files is printed to stdout to give a hint what's wrong.
-
-# Includes a default set of directories NOT to clang-format on.
-blacklist=(
-     "./automation" \
-     "./coreconf" \
-     "./doc" \
-     "./pkg" \
-     "./tests" \
-     "./lib/libpkix" \
-     "./lib/zlib" \
-     "./lib/sqlite" \
-     "./gtests/google_test" \
-     "./.hg" \
-)
-
-top="$PWD/$(dirname $0)/../../.."
-cd "$top"
-
-if [ $# -gt 0 ]; then
-    dirs=("$@")
-else
-    dirs=($(find . ! -path . \( ! -regex '.*/' \) -maxdepth 2 -mindepth 1 -type d))
-fi
-
-format_folder()
-{
-    for black in "${blacklist[@]}"; do
-        if [[ "$1" == "$black"* ]]; then
-            echo "skip $1"
-            return 1
-        fi
-    done
-    return 0
-}
-
-for dir in "${dirs[@]}"; do
-    if format_folder "$dir" ; then
-        c="${dir//[^\/]}"
-        echo "formatting $dir ..."
-        depth=""
-        if [ "${#c}" == "1" ]; then
-            depth="-maxdepth 1"
-        fi
-        find "$dir" $depth -type f \( -name '*.[ch]' -o -name '*.cc' \) -exec clang-format -i {} \+
-    fi
-done
-
-TMPFILE=$(mktemp /tmp/$(basename $0).XXXXXX)
-trap 'rm $TMPFILE' exit
-if (cd $(dirname $0); hg root >/dev/null 2>&1); then
-    hg diff --git "$top" | tee $TMPFILE
-else
-    git -C "$top" diff | tee $TMPFILE
-fi
-[[ ! -s $TMPFILE ]]
--- a/automation/taskcluster/scripts/split.sh
+++ b/automation/taskcluster/scripts/split.sh
@@ -19,24 +19,25 @@ split_util() {
   #   nss                         top files only
   #   nss/lib                     top files only
   #   nss/lib/util                full directory
 
   # Copy everything.
   cp -R $nssdir $dstdir
 
   # Skip gtests when building.
-  sed '/^DIRS = /s/ gtests$//' $nssdir/manifest.mn > $dstdir/manifest.mn-t && mv $dstdir/manifest.mn-t $dstdir/manifest.mn
+  sed '/^DIRS = /s/ cpputil gtests$//' $nssdir/manifest.mn > $dstdir/manifest.mn-t && mv $dstdir/manifest.mn-t $dstdir/manifest.mn
 
   # Remove subdirectories that we don't want.
   rm -rf $dstdir/cmd
   rm -rf $dstdir/tests
   rm -rf $dstdir/lib
   rm -rf $dstdir/automation
   rm -rf $dstdir/gtests
+  rm -rf $dstdir/cpputil
   rm -rf $dstdir/doc
 
   # Start with an empty cmd lib directories to be filled selectively.
   mkdir $dstdir/cmd
   cp $nssdir/cmd/Makefile $dstdir/cmd
   cp $nssdir/cmd/manifest.mn $dstdir/cmd
   cp $nssdir/cmd/platlibs.mk $dstdir/cmd
   cp $nssdir/cmd/platrules.mk $dstdir/cmd
@@ -61,25 +62,26 @@ split_softoken() {
   #   nss/lib/freebl              full directory
   #   nss/lib/softoken            full directory
   #   nss/lib/softoken/dbm        full directory
 
   # Copy everything.
   cp -R $nssdir $dstdir
 
   # Skip gtests when building.
-  sed '/^DIRS = /s/ gtests$//' $nssdir/manifest.mn > $dstdir/manifest.mn-t && mv $dstdir/manifest.mn-t $dstdir/manifest.mn
+  sed '/^DIRS = /s/ cpputil gtests$//' $nssdir/manifest.mn > $dstdir/manifest.mn-t && mv $dstdir/manifest.mn-t $dstdir/manifest.mn
 
   # Remove subdirectories that we don't want.
   rm -rf $dstdir/cmd
   rm -rf $dstdir/tests
   rm -rf $dstdir/lib
   rm -rf $dstdir/pkg
   rm -rf $dstdir/automation
   rm -rf $dstdir/gtests
+  rm -rf $dstdir/cpputil
   rm -rf $dstdir/doc
 
   # Start with an empty lib directory and copy only what we need.
   mkdir $dstdir/lib
   copy_top $nssdir/lib $dstdir/lib
   cp -R $nssdir/lib/dbm $dstdir/lib/dbm
   cp -R $nssdir/lib/freebl $dstdir/lib/freebl
   cp -R $nssdir/lib/softoken $dstdir/lib/softoken
--- a/build.sh
+++ b/build.sh
@@ -88,16 +88,17 @@ while [ $# -gt 0 ]; do
         --sancov=?*) enable_sancov "${1#*=}" ;;
         --pprof) gyp_params+=(-Duse_pprof=1) ;;
         --ct-verif) gyp_params+=(-Dct_verif=1) ;;
         --disable-tests) gyp_params+=(-Ddisable_tests=1) ;;
         --no-zdefs) gyp_params+=(-Dno_zdefs=1) ;;
         --system-sqlite) gyp_params+=(-Duse_system_sqlite=1) ;;
         --with-nspr=?*) set_nspr_path "${1#*=}"; no_local_nspr=1 ;;
         --system-nspr) set_nspr_path "/usr/include/nspr/:"; no_local_nspr=1 ;;
+        --enable-libpkix) gyp_params+=(-Ddisable_libpkix=0) ;;
         *) show_help; exit 2 ;;
     esac
     shift
 done
 
 if [ "$opt_build" = 1 ]; then
     target=Release
 else
--- a/cmd/certutil/keystuff.c
+++ b/cmd/certutil/keystuff.c
@@ -12,24 +12,16 @@
 #include <termios.h>
 #endif
 
 #if defined(XP_WIN) || defined(XP_PC)
 #include <time.h>
 #include <conio.h>
 #endif
 
-#if defined(__sun) && !defined(SVR4)
-extern int fclose(FILE *);
-extern int fprintf(FILE *, char *, ...);
-extern int isatty(int);
-extern char *sys_errlist[];
-#define strerror(errno) sys_errlist[errno]
-#endif
-
 #include "nspr.h"
 #include "prtypes.h"
 #include "prtime.h"
 #include "prlong.h"
 
 #include "pk11func.h"
 
 #define NUM_KEYSTROKES 120
--- a/cmd/platlibs.gypi
+++ b/cmd/platlibs.gypi
@@ -28,39 +28,25 @@
           '<(DEPTH)/lib/pk11wrap/pk11wrap.gyp:pk11wrap',
           '<(DEPTH)/lib/softoken/softoken.gyp:softokn',
           '<(DEPTH)/lib/certdb/certdb.gyp:certdb',
           '<(DEPTH)/lib/pki/pki.gyp:nsspki',
           '<(DEPTH)/lib/dev/dev.gyp:nssdev',
           '<(DEPTH)/lib/base/base.gyp:nssb',
           '<(DEPTH)/lib/freebl/freebl.gyp:freebl',
           '<(DEPTH)/lib/sqlite/sqlite.gyp:sqlite3',
+          '<(DEPTH)/lib/libpkix/libpkix.gyp:libpkix',
         ],
         'conditions': [
           [ 'disable_dbm==0', {
             'dependencies': [
               '<(DEPTH)/lib/dbm/src/src.gyp:dbm',
               '<(DEPTH)/lib/softoken/legacydb/legacydb.gyp:nssdbm',
             ],
           }],
-          [ 'disable_libpkix==0', {
-            'dependencies': [
-              '<(DEPTH)/lib/libpkix/pkix/certsel/certsel.gyp:pkixcertsel',
-              '<(DEPTH)/lib/libpkix/pkix/checker/checker.gyp:pkixchecker',
-              '<(DEPTH)/lib/libpkix/pkix/params/params.gyp:pkixparams',
-              '<(DEPTH)/lib/libpkix/pkix/results/results.gyp:pkixresults',
-              '<(DEPTH)/lib/libpkix/pkix/top/top.gyp:pkixtop',
-              '<(DEPTH)/lib/libpkix/pkix/util/util.gyp:pkixutil',
-              '<(DEPTH)/lib/libpkix/pkix/crlsel/crlsel.gyp:pkixcrlsel',
-              '<(DEPTH)/lib/libpkix/pkix/store/store.gyp:pkixstore',
-              '<(DEPTH)/lib/libpkix/pkix_pl_nss/pki/pki.gyp:pkixpki',
-              '<(DEPTH)/lib/libpkix/pkix_pl_nss/system/system.gyp:pkixsystem',
-              '<(DEPTH)/lib/libpkix/pkix_pl_nss/module/module.gyp:pkixmodule'
-            ],
-          }],
         ]},{ # !use_static_libs
           'conditions': [
             ['moz_fold_libs==0', {
               'dependencies': [
                 '<(DEPTH)/lib/ssl/ssl.gyp:ssl3',
                 '<(DEPTH)/lib/smime/smime.gyp:smime3',
                 '<(DEPTH)/lib/nss/nss.gyp:nss3',
               ],
--- a/cmd/platlibs.mk
+++ b/cmd/platlibs.mk
@@ -27,16 +27,22 @@ endif
 endif # BUILD_SUN_PKG
 
 ifdef NSS_DISABLE_DBM
 DBMLIB = $(NULL)
 else
 DBMLIB = $(DIST)/lib/$(LIB_PREFIX)dbm.$(LIB_SUFFIX) 
 endif
 
+ifeq ($(NSS_BUILD_UTIL_ONLY),1)
+SECTOOL_LIB = $(NULL)
+else
+SECTOOL_LIB = $(DIST)/lib/$(LIB_PREFIX)sectool.$(LIB_SUFFIX)
+endif
+
 ifdef USE_STATIC_LIBS
 
 DEFINES += -DNSS_USE_STATIC_LIBS
 # $(PROGRAM) has explicit dependencies on $(EXTRA_LIBS)
 ifndef NSS_USE_SYSTEM_FREEBL
 CRYPTOLIB=$(DIST)/lib/$(LIB_PREFIX)freebl.$(LIB_SUFFIX)
 SOFTOKENLIB=$(DIST)/lib/$(LIB_PREFIX)softokn.$(LIB_SUFFIX)
 else
@@ -65,30 +71,20 @@ PKIXLIB = \
 	$(DIST)/lib/$(LIB_PREFIX)pkixpki.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)pkixtop.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)pkixresults.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)pkixcertsel.$(LIB_SUFFIX)
 endif
 endif
 
 NSS_LIBS_1=
-SECTOOL_LIB=
 NSS_LIBS_2=
 NSS_LIBS_3=
 NSS_LIBS_4=
 
-ifneq ($(NSS_BUILD_UTIL_ONLY),1)
-SECTOOL_LIB = \
-	$(DIST)/lib/$(LIB_PREFIX)sectool.$(LIB_SUFFIX) \
-	$(NULL)
-else
-SECTOOL_LIB = \
-	$(NULL)
-endif
-
 ifneq ($(NSS_BUILD_SOFTOKEN_ONLY),1)
 ifeq ($(OS_ARCH), WINNT)
 # breakdown for windows
 NSS_LIBS_1 = \
 	$(DIST)/lib/$(LIB_PREFIX)smime.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)ssl.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)nss.$(LIB_SUFFIX) \
 	$(NULL)
@@ -116,19 +112,16 @@ NSS_LIBS_4 = \
 	$(NULL)
 else
 # breakdown for others
 NSS_LIBS_1 = \
 	$(DIST)/lib/$(LIB_PREFIX)smime.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)ssl.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)nss.$(LIB_SUFFIX) \
 	$(NULL)
-SECTOOL_LIB = \
-	$(DIST)/lib/$(LIB_PREFIX)sectool.$(LIB_SUFFIX) \
-	$(NULL)
 NSS_LIBS_2 = \
 	$(DIST)/lib/$(LIB_PREFIX)pkcs12.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)pkcs7.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)certhi.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)cryptohi.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)pk11wrap.$(LIB_SUFFIX) \
 	$(NULL)
 NSS_LIBS_3 = \
@@ -196,17 +189,17 @@ EXTRA_SHARED_LIBS += \
 endif
 
 else # USE_STATIC_LIBS
 # can't do this in manifest.mn because OS_ARCH isn't defined there.
 ifeq ($(OS_ARCH), WINNT)
 
 # $(PROGRAM) has explicit dependencies on $(EXTRA_LIBS)
 EXTRA_LIBS += \
-	$(DIST)/lib/$(LIB_PREFIX)sectool.$(LIB_SUFFIX) \
+	$(SECTOOL_LIB) \
 	$(NSSUTIL_LIB_DIR)/$(IMPORT_LIB_PREFIX)nssutil3$(IMPORT_LIB_SUFFIX) \
 	$(DIST)/lib/$(IMPORT_LIB_PREFIX)smime3$(IMPORT_LIB_SUFFIX) \
 	$(DIST)/lib/$(IMPORT_LIB_PREFIX)ssl3$(IMPORT_LIB_SUFFIX) \
 	$(DIST)/lib/$(IMPORT_LIB_PREFIX)nss3$(IMPORT_LIB_SUFFIX) \
 	$(NSPR_LIB_DIR)/$(NSPR31_LIB_PREFIX)plc4$(IMPORT_LIB_SUFFIX) \
 	$(NSPR_LIB_DIR)/$(NSPR31_LIB_PREFIX)plds4$(IMPORT_LIB_SUFFIX) \
 	$(NSPR_LIB_DIR)/$(NSPR31_LIB_PREFIX)nspr4$(IMPORT_LIB_SUFFIX) \
 	$(NULL)
@@ -215,17 +208,17 @@ EXTRA_LIBS += \
 #OS_LIBS += \
 	wsock32.lib \
 	winmm.lib \
 	$(NULL)
 else
 
 # $(PROGRAM) has explicit dependencies on $(EXTRA_LIBS)
 EXTRA_LIBS += \
-	$(DIST)/lib/$(LIB_PREFIX)sectool.$(LIB_SUFFIX) \
+	$(SECTOOL_LIB) \
 	$(NULL)
 
 ifeq ($(OS_ARCH), AIX) 
 EXTRA_SHARED_LIBS += -brtl 
 endif
 
 # $(PROGRAM) has NO explicit dependencies on $(EXTRA_SHARED_LIBS)
 # $(EXTRA_SHARED_LIBS) come before $(OS_LIBS), except on AIX.
@@ -233,23 +226,25 @@ EXTRA_SHARED_LIBS += \
 	-L$(DIST)/lib \
 	-L$(NSSUTIL_LIB_DIR) \
 	-lnssutil3 \
 	-L$(NSPR_LIB_DIR) \
 	-lplc4 \
 	-lplds4 \
 	-lnspr4 \
 	$(NULL)
+ifndef NSS_BUILD_UTIL_ONLY
 ifndef NSS_BUILD_SOFTOKEN_ONLY
 EXTRA_SHARED_LIBS += \
 	-lssl3 \
 	-lsmime3 \
 	-lnss3
 endif
 endif
+endif
 
 ifdef SOFTOKEN_LIB_DIR
 ifdef NSS_USE_SYSTEM_FREEBL
 EXTRA_SHARED_LIBS += -L$(SOFTOKEN_LIB_DIR) -lsoftokn3
 endif
 endif
 
 endif # USE_STATIC_LIBS
--- a/cmd/symkeyutil/symkeyutil.c
+++ b/cmd/symkeyutil/symkeyutil.c
@@ -228,16 +228,19 @@ ToDigit(unsigned char c)
 char *
 BufToHex(SECItem *outbuf)
 {
     int len = outbuf->len * 2 + 1;
     char *string, *ptr;
     unsigned int i;
 
     string = PORT_Alloc(len);
+    if (!string) {
+        return NULL;
+    }
 
     ptr = string;
     for (i = 0; i < outbuf->len; i++) {
         *ptr++ = ToDigit(outbuf->data[i] >> 4);
         *ptr++ = ToDigit(outbuf->data[i] & 0xf);
     }
     *ptr = 0;
     return string;
new file mode 100644
--- /dev/null
+++ b/cpputil/Makefile
@@ -0,0 +1,49 @@
+#! gmake
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#######################################################################
+# (1) Include initial platform-independent assignments (MANDATORY).   #
+#######################################################################
+
+include manifest.mn
+
+#######################################################################
+# (2) Include "global" configuration information. (OPTIONAL)          #
+#######################################################################
+
+include $(CORE_DEPTH)/coreconf/config.mk
+
+#######################################################################
+# (3) Include "component" configuration information. (OPTIONAL)       #
+#######################################################################
+
+ifeq (WINNT,$(OS_ARCH))
+OS_CFLAGS += -EHsc
+else
+CXXFLAGS += -std=c++0x
+endif
+
+#######################################################################
+# (4) Include "local" platform-dependent assignments (OPTIONAL).      #
+#######################################################################
+
+include config.mk
+
+#######################################################################
+# (5) Execute "global" rules. (OPTIONAL)                              #
+#######################################################################
+
+include $(CORE_DEPTH)/coreconf/rules.mk
+
+#######################################################################
+# (6) Execute "component" rules. (OPTIONAL)                           #
+#######################################################################
+
+
+
+#######################################################################
+# (7) Execute "local" rules. (OPTIONAL).                              #
+#######################################################################
new file mode 100644
--- /dev/null
+++ b/cpputil/config.mk
@@ -0,0 +1,15 @@
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+#
+#  Override TARGETS variable so that only static libraries
+#  are specifed as dependencies within rules.mk.
+#
+
+TARGETS        = $(LIBRARY)
+SHARED_LIBRARY =
+IMPORT_LIBRARY =
+PROGRAM        =
+
--- a/cpputil/dummy_io.cc
+++ b/cpputil/dummy_io.cc
@@ -14,16 +14,20 @@
   std::cerr << "Unimplemented: " << __FUNCTION__ << std::endl; \
   assert(false);
 
 extern const struct PRIOMethods DummyMethodsForward;
 
 ScopedPRFileDesc DummyIOLayerMethods::CreateFD(PRDescIdentity id,
                                                DummyIOLayerMethods *methods) {
   ScopedPRFileDesc fd(PR_CreateIOLayerStub(id, &DummyMethodsForward));
+  assert(fd);
+  if (!fd) {
+    return nullptr;
+  }
   fd->secret = reinterpret_cast<PRFilePrivate *>(methods);
   return fd;
 }
 
 PRStatus DummyIOLayerMethods::Close(PRFileDesc *f) {
   f->secret = nullptr;
   f->dtor(f);
   return PR_SUCCESS;
new file mode 100644
--- /dev/null
+++ b/cpputil/manifest.mn
@@ -0,0 +1,18 @@
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+CORE_DEPTH = ..
+DEPTH      = ..
+
+MODULE = nss
+LIBRARY_NAME = cpputil
+
+CPPSRCS = \
+      dummy_io.cc \
+      dummy_io_fwd.cc \
+      tls_parser.cc \
+      $(NULL)
+
+EXPORTS = \
+      $(NULL)
new file mode 100644
--- /dev/null
+++ b/cpputil/scoped_ptrs_util.h
@@ -0,0 +1,39 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#ifndef scoped_ptrs_util_h__
+#define scoped_ptrs_util_h__
+
+#include <memory>
+#include "pkcs11uri.h"
+#include "secoid.h"
+
+struct ScopedDelete {
+  void operator()(SECAlgorithmID* id) { SECOID_DestroyAlgorithmID(id, true); }
+  void operator()(SECItem* item) { SECITEM_FreeItem(item, true); }
+  void operator()(PK11URI* uri) { PK11URI_DestroyURI(uri); }
+  void operator()(PLArenaPool* arena) { PORT_FreeArena(arena, PR_FALSE); }
+};
+
+template <class T>
+struct ScopedMaybeDelete {
+  void operator()(T* ptr) {
+    if (ptr) {
+      ScopedDelete del;
+      del(ptr);
+    }
+  }
+};
+
+#define SCOPED(x) typedef std::unique_ptr<x, ScopedMaybeDelete<x> > Scoped##x
+
+SCOPED(SECAlgorithmID);
+SCOPED(SECItem);
+SCOPED(PK11URI);
+
+#undef SCOPED
+
+#endif  // scoped_ptrs_util_h__
--- a/gtests/.clang-format
+++ b/gtests/.clang-format
@@ -1,4 +1,5 @@
 ---
 Language: Cpp
 BasedOnStyle: Google
+SortIncludes: false
 ...
--- a/gtests/certhigh_gtest/manifest.mn
+++ b/gtests/certhigh_gtest/manifest.mn
@@ -9,14 +9,14 @@ MODULE = nss
 CPPSRCS = \
       certhigh_unittest.cc \
       $(NULL)
 
 INCLUDES += -I$(CORE_DEPTH)/gtests/google_test/gtest/include \
             -I$(CORE_DEPTH)/gtests/common \
             -I$(CORE_DEPTH)/cpputil
 
-REQUIRES = nspr nss libdbm gtest
+REQUIRES = nspr gtest
 
 PROGRAM = certhigh_gtest
 
 EXTRA_LIBS = $(DIST)/lib/$(LIB_PREFIX)gtest.$(LIB_SUFFIX) $(EXTRA_OBJS) \
-             ../common/$(OBJDIR)/gtests$(OBJ_SUFFIX)
+             $(DIST)/lib/$(LIB_PREFIX)gtestutil.$(LIB_SUFFIX)
new file mode 100644
--- /dev/null
+++ b/gtests/common/gtests-util.cc
@@ -0,0 +1,26 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include "nspr.h"
+#include "secoid.h"
+
+#include <cstdlib>
+
+#define GTEST_HAS_RTTI 0
+#include "gtest/gtest.h"
+
+int main(int argc, char **argv) {
+  ::testing::InitGoogleTest(&argc, argv);
+
+  if (SECOID_Init() != SECSuccess) {
+    return 1;
+  }
+  int rv = RUN_ALL_TESTS();
+
+  if (SECOID_Shutdown() != SECSuccess) {
+    return 1;
+  }
+
+  return rv;
+}
--- a/gtests/common/manifest.mn
+++ b/gtests/common/manifest.mn
@@ -1,22 +1,23 @@
 #
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 CORE_DEPTH = ../..
 DEPTH      = ../..
 MODULE = nss
 
-CPPSRCS = \
-      gtests.cc \
-      $(NULL)
+LIBRARY_NAME = gtestutil
+
+ifeq ($(NSS_BUILD_UTIL_ONLY),1)
+CPPSRCS = gtests-util.cc
+else
+CPPSRCS = gtests.cc
+endif
 
 INCLUDES += -I$(CORE_DEPTH)/gtests/google_test/gtest/include \
             -I$(CORE_DEPTH)/gtests/common \
             -I$(CORE_DEPTH)/cpputil
 
 REQUIRES = gtest
 
 EXTRA_LIBS = $(DIST)/lib/$(LIB_PREFIX)gtest.$(LIB_SUFFIX)
-
-# NOTE: this is not actually used but required to build gtests.o
-PROGRAM = gtests
--- a/gtests/der_gtest/der_getint_unittest.cc
+++ b/gtests/der_gtest/der_getint_unittest.cc
@@ -1,22 +1,21 @@
 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
+#include "secder.h"
+#include "secerr.h"
+
 #include <climits>
 #include <memory>
-#include "nss.h"
-#include "pk11pub.h"
-#include "secutil.h"
 
 #include "gtest/gtest.h"
-#include "scoped_ptrs.h"
 
 namespace nss_test {
 
 class DERIntegerDecodingTest : public ::testing::Test {
  public:
   void TestGetInteger(long number, unsigned char *der_number,
                       unsigned int len) {
     SECItem input = {siBuffer, der_number, len};
--- a/gtests/der_gtest/der_gtest.gyp
+++ b/gtests/der_gtest/der_gtest.gyp
@@ -7,17 +7,16 @@
     '../common/gtest.gypi',
   ],
   'targets': [
     {
       'target_name': 'der_gtest',
       'type': 'executable',
       'sources': [
         'der_getint_unittest.cc',
-        'der_private_key_import_unittest.cc',
         'der_quickder_unittest.cc',
         '<(DEPTH)/gtests/common/gtests.cc'
       ],
       'dependencies': [
         '<(DEPTH)/exports.gyp:nss_exports',
         '<(DEPTH)/gtests/google_test/google_test.gyp:gtest',
         '<(DEPTH)/lib/util/util.gyp:nssutil3',
         '<(DEPTH)/lib/ssl/ssl.gyp:ssl3',
--- a/gtests/der_gtest/der_quickder_unittest.cc
+++ b/gtests/der_gtest/der_quickder_unittest.cc
@@ -2,21 +2,22 @@
 /* vim: set ts=2 et sw=2 tw=80: */
 /* This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <stdint.h>
 
 #include "gtest/gtest.h"
-#include "scoped_ptrs.h"
+#include "scoped_ptrs_util.h"
 
 #include "nss.h"
 #include "prerror.h"
 #include "secasn1.h"
+#include "secder.h"
 #include "secerr.h"
 #include "secitem.h"
 
 const SEC_ASN1Template mySEC_NullTemplate[] = {
     {SEC_ASN1_NULL, 0, NULL, sizeof(SECItem)}};
 
 namespace nss_test {
 
--- a/gtests/der_gtest/manifest.mn
+++ b/gtests/der_gtest/manifest.mn
@@ -3,22 +3,21 @@
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 CORE_DEPTH = ../..
 DEPTH      = ../..
 MODULE = nss
 
 CPPSRCS = \
       der_getint_unittest.cc \
-      der_private_key_import_unittest.cc \
       der_quickder_unittest.cc \
       $(NULL)
 
 INCLUDES += -I$(CORE_DEPTH)/gtests/google_test/gtest/include \
             -I$(CORE_DEPTH)/gtests/common \
             -I$(CORE_DEPTH)/cpputil
 
-REQUIRES = nspr nss libdbm gtest
+REQUIRES = nspr gtest
 
 PROGRAM = der_gtest
 
 EXTRA_LIBS = $(DIST)/lib/$(LIB_PREFIX)gtest.$(LIB_SUFFIX) $(EXTRA_OBJS) \
-             ../common/$(OBJDIR)/gtests$(OBJ_SUFFIX)
+             $(DIST)/lib/$(LIB_PREFIX)gtestutil.$(LIB_SUFFIX)
--- a/gtests/freebl_gtest/freebl_gtest.gyp
+++ b/gtests/freebl_gtest/freebl_gtest.gyp
@@ -46,16 +46,17 @@
         '<(DEPTH)/lib/pk11wrap/pk11wrap.gyp:pk11wrap_static',
         '<(DEPTH)/lib/cryptohi/cryptohi.gyp:cryptohi',
         '<(DEPTH)/lib/certhigh/certhigh.gyp:certhi',
         '<(DEPTH)/lib/certdb/certdb.gyp:certdb',
         '<(DEPTH)/lib/base/base.gyp:nssb',
         '<(DEPTH)/lib/dev/dev.gyp:nssdev',
         '<(DEPTH)/lib/pki/pki.gyp:nsspki',
         '<(DEPTH)/lib/ssl/ssl.gyp:ssl',
+        '<(DEPTH)/lib/libpkix/libpkix.gyp:libpkix',
       ],
       'conditions': [
         [ 'OS=="win"', {
           'libraries': [
             'advapi32.lib',
           ],
         }],
       ],
--- a/gtests/manifest.mn
+++ b/gtests/manifest.mn
@@ -1,18 +1,36 @@
 # 
 # This Source Code Form is subject to the terms of the Mozilla Public
 # License, v. 2.0. If a copy of the MPL was not distributed with this
 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
 CORE_DEPTH = ..
 DEPTH      = ..
 
-DIRS = \
+LIB_SRCDIRS = \
 	google_test \
 	common \
+	$(NULL)
+
+ifneq ($(NSS_BUILD_WITHOUT_UTIL),1)
+UTIL_SRCDIRS = \
+	util_gtest \
+	der_gtest \
+	$(NULL)
+endif
+
+ifneq ($(NSS_BUILD_SOFTOKEN_ONLY),1)
+ifneq ($(NSS_BUILD_UTIL_ONLY),1)
+NSS_SRCDIRS = \
 	certdb_gtest \
 	certhigh_gtest \
-	der_gtest \
-	util_gtest \
 	pk11_gtest \
 	ssl_gtest \
         nss_bogo_shim \
 	$(NULL)
+endif
+endif
+
+DIRS = \
+	$(LIB_SRCDIRS) \
+	$(UTIL_SRCDIRS) \
+	$(NSS_SRCDIRS) \
+	$(NULL)
--- a/gtests/nss_bogo_shim/nss_bogo_shim.gyp
+++ b/gtests/nss_bogo_shim/nss_bogo_shim.gyp
@@ -30,39 +30,25 @@
         '<(DEPTH)/lib/cryptohi/cryptohi.gyp:cryptohi',
         '<(DEPTH)/lib/pk11wrap/pk11wrap.gyp:pk11wrap',
         '<(DEPTH)/lib/softoken/softoken.gyp:softokn',
         '<(DEPTH)/lib/certdb/certdb.gyp:certdb',
         '<(DEPTH)/lib/pki/pki.gyp:nsspki',
         '<(DEPTH)/lib/dev/dev.gyp:nssdev',
         '<(DEPTH)/lib/base/base.gyp:nssb',
         '<(DEPTH)/lib/freebl/freebl.gyp:freebl',
-        '<(DEPTH)/lib/zlib/zlib.gyp:nss_zlib'
+        '<(DEPTH)/lib/zlib/zlib.gyp:nss_zlib',
+        '<(DEPTH)/lib/libpkix/libpkix.gyp:libpkix',
       ],
       'conditions': [
         [ 'disable_dbm==0', {
           'dependencies': [
             '<(DEPTH)/lib/dbm/src/src.gyp:dbm',
           ],
         }],
-        [ 'disable_libpkix==0', {
-          'dependencies': [
-            '<(DEPTH)/lib/libpkix/pkix/certsel/certsel.gyp:pkixcertsel',
-            '<(DEPTH)/lib/libpkix/pkix/checker/checker.gyp:pkixchecker',
-            '<(DEPTH)/lib/libpkix/pkix/crlsel/crlsel.gyp:pkixcrlsel',
-            '<(DEPTH)/lib/libpkix/pkix/params/params.gyp:pkixparams',
-            '<(DEPTH)/lib/libpkix/pkix/results/results.gyp:pkixresults',
-            '<(DEPTH)/lib/libpkix/pkix/store/store.gyp:pkixstore',
-            '<(DEPTH)/lib/libpkix/pkix/top/top.gyp:pkixtop',
-            '<(DEPTH)/lib/libpkix/pkix/util/util.gyp:pkixutil',
-            '<(DEPTH)/lib/libpkix/pkix_pl_nss/system/system.gyp:pkixsystem',
-            '<(DEPTH)/lib/libpkix/pkix_pl_nss/module/module.gyp:pkixmodule',
-            '<(DEPTH)/lib/libpkix/pkix_pl_nss/pki/pki.gyp:pkixpki',
-          ],
-        }],
       ],
     }
   ],
   'target_defaults': {
     'defines': [
       'NSS_USE_STATIC_LIBS'
     ],
     'include_dirs': [
--- a/gtests/pk11_gtest/manifest.mn
+++ b/gtests/pk11_gtest/manifest.mn
@@ -11,21 +11,22 @@ CPPSRCS = \
       pk11_chacha20poly1305_unittest.cc \
       pk11_curve25519_unittest.cc \
       pk11_ecdsa_unittest.cc \
       pk11_export_unittest.cc \
       pk11_pbkdf2_unittest.cc \
       pk11_prf_unittest.cc \
       pk11_prng_unittest.cc \
       pk11_rsapss_unittest.cc \
+      pk11_der_private_key_import_unittest.cc \
       $(NULL)
 
 INCLUDES += -I$(CORE_DEPTH)/gtests/google_test/gtest/include \
             -I$(CORE_DEPTH)/gtests/common \
             -I$(CORE_DEPTH)/cpputil
 
 REQUIRES = nspr nss libdbm gtest
 
 PROGRAM = pk11_gtest
 
 EXTRA_LIBS = $(DIST)/lib/$(LIB_PREFIX)gtest.$(LIB_SUFFIX) $(EXTRA_OBJS) \
-             ../common/$(OBJDIR)/gtests$(OBJ_SUFFIX)
+             $(DIST)/lib/$(LIB_PREFIX)gtestutil.$(LIB_SUFFIX)
 
new file mode 100644
--- /dev/null
+++ b/gtests/pk11_gtest/pk11_der_private_key_import_unittest.cc
@@ -0,0 +1,110 @@
+/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/* vim: set ts=2 et sw=2 tw=80: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this file,
+ * You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+#include <climits>
+#include <memory>
+#include "nss.h"
+#include "pk11pub.h"
+#include "secutil.h"
+
+#include "gtest/gtest.h"
+#include "scoped_ptrs.h"
+
+namespace nss_test {
+
+const std::vector<uint8_t> kValidRSAKey = {
+    // 512-bit RSA private key (PKCS#8)
+    0x30, 0x82, 0x01, 0x54, 0x02, 0x01, 0x00, 0x30, 0x0d, 0x06, 0x09, 0x2a,
+    0x86, 0x48, 0x86, 0xf7, 0x0d, 0x01, 0x01, 0x01, 0x05, 0x00, 0x04, 0x82,
+    0x01, 0x3e, 0x30, 0x82, 0x01, 0x3a, 0x02, 0x01, 0x00, 0x02, 0x41, 0x00,
+    0xa2, 0x40, 0xce, 0xb5, 0x4e, 0x70, 0xdc, 0x14, 0x82, 0x5b, 0x58, 0x7d,
+    0x2f, 0x5d, 0xfd, 0x46, 0x3c, 0x4b, 0x82, 0x50, 0xb6, 0x96, 0x00, 0x4a,
+    0x1a, 0xca, 0xaf, 0xe4, 0x9b, 0xcf, 0x38, 0x4a, 0x46, 0xaa, 0x9f, 0xb4,
+    0xd9, 0xc7, 0xee, 0x88, 0xe9, 0xef, 0x0a, 0x31, 0x5f, 0x53, 0x86, 0x8f,
+    0x63, 0x68, 0x0b, 0x58, 0x34, 0x72, 0x49, 0xba, 0xed, 0xd9, 0x34, 0x15,
+    0x16, 0xc4, 0xca, 0xb7, 0x02, 0x03, 0x01, 0x00, 0x01, 0x02, 0x40, 0x34,
+    0xe6, 0xdc, 0x7e, 0xd0, 0xec, 0x8b, 0x55, 0x44, 0x8b, 0x73, 0xf6, 0x9d,
+    0x13, 0x10, 0x19, 0x6e, 0x5f, 0x50, 0x45, 0xf0, 0xc2, 0x47, 0xa5, 0xe1,
+    0xc6, 0x64, 0x43, 0x2d, 0x6a, 0x0a, 0xf7, 0xe7, 0xda, 0x40, 0xb8, 0x3a,
+    0xf0, 0x47, 0xdd, 0x01, 0xf5, 0xe0, 0xa9, 0x0e, 0x47, 0xc2, 0x24, 0xd7,
+    0xb5, 0x13, 0x3a, 0x35, 0x4d, 0x11, 0xaa, 0x50, 0x03, 0xb3, 0xe8, 0x54,
+    0x6c, 0x99, 0x01, 0x02, 0x21, 0x00, 0xcd, 0xb2, 0xd7, 0xa7, 0x43, 0x5b,
+    0xcb, 0x45, 0xe5, 0x0e, 0x86, 0xf6, 0xc1, 0x4e, 0x97, 0xed, 0x78, 0x1f,
+    0x09, 0x56, 0xcd, 0x26, 0xe6, 0xf7, 0x5e, 0xd9, 0xfc, 0x88, 0x12, 0x5f,
+    0x84, 0x07, 0x02, 0x21, 0x00, 0xc9, 0xee, 0x30, 0xaf, 0x6c, 0xb9, 0x5a,
+    0xc9, 0xc1, 0x14, 0x9e, 0xd8, 0x4b, 0x33, 0x38, 0x48, 0x17, 0x41, 0x35,
+    0x94, 0x09, 0xf3, 0x69, 0xc4, 0x97, 0xbe, 0x17, 0x7d, 0x95, 0x0f, 0xb7,
+    0xd1, 0x02, 0x21, 0x00, 0x8b, 0x0e, 0xf9, 0x8d, 0x61, 0x13, 0x20, 0x63,
+    0x9b, 0x0b, 0x6c, 0x20, 0x4a, 0xe4, 0xa7, 0xfe, 0xe8, 0xf3, 0x0a, 0x6c,
+    0x3c, 0xfa, 0xac, 0xaf, 0xd4, 0xd6, 0xc7, 0x4a, 0xf2, 0x28, 0xd2, 0x67,
+    0x02, 0x20, 0x6b, 0x0e, 0x1d, 0xbf, 0x93, 0x5b, 0xbd, 0x77, 0x43, 0x27,
+    0x24, 0x83, 0xb5, 0x72, 0xa5, 0x3f, 0x0b, 0x1d, 0x26, 0x43, 0xa2, 0xf6,
+    0xea, 0xb7, 0x30, 0x5f, 0xb6, 0x62, 0x7c, 0xf9, 0x85, 0x51, 0x02, 0x20,
+    0x3d, 0x22, 0x63, 0x15, 0x6b, 0x32, 0x41, 0x46, 0x44, 0x78, 0xb7, 0x13,
+    0xeb, 0x85, 0x4c, 0x4f, 0x6b, 0x3e, 0xf0, 0x52, 0xf0, 0x46, 0x3b, 0x65,
+    0xd8, 0x21, 0x7d, 0xae, 0xc0, 0x09, 0x98, 0x34};
+
+const std::vector<uint8_t> kInvalidLengthKey = {
+    0x30, 0x1b,        // SEQUENCE(len=27)
+    0x02, 0x01, 0x00,  // INT(len=1) = 0
+    0x30, 0x13,        // SEQUENCE(len=19)
+    0x06, 0x07,        // OID(len=7)
+    // dhPublicKey (1.2.840.10046.2.1)
+    0x2a, 0x86, 0x48, 0xce, 0x3e, 0x02, 0x01, 0x06, 0x08,  // OID(len=8)
+    // prime256v1 (1.2.840.10045.3.1.7) */
+    0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x04,
+    0x00  // OCTET STRING(len=0)
+};
+
+const std::vector<uint8_t> kInvalidZeroLengthKey = {
+    0x30, 0x1a,        // SEQUENCE(len=26)
+    0x02, 0x01, 0x00,  // INT(len=1) = 0
+    0x30, 0x13,        // SEQUENCE(len=19)
+    0x06, 0x07,        // OID(len=7)
+    // dhPublicKey (1.2.840.10046.2.1)
+    0x2a, 0x86, 0x48, 0xce, 0x3e, 0x02, 0x01, 0x06, 0x08,  // OID(len=8)
+    // prime256v1 (1.2.840.10045.3.1.7) */
+    0x2a, 0x86, 0x48, 0xce, 0x3d, 0x03, 0x01, 0x07, 0x04,
+    0x00  // OCTET STRING(len=0)
+};
+
+class DERPrivateKeyImportTest : public ::testing::Test {
+ public:
+  bool ParsePrivateKey(const std::vector<uint8_t>& data) {
+    ScopedPK11SlotInfo slot(PK11_GetInternalSlot());
+    EXPECT_TRUE(slot);
+
+    SECKEYPrivateKey* key = nullptr;
+    SECItem item = {siBuffer, const_cast<unsigned char*>(data.data()),
+                    (unsigned int)data.size()};
+
+    SECStatus rv = PK11_ImportDERPrivateKeyInfoAndReturnKey(
+        slot.get(), &item, nullptr, nullptr, false, false, KU_ALL, &key,
+        nullptr);
+
+    EXPECT_EQ(rv == SECSuccess, key != nullptr);
+    SECKEY_DestroyPrivateKey(key);
+
+    return rv == SECSuccess;
+  }
+};
+
+TEST_F(DERPrivateKeyImportTest, ImportPrivateRSAKey) {
+  EXPECT_TRUE(ParsePrivateKey(kValidRSAKey));
+  EXPECT_FALSE(PORT_GetError());
+}
+
+TEST_F(DERPrivateKeyImportTest, ImportInvalidPrivateKey) {
+  EXPECT_FALSE(ParsePrivateKey(kInvalidLengthKey));
+  EXPECT_EQ(PORT_GetError(), SEC_ERROR_BAD_DER);
+}
+
+TEST_F(DERPrivateKeyImportTest, ImportZeroLengthPrivateKey) {
+  EXPECT_FALSE(ParsePrivateKey(kInvalidZeroLengthKey));
+  EXPECT_EQ(PORT_GetError(), SEC_ERROR_BAD_KEY);
+}
+
+}  // namespace nss_test
--- a/gtests/pk11_gtest/pk11_gtest.gyp
+++ b/gtests/pk11_gtest/pk11_gtest.gyp
@@ -15,16 +15,17 @@
         'pk11_aes_gcm_unittest.cc',
         'pk11_chacha20poly1305_unittest.cc',
         'pk11_curve25519_unittest.cc',
         'pk11_ecdsa_unittest.cc',
         'pk11_pbkdf2_unittest.cc',
         'pk11_prf_unittest.cc',
         'pk11_prng_unittest.cc',
         'pk11_rsapss_unittest.cc',
+        'pk11_der_private_key_import_unittest.cc',
         '<(DEPTH)/gtests/common/gtests.cc'
       ],
       'dependencies': [
         '<(DEPTH)/exports.gyp:nss_exports',
         '<(DEPTH)/lib/util/util.gyp:nssutil3',
         '<(DEPTH)/gtests/google_test/google_test.gyp:gtest',
       ],
       'conditions': [
--- a/gtests/ssl_gtest/manifest.mn
+++ b/gtests/ssl_gtest/manifest.mn
@@ -7,19 +7,16 @@ DEPTH      = ../..
 MODULE = nss
 
 # These sources have access to libssl internals
 CSRCS = \
       libssl_internals.c \
       $(NULL)
 
 CPPSRCS = \
-      $(CORE_DEPTH)/cpputil/dummy_io.cc \
-      $(CORE_DEPTH)/cpputil/dummy_io_fwd.cc \
-      $(CORE_DEPTH)/cpputil/tls_parser.cc \
       ssl_0rtt_unittest.cc \
       ssl_agent_unittest.cc \
       ssl_auth_unittest.cc \
       ssl_cert_ext_unittest.cc \
       ssl_ciphersuite_unittest.cc \
       ssl_damage_unittest.cc \
       ssl_dhe_unittest.cc \
       ssl_drop_unittest.cc \
@@ -48,14 +45,17 @@ CPPSRCS = \
       tls_filter.cc \
       tls_protect.cc \
       $(NULL)
 
 INCLUDES += -I$(CORE_DEPTH)/gtests/google_test/gtest/include \
             -I$(CORE_DEPTH)/gtests/common \
             -I$(CORE_DEPTH)/cpputil
 
-REQUIRES = nspr nss libdbm gtest
+REQUIRES = nspr nss libdbm gtest cpputil
 
 PROGRAM = ssl_gtest
-EXTRA_LIBS = $(DIST)/lib/$(LIB_PREFIX)gtest.$(LIB_SUFFIX)
+EXTRA_LIBS += \
+      $(DIST)/lib/$(LIB_PREFIX)gtest.$(LIB_SUFFIX) \
+      $(DIST)/lib/$(LIB_PREFIX)cpputil.$(LIB_SUFFIX) \
+      $(NULL)
 
 USE_STATIC_LIBS = 1
--- a/gtests/ssl_gtest/selfencrypt_unittest.cc
+++ b/gtests/ssl_gtest/selfencrypt_unittest.cc
@@ -5,18 +5,20 @@
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <functional>
 #include <memory>
 #include "nss.h"
 #include "pk11pub.h"
 #include "prerror.h"
 #include "secerr.h"
+#include "ssl.h"
 #include "sslerr.h"
 extern "C" {
+#include "sslimpl.h"
 #include "selfencrypt.h"
 }
 
 #include "databuffer.h"
 #include "gtest_utils.h"
 #include "scoped_ptrs.h"
 
 namespace nss_test {
--- a/gtests/ssl_gtest/ssl_gtest.gyp
+++ b/gtests/ssl_gtest/ssl_gtest.gyp
@@ -57,16 +57,17 @@
         '<(DEPTH)/lib/certhigh/certhigh.gyp:certhi',
         '<(DEPTH)/lib/cryptohi/cryptohi.gyp:cryptohi',
         '<(DEPTH)/lib/certdb/certdb.gyp:certdb',
         '<(DEPTH)/lib/pki/pki.gyp:nsspki',
         '<(DEPTH)/lib/dev/dev.gyp:nssdev',
         '<(DEPTH)/lib/base/base.gyp:nssb',
         '<(DEPTH)/lib/zlib/zlib.gyp:nss_zlib',
         '<(DEPTH)/cpputil/cpputil.gyp:cpputil',
+        '<(DEPTH)/lib/libpkix/libpkix.gyp:libpkix',
       ],
       'conditions': [
         [ 'test_build==1', {
           'dependencies': [
             '<(DEPTH)/lib/pk11wrap/pk11wrap.gyp:pk11wrap_static',
           ],
         }, {
           'dependencies': [
@@ -76,31 +77,16 @@
             '<(DEPTH)/lib/freebl/freebl.gyp:freebl',
           ],
         }],
         [ 'disable_dbm==0', {
           'dependencies': [
             '<(DEPTH)/lib/dbm/src/src.gyp:dbm',
           ],
         }],
-        [ 'disable_libpkix==0', {
-          'dependencies': [
-            '<(DEPTH)/lib/libpkix/pkix/certsel/certsel.gyp:pkixcertsel',
-            '<(DEPTH)/lib/libpkix/pkix/checker/checker.gyp:pkixchecker',
-            '<(DEPTH)/lib/libpkix/pkix/crlsel/crlsel.gyp:pkixcrlsel',
-            '<(DEPTH)/lib/libpkix/pkix/params/params.gyp:pkixparams',
-            '<(DEPTH)/lib/libpkix/pkix/results/results.gyp:pkixresults',
-            '<(DEPTH)/lib/libpkix/pkix/store/store.gyp:pkixstore',
-            '<(DEPTH)/lib/libpkix/pkix/top/top.gyp:pkixtop',
-            '<(DEPTH)/lib/libpkix/pkix/util/util.gyp:pkixutil',
-            '<(DEPTH)/lib/libpkix/pkix_pl_nss/system/system.gyp:pkixsystem',
-            '<(DEPTH)/lib/libpkix/pkix_pl_nss/module/module.gyp:pkixmodule',
-            '<(DEPTH)/lib/libpkix/pkix_pl_nss/pki/pki.gyp:pkixpki',
-          ],
-        }],
       ],
     }
   ],
   'target_defaults': {
     'include_dirs': [
       '../../lib/ssl'
     ],
     'defines': [
--- a/gtests/ssl_gtest/tls_agent.cc
+++ b/gtests/ssl_gtest/tls_agent.cc
@@ -912,20 +912,20 @@ void TlsAgent::SendBuffer(const DataBuff
     EXPECT_NE(PR_WOULD_BLOCK_ERROR, error_code_);
     error_code_ = PR_GetError();
     expect_readwrite_error_ = false;
   } else {
     ASSERT_EQ(buf.len(), static_cast<size_t>(rv));
   }
 }
 
-void TlsAgent::ReadBytes(size_t max) {
-  uint8_t block[max];
+void TlsAgent::ReadBytes(size_t amount) {
+  uint8_t block[16384];
 
-  int32_t rv = PR_Read(ssl_fd(), block, sizeof(block));
+  int32_t rv = PR_Read(ssl_fd(), block, (std::min)(amount, sizeof(block)));
   LOGV("ReadBytes " << rv);
   int32_t err;
 
   if (rv >= 0) {
     size_t count = static_cast<size_t>(rv);
     for (size_t i = 0; i < count; ++i) {
       ASSERT_EQ(recv_ctr_ & 0xff, block[i]);
       recv_ctr_++;
--- a/gtests/util_gtest/manifest.mn
+++ b/gtests/util_gtest/manifest.mn
@@ -20,10 +20,10 @@ INCLUDES += \
 
 REQUIRES = nspr gtest
 
 PROGRAM = util_gtest
 
 EXTRA_LIBS = \
 	$(DIST)/lib/$(LIB_PREFIX)gtest.$(LIB_SUFFIX) \
 	$(DIST)/lib/$(LIB_PREFIX)nssutil.$(LIB_SUFFIX) \
-	../common/$(OBJDIR)/gtests$(OBJ_SUFFIX) \
+	$(DIST)/lib/$(LIB_PREFIX)gtestutil.$(LIB_SUFFIX) \
 	$(NULL)
--- a/gtests/util_gtest/util_b64_unittest.cc
+++ b/gtests/util_gtest/util_b64_unittest.cc
@@ -4,17 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <climits>
 #include <memory>
 #include "nssb64.h"
 
 #include "gtest/gtest.h"
-#include "scoped_ptrs.h"
+#include "scoped_ptrs_util.h"
 
 namespace nss_test {
 
 class B64EncodeDecodeTest : public ::testing::Test {
  public:
   void TestDecodeStr(const std::string &str) {
     ScopedSECItem tmp(
         NSSBase64_DecodeBuffer(nullptr, nullptr, str.c_str(), str.size()));
--- a/gtests/util_gtest/util_gtest.gyp
+++ b/gtests/util_gtest/util_gtest.gyp
@@ -24,16 +24,17 @@
         '<(DEPTH)/lib/pk11wrap/pk11wrap.gyp:pk11wrap_static',
         '<(DEPTH)/lib/cryptohi/cryptohi.gyp:cryptohi',
         '<(DEPTH)/lib/certhigh/certhigh.gyp:certhi',
         '<(DEPTH)/lib/certdb/certdb.gyp:certdb',
         '<(DEPTH)/lib/base/base.gyp:nssb',
         '<(DEPTH)/lib/dev/dev.gyp:nssdev',
         '<(DEPTH)/lib/pki/pki.gyp:nsspki',
         '<(DEPTH)/lib/ssl/ssl.gyp:ssl',
+        '<(DEPTH)/lib/libpkix/libpkix.gyp:libpkix',
       ],
       'conditions': [
         [ 'OS=="win"', {
           'libraries': [
             'advapi32.lib',
           ],
         }],
       ],
--- a/gtests/util_gtest/util_pkcs11uri_unittest.cc
+++ b/gtests/util_gtest/util_pkcs11uri_unittest.cc
@@ -4,17 +4,17 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this file,
  * You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #include <climits>
 #include <memory>
 #include "pkcs11uri.h"
 
 #include "gtest/gtest.h"
-#include "scoped_ptrs.h"
+#include "scoped_ptrs_util.h"
 
 namespace nss_test {
 
 class PK11URITest : public ::testing::Test {
  public:
   bool TestCreate(const PK11URIAttribute *pattrs, size_t num_pattrs,
                   const PK11URIAttribute *qattrs, size_t num_qattrs) {
     ScopedPK11URI tmp(
--- a/help.txt
+++ b/help.txt
@@ -1,13 +1,13 @@
 Usage: build.sh [-hcv] [-j <n>] [--nspr] [--gyp|-g] [--opt|-o] [-m32]
                 [--test] [--pprof] [--scan-build[=output]] [--ct-verif]
                 [--asan] [--ubsan] [--msan] [--sancov[=edge|bb|func|...]]
                 [--disable-tests] [--fuzz[=tls|oss]] [--system-sqlite]
-                [--no-zdefs] [--with-nspr] [--system-nspr]
+                [--no-zdefs] [--with-nspr] [--system-nspr] [--enable-libpkix]
 
 This script builds NSS with gyp and ninja.
 
 This build system is still under development.  It does not yet support all
 the features or platforms that NSS supports.
 
 NSS build tool options:
 
@@ -35,8 +35,9 @@ NSS build tool options:
                      --sancov=func sets coverage to function level for example
     --disable-tests  don't build tests and corresponding cmdline utils
     --system-sqlite  use system sqlite
     --no-zdefs       don't set -Wl,-z,defs
     --with-nspr      don't build NSPR but use the one at the given location, e.g.
                      --with-nspr=/path/to/nspr/include:/path/to/nspr/lib
     --system-nspr    use system nspr. This requires an installation of NSPR and
                      might not work on all systems.
+    --enable-libpkix make libpkix part of the build.
--- a/lib/certdb/certv3.c
+++ b/lib/certdb/certv3.c
@@ -208,15 +208,15 @@ CERT_CheckCertUsage(CERTCertificate *cer
     /* This code formerly ignored the Key Usage extension if it was
     ** marked non-critical.  That was wrong.  Since we do understand it,
     ** we are obligated to honor it, whether or not it is critical.
     */
     rv = CERT_FindKeyUsageExtension(cert, &keyUsage);
     if (rv == SECFailure) {
         rv = (PORT_GetError() == SEC_ERROR_EXTENSION_NOT_FOUND) ? SECSuccess
                                                                 : SECFailure;
-    } else if (!(keyUsage.data[0] & usage)) {
+    } else if (!keyUsage.data || !(keyUsage.data[0] & usage)) {
         PORT_SetError(SEC_ERROR_CERT_USAGES_INVALID);
         rv = SECFailure;
     }
     PORT_Free(keyUsage.data);
     return (rv);
 }
--- a/lib/freebl/dh.c
+++ b/lib/freebl/dh.c
@@ -80,16 +80,21 @@ DH_GenParam(int primeLen, DHParams **par
     CHECK_MPI_OK(mp_init(&test));
     /* generate prime with MPI, uses Miller-Rabin to generate strong prime. */
     CHECK_SEC_OK(generate_prime(&p, primeLen));
     /* construct Sophie-Germain prime q = (p-1)/2. */
     CHECK_MPI_OK(mp_sub_d(&p, 1, &psub1));
     CHECK_MPI_OK(mp_div_2(&psub1, &q));
     /* construct a generator from the prime. */
     ab = PORT_Alloc(primeLen);
+    if (!ab) {
+        PORT_SetError(SEC_ERROR_NO_MEMORY);
+        rv = SECFailure;
+        goto cleanup;
+    }
     /* generate a candidate number a in p's field */
     CHECK_SEC_OK(RNG_GenerateGlobalRandomBytes(ab, primeLen));
     CHECK_MPI_OK(mp_read_unsigned_octets(&a, ab, primeLen));
     /* force a < p (note that quot(a/p) <= 1) */
     if (mp_cmp(&a, &p) > 0)
         CHECK_MPI_OK(mp_sub(&a, &p, &a));
     do {
         /* check that a is in the range [2..p-1] */
@@ -109,24 +114,26 @@ DH_GenParam(int primeLen, DHParams **par
     *params = dhparams;
 cleanup:
     mp_clear(&p);
     mp_clear(&q);
     mp_clear(&a);
     mp_clear(&h);
     mp_clear(&psub1);
     mp_clear(&test);
-    if (ab)
+    if (ab) {
         PORT_ZFree(ab, primeLen);
+    }
     if (err) {
         MP_TO_SEC_ERROR(err);
         rv = SECFailure;
     }
-    if (rv)
+    if (rv != SECSuccess) {
         PORT_FreeArena(arena, PR_TRUE);
+    }
     return rv;
 }
 
 SECStatus
 DH_NewKey(DHParams *params, DHPrivateKey **privKey)
 {
     PLArenaPool *arena;
     DHPrivateKey *key;
--- a/lib/freebl/freebl.gyp
+++ b/lib/freebl/freebl.gyp
@@ -148,31 +148,33 @@
       'SHLIB_SUFFIX=\"<(dll_suffix)\"',
       'SHLIB_PREFIX=\"<(dll_prefix)\"',
       'SHLIB_VERSION=\"3\"',
       'SOFTOKEN_SHLIB_VERSION=\"3\"',
       'RIJNDAEL_INCLUDE_TABLES',
       'MP_API_COMPATIBLE'
     ],
     'conditions': [
+      [ 'target_arch=="ia32" or target_arch=="x64"', {
+        'cflags_mozilla': [
+          '-mpclmul',
+          '-maes',
+        ],
+      }],
       [ 'OS=="mac"', {
         'xcode_settings': {
           # I'm not sure since when this is supported.
           # But I hope that doesn't matter. We also assume this is x86/x64.
           'OTHER_CFLAGS': [
             '-mpclmul',
             '-maes',
           ],
         },
       }],
       [ 'OS=="win" and target_arch=="ia32"', {
-        'cflags_mozilla': [
-          '-mpclmul',
-          '-maes',
-        ],
         'msvs_settings': {
           'VCCLCompilerTool': {
             #TODO: -Ox optimize flags
             'PreprocessorDefinitions': [
               'MP_ASSEMBLY_MULTIPLY',
               'MP_ASSEMBLY_SQUARE',
               'MP_ASSEMBLY_DIV_2DX1D',
               'MP_USE_UINT_DIGIT',
@@ -196,20 +198,16 @@
               'NSS_USE_COMBA',
               'USE_HW_AES',
               'INTEL_GCM',
             ],
           },
         },
       }],
       [ 'cc_use_gnu_ld==1 and OS=="win" and target_arch=="x64"', {
-        'cflags_mozilla': [
-          '-mpclmul',
-          '-maes',
-        ],
         'defines': [
           'MP_IS_LITTLE_ENDIAN',
           'NSS_BEVAND_ARCFOUR',
           'MPI_AMD64',
           'MP_ASSEMBLY_MULTIPLY',
           'NSS_USE_COMBA',
           'USE_HW_AES',
           'INTEL_GCM',
@@ -263,20 +261,16 @@
           }],
           [ 'target_arch=="ia32" or target_arch=="x64"', {
             'cflags': [
               # enable isa option for pclmul am aes-ni; supported since gcc 4.4
               # This is only support by x84/x64. It's not needed for Windows.
               '-mpclmul',
               '-maes',
             ],
-            'cflags_mozilla': [
-              '-mpclmul',
-              '-maes',
-            ],
           }],
           [ 'target_arch=="arm"', {
             'defines': [
               'MP_ASSEMBLY_MULTIPLY',
               'MP_ASSEMBLY_SQUARE',
               'MP_USE_UINT_DIGIT',
               'SHA_NO_LONG_LONG',
               'ARMHF',
deleted file mode 100644
--- a/lib/freebl/mpi/Makefile
+++ /dev/null
@@ -1,244 +0,0 @@
-#
-# Makefile for MPI library
-
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-## Define CC to be the C compiler you wish to use.  The GNU cc
-## compiler (gcc) should work, at the very least
-#CC=cc
-#CC=gcc
-
-## 
-## Define PERL to point to your local Perl interpreter.  It
-## should be Perl 5.x, although it's conceivable that Perl 4
-## might work ... I haven't tested it.
-##
-#PERL=/usr/bin/perl
-#PERL=perl
-
-include target.mk
-
-CFLAGS+= $(XCFLAGS)
-
-##
-## Define LIBS to include any libraries you need to link against.
-## If NO_TABLE is define, LIBS should include '-lm' or whatever is
-## necessary to bring in the math library.  Otherwise, it can be
-## left alone, unless your system has other peculiar requirements.
-##
-LIBS=#-lmalloc#-lefence#-lm
-
-## 
-## Define RANLIB to be the library header randomizer; you might not
-## need this on some systems (just set it to 'echo' on these systems,
-## such as IRIX)
-##
-RANLIB=echo
-
-##
-## This is the version string used for the documentation and 
-## building the distribution tarball.  Don't mess with it unless
-## you are releasing a new version
-VERS=1.7p6
-
-## ----------------------------------------------------------------------
-## You probably don't need to change anything below this line...
-##
-
-##
-## This is the list of source files that need to be packed into
-## the distribution file
-SRCS=   mpi.c mpprime.c mplogic.c mp_gf2m.c mpmontg.c mpi-test.c primes.c \
-	mpcpucache.c tests/ \
-	utils/gcd.c utils/invmod.c utils/lap.c \
-	utils/ptab.pl utils/sieve.c utils/isprime.c\
-	utils/dec2hex.c utils/hex2dec.c utils/bbs_rand.c \
-	utils/bbsrand.c utils/prng.c utils/primegen.c \
-	utils/basecvt.c utils/makeprime.c\
-	utils/fact.c utils/exptmod.c utils/pi.c utils/metime.c \
-	utils/mpi.h utils/mpprime.h mulsqr.c \
-	make-test-arrays test-arrays.txt all-tests make-logtab \
-	types.pl stats timetest multest
-
-## These are the header files that go into the distribution file
-HDRS=mpi.h mpi-config.h utils/mpi.h utils/mpi-config.h mpprime.h mplogic.h mp_gf2m.h \
-     mp_gf2m-priv.h utils/bbs_rand.h tests/mpi.h tests/mpprime.h
-
-## These are the documentation files that go into the distribution file
-DOCS=README doc utils/README utils/PRIMES 
-
-## This is the list of tools built by 'make tools'
-TOOLS=gcd invmod isprime lap dec2hex hex2dec primegen prng \
-	basecvt fact exptmod pi makeprime identest
-
-LIBOBJS = mpprime.o mpmontg.o mplogic.o mp_gf2m.o mpi.o mpcpucache.o $(AS_OBJS)
-LIBHDRS = mpi-config.h mpi-priv.h mpi.h
-APPHDRS = mpi-config.h mpi.h mplogic.h mp_gf2m.h mpprime.h
-
-help:
-	@ echo ""
-	@ echo "The following targets can be built with this Makefile:"
-	@ echo ""
-	@ echo "libmpi.a     - arithmetic and prime testing library"
-	@ echo "mpi-test     - test driver (requires MP_IOFUNC)"
-	@ echo "tools        - command line tools"
-	@ echo "doc          - manual pages for tools"
-	@ echo "clean        - clean up objects and such"
-	@ echo "distclean    - get ready for distribution"
-	@ echo "dist         - distribution tarball"
-	@ echo ""
-
-.SUFFIXES: .c .o .i
-
-.c.i:
-	$(CC) $(CFLAGS) -E $< > $@
-
-#.c.o: $*.h $*.c
-#	$(CC) $(CFLAGS) -c $<
-
-#---------------------------------------
-
-$(LIBOBJS): $(LIBHDRS)
-
-logtab.h: make-logtab
-	$(PERL) make-logtab > logtab.h
-
-mpi.o: mpi.c logtab.h $(LIBHDRS)
-
-mplogic.o: mplogic.c mpi-priv.h mplogic.h $(LIBHDRS)
-
-mp_gf2m.o: mp_gf2m.c mpi-priv.h mp_gf2m.h mp_gf2m-priv.h $(LIBHDRS)
-
-mpmontg.o: mpmontg.c mpi-priv.h mplogic.h mpprime.h $(LIBHDRS)
-
-mpprime.o: mpprime.c mpi-priv.h mpprime.h mplogic.h primes.c $(LIBHDRS)
-
-mpcpucache.o: mpcpucache.c $(LIBHDRS)
-
-mpi_mips.o: mpi_mips.s
-	$(CC) -o $@ $(ASFLAGS) -c mpi_mips.s
-
-mpi_sparc.o : montmulf.h
-
-mpv_sparcv9.s: vis_64.il mpv_sparc.c
-	$(CC) -o $@ $(SOLARIS_FPU_FLAGS) -S vis_64.il mpv_sparc.c
-
-mpv_sparcv8.s: vis_64.il mpv_sparc.c
-	$(CC) -o $@ $(SOLARIS_FPU_FLAGS) -S vis_32.il mpv_sparc.c
-
-montmulfv8.o montmulfv9.o mpv_sparcv8.o mpv_sparcv9.o : %.o : %.s 
-	$(CC) -o $@ $(SOLARIS_ASM_FLAGS) -c $<
-
-mpi_arm.o: mpi_arm.c $(LIBHDRS)
-
-# This rule is used to build the .s sources, which are then hand optimized.
-#montmulfv8.s montmulfv9.s : montmulf%.s : montmulf%.il montmulf.c montmulf.h 
-#	$(CC) -o $@ $(SOLARIS_ASM_FLAGS) -S montmulf$*.il montmulf.c
-
-
-libmpi.a: $(LIBOBJS)
-	ar -cvr libmpi.a $(LIBOBJS)
-	$(RANLIB) libmpi.a
-
-lib libs: libmpi.a
-
-mpi.i: mpi.h
-
-#---------------------------------------
-
-MPTESTOBJS = mptest1.o mptest2.o mptest3.o mptest3a.o mptest4.o mptest4a.o \
-	mptest4b.o mptest6.o mptest7.o mptest8.o mptest9.o mptestb.o
-MPTESTS = $(MPTESTOBJS:.o=)
-
-$(MPTESTOBJS): mptest%.o: tests/mptest-%.c $(LIBHDRS)
-	$(CC) $(CFLAGS) -o $@ -c $<
-
-$(MPTESTS): mptest%: mptest%.o libmpi.a
-	$(CC) $(CFLAGS) -o $@ $^  $(LIBS)
-
-tests: mptest1 mptest2 mptest3 mptest3a mptest4 mptest4a mptest4b mptest6 \
-	mptestb bbsrand
-
-utests: mptest7 mptest8 mptest9
-
-#---------------------------------------
-
-EXTRAOBJS = bbsrand.o bbs_rand.o prng.o
-UTILOBJS = primegen.o metime.o identest.o basecvt.o fact.o exptmod.o pi.o \
-	makeprime.o gcd.o invmod.o lap.o isprime.o \
-	dec2hex.o hex2dec.o
-UTILS = $(UTILOBJS:.o=) 
-
-$(UTILS): % : %.o libmpi.a
-	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
-
-$(UTILOBJS) $(EXTRAOBJS): %.o : utils/%.c $(LIBHDRS)
-	$(CC) $(CFLAGS) -o $@ -c $<
-
-prng: prng.o bbs_rand.o libmpi.a
-	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
-
-bbsrand: bbsrand.o bbs_rand.o libmpi.a
-	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
-
-utils: $(UTILS) prng bbsrand
-
-#---------------------------------------
-
-test-info.c: test-arrays.txt
-	$(PERL) make-test-arrays test-arrays.txt > test-info.c
-
-mpi-test.o: mpi-test.c test-info.c $(LIBHDRS)
-	$(CC) $(CFLAGS) -o $@ -c $<
-
-mpi-test: mpi-test.o libmpi.a
-	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
-
-mdxptest.o: mdxptest.c $(LIBHDRS) mpi-priv.h
-
-mdxptest: mdxptest.o libmpi.a
-	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
-
-mulsqr.o: mulsqr.c logtab.h mpi.h mpi-config.h mpprime.h 
-	$(CC) $(CFLAGS) -DMP_SQUARE=1 -o $@ -c mulsqr.c 
-
-mulsqr: mulsqr.o libmpi.a
-	$(CC) $(CFLAGS) -o $@ $^ $(LIBS)
-
-#---------------------------------------
-
-alltests: tests utests mpi-test
-
-tools: $(TOOLS)
-
-doc:
-	(cd doc; ./build)
-
-clean:
-	rm -f *.o *.a *.i
-	rm -f core
-	rm -f *~ .*~
-	rm -f utils/*.o
-	rm -f utils/core
-	rm -f utils/*~ utils/.*~
-
-clobber: clean
-	rm -f $(TOOLS) $(UTILS)
-
-distclean: clean
-	rm -f mptest? mpi-test metime mulsqr karatsuba
-	rm -f mptest?a mptest?b
-	rm -f utils/mptest?
-	rm -f test-info.c logtab.h
-	rm -f libmpi.a
-	rm -f $(TOOLS)
-
-dist: Makefile $(HDRS) $(SRCS) $(DOCS)
-	tar -cvf mpi-$(VERS).tar Makefile $(HDRS) $(SRCS) $(DOCS)
-	pgps -ab mpi-$(VERS).tar
-	chmod +r mpi-$(VERS).tar.asc
-	gzip -9 mpi-$(VERS).tar
-
-# END
deleted file mode 100644
--- a/lib/freebl/mpi/Makefile.os2
+++ /dev/null
@@ -1,243 +0,0 @@
-#
-# Makefile.win - gmake Makefile for building MPI with VACPP on OS/2
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-## Define CC to be the C compiler you wish to use.  The GNU cc
-## compiler (gcc) should work, at the very least
-#CC=cc
-#CC=gcc
-CC=icc.exe
-AS=alp.exe
-
-## 
-## Define PERL to point to your local Perl interpreter.  It
-## should be Perl 5.x, although it's conceivable that Perl 4
-## might work ... I haven't tested it.
-##
-#PERL=/usr/bin/perl
-#PERL=perl
-
-##
-## Define CFLAGS to contain any local options your compiler
-## setup requires.
-##
-## Conditional compilation options are no longer here; see
-## the file 'mpi-config.h' instead.
-##
-MPICMN = -I. -DMP_API_COMPATIBLE -DMP_IOFUNC -DMP_USE_UINT_DIGIT -DMP_NO_MP_WORD
-
-#OS/2
-AS_SRCS = mpi_x86.asm
-MPICMN += -DMP_ASSEMBLY_MULTIPLY -DMP_ASSEMBLY_SQUARE -DMP_ASSEMBLY_DIV_2DX1D
-#CFLAGS= -Od -Z7 -MD -W3 -nologo -D_X86_ -DXP_PC \
- -DDEBUG -D_DEBUG -UNDEBUG -DWIN32 -D_WINDOWS -DWIN95 $(MPICMN)
-#CFLAGS = -O2 -MD -W3 -nologo -D_X86_ -DXP_PC -UDEBUG -U_DEBUG -DNDEBUG \
- -DWIN32 -D_WINDOWS -DWIN95 $(MPICMN)
-#CFLAGS = -Od -Z7 -MD -W3 -nologo -D_X86_ -DXP_PC -UDEBUG -U_DEBUG -DNDEBUG \
- -DWIN32 -D_WINDOWS -DWIN95 $(MPICMN)
-CFLAGS = /Ti+ -D_X86_ -DXP_PC -UDEBUG -U_DEBUG -DNDEBUG \
- $(MPICMN)
-ASFLAGS =
-
-##
-## Define LIBS to include any libraries you need to link against.
-## If NO_TABLE is define, LIBS should include '-lm' or whatever is
-## necessary to bring in the math library.  Otherwise, it can be
-## left alone, unless your system has other peculiar requirements.
-##
-LIBS=#-lmalloc#-lefence#-lm
-
-## 
-## Define RANLIB to be the library header randomizer; you might not
-## need this on some systems (just set it to 'echo' on these systems,
-## such as IRIX)
-##
-RANLIB=echo
-
-##
-## This is the version string used for the documentation and 
-## building the distribution tarball.  Don't mess with it unless
-## you are releasing a new version
-VERS=1.7p6
-
-## ----------------------------------------------------------------------
-## You probably don't need to change anything below this line...
-##
-
-##
-## This is the list of source files that need to be packed into
-## the distribution file
-SRCS=   mpi.c mpprime.c mplogic.c mpmontg.c mpi-test.c primes.c tests/ \
-	utils/gcd.c utils/invmod.c utils/lap.c \
-	utils/ptab.pl utils/sieve.c utils/isprime.c\
-	utils/dec2hex.c utils/hex2dec.c utils/bbs_rand.c \
-	utils/bbsrand.c utils/prng.c utils/primegen.c \
-	utils/basecvt.c utils/makeprime.c\
-	utils/fact.c utils/exptmod.c utils/pi.c utils/metime.c \
-	utils/mpi.h utils/mpprime.h mulsqr.c \
-	make-test-arrays test-arrays.txt all-tests make-logtab \
-	types.pl stats timetest multest
-
-## These are the header files that go into the distribution file
-HDRS=mpi.h mpi-config.h utils/mpi.h utils/mpi-config.h mpprime.h mplogic.h \
-     utils/bbs_rand.h tests/mpi.h tests/mpprime.h
-
-## These are the documentation files that go into the distribution file
-DOCS=README doc utils/README utils/PRIMES 
-
-## This is the list of tools built by 'make tools'
-TOOLS=gcd.exe invmod.exe isprime.exe lap.exe dec2hex.exe hex2dec.exe \
- primegen.exe prng.exe basecvt.exe fact.exe exptmod.exe pi.exe makeprime.exe
-
-AS_OBJS = $(AS_SRCS:.asm=.obj)
-LIBOBJS = mpprime.obj mpmontg.obj mplogic.obj mpi.obj $(AS_OBJS)
-LIBHDRS = mpi-config.h mpi-priv.h mpi.h
-APPHDRS = mpi-config.h mpi.h mplogic.h mpprime.h
-
-
-help:
-	@ echo ""
-	@ echo "The following targets can be built with this Makefile:"
-	@ echo ""
-	@ echo "mpi.lib      - arithmetic and prime testing library"
-	@ echo "mpi-test.exe - test driver (requires MP_IOFUNC)"
-	@ echo "tools        - command line tools"
-	@ echo "doc          - manual pages for tools"
-	@ echo "clean        - clean up objects and such"
-	@ echo "distclean    - get ready for distribution"
-	@ echo "dist         - distribution tarball"
-	@ echo ""
-
-.SUFFIXES: .c .obj .i .lib .exe .asm
-
-.c.i:
-	$(CC) $(CFLAGS) -E $< > $@
-
-.c.obj: 
-	$(CC) $(CFLAGS) -c $<
-
-.asm.obj:
-	$(AS) $(ASFLAGS) $<
-
-.obj.exe:
-	$(CC) $(CFLAGS) -Fo$@ $<
-
-#---------------------------------------
-
-$(LIBOBJS): $(LIBHDRS)
-
-logtab.h: make-logtab
-	$(PERL) make-logtab > logtab.h
-
-mpi.obj: mpi.c logtab.h $(LIBHDRS)
-
-mplogic.obj: mplogic.c mpi-priv.h mplogic.h $(LIBHDRS)
-
-mpmontg.obj: mpmontg.c mpi-priv.h mplogic.h mpprime.h $(LIBHDRS)
-
-mpprime.obj: mpprime.c mpi-priv.h mpprime.h mplogic.h primes.c $(LIBHDRS)
-
-mpi_mips.obj: mpi_mips.s
-	$(CC) -Fo$@ $(ASFLAGS) -c mpi_mips.s
-
-mpi.lib: $(LIBOBJS)
-	ilib /out:mpi.lib $(LIBOBJS)
-	$(RANLIB) mpi.lib
-
-lib libs: mpi.lib
-
-#---------------------------------------
-
-MPTESTOBJS = mptest1.obj mptest2.obj mptest3.obj mptest3a.obj mptest4.obj \
- mptest4a.obj mptest4b.obj mptest6.obj mptest7.obj mptest8.obj mptest9.obj
-MPTESTS = $(MPTESTOBJS:.obj=.exe)
-
-$(MPTESTOBJS): mptest%.obj: tests/mptest-%.c $(LIBHDRS)
-	$(CC) $(CFLAGS) -Fo$@ -c $<
-
-$(MPTESTS): mptest%.exe: mptest%.obj mpi.lib $(LIBS)
-	$(CC) $(CFLAGS) -Fo$@ $^ 
-
-tests: mptest1.exe mptest2.exe mptest3.exe mptest3a.exe mptest4.exe \
- mptest4a.exe mptest4b.exe mptest6.exe bbsrand.exe
-
-utests: mptest7.exe mptest8.exe mptest9.exe
-
-#---------------------------------------
-
-EXTRAOBJS = bbsrand.obj bbs_rand.obj prng.obj
-UTILOBJS = primegen.obj metime.obj identest.obj basecvt.obj fact.obj \
- exptmod.obj pi.obj makeprime.obj karatsuba.obj gcd.obj invmod.obj lap.obj \
- isprime.obj dec2hex.obj hex2dec.obj
-UTILS = $(UTILOBJS:.obj=.exe) 
-
-$(UTILS): %.exe : %.obj mpi.lib $(LIBS)
-	$(CC) $(CFLAGS) -Fo$@ $^ 
-
-$(UTILOBJS) $(EXTRAOBJS): %.obj : utils/%.c $(LIBHDRS)
-	$(CC) $(CFLAGS) -Fo$@ -c $<
-
-prng.exe: prng.obj bbs_rand.obj mpi.lib $(LIBS)
-	$(CC) $(CFLAGS) -Fo$@ $^
-
-bbsrand.exe: bbsrand.obj bbs_rand.obj mpi.lib $(LIBS)
-	$(CC) $(CFLAGS) -Fo$@ $^
-
-utils: $(UTILS) prng.exe bbsrand.exe
-
-#---------------------------------------
-
-test-info.c: test-arrays.txt
-	$(PERL) make-test-arrays test-arrays.txt > test-info.c
-
-mpi-test.obj: mpi-test.c test-info.c $(LIBHDRS)
-	$(CC) $(CFLAGS) -Fo$@ -c $<
-
-mpi-test.exe: mpi-test.obj mpi.lib $(LIBS)
-	$(CC) $(CFLAGS) -Fo$@ $^
-
-mdxptest.obj: mdxptest.c $(LIBHDRS) mpi-priv.h
-
-mdxptest.exe: mdxptest.obj mpi.lib $(LIBS)
-	$(CC) $(CFLAGS) -Fo$@ $^
-
-mulsqr.obj: mulsqr.c logtab.h mpi.h mpi-config.h mpprime.h 
-	$(CC) $(CFLAGS) -DMP_SQUARE=1 -Fo$@ -c mulsqr.c 
-
-mulsqr.exe: mulsqr.obj mpi.lib $(LIBS)
-	$(CC) $(CFLAGS) -Fo$@ $^
-
-#---------------------------------------
-
-alltests: tests utests mpi-test.exe
-
-tools: $(TOOLS)
-
-doc:
-	(cd doc; ./build)
-
-clean:
-	rm -f *.obj *.lib *.pdb *.ilk
-	cd utils; rm -f *.obj *.lib *.pdb *.ilk
-
-distclean: clean
-	rm -f mptest? mpi-test metime mulsqr karatsuba
-	rm -f mptest?a mptest?b
-	rm -f utils/mptest?
-	rm -f test-info.c logtab.h
-	rm -f mpi.lib
-	rm -f $(TOOLS)
-
-dist: Makefile $(HDRS) $(SRCS) $(DOCS)
-	tar -cvf mpi-$(VERS).tar Makefile $(HDRS) $(SRCS) $(DOCS)
-	pgps -ab mpi-$(VERS).tar
-	chmod +r mpi-$(VERS).tar.asc
-	gzip -9 mpi-$(VERS).tar
-
-
-print: 
-	@echo LIBOBJS = $(LIBOBJS)
-# END
deleted file mode 100644
--- a/lib/freebl/mpi/Makefile.win
+++ /dev/null
@@ -1,254 +0,0 @@
-#
-# Makefile.win - gmake Makefile for building MPI with MSVC on NT
-
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-## Define CC to be the C compiler you wish to use.  The GNU cc
-## compiler (gcc) should work, at the very least
-#CC=cc
-#CC=gcc
-CC=cl.exe
-ifeq ($(CPU_ARCH),x86_64)
-AS=ml64.exe
-else
-AS=ml.exe
-endif
-
-## 
-## Define PERL to point to your local Perl interpreter.  It
-## should be Perl 5.x, although it's conceivable that Perl 4
-## might work ... I haven't tested it.
-##
-#PERL=/usr/bin/perl
-#PERL=perl
-
-##
-## Define CFLAGS to contain any local options your compiler
-## setup requires.
-##
-## Conditional compilation options are no longer here; see
-## the file 'mpi-config.h' instead.
-##
-MPICMN = -I. -DMP_API_COMPATIBLE -DMP_IOFUNC
-
-ifeq ($(CPU_ARCH),x86_64)
-AS_SRCS = mpi_x86_64.asm
-CFLAGS = -O2 -Z7 -MD -W3 -nologo -DXP_PC -UDEBUG -U_DEBUG -DNDEBUG \
- -DWIN32 -D_WIN64 -D_AMD64_ -D_M_AMD64 -D_WINDOWS -DWIN95 $(MPICMN)
-ASFLAGS = -Cp -Sn -Zi -I.
-else
-#NT
-AS_SRCS = mpi_x86.asm
-MPICMN += -DMP_ASSEMBLY_MULTIPLY -DMP_ASSEMBLY_SQUARE -DMP_ASSEMBLY_DIV_2DX1D
-#CFLAGS= -Od -Z7 -MD -W3 -nologo -D_X86_ -DXP_PC \
- -DDEBUG -D_DEBUG -UNDEBUG -DWIN32 -D_WINDOWS -DWIN95 $(MPICMN)
-#CFLAGS = -O2 -MD -W3 -nologo -D_X86_ -DXP_PC -UDEBUG -U_DEBUG -DNDEBUG \
- -DWIN32 -D_WINDOWS -DWIN95 $(MPICMN)
-#CFLAGS = -Od -Z7 -MD -W3 -nologo -D_X86_ -DXP_PC -UDEBUG -U_DEBUG -DNDEBUG \
- -DWIN32 -D_WINDOWS -DWIN95 $(MPICMN)
-CFLAGS = -O2 -Z7 -MD -W3 -nologo -D_X86_ -DXP_PC -UDEBUG -U_DEBUG -DNDEBUG \
- -DWIN32 -D_WINDOWS -DWIN95 $(MPICMN)
-ASFLAGS = -Cp -Sn -Zi -coff -I. 
-endif
-
-##
-## Define LIBS to include any libraries you need to link against.
-## If NO_TABLE is define, LIBS should include '-lm' or whatever is
-## necessary to bring in the math library.  Otherwise, it can be
-## left alone, unless your system has other peculiar requirements.
-##
-LIBS=#-lmalloc#-lefence#-lm
-
-## 
-## Define RANLIB to be the library header randomizer; you might not
-## need this on some systems (just set it to 'echo' on these systems,
-## such as IRIX)
-##
-RANLIB=echo
-
-##
-## This is the version string used for the documentation and 
-## building the distribution tarball.  Don't mess with it unless
-## you are releasing a new version
-VERS=1.7p6
-
-## ----------------------------------------------------------------------
-## You probably don't need to change anything below this line...
-##
-
-##
-## This is the list of source files that need to be packed into
-## the distribution file
-SRCS=   mpi.c mpprime.c mplogic.c mpmontg.c mpi-test.c primes.c tests/ \
-	utils/gcd.c utils/invmod.c utils/lap.c \
-	utils/ptab.pl utils/sieve.c utils/isprime.c\
-	utils/dec2hex.c utils/hex2dec.c utils/bbs_rand.c \
-	utils/bbsrand.c utils/prng.c utils/primegen.c \
-	utils/basecvt.c utils/makeprime.c\
-	utils/fact.c utils/exptmod.c utils/pi.c utils/metime.c \
-	utils/mpi.h utils/mpprime.h mulsqr.c \
-	make-test-arrays test-arrays.txt all-tests make-logtab \
-	types.pl stats timetest multest
-
-## These are the header files that go into the distribution file
-HDRS=mpi.h mpi-config.h utils/mpi.h utils/mpi-config.h mpprime.h mplogic.h \
-     utils/bbs_rand.h tests/mpi.h tests/mpprime.h
-
-## These are the documentation files that go into the distribution file
-DOCS=README doc utils/README utils/PRIMES 
-
-## This is the list of tools built by 'make tools'
-TOOLS=gcd.exe invmod.exe isprime.exe lap.exe dec2hex.exe hex2dec.exe \
- primegen.exe prng.exe basecvt.exe fact.exe exptmod.exe pi.exe makeprime.exe
-
-AS_OBJS = $(AS_SRCS:.asm=.obj)
-LIBOBJS = mpprime.obj mpmontg.obj mplogic.obj mpi.obj $(AS_OBJS)
-LIBHDRS = mpi-config.h mpi-priv.h mpi.h
-APPHDRS = mpi-config.h mpi.h mplogic.h mpprime.h
-
-
-help:
-	@ echo ""
-	@ echo "The following targets can be built with this Makefile:"
-	@ echo ""
-	@ echo "mpi.lib     - arithmetic and prime testing library"
-	@ echo "mpi-test     - test driver (requires MP_IOFUNC)"
-	@ echo "tools        - command line tools"
-	@ echo "doc          - manual pages for tools"
-	@ echo "clean        - clean up objects and such"
-	@ echo "distclean    - get ready for distribution"
-	@ echo "dist         - distribution tarball"
-	@ echo ""
-
-.SUFFIXES: .c .obj .i .lib .exe .asm
-
-.c.i:
-	$(CC) $(CFLAGS) -E $< > $@
-
-.c.obj: 
-	$(CC) $(CFLAGS) -c $<
-
-.asm.obj:
-	$(AS) $(ASFLAGS) -c $<
-
-.obj.exe:
-	$(CC) $(CFLAGS) -Fo$@ $<
-
-#---------------------------------------
-
-$(LIBOBJS): $(LIBHDRS)
-
-logtab.h: make-logtab
-	$(PERL) make-logtab > logtab.h
-
-mpi.obj: mpi.c logtab.h $(LIBHDRS)
-
-mplogic.obj: mplogic.c mpi-priv.h mplogic.h $(LIBHDRS)
-
-mpmontg.obj: mpmontg.c mpi-priv.h mplogic.h mpprime.h $(LIBHDRS)
-
-mpprime.obj: mpprime.c mpi-priv.h mpprime.h mplogic.h primes.c $(LIBHDRS)
-
-mpi_mips.obj: mpi_mips.s
-	$(CC) -Fo$@ $(ASFLAGS) -c mpi_mips.s
-
-mpi.lib: $(LIBOBJS)
-	ar -cvr mpi.lib $(LIBOBJS)
-	$(RANLIB) mpi.lib
-
-lib libs: mpi.lib
-
-#---------------------------------------
-
-MPTESTOBJS = mptest1.obj mptest2.obj mptest3.obj mptest3a.obj mptest4.obj \
- mptest4a.obj mptest4b.obj mptest6.obj mptest7.obj mptest8.obj mptest9.obj
-MPTESTS = $(MPTESTOBJS:.obj=.exe)
-
-$(MPTESTOBJS): mptest%.obj: tests/mptest-%.c $(LIBHDRS)
-	$(CC) $(CFLAGS) -Fo$@ -c $<
-
-$(MPTESTS): mptest%.exe: mptest%.obj mpi.lib $(LIBS)
-	$(CC) $(CFLAGS) -Fo$@ $^ 
-
-tests: mptest1.exe mptest2.exe mptest3.exe mptest3a.exe mptest4.exe \
- mptest4a.exe mptest4b.exe mptest6.exe bbsrand.exe
-
-utests: mptest7.exe mptest8.exe mptest9.exe
-
-#---------------------------------------
-
-EXTRAOBJS = bbsrand.obj bbs_rand.obj prng.obj
-UTILOBJS = primegen.obj metime.obj identest.obj basecvt.obj fact.obj \
- exptmod.obj pi.obj makeprime.obj karatsuba.obj gcd.obj invmod.obj lap.obj \
- isprime.obj dec2hex.obj hex2dec.obj
-UTILS = $(UTILOBJS:.obj=.exe) 
-
-$(UTILS): %.exe : %.obj mpi.lib $(LIBS)
-	$(CC) $(CFLAGS) -Fo$@ $^ 
-
-$(UTILOBJS) $(EXTRAOBJS): %.obj : utils/%.c $(LIBHDRS)
-	$(CC) $(CFLAGS) -Fo$@ -c $<
-
-prng.exe: prng.obj bbs_rand.obj mpi.lib $(LIBS)
-	$(CC) $(CFLAGS) -Fo$@ $^
-
-bbsrand.exe: bbsrand.obj bbs_rand.obj mpi.lib $(LIBS)
-	$(CC) $(CFLAGS) -Fo$@ $^
-
-utils: $(UTILS) prng.exe bbsrand.exe
-
-#---------------------------------------
-
-test-info.c: test-arrays.txt
-	$(PERL) make-test-arrays test-arrays.txt > test-info.c
-
-mpi-test.obj: mpi-test.c test-info.c $(LIBHDRS)
-	$(CC) $(CFLAGS) -Fo$@ -c $<
-
-mpi-test.exe: mpi-test.obj mpi.lib $(LIBS)
-	$(CC) $(CFLAGS) -Fo$@ $^
-
-mdxptest.obj: mdxptest.c $(LIBHDRS) mpi-priv.h
-
-mdxptest.exe: mdxptest.obj mpi.lib $(LIBS)
-	$(CC) $(CFLAGS) -Fo$@ $^
-
-mulsqr.obj: mulsqr.c logtab.h mpi.h mpi-config.h mpprime.h 
-	$(CC) $(CFLAGS) -DMP_SQUARE=1 -Fo$@ -c mulsqr.c 
-
-mulsqr.exe: mulsqr.obj mpi.lib $(LIBS)
-	$(CC) $(CFLAGS) -Fo$@ $^
-
-#---------------------------------------
-
-alltests: tests utests mpi-test.exe
-
-tools: $(TOOLS)
-
-doc:
-	(cd doc; ./build)
-
-clean:
-	rm -f *.obj *.lib *.pdb *.ilk
-	cd utils; rm -f *.obj *.lib *.pdb *.ilk
-
-distclean: clean
-	rm -f mptest? mpi-test metime mulsqr karatsuba
-	rm -f mptest?a mptest?b
-	rm -f utils/mptest?
-	rm -f test-info.c logtab.h
-	rm -f mpi.lib
-	rm -f $(TOOLS)
-
-dist: Makefile $(HDRS) $(SRCS) $(DOCS)
-	tar -cvf mpi-$(VERS).tar Makefile $(HDRS) $(SRCS) $(DOCS)
-	pgps -ab mpi-$(VERS).tar
-	chmod +r mpi-$(VERS).tar.asc
-	gzip -9 mpi-$(VERS).tar
-
-
-print: 
-	@echo LIBOBJS = $(LIBOBJS)
-# END
--- a/lib/freebl/mpi/README
+++ b/lib/freebl/mpi/README
@@ -62,24 +62,16 @@ code relies on having the full positive 
 digits and words.
 
 The remaining type definitions should be left alone, for the most
 part.  The code in the library does not make any significant
 assumptions about the sizes of things, but there is little if any
 reason to change the other parameters, so I would recommend you leave
 them as you found them.
 
-The library comes with a Perl script, 'types.pl', which will scan your
-current Makefile settings, and attempt to find good definitions for
-these types.  It relies on a Unix sort of build environment, so it
-probably won't work under MacOS or Windows, but it can be convenient
-if you're porting to a new flavour of Unix.  Just run 'types.pl' at
-the command line, and it will spit out its results to the standard
-output.
-
 
 Conventions
 -----------
 
 Most functions in the library return a value of type mp_err.  This
 permits the library to communicate success or various kinds of failure
 to the calling program.  The return values currently defined are:
 
@@ -625,102 +617,16 @@ fact.c          Computes the factorial o
 
 exptmod.c       Computes arbitrary precision modular exponentiation
                 from the command line (exptmod a b m -> a^b (mod m))
 
 Most of these can be built from the Makefile that comes with the
 library.  Try 'make tools', if your environment supports it.
 
 
-Testing the Library
--------------------
-
-Automatic test vectors are included, in the form of a program called
-'mpi-test'.  To build this program and run all the tests, simply
-invoke the shell script 'all-tests'.  If all the tests pass, you
-should see a message:
-
-        All tests passed
-
-If something went wrong, you'll get:
-
-        One or more tests failed.
-
-If this happens, scan back through the preceding lines, to see which
-test failed.  Any failure indicates a bug in the library, which needs
-to be fixed before it will give accurate results.  If you get any such
-thing, please let me know, and I'll try to fix it.  Please let me know
-what platform and compiler you were using, as well as which test
-failed.  If a reason for failure was given, please send me that text
-as well.
-
-If you're on a system where the standard Unix build tools don't work,
-you can build the 'mpi-test' program manually, and run it by hand.
-This is tedious and obnoxious, sorry.
-
-Further manual testing can be performed by building the manual testing
-programs, whose source is found in the 'tests' subdirectory.  Each
-test is in a source file called 'mptest-X.c'.  The Makefile contains a
-target to build all of them at once:
-
-        make tests
-
-Read the comments at the top of each source file to see what the
-driver is supposed to test.  You probably don't need to do this; these
-programs were only written to help me as I was developing the library.
-
-The relevant files are:
-
-mpi-test.c              The source for the test driver
-
-make-test-arrays        A Perl script to generate some of the internal
-                        data structures used by mpi-test.c
-
-test-arrays.txt         The source file for make-test-arrays
-
-all-tests               A Bourne shell script which runs all the
-                        tests in the mpi-test suite
-
-Running 'make mpi-test' should build the mpi-test program.  If you
-cannot use make, here is what needs to be done:
-
-(1) Use 'make-test-arrays' to generate the file 'test-info.c' from
-    the 'test-arrays.txt' file.  Since Perl can be found everywhere,
-    this should be no trouble.  Under Unix, this looks like:
-
-        make-test-arrays test-arrays.txt > test-info.c
-
-(2) Build the MPI library:
-
-        gcc -ansi -pedantic -Wall -c mpi.c
-
-(3) Build the mpi-test program:
-
-        gcc -ansi -pedantic -Wall -o mpi-test mpi.o mpi-test.c
-
-When you've got mpi-test, you can use 'all-tests' to run all the tests
-made available by mpi-test.  If any of them fail, there should be a
-diagnostic indicating what went wrong.  These are fairly high-level
-diagnostics, and won't really help you debug the problem; they're
-simply intended to help you isolate which function caused the problem.
-If you encounter a problem of this sort, feel free to e-mail me, and I
-will certainly attempt to help you debug it.
-
-Note:   Several of the tests hard-wired into 'mpi-test' operate under
-----    the assumption that you are using at least a 16-bit mp_digit 
-        type.  If that is not true, several tests might fail, because 
-        of range problems with the maximum digit value.
-
-        If you are using an 8-bit digit, you will also need to 
-        modify the code for mp_read_raw(), which assumes that
-        multiplication by 256 can be done with mp_mul_d(), a
-        fact that fails when DIGIT_MAX is 255.  You can replace
-        the call with s_mp_lshd(), which will give you the same
-        effect, and without doing as much work. :)
-
 Acknowledgements:
 ----------------
 
 The algorithms used in this library were drawn primarily from Volume
 2 of Donald Knuth's magnum opus, _The Art of Computer Programming_, 
 "Semi-Numerical Methods".  Barrett's algorithm for modular reduction
 came from Menezes, Oorschot, and Vanstone's _Handbook of Applied
 Cryptography_, Chapter 14.
deleted file mode 100755
--- a/lib/freebl/mpi/all-tests
+++ /dev/null
@@ -1,83 +0,0 @@
-#!/bin/sh
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-ECHO=/bin/echo
-MAKE=gmake
-
-$ECHO "\n** Running unit tests for MPI library\n"
-
-# Build the mpi-test program, which comprises all the unit tests for
-# the MPI library...
-
-$ECHO "Bringing mpi-test up to date ... "
-if $MAKE mpi-test ; then
-  :
-else
-  $ECHO " "
-  $ECHO "Make failed to build mpi-test."
-  $ECHO " "
-  exit 1
-fi
-
-if [ ! -x mpi-test ] ; then
-  $ECHO " "
-  $ECHO "Cannot find 'mpi-test' program, testing cannot continue."
-  $ECHO " "
-  exit 1
-fi
-
-# Get the list of available test suites...
-tests=`./mpi-test list | awk '{print $1}'`
-errs=0
-
-# Run each test suite and check the result code of mpi-test
-for test in $tests ; do
-  $ECHO "$test ... \c"
-  if ./mpi-test $test ; then
-    $ECHO "passed"
-  else
-    $ECHO "FAILED"
-    errs=1
-  fi
-done
-
-# If any tests failed, we'll stop at this point
-if [ "$errs" = "0" ] ; then
-  $ECHO "All unit tests passed"
-else
-  $ECHO "One or more tests failed"
-  exit 1
-fi
-
-# Now try to build the 'pi' program, and see if it can compute the
-# first thousand digits of pi correctly
-$ECHO "\n** Running other tests\n"
-
-$ECHO "Bringing 'pi' up to date ... "
-if $MAKE pi ; then
-    :
-else
-    $ECHO "\nMake failed to build pi.\n"
-    exit 1
-fi
-
-if [ ! -x pi ] ; then
-    $ECHO "\nCannot find 'pi' program; testing cannot continue.\n"
-    exit 1
-fi
-
-./pi 2000 > /tmp/pi.tmp.$$
-if cmp tests/pi2k.txt /tmp/pi.tmp.$$ ; then
-    $ECHO "Okay!  The pi test passes."
-else
-    $ECHO "Oops!  The pi test failed. :("
-    exit 1
-fi
-
-rm -f /tmp/pi.tmp.$$
-
-exit 0
-
-# Here there be dragons
deleted file mode 100644
--- a/lib/freebl/mpi/hppatch.adb
+++ /dev/null
@@ -1,21 +0,0 @@
-#/bin/sh
-#
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-# script to change the system id in an object file from PA-RISC 2.0 to 1.1
-
-adb -w $1 << EOF
-?m 0 -1 0
-0x0?X
-0x0?W (@0x0&~0x40000)|(~@0x0&0x40000)
-
-0?"change checksum"
-0x7c?X
-0x7c?W (@0x7c&~0x40000)|(~@0x7c&0x40000)
-$q
-EOF
-
-exit 0
-
deleted file mode 100755
--- a/lib/freebl/mpi/make-logtab
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/usr/bin/perl
-
-#
-# make-logtab
-#
-# Generate a table of logarithms of 2 in various bases, for use in
-# estimating the output sizes of various bases.
-
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-$ARRAYNAME = $ENV{'ARRAYNAME'} || "s_logv_2";
-$ARRAYTYPE = $ENV{'ARRAYTYPE'} || "float";
-
-printf("const %s %s[] = {\n   %0.9ff, %0.9ff, ", 
-       $ARRAYTYPE, $ARRAYNAME, 0, 0);
-$brk = 2;
-for($ix = 2; $ix < 64; $ix++) {
-    printf("%0.9ff, ", (log(2)/log($ix)));
-    $brk = ($brk + 1) & 3;
-    if(!$brk) {
-	printf(" /* %2d %2d %2d %2d */\n   ",
-	       $ix - 3, $ix - 2, $ix - 1, $ix);
-    }
-}
-printf("%0.9ff\n};\n\n", (log(2)/log($ix)));
-
-exit 0;
deleted file mode 100755
--- a/lib/freebl/mpi/make-test-arrays
+++ /dev/null
@@ -1,98 +0,0 @@
-#!/usr/bin/perl
-
-#
-# make-test-arrays
-#
-# Given a test-arrays file, which specifies the test suite names, the
-# names of the functions which perform those test suites, and
-# descriptive comments, this script generates C structures for the
-# mpi-test program.  The input consists of lines of the form:
-#
-# suite-name:function-name:comment
-#
-# The output is written to the standard output.  Blank lines are
-# ignored, and comments beginning with '#' are stripped.
-
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-# Read parameters from the environment, if available
-$NAMEVAR = $ENV{'NAMEVAR'} || "g_names";
-$COUNTVAR = $ENV{'COUNTVAR'} || "g_count";
-$FUNCVAR = $ENV{'FUNCVAR'} || "g_tests";
-$DESCVAR = $ENV{'DESCVAR'} || "g_descs";
-$FUNCLEN = 13;
-$NAMELEN = 18;
-$DESCLEN = 45;
-
-#------------------------------------------------------------------------
-# Suck in input from the files on the command line, or standard input
-while(<>) {
-    chomp;
-    s/\#.*$//;
-    next if /^\s*$/;
-
-    ($suite, $func, $desc) = split(/:/, $_);
-
-    $tmp = { "suite" => $suite,
-	     "func"  => $func,
-	     "desc"  => $desc };
-
-    push(@item, $tmp);
-}
-$count = scalar(@item);
-$last = pop(@item);
-
-#------------------------------------------------------------------------
-# Output the table of names
-print "/* Table mapping test suite names to index numbers */\n";
-printf("const int   %s = %d;\n", $COUNTVAR, $count);
-printf("const char *%s[] = {\n", $NAMEVAR);
-
-foreach $elt (@item) {
-    printf("   \"%s\",%s/* %s%s */\n", $elt->{"suite"},
-	   " " x ($NAMELEN - length($elt->{"suite"})),
-	   $elt->{"desc"},
-	   " " x ($DESCLEN - length($elt->{"desc"})));
-}
-printf("   \"%s\" %s/* %s%s */\n", $last->{"suite"},
-       " " x ($NAMELEN - length($last->{"suite"})),
-       $last->{"desc"},
-       " " x ($DESCLEN - length($last->{"desc"})));
-print "};\n\n";
-
-#------------------------------------------------------------------------
-# Output the driver function prototypes
-print "/* Test function prototypes */\n";
-foreach $elt (@item, $last) {
-    printf("int  %s(void);\n", $elt->{"func"});
-}
-print "\n";
-
-#------------------------------------------------------------------------
-# Output the table of functions
-print "/* Table mapping index numbers to functions */\n";
-printf("int (*%s[])(void)  = {\n   ", $FUNCVAR);
-$brk = 0;
-
-foreach $elt (@item) {
-    print($elt->{"func"}, ", ", 
-	  " " x ($FUNCLEN - length($elt->{"func"})));
-    $brk = ($brk + 1) & 3;
-    print "\n   " unless($brk);
-}
-print $last->{"func"}, "\n};\n\n";
-
-#------------------------------------------------------------------------
-# Output the table of descriptions
-print "/* Table mapping index numbers to descriptions */\n";
-printf("const char *%s[] = {\n", $DESCVAR);
-
-foreach $elt (@item) {
-    printf("   \"%s\",\n", $elt->{"desc"});
-}
-printf("   \"%s\"\n};\n\n", $last->{"desc"});
-
-exit 0;
-
deleted file mode 100644
--- a/lib/freebl/mpi/mdxptest.c
+++ /dev/null
@@ -1,306 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include "mpi.h"
-#include "mpi-priv.h"
-
-/* #define OLD_WAY 1  */
-
-/* This key is the 1024-bit test key used for speed testing of RSA private
-** key ops.
-*/
-
-#define CONST const
-
-static CONST unsigned char default_n[128] = {
-    0xc2, 0xae, 0x96, 0x89, 0xaf, 0xce, 0xd0, 0x7b, 0x3b, 0x35, 0xfd, 0x0f, 0xb1, 0xf4, 0x7a, 0xd1,
-    0x3c, 0x7d, 0xb5, 0x86, 0xf2, 0x68, 0x36, 0xc9, 0x97, 0xe6, 0x82, 0x94, 0x86, 0xaa, 0x05, 0x39,
-    0xec, 0x11, 0x51, 0xcc, 0x5c, 0xa1, 0x59, 0xba, 0x29, 0x18, 0xf3, 0x28, 0xf1, 0x9d, 0xe3, 0xae,
-    0x96, 0x5d, 0x6d, 0x87, 0x73, 0xf6, 0xf6, 0x1f, 0xd0, 0x2d, 0xfb, 0x2f, 0x7a, 0x13, 0x7f, 0xc8,
-    0x0c, 0x7a, 0xe9, 0x85, 0xfb, 0xce, 0x74, 0x86, 0xf8, 0xef, 0x2f, 0x85, 0x37, 0x73, 0x0f, 0x62,
-    0x4e, 0x93, 0x17, 0xb7, 0x7e, 0x84, 0x9a, 0x94, 0x11, 0x05, 0xca, 0x0d, 0x31, 0x4b, 0x2a, 0xc8,
-    0xdf, 0xfe, 0xe9, 0x0c, 0x13, 0xc7, 0xf2, 0xad, 0x19, 0x64, 0x28, 0x3c, 0xb5, 0x6a, 0xc8, 0x4b,
-    0x79, 0xea, 0x7c, 0xce, 0x75, 0x92, 0x45, 0x3e, 0xa3, 0x9d, 0x64, 0x6f, 0x04, 0x69, 0x19, 0x17
-};
-
-static CONST unsigned char default_d[128] = {
-    0x13, 0xcb, 0xbc, 0xf2, 0xf3, 0x35, 0x8c, 0x6d, 0x7b, 0x6f, 0xd9, 0xf3, 0xa6, 0x9c, 0xbd, 0x80,
-    0x59, 0x2e, 0x4f, 0x2f, 0x11, 0xa7, 0x17, 0x2b, 0x18, 0x8f, 0x0f, 0xe8, 0x1a, 0x69, 0x5f, 0x6e,
-    0xac, 0x5a, 0x76, 0x7e, 0xd9, 0x4c, 0x6e, 0xdb, 0x47, 0x22, 0x8a, 0x57, 0x37, 0x7a, 0x5e, 0x94,
-    0x7a, 0x25, 0xb5, 0xe5, 0x78, 0x1d, 0x3c, 0x99, 0xaf, 0x89, 0x7d, 0x69, 0x2e, 0x78, 0x9d, 0x1d,
-    0x84, 0xc8, 0xc1, 0xd7, 0x1a, 0xb2, 0x6d, 0x2d, 0x8a, 0xd9, 0xab, 0x6b, 0xce, 0xae, 0xb0, 0xa0,
-    0x58, 0x55, 0xad, 0x5c, 0x40, 0x8a, 0xd6, 0x96, 0x08, 0x8a, 0xe8, 0x63, 0xe6, 0x3d, 0x6c, 0x20,
-    0x49, 0xc7, 0xaf, 0x0f, 0x25, 0x73, 0xd3, 0x69, 0x43, 0x3b, 0xf2, 0x32, 0xf8, 0x3d, 0x5e, 0xee,
-    0x7a, 0xca, 0xd6, 0x94, 0x55, 0xe5, 0xbd, 0x25, 0x34, 0x8d, 0x63, 0x40, 0xb5, 0x8a, 0xc3, 0x01
-};
-
-#define DEFAULT_ITERS 50
-
-typedef clock_t timetype;
-#define gettime(x) *(x) = clock()
-#define subtime(a, b) a -= b
-#define msec(x) ((clock_t)((double)x * 1000.0 / CLOCKS_PER_SEC))
-#define sec(x) (x / CLOCKS_PER_SEC)
-
-struct TimingContextStr {
-    timetype start;
-    timetype end;
-    timetype interval;
-
-    int minutes;
-    int seconds;
-    int millisecs;
-};
-
-typedef struct TimingContextStr TimingContext;
-
-TimingContext *
-CreateTimingContext(void)
-{
-    return (TimingContext *)malloc(sizeof(TimingContext));
-}
-
-void
-DestroyTimingContext(TimingContext *ctx)
-{
-    free(ctx);
-}
-
-void
-TimingBegin(TimingContext *ctx)
-{
-    gettime(&ctx->start);
-}
-
-static void
-timingUpdate(TimingContext *ctx)
-{
-
-    ctx->millisecs = msec(ctx->interval) % 1000;
-    ctx->seconds = sec(ctx->interval);
-    ctx->minutes = ctx->seconds / 60;
-    ctx->seconds %= 60;
-}
-
-void
-TimingEnd(TimingContext *ctx)
-{
-    gettime(&ctx->end);
-    ctx->interval = ctx->end;
-    subtime(ctx->interval, ctx->start);
-    timingUpdate(ctx);
-}
-
-char *
-TimingGenerateString(TimingContext *ctx)
-{
-    static char sBuf[4096];
-
-    sprintf(sBuf, "%d minutes, %d.%03d seconds", ctx->minutes,
-            ctx->seconds, ctx->millisecs);
-    return sBuf;
-}
-
-static void
-dumpBytes(unsigned char *b, int l)
-{
-    int i;
-    if (l <= 0)
-        return;
-    for (i = 0; i < l; ++i) {
-        if (i % 16 == 0)
-            printf("\t");
-        printf(" %02x", b[i]);
-        if (i % 16 == 15)
-            printf("\n");
-    }
-    if ((i % 16) != 0)
-        printf("\n");
-    printf("\n");
-}
-
-static mp_err
-testNewFuncs(const unsigned char *modulusBytes, int modulus_len)
-{
-    mp_err mperr = MP_OKAY;
-    mp_int modulus;
-    unsigned char buf[512];
-
-    mperr = mp_init(&modulus);
-    mperr = mp_read_unsigned_octets(&modulus, modulusBytes, modulus_len);
-    mperr = mp_to_fixlen_octets(&modulus, buf, modulus_len);
-    mperr = mp_to_fixlen_octets(&modulus, buf, modulus_len + 1);
-    mperr = mp_to_fixlen_octets(&modulus, buf, modulus_len + 4);
-    mperr = mp_to_unsigned_octets(&modulus, buf, modulus_len);
-    mperr = mp_to_signed_octets(&modulus, buf, modulus_len + 1);
-    mp_clear(&modulus);
-    return mperr;
-}
-
-int
-testModExp(const unsigned char *modulusBytes,
-           const unsigned int expo,
-           const unsigned char *input,
-           unsigned char *output,
-           int modulus_len)
-{
-    mp_err mperr = MP_OKAY;
-    mp_int modulus;
-    mp_int base;
-    mp_int exponent;
-    mp_int result;
-
-    mperr = mp_init(&modulus);
-    mperr += mp_init(&base);
-    mperr += mp_init(&exponent);
-    mperr += mp_init(&result);
-    /* we initialize all mp_ints unconditionally, even if some fail.
-    ** This guarantees that the DIGITS pointer is valid (even if null).
-    ** So, mp_clear will do the right thing below.
-    */
-    if (mperr == MP_OKAY) {
-        mperr = mp_read_unsigned_octets(&modulus,
-                                        modulusBytes + (sizeof default_n - modulus_len), modulus_len);
-        mperr += mp_read_unsigned_octets(&base, input, modulus_len);
-        mp_set(&exponent, expo);
-        if (mperr == MP_OKAY) {
-#if OLD_WAY
-            mperr = s_mp_exptmod(&base, &exponent, &modulus, &result);
-#else
-            mperr = mp_exptmod(&base, &exponent, &modulus, &result);
-#endif
-            if (mperr == MP_OKAY) {
-                mperr = mp_to_fixlen_octets(&result, output, modulus_len);
-            }
-        }
-    }
-    mp_clear(&base);
-    mp_clear(&result);
-
-    mp_clear(&modulus);
-    mp_clear(&exponent);
-
-    return (int)mperr;
-}
-
-int
-doModExp(const unsigned char *modulusBytes,
-         const unsigned char *exponentBytes,
-         const unsigned char *input,
-         unsigned char *output,
-         int modulus_len)
-{
-    mp_err mperr = MP_OKAY;
-    mp_int modulus;
-    mp_int base;
-    mp_int exponent;
-    mp_int result;
-
-    mperr = mp_init(&modulus);
-    mperr += mp_init(&base);
-    mperr += mp_init(&exponent);
-    mperr += mp_init(&result);
-    /* we initialize all mp_ints unconditionally, even if some fail.
-    ** This guarantees that the DIGITS pointer is valid (even if null).
-    ** So, mp_clear will do the right thing below.
-    */
-    if (mperr == MP_OKAY) {
-        mperr = mp_read_unsigned_octets(&modulus,
-                                        modulusBytes + (sizeof default_n - modulus_len), modulus_len);
-        mperr += mp_read_unsigned_octets(&exponent, exponentBytes, modulus_len);
-        mperr += mp_read_unsigned_octets(&base, input, modulus_len);
-        if (mperr == MP_OKAY) {
-#if OLD_WAY
-            mperr = s_mp_exptmod(&base, &exponent, &modulus, &result);
-#else
-            mperr = mp_exptmod(&base, &exponent, &modulus, &result);
-#endif
-            if (mperr == MP_OKAY) {
-                mperr = mp_to_fixlen_octets(&result, output, modulus_len);
-            }
-        }
-    }
-    mp_clear(&base);
-    mp_clear(&result);
-
-    mp_clear(&modulus);
-    mp_clear(&exponent);
-
-    return (int)mperr;
-}
-
-int
-main(int argc, char **argv)
-{
-    TimingContext *timeCtx;
-    char *progName;
-    long iters = DEFAULT_ITERS;
-    unsigned int modulus_len;
-    int i;
-    int rv;
-    unsigned char buf[1024];
-    unsigned char buf2[1024];
-
-    progName = strrchr(argv[0], '/');
-    if (!progName)
-        progName = strrchr(argv[0], '\\');
-    progName = progName ? progName + 1 : argv[0];
-
-    if (argc >= 2) {
-        iters = atol(argv[1]);
-    }
-
-    if (argc >= 3) {
-        modulus_len = atol(argv[2]);
-    } else
-        modulus_len = sizeof default_n;
-
-    /* no library init function !? */
-
-    memset(buf, 0x41, sizeof buf);
-
-    if (iters < 2) {
-        testNewFuncs(default_n, modulus_len);
-        testNewFuncs(default_n + 1, modulus_len - 1);
-        testNewFuncs(default_n + 2, modulus_len - 2);
-        testNewFuncs(default_n + 3, modulus_len - 3);
-
-        rv = testModExp(default_n, 0, buf, buf2, modulus_len);
-        dumpBytes((unsigned char *)buf2, modulus_len);
-
-        rv = testModExp(default_n, 1, buf, buf2, modulus_len);
-        dumpBytes((unsigned char *)buf2, modulus_len);
-
-        rv = testModExp(default_n, 2, buf, buf2, modulus_len);
-        dumpBytes((unsigned char *)buf2, modulus_len);
-
-        rv = testModExp(default_n, 3, buf, buf2, modulus_len);
-        dumpBytes((unsigned char *)buf2, modulus_len);
-    }
-    rv = doModExp(default_n, default_d, buf, buf2, modulus_len);
-    if (rv != 0) {
-        fprintf(stderr, "Error in modexp operation:\n");
-        exit(1);
-    }
-    dumpBytes((unsigned char *)buf2, modulus_len);
-
-    timeCtx = CreateTimingContext();
-    TimingBegin(timeCtx);
-    i = iters;
-    while (i--) {
-        rv = doModExp(default_n, default_d, buf, buf2, modulus_len);
-        if (rv != 0) {
-            fprintf(stderr, "Error in modexp operation\n");
-            exit(1);
-        }
-    }
-    TimingEnd(timeCtx);
-    printf("%ld iterations in %s\n", iters, TimingGenerateString(timeCtx));
-
-    return 0;
-}
--- a/lib/freebl/mpi/mpcpucache.c
+++ b/lib/freebl/mpi/mpcpucache.c
@@ -12,17 +12,17 @@
  * cache line exists, it should return the smallest line size (which is
  * usually the L1 cache).
  *
  * mp_modexp uses this information to make sure that private key information
  * isn't being leaked through the cache.
  *
  * Currently the file returns good data for most modern x86 processors, and
  * reasonable data on 64-bit ppc processors. All other processors are assumed
- * to have a cache line size of 32 bytes unless modified by target.mk.
+ * to have a cache line size of 32 bytes.
  *
  */
 
 #if defined(i386) || defined(__i386) || defined(__X86__) || defined(_M_IX86) || defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64)
 /* X86 processors have special instructions that tell us about the cache */
 #include "string.h"
 
 #if defined(__x86_64__) || defined(__x86_64) || defined(_M_AMD64)
@@ -770,39 +770,18 @@ s_mpi_getProcessorLineSize()
  *
  * If there is no cache, return 0;
  *
  * define MPI_GET_PROCESSOR_LINE_SIZE_DEFINED so the generic functions
  * below aren't compiled.
  *
  */
 
-/* target.mk can define MPI_CACHE_LINE_SIZE if it's common for the family or
- * OS */
-#if defined(MPI_CACHE_LINE_SIZE) && !defined(MPI_GET_PROCESSOR_LINE_SIZE_DEFINED)
-
-unsigned long
-s_mpi_getProcessorLineSize()
-{
-    return MPI_CACHE_LINE_SIZE;
-}
-#define MPI_GET_PROCESSOR_LINE_SIZE_DEFINED 1
-#endif
-
 /* If no way to get the processor cache line size has been defined, assume
  * it's 32 bytes (most common value, does not significantly impact performance)
  */
 #ifndef MPI_GET_PROCESSOR_LINE_SIZE_DEFINED
 unsigned long
 s_mpi_getProcessorLineSize()
 {
     return 32;
 }
 #endif
-
-#ifdef TEST_IT
-#include <stdio.h>
-
-main()
-{
-    printf("line size = %d\n", s_mpi_getProcessorLineSize());
-}
-#endif
--- a/lib/freebl/mpi/mpmontg.c
+++ b/lib/freebl/mpi/mpmontg.c
@@ -200,17 +200,21 @@ mp_exptmod_f(const mp_int *montBase,
     mp_set(&accum1, 1);
     MP_CHECKOK(s_mp_to_mont(&accum1, mmm, &accum1));
     MP_CHECKOK(s_mp_pad(&accum1, nLen));
 
     oddPowSize = 2 * nLen + 1;
     dTmpSize = 2 * oddPowSize;
     dSize = sizeof(double) * (nLen * 4 + 1 +
                               ((odd_ints + 1) * oddPowSize) + dTmpSize);
-    dBuf = (double *)malloc(dSize);
+    dBuf = malloc(dSize);
+    if (!dBuf) {
+        res = MP_MEM;
+        goto CLEANUP;
+    }
     dm1 = dBuf;           /* array of d32 */
     dn = dBuf + nLen;     /* array of d32 */
     dSqr = dn + nLen;     /* array of d32 */
     d16Tmp = dSqr + nLen; /* array of d16 */
     dTmp = d16Tmp + oddPowSize;
 
     for (i = 0; i < odd_ints; ++i) {
         oddPowers[i] = dTmp;
deleted file mode 100755
--- a/lib/freebl/mpi/multest
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/bin/sh
-#
-# multest
-#
-# Run multiply and square timing tests, to compute a chart for the
-# current processor and compiler combination.
-
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-ECHO=/bin/echo
-MAKE=gmake
-
-$ECHO "\n** Running multiply and square timing tests\n"
-
-$ECHO "Bringing 'mulsqr' up to date ... "
-if $MAKE mulsqr ; then
-    :
-else
-    $ECHO "\nMake failed to build mulsqr.\n"
-    exit 1
-fi
-
-if [ ! -x ./mulsqr ] ; then
-    $ECHO "\nCannot find 'mulsqr' program, testing cannot continue.\n"
-    exit 1
-fi
-
-sizes='64 128 192 256 320 384 448 512 640 768 896 1024 1536 2048'
-ntests=500000
-
-$ECHO "Running timing tests, please wait ... "
-
-trap 'echo "oop!";rm -f tt*.tmp;exit 0' INT HUP
-
-touch tt$$.tmp
-$ECHO $ntests tests >> tt$$.tmp
-for size in $sizes ; do
-    $ECHO "$size bits ... \c"
-    set -A res `./mulsqr $ntests $size|head -3|tr -d '%'|awk '{print $2}'`
-    $ECHO $size"\t"${res[0]}"\t"${res[1]}"\t"${res[2]} >> tt$$.tmp
-    $ECHO "(done)"
-done
-mv tt$$.tmp mulsqr-results.txt
-rm -f tt$$.tmp
-
-$ECHO "\n** Running Karatsuba-Ofman multiplication tests\n"
-
-$ECHO "Brining 'karatsuba' up to date ... "
-if $MAKE karatsuba ; then
-    :
-else
-    $ECHO "\nMake failed to build karatsuba.\n"
-    exit 1
-fi
-
-if [ ! -x ./karatsuba ] ; then
-    $ECHO "\nCannot find 'karatsuba' program, testing cannot continue.\n"
-    exit 1
-fi
-
-ntests=100000
-
-trap 'echo "oop!";rm -f tt*.tmp;exit 0' INT HUP
-
-touch tt$$.tmp
-for size in $sizes ; do
-    $ECHO "$size bits ... "
-    ./karatsuba $ntests $size >> tt$$.tmp
-    tail -2 tt$$.tmp
-done
-mv tt$$.tmp karatsuba-results.txt
-rm -f tt$$.tmp
-
-exit 0
deleted file mode 100755
--- a/lib/freebl/mpi/stats
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/usr/bin/perl
-
-#
-# Treat each line as a sequence of comma and/or space delimited
-# floating point numbers, and compute basic statistics on them.
-# These are written to standard output
-
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-$min = 1.7976931348623157E+308;
-$max = 2.2250738585072014E-308;
-$sum = $num = 0;
-
-while(<>) {
-    chomp;
-
-    @nums = split(/[\s,]+/, $_);
-    next if($#nums < 0);
-
-    $num += scalar @nums;
-    foreach (@nums) {
-	$min = $_ if($_ < $min);
-	$max = $_ if($_ > $max);
-	$sum += $_;
-    }
-}
-
-if($num) {
-    $avg = $sum / $num;
-} else {
-    $min = $max = 0;
-}
-
-printf "%d\tmin=%.2f, avg=%.2f, max=%.2f, sum=%.2f\n",
-    $num, $min, $avg, $max, $sum;
-
-# end
deleted file mode 100644
--- a/lib/freebl/mpi/target.mk
+++ /dev/null
@@ -1,233 +0,0 @@
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-##
-## Define CFLAGS to contain any local options your compiler
-## setup requires.
-##
-## Conditional compilation options are no longer here; see
-## the file 'mpi-config.h' instead.
-##
-MPICMN = -I. -DMP_API_COMPATIBLE -DMP_IOFUNC
-CFLAGS= -O $(MPICMN)
-#CFLAGS=-ansi -fullwarn -woff 1521 -O3 $(MPICMN)
-#CFLAGS=-ansi -pedantic -Wall -O3 $(MPICMN)
-#CFLAGS=-ansi -pedantic -Wall -g -O2 -DMP_DEBUG=1 $(MPICMN)
-
-ifeq ($(TARGET),mipsIRIX)
-#IRIX
-#MPICMN += -DMP_MONT_USE_MP_MUL 
-MPICMN += -DMP_ASSEMBLY_MULTIPLY -DMP_ASSEMBLY_SQUARE
-MPICMN += -DMP_USE_UINT_DIGIT
-#MPICMN += -DMP_NO_MP_WORD
-AS_OBJS = mpi_mips.o
-#ASFLAGS = -O -OPT:Olimit=4000 -dollar -fullwarn -xansi -n32 -mips3 -exceptions
-ASFLAGS = -O -OPT:Olimit=4000 -dollar -fullwarn -xansi -n32 -mips3 
-#CFLAGS=-ansi -n32 -O3 -fullwarn -woff 1429 -D_SGI_SOURCE $(MPICMN)
-CFLAGS=-ansi -n32 -O2 -fullwarn -woff 1429 -D_SGI_SOURCE $(MPICMN)
-#CFLAGS=-ansi -n32 -g -fullwarn -woff 1429 -D_SGI_SOURCE $(MPICMN)
-#CFLAGS=-ansi -64 -O2 -fullwarn -woff 1429 -D_SGI_SOURCE -DMP_NO_MP_WORD \
- $(MPICMN)
-endif
-
-ifeq ($(TARGET),alphaOSF1)
-#Alpha/OSF1
-MPICMN += -DMP_ASSEMBLY_MULTIPLY
-AS_OBJS+= mpvalpha.o
-#CFLAGS= -O -Olimit 4000 -ieee_with_inexact -std1 -DOSF1 -D_REENTRANT $(MPICMN)
-CFLAGS= -O -Olimit 4000 -ieee_with_inexact -std1 -DOSF1 -D_REENTRANT \
- -DMP_NO_MP_WORD $(MPICMN)
-endif
-
-ifeq ($(TARGET),v9SOLARIS)
-#Solaris 64
-SOLARIS_FPU_FLAGS = -fast -xO5 -xrestrict=%all -xchip=ultra -xarch=v9a -KPIC -mt
-#SOLARIS_FPU_FLAGS = -fast -xO5 -xrestrict=%all -xdepend -xchip=ultra -xarch=v9a -KPIC -mt
-SOLARIS_ASM_FLAGS = -xchip=ultra -xarch=v9a -KPIC -mt 
-AS_OBJS += montmulfv9.o 
-AS_OBJS += mpi_sparc.o mpv_sparcv9.o
-MPICMN += -DMP_USE_UINT_DIGIT 
-#MPICMN += -DMP_NO_MP_WORD 
-MPICMN += -DMP_ASSEMBLY_MULTIPLY 
-MPICMN += -DMP_USING_MONT_MULF
-CFLAGS= -O -KPIC -DSVR4 -DSYSV -D__svr4 -D__svr4__ -DSOLARIS -D_REENTRANT \
- -DSOLARIS2_8 -xarch=v9 -DXP_UNIX $(MPICMN)
-#CFLAGS= -g -KPIC -DSVR4 -DSYSV -D__svr4 -D__svr4__ -DSOLARIS -D_REENTRANT \
- -DSOLARIS2_8 -xarch=v9 -DXP_UNIX $(MPICMN)
-endif
-
-ifeq ($(TARGET),v8plusSOLARIS)
-#Solaris 32
-SOLARIS_FPU_FLAGS = -fast -xO5 -xrestrict=%all -xdepend -xchip=ultra -xarch=v8plusa -KPIC -mt
-SOLARIS_ASM_FLAGS = -xchip=ultra -xarch=v8plusa -KPIC -mt 
-AS_OBJS += montmulfv8.o 
-AS_OBJS += mpi_sparc.o mpv_sparcv8.o
-#AS_OBJS = montmulf.o
-MPICMN += -DMP_ASSEMBLY_MULTIPLY 
-MPICMN += -DMP_USING_MONT_MULF 
-MPICMN += -DMP_USE_UINT_DIGIT
-MPICMN += -DMP_NO_MP_WORD
-CFLAGS=-O -KPIC -DSVR4 -DSYSV -D__svr4 -D__svr4__ -DSOLARIS -D_REENTRANT \
- -DSOLARIS2_6 -xarch=v8plus -DXP_UNIX $(MPICMN)
-endif
-
-ifeq ($(TARGET),v8SOLARIS)
-#Solaris 32
-#SOLARIS_FPU_FLAGS = -fast -xO5 -xrestrict=%all -xdepend -xchip=ultra -xarch=v8 -KPIC -mt
-#SOLARIS_ASM_FLAGS = -xchip=ultra -xarch=v8plusa -KPIC -mt 
-#AS_OBJS = montmulfv8.o mpi_sparc.o mpv_sparcv8.o
-#AS_OBJS = montmulf.o
-#MPICMN += -DMP_USING_MONT_MULF
-#MPICMN += -DMP_ASSEMBLY_MULTIPLY 
-MPICMN += -DMP_USE_LONG_LONG_MULTIPLY -DMP_USE_UINT_DIGIT
-MPICMN += -DMP_NO_MP_WORD
-CFLAGS=-O -KPIC -DSVR4 -DSYSV -D__svr4 -D__svr4__ -DSOLARIS -D_REENTRANT \
- -DSOLARIS2_6 -xarch=v8 -DXP_UNIX $(MPICMN)
-endif
-
-ifeq ($(TARGET),ia64HPUX)
-#HPUX 32 on ia64  -- 64 bit digits SCREAM.
-# This one is for DD32 which is the 32-bit ABI with 64-bit registers.
-CFLAGS= +O3 -DHPUX10 -D_POSIX_C_SOURCE=199506L -Aa +Z -DHPUX -Dhppa \
- -D_HPUX_SOURCE -Aa +e -z +p +DD32 -DHPUX11 -DXP_UNIX -Wl,+k $(MPICMN)
-#CFLAGS= -O -DHPUX10 -D_POSIX_C_SOURCE=199506L -Aa +Z -DHPUX -Dhppa \
- -D_HPUX_SOURCE -Aa +e -z +p +DD32 -DHPUX11 -DXP_UNIX -Wl,+k $(MPICMN)
-#CFLAGS= -g -DHPUX10 -D_POSIX_C_SOURCE=199506L -Ae +Z -DHPUX -Dhppa \
- -D_HPUX_SOURCE -Aa +e -z +p +DD32 -DHPUX11 -DXP_UNIX -Wl,+k $(MPICMN)
-endif
-
-ifeq ($(TARGET),ia64HPUX64)
-#HPUX 32 on ia64
-# This one is for DD64 which is the 64-bit ABI 
-CFLAGS= +O3 -DHPUX10 -D_POSIX_C_SOURCE=199506L -Aa +Z -DHPUX -Dhppa \
- -D_HPUX_SOURCE -Aa +e -z +p +DD64 -DHPUX11 -DXP_UNIX -Wl,+k $(MPICMN)
-#CFLAGS= -g -DHPUX10 -D_POSIX_C_SOURCE=199506L -Ae +Z -DHPUX -Dhppa \
- -D_HPUX_SOURCE -Aa +e -z +p +DD64 -DHPUX11 -DXP_UNIX -Wl,+k $(MPICMN)
-endif
-
-ifeq ($(TARGET),PA2.0WHPUX)
-#HPUX64 (HP PA 2.0 Wide) using MAXPY and 64-bit digits
-MPICMN += -DMP_ASSEMBLY_MULTIPLY -DMP_ASSEMBLY_SQUARE
-AS_OBJS = mpi_hp.o hpma512.o hppa20.o 
-CFLAGS= -O -DHPUX10 -D_POSIX_C_SOURCE=199506L -Ae +Z -DHPUX -Dhppa \
- -D_HPUX_SOURCE -Aa +e -z +DA2.0W +DS2.0 +O3 +DChpux -DHPUX11  -DXP_UNIX \
- $(MPICMN)
-#CFLAGS= -g -DHPUX10 -D_POSIX_C_SOURCE=199506L -Ae +Z -DHPUX -Dhppa \
- -D_HPUX_SOURCE -Aa +e -z +DA2.0W +DS2.0 +DChpux -DHPUX11  -DXP_UNIX \
- $(MPICMN)
-AS = $(CC) $(CFLAGS) -c
-endif
-
-ifeq ($(TARGET),PA2.0NHPUX)
-#HPUX32 (HP PA 2.0 Narrow) hybrid model, using 32-bit digits
-# This one is for DA2.0 (N) which is the 32-bit ABI with 64-bit registers.
-MPICMN += -DMP_ASSEMBLY_MULTIPLY -DMP_ASSEMBLY_SQUARE
-AS_OBJS = mpi_hp.o hpma512.o hppa20.o 
-CFLAGS= +O3 -DHPUX10 -D_POSIX_C_SOURCE=199506L -Ae +Z -DHPUX -Dhppa \
- -D_HPUX_SOURCE -Aa +e -z +DA2.0 +DS2.0 +DChpux -DHPUX11  -DXP_UNIX \
- -Wl,+k $(MPICMN)
-#CFLAGS= -g -DHPUX10 -D_POSIX_C_SOURCE=199506L -Ae +Z -DHPUX -Dhppa \
- -D_HPUX_SOURCE -Aa +e -z +DA2.0 +DS2.0 +DChpux -DHPUX11  -DXP_UNIX \
- -Wl,+k $(MPICMN)
-AS = $(CC) $(CFLAGS) -c
-endif
-
-ifeq ($(TARGET),PA1.1HPUX)
-#HPUX32 (HP PA 1.1) Pure 32 bit
-MPICMN += -DMP_USE_UINT_DIGIT -DMP_NO_MP_WORD
-#MPICMN += -DMP_USE_LONG_LONG_MULTIPLY
-CFLAGS= -O -DHPUX10 -D_POSIX_C_SOURCE=199506L -Ae +Z -DHPUX -Dhppa \
- -D_HPUX_SOURCE +DAportable +DS1.1 -DHPUX11 -DXP_UNIX $(MPICMN)
-##CFLAGS= -g -DHPUX10 -D_POSIX_C_SOURCE=199506L -Ae +Z -DHPUX -Dhppa \
-# -D_HPUX_SOURCE +DAportable +DS1.1 -DHPUX11 -DXP_UNIX $(MPICMN)
-endif
-
-ifeq ($(TARGET),32AIX)
-#
-CC = xlC_r
-MPICMN += -DMP_USE_UINT_DIGIT
-MPICMN += -DMP_NO_DIV_WORD
-#MPICMN += -DMP_NO_MUL_WORD
-MPICMN += -DMP_NO_ADD_WORD
-MPICMN += -DMP_NO_SUB_WORD
-#MPICMN += -DMP_NO_MP_WORD
-#MPICMN += -DMP_USE_LONG_LONG_MULTIPLY
-CFLAGS = -O -DAIX -DSYSV -qarch=com -DAIX4_3 -DXP_UNIX -UDEBUG -DNDEBUG  $(MPICMN)
-#CFLAGS = -g -DAIX -DSYSV -qarch=com -DAIX4_3 -DXP_UNIX -UDEBUG -DNDEBUG  $(MPICMN)
-#CFLAGS += -pg
-endif
-
-ifeq ($(TARGET),64AIX)
-#
-CC = xlC_r
-MPICMN += -DMP_USE_UINT_DIGIT
-CFLAGS = -O -O2 -DAIX -DSYSV -qarch=com -DAIX_64BIT -DAIX4_3 -DXP_UNIX -UDEBUG -DNDEBUG $(MPICMN)
-OBJECT_MODE=64
-export OBJECT_MODE
-endif
-
-ifeq ($(TARGET),x86LINUX)
-#Linux
-AS_OBJS = mpi_x86.o
-MPICMN += -DMP_ASSEMBLY_MULTIPLY -DMP_ASSEMBLY_SQUARE -DMP_ASSEMBLY_DIV_2DX1D
-MPICMN += -DMP_MONT_USE_MP_MUL -DMP_IS_LITTLE_ENDIAN
-CFLAGS= -O2 -fPIC -DLINUX1_2 -Di386 -D_XOPEN_SOURCE -DLINUX2_1 -ansi -Wall \
- -pipe -DLINUX -Dlinux -D_POSIX_SOURCE -D_BSD_SOURCE -DHAVE_STRERROR \
- -DXP_UNIX -UDEBUG -DNDEBUG -D_REENTRANT $(MPICMN)
-#CFLAGS= -g -fPIC -DLINUX1_2 -Di386 -D_XOPEN_SOURCE -DLINUX2_1 -ansi -Wall \
- -pipe -DLINUX -Dlinux -D_POSIX_SOURCE -D_BSD_SOURCE -DHAVE_STRERROR \
- -DXP_UNIX -DDEBUG -UNDEBUG -D_REENTRANT $(MPICMN)
-#CFLAGS= -g -fPIC -DLINUX1_2 -Di386 -D_XOPEN_SOURCE -DLINUX2_1 -ansi -Wall \
- -pipe -DLINUX -Dlinux -D_POSIX_SOURCE -D_BSD_SOURCE -DHAVE_STRERROR \
- -DXP_UNIX -UDEBUG -DNDEBUG -D_REENTRANT $(MPICMN)
-endif
-
-ifeq ($(TARGET),armLINUX)
-MPICMN += -DMP_ASSEMBLY_MULTIPLY -DMP_ASSEMBLY_SQUARE
-MPICMN += -DMP_USE_UINT_DIGIT 
-AS_OBJS += mpi_arm.o
-endif
-
-ifeq ($(TARGET),AMD64SOLARIS)
-ASFLAGS += -xarch=generic64
-AS_OBJS = mpi_amd64.o mpi_amd64_sun.o
-MP_CONFIG = -DMP_ASSEMBLY_MULTIPLY -DMPI_AMD64
-MP_CONFIG += -DMP_IS_LITTLE_ENDIAN
-CFLAGS = -xarch=generic64 -xO4 -I. -DMP_API_COMPATIBLE -DMP_IOFUNC $(MP_CONFIG)
-MPICMN += $(MP_CONFIG)
-
-mpi_amd64_asm.o: mpi_amd64_sun.s
-	$(AS) -xarch=generic64 -P -D_ASM mpi_amd64_sun.s
-endif
-
-ifeq ($(TARGET),WIN32)
-ifeq ($(CPU_ARCH),x86_64)
-AS_OBJS = mpi_amd64.obj mpi_amd64_masm.obj mp_comba_amd64_masm.asm
-CFLAGS  = -Od -Z7 -MDd -W3 -nologo -DDEBUG -D_DEBUG -UNDEBUG -DDEBUG_$(USER)
-CFLAGS += -DWIN32 -DWIN64 -D_WINDOWS -D_AMD_64_ -D_M_AMD64 -DWIN95 -DXP_PC
-CFLAGS += $(MPICMN)
-
-$(AS_OBJS): %.obj : %.asm
-	ml64 -Cp -Sn -Zi -coff -nologo -c $<
-
-$(LIBOBJS): %.obj : %.c 
-	cl $(CFLAGS) -Fo$@ -c $<
-else
-AS_OBJS = mpi_x86.obj
-MPICMN += -DMP_ASSEMBLY_MULTIPLY -DMP_ASSEMBLY_SQUARE -DMP_ASSEMBLY_DIV_2DX1D
-MPICMN += -DMP_USE_UINT_DIGIT -DMP_NO_MP_WORD -DMP_API_COMPATIBLE 
-MPICMN += -DMP_MONT_USE_MP_MUL 
-MPICMN += -DMP_CHAR_STORE_SLOW -DMP_IS_LITTLE_ENDIAN
-CFLAGS  = -Od -Z7 -MDd -W3 -nologo -DDEBUG -D_DEBUG -UNDEBUG -DDEBUG_$(USER)
-CFLAGS += -DWIN32 -D_WINDOWS -D_X86_ -DWIN95 -DXP_PC
-CFLAGS += $(MPICMN)
-
-$(AS_OBJS): %.obj : %.asm
-	ml -Cp -Sn -Zi -coff -nologo -c $<
-
-$(LIBOBJS): %.obj : %.c 
-	cl $(CFLAGS) -Fo$@ -c $<
-
-endif
-endif
deleted file mode 100644
--- a/lib/freebl/mpi/test-arrays.txt
+++ /dev/null
@@ -1,55 +0,0 @@
-#
-# Test suite table for MPI library
-#
-# Format of entries:
-# suite-name:function-name:description
-#
-# suite-name	The name used to identify this test in mpi-test
-# function-name	The function called to perform this test in mpi-test.c
-# description   A brief description of what the suite tests
-
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-list:test_list:print out a list of the available test suites
-copy:test_copy:test assignment of mp-int structures
-exchange:test_exch:test exchange of mp-int structures
-zero:test_zero:test zeroing of an mp-int
-set:test_set:test setting an mp-int to a small constant
-absolute-value:test_abs:test the absolute value function
-negate:test_neg:test the arithmetic negation function
-add-digit:test_add_d:test digit addition
-add:test_add:test full addition
-subtract-digit:test_sub_d:test digit subtraction
-subtract:test_sub:test full subtraction
-multiply-digit:test_mul_d:test digit multiplication
-multiply:test_mul:test full multiplication
-square:test_sqr:test full squaring function
-divide-digit:test_div_d:test digit division
-divide-2:test_div_2:test division by two
-divide-2d:test_div_2d:test division & remainder by 2^d
-divide:test_div:test full division
-expt-digit:test_expt_d:test digit exponentiation
-expt:test_expt:test full exponentiation
-expt-2:test_2expt:test power-of-two exponentiation
-modulo-digit:test_mod_d:test digit modular reduction
-modulo:test_mod:test full modular reduction
-mod-add:test_addmod:test modular addition
-mod-subtract:test_submod:test modular subtraction
-mod-multiply:test_mulmod:test modular multiplication
-mod-square:test_sqrmod:test modular squaring function
-mod-expt:test_exptmod:test full modular exponentiation
-mod-expt-digit:test_exptmod_d:test digit modular exponentiation
-mod-inverse:test_invmod:test modular inverse function
-compare-digit:test_cmp_d:test digit comparison function
-compare-zero:test_cmp_z:test zero comparison function
-compare:test_cmp:test general signed comparison
-compare-magnitude:test_cmp_mag:test general magnitude comparison
-parity:test_parity:test parity comparison functions
-gcd:test_gcd:test greatest common divisor functions
-lcm:test_lcm:test least common multiple function
-conversion:test_convert:test general radix conversion facilities
-binary:test_raw:test raw output format
-pprime:test_pprime:test probabilistic primality tester
-fermat:test_fermat:test Fermat pseudoprimality tester
deleted file mode 100644
--- a/lib/freebl/mpi/tests/LICENSE
+++ /dev/null
@@ -1,6 +0,0 @@
-Within this directory, each of the file listed below is licensed under 
-the terms given in the file LICENSE-MPL, also in this directory.
-
-pi1k.txt
-pi2k.txt
-pi5k.txt
deleted file mode 100644
--- a/lib/freebl/mpi/tests/LICENSE-MPL
+++ /dev/null
@@ -1,3 +0,0 @@
-This Source Code Form is subject to the terms of the Mozilla Public
-License, v. 2.0. If a copy of the MPL was not distributed with this
-file, You can obtain one at http://mozilla.org/MPL/2.0/.
deleted file mode 100644
--- a/lib/freebl/mpi/tests/mptest-1.c
+++ /dev/null
@@ -1,43 +0,0 @@
-/*
- * Simple test driver for MPI library
- *
- * Test 1: Simple input test (drives single-digit multiply and add,
- *         as well as I/O routines)
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <limits.h>
-
-#ifdef MAC_CW_SIOUX
-#include <console.h>
-#endif
-
-#include "mpi.h"
-
-int
-main(int argc, char *argv[])
-{
-    int ix;
-    mp_int mp;
-
-#ifdef MAC_CW_SIOUX
-    argc = ccommand(&argv);
-#endif
-
-    mp_init(&mp);
-
-    for (ix = 1; ix < argc; ix++) {
-        mp_read_radix(&mp, argv[ix], 10);
-        mp_print(&mp, stdout);
-        fputc('\n', stdout);
-    }
-
-    mp_clear(&mp);
-    return 0;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/tests/mptest-2.c
+++ /dev/null
@@ -1,62 +0,0 @@
-/*
- * Simple test driver for MPI library
- *
- * Test 2: Basic addition and subtraction test
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <limits.h>
-
-#include "mpi.h"
-
-int
-main(int argc, char *argv[])
-{
-    mp_int a, b, c;
-
-    if (argc < 3) {
-        fprintf(stderr, "Usage: %s <a> <b>\n", argv[0]);
-        return 1;
-    }
-
-    printf("Test 2: Basic addition and subtraction\n\n");
-
-    mp_init(&a);
-    mp_init(&b);
-
-    mp_read_radix(&a, argv[1], 10);
-    mp_read_radix(&b, argv[2], 10);
-    printf("a = ");
-    mp_print(&a, stdout);
-    fputc('\n', stdout);
-    printf("b = ");
-    mp_print(&b, stdout);
-    fputc('\n', stdout);
-
-    mp_init(&c);
-    printf("c = a + b\n");
-
-    mp_add(&a, &b, &c);
-    printf("c = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-
-    printf("c = a - b\n");
-
-    mp_sub(&a, &b, &c);
-    printf("c = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-
-    mp_clear(&c);
-    mp_clear(&b);
-    mp_clear(&a);
-
-    return 0;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/tests/mptest-3.c
+++ /dev/null
@@ -1,105 +0,0 @@
-/*
- * Simple test driver for MPI library
- *
- * Test 3: Multiplication, division, and exponentiation test
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <limits.h>
-
-#include <time.h>
-
-#include "mpi.h"
-
-#define EXPT 0 /* define nonzero to get exponentiate test */
-
-int
-main(int argc, char *argv[])
-{
-    int ix;
-    mp_int a, b, c, d;
-    mp_digit r;
-    mp_err res;
-
-    if (argc < 3) {
-        fprintf(stderr, "Usage: %s <a> <b>\n", argv[0]);
-        return 1;
-    }
-
-    printf("Test 3: Multiplication and division\n\n");
-    srand(time(NULL));
-
-    mp_init(&a);
-    mp_init(&b);
-
-    mp_read_variable_radix(&a, argv[1], 10);
-    mp_read_variable_radix(&b, argv[2], 10);
-    printf("a = ");
-    mp_print(&a, stdout);
-    fputc('\n', stdout);
-    printf("b = ");
-    mp_print(&b, stdout);
-    fputc('\n', stdout);
-
-    mp_init(&c);
-    printf("\nc = a * b\n");
-
-    mp_mul(&a, &b, &c);
-    printf("c = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-
-    printf("\nc = b * 32523\n");
-
-    mp_mul_d(&b, 32523, &c);
-    printf("c = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-
-    mp_init(&d);
-    printf("\nc = a / b, d = a mod b\n");
-
-    mp_div(&a, &b, &c, &d);
-    printf("c = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-    printf("d = ");
-    mp_print(&d, stdout);
-    fputc('\n', stdout);
-
-    ix = rand() % 256;
-    printf("\nc = a / %d, r = a mod %d\n", ix, ix);
-    mp_div_d(&a, (mp_digit)ix, &c, &r);
-    printf("c = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-    printf("r = %04X\n", r);
-
-#if EXPT
-    printf("\nc = a ** b\n");
-    mp_expt(&a, &b, &c);
-    printf("c = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-#endif
-
-    ix = rand() % 256;
-    printf("\nc = 2^%d\n", ix);
-    mp_2expt(&c, ix);
-    printf("c = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-
-    mp_clear(&d);
-    mp_clear(&c);
-    mp_clear(&b);
-    mp_clear(&a);
-
-    return 0;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/tests/mptest-3a.c
+++ /dev/null
@@ -1,123 +0,0 @@
-/*
- * Simple test driver for MPI library
- *
- * Test 3a: Multiplication vs. squaring timing test
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <limits.h>
-
-#include <time.h>
-
-#include "mpi.h"
-#include "mpprime.h"
-
-int
-main(int argc, char *argv[])
-{
-    int ix, num, prec = 8;
-    double d1, d2;
-    clock_t start, finish;
-    time_t seed;
-    mp_int a, c, d;
-
-    seed = time(NULL);
-
-    if (argc < 2) {
-        fprintf(stderr, "Usage: %s <num-tests> [<precision>]\n", argv[0]);
-        return 1;
-    }
-
-    if ((num = atoi(argv[1])) < 0)
-        num = -num;
-
-    if (!num) {
-        fprintf(stderr, "%s: must perform at least 1 test\n", argv[0]);
-        return 1;
-    }
-
-    if (argc > 2) {
-        if ((prec = atoi(argv[2])) <= 0)
-            prec = 8;
-        else
-            prec = (prec + (DIGIT_BIT - 1)) / DIGIT_BIT;
-    }
-
-    printf("Test 3a: Multiplication vs squaring timing test\n"
-           "Precision:  %d digits (%u bits)\n"
-           "# of tests: %d\n\n",
-           prec, prec * DIGIT_BIT, num);
-
-    mp_init_size(&a, prec);
-
-    mp_init(&c);
-    mp_init(&d);
-
-    printf("Verifying accuracy ... \n");
-    srand((unsigned int)seed);
-    for (ix = 0; ix < num; ix++) {
-        mpp_random_size(&a, prec);
-        mp_mul(&a, &a, &c);
-        mp_sqr(&a, &d);
-
-        if (mp_cmp(&c, &d) != 0) {
-            printf("Error!  Results not accurate:\n");
-            printf("a = ");
-            mp_print(&a, stdout);
-            fputc('\n', stdout);
-            printf("c = ");
-            mp_print(&c, stdout);
-            fputc('\n', stdout);
-            printf("d = ");
-            mp_print(&d, stdout);
-            fputc('\n', stdout);
-            mp_sub(&c, &d, &d);
-            printf("dif ");
-            mp_print(&d, stdout);
-            fputc('\n', stdout);
-            mp_clear(&c);
-            mp_clear(&d);
-            mp_clear(&a);
-            return 1;
-        }
-    }
-    printf("Accuracy is confirmed for the %d test samples\n", num);
-    mp_clear(&d);
-
-    printf("Testing squaring ... \n");
-    srand((unsigned int)seed);
-    start = clock();
-    for (ix = 0; ix < num; ix++) {
-        mpp_random_size(&a, prec);
-        mp_sqr(&a, &c);
-    }
-    finish = clock();
-
-    d2 = (double)(finish - start) / CLOCKS_PER_SEC;
-
-    printf("Testing multiplication ... \n");
-    srand((unsigned int)seed);
-    start = clock();
-    for (ix = 0; ix < num; ix++) {
-        mpp_random(&a);
-        mp_mul(&a, &a, &c);
-    }
-    finish = clock();
-
-    d1 = (double)(finish - start) / CLOCKS_PER_SEC;
-
-    printf("Multiplication time: %.3f sec (%.3f each)\n", d1, d1 / num);
-    printf("Squaring time:       %.3f sec (%.3f each)\n", d2, d2 / num);
-    printf("Improvement:         %.2f%%\n", (1.0 - (d2 / d1)) * 100.0);
-
-    mp_clear(&c);
-    mp_clear(&a);
-
-    return 0;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/tests/mptest-4.c
+++ /dev/null
@@ -1,111 +0,0 @@
-/*
- * Simple test driver for MPI library
- *
- * Test 4: Modular arithmetic tests
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <limits.h>
-
-#include "mpi.h"
-
-int
-main(int argc, char *argv[])
-{
-    int ix;
-    mp_int a, b, c, m;
-    mp_digit r;
-
-    if (argc < 4) {
-        fprintf(stderr, "Usage: %s <a> <b> <m>\n", argv[0]);
-        return 1;
-    }
-
-    printf("Test 4: Modular arithmetic\n\n");
-
-    mp_init(&a);
-    mp_init(&b);
-    mp_init(&m);
-
-    mp_read_radix(&a, argv[1], 10);
-    mp_read_radix(&b, argv[2], 10);
-    mp_read_radix(&m, argv[3], 10);
-    printf("a = ");
-    mp_print(&a, stdout);
-    fputc('\n', stdout);
-    printf("b = ");
-    mp_print(&b, stdout);
-    fputc('\n', stdout);
-    printf("m = ");
-    mp_print(&m, stdout);
-    fputc('\n', stdout);
-
-    mp_init(&c);
-    printf("\nc = a (mod m)\n");
-
-    mp_mod(&a, &m, &c);
-    printf("c = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-
-    printf("\nc = b (mod m)\n");
-
-    mp_mod(&b, &m, &c);
-    printf("c = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-
-    printf("\nc = b (mod 1853)\n");
-
-    mp_mod_d(&b, 1853, &r);
-    printf("c = %04X\n", r);
-
-    printf("\nc = (a + b) mod m\n");
-
-    mp_addmod(&a, &b, &m, &c);
-    printf("c = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-
-    printf("\nc = (a - b) mod m\n");
-
-    mp_submod(&a, &b, &m, &c);
-    printf("c = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-
-    printf("\nc = (a * b) mod m\n");
-
-    mp_mulmod(&a, &b, &m, &c);
-    printf("c = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-
-    printf("\nc = (a ** b) mod m\n");
-
-    mp_exptmod(&a, &b, &m, &c);
-    printf("c = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-
-    printf("\nIn-place modular squaring test:\n");
-    for (ix = 0; ix < 5; ix++) {
-        printf("a = (a * a) mod m   a = ");
-        mp_sqrmod(&a, &m, &a);
-        mp_print(&a, stdout);
-        fputc('\n', stdout);
-    }
-
-    mp_clear(&c);
-    mp_clear(&m);
-    mp_clear(&b);
-    mp_clear(&a);
-
-    return 0;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/tests/mptest-4a.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- *  mptest4a - modular exponentiation speed test
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <time.h>
-
-#include <sys/time.h>
-
-#include "mpi.h"
-#include "mpprime.h"
-
-typedef struct {
-    unsigned int sec;
-    unsigned int usec;
-} instant_t;
-
-instant_t
-now(void)
-{
-    struct timeval clk;
-    instant_t res;
-
-    res.sec = res.usec = 0;
-
-    if (gettimeofday(&clk, NULL) != 0)
-        return res;
-
-    res.sec = clk.tv_sec;
-    res.usec = clk.tv_usec;
-
-    return res;
-}
-
-extern mp_err s_mp_pad();
-
-int
-main(int argc, char *argv[])
-{
-    int ix, num, prec = 8;
-    unsigned int d;
-    instant_t start, finish;
-    time_t seed;
-    mp_int a, m, c;
-
-    seed = time(NULL);
-
-    if (argc < 2) {
-        fprintf(stderr, "Usage: %s <num-tests> [<precision>]\n", argv[0]);
-        return 1;
-    }
-
-    if ((num = atoi(argv[1])) < 0)
-        num = -num;
-
-    if (!num) {
-        fprintf(stderr, "%s: must perform at least 1 test\n", argv[0]);
-        return 1;
-    }
-
-    if (argc > 2) {
-        if ((prec = atoi(argv[2])) <= 0)
-            prec = 8;
-    }
-
-    printf("Test 3a: Modular exponentiation timing test\n"
-           "Precision:  %d digits (%d bits)\n"
-           "# of tests: %d\n\n",
-           prec, prec * DIGIT_BIT, num);
-
-    mp_init_size(&a, prec);
-    mp_init_size(&m, prec);
-    mp_init_size(&c, prec);
-    s_mp_pad(&a, prec);
-    s_mp_pad(&m, prec);
-    s_mp_pad(&c, prec);
-
-    printf("Testing modular exponentiation ... \n");
-    srand((unsigned int)seed);
-
-    start = now();
-    for (ix = 0; ix < num; ix++) {
-        mpp_random(&a);
-        mpp_random(&c);
-        mpp_random(&m);
-        mp_exptmod(&a, &c, &m, &c);
-    }
-    finish = now();
-
-    d = (finish.sec - start.sec) * 1000000;
-    d -= start.usec;
-    d += finish.usec;
-
-    printf("Total time elapsed:        %u usec\n", d);
-    printf("Time per exponentiation:   %u usec (%.3f sec)\n",
-           (d / num), (double)(d / num) / 1000000);
-
-    mp_clear(&c);
-    mp_clear(&a);
-    mp_clear(&m);
-
-    return 0;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/tests/mptest-4b.c
+++ /dev/null
@@ -1,107 +0,0 @@
-/*
- * mptest-4b.c
- *
- * Test speed of a large modular exponentiation of a primitive element
- * modulo a prime.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <time.h>
-
-#include <sys/time.h>
-
-#include "mpi.h"
-#include "mpprime.h"
-
-char *g_prime =
-    "34BD53C07350E817CCD49721020F1754527959C421C1533244769D4CF060A8B1C3DA"
-    "25094BE723FB1E2369B55FEEBBE0FAC16425161BF82684062B5EC5D7D47D1B23C117"
-    "0FA19745E44A55E148314E582EB813AC9EE5126295E2E380CACC2F6D206B293E5ED9"
-    "23B54EE961A8C69CD625CE4EC38B70C649D7F014432AEF3A1C93";
-char *g_gen = "5";
-
-typedef struct {
-    unsigned int sec;
-    unsigned int usec;
-} instant_t;
-
-instant_t
-now(void)
-{
-    struct timeval clk;
-    instant_t res;
-
-    res.sec = res.usec = 0;
-
-    if (gettimeofday(&clk, NULL) != 0)
-        return res;
-
-    res.sec = clk.tv_sec;
-    res.usec = clk.tv_usec;
-
-    return res;
-}
-
-extern mp_err s_mp_pad();
-
-int
-main(int argc, char *argv[])
-{
-    instant_t start, finish;
-    mp_int prime, gen, expt, res;
-    unsigned int ix, diff;
-    int num;
-
-    srand(time(NULL));
-
-    if (argc < 2) {
-        fprintf(stderr, "Usage: %s <num-tests>\n", argv[0]);
-        return 1;
-    }
-
-    if ((num = atoi(argv[1])) < 0)
-        num = -num;
-
-    if (num == 0)
-        ++num;
-
-    mp_init(&prime);
-    mp_init(&gen);
-    mp_init(&res);
-    mp_read_radix(&prime, g_prime, 16);
-    mp_read_radix(&gen, g_gen, 16);
-
-    mp_init_size(&expt, USED(&prime) - 1);
-    s_mp_pad(&expt, USED(&prime) - 1);
-
-    printf("Testing %d modular exponentations ... \n", num);
-
-    start = now();
-    for (ix = 0; ix < num; ix++) {
-        mpp_random(&expt);
-        mp_exptmod(&gen, &expt, &prime, &res);
-    }
-    finish = now();
-
-    diff = (finish.sec - start.sec) * 1000000;
-    diff += finish.usec;
-    diff -= start.usec;
-
-    printf("%d operations took %u usec (%.3f sec)\n",
-           num, diff, (double)diff / 1000000.0);
-    printf("That is %.3f sec per operation.\n",
-           ((double)diff / 1000000.0) / num);
-
-    mp_clear(&expt);
-    mp_clear(&res);
-    mp_clear(&gen);
-    mp_clear(&prime);
-
-    return 0;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/tests/mptest-5.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Simple test driver for MPI library
- *
- * Test 5: Other number theoretic functions
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <limits.h>
-
-#include "mpi.h"
-
-int
-main(int argc, char *argv[])
-{
-    mp_int a, b, c, x, y;
-
-    if (argc < 3) {
-        fprintf(stderr, "Usage: %s <a> <b>\n", argv[0]);
-        return 1;
-    }
-
-    printf("Test 5: Number theoretic functions\n\n");
-
-    mp_init(&a);
-    mp_init(&b);
-
-    mp_read_radix(&a, argv[1], 10);
-    mp_read_radix(&b, argv[2], 10);
-
-    printf("a = ");
-    mp_print(&a, stdout);
-    fputc('\n', stdout);
-    printf("b = ");
-    mp_print(&b, stdout);
-    fputc('\n', stdout);
-
-    mp_init(&c);
-    printf("\nc = (a, b)\n");
-
-    mp_gcd(&a, &b, &c);
-    printf("Euclid: c = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-    /*
-      mp_bgcd(&a, &b, &c);
-      printf("Binary: c = "); mp_print(&c, stdout); fputc('\n', stdout);
-    */
-    mp_init(&x);
-    mp_init(&y);
-    printf("\nc = (a, b) = ax + by\n");
-
-    mp_xgcd(&a, &b, &c, &x, &y);
-    printf("c = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-    printf("x = ");
-    mp_print(&x, stdout);
-    fputc('\n', stdout);
-    printf("y = ");
-    mp_print(&y, stdout);
-    fputc('\n', stdout);
-
-    printf("\nc = a^-1 (mod b)\n");
-    if (mp_invmod(&a, &b, &c) == MP_UNDEF) {
-        printf("a has no inverse mod b\n");
-    } else {
-        printf("c = ");
-        mp_print(&c, stdout);
-        fputc('\n', stdout);
-    }
-
-    mp_clear(&y);
-    mp_clear(&x);
-    mp_clear(&c);
-    mp_clear(&b);
-    mp_clear(&a);
-
-    return 0;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/tests/mptest-5a.c
+++ /dev/null
@@ -1,147 +0,0 @@
-/*
- * Simple test driver for MPI library
- *
- * Test 5a: Greatest common divisor speed test, binary vs. Euclid
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <limits.h>
-#include <time.h>
-
-#include <sys/time.h>
-
-#include "mpi.h"
-#include "mpprime.h"
-
-typedef struct {
-    unsigned int sec;
-    unsigned int usec;
-} instant_t;
-
-instant_t
-now(void)
-{
-    struct timeval clk;
-    instant_t res;
-
-    res.sec = res.usec = 0;
-
-    if (gettimeofday(&clk, NULL) != 0)
-        return res;
-
-    res.sec = clk.tv_sec;
-    res.usec = clk.tv_usec;
-
-    return res;
-}
-
-#define PRECISION 16
-
-int
-main(int argc, char *argv[])
-{
-    int ix, num, prec = PRECISION;
-    mp_int a, b, c, d;
-    instant_t start, finish;
-    time_t seed;
-    unsigned int d1, d2;
-
-    seed = time(NULL);
-
-    if (argc < 2) {
-        fprintf(stderr, "Usage: %s <num-tests>\n", argv[0]);
-        return 1;
-    }
-
-    if ((num = atoi(argv[1])) < 0)
-        num = -num;
-
-    printf("Test 5a: Euclid vs. Binary, a GCD speed test\n\n"
-           "Number of tests: %d\n"
-           "Precision:       %d digits\n\n",
-           num, prec);
-
-    mp_init_size(&a, prec);
-    mp_init_size(&b, prec);
-    mp_init(&c);
-    mp_init(&d);
-
-    printf("Verifying accuracy ... \n");
-    srand((unsigned int)seed);
-    for (ix = 0; ix < num; ix++) {
-        mpp_random_size(&a, prec);
-        mpp_random_size(&b, prec);
-
-        mp_gcd(&a, &b, &c);
-        mp_bgcd(&a, &b, &d);
-
-        if (mp_cmp(&c, &d) != 0) {
-            printf("Error!  Results not accurate:\n");
-            printf("a = ");
-            mp_print(&a, stdout);
-            fputc('\n', stdout);
-            printf("b = ");
-            mp_print(&b, stdout);
-            fputc('\n', stdout);
-            printf("c = ");
-            mp_print(&c, stdout);
-            fputc('\n', stdout);
-            printf("d = ");
-            mp_print(&d, stdout);
-            fputc('\n', stdout);
-
-            mp_clear(&a);
-            mp_clear(&b);
-            mp_clear(&c);
-            mp_clear(&d);
-            return 1;
-        }
-    }
-    mp_clear(&d);
-    printf("Accuracy confirmed for the %d test samples\n", num);
-
-    printf("Testing Euclid ... \n");
-    srand((unsigned int)seed);
-    start = now();
-    for (ix = 0; ix < num; ix++) {
-        mpp_random_size(&a, prec);
-        mpp_random_size(&b, prec);
-        mp_gcd(&a, &b, &c);
-    }
-    finish = now();
-
-    d1 = (finish.sec - start.sec) * 1000000;
-    d1 -= start.usec;
-    d1 += finish.usec;
-
-    printf("Testing binary ... \n");
-    srand((unsigned int)seed);
-    start = now();
-    for (ix = 0; ix < num; ix++) {
-        mpp_random_size(&a, prec);
-        mpp_random_size(&b, prec);
-        mp_bgcd(&a, &b, &c);
-    }
-    finish = now();
-
-    d2 = (finish.sec - start.sec) * 1000000;
-    d2 -= start.usec;
-    d2 += finish.usec;
-
-    printf("Euclidean algorithm time: %u usec\n", d1);
-    printf("Binary algorithm time:    %u usec\n", d2);
-    printf("Improvement:              %.2f%%\n",
-           (1.0 - ((double)d2 / (double)d1)) * 100.0);
-
-    mp_clear(&c);
-    mp_clear(&b);
-    mp_clear(&a);
-
-    return 0;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/tests/mptest-6.c
+++ /dev/null
@@ -1,78 +0,0 @@
-/*
- *  Simple test driver for MPI library
- *
- *  Test 6: Output functions
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <limits.h>
-
-#include "mpi.h"
-
-void
-print_buf(FILE *ofp, char *buf, int len)
-{
-    int ix, brk = 0;
-
-    for (ix = 0; ix < len; ix++) {
-        fprintf(ofp, "%02X ", buf[ix]);
-
-        brk = (brk + 1) & 0xF;
-        if (!brk)
-            fputc('\n', ofp);
-    }
-
-    if (brk)
-        fputc('\n', ofp);
-}
-
-int
-main(int argc, char *argv[])
-{
-    int ix, size;
-    mp_int a;
-    char *buf;
-
-    if (argc < 2) {
-        fprintf(stderr, "Usage: %s <a>\n", argv[0]);
-        return 1;
-    }
-
-    printf("Test 6: Output functions\n\n");
-
-    mp_init(&a);
-
-    mp_read_radix(&a, argv[1], 10);
-
-    printf("\nConverting to a string:\n");
-
-    printf("Rx Size Representation\n");
-    for (ix = 2; ix <= MAX_RADIX; ix++) {
-        size = mp_radix_size(&a, ix);
-
-        buf = calloc(size, sizeof(char));
-        mp_toradix(&a, buf, ix);
-        printf("%2d: %3d: %s\n", ix, size, buf);
-        free(buf);
-    }
-
-    printf("\nRaw output:\n");
-    size = mp_raw_size(&a);
-    buf = calloc(size, sizeof(char));
-
-    printf("Size:  %d bytes\n", size);
-
-    mp_toraw(&a, buf);
-    print_buf(stdout, buf, size);
-    free(buf);
-
-    mp_clear(&a);
-
-    return 0;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/tests/mptest-7.c
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- *  Simple test driver for MPI library
- *
- *  Test 7: Random and divisibility tests
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <limits.h>
-#include <time.h>
-
-#define MP_IOFUNC 1
-#include "mpi.h"
-
-#include "mpprime.h"
-
-int
-main(int argc, char *argv[])
-{
-    mp_digit num;
-    mp_int a, b;
-
-    srand(time(NULL));
-
-    if (argc < 3) {
-        fprintf(stderr, "Usage: %s <a> <b>\n", argv[0]);
-        return 1;
-    }
-
-    printf("Test 7: Random & divisibility tests\n\n");
-
-    mp_init(&a);
-    mp_init(&b);
-
-    mp_read_radix(&a, argv[1], 10);
-    mp_read_radix(&b, argv[2], 10);
-
-    printf("a = ");
-    mp_print(&a, stdout);
-    fputc('\n', stdout);
-    printf("b = ");
-    mp_print(&b, stdout);
-    fputc('\n', stdout);
-
-    if (mpp_divis(&a, &b) == MP_YES)
-        printf("a is divisible by b\n");
-    else
-        printf("a is not divisible by b\n");
-
-    if (mpp_divis(&b, &a) == MP_YES)
-        printf("b is divisible by a\n");
-    else
-        printf("b is not divisible by a\n");
-
-    printf("\nb = mpp_random()\n");
-    mpp_random(&b);
-    printf("b = ");
-    mp_print(&b, stdout);
-    fputc('\n', stdout);
-    mpp_random(&b);
-    printf("b = ");
-    mp_print(&b, stdout);
-    fputc('\n', stdout);
-    mpp_random(&b);
-    printf("b = ");
-    mp_print(&b, stdout);
-    fputc('\n', stdout);
-
-    printf("\nTesting a for divisibility by first 170 primes\n");
-    num = 170;
-    if (mpp_divis_primes(&a, &num) == MP_YES)
-        printf("It is divisible by at least one of them\n");
-    else
-        printf("It is not divisible by any of them\n");
-
-    mp_clear(&b);
-    mp_clear(&a);
-
-    return 0;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/tests/mptest-8.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- *  Simple test driver for MPI library
- *
- *  Test 8: Probabilistic primality tester
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <limits.h>
-#include <time.h>
-
-#define MP_IOFUNC 1
-#include "mpi.h"
-
-#include "mpprime.h"
-
-int
-main(int argc, char *argv[])
-{
-    int ix;
-    mp_digit num;
-    mp_int a;
-
-    srand(time(NULL));
-
-    if (argc < 2) {
-        fprintf(stderr, "Usage: %s <a>\n", argv[0]);
-        return 1;
-    }
-
-    printf("Test 8: Probabilistic primality testing\n\n");
-
-    mp_init(&a);
-
-    mp_read_radix(&a, argv[1], 10);
-
-    printf("a = ");
-    mp_print(&a, stdout);
-    fputc('\n', stdout);
-
-    printf("\nChecking for divisibility by small primes ... \n");
-    num = 170;
-    if (mpp_divis_primes(&a, &num) == MP_YES) {
-        printf("it is not prime\n");
-        goto CLEANUP;
-    }
-    printf("Passed that test (not divisible by any small primes).\n");
-
-    for (ix = 0; ix < 10; ix++) {
-        printf("\nPerforming Rabin-Miller test, iteration %d\n", ix + 1);
-
-        if (mpp_pprime(&a, 5) == MP_NO) {
-            printf("it is not prime\n");
-            goto CLEANUP;
-        }
-    }
-    printf("All tests passed; a is probably prime\n");
-
-CLEANUP:
-    mp_clear(&a);
-
-    return 0;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/tests/mptest-9.c
+++ /dev/null
@@ -1,109 +0,0 @@
-/*
- *    mptest-9.c
- *
- *   Test logical functions
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <limits.h>
-#include <time.h>
-
-#include "mpi.h"
-#include "mplogic.h"
-
-int
-main(int argc, char *argv[])
-{
-    mp_int a, b, c;
-    int pco;
-    mp_err res;
-
-    printf("Test 9: Logical functions\n\n");
-
-    if (argc < 3) {
-        fprintf(stderr, "Usage: %s <a> <b>\n", argv[0]);
-        return 1;
-    }
-
-    mp_init(&a);
-    mp_init(&b);
-    mp_init(&c);
-    mp_read_radix(&a, argv[1], 16);
-    mp_read_radix(&b, argv[2], 16);
-
-    printf("a       = ");
-    mp_print(&a, stdout);
-    fputc('\n', stdout);
-    printf("b       = ");
-    mp_print(&b, stdout);
-    fputc('\n', stdout);
-
-    mpl_not(&a, &c);
-    printf("~a      = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-
-    mpl_and(&a, &b, &c);
-    printf("a & b   = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-
-    mpl_or(&a, &b, &c);
-    printf("a | b   = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-
-    mpl_xor(&a, &b, &c);
-    printf("a ^ b   = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-
-    mpl_rsh(&a, &c, 1);
-    printf("a >>  1 = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-    mpl_rsh(&a, &c, 5);
-    printf("a >>  5 = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-    mpl_rsh(&a, &c, 16);
-    printf("a >> 16 = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-
-    mpl_lsh(&a, &c, 1);
-    printf("a <<  1 = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-    mpl_lsh(&a, &c, 5);
-    printf("a <<  5 = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-    mpl_lsh(&a, &c, 16);
-    printf("a << 16 = ");
-    mp_print(&c, stdout);
-    fputc('\n', stdout);
-
-    mpl_num_set(&a, &pco);
-    printf("population(a) = %d\n", pco);
-    mpl_num_set(&b, &pco);
-    printf("population(b) = %d\n", pco);
-
-    res = mpl_parity(&a);
-    if (res == MP_EVEN)
-        printf("a has even parity\n");
-    else
-        printf("a has odd parity\n");
-
-    mp_clear(&c);
-    mp_clear(&b);
-    mp_clear(&a);
-
-    return 0;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/tests/mptest-b.c
+++ /dev/null
@@ -1,230 +0,0 @@
-/*
- * Simple test driver for MPI library
- *
- * Test GF2m: Binary Polynomial Arithmetic
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <ctype.h>
-#include <limits.h>
-
-#include "mp_gf2m.h"
-
-int
-main(int argc, char *argv[])
-{
-    int ix;
-    mp_int pp, a, b, x, y, order;
-    mp_int c, d, e;
-    mp_digit r;
-    mp_err res;
-    unsigned int p[] = { 163, 7, 6, 3, 0 };
-    unsigned int ptemp[10];
-
-    printf("Test b: Binary Polynomial Arithmetic\n\n");
-
-    mp_init(&pp);
-    mp_init(&a);
-    mp_init(&b);
-    mp_init(&x);
-    mp_init(&y);
-    mp_init(&order);
-
-    mp_read_radix(&pp, "0800000000000000000000000000000000000000C9", 16);
-    mp_read_radix(&a, "1", 16);
-    mp_read_radix(&b, "020A601907B8C953CA1481EB10512F78744A3205FD", 16);
-    mp_read_radix(&x, "03F0EBA16286A2D57EA0991168D4994637E8343E36", 16);
-    mp_read_radix(&y, "00D51FBC6C71A0094FA2CDD545B11C5C0C797324F1", 16);
-    mp_read_radix(&order, "040000000000000000000292FE77E70C12A4234C33", 16);
-    printf("pp = ");
-    mp_print(&pp, stdout);
-    fputc('\n', stdout);
-    printf("a = ");
-    mp_print(&a, stdout);
-    fputc('\n', stdout);
-    printf("b = ");
-    mp_print(&b, stdout);
-    fputc('\n', stdout);
-    printf("x = ");
-    mp_print(&x, stdout);
-    fputc('\n', stdout);
-    printf("y = ");
-    mp_print(&y, stdout);
-    fputc('\n', stdout);
-    printf("order = ");
-    mp_print(&order, stdout);
-    fputc('\n', stdout);
-
-    mp_init(&c);
-    mp_init(&d);
-    mp_init(&e);
-
-    /* Test polynomial conversion */
-    ix = mp_bpoly2arr(&pp, ptemp, 10);
-    if (
-        (ix != 5) ||
-        (ptemp[0] != p[0]) ||
-        (ptemp[1] != p[1]) ||
-        (ptemp[2] != p[2]) ||
-        (ptemp[3] != p[3]) ||
-        (ptemp[4] != p[4])) {
-        printf("Polynomial to array conversion not correct\n");
-        return -1;
-    }
-
-    printf("Polynomial conversion test #1 successful.\n");
-    MP_CHECKOK(mp_barr2poly(p, &c));
-    if (mp_cmp(&pp, &c) != 0) {
-        printf("Array to polynomial conversion not correct\n");
-        return -1;
-    }
-    printf("Polynomial conversion test #2 successful.\n");
-
-    /* Test addition */
-    MP_CHECKOK(mp_badd(&a, &a, &c));
-    if (mp_cmp_z(&c) != 0) {
-        printf("a+a should equal zero\n");
-        return -1;
-    }
-    printf("Addition test #1 successful.\n");
-    MP_CHECKOK(mp_badd(&a, &b, &c));
-    MP_CHECKOK(mp_badd(&b, &c, &c));
-    if (mp_cmp(&c, &a) != 0) {
-        printf("c = (a + b) + b should equal a\n");
-        printf("a = ");
-        mp_print(&a, stdout);
-        fputc('\n', stdout);
-        printf("c = ");
-        mp_print(&c, stdout);
-        fputc('\n', stdout);
-        return -1;
-    }
-    printf("Addition test #2 successful.\n");
-
-    /* Test multiplication */
-    mp_set(&c, 2);
-    MP_CHECKOK(mp_bmul(&b, &c, &c));
-    MP_CHECKOK(mp_badd(&b, &c, &c));
-    mp_set(&d, 3);
-    MP_CHECKOK(mp_bmul(&b, &d, &d));
-    if (mp_cmp(&c, &d) != 0) {
-        printf("c = (2 * b) + b should equal c = 3 * b\n");
-        printf("c = ");
-        mp_print(&c, stdout);
-        fputc('\n', stdout);
-        printf("d = ");
-        mp_print(&d, stdout);
-        fputc('\n', stdout);
-        return -1;
-    }
-    printf("Multiplication test #1 successful.\n");
-
-    /* Test modular reduction */
-    MP_CHECKOK(mp_bmod(&b, p, &c));
-    if (mp_cmp(&b, &c) != 0) {
-        printf("c = b mod p should equal b\n");
-        printf("b = ");
-        mp_print(&b, stdout);
-        fputc('\n', stdout);
-        printf("c = ");
-        mp_print(&c, stdout);
-        fputc('\n', stdout);
-        return -1;
-    }
-    printf("Modular reduction test #1 successful.\n");
-    MP_CHECKOK(mp_badd(&b, &pp, &c));
-    MP_CHECKOK(mp_bmod(&c, p, &c));
-    if (mp_cmp(&b, &c) != 0) {
-        printf("c = (b + p) mod p should equal b\n");
-        printf("b = ");
-        mp_print(&b, stdout);
-        fputc('\n', stdout);
-        printf("c = ");
-        mp_print(&c, stdout);
-        fputc('\n', stdout);
-        return -1;
-    }
-    printf("Modular reduction test #2 successful.\n");
-    MP_CHECKOK(mp_bmul(&b, &pp, &c));
-    MP_CHECKOK(mp_bmod(&c, p, &c));
-    if (mp_cmp_z(&c) != 0) {
-        printf("c = (b * p) mod p should equal 0\n");
-        printf("c = ");
-        mp_print(&c, stdout);
-        fputc('\n', stdout);
-        return -1;
-    }
-    printf("Modular reduction test #3 successful.\n");
-
-    /* Test modular multiplication */
-    MP_CHECKOK(mp_bmulmod(&b, &pp, p, &c));
-    if (mp_cmp_z(&c) != 0) {
-        printf("c = (b * p) mod p should equal 0\n");
-        printf("c = ");
-        mp_print(&c, stdout);
-        fputc('\n', stdout);
-        return -1;
-    }
-    printf("Modular multiplication test #1 successful.\n");
-    mp_set(&c, 1);
-    MP_CHECKOK(mp_badd(&pp, &c, &c));
-    MP_CHECKOK(mp_bmulmod(&b, &c, p, &c));
-    if (mp_cmp(&b, &c) != 0) {
-        printf("c = (b * (p + 1)) mod p should equal b\n");
-        printf("b = ");
-        mp_print(&b, stdout);
-        fputc('\n', stdout);
-        printf("c = ");
-        mp_print(&c, stdout);
-        fputc('\n', stdout);
-        return -1;
-    }
-    printf("Modular multiplication test #2 successful.\n");
-
-    /* Test modular squaring */
-    MP_CHECKOK(mp_copy(&b, &c));
-    MP_CHECKOK(mp_bmulmod(&b, &c, p, &c));
-    MP_CHECKOK(mp_bsqrmod(&b, p, &d));
-    if (mp_cmp(&c, &d) != 0) {
-        printf("c = (b * b) mod p should equal d = b^2 mod p\n");
-        printf("c = ");
-        mp_print(&c, stdout);
-        fputc('\n', stdout);
-        printf("d = ");
-        mp_print(&d, stdout);
-        fputc('\n', stdout);
-        return -1;
-    }
-    printf("Modular squaring test #1 successful.\n");
-
-    /* Test modular division */
-    MP_CHECKOK(mp_bdivmod(&b, &x, &pp, p, &c));
-    MP_CHECKOK(mp_bmulmod(&c, &x, p, &c));
-    if (mp_cmp(&b, &c) != 0) {
-        printf("c = (b / x) * x mod p should equal b\n");
-        printf("b = ");
-        mp_print(&b, stdout);
-        fputc('\n', stdout);
-        printf("c = ");
-        mp_print(&c, stdout);
-        fputc('\n', stdout);
-        return -1;
-    }
-    printf("Modular division test #1 successful.\n");
-
-CLEANUP:
-
-    mp_clear(&order);
-    mp_clear(&y);
-    mp_clear(&x);
-    mp_clear(&b);
-    mp_clear(&a);
-    mp_clear(&pp);
-
-    return 0;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/tests/pi1k.txt
+++ /dev/null
@@ -1,1 +0,0 @@
-31415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679821480865132823066470938446095505822317253594081284811174502841027019385211055596446229489549303819644288109756659334461284756482337867831652712019091456485669234603486104543266482133936072602491412737245870066063155881748815209209628292540917153643678925903600113305305488204665213841469519415116094330572703657595919530921861173819326117931051185480744623799627495673518857527248912279381830119491298336733624406566430860213949463952247371907021798609437027705392171762931767523846748184676694051320005681271452635608277857713427577896091736371787214684409012249534301465495853710507922796892589235420199561121290219608640344181598136297747713099605187072113499999983729780499510597317328160963185950244594553469083026425223082533446850352619311881710100031378387528865875332083814206171776691473035982534904287554687311595628638823537875937519577818577805321712268066130019278766111959092164201989
deleted file mode 100644
--- a/lib/freebl/mpi/tests/pi2k.txt
+++ /dev/null
@@ -1,1 +0,0 @@
-314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019893809525720106548586327886593615338182796823030195203530185296899577362259941389124972177528347913151557485724245415069595082953311686172785588907509838175463746493931925506040092770167113900984882401285836160356370766010471018194295559619894676783744944825537977472684710404753464620804668425906949129331367702898915210475216205696602405803815019351125338243003558764024749647326391419927260426992279678235478163600934172164121992458631503028618297455570674983850549458858692699569092721079750930295532116534498720275596023648066549911988183479775356636980742654252786255181841757467289097777279380008164706001614524919217321721477235014144197356854816136115735255213347574184946843852332390739414333454776241686251898356948556209921922218427255025425688767179049460165346680498862723279178608578438382796797668145410095388378636095068006422512520511739298489608412848862694560424196528502221066118630674427862203919494504712371378696095636437191728746776465757396241389086583264599581339047802759010
deleted file mode 100644
--- a/lib/freebl/mpi/tests/pi5k.txt
+++ /dev/null
@@ -1,1 +0,0 @@
-314159265358979323846264338327950288419716939937510582097494459230781640628620899862803482534211706798214808651328230664709384460955058223172535940812848111745028410270193852110555964462294895493038196442881097566593344612847564823378678316527120190914564856692346034861045432664821339360726024914127372458700660631558817488152092096282925409171536436789259036001133053054882046652138414695194151160943305727036575959195309218611738193261179310511854807446237996274956735188575272489122793818301194912983367336244065664308602139494639522473719070217986094370277053921717629317675238467481846766940513200056812714526356082778577134275778960917363717872146844090122495343014654958537105079227968925892354201995611212902196086403441815981362977477130996051870721134999999837297804995105973173281609631859502445945534690830264252230825334468503526193118817101000313783875288658753320838142061717766914730359825349042875546873115956286388235378759375195778185778053217122680661300192787661119590921642019893809525720106548586327886593615338182796823030195203530185296899577362259941389124972177528347913151557485724245415069595082953311686172785588907509838175463746493931925506040092770167113900984882401285836160356370766010471018194295559619894676783744944825537977472684710404753464620804668425906949129331367702898915210475216205696602405803815019351125338243003558764024749647326391419927260426992279678235478163600934172164121992458631503028618297455570674983850549458858692699569092721079750930295532116534498720275596023648066549911988183479775356636980742654252786255181841757467289097777279380008164706001614524919217321721477235014144197356854816136115735255213347574184946843852332390739414333454776241686251898356948556209921922218427255025425688767179049460165346680498862723279178608578438382796797668145410095388378636095068006422512520511739298489608412848862694560424196528502221066118630674427862203919494504712371378696095636437191728746776465757396241389086583264599581339047802759009946576407895126946839835259570982582262052248940772671947826848260147699090264013639443745530506820349625245174939965143142980919065925093722169646151570985838741059788595977297549893016175392846813826868386894277415599185592524595395943104997252468084598727364469584865383673622262609912460805124388439045124413654976278079771569143599770012961608944169486855584840635342207222582848864815845602850601684273945226746767889525213852254995466672782398645659611635488623057745649803559363456817432411251507606947945109659609402522887971089314566913686722874894056010150330861792868092087476091782493858900971490967598526136554978189312978482168299894872265880485756401427047755513237964145152374623436454285844479526586782105114135473573952311342716610213596953623144295248493718711014576540359027993440374200731057853906219838744780847848968332144571386875194350643021845319104848100537061468067491927819119793995206141966342875444064374512371819217999839101591956181467514269123974894090718649423196156794520809514655022523160388193014209376213785595663893778708303906979207734672218256259966150142150306803844773454920260541466592520149744285073251866600213243408819071048633173464965145390579626856100550810665879699816357473638405257145910289706414011097120628043903975951567715770042033786993600723055876317635942187312514712053292819182618612586732157919841484882916447060957527069572209175671167229109816909152801735067127485832228718352093539657251210835791513698820914442100675103346711031412671113699086585163983150197016515116851714376576183515565088490998985998238734552833163550764791853589322618548963213293308985706420467525907091548141654985946163718027098199430992448895757128289059232332609729971208443357326548938239119325974636673058360414281388303203824903758985243744170291327656180937734440307074692112019130203303801976211011004492932151608424448596376698389522868478312355265821314495768572624334418930396864262434107732269780280731891544110104468232527162010526522721116603966655730925471105578537634668206531098965269186205647693125705863566201855810072936065987648611791045334885034611365768675324944166803962657978771855608455296541266540853061434443185867697514566140680070023787765913440171274947042056223053899456131407112700040785473326993908145466464588079727082668306343285878569830523580893306575740679545716377525420211495576158140025012622859413021647155097925923099079654737612551765675135751782966645477917450112996148903046399471329621073404375189573596145890193897131117904297828564750320319869151402870808599048010941214722131794764777262241425485454033215718530614228813758504306332175182979866223717215916077166925474873898665494945011465406284336639379003976926567214638530673609657120918076383271664162748888007869256029022847210403172118608204190004229661711963779213375751149595015660496318629472654736425230817703675159067350235072835405670403867435136222247715891504953098444893330963408780769325993978054193414473774418426312986080998886874132604721
deleted file mode 100755
--- a/lib/freebl/mpi/timetest
+++ /dev/null
@@ -1,99 +0,0 @@
-#!/bin/sh
-
-# Simple timing test for the MPI library.  Basically, we use prime
-# generation as a timing test, since it exercises most of the pathways
-# of the library fairly heavily.  The 'primegen' tool outputs a line
-# summarizing timing results.  We gather these and process them for
-# statistical information, which is collected into a file.
-
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-# Avoid using built-in shell echoes
-ECHO=/bin/echo
-MAKE=gmake
-PERL=perl
-
-# Use a fixed seed so timings will be more consistent
-# This one is the 11th-18th decimal digits of 'e'
-#export SEED=45904523
-SEED=45904523; export SEED
-
-#------------------------------------------------------------------------
-
-$ECHO "\n** Running timing tests for MPI library\n"
-
-$ECHO "Bringing 'metime' up to date ... "
-if $MAKE metime ; then
-    :
-else 
-    $ECHO "\nMake failed to build metime.\n"
-    exit 1
-fi
-
-if [ ! -x ./metime ] ; then 
-    $ECHO "\nCannot find 'metime' program, testing cannot continue.\n"
-    exit 1
-fi
-
-#------------------------------------------------------------------------
-
-$ECHO "Bringing 'primegen' up to date ... "
-if $MAKE primegen ; then
-    :
-else
-    $ECHO "\nMake failed to build primegen.\n"
-    exit 1
-fi
-
-if [ ! -x ./primegen ] ; then
-    $ECHO "\nCannot find 'primegen' program, testing cannot continue.\n"
-    exit 1
-fi
-
-#------------------------------------------------------------------------
-
-rm -f timing-results.txt
-touch timing-results.txt
-
-sizes="256 512 1024 2048"
-ntests=10
-
-trap 'echo "oop!";rm -f tt*.tmp timing-results.txt;exit 0' INT HUP
-
-$ECHO "\n-- Modular exponentiation\n"
-$ECHO "Modular exponentiation:" >> timing-results.txt
-
-$ECHO "Running $ntests modular exponentiations per test:"
-for size in $sizes ; do
-    $ECHO "- Gathering statistics for $size bits ... "
-    secs=`./metime $ntests $size | tail -1 | awk '{print $2}'`
-    $ECHO "$size: " $secs " seconds per op" >> timing-results.txt
-    tail -1 timing-results.txt
-done
-
-$ECHO "<done>";
-
-sizes="256 512 1024"
-ntests=1
-
-$ECHO "\n-- Prime generation\n"
-$ECHO "Prime generation:" >> timing-results.txt
-
-$ECHO "Generating $ntests prime values per test:"
-for size in $sizes ; do
-    $ECHO "- Gathering statistics for $size bits ... "
-    ./primegen $size $ntests | grep ticks | awk '{print $7}' | tr -d '(' > tt$$.tmp
-    $ECHO "$size:" >> timing-results.txt
-    $PERL stats tt$$.tmp >> timing-results.txt
-    tail -1 timing-results.txt
-    rm -f tt$$.tmp
-done
-
-$ECHO "<done>"
-
-trap 'rm -f tt*.tmp timing-results.txt' INT HUP
-
-exit 0
-
deleted file mode 100755
--- a/lib/freebl/mpi/types.pl
+++ /dev/null
@@ -1,127 +0,0 @@
-#!/usr/bin/perl
-
-#
-# types.pl - find recommended type definitions for digits and words
-#
-# This script scans the Makefile for the C compiler and compilation
-# flags currently in use, and using this combination, attempts to
-# compile a simple test program that outputs the sizes of the various
-# unsigned integer types, in bytes.  Armed with these, it finds all
-# the "viable" type combinations for mp_digit and mp_word, where
-# viability is defined by the requirement that mp_word be at least two
-# times the precision of mp_digit.
-#
-# Of these, the one with the largest digit size is chosen, and
-# appropriate typedef statements are written to standard output.
-
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-@_=split(/\//,$0);chomp($prog=pop(@_));
-
-# The array of integer types to be considered...
-@TYPES = ( 
-	   "unsigned char", 
-	   "unsigned short", 
-	   "unsigned int", 
-	   "unsigned long"
-);
-
-# Macro names for the maximum unsigned value of each type
-%TMAX = ( 
-	  "unsigned char"   => "UCHAR_MAX",
-	  "unsigned short"  => "USHRT_MAX",
-	  "unsigned int"    => "UINT_MAX",
-	  "unsigned long"   => "ULONG_MAX"
-);
-
-# Read the Makefile to find out which C compiler to use
-open(MFP, "<Makefile") or die "$prog: Makefile: $!\n";
-while(<MFP>) {
-    chomp;
-    if(/^CC=(.*)$/) {
-	$cc = $1;
-	last if $cflags;
-    } elsif(/^CFLAGS=(.*)$/) {
-	$cflags = $1;
-	last if $cc;
-    }
-}
-close(MFP);
-
-# If we couldn't find that, use 'cc' by default
-$cc = "cc" unless $cc;
-
-printf STDERR "Using '%s' as the C compiler.\n", $cc;
-
-print STDERR "Determining type sizes ... \n";
-open(OFP, ">tc$$.c") or die "$prog: tc$$.c: $!\n";
-print OFP "#include <stdio.h>\n\nint main(void)\n{\n";
-foreach $type (@TYPES) {
-    printf OFP "\tprintf(\"%%d\\n\", (int)sizeof(%s));\n", $type;
-}
-print OFP "\n\treturn 0;\n}\n";
-close(OFP);
-
-system("$cc $cflags -o tc$$ tc$$.c");
-
-die "$prog: unable to build test program\n" unless(-x "tc$$");
-
-open(IFP, "./tc$$|") or die "$prog: can't execute test program\n";
-$ix = 0;
-while(<IFP>) {
-    chomp;
-    $size{$TYPES[$ix++]} = $_;
-}
-close(IFP);
-
-unlink("tc$$");
-unlink("tc$$.c");
-
-print STDERR "Selecting viable combinations ... \n";
-while(($type, $size) = each(%size)) {
-    push(@ts, [ $size, $type ]);
-}
-
-# Sort them ascending by size 
-@ts = sort { $a->[0] <=> $b->[0] } @ts;
-
-# Try all possible combinations, finding pairs in which the word size
-# is twice the digit size.  The number of possible pairs is too small
-# to bother doing this more efficiently than by brute force
-for($ix = 0; $ix <= $#ts; $ix++) {
-    $w = $ts[$ix];
-
-    for($jx = 0; $jx <= $#ts; $jx++) {
-	$d = $ts[$jx];
-
-	if($w->[0] == 2 * $d->[0]) {
-	    push(@valid, [ $d, $w ]);
-	}
-    }
-}
-
-# Sort descending by digit size
-@valid = sort { $b->[0]->[0] <=> $a->[0]->[0] } @valid;
-
-# Select the maximum as the recommended combination
-$rec = shift(@valid);
-
-printf("typedef %-18s mp_sign;\n", "char");
-printf("typedef %-18s mp_digit;  /* %d byte type */\n", 
-       $rec->[0]->[1], $rec->[0]->[0]);
-printf("typedef %-18s mp_word;   /* %d byte type */\n", 
-       $rec->[1]->[1], $rec->[1]->[0]);
-printf("typedef %-18s mp_size;\n", "unsigned int");
-printf("typedef %-18s mp_err;\n\n", "int");
-
-printf("#define %-18s (CHAR_BIT*sizeof(mp_digit))\n", "DIGIT_BIT");
-printf("#define %-18s %s\n", "DIGIT_MAX", $TMAX{$rec->[0]->[1]});
-printf("#define %-18s (CHAR_BIT*sizeof(mp_word))\n", "MP_WORD_BIT");
-printf("#define %-18s %s\n\n", "MP_WORD_MAX", $TMAX{$rec->[1]->[1]});
-printf("#define %-18s (DIGIT_MAX+1)\n\n", "RADIX");
-
-printf("#define %-18s \"%%0%dX\"\n", "DIGIT_FMT", (2 * $rec->[0]->[0]));
-
-exit 0;
deleted file mode 100644
--- a/lib/freebl/mpi/utils/LICENSE
+++ /dev/null
@@ -1,4 +0,0 @@
-Within this directory, each of the file listed below is licensed under 
-the terms given in the file LICENSE-MPL, also in this directory.
-
-PRIMES
deleted file mode 100644
--- a/lib/freebl/mpi/utils/LICENSE-MPL
+++ /dev/null
@@ -1,3 +0,0 @@
-This Source Code Form is subject to the terms of the Mozilla Public
-License, v. 2.0. If a copy of the MPL was not distributed with this
-file, You can obtain one at http://mozilla.org/MPL/2.0/.
deleted file mode 100644
--- a/lib/freebl/mpi/utils/PRIMES
+++ /dev/null
@@ -1,41 +0,0 @@
-Probable primes (sorted by number of significant bits)
-
- 128: 81386202757205669562183851789305348631
-
- 128: 180241813863264101444573802809858694397
-
- 128: 245274683055224433281596312431122059021
-
- 128: 187522309397665259809392608791686659539
-
- 256: 83252422946206411852330647237287722547866360773229941071371588246436\
-      513990159
-
- 256: 79132571131322331023736933767063051273085304521895229780914612117520\
-      058517909
-
- 256: 72081815425552909748220041100909735706208853818662000557743644603407\
-      965465527
-
- 256: 87504602391905701494845474079163412737334477797316409702279059573654\
-      274811271
-
- 512: 12233064210800062190450937494718705259777386009095453001870729392786\
-      63450255179083524798507997690270500580265258111668148238355016411719\
-      9168737693316468563
-
- 512: 12003639081420725322369909586347545220275253633035565716386136197501\
-      88208318984400479275215620499883521216480724155582768193682335576385\
-      2069481074929084063
-
-1024: 16467877625718912296741904171202513097057724053648819680815842057593\
-      20371835940722471475475803725455063836431454757000451907612224427007\
-      63984592414360595161051906727075047683803534852982766542661204179549\
-      77327573530800542562611753617736693359790119074768292178493884576587\
-      0230450429880021317876149636714743053
-
-1024: 16602953991090311275234291158294516471009930684624948451178742895360\
-      86073703307475884280944414508444679430090561246728195735962931545473\
-      40743240318558456247740186704660778277799687988031119436541068736925\
-      20563780233711166724859277827382391527748470939542560819625727876091\
-      5372193745283891895989104479029844957
deleted file mode 100644
--- a/lib/freebl/mpi/utils/README
+++ /dev/null
@@ -1,206 +0,0 @@
-This Source Code Form is subject to the terms of the Mozilla Public
-License, v. 2.0. If a copy of the MPL was not distributed with this
-file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-Additional MPI utilities
-------------------------
-
-The files 'mpprime.h' and 'mpprime.c' define some useful extensions to
-the MPI library for dealing with prime numbers (in particular, testing
-for divisbility, and the Rabin-Miller probabilistic primality test).
-
-The files 'mplogic.h' and 'mplogic.c' define extensions to the MPI
-library for doing bitwise logical operations and shifting.
-
-This document assumes you have read the help file for the MPI library
-and understand its conventions.
-
-Divisibility (mpprime.h)
-------------
-
-To test a number for divisibility by another number:
-
-mpp_divis(a, b)		- test if b|a
-mpp_divis_d(a, d)	- test if d|a
-
-Each of these functions returns MP_YES if its initial argument is
-divisible by its second, or MP_NO if it is not.  Other errors may be
-returned as appropriate (such as MP_RANGE if you try to test for
-divisibility by zero).
-
-Randomness (mpprime.h)
-----------
-
-To generate random data:
-
-mpp_random(a)		- fill a with random data
-mpp_random_size(a, p)   - fill a with p digits of random data
-
-The mpp_random_size() function increases the precision of a to at
-least p, then fills all those digits randomly.  The mp_random()
-function fills a to its current precision (as determined by the number
-of significant digits, USED(a))
-
-Note that these functions simply use the C library's rand() function
-to fill a with random digits up to its precision.  This should be
-adequate for primality testing, but should not be used for
-cryptographic applications where truly random values are required for
-security.  
-
-You should call srand() in your driver program in order to seed the
-random generator; this function doesn't call it.
-
-Primality Testing (mpprime.h)
------------------
-
-mpp_divis_vector(a, v, s, w)   - is a divisible by any of the s values
-                                 in v, and if so, w = which.
-mpp_divis_primes(a, np)   - is a divisible by any of the first np primes?
-mpp_fermat(a, w)          - is a pseudoprime with respect to witness w?
-mpp_pprime(a, nt)	  - run nt iterations of Rabin-Miller on a.
-
-The mpp_divis_vector() function tests a for divisibility by each
-member of an array of digits.  The array is v, the size of that array
-is s.  Returns MP_YES if a is divisible, and stores the index of the
-offending digit in w.  Returns MP_NO if a is not divisible by any of
-the digits in the array.
-
-A small table of primes is compiled into the library (typically the
-first 128 primes, although you can change this by editing the file
-'primes.c' before you build).  The global variable prime_tab_size
-contains the number of primes in the table, and the values themselves
-are in the array prime_tab[], which is an array of mp_digit.
-
-The mpp_divis_primes() function is basically just a wrapper around
-mpp_divis_vector() that uses prime_tab[] as the test vector.  The np
-parameter is a pointer to an mp_digit -- on input, it should specify
-the number of primes to be tested against.  If a is divisible by any
-of the primes, MP_YES is returned and np is given the prime value that
-divided a (you can use this if you're factoring, for example).
-Otherwise, MP_NO is returned and np is untouched.
-
-The function mpp_fermat() performs Fermat's test, using w as a
-witness.  This test basically relies on the fact that if a is prime,
-and w is relatively prime to a, then:
-
-	w^a = w (mod a)
-
-That is,
-
-	w^(a - 1) = 1 (mod a)
-
-The function returns MP_YES if the test passes, MP_NO if it fails.  If
-w is relatively prime to a, and the test fails, a is definitely
-composite.  If w is relatively prime to a and the test passes, then a
-is either prime, or w is a false witness (the probability of this
-happening depends on the choice of w and of a ... consult a number
-theory textbook for more information about this).  
-
-Note:  If (w, a) != 1, the output of this test is meaningless.
-----
-
-The function mpp_pprime() performs the Rabin-Miller probabilistic
-primality test for nt rounds.  If all the tests pass, MP_YES is
-returned, and a is probably prime.  The probability that an answer of
-MP_YES is incorrect is no greater than 1 in 4^nt, and in fact is
-usually much less than that (this is a pessimistic estimate).  If any
-test fails, MP_NO is returned, and a is definitely composite.
-
-Bruce Schneier recommends at least 5 iterations of this test for most
-cryptographic applications; Knuth suggests that 25 are reasonable.
-Run it as many times as you feel are necessary.
-
-See the programs 'makeprime.c' and 'isprime.c' for reasonable examples
-of how to use these functions for primality testing.
-
-
-Bitwise Logic (mplogic.c)
--------------
-
-The four commonest logical operations are implemented as:
-
-mpl_not(a, b)		- Compute bitwise (one's) complement, b = ~a
-
-mpl_and(a, b, c)	- Compute bitwise AND, c = a & b
-
-mpl_or(a, b, c)		- Compute bitwise OR, c = a | b
-
-mpl_xor(a, b, c)	- Compute bitwise XOR, c = a ^ b
-
-Left and right shifts are available as well.  These take a number to
-shift, a destination, and a shift amount.  The shift amount must be a
-digit value between 0 and DIGIT_BIT inclusive; if it is not, MP_RANGE
-will be returned and the shift will not happen.
-
-mpl_rsh(a, b, d)	- Compute logical right shift, b = a >> d
-
-mpl_lsh(a, b, d)	- Compute logical left shift, b = a << d
-
-Since these are logical shifts, they fill with zeroes (the library
-uses a signed magnitude representation, so there are no sign bits to
-extend anyway).
-
-
-Command-line Utilities
-----------------------
-
-A handful of interesting command-line utilities are provided.  These
-are:
-
-lap.c		- Find the order of a mod m.  Usage is 'lap <a> <m>'.
-                  This uses a dumb algorithm, so don't use it for 
-                  a really big modulus.
-
-invmod.c	- Find the inverse of a mod m, if it exists.  Usage
-		  is 'invmod <a> <m>'
-
-sieve.c		- A simple bitmap-based implementation of the Sieve
-		  of Eratosthenes.  Used to generate the table of 
-		  primes in primes.c.  Usage is 'sieve <nbits>'
-
-prng.c          - Uses the routines in bbs_rand.{h,c} to generate
-                  one or more 32-bit pseudo-random integers.  This
-                  is mainly an example, not intended for use in a
-                  cryptographic application (the system time is 
-                  the only source of entropy used)
-
-dec2hex.c       - Convert decimal to hexadecimal
-
-hex2dec.c       - Convert hexadecimal to decimal
-
-basecvt.c       - General radix conversion tool (supports 2-64)
-
-isprime.c       - Probabilistically test an integer for primality
-                  using the Rabin-Miller pseudoprime test combined
-                  with division by small primes.
-
-primegen.c      - Generate primes at random.
-
-exptmod.c       - Perform modular exponentiation
-
-ptab.pl		- A Perl script to munge the output of the sieve
-		  program into a compilable C structure.
-
-
-Other Files
------------
-
-PRIMES		- Some randomly generated numbers which are prime with
-		  extremely high probability.
-
-README		- You're reading me already.
-
-
-About the Author
-----------------
-
-This software was written by Michael J. Fromberger.  You can contact
-the author as follows:
-
-E-mail:	  <sting@linguist.dartmouth.edu>
-
-Postal:	  8000 Cummings Hall, Thayer School of Engineering
-	  Dartmouth College, Hanover, New Hampshire, USA
-
-PGP key:  http://linguist.dartmouth.edu/~sting/keys/mjf.html
-          9736 188B 5AFA 23D6 D6AA  BE0D 5856 4525 289D 9907
deleted file mode 100644
--- a/lib/freebl/mpi/utils/basecvt.c
+++ /dev/null
@@ -1,68 +0,0 @@
-/*
- *  basecvt.c
- *
- *  Convert integer values specified on the command line from one input
- *  base to another.  Accepts input and output bases between 2 and 36
- *  inclusive.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "mpi.h"
-
-#define IBASE 10
-#define OBASE 16
-#define USAGE "Usage: %s ibase obase [value]\n"
-#define MAXBASE 64
-#define MINBASE 2
-
-int
-main(int argc, char *argv[])
-{
-    int ix, ibase = IBASE, obase = OBASE;
-    mp_int val;
-
-    ix = 1;
-    if (ix < argc) {
-        ibase = atoi(argv[ix++]);
-
-        if (ibase < MINBASE || ibase > MAXBASE) {
-            fprintf(stderr, "%s: input radix must be between %d and %d inclusive\n",
-                    argv[0], MINBASE, MAXBASE);
-            return 1;
-        }
-    }
-    if (ix < argc) {
-        obase = atoi(argv[ix++]);
-
-        if (obase < MINBASE || obase > MAXBASE) {
-            fprintf(stderr, "%s: output radix must be between %d and %d inclusive\n",
-                    argv[0], MINBASE, MAXBASE);
-            return 1;
-        }
-    }
-
-    mp_init(&val);
-    while (ix < argc) {
-        char *out;
-        int outlen;
-
-        mp_read_radix(&val, argv[ix++], ibase);
-
-        outlen = mp_radix_size(&val, obase);
-        out = calloc(outlen, sizeof(char));
-        mp_toradix(&val, out, obase);
-
-        printf("%s\n", out);
-        free(out);
-    }
-
-    mp_clear(&val);
-
-    return 0;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/utils/bbs_rand.c
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- *  Blum, Blum & Shub PRNG using the MPI library
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include "bbs_rand.h"
-
-#define SEED 1
-#define MODULUS 2
-
-/* This modulus is the product of two randomly generated 512-bit
-   prime integers, each of which is congruent to 3 (mod 4).          */
-static char *bbs_modulus =
-    "75A2A6E1D27393B86562B9CE7279A8403CB4258A637DAB5233465373E37837383EDC"
-    "332282B8575927BC4172CE8C147B4894050EE9D2BDEED355C121037270CA2570D127"
-    "7D2390CD1002263326635CC6B259148DE3A1A03201980A925E395E646A5E9164B0EC"
-    "28559EBA58C87447245ADD0651EDA507056A1129E3A3E16E903D64B437";
-
-static int bbs_init = 0; /* flag set when library is initialized */
-static mp_int bbs_state; /* the current state of the generator   */
-
-/* Suggested size of random seed data */
-int bbs_seed_size = (sizeof(bbs_modulus) / 2);
-
-void
-bbs_srand(unsigned char *data, int len)
-{
-    if ((bbs_init & SEED) == 0) {
-        mp_init(&bbs_state);
-        bbs_init |= SEED;
-    }
-
-    mp_read_raw(&bbs_state, (char *)data, len);
-
-} /* end bbs_srand() */
-
-unsigned int
-bbs_rand(void)
-{
-    static mp_int modulus;
-    unsigned int result = 0, ix;
-
-    if ((bbs_init & MODULUS) == 0) {
-        mp_init(&modulus);
-        mp_read_radix(&modulus, bbs_modulus, 16);
-        bbs_init |= MODULUS;
-    }
-
-    for (ix = 0; ix < sizeof(unsigned int); ix++) {
-        mp_digit d;
-
-        mp_sqrmod(&bbs_state, &modulus, &bbs_state);
-        d = DIGIT(&bbs_state, 0);
-
-        result = (result << CHAR_BIT) | (d & UCHAR_MAX);
-    }
-
-    return result;
-
-} /* end bbs_rand() */
-
-/*------------------------------------------------------------------------*/
-/* HERE THERE BE DRAGONS                                                  */
deleted file mode 100644
--- a/lib/freebl/mpi/utils/bbs_rand.h
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- *  bbs_rand.h
- *
- *  Blum, Blum & Shub PRNG using the MPI library
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#ifndef _H_BBSRAND_
-#define _H_BBSRAND_
-
-#include <limits.h>
-#include "mpi.h"
-
-#define BBS_RAND_MAX UINT_MAX
-
-/* Suggested length of seed data */
-extern int bbs_seed_size;
-
-void bbs_srand(unsigned char *data, int len);
-unsigned int bbs_rand(void);
-
-#endif /* end _H_BBSRAND_ */
deleted file mode 100644
--- a/lib/freebl/mpi/utils/bbsrand.c
+++ /dev/null
@@ -1,35 +0,0 @@
-/*
- *  bbsrand.c
- *
- *  Test driver for routines in bbs_rand.h
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <time.h>
-#include <limits.h>
-
-#include "bbs_rand.h"
-
-#define NUM_TESTS 100
-
-int
-main(void)
-{
-    unsigned int seed, result, ix;
-
-    seed = time(NULL);
-    bbs_srand((unsigned char *)&seed, sizeof(seed));
-
-    for (ix = 0; ix < NUM_TESTS; ix++) {
-        result = bbs_rand();
-
-        printf("Test %3u: %08X\n", ix + 1, result);
-    }
-
-    return 0;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/utils/dec2hex.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- *  dec2hex.c
- *
- *  Convert decimal integers into hexadecimal
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "mpi.h"
-
-int
-main(int argc, char *argv[])
-{
-    mp_int a;
-    char *buf;
-    int len;
-
-    if (argc < 2) {
-        fprintf(stderr, "Usage: %s <a>\n", argv[0]);
-        return 1;
-    }
-
-    mp_init(&a);
-    mp_read_radix(&a, argv[1], 10);
-    len = mp_radix_size(&a, 16);
-    buf = malloc(len);
-    mp_toradix(&a, buf, 16);
-
-    printf("%s\n", buf);
-
-    free(buf);
-    mp_clear(&a);
-
-    return 0;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/utils/exptmod.c
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- *  exptmod.c
- *
- * Command line tool to perform modular exponentiation on arbitrary
- * precision integers.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "mpi.h"
-
-int
-main(int argc, char *argv[])
-{
-    mp_int a, b, m;
-    mp_err res;
-    char *str;
-    int len, rval = 0;
-
-    if (argc < 3) {
-        fprintf(stderr, "Usage: %s <a> <b> <m>\n", argv[0]);
-        return 1;
-    }
-
-    mp_init(&a);
-    mp_init(&b);
-    mp_init(&m);
-    mp_read_radix(&a, argv[1], 10);
-    mp_read_radix(&b, argv[2], 10);
-    mp_read_radix(&m, argv[3], 10);
-
-    if ((res = mp_exptmod(&a, &b, &m, &a)) != MP_OKAY) {
-        fprintf(stderr, "%s: error: %s\n", argv[0], mp_strerror(res));
-        rval = 1;
-    } else {
-        len = mp_radix_size(&a, 10);
-        str = calloc(len, sizeof(char));
-        mp_toradix(&a, str, 10);
-
-        printf("%s\n", str);
-
-        free(str);
-    }
-
-    mp_clear(&a);
-    mp_clear(&b);
-    mp_clear(&m);
-
-    return rval;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/utils/fact.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/*
- * fact.c
- *
- * Compute factorial of input integer
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "mpi.h"
-
-mp_err mp_fact(mp_int *a, mp_int *b);
-
-int
-main(int argc, char *argv[])
-{
-    mp_int a;
-    mp_err res;
-
-    if (argc < 2) {
-        fprintf(stderr, "Usage: %s <number>\n", argv[0]);
-        return 1;
-    }
-
-    mp_init(&a);
-    mp_read_radix(&a, argv[1], 10);
-
-    if ((res = mp_fact(&a, &a)) != MP_OKAY) {
-        fprintf(stderr, "%s: error: %s\n", argv[0],
-                mp_strerror(res));
-        mp_clear(&a);
-        return 1;
-    }
-
-    {
-        char *buf;
-        int len;
-
-        len = mp_radix_size(&a, 10);
-        buf = malloc(len);
-        mp_todecimal(&a, buf);
-
-        puts(buf);
-
-        free(buf);
-    }
-
-    mp_clear(&a);
-    return 0;
-}
-
-mp_err
-mp_fact(mp_int *a, mp_int *b)
-{
-    mp_int ix, s;
-    mp_err res = MP_OKAY;
-
-    if (mp_cmp_z(a) < 0)
-        return MP_UNDEF;
-
-    mp_init(&s);
-    mp_add_d(&s, 1, &s); /* s = 1  */
-    mp_init(&ix);
-    mp_add_d(&ix, 1, &ix); /* ix = 1 */
-
-    for (/*  */; mp_cmp(&ix, a) <= 0; mp_add_d(&ix, 1, &ix)) {
-        if ((res = mp_mul(&s, &ix, &s)) != MP_OKAY)
-            break;
-    }
-
-    mp_clear(&ix);
-
-    /* Copy out results if we got them */
-    if (res == MP_OKAY)
-        mp_copy(&s, b);
-
-    mp_clear(&s);
-
-    return res;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/utils/gcd.c
+++ /dev/null
@@ -1,95 +0,0 @@
-/*
- *  gcd.c
- *
- *  Greatest common divisor
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "mpi.h"
-
-char *g_prog = NULL;
-
-void print_mp_int(mp_int *mp, FILE *ofp);
-
-int
-main(int argc, char *argv[])
-{
-    mp_int a, b, x, y;
-    mp_err res;
-    int ext = 0;
-
-    g_prog = argv[0];
-
-    if (argc < 3) {
-        fprintf(stderr, "Usage: %s <a> <b>\n", g_prog);
-        return 1;
-    }
-
-    mp_init(&a);
-    mp_read_radix(&a, argv[1], 10);
-    mp_init(&b);
-    mp_read_radix(&b, argv[2], 10);
-
-    /* If we were called 'xgcd', compute x, y so that g = ax + by */
-    if (strcmp(g_prog, "xgcd") == 0) {
-        ext = 1;
-        mp_init(&x);
-        mp_init(&y);
-    }
-
-    if (ext) {
-        if ((res = mp_xgcd(&a, &b, &a, &x, &y)) != MP_OKAY) {
-            fprintf(stderr, "%s: error: %s\n", g_prog, mp_strerror(res));
-            mp_clear(&a);
-            mp_clear(&b);
-            mp_clear(&x);
-            mp_clear(&y);
-            return 1;
-        }
-    } else {
-        if ((res = mp_gcd(&a, &b, &a)) != MP_OKAY) {
-            fprintf(stderr, "%s: error: %s\n", g_prog,
-                    mp_strerror(res));
-            mp_clear(&a);
-            mp_clear(&b);
-            return 1;
-        }
-    }
-
-    print_mp_int(&a, stdout);
-    if (ext) {
-        fputs("x = ", stdout);
-        print_mp_int(&x, stdout);
-        fputs("y = ", stdout);
-        print_mp_int(&y, stdout);
-    }
-
-    mp_clear(&a);
-    mp_clear(&b);
-
-    if (ext) {
-        mp_clear(&x);
-        mp_clear(&y);
-    }
-
-    return 0;
-}
-
-void
-print_mp_int(mp_int *mp, FILE *ofp)
-{
-    char *buf;
-    int len;
-
-    len = mp_radix_size(mp, 10);
-    buf = calloc(len, sizeof(char));
-    mp_todecimal(mp, buf);
-    fprintf(ofp, "%s\n", buf);
-    free(buf);
-}
deleted file mode 100644
--- a/lib/freebl/mpi/utils/hex2dec.c
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- *  hex2dec.c
- *
- *  Convert decimal integers into hexadecimal
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "mpi.h"
-
-int
-main(int argc, char *argv[])
-{
-    mp_int a;
-    char *buf;
-    int len;
-
-    if (argc < 2) {
-        fprintf(stderr, "Usage: %s <a>\n", argv[0]);
-        return 1;
-    }
-
-    mp_init(&a);
-    mp_read_radix(&a, argv[1], 16);
-    len = mp_radix_size(&a, 10);
-    buf = malloc(len);
-    mp_toradix(&a, buf, 10);
-
-    printf("%s\n", buf);
-
-    free(buf);
-    mp_clear(&a);
-
-    return 0;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/utils/identest.c
+++ /dev/null
@@ -1,84 +0,0 @@
-/* This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include "mpi.h"
-#include "mpprime.h"
-#include <sys/types.h>
-#include <time.h>
-
-#define MAX_PREC (4096 / MP_DIGIT_BIT)
-
-mp_err
-identity_test(void)
-{
-    mp_size preca, precb;
-    mp_err res;
-    mp_int a, b;
-    mp_int t1, t2, t3, t4, t5;
-
-    preca = (rand() % MAX_PREC) + 1;
-    precb = (rand() % MAX_PREC) + 1;
-
-    MP_DIGITS(&a) = 0;
-    MP_DIGITS(&b) = 0;
-    MP_DIGITS(&t1) = 0;
-    MP_DIGITS(&t2) = 0;
-    MP_DIGITS(&t3) = 0;
-    MP_DIGITS(&t4) = 0;
-    MP_DIGITS(&t5) = 0;
-
-    MP_CHECKOK(mp_init(&a));
-    MP_CHECKOK(mp_init(&b));
-    MP_CHECKOK(mp_init(&t1));
-    MP_CHECKOK(mp_init(&t2));
-    MP_CHECKOK(mp_init(&t3));
-    MP_CHECKOK(mp_init(&t4));
-    MP_CHECKOK(mp_init(&t5));
-
-    MP_CHECKOK(mpp_random_size(&a, preca));
-    MP_CHECKOK(mpp_random_size(&b, precb));
-
-    if (mp_cmp(&a, &b) < 0)
-        mp_exch(&a, &b);
-
-    MP_CHECKOK(mp_mod(&a, &b, &t1));       /* t1 = a%b */
-    MP_CHECKOK(mp_div(&a, &b, &t2, NULL)); /* t2 = a/b */
-    MP_CHECKOK(mp_mul(&b, &t2, &t3));      /* t3 = (a/b)*b */
-    MP_CHECKOK(mp_add(&t1, &t3, &t4));     /* t4 = a%b + (a/b)*b */
-    MP_CHECKOK(mp_sub(&t4, &a, &t5));      /* t5 = a%b + (a/b)*b - a */
-    if (mp_cmp_z(&t5) != 0) {
-        res = MP_UNDEF;
-        goto CLEANUP;
-    }
-
-CLEANUP:
-    mp_clear(&t5);
-    mp_clear(&t4);
-    mp_clear(&t3);
-    mp_clear(&t2);
-    mp_clear(&t1);
-    mp_clear(&b);
-    mp_clear(&a);
-    return res;
-}
-
-int
-main(void)
-{
-    unsigned int seed = (unsigned int)time(NULL);
-    unsigned long count = 0;
-    mp_err res;
-
-    srand(seed);
-
-    while (MP_OKAY == (res = identity_test())) {
-        if ((++count % 100) == 0)
-            fputc('.', stderr);
-    }
-
-    fprintf(stderr, "\ntest failed, err %d\n", res);
-    return res;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/utils/invmod.c
+++ /dev/null
@@ -1,61 +0,0 @@
-/*
- *  invmod.c
- *
- *  Compute modular inverses
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-
-#include "mpi.h"
-
-int
-main(int argc, char *argv[])
-{
-    mp_int a, m;
-    mp_err res;
-    char *buf;
-    int len, out = 0;
-
-    if (argc < 3) {
-        fprintf(stderr, "Usage: %s <a> <m>\n", argv[0]);
-        return 1;
-    }
-
-    mp_init(&a);
-    mp_init(&m);
-    mp_read_radix(&a, argv[1], 10);
-    mp_read_radix(&m, argv[2], 10);
-
-    if (mp_cmp(&a, &m) > 0)
-        mp_mod(&a, &m, &a);
-
-    switch ((res = mp_invmod(&a, &m, &a))) {
-        case MP_OKAY:
-            len = mp_radix_size(&a, 10);
-            buf = malloc(len);
-
-            mp_toradix(&a, buf, 10);
-            printf("%s\n", buf);
-            free(buf);
-            break;
-
-        case MP_UNDEF:
-            printf("No inverse\n");
-            out = 1;
-            break;
-
-        default:
-            printf("error: %s (%d)\n", mp_strerror(res), res);
-            out = 2;
-            break;
-    }
-
-    mp_clear(&a);
-    mp_clear(&m);
-
-    return out;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/utils/isprime.c
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- *  isprime.c
- *
- *  Probabilistic primality tester command-line tool
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-
-#include "mpi.h"
-#include "mpprime.h"
-
-#define RM_TESTS 15  /* how many iterations of Rabin-Miller? */
-#define MINIMUM 1024 /* don't bother us with a < this        */
-
-int g_tests = RM_TESTS;
-char *g_prog = NULL;
-
-int
-main(int argc, char *argv[])
-{
-    mp_int a;
-    mp_digit np = prime_tab_size; /* from mpprime.h */
-    int res = 0;
-
-    g_prog = argv[0];
-
-    if (argc < 2) {
-        fprintf(stderr, "Usage: %s <a>, where <a> is a decimal integer\n"
-                        "Use '0x' prefix for a hexadecimal value\n",
-                g_prog);
-        return 1;
-    }
-
-    /* Read number of tests from environment, if present */
-    {
-        char *tmp;
-
-        if ((tmp = PR_GetEnvSecure("RM_TESTS")) != NULL) {
-            if ((g_tests = atoi(tmp)) <= 0)
-                g_tests = RM_TESTS;
-        }
-    }
-
-    mp_init(&a);
-    if (argv[1][0] == '0' && argv[1][1] == 'x')
-        mp_read_radix(&a, argv[1] + 2, 16);
-    else
-        mp_read_radix(&a, argv[1], 10);
-
-    if (mp_cmp_d(&a, MINIMUM) <= 0) {
-        fprintf(stderr, "%s: please use a value greater than %d\n",
-                g_prog, MINIMUM);
-        mp_clear(&a);
-        return 1;
-    }
-
-    /* Test for divisibility by small primes */
-    if (mpp_divis_primes(&a, &np) != MP_NO) {
-        printf("Not prime (divisible by small prime %d)\n", np);
-        res = 2;
-        goto CLEANUP;
-    }
-
-    /* Test with Fermat's test, using 2 as a witness */
-    if (mpp_fermat(&a, 2) != MP_YES) {
-        printf("Not prime (failed Fermat test)\n");
-        res = 2;
-        goto CLEANUP;
-    }
-
-    /* Test with Rabin-Miller probabilistic test */
-    if (mpp_pprime(&a, g_tests) == MP_NO) {
-        printf("Not prime (failed pseudoprime test)\n");
-        res = 2;
-        goto CLEANUP;
-    }
-
-    printf("Probably prime, 1 in 4^%d chance of false positive\n", g_tests);
-
-CLEANUP:
-    mp_clear(&a);
-
-    return res;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/utils/lap.c
+++ /dev/null
@@ -1,90 +0,0 @@
-/*
- *  lap.c
- *
- *  Find least annihilating power of a mod m
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <signal.h>
-
-#include "mpi.h"
-
-void sig_catch(int ign);
-
-int g_quit = 0;
-
-int
-main(int argc, char *argv[])
-{
-    mp_int a, m, p, k;
-
-    if (argc < 3) {
-        fprintf(stderr, "Usage: %s <a> <m>\n", argv[0]);
-        return 1;
-    }
-
-    mp_init(&a);
-    mp_init(&m);
-    mp_init(&p);
-    mp_add_d(&p, 1, &p);
-
-    mp_read_radix(&a, argv[1], 10);
-    mp_read_radix(&m, argv[2], 10);
-
-    mp_init_copy(&k, &a);
-
-    signal(SIGINT, sig_catch);
-#ifndef __OS2__
-    signal(SIGHUP, sig_catch);
-#endif
-    signal(SIGTERM, sig_catch);
-
-    while (mp_cmp(&p, &m) < 0) {
-        if (g_quit) {
-            int len;
-            char *buf;
-
-            len = mp_radix_size(&p, 10);
-            buf = malloc(len);
-            mp_toradix(&p, buf, 10);
-
-            fprintf(stderr, "Terminated at: %s\n", buf);
-            free(buf);
-            return 1;
-        }
-        if (mp_cmp_d(&k, 1) == 0) {
-            int len;
-            char *buf;
-
-            len = mp_radix_size(&p, 10);
-            buf = malloc(len);
-            mp_toradix(&p, buf, 10);
-
-            printf("%s\n", buf);
-
-            free(buf);
-            break;
-        }
-
-        mp_mulmod(&k, &a, &m, &k);
-        mp_add_d(&p, 1, &p);
-    }
-
-    if (mp_cmp(&p, &m) >= 0)
-        printf("No annihilating power.\n");
-
-    mp_clear(&p);
-    mp_clear(&m);
-    mp_clear(&a);
-    return 0;
-}
-
-void
-sig_catch(int ign)
-{
-    g_quit = 1;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/utils/makeprime.c
+++ /dev/null
@@ -1,116 +0,0 @@
-/*
- * makeprime.c
- *
- * A simple prime generator function (and test driver).  Prints out the
- * first prime it finds greater than or equal to the starting value.
- *
- * Usage: makeprime <start>
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <ctype.h>
-
-/* These two must be included for make_prime() to work */
-
-#include "mpi.h"
-#include "mpprime.h"
-
-/*
-  make_prime(p, nr)
-
-  Find the smallest prime integer greater than or equal to p, where
-  primality is verified by 'nr' iterations of the Rabin-Miller
-  probabilistic primality test.  The caller is responsible for
-  generating the initial value of p.
-
-  Returns MP_OKAY if a prime has been generated, otherwise the error
-  code indicates some other problem.  The value of p is clobbered; the
-  caller should keep a copy if the value is needed.
- */
-mp_err make_prime(mp_int *p, int nr);
-
-/* The main() is not required -- it's just a test driver */
-int
-main(int argc, char *argv[])
-{
-    mp_int start;
-    mp_err res;
-
-    if (argc < 2) {
-        fprintf(stderr, "Usage: %s <start-value>\n", argv[0]);
-        return 1;
-    }
-
-    mp_init(&start);
-    if (argv[1][0] == '0' && tolower(argv[1][1]) == 'x') {
-        mp_read_radix(&start, argv[1] + 2, 16);
-    } else {
-        mp_read_radix(&start, argv[1], 10);
-    }
-    mp_abs(&start, &start);
-
-    if ((res = make_prime(&start, 5)) != MP_OKAY) {
-        fprintf(stderr, "%s: error: %s\n", argv[0], mp_strerror(res));
-        mp_clear(&start);
-
-        return 1;
-
-    } else {
-        char *buf = malloc(mp_radix_size(&start, 10));
-
-        mp_todecimal(&start, buf);
-        printf("%s\n", buf);
-        free(buf);
-
-        mp_clear(&start);
-
-        return 0;
-    }
-
-} /* end main() */
-
-/*------------------------------------------------------------------------*/
-
-mp_err
-make_prime(mp_int *p, int nr)
-{
-    mp_err res;
-
-    if (mp_iseven(p)) {
-        mp_add_d(p, 1, p);
-    }
-
-    do {
-        mp_digit which = prime_tab_size;
-
-        /*  First test for divisibility by a few small primes */
-        if ((res = mpp_divis_primes(p, &which)) == MP_YES)
-            continue;
-        else if (res != MP_NO)
-            goto CLEANUP;
-
-        /* If that passes, try one iteration of Fermat's test */
-        if ((res = mpp_fermat(p, 2)) == MP_NO)
-            continue;
-        else if (res != MP_YES)
-            goto CLEANUP;
-
-        /* If that passes, run Rabin-Miller as often as requested */
-        if ((res = mpp_pprime(p, nr)) == MP_YES)
-            break;
-        else if (res != MP_NO)
-            goto CLEANUP;
-
-    } while ((res = mp_add_d(p, 2, p)) == MP_OKAY);
-
-CLEANUP:
-    return res;
-
-} /* end make_prime() */
-
-/*------------------------------------------------------------------------*/
-/* HERE THERE BE DRAGONS                                                  */
deleted file mode 100644
--- a/lib/freebl/mpi/utils/metime.c
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- *  metime.c
- *
- * Modular exponentiation timing test
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <time.h>
-
-#include "mpi.h"
-#include "mpprime.h"
-
-double clk_to_sec(clock_t start, clock_t stop);
-
-int
-main(int argc, char *argv[])
-{
-    int ix, num, prec = 8;
-    unsigned int seed;
-    clock_t start, stop;
-    double sec;
-
-    mp_int a, m, c;
-
-    if (PR_GetEnvSecure("SEED") != NULL)
-        seed = abs(atoi(PR_GetEnvSecure("SEED")));
-    else
-        seed = (unsigned int)time(NULL);
-
-    if (argc < 2) {
-        fprintf(stderr, "Usage: %s <num-tests> [<nbits>]\n", argv[0]);
-        return 1;
-    }
-
-    if ((num = atoi(argv[1])) < 0)
-        num = -num;
-
-    if (!num) {
-        fprintf(stderr, "%s: must perform at least 1 test\n", argv[0]);
-        return 1;
-    }
-
-    if (argc > 2) {
-        if ((prec = atoi(argv[2])) <= 0)
-            prec = 8;
-        else
-            prec = (prec + (DIGIT_BIT - 1)) / DIGIT_BIT;
-    }
-
-    printf("Modular exponentiation timing test\n"
-           "Precision:  %d digits (%d bits)\n"
-           "# of tests: %d\n\n",
-           prec, prec * DIGIT_BIT, num);
-
-    mp_init_size(&a, prec);
-    mp_init_size(&m, prec);
-    mp_init_size(&c, prec);
-
-    srand(seed);
-
-    start = clock();
-    for (ix = 0; ix < num; ix++) {
-
-        mpp_random_size(&a, prec);
-        mpp_random_size(&c, prec);
-        mpp_random_size(&m, prec);
-        /* set msb and lsb of m */
-        DIGIT(&m, 0) |= 1;
-        DIGIT(&m, USED(&m) - 1) |= (mp_digit)1 << (DIGIT_BIT - 1);
-        if (mp_cmp(&a, &m) > 0)
-            mp_sub(&a, &m, &a);
-
-        mp_exptmod(&a, &c, &m, &c);
-    }
-    stop = clock();
-
-    sec = clk_to_sec(start, stop);
-
-    printf("Total:      %.3f seconds\n", sec);
-    printf("Individual: %.3f seconds\n", sec / num);
-
-    mp_clear(&c);
-    mp_clear(&a);
-    mp_clear(&m);
-
-    return 0;
-}
-
-double
-clk_to_sec(clock_t start, clock_t stop)
-{
-    return (double)(stop - start) / CLOCKS_PER_SEC;
-}
-
-/*------------------------------------------------------------------------*/
-/* HERE THERE BE DRAGONS                                                  */
deleted file mode 100644
--- a/lib/freebl/mpi/utils/pi.c
+++ /dev/null
@@ -1,171 +0,0 @@
-/*
- * pi.c
- *
- * Compute pi to an arbitrary number of digits.  Uses Machin's formula,
- * like everyone else on the planet:
- *
- *    pi = 16 * arctan(1/5) - 4 * arctan(1/239)
- *
- * This is pretty effective for up to a few thousand digits, but it
- * gets pretty slow after that.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <time.h>
-
-#include "mpi.h"
-
-mp_err arctan(mp_digit mul, mp_digit x, mp_digit prec, mp_int *sum);
-
-int
-main(int argc, char *argv[])
-{
-    mp_err res;
-    mp_digit ndigits;
-    mp_int sum1, sum2;
-    clock_t start, stop;
-    int out = 0;
-
-    /* Make the user specify precision on the command line */
-    if (argc < 2) {
-        fprintf(stderr, "Usage: %s <num-digits>\n", argv[0]);
-        return 1;
-    }
-
-    if ((ndigits = abs(atoi(argv[1]))) == 0) {
-        fprintf(stderr, "%s: you must request at least 1 digit\n", argv[0]);
-        return 1;
-    }
-
-    start = clock();
-    mp_init(&sum1);
-    mp_init(&sum2);
-
-    /* sum1 = 16 * arctan(1/5)  */
-    if ((res = arctan(16, 5, ndigits, &sum1)) != MP_OKAY) {
-        fprintf(stderr, "%s: arctan: %s\n", argv[0], mp_strerror(res));
-        out = 1;
-        goto CLEANUP;
-    }
-
-    /* sum2 = 4 * arctan(1/239) */
-    if ((res = arctan(4, 239, ndigits, &sum2)) != MP_OKAY) {
-        fprintf(stderr, "%s: arctan: %s\n", argv[0], mp_strerror(res));
-        out = 1;
-        goto CLEANUP;
-    }
-
-    /* pi = sum1 - sum2         */
-    if ((res = mp_sub(&sum1, &sum2, &sum1)) != MP_OKAY) {
-        fprintf(stderr, "%s: mp_sub: %s\n", argv[0], mp_strerror(res));
-        out = 1;
-        goto CLEANUP;
-    }
-    stop = clock();
-
-    /* Write the output in decimal */
-    {
-        char *buf = malloc(mp_radix_size(&sum1, 10));
-
-        if (buf == NULL) {
-            fprintf(stderr, "%s: out of memory\n", argv[0]);
-            out = 1;
-            goto CLEANUP;
-        }
-        mp_todecimal(&sum1, buf);
-        printf("%s\n", buf);
-        free(buf);
-    }
-
-    fprintf(stderr, "Computation took %.2f sec.\n",
-            (double)(stop - start) / CLOCKS_PER_SEC);
-
-CLEANUP:
-    mp_clear(&sum1);
-    mp_clear(&sum2);
-
-    return out;
-}
-
-/* Compute sum := mul * arctan(1/x), to 'prec' digits of precision */
-mp_err
-arctan(mp_digit mul, mp_digit x, mp_digit prec, mp_int *sum)
-{
-    mp_int t, v;
-    mp_digit q = 1, rd;
-    mp_err res;
-    int sign = 1;
-
-    prec += 3; /* push inaccuracies off the end */
-
-    mp_init(&t);
-    mp_set(&t, 10);
-    mp_init(&v);
-    if ((res = mp_expt_d(&t, prec, &t)) != MP_OKAY || /* get 10^prec    */
-        (res = mp_mul_d(&t, mul, &t)) != MP_OKAY ||   /* ... times mul  */
-        (res = mp_mul_d(&t, x, &t)) != MP_OKAY)       /* ... times x    */
-        goto CLEANUP;
-
-    /*
-    The extra multiplication by x in the above takes care of what
-    would otherwise have to be a special case for 1 / x^1 during the
-    first loop iteration.  A little sneaky, but effective.
-
-    We compute arctan(1/x) by the formula:
-
-         1     1       1       1
-     - - ----- + ----- - ----- + ...
-     x   3 x^3   5 x^5   7 x^7
-
-    We multiply through by 'mul' beforehand, which gives us a couple
-    more iterations and more precision
-   */
-
-    x *= x; /* works as long as x < sqrt(RADIX), which it is here */
-
-    mp_zero(sum);
-
-    do {
-        if ((res = mp_div_d(&t, x, &t, &rd)) != MP_OKAY)
-            goto CLEANUP;
-
-        if (sign < 0 && rd != 0)
-            mp_add_d(&t, 1, &t);
-
-        if ((res = mp_div_d(&t, q, &v, &rd)) != MP_OKAY)
-            goto CLEANUP;
-
-        if (sign < 0 && rd != 0)
-            mp_add_d(&v, 1, &v);
-
-        if (sign > 0)
-            res = mp_add(sum, &v, sum);
-        else
-            res = mp_sub(sum, &v, sum);
-
-        if (res != MP_OKAY)
-            goto CLEANUP;
-
-        sign *= -1;
-        q += 2;
-
-    } while (mp_cmp_z(&t) != 0);
-
-    /* Chop off inaccurate low-order digits */
-    mp_div_d(sum, 1000, sum, NULL);
-
-CLEANUP:
-    mp_clear(&v);
-    mp_clear(&t);
-
-    return res;
-}
-
-/*------------------------------------------------------------------------*/
-/* HERE THERE BE DRAGONS                                                  */
deleted file mode 100644
--- a/lib/freebl/mpi/utils/primegen.c
+++ /dev/null
@@ -1,159 +0,0 @@
-/*
- *  primegen.c
- *
- * Generates random integers which are prime with a high degree of
- * probability using the Miller-Rabin probabilistic primality testing
- * algorithm.
- *
- * Usage:
- *    primegen <bits> [<num>]
- *
- *    <bits>   - number of significant bits each prime should have
- *    <num>    - number of primes to generate
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <limits.h>
-#include <time.h>
-
-#include "mpi.h"
-#include "mplogic.h"
-#include "mpprime.h"
-
-#define NUM_TESTS 5 /* Number of Rabin-Miller iterations to test with */
-
-#ifdef DEBUG
-#define FPUTC(x, y) fputc(x, y)
-#else
-#define FPUTC(x, y)
-#endif
-
-int
-main(int argc, char *argv[])
-{
-    unsigned char *raw;
-    char *out;
-    unsigned long nTries;
-    int rawlen, bits, outlen, ngen, ix, jx;
-    int g_strong = 0;
-    mp_int testval;
-    mp_err res;
-    clock_t start, end;
-
-    /* We'll just use the C library's rand() for now, although this
-     won't be good enough for cryptographic purposes */
-    if ((out = PR_GetEnvSecure("SEED")) == NULL) {
-        srand((unsigned int)time(NULL));
-    } else {
-        srand((unsigned int)atoi(out));
-    }
-
-    if (argc < 2) {
-        fprintf(stderr, "Usage: %s <bits> [<count> [strong]]\n", argv[0]);
-        return 1;
-    }
-
-    if ((bits = abs(atoi(argv[1]))) < CHAR_BIT) {
-        fprintf(stderr, "%s: please request at least %d bits.\n",
-                argv[0], CHAR_BIT);
-        return 1;
-    }
-
-    /* If optional third argument is given, use that as the number of
-     primes to generate; otherwise generate one prime only.
-   */
-    if (argc < 3) {
-        ngen = 1;
-    } else {
-        ngen = abs(atoi(argv[2]));
-    }
-
-    /* If fourth argument is given, and is the word "strong", we'll 
-     generate strong (Sophie Germain) primes. 
-   */
-    if (argc > 3 && strcmp(argv[3], "strong") == 0)
-        g_strong = 1;
-
-    /* testval - candidate being tested; nTries - number tried so far */
-    if ((res = mp_init(&testval)) != MP_OKAY) {
-        fprintf(stderr, "%s: error: %s\n", argv[0], mp_strerror(res));
-        return 1;
-    }
-
-    if (g_strong) {
-        printf("Requested %d strong prime value(s) of %d bits.\n",
-               ngen, bits);
-    } else {
-        printf("Requested %d prime value(s) of %d bits.\n", ngen, bits);
-    }
-
-    rawlen = (bits / CHAR_BIT) + ((bits % CHAR_BIT) ? 1 : 0) + 1;
-
-    if ((raw = calloc(rawlen, sizeof(unsigned char))) == NULL) {
-        fprintf(stderr, "%s: out of memory, sorry.\n", argv[0]);
-        return 1;
-    }
-
-    /* This loop is one for each prime we need to generate */
-    for (jx = 0; jx < ngen; jx++) {
-
-        raw[0] = 0; /* sign is positive */
-
-        /*	Pack the initializer with random bytes	*/
-        for (ix = 1; ix < rawlen; ix++)
-            raw[ix] = (rand() * rand()) & UCHAR_MAX;
-
-        raw[1] |= 0x80;       /* set high-order bit of test value     */
-        raw[rawlen - 1] |= 1; /* set low-order bit of test value      */
-
-        /* Make an mp_int out of the initializer */
-        mp_read_raw(&testval, (char *)raw, rawlen);
-
-        /* Initialize candidate counter */
-        nTries = 0;
-
-        start = clock(); /* time generation for this prime */
-        do {
-            res = mpp_make_prime(&testval, bits, g_strong, &nTries);
-            if (res != MP_NO)
-                break;
-            /* This code works whether digits are 16 or 32 bits */
-            res = mp_add_d(&testval, 32 * 1024, &testval);
-            res = mp_add_d(&testval, 32 * 1024, &testval);
-            FPUTC(',', stderr);
-        } while (1);
-        end = clock();
-
-        if (res != MP_YES) {
-            break;
-        }
-        FPUTC('\n', stderr);
-        puts("The following value is probably prime:");
-        outlen = mp_radix_size(&testval, 10);
-        out = calloc(outlen, sizeof(unsigned char));
-        mp_toradix(&testval, (char *)out, 10);
-        printf("10: %s\n", out);
-        mp_toradix(&testval, (char *)out, 16);
-        printf("16: %s\n\n", out);
-        free(out);
-
-        printf("Number of candidates tried: %lu\n", nTries);
-        printf("This computation took %ld clock ticks (%.2f seconds)\n",
-               (end - start), ((double)(end - start) / CLOCKS_PER_SEC));
-
-        FPUTC('\n', stderr);
-    } /* end of loop to generate all requested primes */
-
-    if (res != MP_OKAY)
-        fprintf(stderr, "%s: error: %s\n", argv[0], mp_strerror(res));
-
-    free(raw);
-    mp_clear(&testval);
-
-    return 0;
-}
deleted file mode 100644
--- a/lib/freebl/mpi/utils/prng.c
+++ /dev/null
@@ -1,57 +0,0 @@
-/*
- *  prng.c
- *
- *  Command-line pseudo-random number generator
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-#include <time.h>
-
-#ifdef __OS2__
-#include <types.h>
-#include <process.h>
-#else
-#include <unistd.h>
-#endif
-
-#include "bbs_rand.h"
-
-int
-main(int argc, char *argv[])
-{
-    unsigned char *seed;
-    unsigned int ix, num = 1;
-    pid_t pid;
-
-    if (argc > 1) {
-        num = atoi(argv[1]);
-        if (num <= 0)
-            num = 1;
-    }
-
-    pid = getpid();
-    srand(time(NULL) * (unsigned int)pid);
-
-    /* Not a perfect seed, but not bad */
-    seed = malloc(bbs_seed_size);
-    for (ix = 0; ix < bbs_seed_size; ix++) {
-        seed[ix] = rand() % UCHAR_MAX;
-    }
-
-    bbs_srand(seed, bbs_seed_size);
-    memset(seed, 0, bbs_seed_size);
-    free(seed);
-
-    while (num-- > 0) {
-        ix = bbs_rand();
-
-        printf("%u\n", ix);
-    }
-
-    return 0;
-}
deleted file mode 100755
--- a/lib/freebl/mpi/utils/ptab.pl
+++ /dev/null
@@ -1,26 +0,0 @@
-#!/usr/bin/perl
-
-# This Source Code Form is subject to the terms of the Mozilla Public
-# License, v. 2.0. If a copy of the MPL was not distributed with this
-# file, You can obtain one at http://mozilla.org/MPL/2.0/.
-
-while(<>) {
-    chomp;
-    push(@primes, $_);
-}
-
-printf("mp_size   prime_tab_size = %d;\n", ($#primes + 1));
-print "mp_digit  prime_tab[] = {\n";
-
-print "\t";
-$last = pop(@primes);
-foreach $prime (sort {$a<=>$b} @primes) {
-    printf("0x%04X, ", $prime);
-    $brk = ($brk + 1) % 8;
-    print "\n\t" if(!$brk);
-}
-printf("0x%04X", $last);
-print "\n" if($brk);
-print "};\n\n";
-
-exit 0;
deleted file mode 100644
--- a/lib/freebl/mpi/utils/sieve.c
+++ /dev/null
@@ -1,243 +0,0 @@
-/*
- * sieve.c
- *
- * Finds prime numbers using the Sieve of Eratosthenes
- *
- * This implementation uses a bitmap to represent all odd integers in a
- * given range.  We iterate over this bitmap, crossing off the
- * multiples of each prime we find.  At the end, all the remaining set
- * bits correspond to prime integers.
- *
- * Here, we make two passes -- once we have generated a sieve-ful of
- * primes, we copy them out, reset the sieve using the highest
- * generated prime from the first pass as a base.  Then we cross out
- * all the multiples of all the primes we found the first time through,
- * and re-sieve.  In this way, we get double use of the memory we
- * allocated for the sieve the first time though.  Since we also
- * implicitly ignore multiples of 2, this amounts to 4 times the
- * values.
- *
- * This could (and probably will) be generalized to re-use the sieve a
- * few more times.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <limits.h>
-
-typedef unsigned char byte;
-
-typedef struct {
-    int size;
-    byte *bits;
-    long base;
-    int next;
-    int nbits;
-} sieve;
-
-void sieve_init(sieve *sp, long base, int nbits);
-void sieve_grow(sieve *sp, int nbits);
-long sieve_next(sieve *sp);
-void sieve_reset(sieve *sp, long base);
-void sieve_cross(sieve *sp, long val);
-void sieve_clear(sieve *sp);
-
-#define S_ISSET(S, B) (((S)->bits[(B) / CHAR_BIT] >> ((B) % CHAR_BIT)) & 1)
-#define S_SET(S, B) ((S)->bits[(B) / CHAR_BIT] |= (1 << ((B) % CHAR_BIT)))
-#define S_CLR(S, B) ((S)->bits[(B) / CHAR_BIT] &= ~(1 << ((B) % CHAR_BIT)))
-#define S_VAL(S, B) ((S)->base + (2 * (B)))
-#define S_BIT(S, V) (((V) - ((S)->base)) / 2)
-
-int
-main(int argc, char *argv[])
-{
-    sieve s;
-    long pr, *p;
-    int c, ix, cur = 0;
-
-    if (argc < 2) {
-        fprintf(stderr, "Usage: %s <width>\n", argv[0]);
-        return 1;
-    }
-
-    c = atoi(argv[1]);
-    if (c < 0)
-        c = -c;
-
-    fprintf(stderr, "%s: sieving to %d positions\n", argv[0], c);
-
-    sieve_init(&s, 3, c);
-
-    c = 0;
-    while ((pr = sieve_next(&s)) > 0) {
-        ++c;
-    }
-
-    p = calloc(c, sizeof(long));
-    if (!p) {
-        fprintf(stderr, "%s: out of memory after first half\n", argv[0]);
-        sieve_clear(&s);
-        exit(1);
-    }
-
-    fprintf(stderr, "%s: half done ... \n", argv[0]);
-
-    for (ix = 0; ix < s.nbits; ix++) {
-        if (S_ISSET(&s, ix)) {
-            p[cur] = S_VAL(&s, ix);
-            printf("%ld\n", p[cur]);
-            ++cur;
-        }
-    }
-
-    sieve_reset(&s, p[cur - 1]);
-    fprintf(stderr, "%s: crossing off %d found primes ... \n", argv[0], cur);
-    for (ix = 0; ix < cur; ix++) {
-        sieve_cross(&s, p[ix]);
-        if (!(ix % 1000))
-            fputc('.', stderr);
-    }
-    fputc('\n', stderr);
-
-    free(p);
-
-    fprintf(stderr, "%s: sieving again from %ld ... \n", argv[0], p[cur - 1]);
-    c = 0;
-    while ((pr = sieve_next(&s)) > 0) {
-        ++c;
-    }
-
-    fprintf(stderr, "%s: done!\n", argv[0]);
-    for (ix = 0; ix < s.nbits; ix++) {
-        if (S_ISSET(&s, ix)) {
-            printf("%ld\n", S_VAL(&s, ix));
-        }
-    }
-
-    sieve_clear(&s);
-
-    return 0;
-}
-
-void
-sieve_init(sieve *sp, long base, int nbits)
-{
-    sp->size = (nbits / CHAR_BIT);
-
-    if (nbits % CHAR_BIT)
-        ++sp->size;
-
-    sp->bits = calloc(sp->size, sizeof(byte));
-    memset(sp->bits, UCHAR_MAX, sp->size);
-    if (!(base & 1))
-        ++base;
-    sp->base = base;
-
-    sp->next = 0;
-    sp->nbits = sp->size * CHAR_BIT;
-}
-
-void
-sieve_grow(sieve *sp, int nbits)
-{
-    int ns = (nbits / CHAR_BIT);
-
-    if (nbits % CHAR_BIT)
-        ++ns;
-
-    if (ns > sp->size) {
-        byte *tmp;
-        int ix;
-
-        tmp = calloc(ns, sizeof(byte));
-        if (tmp == NULL) {
-            fprintf(stderr, "Error: out of memory in sieve_grow\n");
-            return;
-        }
-
-        memcpy(tmp, sp->bits, sp->size);
-        for (ix = sp->size; ix < ns; ix++) {
-            tmp[ix] = UCHAR_MAX;
-        }
-
-        free(sp->bits);
-        sp->bits = tmp;
-        sp->size = ns;
-
-        sp->nbits = sp->size * CHAR_BIT;
-    }
-}
-
-long
-sieve_next(sieve *sp)
-{
-    long out;
-    int ix = 0;
-    long val;
-
-    if (sp->next > sp->nbits)
-        return -1;
-
-    out = S_VAL(sp, sp->next);
-#ifdef DEBUG
-    fprintf(stderr, "Sieving %ld\n", out);
-#endif
-
-    /* Sieve out all multiples of the current prime */
-    val = out;
-    while (ix < sp->nbits) {
-        val += out;
-        ix = S_BIT(sp, val);
-        if ((val & 1) && ix < sp->nbits) { /* && S_ISSET(sp, ix)) { */
-            S_CLR(sp, ix);
-#ifdef DEBUG
-            fprintf(stderr, "Crossing out %ld (bit %d)\n", val, ix);
-#endif
-        }
-    }
-
-    /* Scan ahead to the next prime */
-    ++sp->next;
-    while (sp->next < sp->nbits && !S_ISSET(sp, sp->next))
-        ++sp->next;
-
-    return out;
-}
-
-void
-sieve_cross(sieve *sp, long val)
-{
-    int ix = 0;
-    long cur = val;
-
-    while (cur < sp->base)
-        cur += val;
-
-    ix = S_BIT(sp, cur);
-    while (ix < sp->nbits) {
-        if (cur & 1)
-            S_CLR(sp, ix);
-        cur += val;
-        ix = S_BIT(sp, cur);
-    }
-}
-
-void
-sieve_reset(sieve *sp, long base)
-{
-    memset(sp->bits, UCHAR_MAX, sp->size);
-    sp->base = base;
-    sp->next = 0;
-}
-
-void
-sieve_clear(sieve *sp)
-{
-    if (sp->bits)
-        free(sp->bits);
-
-    sp->bits = NULL;
-}
--- a/lib/freebl/rsa.c
+++ b/lib/freebl/rsa.c
@@ -316,17 +316,16 @@ RSA_NewKey(int keySizeInBits, SECItem *p
     /* 2.  Set the version number (PKCS1 v1.5 says it should be zero) */
     SECITEM_AllocItem(arena, &key->version, 1);
     key->version.data[0] = 0;
     /* 3.  Set the public exponent */
     SECITEM_TO_MPINT(*publicExponent, &e);
     kiter = 0;
     max_attempts = 5 * (keySizeInBits / 2); /* FIPS 186-4 B.3.3 steps 4.7 and 5.8 */
     do {
-        prerr = 0;
         PORT_SetError(0);
         CHECK_SEC_OK(generate_prime(&p, primeLen));
         CHECK_SEC_OK(generate_prime(&q, primeLen));
         /* Assure p > q */
         /* NOTE: PKCS #1 does not require p > q, and NSS doesn't use any
          * implementation optimization that requires p > q. We can remove
          * this code in the future.
          */
@@ -343,18 +342,17 @@ RSA_NewKey(int keySizeInBits, SECItem *p
             }
             prerr = SEC_ERROR_NEED_RANDOM; /* retry with different values */
         } else {
             prerr = PORT_GetError();
         }
         kiter++;
         /* loop until have primes */
     } while (prerr == SEC_ERROR_NEED_RANDOM && kiter < max_attempts);
-    if (prerr)
-        goto cleanup;
+
 cleanup:
     mp_clear(&p);
     mp_clear(&q);
     mp_clear(&e);
     mp_clear(&d);
     if (err) {
         MP_TO_SEC_ERROR(err);
         rv = SECFailure;
--- a/lib/freebl/rsapkcs.c
+++ b/lib/freebl/rsapkcs.c
@@ -285,20 +285,22 @@ MGF1(HASH_HashType hashAlg,
     unsigned int digestLen;
     PRUint32 counter;
     PRUint32 rounds;
     unsigned char *tempHash;
     unsigned char *temp;
     const SECHashObject *hash;
     void *hashContext;
     unsigned char C[4];
+    SECStatus rv = SECSuccess;
 
     hash = HASH_GetRawHashObject(hashAlg);
-    if (hash == NULL)
+    if (hash == NULL) {
         return SECFailure;
+    }
 
     hashContext = (*hash->create)();
     rounds = (maskLen + hash->length - 1) / hash->length;
     for (counter = 0; counter < rounds; counter++) {
         C[0] = (unsigned char)((counter >> 24) & 0xff);
         C[1] = (unsigned char)((counter >> 16) & 0xff);
         C[2] = (unsigned char)((counter >> 8) & 0xff);
         C[3] = (unsigned char)(counter & 0xff);
@@ -309,24 +311,29 @@ MGF1(HASH_HashType hashAlg,
         (*hash->update)(hashContext, mgfSeed, mgfSeedLen);
         (*hash->update)(hashContext, C, sizeof C);
 
         tempHash = mask + counter * hash->length;
         if (counter != (rounds - 1)) {
             (*hash->end)(hashContext, tempHash, &digestLen, hash->length);
         } else { /* we're in the last round and need to cut the hash */
             temp = (unsigned char *)PORT_Alloc(hash->length);
+            if (!temp) {
+                rv = SECFailure;
+                goto done;
+            }
             (*hash->end)(hashContext, temp, &digestLen, hash->length);
             PORT_Memcpy(tempHash, temp, maskLen - counter * hash->length);
             PORT_Free(temp);
         }
     }
+
+done:
     (*hash->destroy)(hashContext, PR_TRUE);
-
-    return SECSuccess;
+    return rv;
 }
 
 /* XXX Doesn't set error code */
 SECStatus
 RSA_SignRaw(RSAPrivateKey *key,
             unsigned char *output,
             unsigned int *outputLen,
             unsigned int maxOutputLen,
--- a/lib/freebl/shvfy.c
+++ b/lib/freebl/shvfy.c
@@ -7,16 +7,17 @@
 #include "stubs.h"
 #endif
 
 #include "shsign.h"
 #include "prlink.h"
 #include "prio.h"
 #include "blapi.h"
 #include "seccomon.h"
+#include "secerr.h"
 #include "stdio.h"
 #include "prmem.h"
 #include "hasht.h"
 #include "pqg.h"
 #include "blapii.h"
 
 /*
  * Most modern version of Linux support a speed optimization scheme where an
@@ -228,18 +229,22 @@ bl_CloseUnPrelink(PRFileDesc *file, int 
 #endif
 
 /* #define DEBUG_SHVERIFY 1 */
 
 static char *
 mkCheckFileName(const char *libName)
 {
     int ln_len = PORT_Strlen(libName);
+    int index = ln_len + 1 - sizeof("." SHLIB_SUFFIX);
     char *output = PORT_Alloc(ln_len + sizeof(SGN_SUFFIX));
-    int index = ln_len + 1 - sizeof("." SHLIB_SUFFIX);
+    if (!output) {
+        PORT_SetError(SEC_ERROR_NO_MEMORY);
+        return NULL;
+    }
 
     if ((index > 0) &&
         (PORT_Strncmp(&libName[index],
                       "." SHLIB_SUFFIX, sizeof("." SHLIB_SUFFIX)) == 0)) {
         ln_len = index;
     }
     PORT_Memcpy(output, libName, ln_len);
     PORT_Memcpy(&output[ln_len], SGN_SUFFIX, sizeof(SGN_SUFFIX));
new file mode 100644
--- /dev/null
+++ b/lib/libpkix/libpkix.gyp
@@ -0,0 +1,31 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+{
+  'includes': [
+    '../../coreconf/config.gypi'
+  ],
+  'targets': [
+    {
+      'target_name': 'libpkix',
+      'type': 'none',
+      'conditions': [
+        [ 'disable_libpkix==0', {
+          'dependencies': [
+            'pkix/certsel/certsel.gyp:pkixcertsel',
+            'pkix/checker/checker.gyp:pkixchecker',
+            'pkix/crlsel/crlsel.gyp:pkixcrlsel',
+            'pkix/params/params.gyp:pkixparams',
+            'pkix/results/results.gyp:pkixresults',
+            'pkix/store/store.gyp:pkixstore',
+            'pkix/top/top.gyp:pkixtop',
+            'pkix/util/util.gyp:pkixutil',
+            'pkix_pl_nss/module/module.gyp:pkixmodule',
+            'pkix_pl_nss/pki/pki.gyp:pkixpki',
+            'pkix_pl_nss/system/system.gyp:pkixsystem',
+          ],
+        }],
+      ],
+    },
+  ],
+}
\ No newline at end of file
--- a/lib/nss/nss.gyp
+++ b/lib/nss/nss.gyp
@@ -28,34 +28,18 @@
         'nss_static',
         '<(DEPTH)/lib/certhigh/certhigh.gyp:certhi',
         '<(DEPTH)/lib/cryptohi/cryptohi.gyp:cryptohi',
         '<(DEPTH)/lib/pk11wrap/pk11wrap.gyp:pk11wrap',
         '<(DEPTH)/lib/certdb/certdb.gyp:certdb',
         '<(DEPTH)/lib/pki/pki.gyp:nsspki',
         '<(DEPTH)/lib/dev/dev.gyp:nssdev',
         '<(DEPTH)/lib/base/base.gyp:nssb',
+        '<(DEPTH)/lib/libpkix/libpkix.gyp:libpkix',
       ],
-      'conditions': [
-        [ 'disable_libpkix==0', {
-          'dependencies': [
-            '<(DEPTH)/lib/libpkix/pkix/certsel/certsel.gyp:pkixcertsel',
-            '<(DEPTH)/lib/libpkix/pkix/checker/checker.gyp:pkixchecker',
-            '<(DEPTH)/lib/libpkix/pkix/params/params.gyp:pkixparams',
-            '<(DEPTH)/lib/libpkix/pkix/results/results.gyp:pkixresults',
-            '<(DEPTH)/lib/libpkix/pkix/top/top.gyp:pkixtop',
-            '<(DEPTH)/lib/libpkix/pkix/util/util.gyp:pkixutil',
-            '<(DEPTH)/lib/libpkix/pkix/crlsel/crlsel.gyp:pkixcrlsel',
-            '<(DEPTH)/lib/libpkix/pkix/store/store.gyp:pkixstore',
-            '<(DEPTH)/lib/libpkix/pkix_pl_nss/pki/pki.gyp:pkixpki',
-            '<(DEPTH)/lib/libpkix/pkix_pl_nss/system/system.gyp:pkixsystem',
-            '<(DEPTH)/lib/libpkix/pkix_pl_nss/module/module.gyp:pkixmodule'
-          ],
-          }],
-        ],
     },
     {
       'target_name': 'nss3',
       'type': 'shared_library',
       'dependencies': [
         'nss3_deps',
         '<(DEPTH)/lib/util/util.gyp:nssutil3',
       ],
--- a/lib/pk11wrap/pk11auth.c
+++ b/lib/pk11wrap/pk11auth.c
@@ -699,19 +699,21 @@ PK11_NeedPWInitForSlot(PK11SlotInfo *slo
     }
     return PR_FALSE;
 }
 
 PRBool
 PK11_NeedPWInit()
 {
     PK11SlotInfo *slot = PK11_GetInternalKeySlot();
-    PRBool ret = PK11_NeedPWInitForSlot(slot);
-
-    PK11_FreeSlot(slot);
+    PRBool ret = PR_FALSE;
+    if (slot) {
+        ret = PK11_NeedPWInitForSlot(slot);
+        PK11_FreeSlot(slot);
+    }
     return ret;
 }
 
 PRBool
 pk11_InDelayPeriod(PRIntervalTime lastTime, PRIntervalTime delayTime,
                    PRIntervalTime *retTime)
 {
     PRIntervalTime time;
--- a/lib/pk11wrap/pk11obj.c
+++ b/lib/pk11wrap/pk11obj.c
@@ -2023,16 +2023,19 @@ PK11_FindObjectsFromNickname(char *nickn
     PK11_SETATTRS(&findTemplate[1], CKA_CLASS, &objclass, sizeof(objclass));
 
     *slotptr = slot = NULL;
     *returnCount = 0;
     /* first find the slot associated with this nickname */
     if ((delimit = PORT_Strchr(nickname, ':')) != NULL) {
         int len = delimit - nickname;
         tokenName = (char *)PORT_Alloc(len + 1);
+        if (!tokenName) {
+            return CK_INVALID_HANDLE;
+        }
         PORT_Memcpy(tokenName, nickname, len);
         tokenName[len] = 0;
 
         slot = *slotptr = PK11_FindSlotByName(tokenName);
         PORT_Free(tokenName);
         /* if we couldn't find a slot, assume the nickname is an internal cert
          * with no proceding slot name */
         if (slot == NULL) {
--- a/lib/pk11wrap/pk11slot.c
+++ b/lib/pk11wrap/pk11slot.c
@@ -2479,17 +2479,21 @@ PK11_RandomUpdate(void *data, size_t byt
     }
 
     bestIsInternal = PK11_IsInternal(slot);
     status = PK11_SeedRandom(slot, data, bytes);
     PK11_FreeSlot(slot);
 
     if (!bestIsInternal) {
         /* do internal slot, too. */
-        slot = PK11_GetInternalSlot(); /* can't fail */
+        slot = PK11_GetInternalSlot();
+        PORT_Assert(slot);
+        if (!slot) {
+            return SECFailure;
+        }
         status = PK11_SeedRandom(slot, data, bytes);
         PK11_FreeSlot(slot);
     }
     return status;
 }
 
 SECStatus
 PK11_GenerateRandom(unsigned char *data, int len)
--- a/lib/softoken/fipstokn.c
+++ b/lib/softoken/fipstokn.c
@@ -31,17 +31,17 @@
 #define NSS_AUDIT_WITH_SYSLOG 1
 #include <syslog.h>
 #include <unistd.h>
 #endif
 
 #ifdef LINUX
 #include <pthread.h>
 #include <dlfcn.h>
-#define LIBAUDIT_NAME "libaudit.so.0"
+#define LIBAUDIT_NAME "libaudit.so.1"
 #ifndef AUDIT_CRYPTO_TEST_USER
 #define AUDIT_CRYPTO_TEST_USER 2400         /* Crypto test results */
 #define AUDIT_CRYPTO_PARAM_CHANGE_USER 2401 /* Crypto attribute change */
 #define AUDIT_CRYPTO_LOGIN 2402             /* Logged in as crypto officer */
 #define AUDIT_CRYPTO_LOGOUT 2403            /* Logged out from crypto */
 #define AUDIT_CRYPTO_KEY_USER 2404          /* Create,delete,negotiate */
 #define AUDIT_CRYPTO_FAILURE_USER 2405      /* Fail decrypt,encrypt,randomize */
 #endif
--- a/lib/softoken/pkcs11c.c
+++ b/lib/softoken/pkcs11c.c
@@ -2634,43 +2634,63 @@ NSC_SignInit(CK_SESSION_HANDLE hSession,
             context->destroy = (privKey == key->objectInfo) ? (SFTKDestroy)sftk_Null : (SFTKDestroy)sftk_FreePrivKey;
             context->maxLen = MAX_ECKEY_LEN * 2;
 
             break;
 #endif /* NSS_DISABLE_ECC */
 
 #define INIT_HMAC_MECH(mmm)                                               \
     case CKM_##mmm##_HMAC_GENERAL:                                        \
+        PORT_Assert(pMechanism->pParameter);                              \
+        if (!pMechanism->pParameter) {                                    \
+            crv = CKR_MECHANISM_PARAM_INVALID;                            \
+            break;                                                        \
+        }                                                                 \
         crv = sftk_doHMACInit(context, HASH_Alg##mmm, key,                \
                               *(CK_ULONG *)pMechanism->pParameter);       \
         break;                                                            \
     case CKM_##mmm##_HMAC:                                                \
         crv = sftk_doHMACInit(context, HASH_Alg##mmm, key, mmm##_LENGTH); \
         break;
 
             INIT_HMAC_MECH(MD2)
             INIT_HMAC_MECH(MD5)
             INIT_HMAC_MECH(SHA224)
             INIT_HMAC_MECH(SHA256)
             INIT_HMAC_MECH(SHA384)
             INIT_HMAC_MECH(SHA512)
 
         case CKM_SHA_1_HMAC_GENERAL:
+            PORT_Assert(pMechanism->pParameter);
+            if (!pMechanism->pParameter) {
+                crv = CKR_MECHANISM_PARAM_INVALID;
+                break;
+            }
             crv = sftk_doHMACInit(context, HASH_AlgSHA1, key,
                                   *(CK_ULONG *)pMechanism->pParameter);
             break;
         case CKM_SHA_1_HMAC:
             crv = sftk_doHMACInit(context, HASH_AlgSHA1, key, SHA1_LENGTH);
             break;
 
         case CKM_SSL3_MD5_MAC:
+            PORT_Assert(pMechanism->pParameter);
+            if (!pMechanism->pParameter) {
+                crv = CKR_MECHANISM_PARAM_INVALID;
+                break;
+            }
             crv = sftk_doSSLMACInit(context, SEC_OID_MD5, key,
                                     *(CK_ULONG *)pMechanism->pParameter);
             break;
         case CKM_SSL3_SHA1_MAC:
+            PORT_Assert(pMechanism->pParameter);
+            if (!pMechanism->pParameter) {
+                crv = CKR_MECHANISM_PARAM_INVALID;
+                break;
+            }
             crv = sftk_doSSLMACInit(context, SEC_OID_SHA1, key,
                                     *(CK_ULONG *)pMechanism->pParameter);
             break;
         case CKM_TLS_PRF_GENERAL:
             crv = sftk_TLSPRFInit(context, key, key_type, HASH_AlgNULL, 0);
             break;
         case CKM_TLS_MAC: {
             CK_TLS_MAC_PARAMS *tls12_mac_params;
@@ -3309,28 +3329,43 @@ NSC_VerifyInit(CK_SESSION_HANDLE hSessio
             INIT_HMAC_MECH(MD2)
             INIT_HMAC_MECH(MD5)
             INIT_HMAC_MECH(SHA224)
             INIT_HMAC_MECH(SHA256)
             INIT_HMAC_MECH(SHA384)
             INIT_HMAC_MECH(SHA512)
 
         case CKM_SHA_1_HMAC_GENERAL:
+            PORT_Assert(pMechanism->pParameter);
+            if (!pMechanism->pParameter) {
+                crv = CKR_MECHANISM_PARAM_INVALID;
+                break;
+            }
             crv = sftk_doHMACInit(context, HASH_AlgSHA1, key,
                                   *(CK_ULONG *)pMechanism->pParameter);
             break;
         case CKM_SHA_1_HMAC:
             crv = sftk_doHMACInit(context, HASH_AlgSHA1, key, SHA1_LENGTH);
             break;
 
         case CKM_SSL3_MD5_MAC:
+            PORT_Assert(pMechanism->pParameter);
+            if (!pMechanism->pParameter) {
+                crv = CKR_MECHANISM_PARAM_INVALID;
+                break;
+            }
             crv = sftk_doSSLMACInit(context, SEC_OID_MD5, key,
                                     *(CK_ULONG *)pMechanism->pParameter);
             break;
         case CKM_SSL3_SHA1_MAC:
+            PORT_Assert(pMechanism->pParameter);
+            if (!pMechanism->pParameter) {
+                crv = CKR_MECHANISM_PARAM_INVALID;
+                break;
+            }
             crv = sftk_doSSLMACInit(context, SEC_OID_SHA1, key,
                                     *(CK_ULONG *)pMechanism->pParameter);
             break;
         case CKM_TLS_PRF_GENERAL:
             crv = sftk_TLSPRFInit(context, key, key_type, HASH_AlgNULL, 0);
             break;
         case CKM_NSS_TLS_PRF_GENERAL_SHA256:
             crv = sftk_TLSPRFInit(context, key, key_type, HASH_AlgSHA256, 0);
--- a/lib/ssl/selfencrypt.h
+++ b/lib/ssl/selfencrypt.h
@@ -6,18 +6,16 @@
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef __selfencrypt_h_
 #define __selfencrypt_h_
 
 #include "secmodt.h"
 
-typedef struct sslSocketStr sslSocket; /* Forward declaration. */
-
 SECStatus ssl_SelfEncryptProtect(
     sslSocket *ss, const PRUint8 *in, unsigned int inLen,
     PRUint8 *out, unsigned int *outLen, unsigned int maxOutLen);
 SECStatus ssl_SelfEncryptUnprotect(
     sslSocket *ss, const PRUint8 *in, unsigned int inLen,
     PRUint8 *out, unsigned int *outLen, unsigned int maxOutLen);
 
 /* Exported for use in unit tests.*/
--- a/lib/ssl/ssl.h
+++ b/lib/ssl/ssl.h
@@ -389,17 +389,17 @@ SSL_IMPORT SECStatus SSL_SignaturePrefGe
     PRFileDesc *fd, SSLSignatureAndHashAlg *algorithms, unsigned int *count,
     unsigned int maxCount);
 
 /*
 ** Returns the maximum number of signature algorithms that are supported and
 ** can be set or retrieved using SSL_SignatureSchemePrefSet or
 ** SSL_SignatureSchemePrefGet.
 */
-SSL_IMPORT unsigned int SSL_SignatureMaxCount();
+SSL_IMPORT unsigned int SSL_SignatureMaxCount(void);
 
 /*
 ** Define custom priorities for EC and FF groups used in DH key exchange and EC
 ** groups for ECDSA. This only changes the order of enabled lists (and thus
 ** their priorities) and enables all groups in |groups| while disabling all other
 ** groups.
 */
 SSL_IMPORT SECStatus SSL_NamedGroupConfig(PRFileDesc *fd,
--- a/lib/ssl/ssl3con.c
+++ b/lib/ssl/ssl3con.c
@@ -13114,17 +13114,17 @@ SSL_SignaturePrefGet(PRFileDesc *fd, SSL
         algorithms[i].hashAlg = (ss->ssl3.signatureSchemes[i] >> 8) & 0xff;
         algorithms[i].sigAlg = ss->ssl3.signatureSchemes[i] & 0xff;
     }
     *count = ss->ssl3.signatureSchemeCount;
     return SECSuccess;
 }
 
 unsigned int
-SSL_SignatureMaxCount()
+SSL_SignatureMaxCount(void)
 {
     return MAX_SIGNATURE_SCHEMES;
 }
 
 /* copy global default policy into socket. */
 void
 ssl3_InitSocketPolicy(sslSocket *ss)
 {
--- a/lib/util/quickder.c
+++ b/lib/util/quickder.c
@@ -403,16 +403,20 @@ DecodeInline(void* dest,
 
 static SECStatus
 DecodePointer(void* dest,
               const SEC_ASN1Template* templateEntry,
               SECItem* src, PLArenaPool* arena, PRBool checkTag)
 {
     const SEC_ASN1Template* ptrTemplate =
         SEC_ASN1GetSubtemplate(templateEntry, dest, PR_FALSE);
+    if (!ptrTemplate) {
+        PORT_SetError(SEC_ERROR_INVALID_ARGS);
+        return SECFailure;
+    }
     void* subdata = PORT_ArenaZAlloc(arena, ptrTemplate->size);
     *(void**)((char*)dest + templateEntry->offset) = subdata;
     if (subdata) {
         return DecodeItem(subdata, ptrTemplate, src, arena, checkTag);
     } else {
         PORT_SetError(SEC_ERROR_NO_MEMORY);
         return SECFailure;
     }
--- a/lib/util/secport.c
+++ b/lib/util/secport.c
@@ -694,16 +694,19 @@ NSS_PutEnv(const char *envVarName, const
     setOK = SetEnvironmentVariable(envVarName, envValue);
     if (!setOK) {
         SET_ERROR_CODE
         return SECFailure;
     }
 #endif
 
     encoded = (char *)PORT_ZAlloc(strlen(envVarName) + 2 + strlen(envValue));
+    if (!encoded) {
+        return SECFailure;
+    }
     strcpy(encoded, envVarName);
     strcat(encoded, "=");
     strcat(encoded, envValue);
 
     putEnvFailed = putenv(encoded); /* adopt. */
     if (putEnvFailed) {
         SET_ERROR_CODE
         result = SECFailure;
new file mode 100755
--- /dev/null
+++ b/mach
@@ -0,0 +1,154 @@
+#!/usr/bin/env python
+#
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+################################################################################
+#
+# This is a collection of helper tools to get stuff done in NSS.
+#
+
+import sys
+import argparse
+import subprocess
+import os
+import platform
+from hashlib import sha256
+
+cwd = os.path.dirname(os.path.abspath(__file__))
+
+
+class cfAction(argparse.Action):
+    docker_command = ["docker"]
+
+    def __call__(self, parser, args, values, option_string=None):
+        if "noroot" not in values:
+            self.setDockerCommand()
+        else:
+            values.remove("noroot")
+
+        # First check if we can run docker.
+        try:
+            with open(os.devnull, "w") as f:
+                subprocess.check_call(
+                    self.docker_command + ["images"], stdout=f)
+        except:
+            print("Please install docker and start the docker daemon.")
+            sys.exit(1)
+
+        docker_image = 'clang-format-service:latest'
+        cf_docker_folder = cwd + "/automation/clang-format"
+
+        # Build the image if necessary.
+        if self.filesChanged(cf_docker_folder):
+            self.buildImage(docker_image, cf_docker_folder)
+
+        # Check if we have the docker image.
+        try:
+            command = self.docker_command + [
+                "image", "inspect", "clang-format-service:latest"
+            ]
+            with open(os.devnull, "w") as f:
+                subprocess.check_call(command, stdout=f)
+        except:
+            print("I have to build the docker image first.")
+            self.buildImage(docker_image, cf_docker_folder)
+
+        command = self.docker_command + [
+            'run', '-v', cwd + ':/home/worker/nss', '--rm', '-ti', docker_image
+        ]
+        # The clang format script returns 1 if something's to do. We don't care.
+        subprocess.call(command + values)
+
+    def filesChanged(self, path):
+        hash = sha256()
+        for dirname, dirnames, files in os.walk(path):
+            for file in files:
+                with open(os.path.join(dirname, file), "rb") as f:
+                    hash.update(f.read())
+        chk_file = cwd + "/.chk"
+        old_chk = ""
+        new_chk = hash.hexdigest()
+        if os.path.exists(chk_file):
+            with open(chk_file) as f:
+                old_chk = f.readline()
+        if old_chk != new_chk:
+            with open(chk_file, "w+") as f:
+                f.write(new_chk)
+            return True
+        return False
+
+    def buildImage(self, docker_image, cf_docker_folder):
+        command = self.docker_command + [
+            "build", "-t", docker_image, cf_docker_folder
+        ]
+        subprocess.check_call(command)
+        return
+
+    def setDockerCommand(self):
+        if platform.system() == "Linux":
+            self.docker_command = ["sudo"] + self.docker_command
+
+
+class buildAction(argparse.Action):
+    def __call__(self, parser, args, values, option_string=None):
+        cwd = os.path.dirname(os.path.abspath(__file__))
+        subprocess.check_call([cwd + "/build.sh"] + values)
+
+
+class testAction(argparse.Action):
+    def runTest(self, test, cycles="standard"):
+        cwd = os.path.dirname(os.path.abspath(__file__))
+        domsuf = os.getenv('DOMSUF', "localdomain")
+        host = os.getenv('HOST', "localhost")
+        env = {
+            "NSS_TESTS": test,
+            "NSS_CYCLES": cycles,
+            "DOMSUF": domsuf,
+            "HOST": host
+        }
+        command = cwd + "/tests/all.sh"
+        subprocess.check_call(command, env=env)
+
+    def __call__(self, parser, args, values, option_string=None):
+        self.runTest(values)
+
+
+def parse_arguments():
+    parser = argparse.ArgumentParser(
+        description='NSS helper script. ' +
+        'Make sure to separate sub-command arguments with --.')
+    subparsers = parser.add_subparsers()
+
+    parser_build = subparsers.add_parser(
+        'build', help='All arguments are passed to build.sh')
+    parser_build.add_argument(
+        'build_args', nargs='*', help="build arguments", action=buildAction)
+
+    parser_cf = subparsers.add_parser(
+        'clang-format',
+        help='Run clang-format on all folders or provide a folder to format.')
+    parser_cf.add_argument(
+        'cf_args',
+        nargs='*',
+        help="clang-format folders and noroot if you don't want to use sudo",
+        action=cfAction)
+
+    parser_test = subparsers.add_parser(
+        'tests', help='Run tests through tests/all.sh.')
+    tests = [
+        "cipher", "lowhash", "chains", "cert", "dbtests", "tools", "fips",
+        "sdr", "crmf", "smime", "ssl", "ocsp", "merge", "pkits", "ec",
+        "gtests", "ssl_gtests"
+    ]
+    parser_test.add_argument(
+        'test', choices=tests, help="Available tests", action=testAction)
+    return parser.parse_args()
+
+
+def main():
+    parse_arguments()
+
+
+if __name__ == '__main__':
+    main()
--- a/manifest.mn
+++ b/manifest.mn
@@ -5,9 +5,9 @@
 CORE_DEPTH = .
 DEPTH      = .
 
 IMPORTS =	nspr20/v4.8 \
 		$(NULL)
 
 RELEASE = nss
 
-DIRS = coreconf lib cmd gtests
+DIRS = coreconf lib cmd cpputil gtests
--- a/nss.gyp
+++ b/nss.gyp
@@ -54,45 +54,31 @@
         'lib/nss/nss.gyp:nss_static',
         'lib/pk11wrap/pk11wrap.gyp:pk11wrap',
         'lib/pkcs12/pkcs12.gyp:pkcs12',
         'lib/pkcs7/pkcs7.gyp:pkcs7',
         'lib/pki/pki.gyp:nsspki',
         'lib/smime/smime.gyp:smime',
         'lib/softoken/softoken.gyp:softokn',
         'lib/ssl/ssl.gyp:ssl',
-        'lib/util/util.gyp:nssutil'
+        'lib/util/util.gyp:nssutil',
+        'lib/libpkix/libpkix.gyp:libpkix',
       ],
       'conditions': [
         [ 'OS=="linux"', {
           'dependencies': [
             'lib/sysinit/sysinit.gyp:nsssysinit_static',
           ],
         }],
         [ 'disable_dbm==0', {
           'dependencies': [
             'lib/dbm/src/src.gyp:dbm',
             'lib/softoken/legacydb/legacydb.gyp:nssdbm',
           ],
         }],
-        [ 'disable_libpkix==0', {
-          'dependencies': [
-            'lib/libpkix/pkix/certsel/certsel.gyp:pkixcertsel',
-            'lib/libpkix/pkix/checker/checker.gyp:pkixchecker',
-            'lib/libpkix/pkix/crlsel/crlsel.gyp:pkixcrlsel',
-            'lib/libpkix/pkix/params/params.gyp:pkixparams',
-            'lib/libpkix/pkix/results/results.gyp:pkixresults',
-            'lib/libpkix/pkix/store/store.gyp:pkixstore',
-            'lib/libpkix/pkix/top/top.gyp:pkixtop',
-            'lib/libpkix/pkix/util/util.gyp:pkixutil',
-            'lib/libpkix/pkix_pl_nss/module/module.gyp:pkixmodule',
-            'lib/libpkix/pkix_pl_nss/pki/pki.gyp:pkixpki',
-            'lib/libpkix/pkix_pl_nss/system/system.gyp:pkixsystem',
-          ],
-        }],
         [ 'use_system_sqlite==0', {
           'dependencies': [
             'lib/sqlite/sqlite.gyp:sqlite',
           ],
         }],
         [ 'moz_fold_libs==1', {
           'dependencies': [
             'lib/nss/nss.gyp:nss3_static',
--- a/readme.md
+++ b/readme.md
@@ -37,19 +37,20 @@ After changing into the NSS directory a 
 Once the build is done the build output is found in the directory
 `../dist/Debug` for debug builds and `../dist/Release` for opt builds.
 Exported header files can be found in the `include` directory, library files in
 directory `lib`, and tools in directory `bin`. In order to run the tools, set
 your system environment to use the libraries of your build from the "lib"
 directory, e.g., using the `LD_LIBRARY_PATH` or `DYLD_LIBRARY_PATH`.
 
     Usage: build.sh [-hcv] [-j <n>] [--nspr] [--gyp|-g] [--opt|-o] [-m32]
-                    [--test] [--fuzz] [--pprof] [--scan-build[=output]]
+                    [--test] [--pprof] [--scan-build[=output]] [--ct-verif]
                     [--asan] [--ubsan] [--msan] [--sancov[=edge|bb|func|...]]
-                    [--ct-verif] [--disable-tests]
+                    [--disable-tests] [--fuzz[=tls|oss]] [--system-sqlite]
+                    [--no-zdefs] [--with-nspr] [--system-nspr] [--enable-libpkix]
 
     This script builds NSS with gyp and ninja.
 
     This build system is still under development.  It does not yet support all
     the features or platforms that NSS supports.
 
     NSS build tool options:
 
@@ -57,28 +58,37 @@ directory, e.g., using the `LD_LIBRARY_P
         -c               clean before build
         -v               verbose build
         -j <n>           run at most <n> concurrent jobs
         --nspr           force a rebuild of NSPR
         --gyp|-g         force a rerun of gyp
         --opt|-o         do an opt build
         -m32             do a 32-bit build on a 64-bit system
         --test           ignore map files and export everything we have
-        --fuzz           enable fuzzing mode. this always enables test builds
+        --fuzz           build fuzzing targets (this always enables test builds)
+                         --fuzz=tls to enable TLS fuzzing mode
+                         --fuzz=oss to build for OSS-Fuzz
         --pprof          build with gperftool support
         --ct-verif       build with valgrind for ct-verif
         --scan-build     run the build with scan-build (scan-build has to be in the path)
                          --scan-build=/out/path sets the output path for scan-build
         --asan           do an asan build
         --ubsan          do an ubsan build
                          --ubsan=bool,shift,... sets specific UB sanitizers
         --msan           do an msan build
         --sancov         do sanitize coverage builds
                          --sancov=func sets coverage to function level for example
         --disable-tests  don't build tests and corresponding cmdline utils
+        --system-sqlite  use system sqlite
+        --no-zdefs       don't set -Wl,-z,defs
+        --with-nspr      don't build NSPR but use the one at the given location, e.g.
+                         --with-nspr=/path/to/nspr/include:/path/to/nspr/lib
+        --system-nspr    use system nspr. This requires an installation of NSPR and
+                         might not work on all systems.
+        --enable-libpkix make libpkix part of the build.
 
 ## Building NSS (legacy build system)
 
 After changing into the NSS directory a typical build of 32-bit NSS is done as
 follows:
 
     make nss_build_all
 
--- a/tests/gtests/gtests.sh
+++ b/tests/gtests/gtests.sh
@@ -19,17 +19,17 @@
 
 ############################## gtest_init ##############################
 # local shell function to initialize this script
 ########################################################################
 gtest_init()
 {
   cd "$(dirname "$1")"
   if [ -z "${INIT_SOURCED}" -o "${INIT_SOURCED}" != "TRUE" ]; then
-      cd common
+      cd ../common
       . ./init.sh
   fi
 
   SCRIPTNAME=gtests.sh
 
   if [ -z "${CLEANUP}" ] ; then   # if nobody else is responsible for
     CLEANUP="${SCRIPTNAME}"       # cleaning this script will do it
   fi