random-util: introduce random_bytes_allocate_iovec() helper function
It is similar to crypto_random_bytes_allocate_iovec(), but possibly insecure.
This commit is contained in:
committed by
Lennart Poettering
parent
4368cc8164
commit
b51c133a4e
@@ -96,6 +96,19 @@ void random_bytes(void *p, size_t n) {
|
||||
fallback_random_bytes(p, n);
|
||||
}
|
||||
|
||||
int random_bytes_allocate_iovec(size_t n, struct iovec *ret) {
|
||||
assert(ret);
|
||||
|
||||
void *p = malloc(MAX(n, 1U));
|
||||
if (!p)
|
||||
return -ENOMEM;
|
||||
|
||||
random_bytes(p, n);
|
||||
|
||||
*ret = IOVEC_MAKE(TAKE_PTR(p), n);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int crypto_random_bytes(void *p, size_t n) {
|
||||
assert(p || n == 0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user