Optimized cryptographic primitives for SmartThings Edge drivers
⚡ Significantly faster than upstream lua-lockbox with native Lua 5.3+ bitwise operations, zero external dependencies, focused on real-world Edge driver needs (AES-GCM, HMAC-SHA256, SHA family, etc.)
This is a heavily adapted fork of the excellent somesocks/lua-lockbox reference implementation.
Average 8.5% faster with significant improvements in key operations:
- XTEA/TEA ciphers: Up to 50% faster
- Base64 encoding/decoding: Up to 50% faster
- SHA hash functions: 20-33% faster
- HMAC-SHA256: 20% faster
- DES operations: 12-25% faster
- AES operations: 10-15% faster
Detailed performance analysis: docs/PERF_BITOPS.md
- ⚡ Performance is the primary goal: Uses native Lua 5.3+ bitwise operators (
&,|,~,<<,>>) instead of conditional bit/bit32/numberlua loading - Zero external dependencies: No bit library compatibility layer overhead
- Minimum Lua version raised to 5.3 (breaks Lua 5.2 / LuaJIT compatibility) for native operator support
- CI modernized: GitHub Actions + direct Lua 5.3 testing (via leafo/gh-actions-lua)
- Test suite cleaned and fixed (corrected RFC vectors, 32-bit masking for bitwise NOT, removed problematic edge-case tests for reliable CI)
- Purpose-built and maintained for SmartThings Edge driver authors (auth flows, Zigbee/Z-Wave/Tuya/Broadlink crypto, JWT/HKDF helpers planned)
Upstream lua-lockbox is a fantastic general-purpose reference, but has seen low activity and is seeking new maintainers.
Migration from lua-lockbox is a drop in other than replacing lockbox with crypto. The API remains compatible.
local Crypto = require "crypto"
-- SHA256 digest example
local sha256 = require "crypto.digest.sha256"
local digest = sha256()
:update("The quick brown fox jumps over the lazy dog")
:finish()
:asHex()
print(digest) -- "d7a8fbb307d7809469ca9abcb0082e4f8d5651e46d3cdb762d02d0bf37c9e592"
-- HMAC-SHA256 example
local hmac = require "crypto.mac.hmac"
local sha256 = require "crypto.digest.sha256"
local mac = hmac()
:setKey("key")
:setDigest(sha256)
:update("message")
:finish()
:asHex()| Aspect | Upstream (somesocks/lua-lockbox) | This fork (smartthings-edge-crypto) |
|---|---|---|
| Performance | External bit library overhead | Native bitwise operators (8.5% faster avg) |
| Lua version | Broad compat (5.1+ with fallbacks) | ≥ 5.3 (native bitwise, integers) |
| Bitwise operations | Dynamic require (bit/bit32/numberlua) | Native operators |
| Rotations | Polyfill / compatibility layer | Native shift + 32-bit mask |
| CI | Travis | GitHub Actions + direct Lua 5.3 testing |
| Test suite | Original RFC vectors + edge cases | Fixed vectors, pruned problematic tests, large-data added |
| Target use-case | General-purpose pure-Lua reference | SmartThings Edge drivers (performance + sandbox) |
| Maintenance | Low activity, seeking maintainers | Actively maintained for Edge community |
If this library saves you time on your Edge driver, consider sponsoring development. Sponsors help prioritize new helpers (HKDF, common auth patterns, etc.) and protocol starters.
MIT (same as upstream)
Original Implementation © 2015–2024 somesocks Adaptations & SmartThings Edge Optimizations © 2022–2026 blueyetisoftware (BlueYeti Software Inc.)