Silk

silk/os_random

Profiles: aarch64-apple-darwin, aarch64-unknown-linux-gnu, x86_64-unknown-linux-gnu.

Native Unix-family cryptographically secure random provider.

When to use

Construct OsRandom at a native application edge and provide it to portable code requiring &mut Random. Use an ordinary scripted provider in deterministic tests.

Details

Construction is stateless and performs no host call. Each nonempty fill calls selected ordinary libc declarations and succeeds only after the complete slice contains fresh CSPRNG bytes. GNU/Linux uses nonblocking getrandom; macOS uses arc4random_buf.

Gotchas

Host failure is a fatal trap because continuing with weak or partial bytes would violate the service contract. GNU/Linux requires glibc 2.25 and Linux 3.17 or later. Unsupported and no-libc profiles do not provide this implementation. A failed fill may already have modified a prefix; the remaining initialized bytes retain their prior values. Failure does not promise rollback.

Import as OsRandom with import silk.os_random { OsRandom }.

Public declarations: 1.

OsRandom

pub struct OsRandom

A stateless native provider of complete fresh secure bytes in initialized borrowed storage.

Gotchas

Native failure traps, possibly after modifying a prefix. No rollback or typed failure is provided.

Associated function OsRandom.make

pub fn make() -> OsRandom

Creates a native provider without reading entropy or installing an ambient default.

Implementation Random for OsRandom

impl Random for OsRandom

Operation fillBytes

fillBytes = OsRandom.impl@0.fillBytes

On this page