From dfbb5ecd56b5e0580df8598a2cbaa35c83d8d2a7 Mon Sep 17 00:00:00 2001 From: nijtmans Date: Thu, 6 Jun 2019 16:22:54 +0200 Subject: [PATCH 1/4] MSVC compile: higher warning-level -Wall, but warning-free --- demo/test.c | 6 ++++-- makefile.msvc | 4 ++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/demo/test.c b/demo/test.c index 8627bf269..748be4b98 100644 --- a/demo/test.c +++ b/demo/test.c @@ -622,6 +622,7 @@ static int test_mp_invmod(void) } +#if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559) static int test_mp_set_double(void) { int i; @@ -632,7 +633,6 @@ static int test_mp_set_double(void) } /* test mp_get_double/mp_set_double */ -#if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559) if (mp_set_double(&a, +1.0/0.0) != MP_VAL) { printf("\nmp_set_double should return MP_VAL for +inf"); goto LBL_ERR; @@ -670,7 +670,6 @@ static int test_mp_set_double(void) goto LBL_ERR; } } -#endif mp_clear_multi(&a, &b, NULL); return EXIT_SUCCESS; @@ -679,6 +678,7 @@ static int test_mp_set_double(void) return EXIT_FAILURE; } +#endif static int test_mp_get_u32(void) { @@ -2112,7 +2112,9 @@ int unit_tests(int argc, char **argv) T(mp_read_radix), T(mp_reduce_2k), T(mp_reduce_2k_l), +#if defined(__STDC_IEC_559__) || defined(__GCC_IEC_559) T(mp_set_double), +#endif T(mp_signed_rsh), T(mp_sqrt), T(mp_sqrtmod_prime), diff --git a/makefile.msvc b/makefile.msvc index 2381b177b..d0d6a56aa 100644 --- a/makefile.msvc +++ b/makefile.msvc @@ -14,7 +14,7 @@ PREFIX = c:\devel CFLAGS = /Ox #Compilation flags -LTM_CFLAGS = /nologo /I./ /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /W3 $(CFLAGS) +LTM_CFLAGS = /nologo /I./ /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /Wall /wd4146 /wd4127 /wd4710 /wd4711 /wd4820 $(CFLAGS) LTM_LDFLAGS = advapi32.lib #Libraries to be created (this makefile builds only static libraries) @@ -60,7 +60,7 @@ $(OBJECTS): $(HEADERS) .c.obj: $(CC) $(LTM_CFLAGS) /c $< /Fo$@ -#Create tomcrypt.lib +#Create tommath.lib $(LIBMAIN_S): $(OBJECTS) lib /out:$(LIBMAIN_S) $(OBJECTS) From 196d88309b54c3933fd6084e95f133f2edefb0ae Mon Sep 17 00:00:00 2001 From: nijtmans Date: Thu, 6 Jun 2019 17:00:18 +0200 Subject: [PATCH 2/4] A little stricter on 32-bit compiles --- makefile.msvc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/makefile.msvc b/makefile.msvc index d0d6a56aa..3fbae6390 100644 --- a/makefile.msvc +++ b/makefile.msvc @@ -14,7 +14,7 @@ PREFIX = c:\devel CFLAGS = /Ox #Compilation flags -LTM_CFLAGS = /nologo /I./ /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /Wall /wd4146 /wd4127 /wd4710 /wd4711 /wd4820 $(CFLAGS) +LTM_CFLAGS = /nologo /I./ /D_CRT_SECURE_NO_WARNINGS /D_CRT_NONSTDC_NO_DEPRECATE /D__STDC_WANT_SECURE_LIB__=0 /Wall /wd4146 /wd4127 /wd4710 /wd4711 /wd4820 $(CFLAGS) LTM_LDFLAGS = advapi32.lib #Libraries to be created (this makefile builds only static libraries) From f00cc99f8c250760308d2a12b9407f58ab2caa16 Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Thu, 6 Jun 2019 18:15:19 +0200 Subject: [PATCH 3/4] replace generate_def.sh with perl function --- generate_def.sh | 9 --------- helper.pl | 31 +++++++++++++++++++++++++------ makefile | 2 +- testme.sh | 4 ++-- tommath.def | 17 ++++++++--------- 5 files changed, 36 insertions(+), 27 deletions(-) delete mode 100755 generate_def.sh diff --git a/generate_def.sh b/generate_def.sh deleted file mode 100755 index fc8f2fb65..000000000 --- a/generate_def.sh +++ /dev/null @@ -1,9 +0,0 @@ -echo "; libtommath" >tommath.def -echo ";" >>tommath.def -echo "; Use this command to produce a 32-bit .lib file, for use in any MSVC version" >>tommath.def -echo "; lib -machine:X86 -name:libtommath.dll -def:tommath.def -out:tommath.lib" >>tommath.def -echo "; Use this command to produce a 64-bit .lib file, for use in any MSVC version" >>tommath.def -echo "; lib -machine:X64 -name:libtommath.dll -def:tommath.def -out:tommath.lib" >>tommath.def -echo ";" >>tommath.def -echo "EXPORTS" >>tommath.def -git ls-files|grep \\.c|sed -e 's/bn_mp_rand/bn_mp_rand\nbn_mp_rand_digit/'|sed -e 's/bn_conversion/bn_mp_set_i32\nbn_mp_set_i64\nbn_mp_set_u32\nbn_mp_set_u64\nbn_mp_set_int\nbn_mp_set_long\nbn_mp_set_long_long\nbn_mp_get_i32\nbn_mp_get_i64\nbn_mp_get_mag32\nbn_mp_get_mag64\nbn_mp_get_int\nbn_mp_get_long\nbn_mp_get_long_long\nbn_mp_init_i32\nbn_mp_init_i64\nbn_mp_init_u32\nbn_mp_init_u64\nbn_mp_init_set_int/'|grep -v bn_mp_radix_smap|grep bn_mp_|sort|sed -e 's/bn_/ /g'|sed -e 's/\.c//g'>>tommath.def diff --git a/helper.pl b/helper.pl index e0baeb064..ab3a4a0d8 100755 --- a/helper.pl +++ b/helper.pl @@ -437,7 +437,26 @@ sub update_dep } sub generate_def { - system("sh", "generate_def.sh"); + my @files = split /\n/, `git ls-files`; + @files = grep(/\.c/, @files); + @files = map { my $x = $_; $x =~ s/^bn_|\.c$//g; $x; } @files; + @files = grep(!/mp_radix_smap/, @files); + + @files = grep(!/conversion/, @files); + push(@files, qw(mp_set_i32 mp_set_i64 mp_set_u32 mp_set_u64 mp_set_int mp_set_long mp_set_long_long mp_get_i32 mp_get_i64 mp_get_mag32 mp_get_mag64 mp_get_int mp_get_long mp_get_long_long mp_init_i32 mp_init_i64 mp_init_u32 mp_init_u64 mp_init_set_int)); + + my $files = join("\n ", sort(grep(/^mp_/, @files))); + write_file "tommath.def", "; libtommath +; +; Use this command to produce a 32-bit .lib file, for use in any MSVC version +; lib -machine:X86 -name:libtommath.dll -def:tommath.def -out:tommath.lib +; Use this command to produce a 64-bit .lib file, for use in any MSVC version +; lib -machine:X64 -name:libtommath.dll -def:tommath.def -out:tommath.lib +; +EXPORTS + $files +"; + return 0; } sub die_usage { @@ -446,7 +465,7 @@ sub die_usage { $0 -o OR $0 --check-comments $0 -m OR $0 --check-makefiles $0 -a OR $0 --check-all - $0 -u OR $0 --update-makefiles + $0 -u OR $0 --update-files MARKER } @@ -455,7 +474,7 @@ sub die_usage { "m|check-makefiles" => \my $check_makefiles, "d|check-doc" => \my $check_doc, "a|check-all" => \my $check_all, - "u|update-makefiles" => \my $update_makefiles, + "u|update-files" => \my $update_files, "h|help" => \my $help ) or die_usage; @@ -464,9 +483,9 @@ sub die_usage { $failure ||= check_comments() if $check_all || $check_comments; $failure ||= check_doc() if $check_doc; # temporarily excluded from --check-all $failure ||= process_makefiles(0) if $check_all || $check_makefiles; -$failure ||= process_makefiles(1) if $update_makefiles; -$failure ||= update_dep() if $update_makefiles; -$failure ||= generate_def() if $update_makefiles; +$failure ||= process_makefiles(1) if $update_files; +$failure ||= update_dep() if $update_files; +$failure ||= generate_def() if $update_files; die_usage unless defined $failure; exit $failure ? 1 : 0; diff --git a/makefile b/makefile index d7619f2b9..e1828da2a 100644 --- a/makefile +++ b/makefile @@ -149,7 +149,7 @@ zipup: clean astyle new_file manual poster docs gpg -b -a ltm-$(VERSION).zip new_file: - perl helper.pl --update-makefiles + perl helper.pl --update-files perlcritic: perlcritic *.pl doc/*.pl diff --git a/testme.sh b/testme.sh index 0e035ce4f..df1b60b84 100755 --- a/testme.sh +++ b/testme.sh @@ -295,8 +295,8 @@ if [[ "$CHECK_FORMAT" == "1" ]] then make astyle _check_git "make astyle" - perl helper.pl --update-makefiles - _check_git "helper.pl --update-makefiles" + perl helper.pl --update-files + _check_git "helper.pl --update-files" perl helper.pl --check-all _check_git "helper.pl --check-all" exit $? diff --git a/tommath.def b/tommath.def index 8258c6516..7f061eda0 100755 --- a/tommath.def +++ b/tommath.def @@ -23,10 +23,10 @@ EXPORTS mp_copy mp_count_bits mp_decr + mp_div mp_div_2 mp_div_2d mp_div_3 - mp_div mp_div_d mp_dr_is_modulus mp_dr_reduce @@ -63,25 +63,25 @@ EXPORTS mp_init_u32 mp_init_u64 mp_invmod + mp_is_square mp_iseven mp_isodd - mp_is_square mp_kronecker mp_lcm mp_lshd - mp_mod_2d mp_mod + mp_mod_2d mp_mod_d mp_montgomery_calc_normalization mp_montgomery_reduce mp_montgomery_setup + mp_mul mp_mul_2 mp_mul_2d - mp_mul mp_mul_d mp_mulmod - mp_neg mp_n_root + mp_neg mp_or mp_prime_fermat mp_prime_frobenius_underwood @@ -93,15 +93,14 @@ EXPORTS mp_prime_strong_lucas_selfridge mp_radix_size mp_rand - mp_rand_digit mp_read_radix mp_read_signed_bin mp_read_unsigned_bin + mp_reduce mp_reduce_2k mp_reduce_2k_l mp_reduce_2k_setup mp_reduce_2k_setup_l - mp_reduce mp_reduce_is_2k mp_reduce_is_2k_l mp_reduce_setup @@ -125,12 +124,12 @@ EXPORTS mp_sub mp_sub_d mp_submod - mp_toradix - mp_toradix_n mp_to_signed_bin mp_to_signed_bin_n mp_to_unsigned_bin mp_to_unsigned_bin_n + mp_toradix + mp_toradix_n mp_unsigned_bin_size mp_xor mp_zero From 8a1ae868ab3bb33f9fec4c2019bbbd8bf781addb Mon Sep 17 00:00:00 2001 From: Daniel Mendler Date: Thu, 6 Jun 2019 18:25:07 +0200 Subject: [PATCH 4/4] tommath.def should be 644 --- tommath.def | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 tommath.def diff --git a/tommath.def b/tommath.def old mode 100755 new mode 100644