3 * $Id: f-binpoly.c,v 1.1.2.1 2004/03/21 22:39:46 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.1.2.1 2004/03/21 22:39:46 mdw
34 * Elliptic curves on binary fields work.
38 /*----- Header files ------------------------------------------------------*/
46 /*----- Data structures ---------------------------------------------------*/
53 /*----- Main code ---------------------------------------------------------*/
55 /* --- Field operations --- */
57 static void fdestroy(field
*ff
)
60 gfreduce_destroy(&f
->r
);
64 static int fzerop(field
*ff
, mp
*x
)
69 static mp
*fadd(field
*ff
, mp
*d
, mp
*x
, mp
*y
)
71 return (gf_add(d
, x
, y
));
74 static mp
*fmul(field
*ff
, mp
*d
, mp
*x
, mp
*y
)
78 return (gfreduce_do(&f
->r
, d
, d
));
81 static mp
*fsqr(field
*ff
, mp
*d
, mp
*x
)
85 return (gfreduce_do(&f
->r
, d
, d
));
88 static mp
*finv(field
*ff
, mp
*d
, mp
*x
)
91 gf_gcd(0, 0, &d
, f
->r
.p
, x
);
95 static mp
*freduce(field
*ff
, mp
*d
, mp
*x
)
98 return (gfreduce_do(&f
->r
, d
, x
));
101 static mp
*fsqrt(field
*ff
, mp
*d
, mp
*x
)
103 fctx
*f
= (fctx
*)ff
;
104 return (gfreduce_sqrt(&f
->r
, d
, x
));
107 static mp
*fquadsolve(field
*ff
, mp
*d
, mp
*x
)
109 fctx
*f
= (fctx
*)ff
;
110 return (gfreduce_quadsolve(&f
->r
, d
, x
));
113 /* --- Field operations table --- */
115 static field_ops fops
= {
118 fzerop
, field_id
, fadd
, fadd
, fmul
, fsqr
, finv
, freduce
, fsqrt
,
123 /* --- @field_binpoly@ --- *
125 * Arguments: @mp *p@ = the reduction polynomial
127 * Returns: A pointer to the field.
129 * Use: Creates a field structure for a binary field mod @p@.
132 field
*field_binpoly(mp
*p
)
134 fctx
*f
= CREATE(fctx
);
138 gfreduce_create(&f
->r
, p
);
142 /*----- That's all, folks -------------------------------------------------*/