the new makeinfo sets the FLOAT_NAME by default.
[gnutls.git] / tests / slow / keygen.c
blob583a3a71cab58852146ab49de89bed81763c2793
1 /*
2 * Copyright (C) 2008-2012 Free Software Foundation, Inc.
4 * Author: David Marín Carreño
6 * This file is part of GnuTLS.
8 * GnuTLS is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
13 * GnuTLS is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with GnuTLS; if not, write to the Free Software Foundation,
20 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 #ifdef HAVE_CONFIG_H
24 #include <config.h>
25 #endif
27 #include <stdlib.h>
28 #include <stdio.h>
29 #include <string.h>
30 #include <gnutls/gnutls.h>
31 #include <gnutls/x509.h>
32 #include <gnutls/abstract.h>
34 #include "utils.h"
36 #define MAX_TRIES 2
38 static int sec_param[MAX_TRIES] = {GNUTLS_SEC_PARAM_LOW, GNUTLS_SEC_PARAM_NORMAL};
40 static void
41 tls_log_func (int level, const char *str)
43 fprintf (stderr, "%s |<%d>| %s", "crq_key_id", level, str);
46 void
47 doit (void)
49 gnutls_x509_privkey_t pkey;
50 int ret, algorithm, i;
52 ret = gnutls_global_init ();
53 if (ret < 0)
54 fail ("gnutls_global_init: %d\n", ret);
56 gnutls_global_set_log_function (tls_log_func);
57 if (debug)
58 gnutls_global_set_log_level (4711);
60 for (i = 0; i < MAX_TRIES; i++)
62 for (algorithm = GNUTLS_PK_RSA; algorithm <= GNUTLS_PK_EC;
63 algorithm++)
65 if (algorithm == GNUTLS_PK_DH)
66 continue;
68 ret = gnutls_x509_privkey_init (&pkey);
69 if (ret < 0)
71 fail ("gnutls_x509_privkey_init: %d\n", ret);
74 ret =
75 gnutls_x509_privkey_generate (pkey, algorithm,
76 gnutls_sec_param_to_pk_bits
77 (algorithm,
78 sec_param[i]),
79 0);
80 if (ret < 0)
82 fail ("gnutls_x509_privkey_generate (%s): %s (%d)\n",
83 gnutls_pk_algorithm_get_name (algorithm),
84 gnutls_strerror (ret), ret);
86 else if (debug)
88 success ("Key[%s] generation ok: %d\n",
89 gnutls_pk_algorithm_get_name (algorithm),
90 ret);
93 ret = gnutls_x509_privkey_verify_params (pkey);
94 if (ret < 0)
96 fail ("gnutls_x509_privkey_generate (%s): %s (%d)\n",
97 gnutls_pk_algorithm_get_name (algorithm),
98 gnutls_strerror (ret), ret);
101 gnutls_x509_privkey_deinit (pkey);
105 gnutls_global_deinit ();