3 * Consistency checking for DSA keys
5 * (c) 2001 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 /*----- Header files ------------------------------------------------------*/
38 /*----- Main code ---------------------------------------------------------*/
40 /* --- @dsa_checkparam@ --- *
42 * Arguments: @keycheck *kc@ = keycheck state
43 * @const dsa_param *dp@ = pointer to the parameter set
44 * @const dsa_seed *ds@ = pointer to seed information
46 * Returns: Zero if all OK, or return status from function.
48 * Use: Checks a set of DSA parameters for consistency and security.
51 int dsa_checkparam(keycheck *kc, const dsa_param *dp, const dsa_seed *ds)
54 grand *r = dsarand_create(ds->p, ds->sz);
55 mp *p = MP_NEW, *q = MP_NEW;
60 r->ops->misc(r, DSARAND_PASSES, 2);
61 q = mprand(q, mp_bits(dp->q), r, 1);
62 if (!mp_eq(q, dp->q) &&
63 keycheck_report(kc, KCSEV_ERR, "q doesn't match seed provided"))
67 r->ops->misc(r, DSARAND_PASSES, 1);
68 for (i = 0; i <= ds->count; i++)
69 p = mprand(p, n, r, 0);
74 if (!mp_eq(p, dp->p) &&
75 keycheck_report(kc, KCSEV_ERR, "p doesn't match seed provided"))
84 return (dh_checkparam(kc, dp, 0, 0));
87 /*----- That's all, folks -------------------------------------------------*/