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
30 #include <gnutls/gnutls.h>
31 #include <gnutls/x509.h>
32 #include <gnutls/abstract.h>
38 static int sec_param
[MAX_TRIES
] = {GNUTLS_SEC_PARAM_LOW
, GNUTLS_SEC_PARAM_NORMAL
};
41 tls_log_func (int level
, const char *str
)
43 fprintf (stderr
, "%s |<%d>| %s", "crq_key_id", level
, str
);
49 gnutls_x509_privkey_t pkey
;
50 int ret
, algorithm
, i
;
52 ret
= gnutls_global_init ();
54 fail ("gnutls_global_init: %d\n", ret
);
56 gnutls_global_set_log_function (tls_log_func
);
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
;
65 if (algorithm
== GNUTLS_PK_DH
)
68 ret
= gnutls_x509_privkey_init (&pkey
);
71 fail ("gnutls_x509_privkey_init: %d\n", ret
);
75 gnutls_x509_privkey_generate (pkey
, algorithm
,
76 gnutls_sec_param_to_pk_bits
82 fail ("gnutls_x509_privkey_generate (%s): %s (%d)\n",
83 gnutls_pk_algorithm_get_name (algorithm
),
84 gnutls_strerror (ret
), ret
);
88 success ("Key[%s] generation ok: %d\n",
89 gnutls_pk_algorithm_get_name (algorithm
),
93 ret
= gnutls_x509_privkey_verify_params (pkey
);
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 ();