Expose bounded operating-system cryptographic random bytes

Aperta
#198 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla

Direzione di ricerca

Inizia leggendo design.md e coordinando la denominazione con il modulo Random di basic-cli. Usa il punto di ingresso pf.Random.bytes! e i controlli elencati per lunghezza zero, limite massimo, concorrenza, successo/fallimento dell’host e piattaforme native come mappa di validazione. Il lavoro è completo quando i criteri di accettazione sono soddisfatti su Linux, macOS e Windows senza esporre byte parziali né uno stato mutabile del PRNG globale.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Summary

Expose cryptographically secure bytes from the operating system:

bytes = Random.bytes!(32)?

Illustrative API:

bytes! : U64 => Try(
    List(U8),
    [
        EntropyUnavailable(IOErr),
        TooManyBytes({ requested : U64, max : U64 }),
    ],
)

Exact names can be settled during implementation.

Why this belongs in the platform

Secure randomness is necessary for session identifiers, CSRF tokens, password-reset tokens, webhook secrets, and other conventional web application capabilities. Applications cannot implement it safely in pure Roc, and the platform is the only supported boundary through which they can access the operating system.

OWASP recommends a CSPRNG and at least 128 bits when an application creates session identifiers. A byte API avoids encouraging applications to concatenate or reinterpret a small integer seed.

This is a small, app-independent OS primitive with identical semantics on every target, so it meets the platform subsystem criteria in design.md.

Required contract

  • Use the operating system's preferred cryptographic random source on Linux, macOS, and Windows.
  • Return exactly the requested number of bytes or a typed failure; never return partial success.
  • bytes!(0) returns Ok([]).
  • Enforce a documented hard allocation bound before allocating. A proposed initial maximum is 64 KiB.
  • Calls are safe under concurrent request handling.
  • Do not expose a mutable global PRNG or require application-provided seeding.
  • Do not log, inspect, or otherwise expose generated bytes on an error path.
  • Coordinate naming with basic-cli's Random module, while keeping this repository independently usable.

Tests

  • Zero length, exact maximum, and over-maximum.
  • Exact output length over representative sizes.
  • Concurrent calls.
  • Injected host success and failure paths.
  • Native smoke coverage on Linux, macOS, and Windows.
  • No statistical randomness tests: those do not validate the security of the OS source.

Non-goals

  • Deterministic seeded random-number generation
  • Probability distributions or random collection helpers
  • UUIDs, tokens, Base64, or hexadecimal encoding
  • Key derivation, hashing, signing, or encryption
  • Arbitrarily large random buffers

Acceptance criteria

  • pf.Random.bytes! returns exact-length OS cryptographic randomness.
  • Allocation has a finite documented maximum and typed over-limit error.
  • The operation has one cross-platform semantic contract.
  • The implementation has no mutable process-global PRNG state.
  • Failure and concurrency paths are covered.

References

Lingua principale
HTML
Stelle
110
Fork
25
Merge medio
18h 28m
PR unite (30g)
16

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di roc-lang/basic-webserver

Tutte le issue di roc-lang/basic-webserver

Issue simili

Altre issue su Operating Systems

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.