ae747c9b |
1 | /* -*-c-*- |
2 | * |
ceb3f0c0 |
3 | * $Id: gfx.h,v 1.1.4.1 2004/03/21 22:39:46 mdw Exp $ |
ae747c9b |
4 | * |
5 | * Low-level arithmetic on binary polynomials |
6 | * |
7 | * (c) 2000 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: gfx.h,v $ |
ceb3f0c0 |
33 | * Revision 1.1.4.1 2004/03/21 22:39:46 mdw |
34 | * Elliptic curves on binary fields work. |
35 | * |
ae747c9b |
36 | * Revision 1.1 2000/10/08 15:49:37 mdw |
37 | * First glimmerings of binary polynomial arithmetic. |
38 | * |
39 | */ |
40 | |
41 | #ifndef CATACOMB_GFX_H |
42 | #define CATACOMB_GFX_H |
43 | |
44 | #ifdef __cplusplus |
45 | extern "C" { |
46 | #endif |
47 | |
48 | /*----- Header files ------------------------------------------------------*/ |
49 | |
50 | #ifndef CATACOMB_MPX_H |
51 | # include "mpx.h" |
52 | #endif |
53 | |
54 | /*----- Functions provided ------------------------------------------------*/ |
55 | |
56 | /* --- @gfx_add@ --- * |
57 | * |
58 | * Arguments: @mpw *dv, *dvl@ = destination vector base and limit |
59 | * @const mpw *av, *avl@ = first addend vector base and limit |
60 | * @const mpw *bv, *bvl@ = second addend vector base and limit |
61 | * |
62 | * Returns: --- |
63 | * |
64 | * Use: Adds two %$\gf{2}$% polynomials. This is the same as |
65 | * subtraction. |
66 | */ |
67 | |
68 | extern void gfx_add(mpw */*dv*/, mpw */*dvl*/, |
69 | const mpw */*av*/, const mpw */*avl*/, |
70 | const mpw */*bv*/, const mpw */*bvl*/); |
71 | |
72 | /* --- @gfx_acc@ --- * |
73 | * |
74 | * Arguments: @mpw *dv, *dvl@ = destination vector base and limit |
75 | * @const mpw *av, *avl@ = addend vector base and limit |
76 | * |
77 | * Returns: --- |
78 | * |
79 | * Use: Adds the addend into the destination. This is considerably |
80 | * faster than the three-address add call. |
81 | */ |
82 | |
83 | extern void gfx_acc(mpw */*dv*/, mpw */*dvl*/, |
84 | const mpw */*av*/, const mpw */*avl*/); |
85 | |
86 | /* --- @gfx_accshift@ --- * |
87 | * |
88 | * Arguments: @mpw *dv, *dvl@ = destination vector base and limit |
89 | * @const mpw *av, *avl@ = addend vector base and limit |
90 | * @size_t n@ = number of bits to shift |
91 | * |
92 | * Returns: --- |
93 | * |
94 | * Use: Shifts the argument left by %$n$% places and adds it to the |
95 | * destination. This is a primitive used by multiplication and |
96 | * division. |
97 | */ |
98 | |
99 | extern void gfx_accshift(mpw */*dv*/, mpw */*dvl*/, |
100 | const mpw */*av*/, const mpw */*avl*/, |
101 | size_t /*n*/); |
102 | |
103 | /* --- @gfx_mul@ --- * |
104 | * |
105 | * Arguments: @mpw *dv, *dvl@ = destination vector base and limit |
106 | * @const mpw *av, *avl@ = first argument vector base and limit |
107 | * @const mpw *bv, *bvl@ = second argument vector base and limit |
108 | * |
109 | * Returns: --- |
110 | * |
111 | * Use: Does multiplication of polynomials over %$\gf{2}$%. |
112 | */ |
113 | |
114 | extern void gfx_mul(mpw */*dv*/, mpw */*dvl*/, |
115 | const mpw */*av*/, const mpw */*avl*/, |
116 | const mpw */*bv*/, const mpw */*bvl*/); |
117 | |
ceb3f0c0 |
118 | /* --- @gfx_sqr@ --- * |
119 | * |
120 | * Arguments: @mpw *dv, *dvl@ = destination vector base and limit |
121 | * @const mpw *av, *avl@ = argument vector base and limit |
122 | * |
123 | * Returns: --- |
124 | * |
125 | * Use: Performs squaring of binary polynomials. |
126 | */ |
127 | |
128 | extern void gfx_sqr(mpw */*dv*/, mpw */*dvl*/, |
129 | const mpw */*av*/, const mpw */*avl*/); |
130 | |
ae747c9b |
131 | /* --- @gfx_div@ --- * |
132 | * |
133 | * Arguments: @mpw *qv, *qvl@ = quotient vector base and limit |
134 | * @mpw *rv, *rvl@ = dividend/remainder vector base and limit |
135 | * @const mpw *dv, *dvl@ = divisor vector base and limit |
136 | * |
137 | * Returns: --- |
138 | * |
139 | * Use: Performs division on polynomials over %$\gf{2}$%. |
140 | */ |
141 | |
142 | extern void gfx_div(mpw */*qv*/, mpw */*qvl*/, mpw */*rv*/, mpw */*rvl*/, |
143 | const mpw */*dv*/, const mpw */*dvl*/); |
144 | |
145 | /*----- Karatsuba multiplication algorithms -------------------------------*/ |
146 | |
147 | /* --- @GFK_THRESH@ --- * |
148 | * |
149 | * This is the limiting length for using Karatsuba algorithms. It's best to |
150 | * use the simpler classical multiplication method on numbers smaller than |
151 | * this. |
152 | */ |
153 | |
154 | #define GFK_THRESH 2 |
155 | |
156 | /* --- @gfx_kmul@ --- * |
157 | * |
158 | * Arguments: @mpw *dv, *dvl@ = pointer to destination buffer |
159 | * @const mpw *av, *avl@ = pointer to first argument |
160 | * @const mpw *bv, *bvl@ = pointer to second argument |
161 | * @mpw *sv, *svl@ = pointer to scratch workspace |
162 | * |
163 | * Returns: --- |
164 | * |
165 | * Use: Multiplies two binary polynomials using Karatsuba's |
166 | * algorithm. This is rather faster than traditional long |
167 | * multiplication (e.g., @gfx_umul@) on polynomials with large |
168 | * degree, although more expensive on small ones. |
169 | * |
170 | * The destination must be twice as large as the larger |
171 | * argument. The scratch space must be twice as large as the |
172 | * larger argument. |
173 | */ |
174 | |
175 | extern void gfx_kmul(mpw */*dv*/, mpw */*dvl*/, |
176 | const mpw */*av*/, const mpw */*avl*/, |
177 | const mpw */*bv*/, const mpw */*bvl*/, |
178 | mpw */*sv*/, mpw */*svl*/); |
179 | |
180 | /*----- That's all, folks -------------------------------------------------*/ |
181 | |
182 | #ifdef __cplusplus |
183 | } |
184 | #endif |
185 | |
186 | #endif |