3 * $Id: group-parse.c,v 1.1 2004/04/01 12:50:09 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.1 2004/04/01 12:50:09 mdw
33 * Add cyclic group abstraction, with test code. Separate off exponentation
34 * functions for better static linking. Fix a buttload of bugs on the way.
35 * Generally ensure that negative exponents do inversion correctly. Add
36 * table of standard prime-field subgroups. (Binary field subgroups are
37 * currently unimplemented but easy to add if anyone ever finds a good one.)
41 /*----- Header files ------------------------------------------------------*/
46 /*----- Main code ---------------------------------------------------------*/
48 /* --- @group_parse@ --- *
50 * Arguments: @qd_parse *qd@ = quick-and-dirty parser
52 * Returns: Group pointer, or null for failure.
54 * Use: Parses a group description and returns the group. This has
55 * the form `TYPE { SPEC }' where TYPE is `prime' or `ec', and
56 * SPEC is the appropriate kind of group specification of the
60 group
*group_parse(qd_parse
*qd
)
64 switch (qd_enum(qd
, "prime,ec")) {
68 if (dh_parse(qd
, &dp
)) break;
76 if (ec_infoparse(qd
, &ei
)) break;
84 /* --- @group_fromstring@ --- *
86 * Arguments: @const char *p@ = pointer to string to read
87 * @group **gg@ = where to put the group pointer
89 * Returns: Null if OK, or an error string.
91 * Use: Parses a group spec from a string, and returns the group.
94 const char *group_fromstring(const char *p
, group
**gg
)
101 if ((g
= group_parse(&qd
)) == 0) return (qd
.e
);
102 if (!qd_eofp(&qd
)) { G_DESTROYGROUP(g
); return ("junk at end of string"); }
107 /*----- That's all, folks -------------------------------------------------*/