Skip to content

Commit 5b3ec96

Browse files
authored
Modified to work on Phoenix
1 parent 0a23090 commit 5b3ec96

18 files changed

+34
-67
lines changed

.vscode/settings.json

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -9,42 +9,10 @@
99
"redefined-local": "Warning"
1010
},
1111
"Lua.diagnostics.globals": [
12-
"printError",
13-
"sleep",
14-
"read",
15-
"write",
1612
"print",
17-
"colours",
18-
"colors",
19-
"commands",
20-
"disk",
21-
"fs",
22-
"gps",
23-
"help",
24-
"http",
25-
"paintutils",
26-
"parallel",
27-
"peripheral",
28-
"rednet",
29-
"redstone",
30-
"keys",
31-
"settings",
32-
"shell",
33-
"multishell",
34-
"term",
35-
"textutils",
36-
"turtle",
37-
"pocket",
38-
"vector",
39-
"bit32",
40-
"window",
41-
"_CC_DEFAULT_SETTINGS",
42-
"_HOST",
4313
"_VERSION",
4414
"_",
45-
"_ENV",
46-
"ccemux",
47-
"wordlib"
15+
"_ENV"
4816
],
49-
"Lua.runtime.version": "Lua 5.1"
17+
"Lua.runtime.version": "Lua 5.2"
5018
}

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# CCryptoLib
2-
An integrated collection of cryptographic primitives written in Lua using the ComputerCraft system API.
2+
An integrated collection of cryptographic primitives written in Lua using the ComputerCraft system API. This is a fork for [Phoenix](https://phoenix.madefor.cc). Requires libsystem.
33

44
## Initializing the Random Number Generator
55
All functions that take secret input may query the library's random generator,
@@ -11,17 +11,27 @@ If you trust the tmpim Krist node, you can fetch a socket token and use it for
1111
initialization:
1212
```lua
1313
local random = require "ccryptolib.random"
14+
local network = require "system.network"
1415

1516
-- Fetch a WebSocket token.
16-
local postHandle = assert(http.post("https://krist.dev/ws/start", ""))
17-
local data = textutils.unserializeJSON(postHandle.readAll())
18-
postHandle.close()
17+
local postHandle = assert(network.post("https://krist.dev/ws/start", ""))
18+
local data = textutils.unserializeJSON(postHandle:read("*a"))
19+
postHandle:close()
1920

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

2324
-- Be polite and actually open the socket too.
24-
http.websocket(data.url).close()
25+
network.connect(data.url):close()
26+
```
27+
28+
On CraftOS-PC or CCEmuX, you can use the built-in `nano` clock for relatively
29+
decent entropy (this will not work in-game!):
30+
```lua
31+
local random = require "ccryptolib.random"
32+
33+
-- Initialize the generator using nanoseconds.
34+
random.init(os.time("nano"))
2535
```
2636

2737
Otherwise, you will need to find another high-quality random entropy source to

ccryptolib/aead.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--- The ChaCha20Poly1305AEAD authenticated encryption with associated data (AEAD) construction.
22

3-
local expect = require "cc.expect".expect
3+
local expect = require "system.expect".expect
44
local lassert = require "ccryptolib.internal.util".lassert
55
local packing = require "ccryptolib.internal.packing"
66
local chacha20 = require "ccryptolib.chacha20"

ccryptolib/blake3.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--- The BLAKE3 cryptographic hash function.
22

3-
local expect = require "cc.expect".expect
3+
local expect = require "system.expect".expect
44
local lassert = require "ccryptolib.internal.util".lassert
55
local packing = require "ccryptolib.internal.packing"
66

ccryptolib/chacha20.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--- The ChaCha20 stream cipher.
22

3-
local expect = require "cc.expect".expect
3+
local expect = require "system.expect".expect
44
local lassert = require "ccryptolib.internal.util".lassert
55
local packing = require "ccryptolib.internal.packing"
66

ccryptolib/ed25519.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--- The Ed25519 digital signature scheme.
22

3-
local expect = require "cc.expect".expect
3+
local expect = require "system.expect".expect
44
local lassert = require "ccryptolib.internal.util".lassert
55
local fq = require "ccryptolib.internal.fq"
66
local sha512 = require "ccryptolib.internal.sha512"

ccryptolib/internal/sha512.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--- The SHA512 cryptographic hash function.
22

3-
local expect = require "cc.expect".expect
3+
local expect = require "system.expect".expect
44
local packing = require "ccryptolib.internal.packing"
55

66
local shl = bit32.lshift

ccryptolib/poly1305.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--- The Poly1305 one-time authenticator.
22

3-
local expect = require "cc.expect".expect
3+
local expect = require "system.expect".expect
44
local lassert = require "ccryptolib.internal.util".lassert
55
local packing = require "ccryptolib.internal.packing"
66

ccryptolib/random.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local expect = require "cc.expect".expect
1+
local expect = require "system.expect".expect
22
local blake3 = require "ccryptolib.blake3"
33
local chacha20 = require "ccryptolib.chacha20"
44
local util = require "ccryptolib.internal.util"
@@ -8,8 +8,8 @@ local lassert = util.lassert
88
-- Extract local context.
99
local ctx = {
1010
"ccryptolib 2023-04-11T19:43Z random.lua initialization context",
11-
os.epoch("utc"),
12-
os.epoch("ingame"),
11+
os.time() * 1000,
12+
os.time("ingame") * 1000,
1313
math.random(0, 2 ^ 24 - 1),
1414
math.random(0, 2 ^ 24 - 1),
1515
tostring({}),

ccryptolib/sha256.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
--- The SHA256 cryptographic hash function.
22

3-
local expect = require "cc.expect".expect
3+
local expect = require "system.expect".expect
44
local lassert = require "ccryptolib.internal.util".lassert
55
local packing = require "ccryptolib.internal.packing"
66

0 commit comments

Comments
 (0)