Skip to content

Phoenix-ComputerCraft/ccryptolib

This branch is 8 commits ahead of, 2 commits behind migeyel/ccryptolib:main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Aug 1, 2024
bbf491c · Aug 1, 2024
Jun 13, 2023
Aug 1, 2024
Jan 16, 2024
Jun 8, 2023
May 31, 2024
Jun 13, 2023

Repository files navigation

CCryptoLib

An integrated collection of cryptographic primitives written in Lua using the ComputerCraft system API. This is a fork for Phoenix. Requires libsystem.

Initializing the Random Number Generator

All functions that take secret input may query the library's random generator, ccryptolib.random. CC doesn't have high-quality entropy sources, so instead of hoping for the best like other libraries do, CCryptoLib shifts that burden into you!

Initializing using a Trusted Web Source

If you trust the tmpim Krist node, you can fetch a socket token and use it for initialization:

local random = require "ccryptolib.random"
local network = require "system.network"

-- Fetch a WebSocket token.
local postHandle = assert(network.post("https://krist.dev/ws/start", ""))
local data = textutils.unserializeJSON(postHandle:read("*a"))
postHandle:close()

-- Initialize the generator using the given URL.
random.init(data.url)

-- Be polite and actually open the socket too.
network.connect(data.url):close()

On CraftOS-PC or CCEmuX, you can use the built-in nano clock for relatively decent entropy (this will not work in-game!):

local random = require "ccryptolib.random"

-- Initialize the generator using nanoseconds.
random.init(os.time("nano"))

Initializing using VM Instruction Counting

As of v1.2.0, you can also initialize the generator using VM instruction timing noise. See the random.initWithTiming method for security risks of taking this approach.

local random = require "ccryptolib.random"
random.initWithTiming()

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Lua 100.0%