3 * Reduction modulo sparse 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,
28 #ifndef CATACOMB_GFREDUCE_H
29 #define CATACOMB_GFREDUCE_H
35 /*----- Header files ------------------------------------------------------*/
43 /*----- Data structures ---------------------------------------------------*/
45 typedef struct gfreduce_instr {
46 unsigned op; /* Instruction opcode */
47 size_t arg; /* Immediate argument */
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]@ */
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 */
66 /*----- Functions provided ------------------------------------------------*/
68 /* --- @gfreduce_create@ --- *
70 * Arguments: @gfreduce *r@ = structure to fill in
71 * @mp *x@ = a (hopefully sparse) polynomial
75 * Use: Initializes a context structure for reduction.
78 extern void gfreduce_create(gfreduce */*r*/, mp */*p*/);
80 /* --- @gfreduce_destroy@ --- *
82 * Arguments: @gfreduce *r@ = structure to free
86 * Use: Reclaims the resources from a reduction context.
89 extern void gfreduce_destroy(gfreduce */*r*/);
91 /* --- @gfreduce_dump@ --- *
93 * Arguments: @gfreduce *r@ = structure to dump
94 * @FILE *fp@ = file to dump on
98 * Use: Dumps a reduction context.
101 extern void gfreduce_dump(gfreduce */*r*/, FILE */*fp*/);
103 /* --- @gfreduce_do@ --- *
105 * Arguments: @gfreduce *r@ = reduction context
106 * @mp *d@ = destination
109 * Returns: Destination, @x@ reduced modulo the reduction poly.
112 extern mp *gfreduce_do(gfreduce */*r*/, mp */*d*/, mp */*x*/);
114 /* --- @gfreduce_sqrt@ --- *
116 * Arguments: @gfreduce *r@ = pointer to reduction context
117 * @mp *d@ = destination
118 * @mp *x@ = some polynomial
120 * Returns: The square root of @x@ modulo @r->p@, or null.
123 extern mp *gfreduce_sqrt(gfreduce */*r*/, mp */*d*/, mp */*x*/);
125 /* --- @gfreduce_trace@ --- *
127 * Arguments: @gfreduce *r@ = pointer to reduction context
128 * @mp *x@ = some polynomial
130 * Returns: The trace of @x@. (%$\Tr(x)=x + x^2 + \cdots + x^{2^{m-1}}$%
131 * if %$x \in \gf{2^m}$%).
134 extern int gfreduce_trace(gfreduce */*r*/, mp */*x*/);
136 /* --- @gfreduce_halftrace@ --- *
138 * Arguments: @gfreduce *r@ = pointer to reduction context
139 * @mp *d@ = destination
140 * @mp *x@ = some polynomial
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).
147 extern mp *gfreduce_halftrace(gfreduce */*r*/, mp */*d*/, mp */*x*/);
149 /* --- @gfreduce_quadsolve@ --- *
151 * Arguments: @gfreduce *r@ = pointer to reduction context
152 * @mp *d@ = destination
153 * @mp *x@ = some polynomial
155 * Returns: A polynomial @y@ such that %$y^2 + y = x$%, or null.
158 extern mp *gfreduce_quadsolve(gfreduce */*r*/, mp */*d*/, mp */*x*/);
160 /* --- @gfreduce_exp@ --- *
162 * Arguments: @gfreduce *gr@ = pointer to reduction context
163 * @mp *d@ = fake destination
167 * Returns: Result, %$a^e \bmod m$%.
170 extern mp *gfreduce_exp(gfreduce */*gr*/, mp */*d*/, mp */*a*/, mp */*e*/);
172 /*----- That's all, folks -------------------------------------------------*/