pipewire: add pw_random()

Make pw_getrandom() more usable by handling the EINTR case and returning
< 0 when there was an error or not enough random data was available.

Make a new pw_random() function that uses pw_getrandom() but falls back
to a pseudo random number generator otherwise. This pseudo random number
generator is seeded with either data from the urandom source or from the
current time when pipewire is initialized.

In most cases where crytographic security is not required pw_random()
should be easier to use.
This commit is contained in:
Wim Taymans 2023-02-22 15:21:24 +01:00
parent 0b69f37a7c
commit 4e298f2fe7
6 changed files with 70 additions and 25 deletions

View file

@ -400,10 +400,8 @@ struct avb_maap *avb_maap_register(struct server *server)
maap->server = server;
pw_log_info("0x%"PRIx64" %d", server->entity_id, server->ifindex);
if (pw_getrandom(maap->xsubi, sizeof(maap->xsubi), 0) != sizeof(maap->xsubi)) {
res = -errno;
goto error_free;
}
pw_random(maap->xsubi, sizeof(maap->xsubi));
load_state(maap);
maap->source = pw_loop_add_io(server->impl->loop, fd, SPA_IO_IN, true, on_socket_data, maap);