diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..6421693 --- /dev/null +++ b/Makefile @@ -0,0 +1,237 @@ +#============================= +#JKHOURY@BBN.COM +# always compiles multi-threaded version +# disable comba optimization using flag comba=n +#============================= +top_srcdir = . +prefix = /usr/local +exec_prefix = ${prefix} +bindir = ${exec_prefix}/bin +libdir = ${exec_prefix}/lib +includedir = ${prefix}/include +mandir = ${prefix}/share/man +type=dynamic +curve=bn +comba=y + +CC = gcc +CPP = g++ +AR = ar +UNAME := $(shell uname) + +HEADERS = mirdef.h miracl.h big.h pairing_3.h zzn.h zzn2.h zzn3.h zzn4.h \ + zzn6.h zzn6a.h zzn8.h zzn12a.h zzn18.h zzn24.h \ + ecn.h ec2.h ecn2.h ecn3.h ecn4.h +DIST=miracl$(curve) +DISTNAME = $(addprefix lib, $(DIST)) +CURVEPREFIX=mrpfc +CURVEDIST=$(CURVEPREFIX)$(curve) +CURVEDISTNAME=lib$(CURVEDIST) +TARGETS = copyfiles $(DISTNAME) $(CURVEDISTNAME) pclean +ifeq ($(curve), kss) + WORDS = 8 +else ifeq ($(curve), mnt) + WORDS = 3 +else ifeq ($(curve), cp) + WORDS = 8 +else ifeq ($(curve), bn) + WORDS = 4 +else ifeq ($(curve), bls) + WORDS = 10 +else + TARGETS = exit +endif + +MIRDEF = mirdef.defaultMT +ifeq ($(strip $(comba)), y) + MIRDEF = mirdef.comba$(WORDS) + CPPFLAG = -DZZNS=$(WORDS) + C_COMBA_OBJECT = mrcomba.o +endif + +CFLAG = -D_REENTRANT +LDFLAGMT = -lpthread + +ifeq ($(strip $(type)), static) + CFLAGS = $(CFLAG) + DISTNAME = $(addprefix lib,$(addsuffix .a, $(DIST))) + DISTS = $(DISTNAME).a $(CURVEDISTNAME).a +else #dynamic + CFLAGS = -fPIC $(CFLAG) +ifeq ($(strip $(UNAME)), Darwin) + DISTS = $(DISTNAME).dylib $(CURVEDISTNAME).dylib +else + DISTS = $(DISTNAME).so $(CURVEDISTNAME).so +endif + +endif + +LDFLAG = -L. -l$(DIST) +LDFLAGS = $(LDFLAG) -l$(CURVEDIST) $(LDFLAGMT) + +#TARGETS = copyfiles $(DISTNAME) libmrpfccp libmrpfcmnt libmrpfcbn libmrpfckss libmrpfcbls libmrpfcss2 pclean + +MANUALS = $(TARGETS:=.1) +HTMLMANS = $(MANUALS:.1=.html) + +C_OBJECTS = mrcore.o mrarth0.o mrarth1.o mrarth2.o mralloc.o mrsmall.o mrzzn2.o mrzzn3.o \ + mrio1.o mrio2.o mrjack.o mrgcd.o mrxgcd.o mrarth3.o mrbits.o mrecn2.o mrzzn4.o \ + mrrand.o mrprime.o mrcrt.o mrscrt.o mrmonty.o mrcurve.o mrsroot.o mrzzn2b.o \ + mrpower.o mrfast.o mrshs.o mrshs256.o mraes.o mrlucas.o mrstrong.o mrgcm.o \ + mrflash.o mrfrnd.o mrdouble.o mrround.o mrbuild.o \ + mrflsh1.o mrpi.o mrflsh2.o mrflsh3.o mrflsh4.o \ + mrbrick.o mrebrick.o mrec2m.o mrgf2m.o mrmuldv.o mrshs512.o $(C_COMBA_OBJECT) + +CPP_OBJECTS = big.o gf2m4x.o gf2m.o \ + ecn.o ec2.o ecn2.o ecn3.o ecn4.o \ + zzn.o zzn2.o zzn3.o zzn4.o zzn6.o zzn6a.o zzn8.o zzn12a.o zzn18.o zzn24.o \ + cp_pair.o mnt_pair.o bn_pair.o kss_pair.o bls_pair.o ss2_pair.o \ + benchmark.o cpabe.o ipe.o cpabethread.o + +cp_OBJECTS = cp_pair.o zzn2.o big.o zzn.o ecn.o +mnt_OBJECTS = mnt_pair.o zzn6a.o ecn3.o zzn3.o zzn2.o big.o zzn.o ecn.o +bn_OBJECTS = bn_pair.o zzn12a.o zzn4.o ecn2.o zzn2.o big.o zzn.o ecn.o +kss_OBJECTS = kss_pair.o zzn18.o zzn6.o ecn3.o zzn3.o big.o zzn.o ecn.o +bls_OBJECTS = bls_pair.o zzn24.o zzn8.o zzn4.o zzn2.o ecn4.o big.o zzn.o ecn.o +ss2_OBJECTS = ss2_pair.o ec2.o gf2m4x.o gf2m.o big.o + +# default target +all: $(TARGETS) + +mex: mex.c + $(CC) -m64 -O2 -o $@ $^ + + +copyfiles: mex + echo "building for OS $(UNAME), curve $(curve)" + cp $(MIRDEF) mirdef.h + ./mex $(WORDS) amd64 mrcomba + cp -p mrmuldv.g64 mrmuldv.c +#ifeq ($(strip $(UNAME)), Darwin) +# cp -p mrmuldv.macs64 mrmuldv.s64 +#else #assume Linux +# cp -p mrmuldv.linuxs64 mrmuldv.s64 +#endif + + +$(DISTNAME): $(C_OBJECTS) +ifeq ($(strip $(type)), static) + $(AR) r $@ $^ +else +ifeq ($(strip $(UNAME)), Darwin) + $(CC) -dynamiclib -m64 -O2 -o $(addsuffix .dylib, $@) $^ +else #assume Linux + $(CC) -shared -Wl,-soname,$(addsuffix .so, $@) -m64 -O2 -o $(addsuffix .so, $@) $^ +endif +endif + +libmrpfccp: $(cp_OBJECTS) +ifeq ($(strip $(type)), static) + $(AR) r $(addsuffux .a, $@) $^ +else +ifeq ($(strip $(UNAME)), Darwin) + $(CPP) -dynamiclib -framework JavaVM -m64 -O2 $(CPPFLAG) -o $(addsuffix .dylib, $@) $^ $(LDFLAG) +else #assume Linux + $(CPP) -shared -Wl,-soname,$(addsuffix .so, $@) -m64 -O2 $(CPPFLAG) -o $(addsuffix .so, $@) $^ $(LDFLAG) +endif +endif + +libmrpfcmnt: $(mnt_OBJECTS) +ifeq ($(strip $(type)), static) + $(AR) r $(addsuffux .a, $@) $^ +else +ifeq ($(strip $(UNAME)), Darwin) + $(CPP) -dynamiclib -framework JavaVM -m64 -O2 $(CPPFLAG) -o $(addsuffix .dylib, $@) $^ $(LDFLAG) +else #assume Linux + $(CPP) -shared -Wl,-soname,$(addsuffix .so, $@) -m64 -O2 $(CPPFLAG) -o $(addsuffix .so, $@) $^ $(LDFLAG) +endif +endif + +libmrpfcbn: $(bn_OBJECTS) +ifeq ($(strip $(type)), static) + $(AR) r $(addsuffux .a, $@) $^ +else +ifeq ($(strip $(UNAME)), Darwin) + $(CPP) -dynamiclib -framework JavaVM -m64 -O2 $(CPPFLAG) -o $(addsuffix .dylib, $@) $^ $(LDFLAG) +else #assume Linux + $(CPP) -shared -Wl,-soname,$(addsuffix .so, $@) -m64 -O2 $(CPPFLAG) -o $(addsuffix .so, $@) $^ $(LDFLAG) +endif +endif + +libmrpfckss: $(kss_OBJECTS) +ifeq ($(strip $(type)), static) + $(AR) r $(addsuffux .a, $@) $^ +else +ifeq ($(strip $(UNAME)), Darwin) + $(CPP) -dynamiclib -framework JavaVM -m64 -O2 $(CPPFLAG) -o $(addsuffix .dylib, $@) $^ $(LDFLAG) +else #assume Linux + $(CPP) -shared -Wl,-soname,$(addsuffix .so, $@) -m64 -O2 $(CPPFLAG) -o $(addsuffix .so, $@) $^ $(LDFLAG) +endif +endif + +libmrpfcbls: $(bls_OBJECTS) +ifeq ($(strip $(type)), static) + $(AR) r $(addsuffux .a, $@) $^ +else +ifeq ($(strip $(UNAME)), Darwin) + $(CPP) -dynamiclib -framework JavaVM -m64 -O2 $(CPPFLAG) -o $(addsuffix .dylib, $@) $^ $(LDFLAG) +else #assume Linux + $(CPP) -shared -Wl,-soname,$(addsuffix .so, $@) -m64 -O2 $(CPPFLAG) -o $(addsuffix .so, $@) $^ $(LDFLAG) +endif +endif + +libmrpfcss2: $(ss2_OBJECTS) +ifeq ($(strip $(type)), static) + $(AR) r $(addsuffux .a, $@) $^ +else +ifeq ($(strip $(UNAME)), Darwin) + $(CPP) -dynamiclib -framework JavaVM -m64 -O2 $(CPPFLAG) -o $(addsuffix .dylib, $@) $^ $(LDFLAG) +else #assume Linux + $(CPP) -shared -Wl,-soname,$(addsuffix .so, $@) -m64 -O2 $(CPPFLAG) -o $(addsuffix .so, $@) $^ $(LDFLAG) +endif +endif + +benchmarkthread cpabethread: + $(CPP) -m64 -O2 $(CPPFLAG) -o $@ $(addsuffix .cpp, $@) $(LDFLAGS) + +$(CPP_OBJECTS): + $(CPP) -Wall -c -m64 -O2 $(CFLAGS) $(CPPFLAG) -o $@ $(subst .o,.cpp,$@) + +mrcomba.o: + $(CC) -Wall -c -m64 -O2 $(CFLAGS) -o $@ mrcomba.c + +%.o: %.c +ifeq ($(strip $(wildcard $<)),) + $(CC) -Wall -c -m64 -O2 $(CFLAGS) -o $@ $< +else + $(CPP) -c -m64 -O2 $(CFLAGS) $(CPPFLAG) -o $@ $(addsuffix pp, $<) +endif + +exit: + echo "You need to specify a correct curve: make curve= where curve=cp|mnt|bn|kss|bls" + +pclean: + rm *.o + +# installation +install: $(DISTS) $(HEADERS) + mkdir -p $(libdir) + mkdir -p $(includedir) + $(top_srcdir)/install-sh -m 755 $(DISTS) $(libdir) + $(top_srcdir)/install-sh -m 644 $(HEADERS) $(includedir) + +uninstall: + for HEADER in $(HEADERS); \ + do \ + /bin/rm -f $(includedir)/$$HEADER; \ + done + for LIB in $(DISTS); \ + do \ + /bin/rm -f $(libdir)/$$LIB; \ + done + +# cleanup + +# remove everything an installing user can rebuild +clean: pclean + rm -f $(DISTS) *.tar.gz *~ diff --git a/README-makefile.txt b/README-makefile.txt new file mode 100644 index 0000000..97a4b30 --- /dev/null +++ b/README-makefile.txt @@ -0,0 +1,85 @@ +author: Joud Khoury jkhoury@bbn.com + +============== +Introduction +============== +We have implemented a Makelfiles to automate building the standard library. +This make file builds shared objects for Mac and Linux. It takes care of linking the correct +objects depending on specified curve. It creates a separate library per curve to expose the standard +miracl PFC interface to external applications. +Note that to optimize the Miracl implementation based on the specific architecture, +we used the comba optimizations. Comba optimization depends on the modulus p of the curve being used. +To implement comba we need to specify the number of words n +which should be n=ceil(p/word size) where word size depends on the architecture (64 bit or 32 bit). +For the MNT curve for example, where p=160bits n=3 whereas for the CP curve p=512 and hence n=8. +For additional info see https://certivox.jira.com/wiki/display/MIRACLPUBLIC/MIRACL+User%27s+Manual + +By default all libraries are compiled with multi-threading and COMBA support + +============= +INSTALLATION +============= +We shall different curves with the make below. Here is a list of the allows curves to specify for below + := [cp | mnt | bn | kss | bls | ss2 ] +Anytime curve is specified, make sure to set the same curve in the header of the miracl_wrapper.h + +First flat unzip the miracl code + unzip -j -aa -L miracl.zip + +Now we are ready to make: + +Makefile with optimizations for Intel and AMD64 architecture (e.g. cluster nodes) with comba optimizations, and multi-threading +for both osx and linux + #uninstall first if different version previosuly installed) + $make clean + #make a separate library per curve + $make curve=cp + $make curve=mnt + $make curve=bn + $make curve=kss + $make curve=bls + #install each one (same applies for uninstall) + # libdir and includedir have to specified only when user does not have root access + # and in that case LD_LIBRARY_PATH must include libdir + $sudo make install curve=cp libdir= includedir= + $sudo make install curve=mnt libdir= includedir= + $sudo make install curve=bn libdir= includedir= + $sudo make install curve=kss libdir= includedir= + $sudo make install curve=bls libdir= includedir= + #test it: first set correctly in miracl_wrapper.h and build multi-threaded benchmark as follows + $make benchmarkthread curve= + $./benchmarkthread + +Makefile withOUT optimizations + #same as above except pass comba=n to the make + + #To test the single threaded version run (only if single threaded libs were built above i.e. no mthreading flag passed) + $make cpabe curve= comba=n + $./cpabe + + + #To create single-threaded benchmark + #set the curve in the header of the miracl_wrapper.h; this is what benchmark.cpp will be linked against, then + $make benchmark curve= comba=n + $./benchmark + +============= +Other NOTES +============= +[For record only - do not make these changes, already in the makefile] +To compile an optimized version of the library, we had to implement the following changes +1- define MR_COMBA n in mirdef.h +2- generate mrcomba.c using mex utility e.g. ./mex n amd64 mrcomba (requires compiling mex.c first) +3- use the correct muldiv.c depending on architecture (check use guide) +4- compile mrcomba.c and muldiv.c and include it in the miracle.a library +5- use the -DZZNS=n flag when compiling the c++ libraries + +To compile with multithreading support, pass mthreading=true to the make + +We extended the PFC implementations for G1 , G2, and GT to support serialize/deserialize of elements. +We need that for over the network crypto that we do. The spill/restore functionality only serialized +precomputations which we are less interested in (we can pre comp at the destiantions). + +- [Completed 10/2012] Update AMD makefile to support compiling all curve linbraries (instead of specifying curve) +- [Completed 10/2012] Update AMD makefile to support multi-threading compile +- [Completed 10/2012] Create same for optimized intel \ No newline at end of file diff --git a/include/miracl_wrapper.h b/include/miracl_wrapper.h new file mode 100644 index 0000000..d55bb16 --- /dev/null +++ b/include/miracl_wrapper.h @@ -0,0 +1,69 @@ +/* + Quick Benchmark utility + jkhoury@bbn.com + + Compile with modules as specified below + +TYPE 1 curves +============ + For MR_PAIRING_SS2 curves + ss2_pair.cpp ec2.cpp gf2m4x.cpp gf2m.cpp big.cpp miracl.lib + + For MR_PAIRING_SSP curves + ssp_pair.cpp ecn.cpp zzn2.cpp zzn.cpp big.cpp miracl.lib + +TYPE 3 curves +============= + For MR_PAIRING_CP curve + cp_pair.cpp zzn2.cpp big.cpp zzn.cpp ecn.cpp miracl.lib + + For MR_PAIRING_MNT curve + mnt_pair.cpp zzn6a.cpp ecn3.cpp zzn3.cpp zzn2.cpp big.cpp zzn.cpp ecn.cpp miracl.lib + + For MR_PAIRING_BN curve + bn_pair.cpp zzn12a.cpp ecn2.cpp zzn4.cpp zzn2.cpp big.cpp zzn.cpp ecn.cpp miracl.lib + + For MR_PAIRING_KSS curve + kss_pair.cpp zzn18.cpp zzn6.cpp ecn3.cpp zzn3.cpp big.cpp zzn.cpp ecn.cpp miracl.lib + + For MR_PAIRING_BLS curve + bls_pair.cpp zzn24.cpp zzn8.cpp zzn4.cpp zzn2.cpp ecn4.cpp big.cpp zzn.cpp ecn.cpp miracl.lib + +*/ +#define TYPE3 + +#ifdef TYPE3 +#define GROUP_NAME G2 +//********* choose just one of these pairs ********** +//#define MR_PAIRING_CP // AES-80 security +//#define AES_SECURITY 80 + +//#define MR_PAIRING_MNT // AES-80 security +//#define AES_SECURITY 80 + +#define MR_PAIRING_BN // AES-128 or AES-192 security **** +#define AES_SECURITY 128 +//#define AES_SECURITY 192 + +//#define MR_PAIRING_KSS // AES-192 security +//#define AES_SECURITY 192 + +//#define MR_PAIRING_BLS // AES-256 security +//#define AES_SECURITY 256 +//********************************************* +#include "pairing_3.h" +#endif + +#ifdef TYPE1 +#define GROUP_NAME G1 +//********* choose just one of these ********** +#define MR_PAIRING_SS2 // AES-80 or AES-128 security GF(2^m) curve +#define AES_SECURITY 80 // OR +//#define AES_SECURITY 128 + +//#define MR_PAIRING_SSP // AES-80 or AES-128 security GF(p) curve +//#define AES_SECURITY 80 // OR +//#define AES_SECURITY 128 +//********************************************* +#include "pairing_1.h" +#endif diff --git a/include/mirdef.comba10 b/include/mirdef.comba10 new file mode 100644 index 0000000..b31e50b --- /dev/null +++ b/include/mirdef.comba10 @@ -0,0 +1,18 @@ +/* + * MIRACL compiler/hardware definitions - mirdef.h + * Copyright (c) 1988-2008 Shamus Software Ltd. + */ + +#define MR_LITTLE_ENDIAN +#define MIRACL 64 +#define mr_utype long +#define mr_unsign64 unsigned long +#define MR_IBITS 32 +#define MR_LBITS 64 +#define mr_unsign32 unsigned int +#define MR_FLASH 52 +#define MR_ALWAYS_BINARY +#define MAXBASE ((mr_small)1<<(MIRACL-1)) +#define MR_BITSINCHAR 8 +#define MR_COMBA 10 +#define MR_UNIX_MT diff --git a/include/mirdef.comba3 b/include/mirdef.comba3 new file mode 100644 index 0000000..8824814 --- /dev/null +++ b/include/mirdef.comba3 @@ -0,0 +1,18 @@ +/* + * MIRACL compiler/hardware definitions - mirdef.h + * Copyright (c) 1988-2008 Shamus Software Ltd. + */ + +#define MR_LITTLE_ENDIAN +#define MIRACL 64 +#define mr_utype long +#define mr_unsign64 unsigned long +#define MR_IBITS 32 +#define MR_LBITS 64 +#define mr_unsign32 unsigned int +#define MR_FLASH 52 +#define MR_ALWAYS_BINARY +#define MAXBASE ((mr_small)1<<(MIRACL-1)) +#define MR_BITSINCHAR 8 +#define MR_COMBA 3 +#define MR_UNIX_MT \ No newline at end of file diff --git a/include/mirdef.comba4 b/include/mirdef.comba4 new file mode 100644 index 0000000..66479ce --- /dev/null +++ b/include/mirdef.comba4 @@ -0,0 +1,18 @@ +/* + * MIRACL compiler/hardware definitions - mirdef.h + * Copyright (c) 1988-2008 Shamus Software Ltd. + */ + +#define MR_LITTLE_ENDIAN +#define MIRACL 64 +#define mr_utype long +#define mr_unsign64 unsigned long +#define MR_IBITS 32 +#define MR_LBITS 64 +#define mr_unsign32 unsigned int +#define MR_FLASH 52 +#define MR_ALWAYS_BINARY +#define MAXBASE ((mr_small)1<<(MIRACL-1)) +#define MR_BITSINCHAR 8 +#define MR_COMBA 4 +#define MR_UNIX_MT \ No newline at end of file diff --git a/include/mirdef.comba8 b/include/mirdef.comba8 new file mode 100644 index 0000000..aff7605 --- /dev/null +++ b/include/mirdef.comba8 @@ -0,0 +1,18 @@ +/* + * MIRACL compiler/hardware definitions - mirdef.h + * Copyright (c) 1988-2008 Shamus Software Ltd. + */ + +#define MR_LITTLE_ENDIAN +#define MIRACL 64 +#define mr_utype long +#define mr_unsign64 unsigned long +#define MR_IBITS 32 +#define MR_LBITS 64 +#define mr_unsign32 unsigned int +#define MR_FLASH 52 +#define MR_ALWAYS_BINARY +#define MAXBASE ((mr_small)1<<(MIRACL-1)) +#define MR_BITSINCHAR 8 +#define MR_COMBA 8 +#define MR_UNIX_MT \ No newline at end of file diff --git a/include/mirdef.default b/include/mirdef.default new file mode 100644 index 0000000..631d0ed --- /dev/null +++ b/include/mirdef.default @@ -0,0 +1,15 @@ +/* + * MIRACL compiler/hardware definitions - mirdef.h + * Copyright (c) 1988-2008 Shamus Software Ltd. + */ + +#define MR_LITTLE_ENDIAN +#define MIRACL 64 +#define mr_utype long +#define mr_unsign64 unsigned long +#define MR_IBITS 32 +#define MR_LBITS 64 +#define mr_unsign32 unsigned int +#define MR_FLASH 52 +#define MAXBASE ((mr_small)1<<(MIRACL-1)) +#define MR_BITSINCHAR 8 diff --git a/include/mirdef.defaultMT b/include/mirdef.defaultMT new file mode 100644 index 0000000..78bbf94 --- /dev/null +++ b/include/mirdef.defaultMT @@ -0,0 +1,16 @@ +/* + * MIRACL compiler/hardware definitions - mirdef.h + * Copyright (c) 1988-2008 Shamus Software Ltd. + */ + +#define MR_LITTLE_ENDIAN +#define MIRACL 64 +#define mr_utype long +#define mr_unsign64 unsigned long +#define MR_IBITS 32 +#define MR_LBITS 64 +#define mr_unsign32 unsigned int +#define MR_FLASH 52 +#define MAXBASE ((mr_small)1<<(MIRACL-1)) +#define MR_BITSINCHAR 8 +#define MR_UNIX_MT \ No newline at end of file diff --git a/install-sh b/install-sh new file mode 100755 index 0000000..dd97db7 --- /dev/null +++ b/install-sh @@ -0,0 +1,322 @@ +#!/bin/sh +# install - install a program, script, or datafile + +scriptversion=2004-09-10.20 + +# This originates from X11R5 (mit/util/scripts/install.sh), which was +# later released in X11R6 (xc/config/util/install.sh) with the +# following copyright and license. +# +# Copyright (C) 1994 X Consortium +# +# Permission is hereby granted, free of charge, to any person obtaining a copy +# of this software and associated documentation files (the "Software"), to +# deal in the Software without restriction, including without limitation the +# rights to use, copy, modify, merge, publish, distribute, sublicense, and/or +# sell copies of the Software, and to permit persons to whom the Software is +# furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice shall be included in +# all copies or substantial portions of the Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +# X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN +# AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNEC- +# TION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +# +# Except as contained in this notice, the name of the X Consortium shall not +# be used in advertising or otherwise to promote the sale, use or other deal- +# ings in this Software without prior written authorization from the X Consor- +# tium. +# +# +# FSF changes to this file are in the public domain. +# +# Calling this script install-sh is preferred over install.sh, to prevent +# `make' implicit rules from creating a file called install from it +# when there is no Makefile. +# +# This script is compatible with the BSD install script, but was written +# from scratch. It can only install one file at a time, a restriction +# shared with many OS's install programs. + +# set DOITPROG to echo to test this script + +# Don't use :- since 4.3BSD and earlier shells don't like it. +doit="${DOITPROG-}" + +# put in absolute paths if you don't have them in your path; or use env. vars. + +mvprog="${MVPROG-mv}" +cpprog="${CPPROG-cp}" +chmodprog="${CHMODPROG-chmod}" +chownprog="${CHOWNPROG-chown}" +chgrpprog="${CHGRPPROG-chgrp}" +stripprog="${STRIPPROG-strip}" +rmprog="${RMPROG-rm}" +mkdirprog="${MKDIRPROG-mkdir}" + +chmodcmd="$chmodprog 0755" +chowncmd= +chgrpcmd= +stripcmd= +rmcmd="$rmprog -f" +mvcmd="$mvprog" +src= +dst= +dir_arg= +dstarg= +no_target_directory= + +usage="Usage: $0 [OPTION]... [-T] SRCFILE DSTFILE + or: $0 [OPTION]... SRCFILES... DIRECTORY + or: $0 [OPTION]... -t DIRECTORY SRCFILES... + or: $0 [OPTION]... -d DIRECTORIES... + +In the 1st form, copy SRCFILE to DSTFILE. +In the 2nd and 3rd, copy all SRCFILES to DIRECTORY. +In the 4th, create DIRECTORIES. + +Options: +-c (ignored) +-d create directories instead of installing files. +-g GROUP $chgrpprog installed files to GROUP. +-m MODE $chmodprog installed files to MODE. +-o USER $chownprog installed files to USER. +-s $stripprog installed files. +-t DIRECTORY install into DIRECTORY. +-T report an error if DSTFILE is a directory. +--help display this help and exit. +--version display version info and exit. + +Environment variables override the default commands: + CHGRPPROG CHMODPROG CHOWNPROG CPPROG MKDIRPROG MVPROG RMPROG STRIPPROG +" + +while test -n "$1"; do + case $1 in + -c) shift + continue;; + + -d) dir_arg=true + shift + continue;; + + -g) chgrpcmd="$chgrpprog $2" + shift + shift + continue;; + + --help) echo "$usage"; exit 0;; + + -m) chmodcmd="$chmodprog $2" + shift + shift + continue;; + + -o) chowncmd="$chownprog $2" + shift + shift + continue;; + + -s) stripcmd=$stripprog + shift + continue;; + + -t) dstarg=$2 + shift + shift + continue;; + + -T) no_target_directory=true + shift + continue;; + + --version) echo "$0 $scriptversion"; exit 0;; + + *) # When -d is used, all remaining arguments are directories to create. + # When -t is used, the destination is already specified. + test -n "$dir_arg$dstarg" && break + # Otherwise, the last argument is the destination. Remove it from $@. + for arg + do + if test -n "$dstarg"; then + # $@ is not empty: it contains at least $arg. + set fnord "$@" "$dstarg" + shift # fnord + fi + shift # arg + dstarg=$arg + done + break;; + esac +done + +if test -z "$1"; then + if test -z "$dir_arg"; then + echo "$0: no input file specified." >&2 + exit 1 + fi + # It's OK to call `install-sh -d' without argument. + # This can happen when creating conditional directories. + exit 0 +fi + +for src +do + # Protect names starting with `-'. + case $src in + -*) src=./$src ;; + esac + + if test -n "$dir_arg"; then + dst=$src + src= + + if test -d "$dst"; then + mkdircmd=: + chmodcmd= + else + mkdircmd=$mkdirprog + fi + else + # Waiting for this to be detected by the "$cpprog $src $dsttmp" command + # might cause directories to be created, which would be especially bad + # if $src (and thus $dsttmp) contains '*'. + if test ! -f "$src" && test ! -d "$src"; then + echo "$0: $src does not exist." >&2 + exit 1 + fi + + if test -z "$dstarg"; then + echo "$0: no destination specified." >&2 + exit 1 + fi + + dst=$dstarg + # Protect names starting with `-'. + case $dst in + -*) dst=./$dst ;; + esac + + # If destination is a directory, append the input filename; won't work + # if double slashes aren't ignored. + if test -d "$dst"; then + if test -n "$no_target_directory"; then + echo "$0: $dstarg: Is a directory" >&2 + exit 1 + fi + dst=$dst/`basename "$src"` + fi + fi + + # This sed command emulates the dirname command. + dstdir=`echo "$dst" | sed -e 's,[^/]*$,,;s,/$,,;s,^$,.,'` + + # Make sure that the destination directory exists. + + # Skip lots of stat calls in the usual case. + if test ! -d "$dstdir"; then + defaultIFS=' + ' + IFS="${IFS-$defaultIFS}" + + oIFS=$IFS + # Some sh's can't handle IFS=/ for some reason. + IFS='%' + set - `echo "$dstdir" | sed -e 's@/@%@g' -e 's@^%@/@'` + IFS=$oIFS + + pathcomp= + + while test $# -ne 0 ; do + pathcomp=$pathcomp$1 + shift + if test ! -d "$pathcomp"; then + $mkdirprog "$pathcomp" + # mkdir can fail with a `File exist' error in case several + # install-sh are creating the directory concurrently. This + # is OK. + test -d "$pathcomp" || exit + fi + pathcomp=$pathcomp/ + done + fi + + if test -n "$dir_arg"; then + $doit $mkdircmd "$dst" \ + && { test -z "$chowncmd" || $doit $chowncmd "$dst"; } \ + && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dst"; } \ + && { test -z "$stripcmd" || $doit $stripcmd "$dst"; } \ + && { test -z "$chmodcmd" || $doit $chmodcmd "$dst"; } + + else + dstfile=`basename "$dst"` + + # Make a couple of temp file names in the proper directory. + dsttmp=$dstdir/_inst.$$_ + rmtmp=$dstdir/_rm.$$_ + + # Trap to clean up those temp files at exit. + trap 'ret=$?; rm -f "$dsttmp" "$rmtmp" && exit $ret' 0 + trap '(exit $?); exit' 1 2 13 15 + + # Copy the file name to the temp name. + $doit $cpprog "$src" "$dsttmp" && + + # and set any options; do chmod last to preserve setuid bits. + # + # If any of these fail, we abort the whole thing. If we want to + # ignore errors from any of these, just make sure not to ignore + # errors from the above "$doit $cpprog $src $dsttmp" command. + # + { test -z "$chowncmd" || $doit $chowncmd "$dsttmp"; } \ + && { test -z "$chgrpcmd" || $doit $chgrpcmd "$dsttmp"; } \ + && { test -z "$stripcmd" || $doit $stripcmd "$dsttmp"; } \ + && { test -z "$chmodcmd" || $doit $chmodcmd "$dsttmp"; } && + + # Now rename the file to the real destination. + { $doit $mvcmd -f "$dsttmp" "$dstdir/$dstfile" 2>/dev/null \ + || { + # The rename failed, perhaps because mv can't rename something else + # to itself, or perhaps because mv is so ancient that it does not + # support -f. + + # Now remove or move aside any old file at destination location. + # We try this two ways since rm can't unlink itself on some + # systems and the destination file might be busy for other + # reasons. In this case, the final cleanup might fail but the new + # file should still install successfully. + { + if test -f "$dstdir/$dstfile"; then + $doit $rmcmd -f "$dstdir/$dstfile" 2>/dev/null \ + || $doit $mvcmd -f "$dstdir/$dstfile" "$rmtmp" 2>/dev/null \ + || { + echo "$0: cannot unlink or rename $dstdir/$dstfile" >&2 + (exit 1); exit + } + else + : + fi + } && + + # Now rename the file to the real destination. + $doit $mvcmd "$dsttmp" "$dstdir/$dstfile" + } + } + fi || { (exit 1); exit; } +done + +# The final little trick to "correctly" pass the exit status to the exit trap. +{ + (exit 0); exit +} + +# Local variables: +# eval: (add-hook 'write-file-hooks 'time-stamp) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-end: "$" +# End: diff --git a/source/curve/pairing/benchmark.cpp b/source/curve/pairing/benchmark.cpp new file mode 100644 index 0000000..303e2dc --- /dev/null +++ b/source/curve/pairing/benchmark.cpp @@ -0,0 +1,215 @@ +/* + Quick Benchmark utility + jkhoury@bbn.com + + +*/ +#include "miracl_wrapper.h" + +#include +#include +#include + +int main(int argc, char* argv[]) +{ + const int NUM_GROUPS = 4, NUM_TIMES=11; + int i,j=0, n=20; + double t[NUM_TIMES], elapsed; + clock_t start; + + + PFC pfc(AES_SECURITY); // initialise pairing-friendly curve + miracl* mip=get_mip(); + + time_t seed; + + if(argc == 2) + n = atoi(argv[1]); + + string group_names[NUM_GROUPS ] = {"G1","G2","GT","Zp"}; + string headers[NUM_TIMES] = {"avg pairing time (ms): ", "one more multi_pairing (ms)", + "avg pairing precomp time (ms): ", "avg pairing w/ precomp time (ms): ", "one more multi_pairing x2 w/precomp (ms)", "one more multi_pairing x3 w/precomp (ms)", + "avg multiply_G1 time (ms): ", "avg multiply_GT time (ms): ", + "avg exp time (ms): ", "avg exp precomp time (ms): ", "avg exp w/ precomp time (ms): " + }; + G1 g1[n], h1[n], H1[n], l1[n], r1[n], P1[n]; + G1 *mg1 [2]; + G1* mmg1[3]; + GROUP_NAME g2[n], h2[n], r2[n]; + GROUP_NAME *mg2[2]; + GROUP_NAME *mmg2[3]; + GT *L = new GT[n]; + GT *ML = new GT[n]; + GT *R = new GT[n]; + GT *MR = new GT[n]; + Big b1[n], b2[n]; + + time(&seed); + irand((long)seed); + + Big order=pfc.order(); + for(int i=0; i< NUM_TIMES; i++){ + t[i] = 0; + } + cout << "Starting pairing and multiplication benchmark, n=" << n << " iterations" << endl; + for(int i=0; i +#include +#include +#include +#include + +void *execute(void *id) +//void execute( long id) +{ + long myid = (long)id; + const int NUM_GROUPS = 4, NUM_TIMES=11; + int i,j=0, n=20; + double t[NUM_TIMES], elapsed; + clock_t start; + ostringstream stream; + + stream << "creating thread: " << myid << " ..."<< endl; + PFC pfc(AES_SECURITY); // initialise pairing-friendly curve + miracl* mip=get_mip(); + + time_t seed; + + n = 100; + + string group_names[NUM_GROUPS ] = {"G1","G2","GT","Zp"}; + string headers[NUM_TIMES] = {"avg pairing time (ms): ", "one more multi_pairing (ms)", + "avg pairing precomp time (ms): ", "avg pairing w/ precomp time (ms): ", "one more multi_pairing x2 w/precomp (ms)", "one more multi_pairing x3 w/precomp (ms)", + "avg multiply_G1 time (ms): ", "avg multiply_GT time (ms): ", + "avg exp time (ms): ", "avg exp precomp time (ms): ", "avg exp w/ precomp time (ms): " + }; + G1 g1[n], h1[n], H1[n], l1[n], r1[n], P1[n]; + G1 *mg1 [2]; + G1* mmg1[3]; + GROUP_NAME g2[n], h2[n], r2[n]; + GROUP_NAME *mg2[2]; + GROUP_NAME *mmg2[3]; + GT *L = new GT[n]; + GT *ML = new GT[n]; + GT *R = new GT[n]; + GT *MR = new GT[n]; + Big b1[n], b2[n]; + + time(&seed); + irand((long)(seed+myid)); + + Big order=pfc.order(); + for(int i=0; i< NUM_TIMES; i++){ + t[i] = 0; + } + stream << "Starting pairing and multiplication benchmark, n=" << n << " iterations" << endl; + for(int i=0; i