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_infofromdata@ --- *
40 * Arguments: @dh_param *dp@ = parameters to fill in
41 * @pdata *pd@ = packed data structure
45 * Use: Fills in a parameters structure from a packed data block.
48 void dh_infofromdata(dh_param
*dp
, pdata
*pd
)
49 { dp
->p
= &pd
->p
; dp
->q
= &pd
->q
; dp
->g
= &pd
->g
; }
51 /* --- @dh_parse@, @dhbin_parse@ --- *
53 * Arguments: @qd_parse *qd@ = parser context
54 * @dh_param *dp@ = parameters to fill in
56 * Returns: Zero if OK, nonzero on error.
58 * Use: Parses a prime group string. This is either one of the
59 * standard group strings, or a %$p$%, %$q$%, %$g$% triple
60 * separated by commas.
63 static int parse(qd_parse
*qd
, gprime_param
*dp
)
65 mp
*p
= MP_NEW
, *q
= MP_NEW
, *g
= MP_NEW
;
67 if ((p
= qd_getmp(qd
)) == 0) goto fail
;
68 qd_delim(qd
, ','); if ((q
= qd_getmp(qd
)) == 0) goto fail
;
69 qd_delim(qd
, ','); if ((g
= qd_getmp(qd
)) == 0) goto fail
;
70 dp
->p
= p
; dp
->q
= q
; dp
->g
= g
;
73 mp_drop(p
); mp_drop(q
); mp_drop(g
);
77 int dh_parse(qd_parse
*qd
, dh_param
*dp
)
81 for (pe
= ptab
; pe
->name
; pe
++) {
82 if (qd_enum(qd
, pe
->name
) >= 0) {
83 dh_infofromdata(dp
, pe
->data
);
93 int dhbin_parse(qd_parse
*qd
, gbin_param
*gb
)
97 for (be
= bintab
; be
->name
; be
++) {
98 if (qd_enum(qd
, be
->name
) >= 0) {
99 dh_infofromdata(gb
, be
->data
);
109 /*----- Test rig ----------------------------------------------------------*/
115 int main(int argc
, char *argv
[])
123 gr
= fibrand_create(0);
124 fputs("checking standard prime groups:", stdout
);
126 for (pe
= ptab
; pe
->name
; pe
++) {
129 dh_infofromdata(&dp
, pe
->data
);
130 g
= group_prime(&dp
);
131 if (mp_bits(dp
.q
) > 2048 &&
132 (!argv
[1] || strcmp(argv
[1], "keen") != 0)) {
133 printf(" [%s skipped]", pe
->name
);
141 printf(" [%s failed: %s]", pe
->name
, e
);
144 printf(" %s", pe
->name
);
147 fputs(ok ?
" ok\n" : " failed\n", stdout
);
149 fputs("checking standard binary groups:", stdout
);
150 for (be
= bintab
; be
->name
; be
++) {
153 dh_infofromdata(&gb
, be
->data
);
154 g
= group_binary(&gb
);
159 printf(" [%s failed: %s]", be
->name
, e
);
162 printf(" %s", be
->name
);
165 fputs(ok ?
" ok\n" : " failed\n", stdout
);
166 gr
->ops
->destroy(gr
);
172 /*----- That's all, folks -------------------------------------------------*/