]> git.proxmox.com Git - mirror_qemu.git/blame - crypto/init.c
analyze-migration.py: Remove trick on parsing ramblocks
[mirror_qemu.git] / crypto / init.c
CommitLineData
ddbb0d09
DB
1/*
2 * QEMU Crypto initialization
3 *
4 * Copyright (c) 2015 Red Hat, Inc.
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
b7cbb874 9 * version 2.1 of the License, or (at your option) any later version.
ddbb0d09
DB
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18 *
19 */
20
42f7a448 21#include "qemu/osdep.h"
ddbb0d09 22#include "crypto/init.h"
da34e65c 23#include "qapi/error.h"
62893b67 24#include "qemu/thread.h"
ddbb0d09
DB
25
26#ifdef CONFIG_GNUTLS
27#include <gnutls/gnutls.h>
28#include <gnutls/crypto.h>
91bfcdb0 29#endif
ddbb0d09 30
91bfcdb0 31#ifdef CONFIG_GCRYPT
62893b67
DB
32#include <gcrypt.h>
33#endif
34
a3727816
GMI
35#include "crypto/random.h"
36
ddbb0d09 37/* #define DEBUG_GNUTLS */
ddbb0d09
DB
38#ifdef DEBUG_GNUTLS
39static void qcrypto_gnutls_log(int level, const char *str)
40{
41 fprintf(stderr, "%d: %s", level, str);
42}
43#endif
44
45int qcrypto_init(Error **errp)
46{
91bfcdb0 47#ifdef CONFIG_GNUTLS
ddbb0d09
DB
48 int ret;
49 ret = gnutls_global_init();
50 if (ret < 0) {
51 error_setg(errp,
52 "Unable to initialize GNUTLS library: %s",
53 gnutls_strerror(ret));
54 return -1;
55 }
56#ifdef DEBUG_GNUTLS
57 gnutls_global_set_log_level(10);
58 gnutls_global_set_log_function(qcrypto_gnutls_log);
59#endif
91bfcdb0 60#endif
62893b67 61
91bfcdb0 62#ifdef CONFIG_GCRYPT
d6cca8e1 63 if (!gcry_check_version(NULL)) {
62893b67
DB
64 error_setg(errp, "Unable to initialize gcrypt");
65 return -1;
66 }
62893b67
DB
67 gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
68#endif
69
a3727816
GMI
70 if (qcrypto_random_init(errp) < 0) {
71 return -1;
72 }
73
ddbb0d09
DB
74 return 0;
75}