fba801c885a5e50e51190fc028f387e11377d3a8
[u/mdw/catacomb] / gf.h
1 /* -*-c-*-
2 *
3 * $Id: gf.h,v 1.3 2004/03/27 17:54:11 mdw Exp $
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 /*----- Revision history --------------------------------------------------*
31 *
32 * $Log: gf.h,v $
33 * Revision 1.3 2004/03/27 17:54:11 mdw
34 * Standard curves and curve checking.
35 *
36 * Revision 1.2 2004/03/21 22:52:06 mdw
37 * Merge and close elliptic curve branch.
38 *
39 * Revision 1.1.2.1 2004/03/21 22:39:46 mdw
40 * Elliptic curves on binary fields work.
41 *
42 */
43
44 #ifndef CATACOMB_GF_H
45 #define CATACOMB_GF_H
46
47 #ifdef __cplusplus
48 extern "C" {
49 #endif
50
51 /*----- Header files ------------------------------------------------------*/
52
53 #ifndef CATACOMB_MP_H
54 # include "mp.h"
55 #endif
56
57 #ifndef CATACOMB_GFX_H
58 # include "gfx.h"
59 #endif
60
61 /*----- Functions provided ------------------------------------------------*/
62
63 /* --- @gf_add@ --- *
64 *
65 * Arguments: @mp *d@ = destination
66 * @mp *a, *b@ = sources
67 *
68 * Returns: Result, @a@ added to @b@.
69 */
70
71 extern mp *gf_add(mp */*d*/, mp */*a*/, mp */*b*/);
72 #define gf_sub gf_add
73
74 /* --- @gf_mul@ --- *
75 *
76 * Arguments: @mp *d@ = destination
77 * @mp *a, *b@ = sources
78 *
79 * Returns: Result, @a@ multiplied by @b@.
80 */
81
82 extern mp *gf_mul(mp */*d*/, mp */*a*/, mp */*b*/);
83
84 /* --- @gf_sqr@ --- *
85 *
86 * Arguments: @mp *d@ = destination
87 * @mp *a@ = source
88 *
89 * Returns: Result, @a@ squared.
90 */
91
92 extern mp *gf_sqr(mp */*d*/, mp */*a*/);
93
94 /* --- @gf_div@ --- *
95 *
96 * Arguments: @mp **qq, **rr@ = destination, quotient and remainder
97 * @mp *a, *b@ = sources
98 *
99 * Use: Calculates the quotient and remainder when @a@ is divided by
100 * @b@. The destinations @*qq@ and @*rr@ must be distinct.
101 * Either of @qq@ or @rr@ may be null to indicate that the
102 * result is irrelevant. (Discarding both results is silly.)
103 * There is a performance advantage if @a == *rr@.
104 */
105
106 extern void gf_div(mp **/*qq*/, mp **/*rr*/, mp */*a*/, mp */*b*/);
107
108 /* --- @gf_irreduciblep@ --- *
109 *
110 * Arguments: @mp *f@ = a polynomial
111 *
112 * Returns: Nonzero if the polynomial is irreducible; otherwise zero.
113 */
114
115 extern int gf_irreduciblep(mp */*f*/);
116
117 /* --- @gf_gcd@ --- *
118 *
119 * Arguments: @mp **gcd, **xx, **yy@ = where to write the results
120 * @mp *a, *b@ = sources (must be nonzero)
121 *
122 *
123 * Returns: ---
124 *
125 * Use: Calculates @gcd(a, b)@, and two numbers @x@ and @y@ such that
126 * @ax + by = gcd(a, b)@. This is useful for computing modular
127 * inverses.
128 */
129
130 extern void gf_gcd(mp **/*gcd*/, mp **/*xx*/, mp **/*yy*/,
131 mp */*a*/, mp */*b*/);
132
133 /*----- That's all, folks -------------------------------------------------*/
134
135 #ifdef __cplusplus
136 }
137 #endif
138
139 #endif