hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit f55f1cf85c5935a3bbf972f6ca97e1c3a0f241e0
parent 07f375d5e61278473de5c26e7c529546acf20088
Author: Lorenz (xha) <me@xha.li>
Date:   Sat, 25 Nov 2023 15:18:20 +0100

OpenBSD: add crypto::random

Signed-off-by: Lorenz (xha) <me@xha.li>

Diffstat:
Acrypto/random/+openbsd.ha | 19+++++++++++++++++++
1 file changed, 19 insertions(+), 0 deletions(-)

diff --git a/crypto/random/+openbsd.ha b/crypto/random/+openbsd.ha @@ -0,0 +1,19 @@ +// SPDX-License-Identifier: MPL-2.0 +// (c) Hare authors <https://harelang.org> + +use rt; +use io; + +// Fills the given buffer with cryptographically random data. If the system is +// unable to provide random data, abort. If you need to handle errors or want to +// use whatever random data the system can provide, even if less than the +// requested amount, use [[stream]] instead. +export fn buffer(buf: []u8) void = { + rt::arc4random_buf(buf: *[*]u8: *const opaque, len(buf)); +}; + +fn rand_reader(s: *io::stream, buf: []u8) (size | io::EOF | io::error) = { + assert(s == stream); + buffer(buf); + return len(buf); +};