]> git.proxmox.com Git - mirror_qemu.git/blob - include/qemu/guest-random.h
util/uri: Remove uri_string_unescape()
[mirror_qemu.git] / include / qemu / guest-random.h
1 /*
2 * QEMU guest-visible random functions
3 *
4 * Copyright 2019 Linaro, Ltd.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the Free
8 * Software Foundation; either version 2 of the License, or (at your option)
9 * any later version.
10 */
11
12 #ifndef QEMU_GUEST_RANDOM_H
13 #define QEMU_GUEST_RANDOM_H
14
15 /**
16 * qemu_guest_random_seed_main(const char *seedstr, Error **errp)
17 * @seedstr: a non-NULL pointer to a C string
18 * @errp: an error indicator
19 *
20 * The @seedstr value is that which accompanies the -seed argument.
21 * This forces qemu_guest_getrandom into deterministic mode.
22 *
23 * Returns 0 on success, < 0 on failure while setting *errp.
24 */
25 int qemu_guest_random_seed_main(const char *seedstr, Error **errp);
26
27 /**
28 * qemu_guest_random_seed_thread_part1(void)
29 *
30 * If qemu_getrandom is in deterministic mode, returns an
31 * independent seed for the new thread. Otherwise returns 0.
32 */
33 uint64_t qemu_guest_random_seed_thread_part1(void);
34
35 /**
36 * qemu_guest_random_seed_thread_part2(uint64_t seed)
37 * @seed: a value for the new thread.
38 *
39 * If qemu_guest_getrandom is in deterministic mode, this stores an
40 * independent seed for the new thread. Otherwise a no-op.
41 */
42 void qemu_guest_random_seed_thread_part2(uint64_t seed);
43
44 /**
45 * qemu_guest_getrandom(void *buf, size_t len, Error **errp)
46 * @buf: a buffer of bytes to be written
47 * @len: the number of bytes in @buf
48 * @errp: an error indicator
49 *
50 * Fills len bytes in buf with random data. This should only be used
51 * for data presented to the guest. Host-side crypto services should
52 * use qcrypto_random_bytes.
53 *
54 * Returns 0 on success, < 0 on failure while setting *errp.
55 */
56 int qemu_guest_getrandom(void *buf, size_t len, Error **errp);
57
58 /**
59 * qemu_guest_getrandom_nofail(void *buf, size_t len)
60 * @buf: a buffer of bytes to be written
61 * @len: the number of bytes in @buf
62 *
63 * Like qemu_guest_getrandom, but will assert for failure.
64 * Use this when there is no reasonable recovery.
65 */
66 void qemu_guest_getrandom_nofail(void *buf, size_t len);
67
68 #endif /* QEMU_GUEST_RANDOM_H */