wasi_rand

package module
v0.0.0-...-20f66d0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 24, 2021 License: MIT Imports: 6 Imported by: 0

README

A CSPRNG for TinyGo/WebAssembly (WASI)

TinyGo doesn't support crypto/rand yet, which is quite of a deal breaker for many cryptographic operations.

This module implements wasi_rand, a secure random number generator for TinyGo when used in a WebAssembly/WASI environment.

Usage:

import (
    wasi_rand "github.com/jedisct1/tinygo-wasi_rand"
)

func main() {
    var key [32]byte
    if err := wasi_rand.Read(key[:]); err != nil {
        // panic: no entropy source available
    }
}

wasi_rand.Read() can fill buffers of arbitrary sizes.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var Reader io.Reader = newReader()

Functions

func Read

func Read(b []byte) (n int, err error)

/ Read - Fill `b` with cryptographically-secure random bytes. / For compatibility with similar functions from the Go standard library, this function returns the number of bytes that have been written. / However, unless an error occurred, it is guaranteed to always be equal to the length of `b`.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL