~ubuntu-branches/ubuntu/raring/libgcrypt11/raring

« back to all changes in this revision

Viewing changes to tests/keygen.c

  • Committer: Bazaar Package Importer
  • Author(s): Steve Kowalik
  • Date: 2008-07-02 18:32:45 UTC
  • mfrom: (1.1.5 upstream) (2.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20080702183245-b1p9zumbhmq9wk4g
Tags: 1.4.1-1ubuntu1
* Merge from Debian unstable.
* Remaining Ubuntu changes:
  - Add libgcrypt11-udeb package.
  - Add clean-la.mk, and add a symlink for the .la
* Ubuntu changes dropped:
  - Build-Depends changes.
  - Drop patch 20_socket_nsl_linkage.diff, basically applied upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* keygen.c  -  key generation regression tests
2
 
 *      Copyright (C) 2003 Free Software Foundation, Inc.
 
2
 *      Copyright (C) 2003, 2005 Free Software Foundation, Inc.
3
3
 *
4
4
 * This file is part of Libgcrypt.
5
5
 *
18
18
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
19
19
 */
20
20
 
 
21
#ifdef HAVE_CONFIG_H
 
22
#include <config.h>
 
23
#endif
21
24
#include <stdio.h>
22
25
#include <stdlib.h>
23
26
#include <string.h>
27
30
 
28
31
 
29
32
static int verbose;
 
33
static int debug;
30
34
static int error_count;
31
35
 
32
36
static void
119
123
{
120
124
  gcry_sexp_t keyparm, key;
121
125
  int rc;
122
 
 
123
 
  if (verbose)
124
 
    fprintf (stderr, "creating 1024 bit RSA key using old interface\n");
 
126
  int i;
 
127
 
 
128
  /* Check that DSA generation works and that it can grok the qbits
 
129
     argument. */
 
130
  if (verbose)
 
131
    fprintf (stderr, "creating 5 1024 bit DSA keys\n");
 
132
  for (i=0; i < 5; i++)
 
133
    {
 
134
      rc = gcry_sexp_new (&keyparm, 
 
135
                          "(genkey\n"
 
136
                          " (dsa\n"
 
137
                          "  (nbits 4:1024)\n"
 
138
                          " ))", 0, 1);
 
139
      if (rc)
 
140
        die ("error creating S-expression: %s\n", gpg_strerror (rc));
 
141
      rc = gcry_pk_genkey (&key, keyparm);
 
142
      gcry_sexp_release (keyparm);
 
143
      if (rc)
 
144
        die ("error generating DSA key: %s\n", gpg_strerror (rc));
 
145
      gcry_sexp_release (key);
 
146
      if (verbose)
 
147
        fprintf (stderr, "  done\n");
 
148
    }
 
149
 
 
150
  if (verbose)
 
151
    fprintf (stderr, "creating 1536 bit DSA key\n");
 
152
  rc = gcry_sexp_new (&keyparm, 
 
153
                      "(genkey\n"
 
154
                      " (dsa\n"
 
155
                      "  (nbits 4:1536)\n"
 
156
                      "  (qbits 3:224)\n"
 
157
                      " ))", 0, 1);
 
158
  if (rc)
 
159
    die ("error creating S-expression: %s\n", gpg_strerror (rc));
 
160
  rc = gcry_pk_genkey (&key, keyparm);
 
161
  gcry_sexp_release (keyparm);
 
162
  if (rc)
 
163
    die ("error generating DSA key: %s\n", gpg_strerror (rc));
 
164
  if (debug)
 
165
    {
 
166
      char buffer[20000];
 
167
      gcry_sexp_sprint (key, GCRYSEXP_FMT_ADVANCED, buffer, sizeof buffer);
 
168
      if (verbose)
 
169
        printf ("=============================\n%s\n"
 
170
                "=============================\n", buffer);
 
171
    }
 
172
  gcry_sexp_release (key);
 
173
 
 
174
  if (verbose)
 
175
    fprintf (stderr, "creating 1024 bit RSA key\n");
125
176
  rc = gcry_sexp_new (&keyparm, 
126
177
                      "(genkey\n"
127
178
                      " (rsa\n"
137
188
  check_generated_rsa_key (key, 65537);
138
189
  gcry_sexp_release (key);
139
190
 
 
191
 
140
192
  if (verbose)
141
193
    fprintf (stderr, "creating 512 bit RSA key with e=257\n");
142
194
  rc = gcry_sexp_new (&keyparm, 
214
266
    }
215
267
}
216
268
 
 
269
 
 
270
static void
 
271
progress_cb (void *cb_data, const char *what, int printchar,
 
272
                  int current, int total)
 
273
{
 
274
  (void)cb_data;
 
275
  (void)what;
 
276
  (void)current;
 
277
  (void)total;
 
278
  
 
279
  if (printchar == '\n')
 
280
    fputs ( "<LF>", stdout);
 
281
  else
 
282
    putchar (printchar);
 
283
  fflush (stdout);
 
284
}
 
285
 
 
286
 
217
287
int
218
288
main (int argc, char **argv)
219
289
{
220
 
  int debug = 0;
221
 
 
222
290
  if (argc > 1 && !strcmp (argv[1], "--verbose"))
223
291
    verbose = 1;
224
292
  else if (argc > 1 && !strcmp (argv[1], "--debug"))
232
300
    gcry_control (GCRYCTL_SET_DEBUG_FLAGS, 1u , 0);
233
301
  /* No valuable keys are create, so we can speed up our RNG. */
234
302
  gcry_control (GCRYCTL_ENABLE_QUICK_RANDOM, 0);
 
303
  if (verbose)
 
304
    gcry_set_progress_handler ( progress_cb, NULL );
235
305
 
236
306
  check_rsa_keys ();
237
307
  check_nonce ();