dfc5b58e17eb925807e2229343c52c55b8815268
[u/mdw/catacomb] / math / Makefile.am
1 ### -*-makefile-*-
2 ###
3 ### Build script for mathematical infrastructure
4 ###
5 ### (c) 2013 Straylight/Edgeware
6 ###
7
8 ###----- Licensing notice ---------------------------------------------------
9 ###
10 ### This file is part of Catacomb.
11 ###
12 ### Catacomb is free software; you can redistribute it and/or modify
13 ### it under the terms of the GNU Library General Public License as
14 ### published by the Free Software Foundation; either version 2 of the
15 ### License, or (at your option) any later version.
16 ###
17 ### Catacomb is distributed in the hope that it will be useful,
18 ### but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ### MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ### GNU Library General Public License for more details.
21 ###
22 ### You should have received a copy of the GNU Library General Public
23 ### License along with Catacomb; if not, write to the Free
24 ### Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
25 ### MA 02111-1307, USA.
26
27 include $(top_srcdir)/vars.am
28
29 noinst_LTLIBRARIES = libmath.la
30 libmath_la_SOURCES =
31 nodist_libmath_la_SOURCES =
32 libmath_la_LIBADD =
33
34 TEST_LIBS = libmath.la
35
36 ###--------------------------------------------------------------------------
37 ### Main multiprecision integer library.
38
39 ## This library is unfortunately intertwined with some of the code generation
40 ## programs, so we must be rather careful. The important bits of the maths
41 ## library needed by these programs is separated out into `libmpbase'. There
42 ## is work going on to fix this unpleasant situation by generating the
43 ## relevant files from Python scripts rather than C programs, using
44 ## information gathered by `configure'.
45 noinst_LTLIBRARIES += libmpbase.la
46 libmath_la_LIBADD += libmpbase.la
47 libmpbase_la_LIBADD = $(mLib_LIBS)
48 libmpbase_la_SOURCES =
49 $(libmpbase_la_OBJECTS): mptypes.h
50
51 ## Additional buffer I/O functions for mathematical objects.
52 pkginclude_HEADERS += buf.h
53 libmath_la_SOURCES += buf.c
54
55 ## Infrastructure for fast exponentiation.
56 pkginclude_HEADERS += exp.h
57 libmath_la_SOURCES += exp.c
58
59 ## Main user-visible multiprecision arithmetic.
60 pkginclude_HEADERS += mp.h
61 libmpbase_la_SOURCES += mp-arith.c
62 TESTS += mp-arith.$t
63 libmpbase_la_SOURCES += mp-const.c
64 libmath_la_SOURCES += mp-exp.c mp-exp.h
65 libmath_la_SOURCES += mp-gcd.c
66 TESTS += mp-gcd.$t
67 libmpbase_la_SOURCES += mp-io.c
68 libmath_la_SOURCES += mp-jacobi.c
69 TESTS += mp-jacobi.$t
70 libmpbase_la_SOURCES += mp-mem.c
71 libmpbase_la_SOURCES += mp-misc.c
72 libmath_la_SOURCES += mp-modexp.c
73 TESTS += mp-modexp.$t
74 libmath_la_SOURCES += mp-modsqrt.c
75 TESTS += mp-modsqrt.$t
76 libmath_la_SOURCES += mp-sqrt.c
77 TESTS += mp-sqrt.$t
78 libmath_la_SOURCES += mp-test.c
79 EXTRA_DIST += t/mp
80
81 ## Computing Fibonacci numbers.
82 pkginclude_HEADERS += mp-fibonacci.h
83 libmath_la_SOURCES += mp-fibonacci.c
84 TESTS += mp-fibonacci.$t
85
86 ## Special memory allocation for multiprecision integers.
87 pkginclude_HEADERS += mparena.h
88 libmpbase_la_SOURCES += mparena.c
89
90 ## Barrett reduction, an efficient method for modular reduction.
91 pkginclude_HEADERS += mpbarrett.h
92 libmath_la_SOURCES += mpbarrett.c
93 TESTS += mpbarrett.$t
94 libmath_la_SOURCES += mpbarrett-exp.c mpbarrett-mexp.c mpbarrett-exp.h
95 TESTS += mpbarrett-exp.$t mpbarrett-mexp.$t
96 TESTS += mpbarrett.$t
97 EXTRA_DIST += t/mpbarrett
98
99 ## Solving congruences using the Chinese Remainder Theorem.
100 pkginclude_HEADERS += mpcrt.h
101 libmath_la_SOURCES += mpcrt.c
102 TESTS += mpcrt.$t
103 EXTRA_DIST += t/mpcrt
104
105 ## Conversions between machine-native and multiprecision integers.
106 pkginclude_HEADERS += mpint.h
107 libmath_la_SOURCES += mpint.c
108 TESTS += mpint.$t
109 EXTRA_DIST += t/mpint
110
111 ## Table of upper and lower limits of various types of machine integers, as
112 ## multiprecision integers.
113 nodist_archinclude_HEADERS += mplimits.h
114 nodist_libmath_la_SOURCES += mplimits.c
115 CLEANFILES += mplimits.h mplimits.c
116 noinst_PROGRAMS += genlimits
117 genlimits_LDADD = libmpbase.la
118 mplimits.c: genlimits$e
119 $(AM_V_GEN)./genlimits c >mplimits.c.new && \
120 mv mplimits.c.new mplimits.c
121 mplimits.h: genlimits$e
122 $(AM_V_GEN)./genlimits h >mplimits.h.new && \
123 mv mplimits.h.new mplimits.h
124 $(genlimits_OBJECTS): mptypes.h
125 mplimits.lo: mplimits.h
126
127 ## Montgomery reduction, a clever method for modular arithmetic.
128 pkginclude_HEADERS += mpmont.h
129 libmath_la_SOURCES += mpmont.c
130 TESTS += mpmont.$t
131 libmath_la_SOURCES += mpmont-exp.c mpmont-mexp.c mpmont-exp.h
132 TESTS += mpmont-exp.$t mpmont-mexp.$t
133 EXTRA_DIST += t/mpmont
134
135 ## Efficient multiplication of many small numbers.
136 pkginclude_HEADERS += mpmul.h
137 libmath_la_SOURCES += mpmul.c
138 TESTS += mpmul.$t
139
140 ## Generating random numbers.
141 pkginclude_HEADERS += mprand.h
142 libmath_la_SOURCES += mprand.c
143
144 ## Efficient reduction modulo numbers with conveninent binary
145 ## representations.
146 pkginclude_HEADERS += mpreduce.h
147 libmath_la_SOURCES += mpreduce.c mpreduce-exp.h
148 TESTS += mpreduce.$t
149 EXTRA_DIST += t/mpreduce
150
151 ## Iteratiion over the bianry representation of multiprecision integers.
152 pkginclude_HEADERS += mpscan.h
153 libmpbase_la_SOURCES += mpscan.c
154
155 ## Conversion between multiprecision integers and their textual
156 ## representations.
157 pkginclude_HEADERS += mptext.h
158 libmpbase_la_SOURCES += mptext.c
159 TESTS += mptext.$t
160 libmath_la_SOURCES += mptext-dstr.c
161 libmath_la_SOURCES += mptext-file.c
162 libmath_la_SOURCES += mptext-len.c
163 libmpbase_la_SOURCES += mptext-string.c
164 EXTRA_DIST += t/mptext
165
166 ## Basic types used in the representation of multiprecision integers.
167 nodist_archinclude_HEADERS += mptypes.h
168 BUILT_SOURCES += mptypes.h
169 CLEANFILES += mptypes.h
170 noinst_PROGRAMS += mptypes
171 mptypes.h: mptypes$e
172 $(AM_V_GEN)./mptypes >mptypes.h.new && mv mptypes.h.new mptypes.h
173
174 ## Low-level multiprecision arithmetic.
175 pkginclude_HEADERS += mpx.h bitops.h mpw.h
176 libmpbase_la_SOURCES += mpx.c
177 TESTS += mpx.$t
178 libmpbase_la_SOURCES += karatsuba.h mpx-kmul.c mpx-ksqr.c
179 TESTS += mpx-kmul.$t mpx-ksqr.$t
180 noinst_PROGRAMS += bittest
181 TESTS += bittest
182 EXTRA_DIST += t/mpx
183
184 ## A quick-and-dirty parser, used for parsing descriptions of groups, fields,
185 ## etc.
186 pkginclude_HEADERS += qdparse.h
187 libmath_la_SOURCES += qdparse.c
188
189 ## Pollard's `rho' algorithm for determining discrete logarithms.
190 pkginclude_HEADERS += rho.h
191 libmath_la_SOURCES += rho.c
192 TESTS += rho.$t
193
194 ###--------------------------------------------------------------------------
195 ### Prime number checking, searching, and related jobs.
196
197 ## Generating Lim--Lee groups, i.e., unit groups of finite fields without
198 ## small subgroups (except for the obvious ones).
199 pkginclude_HEADERS += limlee.h
200 libmath_la_SOURCES += limlee.c
201
202 ## A table of small prime numbers.
203 pkginclude_HEADERS += $(precomp)/primetab.h
204 libmath_la_SOURCES += $(precomp)/primetab.c
205 PRECOMPS += $(precomp)/primetab.h $(precomp)/primetab.c
206 PRECOMP_PROGS += genprimes
207 genprimes_LDADD = $(mLib_LIBS)
208 if !CROSS_COMPILING
209 $(precomp)/primetab.h: $(precomp)/primetab.c
210 $(precomp)/primetab.c:
211 $(AM_V_at)$(MKDIR_P) $(precomp)
212 $(AM_V_at)$(MAKE) genprimes$e
213 $(AM_V_GEN)./genprimes -sCATACOMB_PRIMETAB_H \
214 -h$(precomp)/primetab.h -c$(precomp)/primetab.c \
215 -n256 -t"unsigned short" -iprimetab
216 endif
217
218 ## Filtering candidate prime numbers by checking for small factors
219 ## efficiently.
220 pkginclude_HEADERS += pfilt.h
221 libmath_la_SOURCES += pfilt.c
222
223 ## Generating prime numbers (and other kinds of numbers which need searching
224 ## for).
225 pkginclude_HEADERS += pgen.h
226 libmath_la_SOURCES += pgen.c
227 libmath_la_SOURCES += pgen-gcd.c
228 libmath_la_SOURCES += pgen-simul.c
229 libmath_la_SOURCES += pgen-stdev.c
230 TESTS += pgen.$t
231 EXTRA_DIST += t/pgen
232
233 ## Finding primitive elements in finite fields.
234 pkginclude_HEADERS += prim.h
235 libmath_la_SOURCES += prim.c
236
237 ## Iterating over all prime numbers from a given starting point.
238 pkginclude_HEADERS += primeiter.h
239 libmath_la_SOURCES += primeiter.c
240 TESTS += primeiter.$t
241 primeiter.lo: $(precomp)/wheel.h
242
243 ## The Miller--Rabin primality test.
244 pkginclude_HEADERS += rabin.h
245 libmath_la_SOURCES += rabin.c
246
247 ## Finding `strong' primes, using Gordon's algorithm. Once upon a time,
248 ## products of these kinds of numbers were harder to factor.
249 pkginclude_HEADERS += strongprime.h
250 libmath_la_SOURCES += strongprime.c
251
252 ## A `wheel', used by the prime iteration machinery.
253 pkginclude_HEADERS += $(precomp)/wheel.h
254 libmath_la_SOURCES += $(precomp)/wheel.c
255 PRECOMPS += $(precomp)/wheel.h $(precomp)/wheel.c
256 PRECOMP_PROGS += genwheel
257 genwheel_LDADD = $(mLib_LIBS)
258 if !CROSS_COMPILING
259 $(precomp)/wheel.h: $(precomp)/wheel.c
260 $(precomp)/wheel.c:
261 $(AM_V_at)$(MKDIR_P) $(precomp)
262 $(AM_V_at)$(MAKE) genwheel$e
263 $(AM_V_GEN)./genwheel -sCATACOMB_WHEEL_H \
264 -h$(precomp)/wheel.h -c$(precomp)/wheel.c \
265 -n5 -t"unsigned char" -iwheel
266 endif
267
268 ###--------------------------------------------------------------------------
269 ### Binary polynomial arithmetic.
270
271 ## User-visible binary polynomial arithmetic.
272 pkginclude_HEADERS += gf.h
273 libmath_la_SOURCES += gf-arith.c
274 TESTS += gf-arith.$t
275 libmath_la_SOURCES += gf-exp.c gf-exp.h
276 libmath_la_SOURCES += gf-gcd.c
277 TESTS += gf-gcd.$t
278 EXTRA_DIST += t/gf
279
280 ## Low-level binary polynomial arithmetic.
281 pkginclude_HEADERS += gfx.h
282 libmath_la_SOURCES += gfx.c
283 TESTS += gfx.$t
284 libmath_la_SOURCES += gfx-kmul.c
285 TESTS += gfx-kmul.$t
286 libmath_la_SOURCES += gfx-sqr.c $(precomp)/gfx-sqrtab.c
287 PRECOMPS += $(precomp)/gfx-sqrtab.c
288 PRECOMP_PROGS += gfx-sqr-mktab
289 if !CROSS_COMPILING
290 $(precomp)/gfx-sqrtab.c:
291 $(AM_V_at)$(MKDIR_P) $(precomp)
292 $(AM_V_at)$(MAKE) gfx-sqr-mktab$e
293 $(AM_V_GEN)./gfx-sqr-mktab >$(precomp)/gfx-sqrtab.c.new && \
294 mv $(precomp)/gfx-sqrtab.c.new $(precomp)/gfx-sqrtab.c
295 endif
296 TESTS += gfx-sqr.$t
297 EXTRA_DIST += t/gfx
298
299 ## Conversions between normal and polynomial basis representations for binary
300 ## fields.
301 pkginclude_HEADERS += gfn.h
302 libmath_la_SOURCES += gfn.c
303 TESTS += gfn.$t
304 EXTRA_DIST += t/gfn
305
306 ## Efficient reduction modulo sparse polynomials.
307 pkginclude_HEADERS += gfreduce.h
308 libmath_la_SOURCES += gfreduce.c gfreduce-exp.h
309 TESTS += gfreduce.$t
310 EXTRA_DIST += t/gfreduce
311
312 ###--------------------------------------------------------------------------
313 ### Abstractions for various kinds of algebraic objects.
314
315 ## Abstract cyclic groups.
316 pkginclude_HEADERS += group.h group-guts.h
317 libmath_la_SOURCES += group-dstr.c
318 libmath_la_SOURCES += group-exp.c group-exp.h
319 libmath_la_SOURCES += group-file.c
320 libmath_la_SOURCES += group-parse.c
321 libmath_la_SOURCES += group-stdops.c
322 libmath_la_SOURCES += group-string.c
323 libmath_la_SOURCES += g-bin.c
324 libmath_la_SOURCES += g-prime.c
325 libmath_la_SOURCES += g-ec.c
326 EXTRA_DIST += group-test.c
327 TESTS += group-test.$t
328 EXTRA_DIST += t/group
329
330 ## Abstract finite fields.
331 pkginclude_HEADERS += field.h field-guts.h
332 libmath_la_SOURCES += field.c
333 libmath_la_SOURCES += field-exp.c field-exp.h
334 libmath_la_SOURCES += field-parse.c
335 libmath_la_SOURCES += f-binpoly.c
336 libmath_la_SOURCES += f-niceprime.c
337 libmath_la_SOURCES += f-prime.c
338
339 ## Table of built-in binary fields.
340 pkginclude_HEADERS += bintab.h
341 libmath_la_SOURCES += bintab.c
342 CLEANFILES += bintab.c
343 EXTRA_DIST += bintab.in bin-gentab.awk
344 bintab.c: bintab.in bin-gentab.awk mpdump$e
345 $(AM_V_GEN)awk -f $(srcdir)/bin-gentab.awk \
346 <$(srcdir)/bintab.in >bintab.c.new && \
347 mv bintab.c.new bintab.c
348
349 ## Table of built-in prime fields.
350 pkginclude_HEADERS += ptab.h
351 libmath_la_SOURCES += ptab.c
352 CLEANFILES += ptab.c
353 EXTRA_DIST += ptab.in p-gentab.awk
354 ptab.c: ptab.in p-gentab.awk mpdump$e
355 $(AM_V_GEN)awk -f $(srcdir)/p-gentab.awk \
356 <$(srcdir)/ptab.in >ptab.c.new && \
357 mv ptab.c.new ptab.c
358
359 ## A utility for building multiprecision integer constants.
360 noinst_PROGRAMS += mpdump
361 mpdump_LDADD = libmpbase.la
362 $(mpdump_OBJECTS): mptypes.h
363
364 ###--------------------------------------------------------------------------
365 ### Elliptic curve arithmetic.
366
367 ## Basic elliptic curve arithmetic.
368 pkginclude_HEADERS += ec.h ec-guts.h
369 libmath_la_SOURCES += ec.c
370 libmath_la_SOURCES += ec-exp.c ec-exp.h
371 libmath_la_SOURCES += ec-info.c
372 TESTS += ec-info.$t
373 libmath_la_SOURCES += ec-bin.c
374 TESTS += ec-bin.$t
375 libmath_la_SOURCES += ec-prime.c
376 TESTS += ec-prime.$t
377 EXTRA_DIST += t/ec
378
379 ## The standard `raw' encoding (`EC2OSP') of elliptic curve points.
380 pkginclude_HEADERS += ec-raw.h
381 libmath_la_SOURCES += ec-raw.c
382
383 ## Assistance for elliptic-curve keys.
384 pkginclude_HEADERS += ec-keys.h
385 libmath_la_SOURCES += ec-fetch.c
386
387 ## Test infrastructure for elliptic curves.
388 pkginclude_HEADERS += ec-test.h
389 libmath_la_SOURCES += ec-test.c
390 TESTS += ec-test.$t
391
392 ## A table of built-in elliptic curves.
393 pkginclude_HEADERS += ectab.h
394 libmath_la_SOURCES += ectab.c
395 CLEANFILES += ectab.c
396 EXTRA_DIST += ectab.in ec-gentab.awk
397 ectab.c: ectab.in ec-gentab.awk mpdump$e
398 $(AM_V_GEN)awk -f $(srcdir)/ec-gentab.awk \
399 <$(srcdir)/ectab.in >ectab.c.new && \
400 mv ectab.c.new ectab.c
401
402 ###----- That's all, folks --------------------------------------------------