Skip to content

Commit 1c57d84

Browse files
committed
Add libtommath 1.3.0
1 parent 1be3202 commit 1c57d84

File tree

8 files changed

+760
-0
lines changed

8 files changed

+760
-0
lines changed

ci_config.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -778,6 +778,13 @@
778778
"windows": false
779779
}
780780
},
781+
"libtommath": {
782+
"_comment": "MSVC build fails because it doesn't optimize away unreachable code leaving undefined symbols.",
783+
"build_options": [
784+
"libtommath:tests=true",
785+
"libtommath:buildtype=release"
786+
]
787+
},
781788
"libupnp": {
782789
"_comment": "Requires some special pthread library",
783790
"build_on": {

releases.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2459,6 +2459,14 @@
24592459
"1.17-1"
24602460
]
24612461
},
2462+
"libtommath": {
2463+
"dependency_names": [
2464+
"libtommath"
2465+
],
2466+
"versions": [
2467+
"1.3.0-1"
2468+
]
2469+
},
24622470
"libunibreak": {
24632471
"dependency_names": [
24642472
"libunibreak"

subprojects/libtommath.wrap

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
[wrap-file]
2+
directory = libtommath-1.3.0
3+
source_url = https://github.com/libtom/libtommath/releases/download/v1.3.0/ltm-1.3.0.tar.xz
4+
source_filename = ltm-1.3.0.tar.xz
5+
source_hash = 296272d93435991308eb73607600c034b558807a07e829e751142e65ccfa9d08
6+
patch_directory = libtommath
7+
8+
[provide]
9+
dependency_names = libtommath
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
#!/usr/bin/env python3
2+
"""Build the libtommath PDF manual from LaTeX sources
3+
4+
This script is called by meson with the following environment variables set:
5+
LATEX, PDFLATEX, MAKEINDEX
6+
7+
Only requires standard Python library - no external tools beyond LaTeX itself.
8+
"""
9+
10+
import os
11+
import sys
12+
import shutil
13+
import subprocess
14+
import re
15+
from datetime import datetime, timezone
16+
17+
18+
def main():
19+
if len(sys.argv) != 4:
20+
print("Usage: build-manual.py INPUT OUTDIR OUTPUT", file=sys.stderr)
21+
sys.exit(1)
22+
23+
input_file = sys.argv[1]
24+
outdir = sys.argv[2]
25+
output_file = sys.argv[3]
26+
27+
# Get tools from environment
28+
latex = os.environ.get('LATEX', 'latex')
29+
pdflatex = os.environ.get('PDFLATEX', 'pdflatex')
30+
makeindex = os.environ.get('MAKEINDEX', 'makeindex')
31+
32+
# Convert paths to absolute before changing directories
33+
input_file = os.path.abspath(input_file)
34+
output_file = os.path.abspath(output_file)
35+
36+
# Change to output directory
37+
os.chdir(outdir)
38+
39+
# Copy input to bn.tex
40+
shutil.copy2(input_file, 'bn.tex')
41+
42+
# Create backup with same timestamp
43+
shutil.copy2('bn.tex', 'bn.bak')
44+
45+
# Get modification time of bn.tex and format for PDF
46+
mtime = os.stat('bn.tex').st_mtime
47+
dt = datetime.fromtimestamp(mtime, tz=timezone.utc)
48+
49+
# Format as PDF date string: D:YYYYMMDDHHmmSS+HH'mm'
50+
# For UTC, timezone offset is +00'00'
51+
date_str = dt.strftime("D:%Y%m%d%H%M%S+00'00'")
52+
53+
# Write deterministic PDF header
54+
with open('bn-deterministic.tex', 'w') as f:
55+
f.write(f"\\def\\fixedpdfdate{{{date_str}}}\n")
56+
f.write("\\pdfinfo{\n")
57+
f.write(" /CreationDate (\\fixedpdfdate)\n")
58+
f.write(" /ModDate (\\fixedpdfdate)\n")
59+
f.write("}\n")
60+
61+
# Append original content
62+
with open('bn.tex', 'r') as orig:
63+
f.write(orig.read())
64+
65+
# Replace bn.tex with deterministic version
66+
shutil.move('bn-deterministic.tex', 'bn.tex')
67+
68+
# Restore original timestamp
69+
shutil.copystat('bn.bak', 'bn.tex')
70+
71+
# Build the manual
72+
with open('bn.ind', 'w') as f:
73+
f.write('hello\n')
74+
75+
subprocess.run([latex, 'bn'], stdout=subprocess.DEVNULL, check=True)
76+
subprocess.run([latex, 'bn'], stdout=subprocess.DEVNULL, check=True)
77+
subprocess.run([makeindex, 'bn'], check=True)
78+
subprocess.run([latex, 'bn'], stdout=subprocess.DEVNULL, check=True)
79+
subprocess.run([pdflatex, 'bn'], stdout=subprocess.DEVNULL, check=True)
80+
81+
# Make PDF ID deterministic using Python
82+
with open('bn.pdf', 'rb') as f:
83+
pdf_data = f.read()
84+
85+
# Replace /ID [<...> <...>] with /ID [<0> <0>]
86+
pdf_data = re.sub(rb'^/ID \[.*\]$', rb'/ID [<0> <0>]', pdf_data, flags=re.MULTILINE)
87+
88+
with open('bn.pdf', 'wb') as f:
89+
f.write(pdf_data)
90+
91+
# Rename to desired output name
92+
shutil.move('bn.pdf', output_file)
93+
94+
# Cleanup
95+
shutil.move('bn.bak', 'bn.tex')
96+
97+
cleanup_files = [
98+
'bn.aux', 'bn.dvi', 'bn.log', 'bn.idx',
99+
'bn.lof', 'bn.out', 'bn.toc', 'bn.ilg',
100+
'bn.ind', 'bn.tex'
101+
]
102+
for f in cleanup_files:
103+
try:
104+
os.remove(f)
105+
except FileNotFoundError:
106+
pass
107+
108+
109+
if __name__ == '__main__':
110+
main()
Lines changed: 219 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,219 @@
1+
LIBRARY tommath-1
2+
EXPORTS
3+
fast_mp_invmod
4+
fast_mp_montgomery_reduce
5+
fast_s_mp_mul_digs
6+
fast_s_mp_mul_high_digs
7+
fast_s_mp_sqr
8+
mp_2expt
9+
mp_abs
10+
mp_add
11+
mp_add_d
12+
mp_addmod
13+
mp_and
14+
mp_balance_mul
15+
mp_clamp
16+
mp_clear
17+
mp_clear_multi
18+
mp_cmp
19+
mp_cmp_d
20+
mp_cmp_mag
21+
mp_cnt_lsb
22+
mp_complement
23+
mp_copy
24+
mp_count_bits
25+
mp_decr
26+
mp_div
27+
mp_div_2
28+
mp_div_2d
29+
mp_div_3
30+
mp_div_d
31+
mp_dr_is_modulus
32+
mp_dr_reduce
33+
mp_dr_setup
34+
mp_error_to_string
35+
mp_exch
36+
mp_export
37+
mp_expt_d
38+
mp_expt_d_ex
39+
mp_exptmod
40+
mp_exptmod_fast
41+
mp_expt_n
42+
mp_expt_u32
43+
mp_exteuclid
44+
mp_fread
45+
mp_from_sbin
46+
mp_from_ubin
47+
mp_fwrite
48+
mp_gcd
49+
mp_get_bit
50+
mp_get_double
51+
mp_get_i32
52+
mp_get_i64
53+
mp_get_int
54+
mp_get_l
55+
mp_get_ll
56+
mp_get_long
57+
mp_get_long_long
58+
mp_get_mag_u32
59+
mp_get_mag_u64
60+
mp_get_mag_ul
61+
mp_get_mag_ull
62+
mp_grow
63+
mp_import
64+
mp_incr
65+
mp_init
66+
mp_init_copy
67+
mp_init_i32
68+
mp_init_i64
69+
mp_init_l
70+
mp_init_ll
71+
mp_init_multi
72+
mp_init_set
73+
mp_init_set_int
74+
mp_init_size
75+
mp_init_u32
76+
mp_init_u64
77+
mp_init_ul
78+
mp_init_ull
79+
mp_invmod
80+
mp_invmod_slow
81+
mp_iseven
82+
mp_isodd
83+
mp_is_square
84+
mp_jacobi
85+
mp_karatsuba_mul
86+
mp_karatsuba_sqr
87+
mp_kronecker
88+
mp_lcm
89+
mp_log_n
90+
mp_log_u32
91+
mp_lshd
92+
mp_mod
93+
mp_mod_2d
94+
mp_mod_d
95+
mp_montgomery_calc_normalization
96+
mp_montgomery_reduce
97+
mp_montgomery_setup
98+
mp_mul
99+
mp_mul_2
100+
mp_mul_2d
101+
mp_mul_d
102+
mp_mulmod
103+
mp_neg
104+
mp_n_root
105+
mp_n_root_ex
106+
mp_or
107+
mp_pack
108+
mp_pack_count
109+
mp_prime_fermat
110+
mp_prime_frobenius_underwood
111+
mp_prime_is_divisible
112+
mp_prime_is_prime
113+
mp_prime_miller_rabin
114+
mp_prime_next_prime
115+
mp_prime_rabin_miller_trials
116+
mp_prime_rand
117+
mp_prime_random_ex
118+
mp_prime_strong_lucas_selfridge
119+
mp_radix_size
120+
mp_rand
121+
mp_rand_digit
122+
mp_rand_source
123+
mp_read_radix
124+
mp_read_signed_bin
125+
mp_read_unsigned_bin
126+
mp_reduce
127+
mp_reduce_2k
128+
mp_reduce_2k_l
129+
mp_reduce_2k_setup
130+
mp_reduce_2k_setup_l
131+
mp_reduce_is_2k
132+
mp_reduce_is_2k_l
133+
mp_reduce_setup
134+
mp_root_n
135+
mp_root_u32
136+
mp_rshd
137+
mp_sbin_size
138+
mp_set
139+
mp_set_double
140+
mp_set_i32
141+
mp_set_i64
142+
mp_set_int
143+
mp_set_l
144+
mp_set_ll
145+
mp_set_long
146+
mp_set_long_long
147+
mp_set_u32
148+
mp_set_u64
149+
mp_set_ul
150+
mp_set_ull
151+
mp_shrink
152+
mp_signed_bin_size
153+
mp_signed_rsh
154+
mp_sqr
155+
mp_sqrmod
156+
mp_sqrt
157+
mp_sqrtmod_prime
158+
mp_sub
159+
mp_sub_d
160+
mp_submod
161+
mp_tc_and
162+
mp_tc_div_2d
163+
mp_tc_or
164+
mp_tc_xor
165+
mp_toom_mul
166+
mp_toom_sqr
167+
mp_to_radix
168+
mp_toradix
169+
mp_toradix_n
170+
mp_to_sbin
171+
mp_to_signed_bin
172+
mp_to_signed_bin_n
173+
mp_to_ubin
174+
mp_to_unsigned_bin
175+
mp_to_unsigned_bin_n
176+
mp_ubin_size
177+
mp_unpack
178+
mp_unsigned_bin_size
179+
mp_xor
180+
mp_zero
181+
s_mp_add
182+
s_mp_balance_mul
183+
s_mp_div_3
184+
s_mp_exptmod
185+
s_mp_exptmod_fast
186+
s_mp_get_bit
187+
s_mp_invmod_fast
188+
s_mp_invmod_slow
189+
s_mp_karatsuba_mul
190+
s_mp_karatsuba_sqr
191+
s_mp_log
192+
s_mp_log_2expt
193+
s_mp_log_d
194+
s_mp_montgomery_reduce_fast
195+
s_mp_mul_digs
196+
s_mp_mul_digs_fast
197+
s_mp_mul_high_digs
198+
s_mp_mul_high_digs_fast
199+
s_mp_prime_is_divisible
200+
s_mp_prime_random_ex
201+
s_mp_rand_jenkins
202+
s_mp_rand_jenkins_init
203+
s_mp_rand_platform
204+
s_mp_reverse
205+
s_mp_sqr
206+
s_mp_sqr_fast
207+
s_mp_sub
208+
s_mp_toom_mul
209+
s_mp_toom_sqr
210+
KARATSUBA_MUL_CUTOFF DATA
211+
KARATSUBA_SQR_CUTOFF DATA
212+
TOOM_MUL_CUTOFF DATA
213+
TOOM_SQR_CUTOFF DATA
214+
ltm_prime_tab DATA
215+
mp_s_rmap DATA
216+
mp_s_rmap_reverse DATA
217+
mp_s_rmap_reverse_sz DATA
218+
s_mp_prime_tab DATA
219+
s_mp_rand_source DATA

0 commit comments

Comments
 (0)