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 ------------------------------------------------------*/
41 /*----- Data structures ---------------------------------------------------*/
43 typedef struct gfreduce_instr
{
44 unsigned op
; /* Instruction opcode */
45 size_t arg
; /* Immediate argument */
49 GFRI_LOAD
, /* Load @p[arg]@ */
50 GFRI_LSL
, /* XOR with @w << arg@ */
51 GFRI_LSR
, /* XOR with @w >> arg@ */
52 GFRI_STORE
, /* Store @p[arg]@ */
56 typedef struct gfreduce
{
57 size_t lim
; /* Word of degree bit */
58 mpw mask
; /* Mask for degree word */
59 mp
*p
; /* Copy of the polynomial */
60 size_t in
; /* Number of instruction words */
61 gfreduce_instr
*iv
, *liv
; /* Vector of instructions */
64 /*----- Functions provided ------------------------------------------------*/
66 /* --- @gfreduce_create@ --- *
68 * Arguments: @gfreduce *r@ = structure to fill in
69 * @mp *x@ = a (hopefully sparse) polynomial
73 * Use: Initializes a context structure for reduction.
76 extern void gfreduce_create(gfreduce */
*r*/
, mp */
*p*/
);
78 /* --- @gfreduce_destroy@ --- *
80 * Arguments: @gfreduce *r@ = structure to free
84 * Use: Reclaims the resources from a reduction context.
87 extern void gfreduce_destroy(gfreduce */
*r*/
);
89 /* --- @gfreduce_dump@ --- *
91 * Arguments: @gfreduce *r@ = structure to dump
92 * @FILE *fp@ = file to dump on
96 * Use: Dumps a reduction context.
99 extern void gfreduce_dump(gfreduce */
*r*/
, FILE */
*fp*/
);
101 /* --- @gfreduce_do@ --- *
103 * Arguments: @gfreduce *r@ = reduction context
104 * @mp *d@ = destination
107 * Returns: Destination, @x@ reduced modulo the reduction poly.
110 extern mp
*gfreduce_do(gfreduce */
*r*/
, mp */
*d*/
, mp */
*x*/
);
112 /* --- @gfreduce_sqrt@ --- *
114 * Arguments: @gfreduce *r@ = pointer to reduction context
115 * @mp *d@ = destination
116 * @mp *x@ = some polynomial
118 * Returns: The square root of @x@ modulo @r->p@, or null.
121 extern mp
*gfreduce_sqrt(gfreduce */
*r*/
, mp */
*d*/
, mp */
*x*/
);
123 /* --- @gfreduce_trace@ --- *
125 * Arguments: @gfreduce *r@ = pointer to reduction context
126 * @mp *x@ = some polynomial
128 * Returns: The trace of @x@. (%$\Tr(x)=x + x^2 + \cdots + x^{2^{m-1}}$%
129 * if %$x \in \gf{2^m}$%).
132 extern int gfreduce_trace(gfreduce */
*r*/
, mp */
*x*/
);
134 /* --- @gfreduce_halftrace@ --- *
136 * Arguments: @gfreduce *r@ = pointer to reduction context
137 * @mp *d@ = destination
138 * @mp *x@ = some polynomial
140 * Returns: The half-trace of @x@.
141 * (%$\HfTr(x)= x + x^{2^2} + \cdots + x^{2^{m-1}}$%
142 * if %$x \in \gf{2^m}$% with %$m$% odd).
145 extern mp
*gfreduce_halftrace(gfreduce */
*r*/
, mp */
*d*/
, mp */
*x*/
);
147 /* --- @gfreduce_quadsolve@ --- *
149 * Arguments: @gfreduce *r@ = pointer to reduction context
150 * @mp *d@ = destination
151 * @mp *x@ = some polynomial
153 * Returns: A polynomial @y@ such that %$y^2 + y = x$%, or null.
156 extern mp
*gfreduce_quadsolve(gfreduce */
*r*/
, mp */
*d*/
, mp */
*x*/
);
158 /* --- @gfreduce_exp@ --- *
160 * Arguments: @gfreduce *gr@ = pointer to reduction context
161 * @mp *d@ = fake destination
165 * Returns: Result, %$a^e \bmod m$%.
168 extern mp
*gfreduce_exp(gfreduce */
*gr*/
, mp */
*d*/
, mp */
*a*/
, mp */
*e*/
);
170 /*----- That's all, folks -------------------------------------------------*/