BlitzMax

BlitzMax

  • Downloads
  • Docs
  • API
  • Resources
  • About

›Crypto

BlitzMax API

  • Introduction

BRL

    Audio

    • Introduction
    • TChannel
    • TSound

    AudioSample

    • Introduction
    • TAudioSample
    • TAudioSampleLoader

    Bank

    • Introduction
    • TBank

    BankStream

    • Introduction
    • TBankStream

    Base64

    • Introduction
    • TBase64

    Blitz

    • Introduction
    • TArrayBoundsException
    • TBlitzException
    • TNullFunctionException
    • TNullMethodException
    • TNullObjectException
    • TOutOfDataException
    • TRuntimeException
  • BRL.BMPLoader
  • Clipboard

    • Introduction
    • TClipboard
    • TClipboardOpts
    • TWin32ClipboardOpts
    • TX11ClipboardOpts
  • BRL.D3D7Max2D
  • BRL.D3D9Max2D
  • BRL.DirectSoundAudio
  • BRL.EndianStream
  • Event

    • Introduction
    • TEvent
  • BRL.EventQueue
  • BRL.FileSystem
  • BRL.FreeAudioAudio
  • BRL.GLGraphics
  • BRL.GLMax2D
  • BRL.GNet
  • BRL.Graphics
  • BRL.Hook
  • IO

    • Introduction
    • MaxIO
  • BRL.JPGLoader
  • BRL.KeyCodes
  • LinkedList

    • Introduction
    • TList
    • TListEnum
    • TLink

    Map

    • Introduction
    • TMap
    • TIntMap
    • TIntKey
    • TPtrMap
    • TPtrKey
    • TStringMap
  • BRL.Math
  • Matrix

    • Introduction
    • SMat2D
    • SMat2F
    • SMat2I
    • SMat3D
    • SMat3F
    • SMat3I
    • SMat4D
    • SMat4F
    • SMat4I

    Max2D

    • Introduction
    • TImage

    MaxLua

    • Introduction
    • TLuaClass
    • TLuaObject
  • BRL.OGGLoader
  • BRL.OpenALAudio
  • ObjectList

    • Introduction
    • TObjectList
    • TObjectListEnumerator
    • TObjectListReverseEnumerator

    Pixmap

    • Introduction
    • TPixmap
    • TPixmapLoader
  • BRL.PNGLoader
  • BRL.PolledInput
  • Quaternion

    • Introduction
    • SQuatD
    • SQuatF
    • SQuatI
  • BRL.RamStream
  • Random

    • Introduction
    • TRandom

    Reflection

    • Introduction
    • TTypeId
    • TMember
    • TConstant
    • TField
    • TGlobal
    • TFunction
    • TMethod
  • BRL.Retro
  • BRL.Socket
  • BRL.SocketStream
  • BRL.StandardIO
  • Stream

    • Introduction
    • TCStream
    • TIO
    • TStream
    • TStreamException
    • TStreamFactory
    • TStreamReadException
    • TStreamWrapper
    • TStreamWriteException

    StringBuilder

    • Introduction
    • TStringBuilder
    • TSplitBuffer
  • BRL.System
  • BRL.SystemDefault
  • BRL.TextStream
  • BRL.TGALoader
  • ThreadPool

    • Introduction
    • TRunnable
    • TThreadPoolExecutor

    Threads

    • Introduction
    • TThread
    • TThreadData
    • TMutex
    • TSemaphore
    • TCondVar

    Timer

    • Introduction
    • TChrono
  • BRL.TimerDefault
  • Vector

    • Introduction
    • SVec2D
    • SVec2F
    • SVec2I
    • SVec3D
    • SVec3F
    • SVec3I
    • SVec4D
    • SVec4F
    • SVec4I

    Volumes

    • Introduction
    • TVolume
  • BRL.WAVLoader

Text

    CSV

    • Introduction
    • TCsvParser
    • TCsvHeader
    • TCsvRow
    • TCsvOptions
    • SCsvColumn

    Format

    • Introduction
    • TFormatter

    Ini

    • Introduction
    • TIni
    • TIniProperty
    • TIniSection

    JConv

    • Introduction
    • TJConv
    • TJConvBuilder
    • TJConvSerializer

    Json

    • Introduction
    • TJSON
    • TJSONObject
    • TJSONString
    • TJSONInteger
    • TJSONReal
    • TJSONBool
    • TJSONArray
    • TJSONNull
    • TJSONError
    • TJSONNumber

    Regex

    • Introduction
    • TRegEx
    • TRegExMatch
    • TRegExOptions
    • TRegExException

    TOML

    • Introduction
    • ETomlNodeType
    • TToml
    • ITomlNode
    • STomlDate
    • STomlDateTime
    • STomlTime
    • TTomlArray
    • TTomlInteger
    • TTomlString
    • TTomlTable
    • TTomlBoolean

    Xml

    • Introduction
    • TxmlDoc
    • TxmlNode
    • TxmlAttribute

MaxGUI

  • MaxGUI.MaxGUI
  • MaxGUI.Drivers
  • MaxGUI.Localization
  • MaxGUI.ProxyGadgets
  • MaxGUI.CocoaMaxGUI
  • MaxGUI.Win32MaxGUIEx

PUB

  • Pub.FreeJoy
  • Pub.FreeProcess
  • Pub.Glad
  • Pub.Glew
  • Joystick

    • Introduction
    • TJoystickDriver
  • Pub.Lua
  • Pub.OpenAL
  • Pub.OpenGLES
  • Pub.xmmintrin
  • Pub.ZLib

Crypto

    Digest

    • Introduction
    • TMessageDigest
    • TDigestRegister
    • TNoSuchAlgorithmException

    Cipher

    • Introduction
    • TCipher
    • TCipherMode
    • Crypto.AESCipher
    • Crypto.AnubisCipher
    • Crypto.BlowfishCipher
    • Crypto.CamelliaCipher
    • Crypto.Cast5Cipher
    • Crypto.DESCipher
    • Crypto.IdeaCipher
    • Crypto.KasumiCipher
    • Crypto.KhazadCipher
    • Crypto.KSeedCipher
    • Crypto.NoekeonCipher
    • Crypto.SerpentCipher
    • Crypto.SkipjackCipher
    • Crypto.TwofishCipher
    • Crypto.XTeaCipher

    CBCMode

    • Introduction
    • TCBCCipherMode

    CFBMode

    • Introduction
    • TCFBCipherMode

    CTRMode

    • Introduction
    • TCTRCipherMode

    ECBMode

    • Introduction
    • TECBCipherMode

    F8Mode

    • Introduction
    • TF8CipherMode

    LRWMode

    • Introduction
    • TLRWCipherMode

    OFBMode

    • Introduction
    • TOFBCipherMode

    XTSMode

    • Introduction
    • TXTSCipherMode

    Blake2BDigest

    • Introduction
    • TBlake2B_512
    • TBlake2B_384
    • TBlake2B_256
    • TBlake2B_160

    CRC32

    • Introduction
    • TCRC32

    MD5Digest

    • Introduction
    • TMD5

    Ripemd320Digest

    • Introduction
    • TRipemd320

    Ripemd356Digest

    • Introduction
    • TRipemd256

    Ripemd160Digest

    • Introduction
    • TRipemd160

    Ripemd128Digest

    • Introduction
    • TRipemd128

    SHA1Digest

    • Introduction
    • TSHA1

    SHA256Digest

    • Introduction
    • TSHA256

    SHA512Digest

    • Introduction
    • TSHA512

    SHA3Digest

    • Introduction
    • TSHA3_512
    • TSHA3_384
    • TSHA3_256
    • TSHA3_224

    TigerDigest

    • Introduction
    • TTiger

    WhirlpoolDigest

    • Introduction
    • TWhirlpool

    Crypto

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

SDL

    SDL

    • Introduction
    • TSDLStream

    SDLSystem

    • Introduction
    • TSDLMultiGesture

    SDLVideo

    • Introduction
    • TSDLDisplay
    • TSDLDisplayMode
    • TSDLGLContext
    • TSDLWindow

    SDLRender

    • Introduction
    • TSDLRenderer
    • TSDLTexture

    SDLTimer

    • Introduction
    • TSDLTimer

    SDLHaptic

    • Introduction
    • TSDLHaptic
    • TSDLHapticCondition
    • TSDLHapticConstant
    • TSDLHapticCustom
    • TSDLHapticDirection
    • TSDLHapticEffect
    • TSDLHapticLeftRight
    • TSDLHapticPeriodic
    • TSDLHapticRamp

    SDLSensor

    • Introduction
    • TSDLSensor
  • SDL.SDLFreeAudio
  • SDL.GLSDLMax2D
  • SDL.GL2SDLMax2D
  • SDL.D3D9SDLMax2D
  • SDLVirtualJoystick

    • Introduction
    • TVirtualJoystick

Steam

    SteamSDK

    • Introduction
    • TSteamClient
    • TSteamUtils
    • TSteamUserStats
    • TSteamFriends
    • TSteamUGC
    • ISteamFriendsListener
    • ISteamUGCListener
    • ISteamUserStatsListener
    • ISteamUtilsListener
    • EItemPreviewType
    • EPersonaChange
    • EPersonaState
    • ERemoteStoragePublishedFileVisibility
    • EUGCMatchingUGCType
    • EUGCQuery
    • EUserRestriction
    • EUserUGCList
    • EWorkshopFileType
Edit

TCryptoSecretBox

Encrypts a message with a secret key to keep it confidential.

Computes a nonce and an authentication tag. This tag is used to make sure that the message hasn't been tampered with before decrypting it.

A single key is used both to encrypt/sign and verify/decrypt messages. For this reason, it is critical to keep the key confidential.

Functions

Function KeyGen:TCryptoSecretBoxKey()

Generates a secret key suitable for use with TCryptoSecretBox.


Function Encrypt:Int(c:Byte Ptr, cLen:Size_T, m:Byte Ptr, mLen:Size_T, msgId:ULong, context:String, key:TCryptoKey)

Encrypts a message m of length mLen bytes using a context, a secret key and a message counter msgId.

It puts the ciphertext whose length is CRYPTO_SECRETBOX_HEADERBYTES + mlen into c.

The header includes an automatically-generated 160-bit nonce as well as a 128-bit authentication tag.

A nonce doesn't have to be provided: it is automatically computed using the output of the PRNG and a keyed hash of the message and its metadata. This prevents catastrophic failures even if the PRNG cannot be trusted.

msgId is an optional message tag. For example, if 3 messages are sent to the same recipient using the same key, these messages can sequentially use 0, 1 and 2 as identifiers.

If the recipient expects message 2, but receives a message with a different identifier, it will not decrypt it even if it was encrypted with the correct key.

This can be used to discard duplicate or old messages.

A msgId doesn't have to be secret and it doesn't have to be sequential either. Some applications might prefer a coarse timestamp instead. Any value up to 2^64-1 is acceptable.

If this mechanism is not required by an application, using a constant msgId such as 0 is also totally fine. Message identifiers are optional and do not have to be unique.


Function Encrypt:Int(c:Byte[], m:Byte[], msgId:ULong, context:String, key:TCryptoKey)

Encrypts a message m using a context, a secret key and a message counter msgId.

It puts the ciphertext whose length is CRYPTO_SECRETBOX_HEADERBYTES + m.length into c.

The header includes an automatically-generated 160-bit nonce as well as a 128-bit authentication tag.

A nonce doesn't have to be provided: it is automatically computed using the output of the PRNG and a keyed hash of the message and its metadata. This prevents catastrophic failures even if the PRNG cannot be trusted.

msgId is an optional message tag. For example, if 3 messages are sent to the same recipient using the same key, these messages can sequentially use 0, 1 and 2 as identifiers.

If the recipient expects message 2, but receives a message with a different identifier, it will not decrypt it even if it was encrypted with the correct key.

This can be used to discard duplicate or old messages.

A msgId doesn't have to be secret and it doesn't have to be sequential either. Some applications might prefer a coarse timestamp instead. Any value up to 2^64-1 is acceptable.

If this mechanism is not required by an application, using a constant msgId such as 0 is also totally fine. Message identifiers are optional and do not have to be unique.


Function Decrypt:Int(m:Byte Ptr, mLen:Size_T, c:Byte Ptr, cLen:Size_T, msgId:ULong, context:String, key:TCryptoKey)

Decrypts the ciphertext c of length cLen (which includes the CRYPTO_SECRETBOX_HEADERBYTES bytes header) using the secret key key, the context and the message identifier msgId.

If the authentication tag can be verified using these parameters, the function stores the decrypted message into m. The length of this decrypted message is cLen - CRYPTO_SECRETBOX_KEYBYTES. It then returns True.

If the authentication tag doesn't appear to be valid for these parameters, the function returns False.


Function Decrypt:Int(m:Byte[], c:Byte[], msgId:ULong, context:String, key:TCryptoKey)

Decrypts the ciphertext c (which includes the CRYPTO_SECRETBOX_HEADERBYTES bytes header) using the secret key key, the context and the message identifier msgId.

If the authentication tag can be verified using these parameters, the function stores the decrypted message into m. The length of this decrypted message is c.length - CRYPTO_SECRETBOX_KEYBYTES. It then returns True.

If the authentication tag doesn't appear to be valid for these parameters, the function returns False.


Function ProbeCreate(probe:Byte Ptr, probeLen:Size_T, c:Byte Ptr, cLen:Size_T, context:String, key:TCryptoKey)

Computes a probe for the ciphertext c whose length is cLen, using the context and a shared secret key key.

The probe is put into probe whose size is CRYPTO_SECRETBOX_PROBEBYTES bytes.


Function ProbeCreate(probe:Byte[], c:Byte[], context:String, key:TCryptoKey)

Computes a probe for the ciphertext c, using the context and a shared secret key key.

The probe is put into probe whose size is CRYPTO_SECRETBOX_PROBEBYTES bytes.


Function ProbeVerify:Int(probe:Byte Ptr, probeLen:Size_T, c:Byte Ptr, cLen:Size_T, context:String, key:TCryptoKey)

Verifies that a received probe probe is valid for the ciphertext c whose length is cLen, using the context and the shared secret key key that was initially used to compute the probe.

It returns True on success, and False if the probe didn't pass verification.


Function ProbeVerify:Int(probe:Byte[], c:Byte[], context:String, key:TCryptoKey)

Verifies that a received probe probe is valid for the ciphertext c, using the context and the shared secret key key that was initially used to compute the probe.

It returns True on success, and False if the probe didn't pass verification.


← TCryptoRandomTCryptoHash →
  • Functions
    • Function KeyGen:TCryptoSecretBoxKey()
    • Function Encrypt:Int(c:Byte Ptr, cLen:Size_T, m:Byte Ptr, mLen:Size_T, msgId:ULong, context:String, key:TCryptoKey)
    • Function Encrypt:Int(c:Byte[], m:Byte[], msgId:ULong, context:String, key:TCryptoKey)
    • Function Decrypt:Int(m:Byte Ptr, mLen:Size_T, c:Byte Ptr, cLen:Size_T, msgId:ULong, context:String, key:TCryptoKey)
    • Function Decrypt:Int(m:Byte[], c:Byte[], msgId:ULong, context:String, key:TCryptoKey)
    • Function ProbeCreate(probe:Byte Ptr, probeLen:Size_T, c:Byte Ptr, cLen:Size_T, context:String, key:TCryptoKey)
    • Function ProbeCreate(probe:Byte[], c:Byte[], context:String, key:TCryptoKey)
    • Function ProbeVerify:Int(probe:Byte Ptr, probeLen:Size_T, c:Byte Ptr, cLen:Size_T, context:String, key:TCryptoKey)
    • Function ProbeVerify:Int(probe:Byte[], c:Byte[], context:String, key:TCryptoKey)
BlitzMax
Docs
Getting StartedDownloadsAbout
Community
ResourcesSyntaxBomb Forums
More
GitHubStarChat on Discord
Copyright © 2023 Bruce A Henderson