2 * QEMU Random Number Generator Backend
4 * Copyright IBM, Corp. 2012
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
16 #include "qemu/queue.h"
17 #include "qom/object.h"
19 #define TYPE_RNG_BACKEND "rng-backend"
20 #define RNG_BACKEND(obj) \
21 OBJECT_CHECK(RngBackend, (obj), TYPE_RNG_BACKEND)
22 #define RNG_BACKEND_GET_CLASS(obj) \
23 OBJECT_GET_CLASS(RngBackendClass, (obj), TYPE_RNG_BACKEND)
24 #define RNG_BACKEND_CLASS(klass) \
25 OBJECT_CLASS_CHECK(RngBackendClass, (klass), TYPE_RNG_BACKEND)
27 #define TYPE_RNG_BUILTIN "rng-builtin"
29 typedef struct RngRequest RngRequest;
30 typedef struct RngBackendClass RngBackendClass;
31 typedef struct RngBackend RngBackend;
33 typedef void (EntropyReceiveFunc)(void *opaque,
39 EntropyReceiveFunc *receive_entropy;
44 QSIMPLEQ_ENTRY(RngRequest) next;
47 struct RngBackendClass
49 ObjectClass parent_class;
51 void (*request_entropy)(RngBackend *s, RngRequest *req);
53 void (*opened)(RngBackend *s, Error **errp);
62 QSIMPLEQ_HEAD(, RngRequest) requests;
67 * rng_backend_request_entropy:
68 * @s: the backend to request entropy from
69 * @size: the number of bytes of data to request
70 * @receive_entropy: a function to be invoked when entropy is available
71 * @opaque: data that should be passed to @receive_entropy
73 * This function is used by the front-end to request entropy from an entropy
74 * source. This function can be called multiple times before @receive_entropy
75 * is invoked with different values of @receive_entropy and @opaque. The
76 * backend will queue each request and handle appropriately.
78 * The backend does not need to pass the full amount of data to @receive_entropy
79 * but will pass a value greater than 0.
81 void rng_backend_request_entropy(RngBackend *s, size_t size,
82 EntropyReceiveFunc *receive_entropy,
86 * rng_backend_free_request:
87 * @s: the backend that created the request
88 * @req: the request to finalize
90 * Used by child rng backend classes to finalize requests once they've been
91 * processed. The request is removed from the list of active requests and
94 void rng_backend_finalize_request(RngBackend *s, RngRequest *req);