3 * $Id: dsa-check.c,v 1.2 2004/04/08 01:36:15 mdw Exp $
5 * Consistency checking for DSA keys
7 * (c) 2001 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 ------------------------------------------------------*/
40 /*----- Main code ---------------------------------------------------------*/
42 /* --- @dsa_checkparam@ --- *
44 * Arguments: @keycheck *kc@ = keycheck state
45 * @const dsa_param *dp@ = pointer to the parameter set
46 * @const dsa_seed *ds@ = pointer to seed information
48 * Returns: Zero if all OK, or return status from function.
50 * Use: Checks a set of DSA parameters for consistency and security.
53 int dsa_checkparam(keycheck *kc, const dsa_param *dp, const dsa_seed *ds)
56 grand *r = dsarand_create(ds->p, ds->sz);
57 mp *p = MP_NEW, *q = MP_NEW;
62 r->ops->misc(r, DSARAND_PASSES, 2);
63 q = mprand(q, mp_bits(dp->q), r, 1);
64 if (!mp_eq(q, dp->q) &&
65 keycheck_report(kc, KCSEV_ERR, "q doesn't match seed provided"))
69 r->ops->misc(r, DSARAND_PASSES, 1);
70 for (i = 0; i <= ds->count; i++)
71 p = mprand(p, n, r, 0);
76 if (!mp_eq(p, dp->p) &&
77 keycheck_report(kc, KCSEV_ERR, "p doesn't match seed provided"))
86 return (dh_checkparam(kc, dp, 0, 0));
89 /*----- That's all, folks -------------------------------------------------*/