432c4e18 |
1 | /* -*-c-*- |
2 | * |
4edc47b8 |
3 | * $Id: field-parse.c,v 1.2 2004/04/01 21:28:41 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 $ |
4edc47b8 |
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 | * |
432c4e18 |
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 | { |
4edc47b8 |
64 | field *f = 0; |
65 | mp *m = MP_NEW, *b = MP_NEW; |
432c4e18 |
66 | |
4edc47b8 |
67 | switch (qd_enum(qd, "prime,niceprime,binpoly,binnorm")) { |
432c4e18 |
68 | case 0: |
69 | qd_delim(qd, ':'); |
4edc47b8 |
70 | if ((m = qd_getmp(qd)) == 0) goto done; |
432c4e18 |
71 | f = field_prime(m); |
72 | break; |
73 | case 1: |
74 | qd_delim(qd, ':'); |
4edc47b8 |
75 | if ((m = qd_getmp(qd)) == 0) goto done; |
432c4e18 |
76 | f = field_niceprime(m); |
77 | break; |
78 | case 2: |
79 | qd_delim(qd, ':'); |
4edc47b8 |
80 | if ((m = qd_getmp(qd)) == 0) goto done; |
432c4e18 |
81 | f = field_binpoly(m); |
82 | break; |
4edc47b8 |
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; |
432c4e18 |
90 | default: |
91 | f = 0; |
92 | break; |
93 | } |
4edc47b8 |
94 | done: |
432c4e18 |
95 | mp_drop(m); |
4edc47b8 |
96 | mp_drop(b); |
432c4e18 |
97 | return (f); |
98 | } |
99 | |
100 | /*----- That's all, folks -------------------------------------------------*/ |