3 * $Id: gfx.h,v 1.1.4.1 2004/03/21 22:39:46 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.1.4.1 2004/03/21 22:39:46 mdw
34 * Elliptic curves on binary fields work.
36 * Revision 1.1 2000/10/08 15:49:37 mdw
37 * First glimmerings of binary polynomial arithmetic.
41 #ifndef CATACOMB_GFX_H
42 #define CATACOMB_GFX_H
48 /*----- Header files ------------------------------------------------------*/
50 #ifndef CATACOMB_MPX_H
54 /*----- Functions provided ------------------------------------------------*/
56 /* --- @gfx_add@ --- *
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
64 * Use: Adds two %$\gf{2}$% polynomials. This is the same as
68 extern void gfx_add(mpw */
*dv*/
, mpw */
*dvl*/
,
69 const mpw */
*av*/
, const mpw */
*avl*/
,
70 const mpw */
*bv*/
, const mpw */
*bvl*/
);
72 /* --- @gfx_acc@ --- *
74 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
75 * @const mpw *av, *avl@ = addend vector base and limit
79 * Use: Adds the addend into the destination. This is considerably
80 * faster than the three-address add call.
83 extern void gfx_acc(mpw */
*dv*/
, mpw */
*dvl*/
,
84 const mpw */
*av*/
, const mpw */
*avl*/
);
86 /* --- @gfx_accshift@ --- *
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
94 * Use: Shifts the argument left by %$n$% places and adds it to the
95 * destination. This is a primitive used by multiplication and
99 extern void gfx_accshift(mpw */
*dv*/
, mpw */
*dvl*/
,
100 const mpw */
*av*/
, const mpw */
*avl*/
,
103 /* --- @gfx_mul@ --- *
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
111 * Use: Does multiplication of polynomials over %$\gf{2}$%.
114 extern void gfx_mul(mpw */
*dv*/
, mpw */
*dvl*/
,
115 const mpw */
*av*/
, const mpw */
*avl*/
,
116 const mpw */
*bv*/
, const mpw */
*bvl*/
);
118 /* --- @gfx_sqr@ --- *
120 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
121 * @const mpw *av, *avl@ = argument vector base and limit
125 * Use: Performs squaring of binary polynomials.
128 extern void gfx_sqr(mpw */
*dv*/
, mpw */
*dvl*/
,
129 const mpw */
*av*/
, const mpw */
*avl*/
);
131 /* --- @gfx_div@ --- *
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
139 * Use: Performs division on polynomials over %$\gf{2}$%.
142 extern void gfx_div(mpw */
*qv*/
, mpw */
*qvl*/
, mpw */
*rv*/
, mpw */
*rvl*/
,
143 const mpw */
*dv*/
, const mpw */
*dvl*/
);
145 /*----- Karatsuba multiplication algorithms -------------------------------*/
147 /* --- @GFK_THRESH@ --- *
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
156 /* --- @gfx_kmul@ --- *
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
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.
170 * The destination must be twice as large as the larger
171 * argument. The scratch space must be twice as large as the
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*/
);
180 /*----- That's all, folks -------------------------------------------------*/