3 * $Id: f-binpoly.c,v 1.2 2004/03/21 22:52:06 mdw Exp $
5 * Binary fields with polynomial basis representation
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: f-binpoly.c,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 /*----- Header files ------------------------------------------------------*/
49 /*----- Data structures ---------------------------------------------------*/
56 /*----- Main code ---------------------------------------------------------*/
58 /* --- Field operations --- */
60 static void fdestroy(field
*ff
)
63 gfreduce_destroy(&f
->r
);
67 static int fzerop(field
*ff
, mp
*x
)
72 static mp
*fadd(field
*ff
, mp
*d
, mp
*x
, mp
*y
)
74 return (gf_add(d
, x
, y
));
77 static mp
*fmul(field
*ff
, mp
*d
, mp
*x
, mp
*y
)
81 return (gfreduce_do(&f
->r
, d
, d
));
84 static mp
*fsqr(field
*ff
, mp
*d
, mp
*x
)
88 return (gfreduce_do(&f
->r
, d
, d
));
91 static mp
*finv(field
*ff
, mp
*d
, mp
*x
)
94 gf_gcd(0, 0, &d
, f
->r
.p
, x
);
98 static mp
*freduce(field
*ff
, mp
*d
, mp
*x
)
100 fctx
*f
= (fctx
*)ff
;
101 return (gfreduce_do(&f
->r
, d
, x
));
104 static mp
*fsqrt(field
*ff
, mp
*d
, mp
*x
)
106 fctx
*f
= (fctx
*)ff
;
107 return (gfreduce_sqrt(&f
->r
, d
, x
));
110 static mp
*fquadsolve(field
*ff
, mp
*d
, mp
*x
)
112 fctx
*f
= (fctx
*)ff
;
113 return (gfreduce_quadsolve(&f
->r
, d
, x
));
116 /* --- Field operations table --- */
118 static field_ops fops
= {
121 fzerop
, field_id
, fadd
, fadd
, fmul
, fsqr
, finv
, freduce
, fsqrt
,
126 /* --- @field_binpoly@ --- *
128 * Arguments: @mp *p@ = the reduction polynomial
130 * Returns: A pointer to the field.
132 * Use: Creates a field structure for a binary field mod @p@.
135 field
*field_binpoly(mp
*p
)
137 fctx
*f
= CREATE(fctx
);
141 gfreduce_create(&f
->r
, p
);
145 /*----- That's all, folks -------------------------------------------------*/