math/gfreduce.[ch]: Fix out-of-bounds memory access.
[u/mdw/catacomb] / math / gfn.h
1 /* -*-c-*-
2 *
3 * Normal-basis translation for binary fields
4 *
5 * (c) 2004 Straylight/Edgeware
6 */
7
8 /*----- Licensing notice --------------------------------------------------*
9 *
10 * This file is part of Catacomb.
11 *
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.
16 *
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.
21 *
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,
25 * MA 02111-1307, USA.
26 */
27
28 #ifndef CATACOMB_GFN_H
29 #define CATACOMB_GFN_H
30
31 #ifdef __cplusplus
32 extern "C" {
33 #endif
34
35 /*----- Header files ------------------------------------------------------*/
36
37 #include "gf.h"
38
39 /*----- Data structures ---------------------------------------------------*/
40
41 typedef struct gfn {
42 size_t n; /* Number of rows */
43 mp **r; /* Array of the rows */
44 } gfn;
45
46 /*----- Functions provided ------------------------------------------------*/
47
48 /* --- @gfn_copy@ --- *
49 *
50 * Arguments: @gfn *d@ = where to put the copy
51 * @const gfn *s@ = where the source is
52 *
53 * Returns: ---
54 *
55 * Use: Makes a copy of a translation matrix.
56 */
57
58 extern void gfn_copy(gfn */*d*/, const gfn */*s*/);
59
60 /* --- @gfn_destroy@ --- *
61 *
62 * Arguments: @gfn *m@ = a transformation matrix to free
63 *
64 * Returns: ---
65 *
66 * Use: Frees up a transformation matrix when it's no longer wanted.
67 */
68
69 extern void gfn_destroy(gfn */*m*/);
70
71 /* --- @gfn_identity@ --- *
72 *
73 * Arguments: @gfn *m@ = where to put the matrix
74 * @size_t n@ = size of the matrix
75 *
76 * Returns: ---
77 *
78 * Use: Fills @m@ with an identity matrix.
79 */
80
81 extern void gfn_identity(gfn */*m*/, size_t /*n*/);
82
83 /* --- @gfn_invert@ --- *
84 *
85 * Arguments: @gfn *m@ = a transformation matrix
86 *
87 * Returns: Zero if successful, nonzero if the matrix was singular.
88 *
89 * Use: Inverts a transformation matrix.
90 */
91
92 extern int gfn_invert(gfn */*m*/);
93
94 /* --- @gfn_transform@ --- *
95 *
96 * Arguments: @gfn *m@ = conversion matrix to apply
97 * @mp *d@ = destination pointer
98 * @mp *x@ = input value
99 *
100 * Returns: The transformed element.
101 *
102 * Use: Transforms a field element according to the given matrix.
103 */
104
105 extern mp *gfn_transform(gfn */*m*/, mp */*d*/, mp */*x*/);
106
107 /* --- @gfn_create@ --- *
108 *
109 * Arguments: @mp *p@ = modulus for polynomial basis
110 * @mp *beta@ = the generator of the normal basis, expressed
111 * relative to the polynomial basis
112 * @gfn *ntop@ = output normal-to-polynomail conversion matrix
113 * @gfn *pton@ = output polynomial-to-normal conversion matrix
114 *
115 * Returns: Zero if it worked, nonzero otherwise (e.g., if %$\beta$%
116 * doesn't generate a proper basis).
117 *
118 * Use: Constructs conversion matrices between polynomial and normal
119 * basis representations of binary field elements.
120 */
121
122 extern int gfn_create(mp */*p*/, mp */*beta*/, gfn */*ntop*/, gfn */*pton*/);
123
124 /*----- That's all, folks -------------------------------------------------*/
125
126 #ifdef __cplusplus
127 }
128 #endif
129
130 #endif