Generate precomputed tables as sources in `precomps/'.
[u/mdw/catacomb] / math / Makefile.am
CommitLineData
0f00dc4c
MW
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
27include $(top_srcdir)/vars.am
28
29noinst_LTLIBRARIES = libmath.la
30libmath_la_SOURCES =
31nodist_libmath_la_SOURCES =
32libmath_la_LIBADD =
33
34TEST_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'.
45noinst_LTLIBRARIES += libmpbase.la
46libmath_la_LIBADD += libmpbase.la
47libmpbase_la_LIBADD = $(mLib_LIBS)
48libmpbase_la_SOURCES =
49$(libmpbase_la_OBJECTS): mptypes.h
50
51## Additional buffer I/O functions for mathematical objects.
52pkginclude_HEADERS += buf.h
53libmath_la_SOURCES += buf.c
54
55## Infrastructure for fast exponentiation.
56pkginclude_HEADERS += exp.h
57libmath_la_SOURCES += exp.c
58
59## Main user-visible multiprecision arithmetic.
60pkginclude_HEADERS += mp.h
61libmpbase_la_SOURCES += mp-arith.c
62TESTS += mp-arith.$t
63libmpbase_la_SOURCES += mp-const.c
64libmath_la_SOURCES += mp-exp.c mp-exp.h
65libmath_la_SOURCES += mp-gcd.c
66TESTS += mp-gcd.$t
67libmpbase_la_SOURCES += mp-io.c
68libmath_la_SOURCES += mp-jacobi.c
69TESTS += mp-jacobi.$t
70libmpbase_la_SOURCES += mp-mem.c
71libmpbase_la_SOURCES += mp-misc.c
72libmath_la_SOURCES += mp-modexp.c
73TESTS += mp-modexp.$t
74libmath_la_SOURCES += mp-modsqrt.c
75TESTS += mp-modsqrt.$t
76libmath_la_SOURCES += mp-sqrt.c
77TESTS += mp-sqrt.$t
78libmath_la_SOURCES += mp-test.c
79EXTRA_DIST += t/mp
80
81## Computing Fibonacci numbers.
82pkginclude_HEADERS += mp-fibonacci.h
83libmath_la_SOURCES += mp-fibonacci.c
84TESTS += mp-fibonacci.$t
85
86## Special memory allocation for multiprecision integers.
87pkginclude_HEADERS += mparena.h
88libmpbase_la_SOURCES += mparena.c
89
90## Barrett reduction, an efficient method for modular reduction.
91pkginclude_HEADERS += mpbarrett.h
92libmath_la_SOURCES += mpbarrett.c
93TESTS += mpbarrett.$t
94libmath_la_SOURCES += mpbarrett-exp.c mpbarrett-mexp.c mpbarrett-exp.h
95TESTS += mpbarrett-exp.$t mpbarrett-mexp.$t
96TESTS += mpbarrett.$t
97EXTRA_DIST += t/mpbarrett
98
99## Solving congruences using the Chinese Remainder Theorem.
100pkginclude_HEADERS += mpcrt.h
101libmath_la_SOURCES += mpcrt.c
102TESTS += mpcrt.$t
103EXTRA_DIST += t/mpcrt
104
105## Conversions between machine-native and multiprecision integers.
106pkginclude_HEADERS += mpint.h
107libmath_la_SOURCES += mpint.c
108TESTS += mpint.$t
109EXTRA_DIST += t/mpint
110
111## Table of upper and lower limits of various types of machine integers, as
112## multiprecision integers.
113nodist_archinclude_HEADERS += mplimits.h
114nodist_libmath_la_SOURCES += mplimits.c
115CLEANFILES += mplimits.h mplimits.c
116noinst_PROGRAMS += genlimits
117genlimits_LDADD = libmpbase.la
118mplimits.c: genlimits$e
119 $(AM_V_GEN)./genlimits c >mplimits.c.new && \
120 mv mplimits.c.new mplimits.c
121mplimits.h: genlimits$e
122 $(AM_V_GEN)./genlimits h >mplimits.h.new && \
123 mv mplimits.h.new mplimits.h
124$(genlimits_OBJECTS): mptypes.h
125mplimits.lo: mplimits.h
126
127## Montgomery reduction, a clever method for modular arithmetic.
128pkginclude_HEADERS += mpmont.h
129libmath_la_SOURCES += mpmont.c
130TESTS += mpmont.$t
131libmath_la_SOURCES += mpmont-exp.c mpmont-mexp.c mpmont-exp.h
132TESTS += mpmont-exp.$t mpmont-mexp.$t
133EXTRA_DIST += t/mpmont
134
135## Efficient multiplication of many small numbers.
136pkginclude_HEADERS += mpmul.h
137libmath_la_SOURCES += mpmul.c
138TESTS += mpmul.$t
139
140## Generating random numbers.
141pkginclude_HEADERS += mprand.h
142libmath_la_SOURCES += mprand.c
143
144## Efficient reduction modulo numbers with conveninent binary
145## representations.
146pkginclude_HEADERS += mpreduce.h
147libmath_la_SOURCES += mpreduce.c mpreduce-exp.h
148TESTS += mpreduce.$t
149EXTRA_DIST += t/mpreduce
150
151## Iteratiion over the bianry representation of multiprecision integers.
152pkginclude_HEADERS += mpscan.h
153libmpbase_la_SOURCES += mpscan.c
154
155## Conversion between multiprecision integers and their textual
156## representations.
157pkginclude_HEADERS += mptext.h
158libmpbase_la_SOURCES += mptext.c
159TESTS += mptext.$t
160libmath_la_SOURCES += mptext-dstr.c
161libmath_la_SOURCES += mptext-file.c
162libmath_la_SOURCES += mptext-len.c
163libmpbase_la_SOURCES += mptext-string.c
164EXTRA_DIST += t/mptext
165
166## Basic types used in the representation of multiprecision integers.
167nodist_archinclude_HEADERS += mptypes.h
168BUILT_SOURCES += mptypes.h
169CLEANFILES += mptypes.h
170noinst_PROGRAMS += mptypes
171mptypes.h: mptypes$e
172 $(AM_V_GEN)./mptypes >mptypes.h.new && mv mptypes.h.new mptypes.h
173
174## Low-level multiprecision arithmetic.
175pkginclude_HEADERS += mpx.h bitops.h mpw.h
176libmpbase_la_SOURCES += mpx.c
177TESTS += mpx.$t
178libmpbase_la_SOURCES += karatsuba.h mpx-kmul.c mpx-ksqr.c
179TESTS += mpx-kmul.$t mpx-ksqr.$t
180noinst_PROGRAMS += bittest
181TESTS += bittest
182EXTRA_DIST += t/mpx
183
184## A quick-and-dirty parser, used for parsing descriptions of groups, fields,
185## etc.
186pkginclude_HEADERS += qdparse.h
187libmath_la_SOURCES += qdparse.c
188
189## Pollard's `rho' algorithm for determining discrete logarithms.
190pkginclude_HEADERS += rho.h
191libmath_la_SOURCES += rho.c
192TESTS += 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).
199pkginclude_HEADERS += limlee.h
200libmath_la_SOURCES += limlee.c
201
202## A table of small prime numbers.
e5b61a8d
MW
203pkginclude_HEADERS += $(precomp)/primetab.h
204libmath_la_SOURCES += $(precomp)/primetab.c
205PRECOMPS += $(precomp)/primetab.h $(precomp)/primetab.c
206PRECOMP_PROGS += genprimes
0f00dc4c 207genprimes_LDADD = $(mLib_LIBS)
e5b61a8d
MW
208if !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 \
0f00dc4c 215 -n256 -t"unsigned short" -iprimetab
e5b61a8d 216endif
0f00dc4c
MW
217
218## Filtering candidate prime numbers by checking for small factors
219## efficiently.
220pkginclude_HEADERS += pfilt.h
221libmath_la_SOURCES += pfilt.c
222
223## Generating prime numbers (and other kinds of numbers which need searching
224## for).
225pkginclude_HEADERS += pgen.h
226libmath_la_SOURCES += pgen.c
227libmath_la_SOURCES += pgen-gcd.c
228libmath_la_SOURCES += pgen-simul.c
229libmath_la_SOURCES += pgen-stdev.c
230TESTS += pgen.$t
231EXTRA_DIST += t/pgen
232
233## Finding primitive elements in finite fields.
234pkginclude_HEADERS += prim.h
235libmath_la_SOURCES += prim.c
236
237## Iterating over all prime numbers from a given starting point.
238pkginclude_HEADERS += primeiter.h
239libmath_la_SOURCES += primeiter.c
240TESTS += primeiter.$t
e5b61a8d 241primeiter.lo: $(precomp)/wheel.h
0f00dc4c
MW
242
243## The Miller--Rabin primality test.
244pkginclude_HEADERS += rabin.h
245libmath_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.
249pkginclude_HEADERS += strongprime.h
250libmath_la_SOURCES += strongprime.c
251
252## A `wheel', used by the prime iteration machinery.
e5b61a8d
MW
253pkginclude_HEADERS += $(precomp)/wheel.h
254libmath_la_SOURCES += $(precomp)/wheel.c
255PRECOMPS += $(precomp)/wheel.h $(precomp)/wheel.c
256PRECOMP_PROGS += genwheel
0f00dc4c 257genwheel_LDADD = $(mLib_LIBS)
e5b61a8d
MW
258if !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 \
0f00dc4c 265 -n5 -t"unsigned char" -iwheel
e5b61a8d 266endif
0f00dc4c
MW
267
268###--------------------------------------------------------------------------
269### Binary polynomial arithmetic.
270
271## User-visible binary polynomial arithmetic.
272pkginclude_HEADERS += gf.h
273libmath_la_SOURCES += gf-arith.c
274TESTS += gf-arith.$t
275libmath_la_SOURCES += gf-exp.c gf-exp.h
276libmath_la_SOURCES += gf-gcd.c
277TESTS += gf-gcd.$t
278EXTRA_DIST += t/gf
279
280## Low-level binary polynomial arithmetic.
281pkginclude_HEADERS += gfx.h
282libmath_la_SOURCES += gfx.c
283TESTS += gfx.$t
284libmath_la_SOURCES += gfx-kmul.c
285TESTS += gfx-kmul.$t
e5b61a8d
MW
286libmath_la_SOURCES += gfx-sqr.c $(precomp)/gfx-sqrtab.c
287PRECOMPS += $(precomp)/gfx-sqrtab.c
288PRECOMP_PROGS += gfx-sqr-mktab
289if !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
295endif
0f00dc4c 296TESTS += gfx-sqr.$t
0f00dc4c
MW
297EXTRA_DIST += t/gfx
298
299## Conversions between normal and polynomial basis representations for binary
300## fields.
301pkginclude_HEADERS += gfn.h
302libmath_la_SOURCES += gfn.c
303TESTS += gfn.$t
304EXTRA_DIST += t/gfn
305
306## Efficient reduction modulo sparse polynomials.
307pkginclude_HEADERS += gfreduce.h
308libmath_la_SOURCES += gfreduce.c gfreduce-exp.h
309TESTS += gfreduce.$t
310EXTRA_DIST += t/gfreduce
311
312###--------------------------------------------------------------------------
313### Abstractions for various kinds of algebraic objects.
314
315## Abstract cyclic groups.
316pkginclude_HEADERS += group.h group-guts.h
317libmath_la_SOURCES += group-dstr.c
318libmath_la_SOURCES += group-exp.c group-exp.h
319libmath_la_SOURCES += group-file.c
320libmath_la_SOURCES += group-parse.c
321libmath_la_SOURCES += group-stdops.c
322libmath_la_SOURCES += group-string.c
323libmath_la_SOURCES += g-bin.c
324libmath_la_SOURCES += g-prime.c
325libmath_la_SOURCES += g-ec.c
326EXTRA_DIST += group-test.c
327TESTS += group-test.$t
328EXTRA_DIST += t/group
329
330## Abstract finite fields.
331pkginclude_HEADERS += field.h field-guts.h
332libmath_la_SOURCES += field.c
333libmath_la_SOURCES += field-exp.c field-exp.h
334libmath_la_SOURCES += field-parse.c
335libmath_la_SOURCES += f-binpoly.c
336libmath_la_SOURCES += f-niceprime.c
337libmath_la_SOURCES += f-prime.c
338
339## Table of built-in binary fields.
340pkginclude_HEADERS += bintab.h
341libmath_la_SOURCES += bintab.c
342CLEANFILES += bintab.c
343EXTRA_DIST += bintab.in bin-gentab.awk
344bintab.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.
350pkginclude_HEADERS += ptab.h
351libmath_la_SOURCES += ptab.c
352CLEANFILES += ptab.c
353EXTRA_DIST += ptab.in p-gentab.awk
354ptab.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.
360noinst_PROGRAMS += mpdump
361mpdump_LDADD = libmpbase.la
362$(mpdump_OBJECTS): mptypes.h
363
364###--------------------------------------------------------------------------
365### Elliptic curve arithmetic.
366
367## Basic elliptic curve arithmetic.
368pkginclude_HEADERS += ec.h ec-guts.h
369libmath_la_SOURCES += ec.c
370libmath_la_SOURCES += ec-exp.c ec-exp.h
371libmath_la_SOURCES += ec-info.c
372TESTS += ec-info.$t
373libmath_la_SOURCES += ec-bin.c
374TESTS += ec-bin.$t
375libmath_la_SOURCES += ec-prime.c
376TESTS += ec-prime.$t
377EXTRA_DIST += t/ec
378
379## The standard `raw' encoding (`EC2OSP') of elliptic curve points.
380pkginclude_HEADERS += ec-raw.h
381libmath_la_SOURCES += ec-raw.c
382
383## Assistance for elliptic-curve keys.
384pkginclude_HEADERS += ec-keys.h
385libmath_la_SOURCES += ec-fetch.c
386
387## Test infrastructure for elliptic curves.
388pkginclude_HEADERS += ec-test.h
389libmath_la_SOURCES += ec-test.c
390TESTS += ec-test.$t
391
392## A table of built-in elliptic curves.
393pkginclude_HEADERS += ectab.h
394libmath_la_SOURCES += ectab.c
395CLEANFILES += ectab.c
396EXTRA_DIST += ectab.in ec-gentab.awk
397ectab.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 --------------------------------------------------