perftest: Document the `-q' option for disabling checking.
[u/mdw/catacomb] / gf.h
1 /* -*-c-*-
2 *
3 * $Id$
4 *
5 * Arithmetic on binary polynomials
6 *
7 * (c) 2004 Straylight/Edgeware
8 */
9
10 /*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of Catacomb.
13 *
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
18 *
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
23 *
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
27 * MA 02111-1307, USA.
28 */
29
30 #ifndef CATACOMB_GF_H
31 #define CATACOMB_GF_H
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /*----- Header files ------------------------------------------------------*/
38
39 #ifndef CATACOMB_MP_H
40 # include "mp.h"
41 #endif
42
43 #ifndef CATACOMB_GFX_H
44 # include "gfx.h"
45 #endif
46
47 /*----- Functions provided ------------------------------------------------*/
48
49 /* --- @gf_add@ --- *
50 *
51 * Arguments: @mp *d@ = destination
52 * @mp *a, *b@ = sources
53 *
54 * Returns: Result, @a@ added to @b@.
55 */
56
57 extern mp *gf_add(mp */*d*/, mp */*a*/, mp */*b*/);
58 #define gf_sub gf_add
59
60 /* --- @gf_mul@ --- *
61 *
62 * Arguments: @mp *d@ = destination
63 * @mp *a, *b@ = sources
64 *
65 * Returns: Result, @a@ multiplied by @b@.
66 */
67
68 extern mp *gf_mul(mp */*d*/, mp */*a*/, mp */*b*/);
69
70 /* --- @gf_sqr@ --- *
71 *
72 * Arguments: @mp *d@ = destination
73 * @mp *a@ = source
74 *
75 * Returns: Result, @a@ squared.
76 */
77
78 extern mp *gf_sqr(mp */*d*/, mp */*a*/);
79
80 /* --- @gf_div@ --- *
81 *
82 * Arguments: @mp **qq, **rr@ = destination, quotient and remainder
83 * @mp *a, *b@ = sources
84 *
85 * Use: Calculates the quotient and remainder when @a@ is divided by
86 * @b@. The destinations @*qq@ and @*rr@ must be distinct.
87 * Either of @qq@ or @rr@ may be null to indicate that the
88 * result is irrelevant. (Discarding both results is silly.)
89 * There is a performance advantage if @a == *rr@.
90 */
91
92 extern void gf_div(mp **/*qq*/, mp **/*rr*/, mp */*a*/, mp */*b*/);
93
94 /* --- @gf_exp@ --- *
95 *
96 * Arguments: @mp *d@ = fake destination
97 * @mp *a@ = base
98 * @mp *e@ = exponent
99 *
100 * Returns: Result, %$a^e$%.
101 */
102
103 extern mp *gf_exp(mp */*d*/, mp */*a*/, mp */*e*/);
104
105 /* --- @gf_irreduciblep@ --- *
106 *
107 * Arguments: @mp *f@ = a polynomial
108 *
109 * Returns: Nonzero if the polynomial is irreducible; otherwise zero.
110 */
111
112 extern int gf_irreduciblep(mp */*f*/);
113
114 /* --- @gf_gcd@ --- *
115 *
116 * Arguments: @mp **gcd, **xx, **yy@ = where to write the results
117 * @mp *a, *b@ = sources (must be nonzero)
118 *
119 *
120 * Returns: ---
121 *
122 * Use: Calculates @gcd(a, b)@, and two numbers @x@ and @y@ such that
123 * @ax + by = gcd(a, b)@. This is useful for computing modular
124 * inverses.
125 */
126
127 extern void gf_gcd(mp **/*gcd*/, mp **/*xx*/, mp **/*yy*/,
128 mp */*a*/, mp */*b*/);
129
130 /* -- @gf_modinv@ --- *
131 *
132 * Arguments: @mp *d@ = destination
133 * @mp *x@ = argument
134 * @mp *p@ = modulus
135 *
136 * Returns: The inverse %$x^{-1} \bmod p$%.
137 *
138 * Use: Computes a modular inverse, the catch being that the
139 * arguments and results are binary polynomials. An assertion
140 * fails if %$p$% has no inverse.
141 */
142
143 extern mp *gf_modinv(mp */*d*/, mp */*x*/, mp */*p*/);
144
145 /*----- That's all, folks -------------------------------------------------*/
146
147 #ifdef __cplusplus
148 }
149 #endif
150
151 #endif