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