perftest: Document the `-q' option for disabling checking.
[u/mdw/catacomb] / gfreduce.h
1 /* -*-c-*-
2 *
3 * $Id: gfreduce.h,v 1.3 2004/04/08 01:36:15 mdw Exp $
4 *
5 * Reduction modulo sparse binary polynomials
6 *
7 * (c) 2004 Straylight/Edgeware
8 */
9
10 /*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of Catacomb.
13 *
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.
18 *
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.
23 *
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,
27 * MA 02111-1307, USA.
28 */
29
30 #ifndef CATACOMB_GFREDUCE_H
31 #define CATACOMB_GFREDUCE_H
32
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36
37 /*----- Header files ------------------------------------------------------*/
38
39 #ifndef CATACOMB_GF_H
40 # include "gf.h"
41 #endif
42
43 /*----- Data structures ---------------------------------------------------*/
44
45 typedef struct gfreduce_instr {
46 unsigned op; /* Instruction opcode */
47 size_t arg; /* Immediate argument */
48 } gfreduce_instr;
49
50 enum {
51 GFRI_LOAD, /* Load @p[arg]@ */
52 GFRI_LSL, /* XOR with @w << arg@ */
53 GFRI_LSR, /* XOR with @w >> arg@ */
54 GFRI_STORE, /* Store @p[arg]@ */
55 GFRI_MAX
56 };
57
58 typedef struct gfreduce {
59 size_t lim; /* Word of degree bit */
60 mpw mask; /* Mask for degree word */
61 mp *p; /* Copy of the polynomial */
62 size_t in; /* Number of instruction words */
63 gfreduce_instr *iv, *liv; /* Vector of instructions */
64 } gfreduce;
65
66 /*----- Functions provided ------------------------------------------------*/
67
68 /* --- @gfreduce_create@ --- *
69 *
70 * Arguments: @gfreduce *r@ = structure to fill in
71 * @mp *x@ = a (hopefully sparse) polynomial
72 *
73 * Returns: ---
74 *
75 * Use: Initializes a context structure for reduction.
76 */
77
78 extern void gfreduce_create(gfreduce */*r*/, mp */*p*/);
79
80 /* --- @gfreduce_destroy@ --- *
81 *
82 * Arguments: @gfreduce *r@ = structure to free
83 *
84 * Returns: ---
85 *
86 * Use: Reclaims the resources from a reduction context.
87 */
88
89 extern void gfreduce_destroy(gfreduce */*r*/);
90
91 /* --- @gfreduce_dump@ --- *
92 *
93 * Arguments: @gfreduce *r@ = structure to dump
94 * @FILE *fp@ = file to dump on
95 *
96 * Returns: ---
97 *
98 * Use: Dumps a reduction context.
99 */
100
101 extern void gfreduce_dump(gfreduce */*r*/, FILE */*fp*/);
102
103 /* --- @gfreduce_do@ --- *
104 *
105 * Arguments: @gfreduce *r@ = reduction context
106 * @mp *d@ = destination
107 * @mp *x@ = source
108 *
109 * Returns: Destination, @x@ reduced modulo the reduction poly.
110 */
111
112 extern mp *gfreduce_do(gfreduce */*r*/, mp */*d*/, mp */*x*/);
113
114 /* --- @gfreduce_sqrt@ --- *
115 *
116 * Arguments: @gfreduce *r@ = pointer to reduction context
117 * @mp *d@ = destination
118 * @mp *x@ = some polynomial
119 *
120 * Returns: The square root of @x@ modulo @r->p@, or null.
121 */
122
123 extern mp *gfreduce_sqrt(gfreduce */*r*/, mp */*d*/, mp */*x*/);
124
125 /* --- @gfreduce_trace@ --- *
126 *
127 * Arguments: @gfreduce *r@ = pointer to reduction context
128 * @mp *x@ = some polynomial
129 *
130 * Returns: The trace of @x@. (%$\Tr(x)=x + x^2 + \cdots + x^{2^{m-1}}$%
131 * if %$x \in \gf{2^m}$%).
132 */
133
134 extern int gfreduce_trace(gfreduce */*r*/, mp */*x*/);
135
136 /* --- @gfreduce_halftrace@ --- *
137 *
138 * Arguments: @gfreduce *r@ = pointer to reduction context
139 * @mp *d@ = destination
140 * @mp *x@ = some polynomial
141 *
142 * Returns: The half-trace of @x@.
143 * (%$\HfTr(x)= x + x^{2^2} + \cdots + x^{2^{m-1}}$%
144 * if %$x \in \gf{2^m}$% with %$m$% odd).
145 */
146
147 extern mp *gfreduce_halftrace(gfreduce */*r*/, mp */*d*/, mp */*x*/);
148
149 /* --- @gfreduce_quadsolve@ --- *
150 *
151 * Arguments: @gfreduce *r@ = pointer to reduction context
152 * @mp *d@ = destination
153 * @mp *x@ = some polynomial
154 *
155 * Returns: A polynomial @y@ such that %$y^2 + y = x$%, or null.
156 */
157
158 extern mp *gfreduce_quadsolve(gfreduce */*r*/, mp */*d*/, mp */*x*/);
159
160 /* --- @gfreduce_exp@ --- *
161 *
162 * Arguments: @gfreduce *gr@ = pointer to reduction context
163 * @mp *d@ = fake destination
164 * @mp *a@ = base
165 * @mp *e@ = exponent
166 *
167 * Returns: Result, %$a^e \bmod m$%.
168 */
169
170 extern mp *gfreduce_exp(gfreduce */*gr*/, mp */*d*/, mp */*a*/, mp */*e*/);
171
172 /*----- That's all, folks -------------------------------------------------*/
173
174 #ifdef __cplusplus
175 }
176 #endif
177
178 #endif