1
2
3
4
5
6
7
8
9
10
11
12
13#ifndef QEMU_RNG_H
14#define QEMU_RNG_H
15
16#include "qemu/queue.h"
17#include "qom/object.h"
18
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)
26
27#define TYPE_RNG_BUILTIN "rng-builtin"
28
29typedef struct RngRequest RngRequest;
30typedef struct RngBackendClass RngBackendClass;
31typedef struct RngBackend RngBackend;
32
33typedef void (EntropyReceiveFunc)(void *opaque,
34 const void *data,
35 size_t size);
36
37struct RngRequest
38{
39 EntropyReceiveFunc *receive_entropy;
40 uint8_t *data;
41 void *opaque;
42 size_t offset;
43 size_t size;
44 QSIMPLEQ_ENTRY(RngRequest) next;
45};
46
47struct RngBackendClass
48{
49 ObjectClass parent_class;
50
51 void (*request_entropy)(RngBackend *s, RngRequest *req);
52
53 void (*opened)(RngBackend *s, Error **errp);
54};
55
56struct RngBackend
57{
58 Object parent;
59
60
61 bool opened;
62 QSIMPLEQ_HEAD(, RngRequest) requests;
63};
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81void rng_backend_request_entropy(RngBackend *s, size_t size,
82 EntropyReceiveFunc *receive_entropy,
83 void *opaque);
84
85
86
87
88
89
90
91
92
93
94void rng_backend_finalize_request(RngBackend *s, RngRequest *req);
95#endif
96