mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-23 21:01:08 +00:00
Bug 1370890 - land NSS a1a6eb781dd4 UPGRADE_NSS_RELEASE, r=me
--HG-- extra : rebase_source : b38b2c15012f240a5d34f91446ca20be38f61962
This commit is contained in:
parent
d136290c7a
commit
ff206e6461
@ -28,6 +28,7 @@ include $(CORE_DEPTH)/coreconf/config.mk
|
||||
|
||||
ifdef NSS_DISABLE_GTESTS
|
||||
DIRS := $(filter-out gtests,$(DIRS))
|
||||
DIRS := $(filter-out cpputil,$(DIRS))
|
||||
endif
|
||||
|
||||
#######################################################################
|
||||
|
@ -1 +1 @@
|
||||
NSS_3_31_RTM
|
||||
a1a6eb781dd4
|
||||
|
@ -1,12 +0,0 @@
|
||||
Functions changes summary: 0 Removed, 0 Changed, 6 Added functions
|
||||
Variables changes summary: 0 Removed, 0 Changed, 0 Added variable
|
||||
|
||||
6 Added functions:
|
||||
|
||||
'function SECStatus CERT_GetCertIsPerm(const CERTCertificate*, PRBool*)' {CERT_GetCertIsPerm@@NSS_3.31}
|
||||
'function SECStatus CERT_GetCertIsTemp(const CERTCertificate*, PRBool*)' {CERT_GetCertIsTemp@@NSS_3.31}
|
||||
'function CERTCertificate* PK11_FindCertFromURI(const char*, void*)' {PK11_FindCertFromURI@@NSS_3.31}
|
||||
'function CERTCertList* PK11_FindCertsFromURI(const char*, void*)' {PK11_FindCertsFromURI@@NSS_3.31}
|
||||
'function char* PK11_GetModuleURI(SECMODModule*)' {PK11_GetModuleURI@@NSS_3.31}
|
||||
'function char* PK11_GetTokenURI()' {PK11_GetTokenURI@@NSS_3.31}
|
||||
|
@ -1,12 +0,0 @@
|
||||
Functions changes summary: 0 Removed, 0 Changed, 6 Added functions
|
||||
Variables changes summary: 0 Removed, 0 Changed, 0 Added variable
|
||||
|
||||
6 Added functions:
|
||||
|
||||
'function void PK11URI_CreateURI(size_t, size_t)' {PK11URI_CreateURI@@NSSUTIL_3.31}
|
||||
'function void PK11URI_DestroyURI()' {PK11URI_DestroyURI@@NSSUTIL_3.31}
|
||||
'function char* PK11URI_FormatURI()' {PK11URI_FormatURI@@NSSUTIL_3.31}
|
||||
'function const char* PK11URI_GetPathAttribute(const char*)' {PK11URI_GetPathAttribute@@NSSUTIL_3.31}
|
||||
'function const char* PK11URI_GetQueryAttribute(const char*)' {PK11URI_GetQueryAttribute@@NSSUTIL_3.31}
|
||||
'function void PK11URI_ParseURI(const char*)' {PK11URI_ParseURI@@NSSUTIL_3.31}
|
||||
|
@ -1,14 +0,0 @@
|
||||
Functions changes summary: 0 Removed, 1 Changed, 0 Added function
|
||||
Variables changes summary: 0 Removed, 0 Changed, 0 Added variable
|
||||
|
||||
1 function with some indirect sub-type change:
|
||||
|
||||
[C]'function SECStatus SSL_GetPreliminaryChannelInfo(SSLPreliminaryChannelInfo*, PRUintn)' at sslinfo.c:115:1 has some indirect sub-type changes:
|
||||
parameter 1 of type 'SSLPreliminaryChannelInfo*' has sub-type changes:
|
||||
in pointed to type 'typedef SSLPreliminaryChannelInfo' at sslt.h:318:1:
|
||||
underlying type 'struct SSLPreliminaryChannelInfoStr' at sslt.h:287:1 changed:
|
||||
type size changed from 128 to 160 bits
|
||||
1 data member insertion:
|
||||
'PRUint32 SSLPreliminaryChannelInfoStr::maxEarlyDataSize', at offset 128 (in bits) at sslt.h:314:1
|
||||
|
||||
|
@ -1 +1 @@
|
||||
NSS_3_30_BRANCH
|
||||
NSS_3_31_BRANCH
|
||||
|
26
security/nss/automation/clang-format/Dockerfile
Normal file
26
security/nss/automation/clang-format/Dockerfile
Normal file
@ -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"]
|
@ -1,8 +1,10 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
source $(dirname "$0")/tools.sh
|
||||
|
||||
set +x
|
||||
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.
|
||||
@ -22,13 +24,13 @@ blacklist=(
|
||||
"./.hg" \
|
||||
)
|
||||
|
||||
top="$PWD/$(dirname $0)/../../.."
|
||||
top="$(dirname $0)/../.."
|
||||
cd "$top"
|
||||
|
||||
if [ $# -gt 0 ]; then
|
||||
dirs=("$@")
|
||||
else
|
||||
dirs=($(find . ! -path . \( ! -regex '.*/' \) -maxdepth 2 -mindepth 1 -type d))
|
||||
dirs=($(find . -maxdepth 2 -mindepth 1 -type d ! -path . \( ! -regex '.*/' \)))
|
||||
fi
|
||||
|
||||
format_folder()
|
43
security/nss/automation/clang-format/setup.sh
Normal file
43
security/nss/automation/clang-format/setup.sh
Normal file
@ -0,0 +1,43 @@
|
||||
#!/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-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
|
@ -10,11 +10,27 @@ import shutil
|
||||
import glob
|
||||
from optparse import OptionParser
|
||||
from subprocess import check_call
|
||||
from subprocess import check_output
|
||||
|
||||
nssutil_h = "lib/util/nssutil.h"
|
||||
softkver_h = "lib/softoken/softkver.h"
|
||||
nss_h = "lib/nss/nss.h"
|
||||
nssckbi_h = "lib/ckfw/builtins/nssckbi.h"
|
||||
abi_base_version_file = "automation/abi-check/previous-nss-release"
|
||||
|
||||
abi_report_files = ['automation/abi-check/expected-report-libfreebl3.so.txt',
|
||||
'automation/abi-check/expected-report-libfreeblpriv3.so.txt',
|
||||
'automation/abi-check/expected-report-libnspr4.so.txt',
|
||||
'automation/abi-check/expected-report-libnss3.so.txt',
|
||||
'automation/abi-check/expected-report-libnssckbi.so.txt',
|
||||
'automation/abi-check/expected-report-libnssdbm3.so.txt',
|
||||
'automation/abi-check/expected-report-libnsssysinit.so.txt',
|
||||
'automation/abi-check/expected-report-libnssutil3.so.txt',
|
||||
'automation/abi-check/expected-report-libplc4.so.txt',
|
||||
'automation/abi-check/expected-report-libplds4.so.txt',
|
||||
'automation/abi-check/expected-report-libsmime3.so.txt',
|
||||
'automation/abi-check/expected-report-libsoftokn3.so.txt',
|
||||
'automation/abi-check/expected-report-libssl3.so.txt']
|
||||
|
||||
def check_call_noisy(cmd, *args, **kwargs):
|
||||
print "Executing command:", cmd
|
||||
@ -132,6 +148,26 @@ def set_root_ca_version():
|
||||
sed_inplace('s/^\(#define *NSS_BUILTINS_LIBRARY_VERSION_MINOR *\).*$/\\1' + minor + '/', nssckbi_h)
|
||||
|
||||
def set_all_lib_versions(version, major, minor, patch, build):
|
||||
grep_major = check_output(['grep', 'define.*NSS_VMAJOR', nss_h])
|
||||
grep_minor = check_output(['grep', 'define.*NSS_VMINOR', nss_h])
|
||||
|
||||
old_major = int(grep_major.split()[2]);
|
||||
old_minor = int(grep_minor.split()[2]);
|
||||
|
||||
new_major = int(major)
|
||||
new_minor = int(minor)
|
||||
|
||||
if (old_major < new_major or (old_major == new_major and old_minor < new_minor)):
|
||||
print "You're increasing the minor (or major) version:"
|
||||
print "- erasing ABI comparison expectations"
|
||||
new_branch = "NSS_" + str(old_major) + "_" + str(old_minor) + "_BRANCH"
|
||||
print "- setting reference branch to the branch of the previous version: " + new_branch
|
||||
with open(abi_base_version_file, "w") as abi_base:
|
||||
abi_base.write("%s\n" % new_branch)
|
||||
for report_file in abi_report_files:
|
||||
with open(report_file, "w") as report_file_handle:
|
||||
report_file_handle.truncate()
|
||||
|
||||
set_full_lib_versions(version)
|
||||
set_major_versions(major)
|
||||
set_minor_versions(minor)
|
||||
|
@ -746,7 +746,7 @@ async function scheduleTools() {
|
||||
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"
|
||||
]
|
||||
}));
|
||||
|
||||
|
@ -24,7 +24,7 @@ split_util() {
|
||||
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
|
||||
@ -32,6 +32,7 @@ split_util() {
|
||||
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.
|
||||
@ -66,7 +67,7 @@ split_softoken() {
|
||||
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
|
||||
@ -75,6 +76,7 @@ split_softoken() {
|
||||
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.
|
||||
|
@ -93,6 +93,7 @@ while [ $# -gt 0 ]; do
|
||||
--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
|
||||
|
@ -33,6 +33,7 @@
|
||||
'<(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', {
|
||||
@ -41,21 +42,6 @@
|
||||
'<(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', {
|
||||
|
@ -32,6 +32,12 @@ 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
|
||||
@ -70,20 +76,10 @@ 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
|
||||
@ -121,9 +117,6 @@ NSS_LIBS_1 = \
|
||||
$(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) \
|
||||
@ -201,7 +194,7 @@ 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) \
|
||||
@ -220,7 +213,7 @@ else
|
||||
|
||||
# $(PROGRAM) has explicit dependencies on $(EXTRA_LIBS)
|
||||
EXTRA_LIBS += \
|
||||
$(DIST)/lib/$(LIB_PREFIX)sectool.$(LIB_SUFFIX) \
|
||||
$(SECTOOL_LIB) \
|
||||
$(NULL)
|
||||
|
||||
ifeq ($(OS_ARCH), AIX)
|
||||
@ -238,6 +231,7 @@ EXTRA_SHARED_LIBS += \
|
||||
-lplds4 \
|
||||
-lnspr4 \
|
||||
$(NULL)
|
||||
ifndef NSS_BUILD_UTIL_ONLY
|
||||
ifndef NSS_BUILD_SOFTOKEN_ONLY
|
||||
EXTRA_SHARED_LIBS += \
|
||||
-lssl3 \
|
||||
@ -245,6 +239,7 @@ EXTRA_SHARED_LIBS += \
|
||||
-lnss3
|
||||
endif
|
||||
endif
|
||||
endif
|
||||
|
||||
ifdef SOFTOKEN_LIB_DIR
|
||||
ifdef NSS_USE_SYSTEM_FREEBL
|
||||
|
@ -10,3 +10,4 @@
|
||||
*/
|
||||
|
||||
#error "Do not include this header file."
|
||||
|
||||
|
49
security/nss/cpputil/Makefile
Normal file
49
security/nss/cpputil/Makefile
Normal file
@ -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). #
|
||||
#######################################################################
|
15
security/nss/cpputil/config.mk
Normal file
15
security/nss/cpputil/config.mk
Normal file
@ -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 =
|
||||
|
18
security/nss/cpputil/manifest.mn
Normal file
18
security/nss/cpputil/manifest.mn
Normal file
@ -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)
|
@ -35,6 +35,7 @@ struct ScopedDelete {
|
||||
}
|
||||
void operator()(PK11URI* uri) { PK11URI_DestroyURI(uri); }
|
||||
void operator()(PLArenaPool* arena) { PORT_FreeArena(arena, PR_FALSE); }
|
||||
void operator()(PK11Context* context) { PK11_DestroyContext(context, true); }
|
||||
};
|
||||
|
||||
template <class T>
|
||||
@ -64,6 +65,7 @@ SCOPED(SECKEYPrivateKey);
|
||||
SCOPED(SECKEYPrivateKeyList);
|
||||
SCOPED(PK11URI);
|
||||
SCOPED(PLArenaPool);
|
||||
SCOPED(PK11Context);
|
||||
|
||||
#undef SCOPED
|
||||
|
||||
|
39
security/nss/cpputil/scoped_ptrs_util.h
Normal file
39
security/nss/cpputil/scoped_ptrs_util.h
Normal file
@ -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__
|
@ -1,4 +1,5 @@
|
||||
---
|
||||
Language: Cpp
|
||||
BasedOnStyle: Google
|
||||
SortIncludes: false
|
||||
...
|
||||
|
@ -18,8 +18,20 @@ typedef struct AVATestValuesStr {
|
||||
bool expectedResult;
|
||||
} AVATestValues;
|
||||
|
||||
class Alg1485Test : public ::testing::Test,
|
||||
public ::testing::WithParamInterface<AVATestValues> {};
|
||||
typedef struct AVACompareValuesStr {
|
||||
std::string avaString1;
|
||||
std::string avaString2;
|
||||
SECComparison expectedResult;
|
||||
} AVACompareValues;
|
||||
|
||||
class Alg1485Test : public ::testing::Test {};
|
||||
|
||||
class Alg1485ParseTest : public Alg1485Test,
|
||||
public ::testing::WithParamInterface<AVATestValues> {};
|
||||
|
||||
class Alg1485CompareTest
|
||||
: public Alg1485Test,
|
||||
public ::testing::WithParamInterface<AVACompareValues> {};
|
||||
|
||||
static const AVATestValues kAVATestStrings[] = {
|
||||
{"CN=Marshall T. Rose, O=Dover Beach Consulting, L=Santa Clara, "
|
||||
@ -45,13 +57,36 @@ static const AVATestValues kAVATestStrings[] = {
|
||||
// { "CN=Somebody,L=Set,O=Up,C=US,01=The,02=Bomb", false },
|
||||
};
|
||||
|
||||
TEST_P(Alg1485Test, TryParsingAVAStrings) {
|
||||
static const AVACompareValues kAVACompareStrings[] = {
|
||||
{"CN=Max, O=Mozilla, ST=Berlin", "CN=Max, O=Mozilla, ST=Berlin, C=DE",
|
||||
SECLessThan},
|
||||
{"CN=Max, O=Mozilla, ST=Berlin, C=DE", "CN=Max, O=Mozilla, ST=Berlin",
|
||||
SECGreaterThan},
|
||||
{"CN=Max, O=Mozilla, ST=Berlin, C=DE", "CN=Max, O=Mozilla, ST=Berlin, C=DE",
|
||||
SECEqual},
|
||||
{"CN=Max1, O=Mozilla, ST=Berlin, C=DE",
|
||||
"CN=Max2, O=Mozilla, ST=Berlin, C=DE", SECLessThan},
|
||||
{"CN=Max, O=Mozilla, ST=Berlin, C=DE", "CN=Max, O=Mozilla, ST=Berlin, C=US",
|
||||
SECLessThan},
|
||||
};
|
||||
|
||||
TEST_P(Alg1485ParseTest, TryParsingAVAStrings) {
|
||||
const AVATestValues& param(GetParam());
|
||||
|
||||
ScopedCERTName certName(CERT_AsciiToName(param.avaString.c_str()));
|
||||
ASSERT_EQ(certName != nullptr, param.expectedResult);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ParseAVAStrings, Alg1485Test,
|
||||
::testing::ValuesIn(kAVATestStrings));
|
||||
TEST_P(Alg1485CompareTest, CompareAVAStrings) {
|
||||
const AVACompareValues& param(GetParam());
|
||||
ScopedCERTName a(CERT_AsciiToName(param.avaString1.c_str()));
|
||||
ScopedCERTName b(CERT_AsciiToName(param.avaString2.c_str()));
|
||||
ASSERT_TRUE(a && b);
|
||||
EXPECT_EQ(param.expectedResult, CERT_CompareName(a.get(), b.get()));
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(ParseAVAStrings, Alg1485ParseTest,
|
||||
::testing::ValuesIn(kAVATestStrings));
|
||||
INSTANTIATE_TEST_CASE_P(CompareAVAStrings, Alg1485CompareTest,
|
||||
::testing::ValuesIn(kAVACompareStrings));
|
||||
}
|
||||
|
@ -14,9 +14,9 @@ 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)
|
||||
|
172
security/nss/gtests/common/gcm-vectors.h
Normal file
172
security/nss/gtests/common/gcm-vectors.h
Normal file
@ -0,0 +1,172 @@
|
||||
/* 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 gcm_vectors_h__
|
||||
#define gcm_vectors_h__
|
||||
|
||||
#include <string>
|
||||
|
||||
typedef struct gcm_kat_str {
|
||||
std::string key;
|
||||
std::string plaintext;
|
||||
std::string additional_data;
|
||||
std::string iv;
|
||||
std::string hash_key;
|
||||
std::string ghash;
|
||||
std::string result;
|
||||
} gcm_kat_value;
|
||||
|
||||
/*
|
||||
* http://csrc.nist.gov/groups/ST/toolkit/BCM/documents/proposedmodes/gcm/gcm-revised-spec.pdf
|
||||
*/
|
||||
const gcm_kat_value kGcmKatValues[] = {
|
||||
{"00000000000000000000000000000000", "", "", "000000000000000000000000",
|
||||
"66e94bd4ef8a2c3b884cfa59ca342b2e", "00000000000000000000000000000000",
|
||||
"58e2fccefa7e3061367f1d57a4e7455a"},
|
||||
|
||||
{"00000000000000000000000000000000", "00000000000000000000000000000000", "",
|
||||
"000000000000000000000000", "66e94bd4ef8a2c3b884cfa59ca342b2e",
|
||||
"f38cbb1ad69223dcc3457ae5b6b0f885",
|
||||
"0388dace60b6a392f328c2b971b2fe78ab6e47d42cec13bdf53a67b21257bddf"},
|
||||
|
||||
{"feffe9928665731c6d6a8f9467308308",
|
||||
"d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c959"
|
||||
"56809532fcf0e2449a6b525b16aedf5aa0de657ba637b391aafd255",
|
||||
"", "cafebabefacedbaddecaf888", "b83b533708bf535d0aa6e52980d53b78",
|
||||
"7f1b32b81b820d02614f8895ac1d4eac",
|
||||
"42831ec2217774244b7221b784d0d49ce3aa212f2c02a4e035c17e2329aca12e21d514b25"
|
||||
"466931c7d8f6a5aac84aa051ba30b396a0aac973d58e091473f59854d5c2af327cd64a62c"
|
||||
"f35abd2ba6fab4"},
|
||||
|
||||
{"feffe9928665731c6d6a8f9467308308",
|
||||
"d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c959"
|
||||
"56809532fcf0e2449a6b525b16aedf5aa0de657ba637b39",
|
||||
"feedfacedeadbeeffeedfacedeadbeefabaddad2", "cafebabefacedbaddecaf888",
|
||||
"b83b533708bf535d0aa6e52980d53b78", "698e57f70e6ecc7fd9463b7260a9ae5f",
|
||||
"42831ec2217774244b7221b784d0d49ce3aa212f2c02a4e035c17e2329aca12e21d514b25"
|
||||
"466931c7d8f6a5aac84aa051ba30b396a0aac973d58e0915bc94fbc3221a5db94fae95ae7"
|
||||
"121a47"},
|
||||
|
||||
{"feffe9928665731c6d6a8f9467308308",
|
||||
"d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c959"
|
||||
"56809532fcf0e2449a6b525b16aedf5aa0de657ba637b39",
|
||||
"feedfacedeadbeeffeedfacedeadbeefabaddad2", "cafebabefacedbad",
|
||||
"b83b533708bf535d0aa6e52980d53b78", "df586bb4c249b92cb6922877e444d37b",
|
||||
"61353b4c2806934a777ff51fa22a4755699b2a714fcdc6f83766e5f97b6c742373806900e"
|
||||
"49f24b22b097544d4896b424989b5e1ebac0f07c23f45983612d2e79e3b0785561be14aac"
|
||||
"a2fccb"},
|
||||
|
||||
{"feffe9928665731c6d6a8f9467308308",
|
||||
"d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c959"
|
||||
"56809532fcf0e2449a6b525b16aedf5aa0de657ba637b39",
|
||||
"feedfacedeadbeeffeedfacedeadbeefabaddad2",
|
||||
"9313225df88406e555909c5aff5269aa6a7a9538534f7da1e4c303d2a318a728c3c0c9515"
|
||||
"6809539fcf0e2429a6b525416aedbf5a0de6a57a637b39b",
|
||||
"b83b533708bf535d0aa6e52980d53b78", "1c5afe9760d3932f3c9a878aac3dc3de",
|
||||
"8ce24998625615b603a033aca13fb894be9112a5c3a211a8ba262a3cca7e2ca701e4a9a4f"
|
||||
"ba43c90ccdcb281d48c7c6fd62875d2aca417034c34aee5619cc5aefffe0bfa462af43c16"
|
||||
"99d050"},
|
||||
|
||||
{"000000000000000000000000000000000000000000000000", "", "",
|
||||
"000000000000000000000000", "aae06992acbf52a3e8f4a96ec9300bd7",
|
||||
"00000000000000000000000000000000", "cd33b28ac773f74ba00ed1f312572435"},
|
||||
|
||||
{"000000000000000000000000000000000000000000000000",
|
||||
"00000000000000000000000000000000", "", "000000000000000000000000",
|
||||
"aae06992acbf52a3e8f4a96ec9300bd7", "e2c63f0ac44ad0e02efa05ab6743d4ce",
|
||||
"98e7247c07f0fe411c267e4384b0f6002ff58d80033927ab8ef4d4587514f0fb"},
|
||||
|
||||
{"feffe9928665731c6d6a8f9467308308feffe9928665731c",
|
||||
"d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c959"
|
||||
"56809532fcf0e2449a6b525b16aedf5aa0de657ba637b391aafd255",
|
||||
"", "cafebabefacedbaddecaf888", "466923ec9ae682214f2c082badb39249",
|
||||
"51110d40f6c8fff0eb1ae33445a889f0",
|
||||
"3980ca0b3c00e841eb06fac4872a2757859e1ceaa6efd984628593b40ca1e19c7d773d00c"
|
||||
"144c525ac619d18c84a3f4718e2448b2fe324d9ccda2710acade2569924a7c8587336bfb1"
|
||||
"18024db8674a14"},
|
||||
|
||||
{"feffe9928665731c6d6a8f9467308308feffe9928665731c",
|
||||
"d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c959"
|
||||
"56809532fcf0e2449a6b525b16aedf5aa0de657ba637b39",
|
||||
"feedfacedeadbeeffeedfacedeadbeefabaddad2", "cafebabefacedbaddecaf888",
|
||||
"466923ec9ae682214f2c082badb39249", "ed2ce3062e4a8ec06db8b4c490e8a268",
|
||||
"3980ca0b3c00e841eb06fac4872a2757859e1ceaa6efd984628593b40ca1e19c7d773d00c"
|
||||
"144c525ac619d18c84a3f4718e2448b2fe324d9ccda27102519498e80f1478f37ba55bd6d"
|
||||
"27618c"},
|
||||
|
||||
{"feffe9928665731c6d6a8f9467308308feffe9928665731c",
|
||||
"d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c959"
|
||||
"56809532fcf0e2449a6b525b16aedf5aa0de657ba637b39",
|
||||
"feedfacedeadbeeffeedfacedeadbeefabaddad2", "cafebabefacedbad",
|
||||
"466923ec9ae682214f2c082badb39249", "1e6a133806607858ee80eaf237064089",
|
||||
"0f10f599ae14a154ed24b36e25324db8c566632ef2bbb34f8347280fc4507057fddc29df9"
|
||||
"a471f75c66541d4d4dad1c9e93a19a58e8b473fa0f062f765dcc57fcf623a24094fcca40d"
|
||||
"3533f8"},
|
||||
|
||||
{"feffe9928665731c6d6a8f9467308308feffe9928665731c",
|
||||
"d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c959"
|
||||
"56809532fcf0e2449a6b525b16aedf5aa0de657ba637b39",
|
||||
"feedfacedeadbeeffeedfacedeadbeefabaddad2",
|
||||
"9313225df88406e555909c5aff5269aa6a7a9538534f7da1e4c303d2a318a728c3c0c9515"
|
||||
"6809539fcf0e2429a6b525416aedbf5a0de6a57a637b39b",
|
||||
"466923ec9ae682214f2c082badb39249", "82567fb0b4cc371801eadec005968e94",
|
||||
"d27e88681ce3243c4830165a8fdcf9ff1de9a1d8e6b447ef6ef7b79828666e4581e79012a"
|
||||
"f34ddd9e2f037589b292db3e67c036745fa22e7e9b7373bdcf566ff291c25bbb8568fc3d3"
|
||||
"76a6d9"},
|
||||
|
||||
{"0000000000000000000000000000000000000000000000000000000000000000", "", "",
|
||||
"000000000000000000000000", "dc95c078a2408989ad48a21492842087",
|
||||
"00000000000000000000000000000000", "530f8afbc74536b9a963b4f1c4cb738b"},
|
||||
|
||||
{"0000000000000000000000000000000000000000000000000000000000000000",
|
||||
"00000000000000000000000000000000", "", "000000000000000000000000",
|
||||
"dc95c078a2408989ad48a21492842087", "83de425c5edc5d498f382c441041ca92",
|
||||
"cea7403d4d606b6e074ec5d3baf39d18d0d1c8a799996bf0265b98b5d48ab919"},
|
||||
|
||||
{"feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308",
|
||||
"d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c959"
|
||||
"56809532fcf0e2449a6b525b16aedf5aa0de657ba637b391aafd255",
|
||||
"", "cafebabefacedbaddecaf888", "acbef20579b4b8ebce889bac8732dad7",
|
||||
"4db870d37cb75fcb46097c36230d1612",
|
||||
"522dc1f099567d07f47f37a32a84427d643a8cdcbfe5c0c97598a2bd2555d1aa8cb08e485"
|
||||
"90dbb3da7b08b1056828838c5f61e6393ba7a0abcc9f662898015adb094dac5d93471bdec"
|
||||
"1a502270e3cc6c"},
|
||||
|
||||
{"feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308",
|
||||
"d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c959"
|
||||
"56809532fcf0e2449a6b525b16aedf5aa0de657ba637b39",
|
||||
"feedfacedeadbeeffeedfacedeadbeefabaddad2", "cafebabefacedbaddecaf888",
|
||||
"acbef20579b4b8ebce889bac8732dad7", "8bd0c4d8aacd391e67cca447e8c38f65",
|
||||
"522dc1f099567d07f47f37a32a84427d643a8cdcbfe5c0c97598a2bd2555d1aa8cb08e485"
|
||||
"90dbb3da7b08b1056828838c5f61e6393ba7a0abcc9f66276fc6ece0f4e1768cddf8853bb"
|
||||
"2d551b"},
|
||||
|
||||
{"feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308",
|
||||
"d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c959"
|
||||
"56809532fcf0e2449a6b525b16aedf5aa0de657ba637b39",
|
||||
"feedfacedeadbeeffeedfacedeadbeefabaddad2", "cafebabefacedbad",
|
||||
"acbef20579b4b8ebce889bac8732dad7", "75a34288b8c68f811c52b2e9a2f97f63",
|
||||
"c3762df1ca787d32ae47c13bf19844cbaf1ae14d0b976afac52ff7d79bba9de0feb582d33"
|
||||
"934a4f0954cc2363bc73f7862ac430e64abe499f47c9b1f3a337dbf46a792c45e454913fe"
|
||||
"2ea8f2"},
|
||||
|
||||
{"feffe9928665731c6d6a8f9467308308feffe9928665731c6d6a8f9467308308",
|
||||
"d9313225f88406e5a55909c5aff5269a86a7a9531534f7da2e4c303d8a318a721c3c0c959"
|
||||
"56809532fcf0e2449a6b525b16aedf5aa0de657ba637b39",
|
||||
"feedfacedeadbeeffeedfacedeadbeefabaddad2",
|
||||
"9313225df88406e555909c5aff5269aa6a7a9538534f7da1e4c303d2a318a728c3c0c9515"
|
||||
"6809539fcf0e2429a6b525416aedbf5a0de6a57a637b39b",
|
||||
"acbef20579b4b8ebce889bac8732dad7", "d5ffcf6fc5ac4d69722187421a7f170b",
|
||||
"5a8def2f0c9e53f1f75d7853659e2a20eeb2b22aafde6419a058ab4f6f746bf40fc0c3b78"
|
||||
"0f244452da3ebf1c5d82cdea2418997200ef82e44ae7e3fa44a8266ee1c8eb0c8b5d4cf5a"
|
||||
"e9f19a"},
|
||||
|
||||
/* Extra, non-NIST, test case to test 64-bit binary multiplication carry
|
||||
* correctness. This is a GHASH-only test. */
|
||||
{"", "", "", "", "0000000000000000fcefef64ffc4766c",
|
||||
"3561e34e52d8b598f9937982512fff27",
|
||||
"0000000000000000ffcef9ebbffdbd8b00000000000000000000000000000000"}};
|
||||
|
||||
#endif // gcm_vectors_h__
|
26
security/nss/gtests/common/gtests-util.cc
Normal file
26
security/nss/gtests/common/gtests-util.cc
Normal file
@ -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;
|
||||
}
|
@ -6,9 +6,13 @@ 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 \
|
||||
@ -17,6 +21,3 @@ INCLUDES += -I$(CORE_DEPTH)/gtests/google_test/gtest/include \
|
||||
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
|
||||
|
21
security/nss/gtests/common/util.h
Normal file
21
security/nss/gtests/common/util.h
Normal file
@ -0,0 +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/. */
|
||||
|
||||
#ifndef util_h__
|
||||
#define util_h__
|
||||
|
||||
#include <cassert>
|
||||
#include <vector>
|
||||
|
||||
std::vector<uint8_t> hex_string_to_bytes(std::string s) {
|
||||
std::vector<uint8_t> bytes;
|
||||
for (size_t i = 0; i < s.length(); i += 2) {
|
||||
bytes.push_back(std::stoul(s.substr(i, 2), nullptr, 16));
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
#endif // util_h__
|
@ -4,14 +4,13 @@
|
||||
* 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 {
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
'type': 'executable',
|
||||
'sources': [
|
||||
'der_getint_unittest.cc',
|
||||
'der_private_key_import_unittest.cc',
|
||||
'der_quickder_unittest.cc',
|
||||
'<(DEPTH)/gtests/common/gtests.cc'
|
||||
],
|
||||
|
@ -7,11 +7,12 @@
|
||||
#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"
|
||||
|
||||
|
@ -8,7 +8,6 @@ MODULE = nss
|
||||
|
||||
CPPSRCS = \
|
||||
der_getint_unittest.cc \
|
||||
der_private_key_import_unittest.cc \
|
||||
der_quickder_unittest.cc \
|
||||
$(NULL)
|
||||
|
||||
@ -16,9 +15,9 @@ 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)
|
||||
|
@ -14,6 +14,7 @@
|
||||
'mpi_unittest.cc',
|
||||
'dh_unittest.cc',
|
||||
'ecl_unittest.cc',
|
||||
'ghash_unittest.cc',
|
||||
'<(DEPTH)/gtests/common/gtests.cc'
|
||||
],
|
||||
'dependencies': [
|
||||
@ -50,6 +51,7 @@
|
||||
'<(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"', {
|
||||
|
55
security/nss/gtests/freebl_gtest/ghash_unittest.cc
Normal file
55
security/nss/gtests/freebl_gtest/ghash_unittest.cc
Normal file
@ -0,0 +1,55 @@
|
||||
// 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 "gcm-vectors.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "gcm.h"
|
||||
|
||||
namespace nss_test {
|
||||
|
||||
class GHashTest : public ::testing::TestWithParam<gcm_kat_value> {
|
||||
protected:
|
||||
void TestGHash(const gcm_kat_value val, bool sw) {
|
||||
// Read test data.
|
||||
std::vector<uint8_t> hash_key = hex_string_to_bytes(val.hash_key);
|
||||
ASSERT_EQ(16UL, hash_key.size());
|
||||
std::vector<uint8_t> additional_data =
|
||||
hex_string_to_bytes(val.additional_data);
|
||||
std::vector<uint8_t> result = hex_string_to_bytes(val.result);
|
||||
std::vector<uint8_t> cipher_text(result.begin(), result.end() - 16);
|
||||
std::vector<uint8_t> expected = hex_string_to_bytes(val.ghash);
|
||||
ASSERT_EQ(16UL, expected.size());
|
||||
|
||||
// Prepare context.
|
||||
gcmHashContext ghashCtx;
|
||||
ASSERT_EQ(SECSuccess, gcmHash_InitContext(&ghashCtx, hash_key.data(), sw));
|
||||
|
||||
// Hash additional_data, cipher_text.
|
||||
gcmHash_Reset(&ghashCtx,
|
||||
const_cast<const unsigned char *>(additional_data.data()),
|
||||
additional_data.size());
|
||||
gcmHash_Update(&ghashCtx,
|
||||
const_cast<const unsigned char *>(cipher_text.data()),
|
||||
cipher_text.size());
|
||||
|
||||
// Finalise (hash in the length).
|
||||
uint8_t result_bytes[16];
|
||||
unsigned int out_len;
|
||||
ASSERT_EQ(SECSuccess, gcmHash_Final(&ghashCtx, result_bytes, &out_len, 16));
|
||||
ASSERT_EQ(16U, out_len);
|
||||
EXPECT_EQ(expected, std::vector<uint8_t>(result_bytes, result_bytes + 16));
|
||||
}
|
||||
};
|
||||
|
||||
#ifdef NSS_X86_OR_X64
|
||||
TEST_P(GHashTest, KAT_X86_HW) { TestGHash(GetParam(), false); }
|
||||
#endif
|
||||
TEST_P(GHashTest, KAT_Sftw) { TestGHash(GetParam(), true); }
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(NISTTestVector, GHashTest,
|
||||
::testing::ValuesIn(kGcmKatValues));
|
||||
|
||||
} // nss_test
|
@ -8,10 +8,10 @@
|
||||
|
||||
#include <cstdlib>
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
|
||||
#define GTEST_HAS_RTTI 0
|
||||
#include "gtest/gtest.h"
|
||||
#include "util.h"
|
||||
|
||||
#include "blapi.h"
|
||||
|
||||
@ -44,15 +44,6 @@ std::string trim(std::string str) {
|
||||
return str.substr(strBegin, strRange);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> hex_string_to_bytes(std::string s) {
|
||||
std::vector<uint8_t> bytes;
|
||||
assert(s.length() % 2 == 0);
|
||||
for (size_t i = 0; i < s.length(); i += 2) {
|
||||
bytes.push_back(std::stoul(s.substr(i, 2), nullptr, 16));
|
||||
}
|
||||
return bytes;
|
||||
}
|
||||
|
||||
std::vector<uint8_t> read_option_s(std::string& s) {
|
||||
size_t start = s.find("=") + 1;
|
||||
assert(start > 0);
|
||||
|
@ -5,14 +5,32 @@
|
||||
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)
|
||||
|
@ -35,7 +35,8 @@
|
||||
'<(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', {
|
||||
@ -43,21 +44,6 @@
|
||||
'<(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',
|
||||
],
|
||||
}],
|
||||
],
|
||||
}
|
||||
],
|
||||
|
@ -16,6 +16,7 @@ CPPSRCS = \
|
||||
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 \
|
||||
@ -27,5 +28,5 @@ 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)
|
||||
|
||||
|
135
security/nss/gtests/pk11_gtest/pk11_aes_gcm_unittest.cc
Normal file
135
security/nss/gtests/pk11_gtest/pk11_aes_gcm_unittest.cc
Normal file
@ -0,0 +1,135 @@
|
||||
/* -*- 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 <memory>
|
||||
#include "nss.h"
|
||||
#include "pk11pub.h"
|
||||
#include "secerr.h"
|
||||
#include "sechash.h"
|
||||
|
||||
#include "scoped_ptrs.h"
|
||||
|
||||
#include "gcm-vectors.h"
|
||||
#include "gtest/gtest.h"
|
||||
#include "util.h"
|
||||
|
||||
namespace nss_test {
|
||||
|
||||
class Pkcs11AesGcmTest : public ::testing::TestWithParam<gcm_kat_value> {
|
||||
protected:
|
||||
void RunTest(const gcm_kat_value val) {
|
||||
std::vector<uint8_t> key = hex_string_to_bytes(val.key);
|
||||
std::vector<uint8_t> iv = hex_string_to_bytes(val.iv);
|
||||
std::vector<uint8_t> plaintext = hex_string_to_bytes(val.plaintext);
|
||||
std::vector<uint8_t> aad = hex_string_to_bytes(val.additional_data);
|
||||
std::vector<uint8_t> result = hex_string_to_bytes(val.result);
|
||||
|
||||
// Ignore GHASH-only vectors.
|
||||
if (key.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Prepare AEAD params.
|
||||
CK_GCM_PARAMS gcmParams;
|
||||
gcmParams.pIv = iv.data();
|
||||
gcmParams.ulIvLen = iv.size();
|
||||
gcmParams.pAAD = aad.data();
|
||||
gcmParams.ulAADLen = aad.size();
|
||||
gcmParams.ulTagBits = 128;
|
||||
|
||||
SECItem params = {siBuffer, reinterpret_cast<unsigned char*>(&gcmParams),
|
||||
sizeof(gcmParams)};
|
||||
|
||||
ScopedPK11SlotInfo slot(PK11_GetInternalSlot());
|
||||
SECItem keyItem = {siBuffer, key.data(),
|
||||
static_cast<unsigned int>(key.size())};
|
||||
|
||||
// Import key.
|
||||
ScopedPK11SymKey symKey(PK11_ImportSymKey(
|
||||
slot.get(), mech, PK11_OriginUnwrap, CKA_ENCRYPT, &keyItem, nullptr));
|
||||
EXPECT_TRUE(!!symKey);
|
||||
|
||||
// Encrypt.
|
||||
unsigned int outputLen = 0;
|
||||
std::vector<uint8_t> output(plaintext.size() + gcmParams.ulTagBits / 8);
|
||||
SECStatus rv =
|
||||
PK11_Encrypt(symKey.get(), mech, ¶ms, output.data(), &outputLen,
|
||||
output.size(), plaintext.data(), plaintext.size());
|
||||
EXPECT_EQ(rv, SECSuccess);
|
||||
ASSERT_EQ(outputLen, output.size());
|
||||
|
||||
// Check ciphertext and tag.
|
||||
EXPECT_EQ(result, output);
|
||||
|
||||
// Decrypt.
|
||||
unsigned int decryptedLen = 0;
|
||||
// The PK11 AES API is stupid, it expects an explicit IV and thus wants
|
||||
// a block more of available output memory.
|
||||
std::vector<uint8_t> decrypted(output.size());
|
||||
rv =
|
||||
PK11_Decrypt(symKey.get(), mech, ¶ms, decrypted.data(),
|
||||
&decryptedLen, decrypted.size(), output.data(), outputLen);
|
||||
EXPECT_EQ(rv, SECSuccess);
|
||||
ASSERT_EQ(decryptedLen, plaintext.size());
|
||||
|
||||
// Check the plaintext.
|
||||
EXPECT_EQ(plaintext,
|
||||
std::vector<uint8_t>(decrypted.begin(),
|
||||
decrypted.begin() + decryptedLen));
|
||||
}
|
||||
|
||||
SECStatus EncryptWithIV(std::vector<uint8_t>& iv) {
|
||||
// Generate a random key.
|
||||
ScopedPK11SlotInfo slot(PK11_GetInternalSlot());
|
||||
ScopedPK11SymKey symKey(
|
||||
PK11_KeyGen(slot.get(), mech, nullptr, 16, nullptr));
|
||||
EXPECT_TRUE(!!symKey);
|
||||
|
||||
std::vector<uint8_t> data(17);
|
||||
std::vector<uint8_t> output(33);
|
||||
std::vector<uint8_t> aad(0);
|
||||
|
||||
// Prepare AEAD params.
|
||||
CK_GCM_PARAMS gcmParams;
|
||||
gcmParams.pIv = iv.data();
|
||||
gcmParams.ulIvLen = iv.size();
|
||||
gcmParams.pAAD = aad.data();
|
||||
gcmParams.ulAADLen = aad.size();
|
||||
gcmParams.ulTagBits = 128;
|
||||
|
||||
SECItem params = {siBuffer, reinterpret_cast<unsigned char*>(&gcmParams),
|
||||
sizeof(gcmParams)};
|
||||
|
||||
// Try to encrypt.
|
||||
unsigned int outputLen = 0;
|
||||
return PK11_Encrypt(symKey.get(), mech, ¶ms, output.data(), &outputLen,
|
||||
output.size(), data.data(), data.size());
|
||||
}
|
||||
|
||||
const CK_MECHANISM_TYPE mech = CKM_AES_GCM;
|
||||
};
|
||||
|
||||
TEST_P(Pkcs11AesGcmTest, TestVectors) { RunTest(GetParam()); }
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(NISTTestVector, Pkcs11AesGcmTest,
|
||||
::testing::ValuesIn(kGcmKatValues));
|
||||
|
||||
TEST_F(Pkcs11AesGcmTest, ZeroLengthIV) {
|
||||
std::vector<uint8_t> iv(0);
|
||||
EXPECT_EQ(EncryptWithIV(iv), SECFailure);
|
||||
}
|
||||
|
||||
TEST_F(Pkcs11AesGcmTest, AllZeroIV) {
|
||||
std::vector<uint8_t> iv(16, 0);
|
||||
EXPECT_EQ(EncryptWithIV(iv), SECSuccess);
|
||||
}
|
||||
|
||||
TEST_F(Pkcs11AesGcmTest, TwelveByteZeroIV) {
|
||||
std::vector<uint8_t> iv(12, 0);
|
||||
EXPECT_EQ(EncryptWithIV(iv), SECSuccess);
|
||||
}
|
||||
|
||||
} // namespace nss_test
|
@ -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
|
@ -12,6 +12,7 @@
|
||||
'type': 'executable',
|
||||
'sources': [
|
||||
'pk11_aeskeywrap_unittest.cc',
|
||||
'pk11_aes_gcm_unittest.cc',
|
||||
'pk11_chacha20poly1305_unittest.cc',
|
||||
'pk11_curve25519_unittest.cc',
|
||||
'pk11_ecdsa_unittest.cc',
|
||||
@ -19,6 +20,7 @@
|
||||
'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': [
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "nss.h"
|
||||
#include "pk11pub.h"
|
||||
#include "seccomon.h"
|
||||
#include "selfencrypt.h"
|
||||
|
||||
SECStatus SSLInt_IncrementClientHandshakeVersion(PRFileDesc *fd) {
|
||||
sslSocket *ss = ssl_FindSocket(fd);
|
||||
@ -55,7 +56,16 @@ PRBool SSLInt_ExtensionNegotiated(PRFileDesc *fd, PRUint16 ext) {
|
||||
return (PRBool)(ss && ssl3_ExtensionNegotiated(ss, ext));
|
||||
}
|
||||
|
||||
void SSLInt_ClearSessionTicketKey() { ssl_ResetSessionTicketKeys(); }
|
||||
void SSLInt_ClearSelfEncryptKey() { ssl_ResetSelfEncryptKeys(); }
|
||||
|
||||
sslSelfEncryptKeys *ssl_GetSelfEncryptKeysInt();
|
||||
|
||||
void SSLInt_SetSelfEncryptMacKey(PK11SymKey *key) {
|
||||
sslSelfEncryptKeys *keys = ssl_GetSelfEncryptKeysInt();
|
||||
|
||||
PK11_FreeSymKey(keys->macKey);
|
||||
keys->macKey = key;
|
||||
}
|
||||
|
||||
SECStatus SSLInt_SetMTU(PRFileDesc *fd, PRUint16 mtu) {
|
||||
sslSocket *ss = ssl_FindSocket(fd);
|
||||
|
@ -22,7 +22,8 @@ SECStatus SSLInt_UpdateSSLv2ClientRandom(PRFileDesc *fd, uint8_t *rnd,
|
||||
size_t msg_len);
|
||||
|
||||
PRBool SSLInt_ExtensionNegotiated(PRFileDesc *fd, PRUint16 ext);
|
||||
void SSLInt_ClearSessionTicketKey();
|
||||
void SSLInt_ClearSelfEncryptKey();
|
||||
void SSLInt_SetSelfEncryptMacKey(PK11SymKey *key);
|
||||
PRInt32 SSLInt_CountTls13CipherSpecs(PRFileDesc *fd);
|
||||
void SSLInt_PrintTls13CipherSpecs(PRFileDesc *fd);
|
||||
void SSLInt_ForceTimerExpiry(PRFileDesc *fd);
|
||||
|
@ -12,9 +12,6 @@ CSRCS = \
|
||||
$(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 \
|
||||
@ -40,6 +37,7 @@ CPPSRCS = \
|
||||
ssl_v2_client_hello_unittest.cc \
|
||||
ssl_version_unittest.cc \
|
||||
ssl_versionpolicy_unittest.cc \
|
||||
selfencrypt_unittest.cc \
|
||||
test_io.cc \
|
||||
tls_agent.cc \
|
||||
tls_connect.cc \
|
||||
@ -52,9 +50,12 @@ 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
|
||||
|
281
security/nss/gtests/ssl_gtest/selfencrypt_unittest.cc
Normal file
281
security/nss/gtests/ssl_gtest/selfencrypt_unittest.cc
Normal file
@ -0,0 +1,281 @@
|
||||
/* -*- 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 <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 {
|
||||
|
||||
static const uint8_t kAesKey1Buf[] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05,
|
||||
0x06, 0x07, 0x08, 0x09, 0x0a, 0x0b,
|
||||
0x0c, 0x0d, 0x0e, 0x0f};
|
||||
static const DataBuffer kAesKey1(kAesKey1Buf, sizeof(kAesKey1Buf));
|
||||
|
||||
static const uint8_t kAesKey2Buf[] = {0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
|
||||
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b,
|
||||
0x1c, 0x1d, 0x1e, 0x1f};
|
||||
static const DataBuffer kAesKey2(kAesKey2Buf, sizeof(kAesKey2Buf));
|
||||
|
||||
static const uint8_t kHmacKey1Buf[] = {
|
||||
0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0a,
|
||||
0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12, 0x13, 0x14, 0x15,
|
||||
0x16, 0x17, 0x18, 0x19, 0x1a, 0x1b, 0x1c, 0x1d, 0x1e, 0x1f};
|
||||
static const DataBuffer kHmacKey1(kHmacKey1Buf, sizeof(kHmacKey1Buf));
|
||||
|
||||
static const uint8_t kHmacKey2Buf[] = {
|
||||
0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17, 0x18, 0x19, 0x1a,
|
||||
0x1b, 0x1c, 0x1d, 0x1e, 0x1f, 0x20, 0x21, 0x22, 0x23, 0x24, 0x25,
|
||||
0x26, 0x27, 0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x2d, 0x2e, 0x2f};
|
||||
static const DataBuffer kHmacKey2(kHmacKey2Buf, sizeof(kHmacKey2Buf));
|
||||
|
||||
static const uint8_t* kKeyName1 =
|
||||
reinterpret_cast<const unsigned char*>("KEY1KEY1KEY1KEY1");
|
||||
static const uint8_t* kKeyName2 =
|
||||
reinterpret_cast<const uint8_t*>("KEY2KEY2KEY2KEY2");
|
||||
|
||||
static void ImportKey(const DataBuffer& key, PK11SlotInfo* slot,
|
||||
CK_MECHANISM_TYPE mech, CK_ATTRIBUTE_TYPE cka,
|
||||
ScopedPK11SymKey* to) {
|
||||
SECItem key_item = {siBuffer, const_cast<uint8_t*>(key.data()),
|
||||
static_cast<unsigned int>(key.len())};
|
||||
|
||||
PK11SymKey* inner =
|
||||
PK11_ImportSymKey(slot, mech, PK11_OriginUnwrap, cka, &key_item, nullptr);
|
||||
ASSERT_NE(nullptr, inner);
|
||||
to->reset(inner);
|
||||
}
|
||||
|
||||
extern "C" {
|
||||
extern char ssl_trace;
|
||||
extern FILE* ssl_trace_iob;
|
||||
}
|
||||
|
||||
class SelfEncryptTestBase : public ::testing::Test {
|
||||
public:
|
||||
SelfEncryptTestBase(size_t message_size)
|
||||
: aes1_(),
|
||||
aes2_(),
|
||||
hmac1_(),
|
||||
hmac2_(),
|
||||
message_(),
|
||||
slot_(PK11_GetInternalSlot()) {
|
||||
EXPECT_NE(nullptr, slot_);
|
||||
char* ev = getenv("SSLTRACE");
|
||||
if (ev && ev[0]) {
|
||||
ssl_trace = atoi(ev);
|
||||
ssl_trace_iob = stderr;
|
||||
}
|
||||
message_.Allocate(message_size);
|
||||
for (size_t i = 0; i < message_.len(); ++i) {
|
||||
message_.data()[i] = i;
|
||||
}
|
||||
}
|
||||
|
||||
void SetUp() {
|
||||
message_.Allocate(100);
|
||||
for (size_t i = 0; i < 100; ++i) {
|
||||
message_.data()[i] = i;
|
||||
}
|
||||
ImportKey(kAesKey1, slot_.get(), CKM_AES_CBC, CKA_ENCRYPT, &aes1_);
|
||||
ImportKey(kAesKey2, slot_.get(), CKM_AES_CBC, CKA_ENCRYPT, &aes2_);
|
||||
ImportKey(kHmacKey1, slot_.get(), CKM_SHA256_HMAC, CKA_SIGN, &hmac1_);
|
||||
ImportKey(kHmacKey2, slot_.get(), CKM_SHA256_HMAC, CKA_SIGN, &hmac2_);
|
||||
}
|
||||
|
||||
void SelfTest(
|
||||
const uint8_t* writeKeyName, const ScopedPK11SymKey& writeAes,
|
||||
const ScopedPK11SymKey& writeHmac, const uint8_t* readKeyName,
|
||||
const ScopedPK11SymKey& readAes, const ScopedPK11SymKey& readHmac,
|
||||
PRErrorCode protect_error_code = 0, PRErrorCode unprotect_error_code = 0,
|
||||
std::function<void(uint8_t* ciphertext, unsigned int* ciphertext_len)>
|
||||
mutate = nullptr) {
|
||||
uint8_t ciphertext[1000];
|
||||
unsigned int ciphertext_len;
|
||||
uint8_t plaintext[1000];
|
||||
unsigned int plaintext_len;
|
||||
|
||||
SECStatus rv = ssl_SelfEncryptProtectInt(
|
||||
writeAes.get(), writeHmac.get(), writeKeyName, message_.data(),
|
||||
message_.len(), ciphertext, &ciphertext_len, sizeof(ciphertext));
|
||||
if (rv != SECSuccess) {
|
||||
std::cerr << "Error: " << PORT_ErrorToName(PORT_GetError()) << std::endl;
|
||||
}
|
||||
if (protect_error_code) {
|
||||
ASSERT_EQ(protect_error_code, PORT_GetError());
|
||||
return;
|
||||
}
|
||||
ASSERT_EQ(SECSuccess, rv);
|
||||
|
||||
if (mutate) {
|
||||
mutate(ciphertext, &ciphertext_len);
|
||||
}
|
||||
rv = ssl_SelfEncryptUnprotectInt(readAes.get(), readHmac.get(), readKeyName,
|
||||
ciphertext, ciphertext_len, plaintext,
|
||||
&plaintext_len, sizeof(plaintext));
|
||||
if (rv != SECSuccess) {
|
||||
std::cerr << "Error: " << PORT_ErrorToName(PORT_GetError()) << std::endl;
|
||||
}
|
||||
if (!unprotect_error_code) {
|
||||
ASSERT_EQ(SECSuccess, rv);
|
||||
EXPECT_EQ(message_.len(), plaintext_len);
|
||||
EXPECT_EQ(0, memcmp(message_.data(), plaintext, message_.len()));
|
||||
} else {
|
||||
ASSERT_EQ(SECFailure, rv);
|
||||
EXPECT_EQ(unprotect_error_code, PORT_GetError());
|
||||
}
|
||||
}
|
||||
|
||||
protected:
|
||||
ScopedPK11SymKey aes1_;
|
||||
ScopedPK11SymKey aes2_;
|
||||
ScopedPK11SymKey hmac1_;
|
||||
ScopedPK11SymKey hmac2_;
|
||||
DataBuffer message_;
|
||||
|
||||
private:
|
||||
ScopedPK11SlotInfo slot_;
|
||||
};
|
||||
|
||||
class SelfEncryptTestVariable : public SelfEncryptTestBase,
|
||||
public ::testing::WithParamInterface<size_t> {
|
||||
public:
|
||||
SelfEncryptTestVariable() : SelfEncryptTestBase(GetParam()) {}
|
||||
};
|
||||
|
||||
class SelfEncryptTest128 : public SelfEncryptTestBase {
|
||||
public:
|
||||
SelfEncryptTest128() : SelfEncryptTestBase(128) {}
|
||||
};
|
||||
|
||||
TEST_P(SelfEncryptTestVariable, SuccessCase) {
|
||||
SelfTest(kKeyName1, aes1_, hmac1_, kKeyName1, aes1_, hmac1_);
|
||||
}
|
||||
|
||||
TEST_P(SelfEncryptTestVariable, WrongMacKey) {
|
||||
SelfTest(kKeyName1, aes1_, hmac1_, kKeyName1, aes1_, hmac2_, 0,
|
||||
SEC_ERROR_BAD_DATA);
|
||||
}
|
||||
|
||||
TEST_P(SelfEncryptTestVariable, WrongKeyName) {
|
||||
SelfTest(kKeyName1, aes1_, hmac1_, kKeyName2, aes1_, hmac1_, 0,
|
||||
SEC_ERROR_NOT_A_RECIPIENT);
|
||||
}
|
||||
|
||||
TEST_P(SelfEncryptTestVariable, AddAByte) {
|
||||
SelfTest(kKeyName1, aes1_, hmac1_, kKeyName1, aes1_, hmac1_, 0,
|
||||
SEC_ERROR_BAD_DATA,
|
||||
[](uint8_t* ciphertext, unsigned int* ciphertext_len) {
|
||||
(*ciphertext_len)++;
|
||||
});
|
||||
}
|
||||
|
||||
TEST_P(SelfEncryptTestVariable, SubtractAByte) {
|
||||
SelfTest(kKeyName1, aes1_, hmac1_, kKeyName1, aes1_, hmac1_, 0,
|
||||
SEC_ERROR_BAD_DATA,
|
||||
[](uint8_t* ciphertext, unsigned int* ciphertext_len) {
|
||||
(*ciphertext_len)--;
|
||||
});
|
||||
}
|
||||
|
||||
TEST_P(SelfEncryptTestVariable, BogusIv) {
|
||||
SelfTest(kKeyName1, aes1_, hmac1_, kKeyName1, aes1_, hmac1_, 0,
|
||||
SEC_ERROR_BAD_DATA,
|
||||
[](uint8_t* ciphertext, unsigned int* ciphertext_len) {
|
||||
ciphertext[16]++;
|
||||
});
|
||||
}
|
||||
|
||||
TEST_P(SelfEncryptTestVariable, BogusCiphertext) {
|
||||
SelfTest(kKeyName1, aes1_, hmac1_, kKeyName1, aes1_, hmac1_, 0,
|
||||
SEC_ERROR_BAD_DATA,
|
||||
[](uint8_t* ciphertext, unsigned int* ciphertext_len) {
|
||||
ciphertext[32]++;
|
||||
});
|
||||
}
|
||||
|
||||
TEST_P(SelfEncryptTestVariable, BadMac) {
|
||||
SelfTest(kKeyName1, aes1_, hmac1_, kKeyName1, aes1_, hmac1_, 0,
|
||||
SEC_ERROR_BAD_DATA,
|
||||
[](uint8_t* ciphertext, unsigned int* ciphertext_len) {
|
||||
ciphertext[*ciphertext_len - 1]++;
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(SelfEncryptTest128, DISABLED_BadPadding) {
|
||||
SelfTest(kKeyName1, aes1_, hmac1_, kKeyName1, aes2_, hmac1_, 0,
|
||||
SEC_ERROR_BAD_DATA);
|
||||
}
|
||||
|
||||
TEST_F(SelfEncryptTest128, ShortKeyName) {
|
||||
SelfTest(kKeyName1, aes1_, hmac1_, kKeyName1, aes1_, hmac1_, 0,
|
||||
SEC_ERROR_BAD_DATA,
|
||||
[](uint8_t* ciphertext, unsigned int* ciphertext_len) {
|
||||
*ciphertext_len = 15;
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(SelfEncryptTest128, ShortIv) {
|
||||
SelfTest(kKeyName1, aes1_, hmac1_, kKeyName1, aes1_, hmac1_, 0,
|
||||
SEC_ERROR_BAD_DATA,
|
||||
[](uint8_t* ciphertext, unsigned int* ciphertext_len) {
|
||||
*ciphertext_len = 31;
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(SelfEncryptTest128, ShortCiphertextLen) {
|
||||
SelfTest(kKeyName1, aes1_, hmac1_, kKeyName1, aes1_, hmac1_, 0,
|
||||
SEC_ERROR_BAD_DATA,
|
||||
[](uint8_t* ciphertext, unsigned int* ciphertext_len) {
|
||||
*ciphertext_len = 32;
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(SelfEncryptTest128, ShortCiphertext) {
|
||||
SelfTest(kKeyName1, aes1_, hmac1_, kKeyName1, aes1_, hmac1_, 0,
|
||||
SEC_ERROR_BAD_DATA,
|
||||
[](uint8_t* ciphertext, unsigned int* ciphertext_len) {
|
||||
*ciphertext_len -= 17;
|
||||
});
|
||||
}
|
||||
|
||||
TEST_F(SelfEncryptTest128, MacWithAESKeyEncrypt) {
|
||||
SelfTest(kKeyName1, aes1_, aes1_, kKeyName1, aes1_, hmac1_,
|
||||
SEC_ERROR_LIBRARY_FAILURE);
|
||||
}
|
||||
|
||||
TEST_F(SelfEncryptTest128, AESWithMacKeyEncrypt) {
|
||||
SelfTest(kKeyName1, hmac1_, hmac1_, kKeyName1, aes1_, hmac1_,
|
||||
SEC_ERROR_INVALID_KEY);
|
||||
}
|
||||
|
||||
TEST_F(SelfEncryptTest128, MacWithAESKeyDecrypt) {
|
||||
SelfTest(kKeyName1, aes1_, hmac1_, kKeyName1, aes1_, aes1_, 0,
|
||||
SEC_ERROR_LIBRARY_FAILURE);
|
||||
}
|
||||
|
||||
TEST_F(SelfEncryptTest128, AESWithMacKeyDecrypt) {
|
||||
SelfTest(kKeyName1, aes1_, hmac1_, kKeyName1, hmac1_, hmac1_, 0,
|
||||
SEC_ERROR_INVALID_KEY);
|
||||
}
|
||||
|
||||
INSTANTIATE_TEST_CASE_P(VariousSizes, SelfEncryptTestVariable,
|
||||
::testing::Values(0, 15, 16, 31, 255, 256, 257));
|
||||
|
||||
} // namespace nss_test
|
@ -281,13 +281,8 @@ FUZZ_P(TlsConnectGeneric, UnencryptedSessionTickets) {
|
||||
offset += 1 + 1 + /* ke_modes */
|
||||
1 + 1; /* auth_modes */
|
||||
}
|
||||
|
||||
offset += 2 + /* ticket length */
|
||||
16 + /* SESS_TICKET_KEY_NAME_LEN */
|
||||
16 + /* AES-128 IV */
|
||||
2 + /* ciphertext length */
|
||||
2; /* TLS_EX_SESS_TICKET_VERSION */
|
||||
|
||||
offset += 2 + /* ticket length */
|
||||
2; /* TLS_EX_SESS_TICKET_VERSION */
|
||||
// Check the protocol version number.
|
||||
uint32_t tls_version = 0;
|
||||
EXPECT_TRUE(i1->buffer().Read(offset, sizeof(version_), &tls_version));
|
||||
|
@ -12,6 +12,7 @@
|
||||
'type': 'executable',
|
||||
'sources': [
|
||||
'libssl_internals.c',
|
||||
'selfencrypt_unittest.cc',
|
||||
'ssl_0rtt_unittest.cc',
|
||||
'ssl_agent_unittest.cc',
|
||||
'ssl_auth_unittest.cc',
|
||||
@ -61,6 +62,7 @@
|
||||
'<(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', {
|
||||
@ -80,21 +82,6 @@
|
||||
'<(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',
|
||||
],
|
||||
}],
|
||||
],
|
||||
}
|
||||
],
|
||||
|
@ -198,8 +198,10 @@ TEST_P(TlsConnectGeneric, ConnectSendReceive) {
|
||||
TEST_P(TlsConnectDatagram, ShortRead) {
|
||||
Connect();
|
||||
client_->ExpectReadWriteError();
|
||||
server_->SendData(1200, 1200);
|
||||
client_->WaitForErrorCode(SSL_ERROR_RX_SHORT_DTLS_READ, 2000);
|
||||
server_->SendData(50, 50);
|
||||
client_->ReadBytes(20);
|
||||
EXPECT_EQ(0U, client_->received_bytes());
|
||||
EXPECT_EQ(SSL_ERROR_RX_SHORT_DTLS_READ, PORT_GetError());
|
||||
|
||||
// Now send and receive another packet.
|
||||
server_->ResetSentBytes(); // Reset the counter.
|
||||
@ -213,13 +215,13 @@ TEST_P(TlsConnectStream, ShortRead) {
|
||||
if (version_ < SSL_LIBRARY_VERSION_TLS_1_1) return;
|
||||
|
||||
Connect();
|
||||
server_->SendData(1200, 1200);
|
||||
server_->SendData(50, 50);
|
||||
// Read the first tranche.
|
||||
WAIT_(client_->received_bytes() == 1024, 2000);
|
||||
ASSERT_EQ(1024U, client_->received_bytes());
|
||||
client_->ReadBytes(20);
|
||||
ASSERT_EQ(20U, client_->received_bytes());
|
||||
// The second tranche should now immediately be available.
|
||||
client_->ReadBytes();
|
||||
ASSERT_EQ(1200U, client_->received_bytes());
|
||||
ASSERT_EQ(50U, client_->received_bytes());
|
||||
}
|
||||
|
||||
TEST_P(TlsConnectGeneric, ConnectWithCompressionMaybe) {
|
||||
|
@ -258,6 +258,30 @@ TEST_P(TlsConnectGeneric, ConnectWithExpiredTicketAtServer) {
|
||||
CheckConnected();
|
||||
}
|
||||
|
||||
TEST_P(TlsConnectGeneric, ConnectResumeCorruptTicket) {
|
||||
// This causes a ticket resumption.
|
||||
ConfigureSessionCache(RESUME_BOTH, RESUME_TICKET);
|
||||
Connect();
|
||||
SendReceive();
|
||||
|
||||
Reset();
|
||||
static const uint8_t kHmacKey1Buf[32] = {0};
|
||||
static const DataBuffer kHmacKey1(kHmacKey1Buf, sizeof(kHmacKey1Buf));
|
||||
|
||||
SECItem key_item = {siBuffer, const_cast<uint8_t*>(kHmacKey1Buf),
|
||||
sizeof(kHmacKey1Buf)};
|
||||
|
||||
ScopedPK11SlotInfo slot(PK11_GetInternalSlot());
|
||||
PK11SymKey* hmac_key =
|
||||
PK11_ImportSymKey(slot.get(), CKM_SHA256_HMAC, PK11_OriginUnwrap,
|
||||
CKA_SIGN, &key_item, nullptr);
|
||||
ASSERT_NE(nullptr, hmac_key);
|
||||
SSLInt_SetSelfEncryptMacKey(hmac_key);
|
||||
ConfigureSessionCache(RESUME_BOTH, RESUME_TICKET);
|
||||
ConnectExpectAlert(server_, illegal_parameter);
|
||||
server_->CheckErrorCode(SSL_ERROR_RX_MALFORMED_CLIENT_HELLO);
|
||||
}
|
||||
|
||||
// This callback switches out the "server" cert used on the server with
|
||||
// the "client" certificate, which should be the same type.
|
||||
static int32_t SwitchCertificates(TlsAgent* agent, const SECItem* srvNameArr,
|
||||
@ -627,7 +651,7 @@ TEST_F(TlsConnectTest, TestTls13ResumptionDuplicateNST) {
|
||||
Connect();
|
||||
|
||||
// Clear the session ticket keys to invalidate the old ticket.
|
||||
SSLInt_ClearSessionTicketKey();
|
||||
SSLInt_ClearSelfEncryptKey();
|
||||
SSLInt_SendNewSessionTicket(server_->ssl_fd());
|
||||
|
||||
SendReceive(); // Need to read so that we absorb the session tickets.
|
||||
|
@ -918,10 +918,10 @@ void TlsAgent::SendBuffer(const DataBuffer& buf) {
|
||||
}
|
||||
}
|
||||
|
||||
void TlsAgent::ReadBytes() {
|
||||
uint8_t block[1024];
|
||||
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;
|
||||
|
||||
|
@ -151,7 +151,7 @@ class TlsAgent : public PollTarget {
|
||||
void SendBuffer(const DataBuffer& buf);
|
||||
// Send data directly to the underlying socket, skipping the TLS layer.
|
||||
void SendDirect(const DataBuffer& buf);
|
||||
void ReadBytes();
|
||||
void ReadBytes(size_t max = 16384U);
|
||||
void ResetSentBytes(); // Hack to test drops.
|
||||
void EnableExtendedMasterSecret();
|
||||
void CheckExtendedMasterSecret(bool expected);
|
||||
|
@ -169,13 +169,13 @@ void TlsConnectTestBase::ClearStats() {
|
||||
|
||||
void TlsConnectTestBase::ClearServerCache() {
|
||||
SSL_ShutdownServerSessionIDCache();
|
||||
SSLInt_ClearSessionTicketKey();
|
||||
SSLInt_ClearSelfEncryptKey();
|
||||
SSL_ConfigServerSessionIDCache(1024, 0, 0, g_working_dir_path.c_str());
|
||||
}
|
||||
|
||||
void TlsConnectTestBase::SetUp() {
|
||||
SSL_ConfigServerSessionIDCache(1024, 0, 0, g_working_dir_path.c_str());
|
||||
SSLInt_ClearSessionTicketKey();
|
||||
SSLInt_ClearSelfEncryptKey();
|
||||
SSLInt_SetTicketLifetime(30);
|
||||
SSLInt_SetMaxEarlyDataSize(1024);
|
||||
ClearStats();
|
||||
@ -187,7 +187,7 @@ void TlsConnectTestBase::TearDown() {
|
||||
server_ = nullptr;
|
||||
|
||||
SSL_ClearSessionCache();
|
||||
SSLInt_ClearSessionTicketKey();
|
||||
SSLInt_ClearSelfEncryptKey();
|
||||
SSL_ShutdownServerSessionIDCache();
|
||||
}
|
||||
|
||||
|
@ -25,5 +25,5 @@ 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)
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "nssb64.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "scoped_ptrs.h"
|
||||
#include "scoped_ptrs_util.h"
|
||||
|
||||
namespace nss_test {
|
||||
|
||||
|
@ -29,6 +29,7 @@
|
||||
'<(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"', {
|
||||
|
@ -9,7 +9,7 @@
|
||||
#include "pkcs11uri.h"
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
#include "scoped_ptrs.h"
|
||||
#include "scoped_ptrs_util.h"
|
||||
|
||||
namespace nss_test {
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
Usage: ${0##*/} [-hcv] [-j <n>] [--nspr] [--gyp|-g] [--opt|-o] [-m32]
|
||||
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.
|
||||
|
||||
@ -40,3 +40,4 @@ NSS build tool options:
|
||||
--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.
|
||||
|
@ -568,8 +568,8 @@ CERT_CompareRDN(const CERTRDN *a, const CERTRDN *b)
|
||||
SECComparison
|
||||
CERT_CompareName(const CERTName *a, const CERTName *b)
|
||||
{
|
||||
CERTRDN **ardns, *ardn;
|
||||
CERTRDN **brdns, *brdn;
|
||||
CERTRDN **ardns;
|
||||
CERTRDN **brdns;
|
||||
int ac, bc;
|
||||
SECComparison rv = SECEqual;
|
||||
|
||||
@ -587,18 +587,8 @@ CERT_CompareName(const CERTName *a, const CERTName *b)
|
||||
if (ac > bc)
|
||||
return SECGreaterThan;
|
||||
|
||||
for (;;) {
|
||||
if (!ardns++ || !brdns++) {
|
||||
break;
|
||||
}
|
||||
ardn = *ardns;
|
||||
brdn = *brdns;
|
||||
if (!ardn) {
|
||||
break;
|
||||
}
|
||||
rv = CERT_CompareRDN(ardn, brdn);
|
||||
if (rv)
|
||||
return rv;
|
||||
while (rv == SECEqual && *ardns) {
|
||||
rv = CERT_CompareRDN(*ardns++, *brdns++);
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
@ -110,6 +110,7 @@ endif
|
||||
# NSS_X86_OR_X64 means the target is either x86 or x64
|
||||
ifeq (,$(filter-out i386 x386 x86 x86_64,$(CPU_ARCH)))
|
||||
DEFINES += -DNSS_X86_OR_X64
|
||||
CFLAGS += -mpclmul -maes
|
||||
ifneq (,$(USE_64)$(USE_X32))
|
||||
DEFINES += -DNSS_X64
|
||||
else
|
||||
|
@ -22,8 +22,9 @@
|
||||
#include "rijndael.h"
|
||||
|
||||
struct AESKeyWrapContextStr {
|
||||
unsigned char iv[AES_KEY_WRAP_IV_BYTES];
|
||||
AESContext aescx;
|
||||
unsigned char iv[AES_KEY_WRAP_IV_BYTES];
|
||||
void *mem; /* Pointer to beginning of allocated memory. */
|
||||
};
|
||||
|
||||
/******************************************/
|
||||
@ -34,8 +35,14 @@ struct AESKeyWrapContextStr {
|
||||
AESKeyWrapContext *
|
||||
AESKeyWrap_AllocateContext(void)
|
||||
{
|
||||
AESKeyWrapContext *cx = PORT_New(AESKeyWrapContext);
|
||||
return cx;
|
||||
/* aligned_alloc is C11 so we have to do it the old way. */
|
||||
AESKeyWrapContext *ctx = PORT_ZAlloc(sizeof(AESKeyWrapContext) + 15);
|
||||
if (ctx == NULL) {
|
||||
PORT_SetError(SEC_ERROR_NO_MEMORY);
|
||||
return NULL;
|
||||
}
|
||||
ctx->mem = ctx;
|
||||
return (AESKeyWrapContext *)(((uintptr_t)ctx + 15) & ~(uintptr_t)0x0F);
|
||||
}
|
||||
|
||||
SECStatus
|
||||
@ -77,7 +84,7 @@ AESKeyWrap_CreateContext(const unsigned char *key, const unsigned char *iv,
|
||||
return NULL; /* error is already set */
|
||||
rv = AESKeyWrap_InitContext(cx, key, keylen, iv, 0, encrypt, 0);
|
||||
if (rv != SECSuccess) {
|
||||
PORT_Free(cx);
|
||||
PORT_Free(cx->mem);
|
||||
cx = NULL; /* error should already be set */
|
||||
}
|
||||
return cx;
|
||||
@ -94,8 +101,9 @@ AESKeyWrap_DestroyContext(AESKeyWrapContext *cx, PRBool freeit)
|
||||
if (cx) {
|
||||
AES_DestroyContext(&cx->aescx, PR_FALSE);
|
||||
/* memset(cx, 0, sizeof *cx); */
|
||||
if (freeit)
|
||||
PORT_Free(cx);
|
||||
if (freeit) {
|
||||
PORT_Free(cx->mem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -801,8 +801,7 @@ SEED_Decrypt(SEEDContext *cx, unsigned char *output,
|
||||
** Create a new AES context suitable for AES encryption/decryption.
|
||||
** "key" raw key data
|
||||
** "keylen" the number of bytes of key data (16, 24, or 32)
|
||||
** "blocklen" is the blocksize to use (16, 24, or 32)
|
||||
** XXX currently only blocksize==16 has been tested!
|
||||
** "blocklen" is the blocksize to use. NOTE: only 16 is supported!
|
||||
*/
|
||||
extern AESContext *
|
||||
AES_CreateContext(const unsigned char *key, const unsigned char *iv,
|
||||
|
@ -51,6 +51,18 @@ SEC_END_PROTOS
|
||||
#define HAVE_NO_SANITIZE_ATTR 0
|
||||
#endif
|
||||
|
||||
/* Alignment helpers. */
|
||||
#if defined(_WINDOWS) && defined(NSS_X86_OR_X64)
|
||||
#define pre_align __declspec(align(16))
|
||||
#define post_align
|
||||
#elif defined(NSS_X86_OR_X64)
|
||||
#define pre_align
|
||||
#define post_align __attribute__((aligned(16)))
|
||||
#else
|
||||
#define pre_align
|
||||
#define post_align
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_UNALIGNED_ACCESS) && HAVE_NO_SANITIZE_ATTR
|
||||
#define NO_SANITIZE_ALIGNMENT __attribute__((no_sanitize("alignment")))
|
||||
#else
|
||||
|
@ -19,30 +19,30 @@
|
||||
|
||||
SECStatus
|
||||
CTR_InitContext(CTRContext *ctr, void *context, freeblCipherFunc cipher,
|
||||
const unsigned char *param, unsigned int blocksize)
|
||||
const unsigned char *param)
|
||||
{
|
||||
const CK_AES_CTR_PARAMS *ctrParams = (const CK_AES_CTR_PARAMS *)param;
|
||||
|
||||
if (ctrParams->ulCounterBits == 0 ||
|
||||
ctrParams->ulCounterBits > blocksize * PR_BITS_PER_BYTE) {
|
||||
ctrParams->ulCounterBits > AES_BLOCK_SIZE * PR_BITS_PER_BYTE) {
|
||||
PORT_SetError(SEC_ERROR_INVALID_ARGS);
|
||||
return SECFailure;
|
||||
}
|
||||
|
||||
/* Invariant: 0 < ctr->bufPtr <= blocksize */
|
||||
/* Invariant: 0 < ctr->bufPtr <= AES_BLOCK_SIZE */
|
||||
ctr->checkWrap = PR_FALSE;
|
||||
ctr->bufPtr = blocksize; /* no unused data in the buffer */
|
||||
ctr->bufPtr = AES_BLOCK_SIZE; /* no unused data in the buffer */
|
||||
ctr->cipher = cipher;
|
||||
ctr->context = context;
|
||||
ctr->counterBits = ctrParams->ulCounterBits;
|
||||
if (blocksize > sizeof(ctr->counter) ||
|
||||
blocksize > sizeof(ctrParams->cb)) {
|
||||
if (AES_BLOCK_SIZE > sizeof(ctr->counter) ||
|
||||
AES_BLOCK_SIZE > sizeof(ctrParams->cb)) {
|
||||
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
|
||||
return SECFailure;
|
||||
}
|
||||
PORT_Memcpy(ctr->counter, ctrParams->cb, blocksize);
|
||||
PORT_Memcpy(ctr->counter, ctrParams->cb, AES_BLOCK_SIZE);
|
||||
if (ctr->counterBits < 64) {
|
||||
PORT_Memcpy(ctr->counterFirst, ctr->counter, blocksize);
|
||||
PORT_Memcpy(ctr->counterFirst, ctr->counter, AES_BLOCK_SIZE);
|
||||
ctr->checkWrap = PR_TRUE;
|
||||
}
|
||||
return SECSuccess;
|
||||
@ -50,7 +50,7 @@ CTR_InitContext(CTRContext *ctr, void *context, freeblCipherFunc cipher,
|
||||
|
||||
CTRContext *
|
||||
CTR_CreateContext(void *context, freeblCipherFunc cipher,
|
||||
const unsigned char *param, unsigned int blocksize)
|
||||
const unsigned char *param)
|
||||
{
|
||||
CTRContext *ctr;
|
||||
SECStatus rv;
|
||||
@ -60,7 +60,7 @@ CTR_CreateContext(void *context, freeblCipherFunc cipher,
|
||||
if (ctr == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
rv = CTR_InitContext(ctr, context, cipher, param, blocksize);
|
||||
rv = CTR_InitContext(ctr, context, cipher, param);
|
||||
if (rv != SECSuccess) {
|
||||
CTR_DestroyContext(ctr, PR_TRUE);
|
||||
ctr = NULL;
|
||||
|
@ -23,8 +23,7 @@ struct CTRContextStr {
|
||||
typedef struct CTRContextStr CTRContext;
|
||||
|
||||
SECStatus CTR_InitContext(CTRContext *ctr, void *context,
|
||||
freeblCipherFunc cipher, const unsigned char *param,
|
||||
unsigned int blocksize);
|
||||
freeblCipherFunc cipher, const unsigned char *param);
|
||||
|
||||
/*
|
||||
* The context argument is the inner cipher context to use with cipher. The
|
||||
@ -34,7 +33,7 @@ SECStatus CTR_InitContext(CTRContext *ctr, void *context,
|
||||
* The cipher argument is a block cipher in the ECB encrypt mode.
|
||||
*/
|
||||
CTRContext *CTR_CreateContext(void *context, freeblCipherFunc cipher,
|
||||
const unsigned char *param, unsigned int blocksize);
|
||||
const unsigned char *param);
|
||||
|
||||
void CTR_DestroyContext(CTRContext *ctr, PRBool freeit);
|
||||
|
||||
|
@ -20,19 +20,15 @@ struct CTSContextStr {
|
||||
|
||||
CTSContext *
|
||||
CTS_CreateContext(void *context, freeblCipherFunc cipher,
|
||||
const unsigned char *iv, unsigned int blocksize)
|
||||
const unsigned char *iv)
|
||||
{
|
||||
CTSContext *cts;
|
||||
|
||||
if (blocksize > MAX_BLOCK_SIZE) {
|
||||
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
|
||||
return NULL;
|
||||
}
|
||||
cts = PORT_ZNew(CTSContext);
|
||||
if (cts == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
PORT_Memcpy(cts->iv, iv, blocksize);
|
||||
PORT_Memcpy(cts->iv, iv, MAX_BLOCK_SIZE);
|
||||
cts->cipher = cipher;
|
||||
cts->context = context;
|
||||
return cts;
|
||||
|
@ -17,7 +17,7 @@ typedef struct CTSContextStr CTSContext;
|
||||
* The cipher argument is a block cipher in the CBC mode.
|
||||
*/
|
||||
CTSContext *CTS_CreateContext(void *context, freeblCipherFunc cipher,
|
||||
const unsigned char *iv, unsigned int blocksize);
|
||||
const unsigned char *iv);
|
||||
|
||||
void CTS_DestroyContext(CTSContext *cts, PRBool freeit);
|
||||
|
||||
|
@ -1707,7 +1707,7 @@ BL_FIPSEntryOK(PRBool freebl_only)
|
||||
return SECSuccess;
|
||||
}
|
||||
/* standalone freebl can initialize */
|
||||
if (freebl_only & self_tests_freebl_success) {
|
||||
if (freebl_only && self_tests_freebl_success) {
|
||||
return SECSuccess;
|
||||
}
|
||||
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
|
||||
|
@ -153,6 +153,22 @@
|
||||
'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"', {
|
||||
'msvs_settings': {
|
||||
'VCCLCompilerTool': {
|
||||
@ -243,6 +259,14 @@
|
||||
'MP_USE_UINT_DIGIT',
|
||||
],
|
||||
}],
|
||||
[ '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',
|
||||
],
|
||||
}],
|
||||
[ 'target_arch=="arm"', {
|
||||
'defines': [
|
||||
'MP_ASSEMBLY_MULTIPLY',
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -6,6 +6,17 @@
|
||||
#define GCM_H 1
|
||||
|
||||
#include "blapii.h"
|
||||
#include <stdint.h>
|
||||
|
||||
#ifdef NSS_X86_OR_X64
|
||||
#include <emmintrin.h> /* __m128i */
|
||||
#endif
|
||||
|
||||
SEC_BEGIN_PROTOS
|
||||
|
||||
#ifdef HAVE_INT128_SUPPORT
|
||||
typedef unsigned __int128 uint128_t;
|
||||
#endif
|
||||
|
||||
typedef struct GCMContextStr GCMContext;
|
||||
|
||||
@ -17,7 +28,7 @@ typedef struct GCMContextStr GCMContext;
|
||||
* The cipher argument is a block cipher in the ECB encrypt mode.
|
||||
*/
|
||||
GCMContext *GCM_CreateContext(void *context, freeblCipherFunc cipher,
|
||||
const unsigned char *params, unsigned int blocksize);
|
||||
const unsigned char *params);
|
||||
void GCM_DestroyContext(GCMContext *gcm, PRBool freeit);
|
||||
SECStatus GCM_EncryptUpdate(GCMContext *gcm, unsigned char *outbuf,
|
||||
unsigned int *outlen, unsigned int maxout,
|
||||
@ -28,4 +39,34 @@ SECStatus GCM_DecryptUpdate(GCMContext *gcm, unsigned char *outbuf,
|
||||
const unsigned char *inbuf, unsigned int inlen,
|
||||
unsigned int blocksize);
|
||||
|
||||
/* These functions are here only so we can test them */
|
||||
#define GCM_HASH_LEN_LEN 8 /* gcm hash defines lengths to be 64 bits */
|
||||
typedef struct gcmHashContextStr gcmHashContext;
|
||||
typedef SECStatus (*ghash_t)(gcmHashContext *, const unsigned char *,
|
||||
unsigned int);
|
||||
pre_align struct gcmHashContextStr {
|
||||
#ifdef NSS_X86_OR_X64
|
||||
__m128i x, h;
|
||||
#endif
|
||||
uint64_t x_low, x_high, h_high, h_low;
|
||||
unsigned char buffer[MAX_BLOCK_SIZE];
|
||||
unsigned int bufLen;
|
||||
uint8_t counterBuf[16];
|
||||
uint64_t cLen;
|
||||
ghash_t ghash_mul;
|
||||
PRBool hw;
|
||||
gcmHashContext *mem;
|
||||
} post_align;
|
||||
|
||||
SECStatus gcmHash_Update(gcmHashContext *ghash, const unsigned char *buf,
|
||||
unsigned int len);
|
||||
SECStatus gcmHash_InitContext(gcmHashContext *ghash, const unsigned char *H,
|
||||
PRBool sw);
|
||||
SECStatus gcmHash_Reset(gcmHashContext *ghash, const unsigned char *AAD,
|
||||
unsigned int AADLen);
|
||||
SECStatus gcmHash_Final(gcmHashContext *ghash, unsigned char *outbuf,
|
||||
unsigned int *outlen, unsigned int maxout);
|
||||
|
||||
SEC_END_PROTOS
|
||||
|
||||
#endif
|
||||
|
@ -91,8 +91,6 @@ LOCAL bail
|
||||
movdqu [rsp + 1*16], xmm7
|
||||
movdqu [rsp + 2*16], xmm8
|
||||
|
||||
lea ctx, [48+ctx]
|
||||
|
||||
loop8:
|
||||
cmp inputLen, 8*16
|
||||
jb loop1
|
||||
@ -555,9 +553,7 @@ LOCAL bail
|
||||
movdqu [rsp + 1*16], xmm7
|
||||
movdqu [rsp + 2*16], xmm8
|
||||
|
||||
lea ctx, [48+ctx]
|
||||
|
||||
movdqu xmm0, [-32+ctx]
|
||||
movdqu xmm0, [256+ctx]
|
||||
|
||||
movdqu xmm2, [0*16 + ctx]
|
||||
movdqu xmm3, [1*16 + ctx]
|
||||
@ -597,7 +593,7 @@ loop1:
|
||||
jmp loop1
|
||||
|
||||
bail:
|
||||
movdqu [-32+ctx], xmm0
|
||||
movdqu [256+ctx], xmm0
|
||||
|
||||
xor rax, rax
|
||||
|
||||
@ -625,8 +621,6 @@ LOCAL bail
|
||||
movdqu [rsp + 1*16], xmm7
|
||||
movdqu [rsp + 2*16], xmm8
|
||||
|
||||
lea ctx, [48+ctx]
|
||||
|
||||
loop8:
|
||||
cmp inputLen, 8*16
|
||||
jb dec1
|
||||
@ -657,7 +651,7 @@ loop8:
|
||||
ENDM
|
||||
aes_dec_last_rnd rnds
|
||||
|
||||
movdqu xmm8, [-32 + ctx]
|
||||
movdqu xmm8, [256 + ctx]
|
||||
pxor xmm0, xmm8
|
||||
movdqu xmm8, [0*16 + input]
|
||||
pxor xmm1, xmm8
|
||||
@ -683,7 +677,7 @@ loop8:
|
||||
movdqu [5*16 + output], xmm5
|
||||
movdqu [6*16 + output], xmm6
|
||||
movdqu [7*16 + output], xmm7
|
||||
movdqu [-32 + ctx], xmm8
|
||||
movdqu [256 + ctx], xmm8
|
||||
|
||||
lea input, [8*16 + input]
|
||||
lea output, [8*16 + output]
|
||||
@ -691,7 +685,7 @@ loop8:
|
||||
jmp loop8
|
||||
dec1:
|
||||
|
||||
movdqu xmm3, [-32 + ctx]
|
||||
movdqu xmm3, [256 + ctx]
|
||||
|
||||
loop1:
|
||||
cmp inputLen, 1*16
|
||||
@ -721,7 +715,7 @@ loop1:
|
||||
jmp loop1
|
||||
|
||||
bail:
|
||||
movdqu [-32 + ctx], xmm3
|
||||
movdqu [256 + ctx], xmm3
|
||||
xor rax, rax
|
||||
|
||||
movdqu xmm6, [rsp + 0*16]
|
||||
@ -773,7 +767,6 @@ LOCAL bail
|
||||
|
||||
mov ctrCtx, ctx
|
||||
mov ctx, [8+ctrCtx]
|
||||
lea ctx, [48+ctx]
|
||||
|
||||
sub rsp, 3*16
|
||||
movdqu [rsp + 0*16], xmm6
|
||||
|
@ -87,8 +87,6 @@ LOCAL bail
|
||||
mov input, [esp + 2*4 + 4*4]
|
||||
mov inputLen, [esp + 2*4 + 5*4]
|
||||
|
||||
lea ctx, [44+ctx]
|
||||
|
||||
loop7:
|
||||
cmp inputLen, 7*16
|
||||
jb loop1
|
||||
@ -557,9 +555,7 @@ LOCAL bail
|
||||
mov input, [esp + 2*4 + 4*4]
|
||||
mov inputLen, [esp + 2*4 + 5*4]
|
||||
|
||||
lea ctx, [44+ctx]
|
||||
|
||||
movdqu xmm0, [-32+ctx]
|
||||
movdqu xmm0, [252+ctx]
|
||||
|
||||
movdqu xmm2, [0*16 + ctx]
|
||||
movdqu xmm3, [1*16 + ctx]
|
||||
@ -597,7 +593,7 @@ loop1:
|
||||
jmp loop1
|
||||
|
||||
bail:
|
||||
movdqu [-32+ctx], xmm0
|
||||
movdqu [252+ctx], xmm0
|
||||
|
||||
xor eax, eax
|
||||
pop inputLen
|
||||
@ -619,8 +615,6 @@ LOCAL bail
|
||||
mov input, [esp + 2*4 + 4*4]
|
||||
mov inputLen, [esp + 2*4 + 5*4]
|
||||
|
||||
lea ctx, [44+ctx]
|
||||
|
||||
loop7:
|
||||
cmp inputLen, 7*16
|
||||
jb dec1
|
||||
@ -649,7 +643,7 @@ loop7:
|
||||
ENDM
|
||||
aes_dec_last_rnd rnds
|
||||
|
||||
movdqu xmm7, [-32 + ctx]
|
||||
movdqu xmm7, [252 + ctx]
|
||||
pxor xmm0, xmm7
|
||||
movdqu xmm7, [0*16 + input]
|
||||
pxor xmm1, xmm7
|
||||
@ -672,7 +666,7 @@ loop7:
|
||||
movdqu [4*16 + output], xmm4
|
||||
movdqu [5*16 + output], xmm5
|
||||
movdqu [6*16 + output], xmm6
|
||||
movdqu [-32 + ctx], xmm7
|
||||
movdqu [252 + ctx], xmm7
|
||||
|
||||
lea input, [7*16 + input]
|
||||
lea output, [7*16 + output]
|
||||
@ -680,7 +674,7 @@ loop7:
|
||||
jmp loop7
|
||||
dec1:
|
||||
|
||||
movdqu xmm3, [-32 + ctx]
|
||||
movdqu xmm3, [252 + ctx]
|
||||
|
||||
loop1:
|
||||
cmp inputLen, 1*16
|
||||
@ -710,7 +704,7 @@ loop1:
|
||||
jmp loop1
|
||||
|
||||
bail:
|
||||
movdqu [-32 + ctx], xmm3
|
||||
movdqu [252 + ctx], xmm3
|
||||
xor eax, eax
|
||||
pop inputLen
|
||||
ret
|
||||
@ -769,7 +763,6 @@ LOCAL bail
|
||||
mov inputLen, [esp + 4*5 + 5*4]
|
||||
|
||||
mov ctx, [4+ctrCtx]
|
||||
lea ctx, [44+ctx]
|
||||
|
||||
mov ebp, esp
|
||||
sub esp, 7*16
|
||||
|
@ -4,8 +4,7 @@
|
||||
|
||||
.text
|
||||
|
||||
#define IV_OFFSET 16
|
||||
#define EXPANDED_KEY_OFFSET 48
|
||||
#define IV_OFFSET 256
|
||||
|
||||
/*
|
||||
* Warning: the length values used in this module are "unsigned int"
|
||||
@ -144,9 +143,6 @@ key_expansion128:
|
||||
.globl intel_aes_encrypt_ecb_128
|
||||
.align 16
|
||||
intel_aes_encrypt_ecb_128:
|
||||
// leaq EXPANDED_KEY_OFFSET(%rdi), %rdi
|
||||
leaq 48(%rdi), %rdi
|
||||
|
||||
movdqu (%rdi), %xmm2
|
||||
movdqu 160(%rdi), %xmm12
|
||||
xor %eax, %eax
|
||||
@ -328,9 +324,6 @@ intel_aes_encrypt_ecb_128:
|
||||
.globl intel_aes_decrypt_ecb_128
|
||||
.align 16
|
||||
intel_aes_decrypt_ecb_128:
|
||||
// leaq EXPANDED_KEY_OFFSET(%rdi), %rdi
|
||||
leaq 48(%rdi), %rdi
|
||||
|
||||
movdqu (%rdi), %xmm2
|
||||
movdqu 160(%rdi), %xmm12
|
||||
xorl %eax, %eax
|
||||
@ -516,9 +509,7 @@ intel_aes_encrypt_cbc_128:
|
||||
je 2f
|
||||
|
||||
// leaq IV_OFFSET(%rdi), %rdx
|
||||
// leaq EXPANDED_KEY_OFFSET(%rdi), %rdi
|
||||
leaq 16(%rdi), %rdx
|
||||
leaq 48(%rdi), %rdi
|
||||
leaq 256(%rdi), %rdx
|
||||
|
||||
movdqu (%rdx), %xmm0
|
||||
movdqu (%rdi), %xmm2
|
||||
@ -575,9 +566,7 @@ intel_aes_encrypt_cbc_128:
|
||||
.align 16
|
||||
intel_aes_decrypt_cbc_128:
|
||||
// leaq IV_OFFSET(%rdi), %rdx
|
||||
// leaq EXPANDED_KEY_OFFSET(%rdi), %rdi
|
||||
leaq 16(%rdi), %rdx
|
||||
leaq 48(%rdi), %rdi
|
||||
leaq 256(%rdi), %rdx
|
||||
|
||||
movdqu (%rdx), %xmm0 /* iv */
|
||||
movdqu (%rdi), %xmm2 /* first key block */
|
||||
@ -902,9 +891,6 @@ key_expansion192:
|
||||
.globl intel_aes_encrypt_ecb_192
|
||||
.align 16
|
||||
intel_aes_encrypt_ecb_192:
|
||||
// leaq EXPANDED_KEY_OFFSET(%rdi), %rdi
|
||||
leaq 48(%rdi), %rdi
|
||||
|
||||
movdqu (%rdi), %xmm2
|
||||
movdqu 192(%rdi), %xmm14
|
||||
xorl %eax, %eax
|
||||
@ -1109,9 +1095,6 @@ intel_aes_encrypt_ecb_192:
|
||||
.globl intel_aes_decrypt_ecb_192
|
||||
.align 16
|
||||
intel_aes_decrypt_ecb_192:
|
||||
// leaq EXPANDED_KEY_OFFSET(%rdi), %rdi
|
||||
leaq 48(%rdi), %rdi
|
||||
|
||||
movdqu (%rdi), %xmm2
|
||||
movdqu 192(%rdi), %xmm14
|
||||
xorl %eax, %eax
|
||||
@ -1320,9 +1303,7 @@ intel_aes_encrypt_cbc_192:
|
||||
je 2f
|
||||
|
||||
// leaq IV_OFFSET(%rdi), %rdx
|
||||
// leaq EXPANDED_KEY_OFFSET(%rdi), %rdi
|
||||
leaq 16(%rdi), %rdx
|
||||
leaq 48(%rdi), %rdi
|
||||
leaq 256(%rdi), %rdx
|
||||
|
||||
movdqu (%rdx), %xmm0
|
||||
movdqu (%rdi), %xmm2
|
||||
@ -1382,8 +1363,8 @@ intel_aes_encrypt_cbc_192:
|
||||
.globl intel_aes_decrypt_cbc_192
|
||||
.align 16
|
||||
intel_aes_decrypt_cbc_192:
|
||||
leaq 16(%rdi), %rdx
|
||||
leaq 48(%rdi), %rdi
|
||||
// leaq IV_OFFSET(%rdi), %rdx
|
||||
leaq 256(%rdi), %rdx
|
||||
|
||||
movdqu (%rdx), %xmm0
|
||||
movdqu (%rdi), %xmm2
|
||||
@ -1738,9 +1719,6 @@ key_expansion256:
|
||||
.globl intel_aes_encrypt_ecb_256
|
||||
.align 16
|
||||
intel_aes_encrypt_ecb_256:
|
||||
// leaq EXPANDED_KEY_OFFSET(%rdi), %rdi
|
||||
leaq 48(%rdi), %rdi
|
||||
|
||||
movdqu (%rdi), %xmm2
|
||||
movdqu 224(%rdi), %xmm15
|
||||
xorl %eax, %eax
|
||||
@ -1970,9 +1948,6 @@ intel_aes_encrypt_ecb_256:
|
||||
.globl intel_aes_decrypt_ecb_256
|
||||
.align 16
|
||||
intel_aes_decrypt_ecb_256:
|
||||
// leaq EXPANDED_KEY_OFFSET(%rdi), %rdi
|
||||
leaq 48(%rdi), %rdi
|
||||
|
||||
movdqu (%rdi), %xmm2
|
||||
movdqu 224(%rdi), %xmm15
|
||||
xorl %eax, %eax
|
||||
@ -2206,9 +2181,7 @@ intel_aes_encrypt_cbc_256:
|
||||
je 2f
|
||||
|
||||
// leaq IV_OFFSET(%rdi), %rdx
|
||||
// leaq EXPANDED_KEY_OFFSET(%rdi), %rdi
|
||||
leaq 16(%rdi), %rdx
|
||||
leaq 48(%rdi), %rdi
|
||||
leaq 256(%rdi), %rdx
|
||||
|
||||
movdqu (%rdx), %xmm0
|
||||
movdqu (%rdi), %xmm8
|
||||
@ -2274,9 +2247,7 @@ intel_aes_encrypt_cbc_256:
|
||||
.align 16
|
||||
intel_aes_decrypt_cbc_256:
|
||||
// leaq IV_OFFSET(%rdi), %rdx
|
||||
// leaq EXPANDED_KEY_OFFSET(%rdi), %rdi
|
||||
leaq 16(%rdi), %rdx
|
||||
leaq 48(%rdi), %rdi
|
||||
leaq 256(%rdi), %rdx
|
||||
|
||||
movdqu (%rdx), %xmm0
|
||||
movdqu (%rdi), %xmm2
|
||||
|
@ -41,8 +41,7 @@ struct intel_AES_GCMContextStr {
|
||||
intel_AES_GCMContext *
|
||||
intel_AES_GCM_CreateContext(void *context,
|
||||
freeblCipherFunc cipher,
|
||||
const unsigned char *params,
|
||||
unsigned int blocksize)
|
||||
const unsigned char *params)
|
||||
{
|
||||
intel_AES_GCMContext *gcm = NULL;
|
||||
AESContext *aes = (AESContext *)context;
|
||||
@ -59,12 +58,11 @@ intel_AES_GCM_CreateContext(void *context,
|
||||
unsigned int j;
|
||||
SECStatus rv;
|
||||
|
||||
if (blocksize != AES_BLOCK_SIZE) {
|
||||
PORT_SetError(SEC_ERROR_LIBRARY_FAILURE);
|
||||
if (gcmParams->ulIvLen == 0) {
|
||||
PORT_SetError(SEC_ERROR_INVALID_ARGS);
|
||||
return NULL;
|
||||
}
|
||||
gcm = PORT_ZNew(intel_AES_GCMContext);
|
||||
|
||||
if (gcm == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
@ -496,8 +496,8 @@ LbeginENC:
|
||||
vmovdqu CTR0, XMMWORD PTR[16*16 + 2*16 + Gctx]
|
||||
vmovdqu BSWAPMASK, XMMWORD PTR[Lbswap_mask]
|
||||
mov KS, [16*16 + 3*16 + Gctx]
|
||||
mov NR, [4 + KS]
|
||||
lea KS, [48 + KS]
|
||||
mov NR, [244 + KS]
|
||||
lea KS, [KS]
|
||||
|
||||
vpshufb CTR0, CTR0, BSWAPMASK
|
||||
|
||||
@ -994,8 +994,7 @@ LbeginDEC:
|
||||
vmovdqu CTR0, XMMWORD PTR[16*16 + 2*16 + Gctx]
|
||||
vmovdqu BSWAPMASK, XMMWORD PTR[Lbswap_mask]
|
||||
mov KS, [16*16 + 3*16 + Gctx]
|
||||
mov NR, [4 + KS]
|
||||
lea KS, [48 + KS]
|
||||
mov NR, [244 + KS]
|
||||
|
||||
vpshufb CTR0, CTR0, BSWAPMASK
|
||||
|
||||
|
@ -390,7 +390,7 @@ Htbl textequ <edx>
|
||||
Gctx textequ <edx>
|
||||
len textequ <DWORD PTR[ebp + 5*4 + 3*4]>
|
||||
KS textequ <esi>
|
||||
NR textequ <DWORD PTR[-40 + KS]>
|
||||
NR textequ <DWORD PTR[244+KS]>
|
||||
|
||||
aluCTR textequ <ebx>
|
||||
aluTMP textequ <edi>
|
||||
@ -463,7 +463,6 @@ LbeginENC:
|
||||
mov Gctx, [ebp + 5*4 + 2*4]
|
||||
|
||||
mov KS, [16*16 + 3*16 + Gctx]
|
||||
lea KS, [44 + KS]
|
||||
|
||||
mov aluCTR, [16*16 + 2*16 + 3*4 + Gctx]
|
||||
bswap aluCTR
|
||||
@ -931,7 +930,6 @@ LbeginDEC:
|
||||
mov Gctx, [ebp + 5*4 + 2*4]
|
||||
|
||||
mov KS, [16*16 + 3*16 + Gctx]
|
||||
lea KS, [44 + KS]
|
||||
|
||||
mov aluCTR, [16*16 + 2*16 + 3*4 + Gctx]
|
||||
bswap aluCTR
|
||||
|
@ -27,7 +27,7 @@
|
||||
typedef struct intel_AES_GCMContextStr intel_AES_GCMContext;
|
||||
|
||||
intel_AES_GCMContext *intel_AES_GCM_CreateContext(void *context, freeblCipherFunc cipher,
|
||||
const unsigned char *params, unsigned int blocksize);
|
||||
const unsigned char *params);
|
||||
|
||||
void intel_AES_GCM_DestroyContext(intel_AES_GCMContext *gcm, PRBool freeit);
|
||||
|
||||
|
@ -467,8 +467,8 @@ intel_aes_gcmENC:
|
||||
vmovdqu 288(Gctx), CTR
|
||||
vmovdqu 272(Gctx), T
|
||||
mov 304(Gctx), KS
|
||||
mov 4(KS), NR
|
||||
lea 48(KS), KS
|
||||
# AESContext->Nr
|
||||
mov 244(KS), NR
|
||||
|
||||
vpshufb .Lbswap_mask(%rip), CTR, CTR
|
||||
vpshufb .Lbswap_mask(%rip), T, T
|
||||
@ -1001,8 +1001,8 @@ intel_aes_gcmDEC:
|
||||
vmovdqu 288(Gctx), CTR
|
||||
vmovdqu 272(Gctx), T
|
||||
mov 304(Gctx), KS
|
||||
mov 4(KS), NR
|
||||
lea 48(KS), KS
|
||||
# AESContext->Nr
|
||||
mov 244(KS), NR
|
||||
|
||||
vpshufb .Lbswap_mask(%rip), CTR, CTR
|
||||
vpshufb .Lbswap_mask(%rip), T, T
|
||||
|
@ -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
|
@ -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
|
@ -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
|
@ -67,14 +67,6 @@ 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
|
||||
-----------
|
||||
@ -630,92 +622,6 @@ 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:
|
||||
----------------
|
||||
|
||||
|
@ -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
|
@ -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
|
||||
|
@ -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;
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
@ -17,7 +17,7 @@
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
*/
|
||||
|
||||
@ -775,18 +775,6 @@ s_mpi_getProcessorLineSize()
|
||||
*
|
||||
*/
|
||||
|
||||
/* 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)
|
||||
*/
|
||||
@ -797,12 +785,3 @@ s_mpi_getProcessorLineSize()
|
||||
return 32;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef TEST_IT
|
||||
#include <stdio.h>
|
||||
|
||||
main()
|
||||
{
|
||||
printf("line size = %d\n", s_mpi_getProcessorLineSize());
|
||||
}
|
||||
#endif
|
||||
|
@ -205,7 +205,11 @@ mp_exptmod_f(const mp_int *montBase,
|
||||
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 */
|
||||
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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
|
@ -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/.
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
@ -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;
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user