2012-06-25 17:03:47 +02:00
|
|
|
/*
|
|
|
|
* QEMU Random Number Generator Backend
|
|
|
|
*
|
|
|
|
* Copyright IBM, Corp. 2012
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Anthony Liguori <aliguori@us.ibm.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2 or later.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef QEMU_RNG_H
|
|
|
|
#define QEMU_RNG_H
|
|
|
|
|
2019-08-12 07:23:49 +02:00
|
|
|
#include "qemu/queue.h"
|
2012-12-17 18:19:50 +01:00
|
|
|
#include "qom/object.h"
|
2012-06-25 17:03:47 +02:00
|
|
|
|
|
|
|
#define TYPE_RNG_BACKEND "rng-backend"
|
2020-08-31 23:07:37 +02:00
|
|
|
OBJECT_DECLARE_TYPE(RngBackend, RngBackendClass,
|
qom: Remove module_obj_name parameter from OBJECT_DECLARE* macros
One of the goals of having less boilerplate on QOM declarations
is to avoid human error. Requiring an extra argument that is
never used is an opportunity for mistakes.
Remove the unused argument from OBJECT_DECLARE_TYPE and
OBJECT_DECLARE_SIMPLE_TYPE.
Coccinelle patch used to convert all users of the macros:
@@
declarer name OBJECT_DECLARE_TYPE;
identifier InstanceType, ClassType, lowercase, UPPERCASE;
@@
OBJECT_DECLARE_TYPE(InstanceType, ClassType,
- lowercase,
UPPERCASE);
@@
declarer name OBJECT_DECLARE_SIMPLE_TYPE;
identifier InstanceType, lowercase, UPPERCASE;
@@
OBJECT_DECLARE_SIMPLE_TYPE(InstanceType,
- lowercase,
UPPERCASE);
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Acked-by: Igor Mammedov <imammedo@redhat.com>
Acked-by: Paul Durrant <paul@xen.org>
Acked-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20200916182519.415636-4-ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2020-09-16 20:25:17 +02:00
|
|
|
RNG_BACKEND)
|
2012-06-25 17:03:47 +02:00
|
|
|
|
2019-08-20 18:06:15 +02:00
|
|
|
#define TYPE_RNG_BUILTIN "rng-builtin"
|
|
|
|
|
2016-03-03 09:37:16 +01:00
|
|
|
typedef struct RngRequest RngRequest;
|
2012-06-25 17:03:47 +02:00
|
|
|
|
|
|
|
typedef void (EntropyReceiveFunc)(void *opaque,
|
|
|
|
const void *data,
|
|
|
|
size_t size);
|
|
|
|
|
2016-03-03 09:37:16 +01:00
|
|
|
struct RngRequest
|
|
|
|
{
|
|
|
|
EntropyReceiveFunc *receive_entropy;
|
|
|
|
uint8_t *data;
|
|
|
|
void *opaque;
|
|
|
|
size_t offset;
|
|
|
|
size_t size;
|
2016-03-03 14:16:11 +01:00
|
|
|
QSIMPLEQ_ENTRY(RngRequest) next;
|
2016-03-03 09:37:16 +01:00
|
|
|
};
|
|
|
|
|
2012-06-25 17:03:47 +02:00
|
|
|
struct RngBackendClass
|
|
|
|
{
|
|
|
|
ObjectClass parent_class;
|
|
|
|
|
2016-03-03 09:37:18 +01:00
|
|
|
void (*request_entropy)(RngBackend *s, RngRequest *req);
|
2012-06-25 17:03:47 +02:00
|
|
|
|
|
|
|
void (*opened)(RngBackend *s, Error **errp);
|
|
|
|
};
|
|
|
|
|
|
|
|
struct RngBackend
|
|
|
|
{
|
|
|
|
Object parent;
|
|
|
|
|
|
|
|
/*< protected >*/
|
|
|
|
bool opened;
|
2018-12-06 11:58:10 +01:00
|
|
|
QSIMPLEQ_HEAD(, RngRequest) requests;
|
2012-06-25 17:03:47 +02:00
|
|
|
};
|
|
|
|
|
2016-03-03 09:37:17 +01:00
|
|
|
|
2012-06-25 17:03:47 +02:00
|
|
|
/**
|
|
|
|
* rng_backend_request_entropy:
|
|
|
|
* @s: the backend to request entropy from
|
|
|
|
* @size: the number of bytes of data to request
|
|
|
|
* @receive_entropy: a function to be invoked when entropy is available
|
|
|
|
* @opaque: data that should be passed to @receive_entropy
|
|
|
|
*
|
|
|
|
* This function is used by the front-end to request entropy from an entropy
|
|
|
|
* source. This function can be called multiple times before @receive_entropy
|
|
|
|
* is invoked with different values of @receive_entropy and @opaque. The
|
2012-11-21 06:51:21 +01:00
|
|
|
* backend will queue each request and handle appropriately.
|
2012-06-25 17:03:47 +02:00
|
|
|
*
|
|
|
|
* The backend does not need to pass the full amount of data to @receive_entropy
|
2012-11-21 06:51:21 +01:00
|
|
|
* but will pass a value greater than 0.
|
2012-06-25 17:03:47 +02:00
|
|
|
*/
|
|
|
|
void rng_backend_request_entropy(RngBackend *s, size_t size,
|
|
|
|
EntropyReceiveFunc *receive_entropy,
|
|
|
|
void *opaque);
|
2016-03-03 09:37:17 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* rng_backend_free_request:
|
|
|
|
* @s: the backend that created the request
|
|
|
|
* @req: the request to finalize
|
|
|
|
*
|
|
|
|
* Used by child rng backend classes to finalize requests once they've been
|
|
|
|
* processed. The request is removed from the list of active requests and
|
|
|
|
* deleted.
|
|
|
|
*/
|
|
|
|
void rng_backend_finalize_request(RngBackend *s, RngRequest *req);
|
2012-06-25 17:03:47 +02:00
|
|
|
#endif
|