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

TCryptoSign

Message signing.

The nonces are non-deterministic. They are computed using the output of the CSPRNG as well as a hash of the message to be signed. As a result, signing the same message multiple times can produce different, all valid signatures. However, only the owner of the secret key can compute a valid signature.

Example 1

SuperStrict

Framework brl.standardio
Import Crypto.Crypto

' generate a key pair
Local keyPair:TCryptoSignKeyPair = TCryptoSign.KeyGen()

Print "keypair : " + keyPair.ToString()

Local signature:TCryptoSignature

Local message:String = "Just a castaway, an island lost at sea. Another lonely day with no one here but me. More loneliness than any man could bear. Rescue me before I fall into despair."
Local mb:Byte Ptr = message.ToUTF8String()

' sign the message with the secret key
TCryptoSign.Sign(signature, mb, Size_T(message.length), "example", keyPair)

Print "signature : " + signature.ToString()

' verify the message with public key
If TCryptoSign.Verify(signature, mb, Size_T(message.length), "example", keyPair) Then
    Print "Verified !"
Else
    Print "Invalid"
End If

MemFree(mb)

Example 2

SuperStrict

Framework brl.standardio
Import Crypto.Crypto

' generate a key pair
Local keyPair:TCryptoSignKeyPair = TCryptoSign.KeyGen()

Print "keypair : " + keyPair.ToString()

Local signature:TCryptoSignature

Local message:String[] = ["Just a castaway, an island lost at sea. " , ..
    "Another lonely day with no one here but me. " , ..
    "More loneliness than any man could bear. " , ..
    "Rescue me before I fall into despair."]

' create a signer with context
Local signer:TCryptoSign = New TCryptoSign.Create("example")

' update all the parts
Update(signer, message)

' create the signature
signer.FinishCreate(signature, keyPair)

Print "signature : " + signature.ToString()

' create a verifier with context
Local verifier:TCryptoSign = New TCryptoSign.Create("example")

' update all the parts
Update(verifier, message)

' verify the public key against the signature
If verifier.FinishVerify(signature, keyPair) Then
    Print "Verified !"
Else
    Print "Invalid"
End If


Function Update(signer:TCryptoSign, message:String[])
    For Local i:Int = 0 Until message.length
        Local mb:Byte Ptr = message[i].ToUTF8String()
        signer.Update(mb, Size_T(message[i].length))
        MemFree(mb)
    Next
End Function

Methods

Method Create:TCryptoSign(context:String)

Initializes a state state using the context.


Method Update:Int(m:Byte Ptr, mLen:Size_T)

Hashes chunk m of mLen bytes.


Method Update:Int(m:Byte[])

Hashes chunk m.


Method FinishCreate:Int(csig:TCryptoSignature Var, kp:TCryptoSignKeyPair)

Computes the signature into csig using the secret key from kp.


Method FinishVerify:Int(csig:TCryptoSignature, kp:TCryptoSignKeyPair)

Verifies the signature into csig using the public key from kp.

Returns False if the signature doesn't appear to be valid for the given message, context and public key, or True if it could be successfully verified.


Functions

Function KeyGen:TCryptoSignKeyPair()

Generates a secret key and a corresponding public key.


Function Sign:Int(csig:TCryptoSignature Var, m:Byte Ptr, mLen:Size_T, context:String, kp:TCryptoSignKeyPair)

Computes a signature for a message m whose length is mLen bytes, using the secret key from kp and a context.


Function Sign:Int(csig:TCryptoSignature Var, m:Byte[], context:String, kp:TCryptoSignKeyPair)

Computes a signature for a message m, using the secret key from kp and a context.


Function Verify:Int(csig:TCryptoSignature, m:Byte Ptr, mLen:Size_T, context:String, kp:TCryptoSignKeyPair)

Checks that the signed message m whose length is mLen bytes has a valid signature for the public key pk and the context.

If the signature is doesn't appear to be valid, the function returns False. On success, it returns True.


Function Verify:Int(csig:TCryptoSignature, m:Byte[], context:String, kp:TCryptoSignKeyPair)

Checks that the signed message m has a valid signature for the public key pk and the context.

If the signature is doesn't appear to be valid, the function returns False. On success, it returns True.


← TCryptoHashTCryptoKeyExchange →
  • Methods
    • Method Create:TCryptoSign(context:String)
    • Method Update:Int(m:Byte Ptr, mLen:Size_T)
    • Method Update:Int(m:Byte[])
    • Method FinishCreate:Int(csig:TCryptoSignature Var, kp:TCryptoSignKeyPair)
    • Method FinishVerify:Int(csig:TCryptoSignature, kp:TCryptoSignKeyPair)
  • Functions
    • Function KeyGen:TCryptoSignKeyPair()
    • Function Sign:Int(csig:TCryptoSignature Var, m:Byte Ptr, mLen:Size_T, context:String, kp:TCryptoSignKeyPair)
    • Function Sign:Int(csig:TCryptoSignature Var, m:Byte[], context:String, kp:TCryptoSignKeyPair)
    • Function Verify:Int(csig:TCryptoSignature, m:Byte Ptr, mLen:Size_T, context:String, kp:TCryptoSignKeyPair)
    • Function Verify:Int(csig:TCryptoSignature, m:Byte[], context:String, kp:TCryptoSignKeyPair)
BlitzMax
Docs
Getting StartedDownloadsAbout
Community
ResourcesSyntaxBomb Forums
More
GitHubStarChat on Discord
Copyright © 2023 Bruce A Henderson