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