~/bend-docscommunity

src/crypto/random.bend checks

raw source on the hub · import 0xd9a2fae439ac7ff9e21e0853948f94fe/src/crypto/random.bend as Random

6 imports
import Base
import ../math/u64.bend as W
import ../math/w64.bend as X
import ../math/random/rand.bend as R
import ../math/random/chacha8.bend as C8
import ../math/random/chacha8/block.bend as B

Types

type Gen source · line 49 · raw

Data

type Fill source · line 97 · raw

Data

the bytes read so far (latest first), the generator and its pending bytes

Definitions

def wrap source · line 52 · raw

@m:Maybe<&2, 0xd9a2fae439ac7ff9e21e0853948f94fe/src/math/random/chacha8.ChaCha8> -> Maybe<&2, Gen>

def new source · line 59 · raw

@+seed:List<&2, U32> -> Maybe<&2, Gen>

def of_words source · line 62 · raw

@+k0:U32 -> @+k1:U32 -> @+k2:U32 -> @+k3:U32 -> @+k4:U32 -> @+k5:U32 -> @+k6:U32 -> @+k7:U32 -> Gen

def os_word source · line 65 · raw

IO(U32)

def from_os source · line 68 · raw

IO(Gen)

def keep_pending source · line 80 · raw

@+p:List<&2, U32> -> @r:Pair(0xd9a2fae439ac7ff9e21e0853948f94fe/src/math/u64.U64, 0xd9a2fae439ac7ff9e21e0853948f94fe/src/math/random/chacha8.ChaCha8) -> Pair(0xd9a2fae439ac7ff9e21e0853948f94fe/src/math/u64.U64, Gen)

def next source · line 85 · raw

@g:Gen -> Pair(0xd9a2fae439ac7ff9e21e0853948f94fe/src/math/u64.U64, Gen)

the Source step: the next 64-bit output (pending bytes are left for bytes)

def le_bytes source · line 91 · raw

@+x:0xd9a2fae439ac7ff9e21e0853948f94fe/src/math/u64.U64 -> List<&2, U32>

the eight little-endian bytes of a 64-bit word

def split_bytes source · line 100 · raw

@acc:List<&2, U32> -> @c:0xd9a2fae439ac7ff9e21e0853948f94fe/src/math/random/chacha8.ChaCha8 -> @bs:List<&2, U32> -> Fill

def split source · line 107 · raw

@acc:List<&2, U32> -> @r:Pair(0xd9a2fae439ac7ff9e21e0853948f94fe/src/math/u64.U64, 0xd9a2fae439ac7ff9e21e0853948f94fe/src/math/random/chacha8.ChaCha8) -> Fill

def take1 source · line 112 · raw

@f:Fill -> Fill

one byte: the next pending byte, or the first byte of a fresh word

def fill source · line 121 · raw

@n:Nat -> @f:Fill -> Fill

def done source · line 128 · raw

@f:Fill -> Pair(List<&2, U32>, Gen)

def bytes source · line 133 · raw

@g:Gen -> @n:Nat -> Pair(List<&2, U32>, Gen)

def uint64 source · line 138 · raw

@g:Gen -> Pair(0xd9a2fae439ac7ff9e21e0853948f94fe/src/math/u64.U64, Gen)

def uint_below source · line 142 · raw

@g:Gen -> @+n:0xd9a2fae439ac7ff9e21e0853948f94fe/src/math/u64.U64 -> Pair(0xd9a2fae439ac7ff9e21e0853948f94fe/src/math/u64.U64, Gen)

uniform in [0, n) for n > 0

Templates

template shuffle source · line 146 · raw

@-A:Data -> @g:Gen -> @+items:List<&2, A> -> Pair(List<&2, A>, Gen)

a uniform permutation of items