3 * $Id: group-parse.c,v 1.2 2004/04/03 03:32:05 mdw Exp $
5 * Parse group description strings
7 * (c) 2004 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Trivial IP Encryption (TrIPE).
14 * TrIPE is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * TrIPE 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 General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with TrIPE; if not, write to the Free Software Foundation,
26 * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
29 /*----- Revision history --------------------------------------------------*
31 * $Log: group-parse.c,v $
32 * Revision 1.2 2004/04/03 03:32:05 mdw
33 * General robustification.
35 * Revision 1.1 2004/04/01 12:50:09 mdw
36 * Add cyclic group abstraction, with test code. Separate off exponentation
37 * functions for better static linking. Fix a buttload of bugs on the way.
38 * Generally ensure that negative exponents do inversion correctly. Add
39 * table of standard prime-field subgroups. (Binary field subgroups are
40 * currently unimplemented but easy to add if anyone ever finds a good one.)
44 /*----- Header files ------------------------------------------------------*/
49 /*----- Main code ---------------------------------------------------------*/
51 /* --- @group_parse@ --- *
53 * Arguments: @qd_parse *qd@ = quick-and-dirty parser
55 * Returns: Group pointer, or null for failure.
57 * Use: Parses a group description and returns the group. This has
58 * the form `TYPE { SPEC }' where TYPE is `prime' or `ec', and
59 * SPEC is the appropriate kind of group specification of the
63 group
*group_parse(qd_parse
*qd
)
67 switch (qd_enum(qd
, "prime,ec")) {
71 if (dh_parse(qd
, &dp
)) break;
79 if (ec_infoparse(qd
, &ei
)) break;
84 if (!g
) qd
->e
= "bad group parameters";
88 /* --- @group_fromstring@ --- *
90 * Arguments: @const char *p@ = pointer to string to read
91 * @group **gg@ = where to put the group pointer
93 * Returns: Null if OK, or an error string.
95 * Use: Parses a group spec from a string, and returns the group.
98 const char *group_fromstring(const char *p
, group
**gg
)
105 if ((g
= group_parse(&qd
)) == 0) return (qd
.e
);
106 if (!qd_eofp(&qd
)) { G_DESTROYGROUP(g
); return ("junk at end of string"); }
111 /*----- That's all, folks -------------------------------------------------*/