Allow explicit group parameters for DH groups.
[u/mdw/catacomb] / field-parse.c
1 /* -*-c-*-
2 *
3 * $Id: field-parse.c,v 1.2 2004/04/01 21:28:41 mdw Exp $
4 *
5 * Parse field descriptions
6 *
7 * (c) 2004 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-parse.c,v $
33 * Revision 1.2 2004/04/01 21:28:41 mdw
34 * Normal basis support (translates to poly basis internally). Rewrite
35 * EC and prime group table generators in awk, so that they can reuse data
36 * for repeated constants.
37 *
38 * Revision 1.1 2004/03/27 17:54:11 mdw
39 * Standard curves and curve checking.
40 *
41 */
42
43 /*----- Header files ------------------------------------------------------*/
44
45 #include "field.h"
46
47 /*----- Main code ---------------------------------------------------------*/
48
49 /* --- @field_parse@ --- *
50 *
51 * Arguments: @qd_parse *qd@ = parser context
52 *
53 * Returns: Field pointer if OK, or null.
54 *
55 * Use: Parses a field description, which has the form
56 *
57 * * `prime', `niceprime' or `binpoly'
58 * * an optional `:'
59 * * the field modulus
60 */
61
62 field *field_parse(qd_parse *qd)
63 {
64 field *f = 0;
65 mp *m = MP_NEW, *b = MP_NEW;
66
67 switch (qd_enum(qd, "prime,niceprime,binpoly,binnorm")) {
68 case 0:
69 qd_delim(qd, ':');
70 if ((m = qd_getmp(qd)) == 0) goto done;
71 f = field_prime(m);
72 break;
73 case 1:
74 qd_delim(qd, ':');
75 if ((m = qd_getmp(qd)) == 0) goto done;
76 f = field_niceprime(m);
77 break;
78 case 2:
79 qd_delim(qd, ':');
80 if ((m = qd_getmp(qd)) == 0) goto done;
81 f = field_binpoly(m);
82 break;
83 case 3:
84 qd_delim(qd, ':');
85 if ((m = qd_getmp(qd)) == 0) goto done;
86 qd_delim(qd, ',');
87 if ((b = qd_getmp(qd)) == 0) goto done;
88 f = field_binnorm(m, b);
89 break;
90 default:
91 f = 0;
92 break;
93 }
94 done:
95 mp_drop(m);
96 mp_drop(b);
97 return (f);
98 }
99
100 /*----- That's all, folks -------------------------------------------------*/