Downloads
Get Reef v0.11.1
Prebuilt tarballs from the object store. Filter by version, OS, and architecture.
Reef is experimental, and releases can break compatibility with each other. Pin a specific version rather than tracking the latest.
Release notes — Reef v0.11.1
Full ChangeLog →
Highlights
Reef 0.11.1 adds one runtime hook for OS entropy, reef_rt_entropy. It uses getrandom on Linux and illumos, arc4random_buf on the BSDs and macOS, and /dev/urandom elsewhere, and it never falls back to the clock. Two new modules build on it. random.random has secure functions that return a Result and a seedable Pcg32 generator for reproducible sequences. encoding.uuid covers RFC 9562 v4, v5, v7, v8, nil and max, and is tested against the RFC's vectors. math.random has fixes that change seeded output: the same seed(n) now gives different random_int_max, random_int_range and random_float results than 0.11.0. On bare metal, math.random now links in a freestanding image and a kernel can override the default reef_panic.
Details
Added — reef_rt_entropy: one OS entropy hook (RB-016)
- The runtime has one entropy primitive,
reef_rt_entropy(buf, len)(reef-runtime/include/reef_entropy.h). Linux and illumos usegetrandom(2), the BSDs and macOSarc4random_buf(3), anything else/dev/urandom(also the fallback when the kernel lacksgetrandom). It fills every byte or returns a code (1 no source, 2 source failed, 3 bad arguments) with the buffer zeroed. It never falls back to the clock.EINTRfrom the GC's SIGURG is retried. - Bare metal:
reef_baremetal.chas a weak default that returns "no source". An OS links its ownreef_rt_entropyto provide one, as it doesreef_putchar. - Reef code reaches it through
sys.platform.runtime.reef_rt_entropy. Prefer therandommodule, which returns aResult. - Link test: a strong
reef_rt_entropyoverrides the weak bare-metal default on amd64 (run and checked by behaviour), aarch64 and riscv64 (checked withnm), with no duplicate-symbol error. If the strong definition is in a static archive linked afterreef_baremetal.o, the linker never pulls it in and the weak default is used silently.reef-baremetal/README.mdgives the safe link lines (object file, or--whole-archive).
Added — encoding.uuid (RFC 9562) (RB-019)
v4()andv7(unix_ms)take their random bits fromrandom.randomand return aResult(Err(Unsupported)with no entropy source, never a predictable UUID).v7puts the 48-bit millisecond time first, so UUIDs from different milliseconds sort by time.v8(bytes)sets the version and variant bits over the caller's 16 bytes (the caller's array is not changed).v5(namespace, name)is SHA-1 name-based viacrypto.sha1, withnamespace_dns/url/oid/x500.nil_uuid()andmax_uuid()(nilis a reserved word).parseaccepts only the canonical 8-4-4-4-12 form (either case);formatwrites lower case.from_bytes/to_bytesuse RFC byte order, the order of the ext2/ext4s_uuidfield. Alsoversion,variant,is_nil,is_max,eq,compare.- Tested against the RFC 9562 Appendix A vectors (v4, v5, v7, v8).
v4,v8andto_bytescompile and link for bare metal.
Added — random.random: secure random numbers and a seedable PCG32 (RB-018)
secure_fill,secure_bytes,secure_u32,secure_u64,secure_below,secure_range(inclusive) andsecure_floatread the OS source throughreef_rt_entropyand return aResult:Err(Unsupported)when the target has no source,Err(IoError)when it fails,Err(InvalidInput)for bad arguments. No silent fallback.Pcg32is a seedable, deterministic generator (PCG-XSH-RR 64/32, bit-identical to pcg-c-basic):pcg32_new(seed, stream),pcg32_from_entropy,pcg32_next_u32/u64,pcg32_below,pcg32_range,pcg32_float,pcg32_bool,pcg32_shuffle. Each generator has its own state, so Active Objects do not share one. Not for secrets.- Ranges are unbiased (rejection sampling) and floats are in [0, 1).
- Bare metal:
reef_baremetal.hhasreef_array_length, so modules that callarr.length()(this one,encoding.uuid) compile freestanding.
Changed — math.random: fixes that change seeded sequences (RB-020)
The same seed(n) now gives different random_int_max,
random_int_range and random_float results than in 0.11.0. Raw
random_int() and random_bool() sequences do not change.
random_float()could return exactly1.0(the divisor was 2^31-1, the largest draw;seed(1584200935)hit it on the first call). It now divides by 2^31, so results are always in[0.0, 1.0).random_int_maxandrandom_int_rangewere biased (random_int() % nfavoured small results: formax = 1500000000, values below 647483648 came up 60% of the time instead of 43%). They now use rejection sampling over the full 32-bit draw.random_int_rangeoverflowed for spans over 2^31-1: it returned values outside the range, andrandom_int_range(INT_MIN, INT_MAX)panicked with integer division by zero. Anyintspan now works.seed_time()seeded from the clock in whole seconds, so programs started in the same second got the same sequence. It now seeds fromreef_rt_entropyand uses the clock only when the target has no entropy source.math.randomis still not for secrets; userandom.random.
Fixed — bare-metal reef_panic can be overridden (RB-022)
- The default
reef_panicinreef-baremetal/src/reef_baremetal.cwas a strong definition, although the README and header comments called it an optional override. A kernel that defined its ownreef_panicand linked that file failed with a duplicate symbol (multiple definitionin GNU ld,duplicate symbolin ld.lld). It is now weak, like the other hooks. The weak-override link test covers it on amd64 (run and checked by behaviour), aarch64 and riscv64 (checked withnm).
Fixed — math.random links on bare metal (RB-017)
reef_baremetaldefinesreef_time(weak, returns 0 = no clock; an OS with an RTC overrides it) andreef_int_to_float(inline). Before, a freestanding image that calledmath.random.seed_time()orrandom_float()failed to link with undefined references to both.- New gate in
run_tests.sh:random_link_probe.reeflinks againstreef_baremetal.con amd64, aarch64 and riscv64, and a strongreef_rt_entropymust override the weak default.