👨‍💻 about me home CV/Resume 🖊️ Contact Github LinkedIn I’m a Haskeller 📝 Blog Freedom, privacy, tutorials… 🏆 Best of Fizzbuzz LuaX Calculadoira panda upp Haskell todo pwd TPG Nextcloud Git

#BoycottQatar2022   ┇   Why everyone should boycott the World Cup in Qatar

🆕 since August 2022: LuaX is a Lua eXtended interpretor/cross compiler providing a bunch of useful modules (statically linked, no dependency). Nice integration with upp (new functions and modules available to extend upp macros) and also with a soon released but yet confidential project about actor oriented programming!
💣 Kick GAFAMs out (✔️ ǝlƃooפ, ✔️ ʞooqǝɔɐℲ, ✔️ uozɐɯ∀): Stop giving our soul and money to evils, be free and respectful!
📰 Friday 2. April 2021: upp is a panda companion. It’s a Lua-scriptable lightweight text preprocessor.
🆕 since December 2020: Playing with the actor model in an embedded multicore context. C imperative components become C stream pure functions with no side effect ➡️ C low level programming with high level pure functional programming properties 🏆
📰 Saturday 30. January 2021: Playing with Pandoc Lua filters in Lua. panda is a lightweight alternative to abp providing a consistent set of Pandoc filters (text substitution, file inclusion, diagrams, scripts, …).
🆕 Sunday 24. May 2020: Working at EasyMile for more than 5 years. Critical real-time software in C, simulation and monitoring in Haskell ➡️ perfect combo! It’s efficient and funny ;-)

LuaX: Lua eXtended

Christophe Delord - http://cdelord.fr/luax

crypt: cryptography module

local crypt = require "crypt"

crypt provides cryptography functions.

Random number generator

The LuaX pseudorandom number generator is a linear congruential generator. This generator is not a cryptographically secure pseudorandom number generator. It can be used as a repeatable generator (e.g. for repeatable tests).

LuaX has a global generator (with a global seed) and can instantiate independant generators with their own seeds.

Random number generator instance

local rng = crypt.prng(seed)

returns a random number generator starting from the optional seed seed. This object has four methods: srand(seed), rand([m, [n]]), rands([bytes]) and randf([a, [b]]).

rng:srand([seed])

sets the seed of the PRNG. The default seed is a number based on the current time and the process id.

rng:rand()

returns a random integral number between 0 and crypt.RAND_MAX.

rng:rand(m)

returns a random integral number between 1 and m.

rng:rand(m, n)

returns a random integral number between m and n.

rng:randf()

returns a random floating point number between 0.0 and 1.0.

rng:randf(a)

returns a random floating point number between 0.0 and a.

rng:randf(a, b)

returns a random floating point number between a and b.

rng:rands(bytes)

returns a string with bytes random bytes.

Global random number generator

crypt.srand([seed])

sets the seed of the global PRNG. The default seed is a number based on the current time and the process id.

crypt.rand()

returns a random integral number between 0 and crypt.RAND_MAX.

crypt.rand(m)

returns a random integral number between 1 and m.

crypt.rand(m, n)

returns a random integral number between m and n.

crypt.randf()

returns a random floating point number between 0.0 and 1.0.

crypt.randf(a)

returns a random floating point number between 0.0 and a.

crypt.randf(a, b)

returns a random floating point number between a and b.

crypt.rands(bytes)

returns a string with bytes random bytes.

Hexadecimal encoding

The hexadecimal encoder transforms a string into a string where bytes are coded with hexadecimal digits.

crypt.hex(data)

encodes data in hexa.

crypt.unhex(data)

decodes the hexa data.

Base64 encoding

The base64 encoder transforms a string with non printable characters into a printable string (see https://en.wikipedia.org/wiki/Base64)

crypt.base64(data)

encodes data in base64.

crypt.unbase64(data)

decodes the base64 data.

crypt.base64url(data)

encodes data in base64url.

crypt.unbase64url(data)

decodes the base64url data.

CRC32 hash

The CRC-32 algorithm has been generated by pycrc with the crc-32 algorithm.

crypt.crc32(data)

computes the CRC32 of data.

CRC64 hash

The CRC-64 algorithm has been generated by pycrc with the crc-64-xz algorithm.

crypt.crc64(data)

computes the CRC64 of data.

RC4 encryption

RC4 is a stream cipher (see https://en.wikipedia.org/wiki/RC4). It is design to be fast and simple.

crypt.rc4(data, key, [drop])
crypt.unrc4(data, key, [drop])      -- note that unrc4 == rc4

encrypts/decrypts data using the RC4Drop algorithm and the encryption key key (drops the first drop encryption steps, the default value of drop is 768).

TinyCrypt library

The crypt contains functions from TinyCrypt.

SHA256 hash

crypt.sha256(data)

returns the SHA256 digest of data.

HMAC-SHA256 hash

crypt.hmac(data, key)

returns the HMAC-SHA256 digest of data using key as a key.

HMAC-SHA256 random number generator

crypt.hmac_prng(personalization)

returns a HMAC PRNG initialized with personalization (32 bytes or more) and some OS dependant entropy. This object has three methods: srand(seed), rand([bytes]) and frand().

CTR random number generator

crypt.ctr_prng(personalization)

returns a CTR PRNG initialized with personalization (32 bytes of more) and some OS dependant entropy. This object has three methods: srand(seed), rand([bytes]) and frand().

AES-128 encryption

crypt.aes(data, key)

encrypts data using the AES-128-CBC algorithm and the encryption key key.

crypt.unaes(data, key)

decrypts data using the AES-128-CBC algorithm and the encryption key key.

String methods

Some functions of the crypt package are added to the string module:

s:hex()             == crypt.hex(s)
s:unhex()           == crypt.unhex(s)
s:base64()          == crypt.base64(s)
s:unbase64()        == crypt.unbase64(s)
s:base64url()       == crypt.base64url(s)
s:unbase64url()     == crypt.unbase64url(s)
s:crc32()           == crypt.crc32(s)
s:crc64()           == crypt.crc64(s)
s:rc4(key, drop)    == crypt.rc4(s, key, drop)
s:unrc4(key, drop)  == crypt.unrc4(s, key, drop)
s:sha256()          == crypt.sha256(s)
s:hmac(key)         == crypt.hmac(s, key)
s:aes(key)          == crypt.aes(s, key)
s:unaes(key)        == crypt.unaes(s, key)