Add an internal-representation no-op function.
[u/mdw/catacomb] / dsa-check.c
1 /* -*-c-*-
2 *
3 * $Id: dsa-check.c,v 1.1 2001/02/03 16:08:24 mdw Exp $
4 *
5 * Consistency checking for DSA keys
6 *
7 * (c) 2001 Straylight/Edgeware
8 */
9
10 /*----- Licensing notice --------------------------------------------------*
11 *
12 * This file is part of Catacomb.
13 *
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.
18 *
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.
23 *
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,
27 * MA 02111-1307, USA.
28 */
29
30 /*----- Revision history --------------------------------------------------*
31 *
32 * $Log: dsa-check.c,v $
33 * Revision 1.1 2001/02/03 16:08:24 mdw
34 * Add consistency checking for public keys.
35 *
36 */
37
38 /*----- Header files ------------------------------------------------------*/
39
40 #include "dh.h"
41 #include "dsa.h"
42 #include "dsarand.h"
43 #include "grand.h"
44 #include "keycheck.h"
45 #include "mp.h"
46 #include "mprand.h"
47
48 /*----- Main code ---------------------------------------------------------*/
49
50 /* --- @dsa_checkparam@ --- *
51 *
52 * Arguments: @keycheck *kc@ = keycheck state
53 * @const dsa_param *dp@ = pointer to the parameter set
54 * @const dsa_seed *ds@ = pointer to seed information
55 *
56 * Returns: Zero if all OK, or return status from function.
57 *
58 * Use: Checks a set of DSA parameters for consistency and security.
59 */
60
61 int dsa_checkparam(keycheck *kc, const dsa_param *dp, const dsa_seed *ds)
62 {
63 if (ds) {
64 grand *r = dsarand_create(ds->p, ds->sz);
65 mp *p = MP_NEW, *q = MP_NEW;
66 int rc = 0;
67 unsigned i;
68 unsigned long n;
69
70 r->ops->misc(r, DSARAND_PASSES, 2);
71 q = mprand(q, mp_bits(dp->q), r, 1);
72 if (!mp_eq(q, dp->q) &&
73 keycheck_report(kc, KCSEV_ERR, "q doesn't match seed provided"))
74 rc = -1;
75 else {
76 n = mp_bits(dp->p);
77 r->ops->misc(r, DSARAND_PASSES, 1);
78 for (i = 0; i <= ds->count; i++)
79 p = mprand(p, n, r, 0);
80 q = mp_lsl(q, q, 1);
81 mp_div(0, &q, p, q);
82 p = mp_sub(p, p, q);
83 p->v[0] |= 1;
84 if (!mp_eq(p, dp->p) &&
85 keycheck_report(kc, KCSEV_ERR, "p doesn't match seed provided"))
86 rc = -1;
87 }
88 mp_drop(p);
89 mp_drop(q);
90 r->ops->destroy(r);
91 if (rc)
92 return (rc);
93 }
94 return (dh_checkparam(kc, dp, 0, 0));
95 }
96
97 /*----- That's all, folks -------------------------------------------------*/