X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/3688eb757240b2332f67ec827be8caf6f6abe924..95ccefe3ce59a0773f915aca6948d5b6f1f7c882:/dh-param.c diff --git a/dh-param.c b/dh-param.c index b02e84b..e1e5374 100644 --- a/dh-param.c +++ b/dh-param.c @@ -7,7 +7,7 @@ * (c) 2004 Straylight/Edgeware */ -/*----- Licensing notice --------------------------------------------------* +/*----- Licensing notice --------------------------------------------------* * * This file is part of Catacomb. * @@ -15,12 +15,12 @@ * it under the terms of the GNU Library General Public License as * published by the Free Software Foundation; either version 2 of the * License, or (at your option) any later version. - * + * * Catacomb is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU Library General Public License for more details. - * + * * You should have received a copy of the GNU Library General Public * License along with Catacomb; if not, write to the Free * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, @@ -35,6 +35,19 @@ /*----- Main code ---------------------------------------------------------*/ +/* ---- @dh_infofromdata@ --- * + * + * Arguments: @dh_param *dp@ = parameters to fill in + * @pdata *pd@ = packed data structure + * + * Returns: --- + * + * Use: Fills in a parameters structure from a packed data block. + */ + +void dh_infofromdata(dh_param *dp, pdata *pd) + { dp->p = &pd->p; dp->q = &pd->q; dp->g = &pd->g; } + /* --- @dh_parse@, @dhbin_parse@ --- * * * Arguments: @qd_parse *qd@ = parser context @@ -47,9 +60,6 @@ * separated by commas. */ -static void getinfo(dh_param *dp, pdata *pd) - { dp->p = &pd->p; dp->q = &pd->q; dp->g = &pd->g; } - static int parse(qd_parse *qd, gprime_param *dp) { mp *p = MP_NEW, *q = MP_NEW, *g = MP_NEW; @@ -70,7 +80,7 @@ int dh_parse(qd_parse *qd, dh_param *dp) for (pe = ptab; pe->name; pe++) { if (qd_enum(qd, pe->name) >= 0) { - getinfo(dp, pe->data); + dh_infofromdata(dp, pe->data); goto found; } } @@ -86,7 +96,7 @@ int dhbin_parse(qd_parse *qd, gbin_param *gb) for (be = bintab; be->name; be++) { if (qd_enum(qd, be->name) >= 0) { - getinfo(gb, be->data); + dh_infofromdata(gb, be->data); goto found; } } @@ -107,53 +117,54 @@ int main(int argc, char *argv[]) const pentry *pe; const binentry *be; const char *e; - int ok = 1; + int ok = 1, aok = 1; grand *gr; gr = fibrand_create(0); - fputs("checking standard prime groups...\n", stdout); + fputs("checking standard prime groups:", stdout); + fflush(stdout); for (pe = ptab; pe->name; pe++) { dh_param dp; group *g; - getinfo(&dp, pe->data); - printf(" %s: ", pe->name); + dh_infofromdata(&dp, pe->data); g = group_prime(&dp); - if (mp_bits(dp.q) > 2048 && + if (mp_bits(dp.p) > 2048 && (!argv[1] || strcmp(argv[1], "keen") != 0)) { - fputs("skipping\n", stdout); + printf(" [%s skipped]", pe->name); + fflush(stdout); continue; } - fflush(stdout); e = G_CHECK(g, gr); G_DESTROYGROUP(g); dh_paramfree(&dp); if (e) { - printf("fails: %s\n", e); - ok = 0; + printf(" [%s failed: %s]", pe->name, e); + ok = aok = 0; } else - fputs("ok\n", stdout); + printf(" %s", pe->name); + fflush(stdout); } - fputs("checking standard binary groups...\n", stdout); + fputs(ok ? " ok\n" : " failed\n", stdout); + ok = 1; + fputs("checking standard binary groups:", stdout); for (be = bintab; be->name; be++) { gbin_param gb; group *g; - getinfo(&gb, be->data); - printf(" %s: ", be->name); + dh_infofromdata(&gb, be->data); g = group_binary(&gb); - fflush(stdout); e = G_CHECK(g, gr); G_DESTROYGROUP(g); dh_paramfree(&gb); if (e) { - printf("fails: %s\n", e); - ok = 0; + printf(" [%s failed: %s]", be->name, e); + ok = aok = 0; } else - fputs("ok\n", stdout); + printf(" %s", be->name); + fflush(stdout); } + fputs(ok ? " ok\n" : " failed\n", stdout); gr->ops->destroy(gr); - if (ok) - fputs("all ok\n", stdout); - return (!ok); + return (!aok); } #endif