Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
237 changes: 237 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,237 @@
#=============================
#[email protected]
# 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=<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 *~
85 changes: 85 additions & 0 deletions README-makefile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
author: Joud Khoury [email protected]

==============
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 <curve> below
<curve> := [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=<libdir> includedir=<includedir>
$sudo make install curve=mnt libdir=<libdir> includedir=<includedir>
$sudo make install curve=bn libdir=<libdir> includedir=<includedir>
$sudo make install curve=kss libdir=<libdir> includedir=<includedir>
$sudo make install curve=bls libdir=<libdir> includedir=<includedir>
#test it: first set <curve> correctly in miracl_wrapper.h and build multi-threaded benchmark as follows
$make benchmarkthread curve=<curve>
$./benchmarkthread <numthreads>

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=<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=<curve> comba=n
$./benchmark <iterations>

=============
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
69 changes: 69 additions & 0 deletions include/miracl_wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
Quick Benchmark utility
[email protected]

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
Loading