Add cyclic group abstraction, with test code. Separate off exponentation
[u/mdw/catacomb] / field.c
CommitLineData
2685767a 1/* -*-c-*-
2 *
34e4f738 3 * $Id: field.c,v 1.3 2004/04/01 12:50:09 mdw Exp $
dbfee00a 4 *
5 * Abstract field operations
2685767a 6 *
2685767a 7 * (c) 2001 Straylight/Edgeware
8 */
9
10/*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of Catacomb.
13 *
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.
18 *
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.
23 *
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,
27 * MA 02111-1307, USA.
28 */
29
30/*----- Revision history --------------------------------------------------*
31 *
32 * $Log: field.c,v $
34e4f738 33 * Revision 1.3 2004/04/01 12:50:09 mdw
34 * Add cyclic group abstraction, with test code. Separate off exponentation
35 * functions for better static linking. Fix a buttload of bugs on the way.
36 * Generally ensure that negative exponents do inversion correctly. Add
37 * table of standard prime-field subgroups. (Binary field subgroups are
38 * currently unimplemented but easy to add if anyone ever finds a good one.)
39 *
c3caa2fa 40 * Revision 1.2 2004/03/21 22:52:06 mdw
41 * Merge and close elliptic curve branch.
42 *
dbfee00a 43 * Revision 1.1.4.1 2003/06/10 13:43:53 mdw
44 * Simple (non-projective) curves over prime fields now seem to work.
45 *
2685767a 46 * Revision 1.1 2001/05/07 17:30:13 mdw
47 * Add an internal-representation no-op function.
48 *
49 */
50
51/*----- Header files ------------------------------------------------------*/
52
53#include "field.h"
54#include "mp.h"
55
56/*----- Main code ---------------------------------------------------------*/
57
58/* --- @field_id@ --- *
59 *
60 * Arguments: @field *f@ = pointer to a field
61 * @mp *d@ = a destination element
62 * @mp *x@ = a source element
63 *
64 * Returns: The result element.
65 *
66 * Use: An identity operation which can be used if your field has no
67 * internal representation.
68 */
69
70mp *field_id(field *f, mp *d, mp *x)
71{
72 x = MP_COPY(x);
73 if (d) MP_DROP(d);
74 return (x);
75}
76
34e4f738 77/* --- @field_samep@ --- *
78 *
79 * Arguments: @field *f, *g@ = two fields
80 *
81 * Returns: Nonzero if the fields are identical (not just isomorphic).
82 *
83 * Use: Checks for sameness of fields. This function does the full
84 * check, not just the field-type-specific check done by the
85 * @sampep@ field operation.
86 */
87
88int field_samep(field *f, field *g)
89{
90 return (f->ops == g->ops && F_SAMEP(f, g));
91}
92
93/* --- @field_stdsamep@ --- *
94 *
95 * Arguments: @field *f, *g@ = two fields
96 *
97 * Returns: Nonzero if the fields are identical (not just isomorphic).
98 *
99 * Use: Standard sameness check, based on equality of the @m@
100 * member.
101 */
102
103int field_stdsamep(field *f, field *g)
104{
105 return (MP_EQ(f->m, g->m));
106}
107
2685767a 108/*----- That's all, folks -------------------------------------------------*/