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 ------------------------------------------------------*/
36 /*----- Main code ---------------------------------------------------------*/
38 /* --- @dh_parse@, @dhbin_parse@ --- *
40 * Arguments: @qd_parse *qd@ = parser context
41 * @dh_param *dp@ = parameters to fill in
43 * Returns: Zero if OK, nonzero on error.
45 * Use: Parses a prime group string. This is either one of the
46 * standard group strings, or a %$p$%, %$q$%, %$g$% triple
47 * separated by commas.
50 static void getinfo(dh_param
*dp
, pdata
*pd
)
51 { dp
->p
= &pd
->p
; dp
->q
= &pd
->q
; dp
->g
= &pd
->g
; }
53 static int parse(qd_parse
*qd
, gprime_param
*dp
)
55 mp
*p
= MP_NEW
, *q
= MP_NEW
, *g
= MP_NEW
;
57 if ((p
= qd_getmp(qd
)) == 0) goto fail
;
58 qd_delim(qd
, ','); if ((q
= qd_getmp(qd
)) == 0) goto fail
;
59 qd_delim(qd
, ','); if ((g
= qd_getmp(qd
)) == 0) goto fail
;
60 dp
->p
= p
; dp
->q
= q
; dp
->g
= g
;
63 mp_drop(p
); mp_drop(q
); mp_drop(g
);
67 int dh_parse(qd_parse
*qd
, dh_param
*dp
)
71 for (pe
= ptab
; pe
->name
; pe
++) {
72 if (qd_enum(qd
, pe
->name
) >= 0) {
73 getinfo(dp
, pe
->data
);
83 int dhbin_parse(qd_parse
*qd
, gbin_param
*gb
)
87 for (be
= bintab
; be
->name
; be
++) {
88 if (qd_enum(qd
, be
->name
) >= 0) {
89 getinfo(gb
, be
->data
);
99 /*----- Test rig ----------------------------------------------------------*/
105 int main(int argc
, char *argv
[])
113 gr
= fibrand_create(0);
114 fputs("checking standard prime groups...\n", stdout
);
115 for (pe
= ptab
; pe
->name
; pe
++) {
118 getinfo(&dp
, pe
->data
);
119 printf(" %s: ", pe
->name
);
120 g
= group_prime(&dp
);
121 if (mp_bits(dp
.q
) > 2048 &&
122 (!argv
[1] || strcmp(argv
[1], "keen") != 0)) {
123 fputs("skipping\n", stdout
);
131 printf("fails: %s\n", e
);
134 fputs("ok\n", stdout
);
136 fputs("checking standard binary groups...\n", stdout
);
137 for (be
= bintab
; be
->name
; be
++) {
140 getinfo(&gb
, be
->data
);
141 printf(" %s: ", be
->name
);
142 g
= group_binary(&gb
);
148 printf("fails: %s\n", e
);
151 fputs("ok\n", stdout
);
153 gr
->ops
->destroy(gr
);
155 fputs("all ok\n", stdout
);
161 /*----- That's all, folks -------------------------------------------------*/