3 * $Id: gfx.h,v 1.3 2004/04/08 01:36:15 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 #ifndef CATACOMB_GFX_H
31 #define CATACOMB_GFX_H
37 /*----- Header files ------------------------------------------------------*/
39 #ifndef CATACOMB_MPX_H
43 /*----- Functions provided ------------------------------------------------*/
45 /* --- @gfx_add@ --- *
47 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
48 * @const mpw *av, *avl@ = first addend vector base and limit
49 * @const mpw *bv, *bvl@ = second addend vector base and limit
53 * Use: Adds two %$\gf{2}$% polynomials. This is the same as
57 extern void gfx_add(mpw */*dv*/, mpw */*dvl*/,
58 const mpw */*av*/, const mpw */*avl*/,
59 const mpw */*bv*/, const mpw */*bvl*/);
61 /* --- @gfx_acc@ --- *
63 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
64 * @const mpw *av, *avl@ = addend vector base and limit
68 * Use: Adds the addend into the destination. This is considerably
69 * faster than the three-address add call.
72 extern void gfx_acc(mpw */*dv*/, mpw */*dvl*/,
73 const mpw */*av*/, const mpw */*avl*/);
75 /* --- @gfx_accshift@ --- *
77 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
78 * @const mpw *av, *avl@ = addend vector base and limit
79 * @size_t n@ = number of bits to shift
83 * Use: Shifts the argument left by %$n$% places and adds it to the
84 * destination. This is a primitive used by multiplication and
88 extern void gfx_accshift(mpw */*dv*/, mpw */*dvl*/,
89 const mpw */*av*/, const mpw */*avl*/,
92 /* --- @gfx_mul@ --- *
94 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
95 * @const mpw *av, *avl@ = first argument vector base and limit
96 * @const mpw *bv, *bvl@ = second argument vector base and limit
100 * Use: Does multiplication of polynomials over %$\gf{2}$%.
103 extern void gfx_mul(mpw */*dv*/, mpw */*dvl*/,
104 const mpw */*av*/, const mpw */*avl*/,
105 const mpw */*bv*/, const mpw */*bvl*/);
107 /* --- @gfx_sqr@ --- *
109 * Arguments: @mpw *dv, *dvl@ = destination vector base and limit
110 * @const mpw *av, *avl@ = argument vector base and limit
114 * Use: Performs squaring of binary polynomials.
117 extern void gfx_sqr(mpw */*dv*/, mpw */*dvl*/,
118 const mpw */*av*/, const mpw */*avl*/);
120 /* --- @gfx_div@ --- *
122 * Arguments: @mpw *qv, *qvl@ = quotient vector base and limit
123 * @mpw *rv, *rvl@ = dividend/remainder vector base and limit
124 * @const mpw *dv, *dvl@ = divisor vector base and limit
128 * Use: Performs division on polynomials over %$\gf{2}$%.
131 extern void gfx_div(mpw */*qv*/, mpw */*qvl*/, mpw */*rv*/, mpw */*rvl*/,
132 const mpw */*dv*/, const mpw */*dvl*/);
134 /*----- Karatsuba multiplication algorithms -------------------------------*/
136 /* --- @GFK_THRESH@ --- *
138 * This is the limiting length for using Karatsuba algorithms. It's best to
139 * use the simpler classical multiplication method on numbers smaller than
145 /* --- @gfx_kmul@ --- *
147 * Arguments: @mpw *dv, *dvl@ = pointer to destination buffer
148 * @const mpw *av, *avl@ = pointer to first argument
149 * @const mpw *bv, *bvl@ = pointer to second argument
150 * @mpw *sv, *svl@ = pointer to scratch workspace
154 * Use: Multiplies two binary polynomials using Karatsuba's
155 * algorithm. This is rather faster than traditional long
156 * multiplication (e.g., @gfx_umul@) on polynomials with large
157 * degree, although more expensive on small ones.
159 * The destination must be twice as large as the larger
160 * argument. The scratch space must be twice as large as the
164 extern void gfx_kmul(mpw */*dv*/, mpw */*dvl*/,
165 const mpw */*av*/, const mpw */*avl*/,
166 const mpw */*bv*/, const mpw */*bvl*/,
167 mpw */*sv*/, mpw */*svl*/);
169 /*----- That's all, folks -------------------------------------------------*/