3 * $Id: gfx.h,v 1.2 2004/03/21 22:52:06 mdw Exp $
5 * Low-level arithmetic on binary polynomials
7 * (c) 2000 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
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.
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.
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,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.2 2004/03/21 22:52:06 mdw
34 * Merge and close elliptic curve branch.
36 * Revision 1.1.4.1 2004/03/21 22:39:46 mdw
37 * Elliptic curves on binary fields work.
39 * Revision 1.1 2000/10/08 15:49:37 mdw
40 * First glimmerings of binary polynomial arithmetic.
44 #ifndef CATACOMB_GFX_H
45 #define CATACOMB_GFX_H
51 /*----- Header files ------------------------------------------------------*/
53 #ifndef CATACOMB_MPX_H
57 /*----- Functions provided ------------------------------------------------*/
59 /* --- @gfx_add@ --- *
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
67 * Use: Adds two %$\gf{2}$% polynomials. This is the same as
71 extern void gfx_add(mpw */
*dv*/
, mpw */
*dvl*/
,
72 const mpw */
*av*/
, const mpw */
*avl*/
,
73 const mpw */
*bv*/
, const mpw */
*bvl*/
);
75 /* --- @gfx_acc@ --- *
77 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
78 * @const mpw *av, *avl@ = addend vector base and limit
82 * Use: Adds the addend into the destination. This is considerably
83 * faster than the three-address add call.
86 extern void gfx_acc(mpw */
*dv*/
, mpw */
*dvl*/
,
87 const mpw */
*av*/
, const mpw */
*avl*/
);
89 /* --- @gfx_accshift@ --- *
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
97 * Use: Shifts the argument left by %$n$% places and adds it to the
98 * destination. This is a primitive used by multiplication and
102 extern void gfx_accshift(mpw */
*dv*/
, mpw */
*dvl*/
,
103 const mpw */
*av*/
, const mpw */
*avl*/
,
106 /* --- @gfx_mul@ --- *
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
114 * Use: Does multiplication of polynomials over %$\gf{2}$%.
117 extern void gfx_mul(mpw */
*dv*/
, mpw */
*dvl*/
,
118 const mpw */
*av*/
, const mpw */
*avl*/
,
119 const mpw */
*bv*/
, const mpw */
*bvl*/
);
121 /* --- @gfx_sqr@ --- *
123 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
124 * @const mpw *av, *avl@ = argument vector base and limit
128 * Use: Performs squaring of binary polynomials.
131 extern void gfx_sqr(mpw */
*dv*/
, mpw */
*dvl*/
,
132 const mpw */
*av*/
, const mpw */
*avl*/
);
134 /* --- @gfx_div@ --- *
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
142 * Use: Performs division on polynomials over %$\gf{2}$%.
145 extern void gfx_div(mpw */
*qv*/
, mpw */
*qvl*/
, mpw */
*rv*/
, mpw */
*rvl*/
,
146 const mpw */
*dv*/
, const mpw */
*dvl*/
);
148 /*----- Karatsuba multiplication algorithms -------------------------------*/
150 /* --- @GFK_THRESH@ --- *
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
159 /* --- @gfx_kmul@ --- *
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
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.
173 * The destination must be twice as large as the larger
174 * argument. The scratch space must be twice as large as the
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*/
);
183 /*----- That's all, folks -------------------------------------------------*/