math/gfreduce.[ch]: Fix out-of-bounds memory access.
[u/mdw/catacomb] / math / gfn.h
CommitLineData
4edc47b8 1/* -*-c-*-
2 *
4edc47b8 3 * Normal-basis translation for binary fields
4 *
5 * (c) 2004 Straylight/Edgeware
6 */
7
45c0fd36 8/*----- Licensing notice --------------------------------------------------*
4edc47b8 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.
45c0fd36 16 *
4edc47b8 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.
45c0fd36 21 *
4edc47b8 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
4edc47b8 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
41typedef 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
58extern 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
69extern 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
81extern 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
92extern 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
105extern 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
122extern 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