BlitzMax

BlitzMax

  • Downloads
  • Docs
  • API
  • Resources
  • About

›BRL.Crypto

BRL.Crypto

  • TCryptoRandom
  • TCryptoSecretBox
  • TCryptoHash
  • TCryptoSign
  • TCryptoKeyExchange
  • TCryptoKey
  • TCryptoHashKey
  • TCryptoSecretBoxKey
  • TCryptoSignature
  • TCryptoExchangeKeyPair
  • TCryptoSessionKeyPair
  • TCryptoNPacket
  • TCryptoKK1Packet
  • TCryptoKK2Packet
  • TCryptoXX1Packet
  • TCryptoXX2Packet
  • TCryptoXX3Packet
  • TCryptoExchangeState
  • TCryptoPWHashMasterKey
  • TCryptoPWHashStoredKey
  • TCryptoPasswordHash
Edit

TCryptoRandom

Generate unpredictable data, suitable for creating secret keys.

If this is used in an application inside a VM, and the VM is snapshotted and restored, then the above functions will produce the same output.

Functions

Function Random:UInt()

Returns an unpredictable value between 0 and $ffffffff (inclusive).

Example

SuperStrict

Framework brl.standardio
Import brl.crypto

For Local i:Int = 0 Until 10
    Print TCryptoRandom.Random()
Next


Function Uniform:UInt(upperBound:UInt)

Returns an unpredictable value between 0 and upperBound (excluded).

Unlike Random() Mod upperBound, it does its best to guarantee a uniform distribution of the possible output values even when upperBound is not a power of 2.

Example

SuperStrict

Framework brl.standardio
Import brl.crypto

For Local i:Int = 0 Until 10
    Print TCryptoRandom.Uniform(1000)
Next


Function FillBuffer(buf:Byte Ptr, size:Size_T)

Fills size bytes starting at buf with an unpredictable sequence of bytes, derived from a secret seed.

Example

SuperStrict

Framework brl.standardio
Import brl.crypto

Local buf:Byte[32]

TCryptoRandom.FillBuffer(buf)

For Local i:Int = 0 Until buf.length
    Print buf[i]
Next


Function FillBuffer(buf:Byte[])

Fills an array of bytes with an unpredictable sequence of bytes, derived from a secret seed.

Example

SuperStrict

Framework brl.standardio
Import brl.crypto

Local buf:Byte[32]

TCryptoRandom.FillBuffer(buf)

For Local i:Int = 0 Until buf.length
    Print buf[i]
Next


Function FillKey(key:TCryptoKey Var, bytes:Size_T = 32)

Fills a key with an unpredictable sequence of bytes in length, derived from a secret seed.


Function Ratchet()

Erases part of the state and replaces the secret key, making it impossible to recover the previous states in case the current one ever gets exposed due to a vulnerability.

Example

SuperStrict

Framework brl.standardio
Import brl.crypto

For Local i:Int = 0 Until 10
    Print TCryptoRandom.Random()
Next

TCryptoRandom.Ratchet()


Function Reseed()

Reseeds the random number generator.

Must be called after a fork() call.

Example

SuperStrict

Framework brl.standardio
Import brl.crypto

For Local i:Int = 0 Until 10
    Print TCryptoRandom.Random()
Next

TCryptoRandom.Reseed()


TCryptoSecretBox →
  • Functions
    • Function Random:UInt()
    • Function Uniform:UInt(upperBound:UInt)
    • Function FillBuffer(buf:Byte Ptr, size:Size_T)
    • Function FillBuffer(buf:Byte[])
    • Function FillKey(key:TCryptoKey Var, bytes:Size_T = 32)
    • Function Ratchet()
    • Function Reseed()
BlitzMax
Docs
Getting StartedDownloadsAbout
Community
ResourcesSyntaxBomb Forums
More
NewsGitHubStar
Copyright © 2020 Bruce A Henderson