3 * $Id: dh-param.c,v 1.2 2004/04/08 01:36:15 mdw Exp $
5 * Reading Diffie-Hellman parameters
7 * (c) 2004 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
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.
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.
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,
30 /*----- Header files ------------------------------------------------------*/
35 /*----- Main code ---------------------------------------------------------*/
37 /* --- @dh_parse@ --- *
39 * Arguments: @qd_parse *qd@ = parser context
40 * @dh_param *dp@ = parameters to fill in
42 * Returns: Zero if OK, nonzero on error.
44 * Use: Parses a prime group string. This is either one of the
45 * standard group strings, or a %$p$%, %$q$%, %$g$% triple
46 * separated by commas.
49 static void getinfo(dh_param
*dp
, pdata
*pd
)
50 { dp
->p
= &pd
->p
; dp
->q
= &pd
->q
; dp
->g
= &pd
->g
; }
52 int dh_parse(qd_parse
*qd
, dh_param
*dp
)
54 mp
*p
= MP_NEW
, *q
= MP_NEW
, *g
= MP_NEW
;
57 for (pe
= ptab
; pe
->name
; pe
++) {
58 if (qd_enum(qd
, pe
->name
) >= 0) {
59 getinfo(dp
, pe
->data
);
63 if ((p
= qd_getmp(qd
)) == 0) goto fail
;
64 qd_delim(qd
, ','); if ((q
= qd_getmp(qd
)) == 0) goto fail
;
65 qd_delim(qd
, ','); if ((g
= qd_getmp(qd
)) == 0) goto fail
;
66 dp
->p
= p
; dp
->q
= q
; dp
->g
= g
;
71 mp_drop(p
); mp_drop(q
); mp_drop(g
);
75 /*----- Test rig ----------------------------------------------------------*/
88 gr
= fibrand_create(0);
89 fputs("checking standard prime fields: ", stdout
);
90 for (pe
= ptab
; pe
->name
; pe
++) {
93 getinfo(&dp
, pe
->data
);
99 fprintf(stderr
, "\n*** group %s fails: %s\n", pe
->name
, e
);
105 gr
->ops
->destroy(gr
);
106 fputs(ok ?
" ok\n" : " failed\n", stdout
);
112 /*----- That's all, folks -------------------------------------------------*/