2018-12-02 12:54:55 +00:00
|
|
|
# MAKEFILE that is intended to be compatible with any kind of make (GNU make, BSD make, ...)
|
|
|
|
# works on: Linux, *BSD, Cygwin, AIX, HP-UX and hopefully other UNIX systems
|
|
|
|
#
|
|
|
|
# Please do not use here neither any special make syntax nor any unusual tools/utilities!
|
|
|
|
|
2018-12-02 17:03:07 +00:00
|
|
|
# using ICC compiler:
|
|
|
|
# make -f makefile.unix CC=icc CFLAGS="-O3 -xP -ip"
|
|
|
|
|
|
|
|
# using Borland C++Builder:
|
|
|
|
# make -f makefile.unix CC=bcc32
|
|
|
|
|
2018-12-02 12:54:55 +00:00
|
|
|
#The following can be overridden from command line e.g. "make -f makefile.unix CC=gcc ARFLAGS=rcs"
|
|
|
|
DESTDIR =
|
|
|
|
PREFIX = /usr/local
|
|
|
|
LIBPATH = $(PREFIX)/lib
|
|
|
|
INCPATH = $(PREFIX)/include
|
|
|
|
CC = cc
|
|
|
|
AR = ar
|
2019-11-05 19:25:39 +00:00
|
|
|
ARFLAGS = rcs
|
2018-12-02 12:54:55 +00:00
|
|
|
CFLAGS = -O2
|
|
|
|
LDFLAGS =
|
|
|
|
|
2019-10-15 19:09:43 +00:00
|
|
|
VERSION = 1.2.0
|
2018-12-02 12:54:55 +00:00
|
|
|
|
|
|
|
#Compilation flags
|
|
|
|
LTM_CFLAGS = -I. $(CFLAGS)
|
|
|
|
LTM_LDFLAGS = $(LDFLAGS)
|
|
|
|
|
|
|
|
#Library to be created (this makefile builds only static library)
|
|
|
|
LIBMAIN_S = libtommath.a
|
|
|
|
|
2019-10-19 14:24:39 +00:00
|
|
|
OBJECTS=mp_2expt.o mp_abs.o mp_add.o mp_add_d.o mp_addmod.o mp_and.o mp_clamp.o mp_clear.o mp_clear_multi.o \
|
|
|
|
mp_cmp.o mp_cmp_d.o mp_cmp_mag.o mp_cnt_lsb.o mp_complement.o mp_copy.o mp_count_bits.o mp_cutoffs.o \
|
2019-11-06 15:50:31 +00:00
|
|
|
mp_div.o mp_div_2.o mp_div_2d.o mp_div_d.o mp_dr_is_modulus.o mp_dr_reduce.o mp_dr_setup.o \
|
2019-11-05 23:13:39 +00:00
|
|
|
mp_error_to_string.o mp_exch.o mp_expt_n.o mp_exptmod.o mp_exteuclid.o mp_fread.o mp_from_sbin.o \
|
2019-10-24 15:33:38 +00:00
|
|
|
mp_from_ubin.o mp_fwrite.o mp_gcd.o mp_get_double.o mp_get_i32.o mp_get_i64.o mp_get_l.o mp_get_ll.o \
|
|
|
|
mp_get_mag_u32.o mp_get_mag_u64.o mp_get_mag_ul.o mp_get_mag_ull.o mp_grow.o mp_init.o mp_init_copy.o \
|
|
|
|
mp_init_i32.o mp_init_i64.o mp_init_l.o mp_init_ll.o mp_init_multi.o mp_init_set.o mp_init_size.o \
|
|
|
|
mp_init_u32.o mp_init_u64.o mp_init_ul.o mp_init_ull.o mp_invmod.o mp_is_square.o mp_kronecker.o mp_lcm.o \
|
2019-11-05 23:13:39 +00:00
|
|
|
mp_log_n.o mp_lshd.o mp_mod.o mp_mod_2d.o mp_montgomery_calc_normalization.o mp_montgomery_reduce.o \
|
apply a series of simplifications
* this is the final commit of a series of simplifications,
containing only the regenerated files and the explanation in the
commit message
* This is in preparation of the size_t change/a potential representation change to use
full width as in tfm, if a (partial?) merge with tfm is desired.
These changes have their own merits however.
* Remove obfuscating tmpx digit pointers (fewer variables, it is more obvious what is
being manipulated)
* Reduce scope of variables where possible
* Stricter error handling/checking (for example handling in karatsuba
was broken)
* In some cases the result was written even in the case of an error
(e.g. s_mp_is_divisible). This will hide bugs, since the user should
check the return value (enforced by MP_WUR). Furthermore if the user
accesses the non-initialized result, valgrind will complain for
example. Global static analysis like coverity will also detect the issue.
Therefore this improves the status quo.
* Introduce generic, private MP_EXCH macro which can be used to swap values.
* Introduce s_mp_copy_digs/s_mp_zero_digs/s_mp_zero_buf
* Some control flow simplifications, e.g, loops instead of goto
* Renamings of variables/labels for consistency
* Renamings of mul/sqr functions for more consistency, e.g., comba
instead of fast suffix
* I didn't read through some very complex functions.
They are so complex, I am too afraid and lazy to touch them.
Maybe someone resposible wants to simplify them if possible. Hint... Hint...
- mp_prime_strong_lucas_selfridge.c
- s_mp_exptmod.c
- s_mp_exptmod_fast.c
2019-10-29 19:26:50 +00:00
|
|
|
mp_montgomery_setup.o mp_mul.o mp_mul_2.o mp_mul_2d.o mp_mul_d.o mp_mulmod.o mp_neg.o mp_or.o mp_pack.o \
|
|
|
|
mp_pack_count.o mp_prime_fermat.o mp_prime_frobenius_underwood.o mp_prime_is_prime.o \
|
|
|
|
mp_prime_miller_rabin.o mp_prime_next_prime.o mp_prime_rabin_miller_trials.o mp_prime_rand.o \
|
2019-11-05 19:35:19 +00:00
|
|
|
mp_prime_strong_lucas_selfridge.o mp_radix_size.o mp_rand.o mp_read_radix.o mp_reduce.o mp_reduce_2k.o \
|
|
|
|
mp_reduce_2k_l.o mp_reduce_2k_setup.o mp_reduce_2k_setup_l.o mp_reduce_is_2k.o mp_reduce_is_2k_l.o \
|
2019-11-05 23:13:39 +00:00
|
|
|
mp_reduce_setup.o mp_root_n.o mp_rshd.o mp_sbin_size.o mp_set.o mp_set_double.o mp_set_i32.o mp_set_i64.o \
|
2019-11-05 19:35:19 +00:00
|
|
|
mp_set_l.o mp_set_ll.o mp_set_u32.o mp_set_u64.o mp_set_ul.o mp_set_ull.o mp_shrink.o mp_signed_rsh.o \
|
2019-11-06 15:50:31 +00:00
|
|
|
mp_sqrmod.o mp_sqrt.o mp_sqrtmod_prime.o mp_sub.o mp_sub_d.o mp_submod.o mp_to_radix.o mp_to_sbin.o \
|
|
|
|
mp_to_ubin.o mp_ubin_size.o mp_unpack.o mp_xor.o mp_zero.o s_mp_add.o s_mp_copy_digs.o s_mp_div_3.o \
|
|
|
|
s_mp_div_recursive.o s_mp_div_school.o s_mp_div_small.o s_mp_exptmod.o s_mp_exptmod_fast.o s_mp_get_bit.o \
|
2019-11-05 23:13:39 +00:00
|
|
|
s_mp_invmod.o s_mp_invmod_odd.o s_mp_log.o s_mp_log_2expt.o s_mp_log_d.o s_mp_montgomery_reduce_comba.o \
|
2019-11-06 15:50:31 +00:00
|
|
|
s_mp_mul.o s_mp_mul_balance.o s_mp_mul_comba.o s_mp_mul_high.o s_mp_mul_high_comba.o s_mp_mul_karatsuba.o \
|
2019-11-05 19:35:19 +00:00
|
|
|
s_mp_mul_toom.o s_mp_prime_is_divisible.o s_mp_prime_tab.o s_mp_radix_map.o s_mp_rand_jenkins.o \
|
apply a series of simplifications
* this is the final commit of a series of simplifications,
containing only the regenerated files and the explanation in the
commit message
* This is in preparation of the size_t change/a potential representation change to use
full width as in tfm, if a (partial?) merge with tfm is desired.
These changes have their own merits however.
* Remove obfuscating tmpx digit pointers (fewer variables, it is more obvious what is
being manipulated)
* Reduce scope of variables where possible
* Stricter error handling/checking (for example handling in karatsuba
was broken)
* In some cases the result was written even in the case of an error
(e.g. s_mp_is_divisible). This will hide bugs, since the user should
check the return value (enforced by MP_WUR). Furthermore if the user
accesses the non-initialized result, valgrind will complain for
example. Global static analysis like coverity will also detect the issue.
Therefore this improves the status quo.
* Introduce generic, private MP_EXCH macro which can be used to swap values.
* Introduce s_mp_copy_digs/s_mp_zero_digs/s_mp_zero_buf
* Some control flow simplifications, e.g, loops instead of goto
* Renamings of variables/labels for consistency
* Renamings of mul/sqr functions for more consistency, e.g., comba
instead of fast suffix
* I didn't read through some very complex functions.
They are so complex, I am too afraid and lazy to touch them.
Maybe someone resposible wants to simplify them if possible. Hint... Hint...
- mp_prime_strong_lucas_selfridge.c
- s_mp_exptmod.c
- s_mp_exptmod_fast.c
2019-10-29 19:26:50 +00:00
|
|
|
s_mp_rand_platform.o s_mp_sqr.o s_mp_sqr_comba.o s_mp_sqr_karatsuba.o s_mp_sqr_toom.o s_mp_sub.o \
|
|
|
|
s_mp_zero_buf.o s_mp_zero_digs.o
|
2018-12-02 12:54:55 +00:00
|
|
|
|
2019-05-19 10:53:49 +00:00
|
|
|
HEADERS_PUB=tommath.h
|
2019-10-01 09:30:13 +00:00
|
|
|
HEADERS=tommath_private.h tommath_class.h tommath_superclass.h tommath_cutoffs.h $(HEADERS_PUB)
|
2018-12-02 12:54:55 +00:00
|
|
|
|
|
|
|
#The default rule for make builds the libtommath.a library (static)
|
|
|
|
default: $(LIBMAIN_S)
|
|
|
|
|
|
|
|
#Dependencies on *.h
|
|
|
|
$(OBJECTS): $(HEADERS)
|
|
|
|
|
|
|
|
#This is necessary for compatibility with BSD make (namely on OpenBSD)
|
|
|
|
.SUFFIXES: .o .c
|
|
|
|
.c.o:
|
|
|
|
$(CC) $(LTM_CFLAGS) -c $< -o $@
|
|
|
|
|
|
|
|
#Create libtommath.a
|
|
|
|
$(LIBMAIN_S): $(OBJECTS)
|
|
|
|
$(AR) $(ARFLAGS) $@ $(OBJECTS)
|
|
|
|
|
2018-12-02 17:46:35 +00:00
|
|
|
#Build test_standalone suite
|
2019-09-10 14:05:27 +00:00
|
|
|
test: demo/shared.o demo/test.o $(LIBMAIN_S)
|
|
|
|
$(CC) $(LTM_CFLAGS) $(LTM_LDFLAGS) $^ -o $@
|
2018-12-02 12:54:55 +00:00
|
|
|
@echo "NOTICE: start the tests by: ./test"
|
|
|
|
|
2019-09-10 14:05:27 +00:00
|
|
|
all: $(LIBMAIN_S) test
|
2018-12-02 12:54:55 +00:00
|
|
|
|
2019-05-04 16:57:07 +00:00
|
|
|
tune: $(LIBMAIN_S)
|
|
|
|
$(MAKE) -C etc tune
|
|
|
|
$(MAKE)
|
|
|
|
|
2018-12-02 12:54:55 +00:00
|
|
|
#NOTE: this makefile works also on cygwin, thus we need to delete *.exe
|
|
|
|
clean:
|
|
|
|
-@rm -f $(OBJECTS) $(LIBMAIN_S)
|
2019-03-04 00:02:22 +00:00
|
|
|
-@rm -f demo/main.o demo/opponent.o demo/test.o test test.exe
|
2018-12-02 12:54:55 +00:00
|
|
|
|
|
|
|
#Install the library + headers
|
|
|
|
install: $(LIBMAIN_S)
|
|
|
|
@mkdir -p $(DESTDIR)$(INCPATH) $(DESTDIR)$(LIBPATH)/pkgconfig
|
|
|
|
@cp $(LIBMAIN_S) $(DESTDIR)$(LIBPATH)/
|
|
|
|
@cp $(HEADERS_PUB) $(DESTDIR)$(INCPATH)/
|
|
|
|
@sed -e 's,^prefix=.*,prefix=$(PREFIX),' -e 's,^Version:.*,Version: $(VERSION),' libtommath.pc.in > $(DESTDIR)$(LIBPATH)/pkgconfig/libtommath.pc
|