3 * $Id: gfreduce.h,v 1.1.2.1 2004/03/21 22:39:46 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.1.2.1 2004/03/21 22:39:46 mdw
34 * Elliptic curves on binary fields work.
38 #ifndef CATACOMB_GFREDUCE_H
39 #define CATACOMB_GFREDUCE_H
45 /*----- Header files ------------------------------------------------------*/
51 /*----- Data structures ---------------------------------------------------*/
53 typedef struct gfreduce_instr
{
54 unsigned op
; /* Instruction opcode */
55 size_t arg
; /* Immediate argument */
59 GFRI_LOAD
, /* Load @p[arg]@ */
60 GFRI_LSL
, /* XOR with @w << arg@ */
61 GFRI_LSR
, /* XOR with @w >> arg@ */
62 GFRI_STORE
, /* Store @p[arg]@ */
66 typedef struct gfreduce
{
67 size_t lim
; /* Word of degree bit */
68 mpw mask
; /* Mask for degree word */
69 mp
*p
; /* Copy of the polynomial */
70 size_t in
; /* Number of instruction words */
71 gfreduce_instr
*iv
, *liv
; /* Vector of instructions */
74 /*----- Functions provided ------------------------------------------------*/
76 /* --- @gfreduce_create@ --- *
78 * Arguments: @gfreduce *r@ = structure to fill in
79 * @mp *x@ = a (hopefully sparse) polynomial
83 * Use: Initializes a context structure for reduction.
86 extern void gfreduce_create(gfreduce */
*r*/
, mp */
*p*/
);
88 /* --- @gfreduce_destroy@ --- *
90 * Arguments: @gfreduce *r@ = structure to free
94 * Use: Reclaims the resources from a reduction context.
97 extern void gfreduce_destroy(gfreduce */
*r*/
);
99 /* --- @gfreduce_dump@ --- *
101 * Arguments: @gfreduce *r@ = structure to dump
102 * @FILE *fp@ = file to dump on
106 * Use: Dumps a reduction context.
109 extern void gfreduce_dump(gfreduce */
*r*/
, FILE */
*fp*/
);
111 /* --- @gfreduce_do@ --- *
113 * Arguments: @gfreduce *r@ = reduction context
114 * @mp *d@ = destination
117 * Returns: Destination, @x@ reduced modulo the reduction poly.
120 extern mp
*gfreduce_do(gfreduce */
*r*/
, mp */
*d*/
, mp */
*x*/
);
122 /* --- @gfreduce_sqrt@ --- *
124 * Arguments: @gfreduce *r@ = pointer to reduction context
125 * @mp *d@ = destination
126 * @mp *x@ = some polynomial
128 * Returns: The square root of @x@ modulo @r->p@, or null.
131 extern mp
*gfreduce_sqrt(gfreduce */
*r*/
, mp */
*d*/
, mp */
*x*/
);
133 /* --- @gfreduce_trace@ --- *
135 * Arguments: @gfreduce *r@ = pointer to reduction context
136 * @mp *x@ = some polynomial
138 * Returns: The trace of @x@. (%$\Tr(x)=x + x^2 + \cdots + x^{2^{m-1}}$%
139 * if %$x \in \gf{2^m}$%).
142 extern int gfreduce_trace(gfreduce */
*r*/
, mp */
*x*/
);
144 /* --- @gfreduce_halftrace@ --- *
146 * Arguments: @gfreduce *r@ = pointer to reduction context
147 * @mp *d@ = destination
148 * @mp *x@ = some polynomial
150 * Returns: The half-trace of @x@.
151 * (%$\HfTr(x)= x + x^{2^2} + \cdots + x^{2^{m-1}}$%
152 * if %$x \in \gf{2^m}$% with %$m$% odd).
155 extern mp
*gfreduce_halftrace(gfreduce */
*r*/
, mp */
*d*/
, mp */
*x*/
);
157 /* --- @gfreduce_quadsolve@ --- *
159 * Arguments: @gfreduce *r@ = pointer to reduction context
160 * @mp *d@ = destination
161 * @mp *x@ = some polynomial
163 * Returns: A polynomial @y@ such that %$y^2 + y = x$%, or null.
166 extern mp
*gfreduce_quadsolve(gfreduce */
*r*/
, mp */
*d*/
, mp */
*x*/
);
168 /* --- @gfreduce_exp@ --- *
170 * Arguments: @gfreduce *gr@ = pointer to reduction context
171 * @mp *d@ = fake destination
175 * Returns: Result, %$a^e \bmod m$%.
178 extern mp
*gfreduce_exp(gfreduce */
*gr*/
, mp */
*d*/
, mp */
*a*/
, mp */
*e*/
);
180 /*----- That's all, folks -------------------------------------------------*/