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