xref: /openbmc/qemu/crypto/random-gnutls.c (revision e2b47666fe1544959c89bd3ed159e9e37cc9fc73)
1b917da4cSDaniel P. Berrange /*
2b917da4cSDaniel P. Berrange  * QEMU Crypto random number provider
3b917da4cSDaniel P. Berrange  *
4b917da4cSDaniel P. Berrange  * Copyright (c) 2015-2016 Red Hat, Inc.
5b917da4cSDaniel P. Berrange  *
6b917da4cSDaniel P. Berrange  * This library is free software; you can redistribute it and/or
7b917da4cSDaniel P. Berrange  * modify it under the terms of the GNU Lesser General Public
8b917da4cSDaniel P. Berrange  * License as published by the Free Software Foundation; either
9*b7cbb874SThomas Huth  * version 2.1 of the License, or (at your option) any later version.
10b917da4cSDaniel P. Berrange  *
11b917da4cSDaniel P. Berrange  * This library is distributed in the hope that it will be useful,
12b917da4cSDaniel P. Berrange  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13b917da4cSDaniel P. Berrange  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14b917da4cSDaniel P. Berrange  * Lesser General Public License for more details.
15b917da4cSDaniel P. Berrange  *
16b917da4cSDaniel P. Berrange  * You should have received a copy of the GNU Lesser General Public
17b917da4cSDaniel P. Berrange  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18b917da4cSDaniel P. Berrange  *
19b917da4cSDaniel P. Berrange  */
20b917da4cSDaniel P. Berrange 
21b917da4cSDaniel P. Berrange #include "qemu/osdep.h"
22b917da4cSDaniel P. Berrange 
23b917da4cSDaniel P. Berrange #include "crypto/random.h"
24e688df6bSMarkus Armbruster #include "qapi/error.h"
25b917da4cSDaniel P. Berrange 
26b917da4cSDaniel P. Berrange #include <gnutls/gnutls.h>
27b917da4cSDaniel P. Berrange #include <gnutls/crypto.h>
28b917da4cSDaniel P. Berrange 
qcrypto_random_bytes(void * buf,size_t buflen,Error ** errp)29d049b1f2SRichard Henderson int qcrypto_random_bytes(void *buf,
30b917da4cSDaniel P. Berrange                          size_t buflen,
31b917da4cSDaniel P. Berrange                          Error **errp)
32b917da4cSDaniel P. Berrange {
33b917da4cSDaniel P. Berrange     int ret;
34b917da4cSDaniel P. Berrange 
35b917da4cSDaniel P. Berrange     ret = gnutls_rnd(GNUTLS_RND_RANDOM, buf, buflen);
36b917da4cSDaniel P. Berrange 
37b917da4cSDaniel P. Berrange     if (ret < 0) {
38b917da4cSDaniel P. Berrange         error_setg(errp, "Cannot get random bytes: %s",
39b917da4cSDaniel P. Berrange                    gnutls_strerror(ret));
40b917da4cSDaniel P. Berrange         return -1;
41b917da4cSDaniel P. Berrange     }
42b917da4cSDaniel P. Berrange 
43b917da4cSDaniel P. Berrange     return 0;
44b917da4cSDaniel P. Berrange }
45a3727816SGeert Martin Ijewski 
46a3727816SGeert Martin Ijewski 
qcrypto_random_init(Error ** errp G_GNUC_UNUSED)47a3727816SGeert Martin Ijewski int qcrypto_random_init(Error **errp G_GNUC_UNUSED) { return 0; }
48