3 * Arithmetic on binary polynomials
5 * (c) 2004 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
35 /*----- Header files ------------------------------------------------------*/
41 #ifndef CATACOMB_GFX_H
45 /*----- Functions provided ------------------------------------------------*/
49 * Arguments: @mp *d@ = destination
50 * @mp *a, *b@ = sources
52 * Returns: Result, @a@ added to @b@.
55 extern mp
*gf_add(mp */
*d*/
, mp */
*a*/
, mp */
*b*/
);
60 * Arguments: @mp *d@ = destination
61 * @mp *a, *b@ = sources
63 * Returns: Result, @a@ multiplied by @b@.
66 extern mp
*gf_mul(mp */
*d*/
, mp */
*a*/
, mp */
*b*/
);
70 * Arguments: @mp *d@ = destination
73 * Returns: Result, @a@ squared.
76 extern mp
*gf_sqr(mp */
*d*/
, mp */
*a*/
);
80 * Arguments: @mp **qq, **rr@ = destination, quotient and remainder
81 * @mp *a, *b@ = sources
83 * Use: Calculates the quotient and remainder when @a@ is divided by
84 * @b@. The destinations @*qq@ and @*rr@ must be distinct.
85 * Either of @qq@ or @rr@ may be null to indicate that the
86 * result is irrelevant. (Discarding both results is silly.)
87 * There is a performance advantage if @a == *rr@.
90 extern void gf_div(mp
**/
*qq*/
, mp
**/
*rr*/
, mp */
*a*/
, mp */
*b*/
);
94 * Arguments: @mp *d@ = fake destination
98 * Returns: Result, %$a^e$%.
101 extern mp
*gf_exp(mp */
*d*/
, mp */
*a*/
, mp */
*e*/
);
103 /* --- @gf_irreduciblep@ --- *
105 * Arguments: @mp *f@ = a polynomial
107 * Returns: Nonzero if the polynomial is irreducible; otherwise zero.
110 extern int gf_irreduciblep(mp */
*f*/
);
112 /* --- @gf_gcd@ --- *
114 * Arguments: @mp **gcd, **xx, **yy@ = where to write the results
115 * @mp *a, *b@ = sources (must be nonzero)
120 * Use: Calculates @gcd(a, b)@, and two numbers @x@ and @y@ such that
121 * @ax + by = gcd(a, b)@. This is useful for computing modular
125 extern void gf_gcd(mp
**/
*gcd*/
, mp
**/
*xx*/
, mp
**/
*yy*/
,
126 mp */
*a*/
, mp */
*b*/
);
128 /* -- @gf_modinv@ --- *
130 * Arguments: @mp *d@ = destination
134 * Returns: The inverse %$x^{-1} \bmod p$%.
136 * Use: Computes a modular inverse, the catch being that the
137 * arguments and results are binary polynomials. An assertion
138 * fails if %$p$% has no inverse.
141 extern mp
*gf_modinv(mp */
*d*/
, mp */
*x*/
, mp */
*p*/
);
143 /*----- That's all, folks -------------------------------------------------*/