Lunatik

crypto_rngClass

Lua interface to synchronous Random Number Generators (RNG).

Methods

crypto_rng:algname () Returns the driver-independent name of the algorithm the transform was allocated with.
crypto_rng:close () Releases the transform.
crypto_rng:generate (n[, additional]) Generates random bytes.
crypto_rng:getbytes (n) Generates random bytes with no additional input.
crypto_rng:reset ([seed]) Reseeds the RNG.
crypto_rng:seedsize () Returns the size in bytes of the seed reset takes, 0 for an algorithm that requires none.

Methods in detail

crypto_rng:algname ()
Returns the driver-independent name of the algorithm the transform was allocated with.

Returns

    string
crypto_rng:close ()
Releases the transform. A to-be-closed variable holding the object releases it the same way. Calling it again does nothing, and every other method raises “closed object” afterwards.

Returns

    nil
crypto_rng:generate (n[, additional])
Generates random bytes. The optional string reaches the algorithm as additional input for this call, which drbg mixes into its output. It does not reseed: reset does.

Parameters

  • n integer number of bytes to generate
  • additional string additional input (optional)

Returns

    string random bytes

Raises

on generation failure
crypto_rng:getbytes (n)
Generates random bytes with no additional input.

Parameters

  • n integer number of bytes to generate

Returns

    string random bytes

Raises

on generation failure
crypto_rng:reset ([seed])
Reseeds the RNG. Without a seed, the kernel draws one of seedsize() random bytes.

Parameters

Raises

on reseed failure
crypto_rng:seedsize ()
Returns the size in bytes of the seed reset takes, 0 for an algorithm that requires none.

Returns

    integer