3 * $Id: gfreduce.h,v 1.2 2004/03/21 22:52:06 mdw Exp $
5 * Reduction modulo sparse binary polynomials
7 * (c) 2004 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
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.
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.
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,
30 /*----- Revision history --------------------------------------------------*
32 * $Log: gfreduce.h,v $
33 * Revision 1.2 2004/03/21 22:52:06 mdw
34 * Merge and close elliptic curve branch.
36 * Revision 1.1.2.1 2004/03/21 22:39:46 mdw
37 * Elliptic curves on binary fields work.
41 #ifndef CATACOMB_GFREDUCE_H
42 #define CATACOMB_GFREDUCE_H
48 /*----- Header files ------------------------------------------------------*/
54 /*----- Data structures ---------------------------------------------------*/
56 typedef struct gfreduce_instr
{
57 unsigned op
; /* Instruction opcode */
58 size_t arg
; /* Immediate argument */
62 GFRI_LOAD
, /* Load @p[arg]@ */
63 GFRI_LSL
, /* XOR with @w << arg@ */
64 GFRI_LSR
, /* XOR with @w >> arg@ */
65 GFRI_STORE
, /* Store @p[arg]@ */
69 typedef struct gfreduce
{
70 size_t lim
; /* Word of degree bit */
71 mpw mask
; /* Mask for degree word */
72 mp
*p
; /* Copy of the polynomial */
73 size_t in
; /* Number of instruction words */
74 gfreduce_instr
*iv
, *liv
; /* Vector of instructions */
77 /*----- Functions provided ------------------------------------------------*/
79 /* --- @gfreduce_create@ --- *
81 * Arguments: @gfreduce *r@ = structure to fill in
82 * @mp *x@ = a (hopefully sparse) polynomial
86 * Use: Initializes a context structure for reduction.
89 extern void gfreduce_create(gfreduce */
*r*/
, mp */
*p*/
);
91 /* --- @gfreduce_destroy@ --- *
93 * Arguments: @gfreduce *r@ = structure to free
97 * Use: Reclaims the resources from a reduction context.
100 extern void gfreduce_destroy(gfreduce */
*r*/
);
102 /* --- @gfreduce_dump@ --- *
104 * Arguments: @gfreduce *r@ = structure to dump
105 * @FILE *fp@ = file to dump on
109 * Use: Dumps a reduction context.
112 extern void gfreduce_dump(gfreduce */
*r*/
, FILE */
*fp*/
);
114 /* --- @gfreduce_do@ --- *
116 * Arguments: @gfreduce *r@ = reduction context
117 * @mp *d@ = destination
120 * Returns: Destination, @x@ reduced modulo the reduction poly.
123 extern mp
*gfreduce_do(gfreduce */
*r*/
, mp */
*d*/
, mp */
*x*/
);
125 /* --- @gfreduce_sqrt@ --- *
127 * Arguments: @gfreduce *r@ = pointer to reduction context
128 * @mp *d@ = destination
129 * @mp *x@ = some polynomial
131 * Returns: The square root of @x@ modulo @r->p@, or null.
134 extern mp
*gfreduce_sqrt(gfreduce */
*r*/
, mp */
*d*/
, mp */
*x*/
);
136 /* --- @gfreduce_trace@ --- *
138 * Arguments: @gfreduce *r@ = pointer to reduction context
139 * @mp *x@ = some polynomial
141 * Returns: The trace of @x@. (%$\Tr(x)=x + x^2 + \cdots + x^{2^{m-1}}$%
142 * if %$x \in \gf{2^m}$%).
145 extern int gfreduce_trace(gfreduce */
*r*/
, mp */
*x*/
);
147 /* --- @gfreduce_halftrace@ --- *
149 * Arguments: @gfreduce *r@ = pointer to reduction context
150 * @mp *d@ = destination
151 * @mp *x@ = some polynomial
153 * Returns: The half-trace of @x@.
154 * (%$\HfTr(x)= x + x^{2^2} + \cdots + x^{2^{m-1}}$%
155 * if %$x \in \gf{2^m}$% with %$m$% odd).
158 extern mp
*gfreduce_halftrace(gfreduce */
*r*/
, mp */
*d*/
, mp */
*x*/
);
160 /* --- @gfreduce_quadsolve@ --- *
162 * Arguments: @gfreduce *r@ = pointer to reduction context
163 * @mp *d@ = destination
164 * @mp *x@ = some polynomial
166 * Returns: A polynomial @y@ such that %$y^2 + y = x$%, or null.
169 extern mp
*gfreduce_quadsolve(gfreduce */
*r*/
, mp */
*d*/
, mp */
*x*/
);
171 /* --- @gfreduce_exp@ --- *
173 * Arguments: @gfreduce *gr@ = pointer to reduction context
174 * @mp *d@ = fake destination
178 * Returns: Result, %$a^e \bmod m$%.
181 extern mp
*gfreduce_exp(gfreduce */
*gr*/
, mp */
*d*/
, mp */
*a*/
, mp */
*e*/
);
183 /*----- That's all, folks -------------------------------------------------*/