Crypto

Implemented in src/lua/luacryptoapi.cpp.

Encrypts/decrypts arbitrary binary data using SCARAB_CONTENT_KEY - a shared secret compiled into this specific build of scarab (a CMake option, never a Lua value), the same way SCARAB_VERSION is. Neither primitive here ever takes a key argument, and the key itself is never exposed to Lua as a readable value - every game's own privately-built scarab has it's own key, and only that same build can decrypt what it encrypted. This is deterrence, not unbreakable DRM - see the root README.md's own "Content encryption" section for why that distinction matters.

crypto_encrypt_data(data) -> encrypted / crypto_decrypt_data(encrypted) -> data

Encrypts data (any Lua string - binary-safe, may contain embedded zero bytes) using the key compiled into this build (SCARAB_CONTENT_KEY - see this class's own doc above). Returns the encrypted blob as a Lua string, ready to write straight to a file, or nil (and logs an error) if this build has no valid key configured. A fresh random nonce is generated for every call and prepended to the returned blob - callers never handle the nonce themselves, crypto_decrypt_data reads it back out automatically.

local encrypted = crypto_encrypt_data(plainBytes)

if encrypted == nil then
  error("content encryption not configured for this build")
end

Key configuration

Set at build time, never at runtime:

cmake -B build -S . -DSCARAB_CONTENT_KEY=<64 hex characters>

A 64-character hex string decodes to the 32 raw bytes crypto_secretbox's key requires. Left empty by default — both primitives above fail cleanly (return nil, log a clear error) rather than silently falling back to some fixed, publicly-known placeholder key. Never commit a real key to version control; pass it from a CI secret or a local, gitignored file instead.