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; /* Vector of instructions */
64 gfreduce_instr *fiv; /* Final-pass instruction suffix */
67 /*----- Functions provided ------------------------------------------------*/
69 /* --- @gfreduce_create@ --- *
71 * Arguments: @gfreduce *r@ = structure to fill in
72 * @mp *x@ = a (hopefully sparse) polynomial
76 * Use: Initializes a context structure for reduction.
79 extern void gfreduce_create(gfreduce */*r*/, mp */*p*/);
81 /* --- @gfreduce_destroy@ --- *
83 * Arguments: @gfreduce *r@ = structure to free
87 * Use: Reclaims the resources from a reduction context.
90 extern void gfreduce_destroy(gfreduce */*r*/);
92 /* --- @gfreduce_dump@ --- *
94 * Arguments: @gfreduce *r@ = structure to dump
95 * @FILE *fp@ = file to dump on
99 * Use: Dumps a reduction context.
102 extern void gfreduce_dump(gfreduce */*r*/, FILE */*fp*/);
104 /* --- @gfreduce_do@ --- *
106 * Arguments: @gfreduce *r@ = reduction context
107 * @mp *d@ = destination
110 * Returns: Destination, @x@ reduced modulo the reduction poly.
113 extern mp *gfreduce_do(gfreduce */*r*/, mp */*d*/, mp */*x*/);
115 /* --- @gfreduce_sqrt@ --- *
117 * Arguments: @gfreduce *r@ = pointer to reduction context
118 * @mp *d@ = destination
119 * @mp *x@ = some polynomial
121 * Returns: The square root of @x@ modulo @r->p@, or null.
124 extern mp *gfreduce_sqrt(gfreduce */*r*/, mp */*d*/, mp */*x*/);
126 /* --- @gfreduce_trace@ --- *
128 * Arguments: @gfreduce *r@ = pointer to reduction context
129 * @mp *x@ = some polynomial
131 * Returns: The trace of @x@. (%$\Tr(x)=x + x^2 + \cdots + x^{2^{m-1}}$%
132 * if %$x \in \gf{2^m}$%).
135 extern int gfreduce_trace(gfreduce */*r*/, mp */*x*/);
137 /* --- @gfreduce_halftrace@ --- *
139 * Arguments: @gfreduce *r@ = pointer to reduction context
140 * @mp *d@ = destination
141 * @mp *x@ = some polynomial
143 * Returns: The half-trace of @x@.
144 * (%$\HfTr(x)= x + x^{2^2} + \cdots + x^{2^{m-1}}$%
145 * if %$x \in \gf{2^m}$% with %$m$% odd).
148 extern mp *gfreduce_halftrace(gfreduce */*r*/, mp */*d*/, mp */*x*/);
150 /* --- @gfreduce_quadsolve@ --- *
152 * Arguments: @gfreduce *r@ = pointer to reduction context
153 * @mp *d@ = destination
154 * @mp *x@ = some polynomial
156 * Returns: A polynomial @y@ such that %$y^2 + y = x$%, or null.
159 extern mp *gfreduce_quadsolve(gfreduce */*r*/, mp */*d*/, mp */*x*/);
161 /* --- @gfreduce_exp@ --- *
163 * Arguments: @gfreduce *gr@ = pointer to reduction context
164 * @mp *d@ = fake destination
168 * Returns: Result, %$a^e \bmod m$%.
171 extern mp *gfreduce_exp(gfreduce */*gr*/, mp */*d*/, mp */*a*/, mp */*e*/);
173 /*----- That's all, folks -------------------------------------------------*/