@quenty/ellipticcurvecryptography 1.1.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +11 -0
- package/package.json +2 -2
- package/src/Shared/EllipticCurveCryptography/arith.lua +1 -0
- package/src/Shared/EllipticCurveCryptography/benchmark.spec.lua +1 -0
- package/src/Shared/EllipticCurveCryptography/chacha20.lua +2 -0
- package/src/Shared/EllipticCurveCryptography/curve.lua +2 -0
- package/src/Shared/EllipticCurveCryptography/init.lua +2 -1
- package/src/Shared/EllipticCurveCryptography/modp.lua +2 -0
- package/src/Shared/EllipticCurveCryptography/modq.lua +2 -0
- package/src/Shared/EllipticCurveCryptography/random.lua +49 -25
- package/src/Shared/EllipticCurveCryptography/sha256.lua +4 -0
- package/src/Shared/EllipticCurveCryptography/twoPower.lua +4 -3
- package/src/Shared/EllipticCurveCryptography/util.lua +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -3,6 +3,17 @@
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
|
5
5
|
|
|
6
|
+
# [1.2.0](https://github.com/Quenty/NevermoreEngine/compare/@quenty/ellipticcurvecryptography@1.1.0...@quenty/ellipticcurvecryptography@1.2.0) (2023-12-14)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Performance Improvements
|
|
10
|
+
|
|
11
|
+
* Improve performance of elliptic curve crypto module, saving 100ms of startup compute time on server start ([b9b500e](https://github.com/Quenty/NevermoreEngine/commit/b9b500e33b0b297c0510b28ce272c553d19408e6))
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
|
|
6
17
|
# 1.1.0 (2023-03-31)
|
|
7
18
|
|
|
8
19
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quenty/ellipticcurvecryptography",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.2.0",
|
|
4
4
|
"description": "Elliptic curve cryptography forked from BoatBomber, forked from ComputerCraft",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"Roblox",
|
|
@@ -28,5 +28,5 @@
|
|
|
28
28
|
"publishConfig": {
|
|
29
29
|
"access": "public"
|
|
30
30
|
},
|
|
31
|
-
"gitHead": "
|
|
31
|
+
"gitHead": "2c2dbbc0cb2fbb46b4f3270c559c63890fe18b26"
|
|
32
32
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
--!native
|
|
2
|
+
|
|
1
3
|
--[=[
|
|
2
4
|
Elliptic Curve Cryptography
|
|
3
5
|
|
|
@@ -36,7 +38,6 @@ local chacha20 = require(script.chacha20)
|
|
|
36
38
|
local random = require(script.random)
|
|
37
39
|
local modq = require(script.modq)
|
|
38
40
|
local curve = require(script.curve)
|
|
39
|
-
|
|
40
41
|
local EllipticCurveCryptography = {}
|
|
41
42
|
|
|
42
43
|
EllipticCurveCryptography.chacha20 = chacha20;
|
|
@@ -1,9 +1,13 @@
|
|
|
1
|
+
--!native
|
|
2
|
+
|
|
1
3
|
-- random.lua - Random Byte Generator
|
|
2
4
|
local sha256 = require(script.Parent.sha256)
|
|
3
5
|
|
|
4
6
|
local entropy = ""
|
|
5
7
|
local accumulator, accumulator_len = {}, 0
|
|
6
8
|
|
|
9
|
+
local random = {}
|
|
10
|
+
|
|
7
11
|
local function feed(data)
|
|
8
12
|
accumulator_len += 1
|
|
9
13
|
accumulator[accumulator_len] = tostring(data or "")
|
|
@@ -16,23 +20,44 @@ local function digest()
|
|
|
16
20
|
accumulator_len = 0
|
|
17
21
|
end
|
|
18
22
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
23
|
+
local entropyInitialized = false
|
|
24
|
+
|
|
25
|
+
-- Defer this initialization until requested
|
|
26
|
+
local function ensureEntropyInit()
|
|
27
|
+
if entropyInitialized then
|
|
28
|
+
return
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
local startTime = os.clock()
|
|
32
|
+
entropyInitialized = true
|
|
33
|
+
|
|
34
|
+
-- This takes about 100ms
|
|
35
|
+
|
|
36
|
+
feed("init")
|
|
37
|
+
feed(math.random(1, 2 ^ 31 - 1))
|
|
38
|
+
feed("|")
|
|
39
|
+
feed(math.random(1, 2 ^ 31 - 1))
|
|
40
|
+
feed("|")
|
|
41
|
+
feed(math.random(1, 2 ^ 4))
|
|
42
|
+
feed("|")
|
|
43
|
+
feed(DateTime.now().UnixTimestampMillis)
|
|
44
|
+
feed("|")
|
|
45
|
+
for _ = 1, 10000 do
|
|
46
|
+
feed(tostring({}):sub(-8))
|
|
47
|
+
end
|
|
48
|
+
digest()
|
|
49
|
+
feed(DateTime.now().UnixTimestampMillis)
|
|
50
|
+
digest()
|
|
51
|
+
|
|
52
|
+
random.save()
|
|
53
|
+
|
|
54
|
+
-- TODO: Suppress this warning
|
|
55
|
+
warn(string.format("[EllipticCurveCryptography.random] - Generating entropy took %s ms", 1000*(os.clock() - startTime)))
|
|
30
56
|
end
|
|
31
|
-
digest()
|
|
32
|
-
feed(DateTime.now().UnixTimestampMillis)
|
|
33
|
-
digest()
|
|
34
57
|
|
|
35
|
-
|
|
58
|
+
function random.save()
|
|
59
|
+
ensureEntropyInit()
|
|
60
|
+
|
|
36
61
|
feed("save")
|
|
37
62
|
feed(DateTime.now().UnixTimestampMillis)
|
|
38
63
|
feed({})
|
|
@@ -40,23 +65,26 @@ local function save()
|
|
|
40
65
|
|
|
41
66
|
entropy = tostring(sha256.digest(entropy))
|
|
42
67
|
end
|
|
43
|
-
save()
|
|
44
68
|
|
|
45
|
-
|
|
69
|
+
function random.seed(data)
|
|
70
|
+
ensureEntropyInit()
|
|
71
|
+
|
|
46
72
|
feed("seed")
|
|
47
73
|
feed(DateTime.now().UnixTimestampMillis)
|
|
48
74
|
feed({})
|
|
49
75
|
feed(data)
|
|
50
76
|
digest()
|
|
51
|
-
save()
|
|
77
|
+
random.save()
|
|
52
78
|
end
|
|
53
79
|
|
|
54
|
-
|
|
80
|
+
function random.random()
|
|
81
|
+
ensureEntropyInit()
|
|
82
|
+
|
|
55
83
|
feed("random")
|
|
56
84
|
feed(DateTime.now().UnixTimestampMillis)
|
|
57
85
|
feed({})
|
|
58
86
|
digest()
|
|
59
|
-
save()
|
|
87
|
+
random.save()
|
|
60
88
|
|
|
61
89
|
local result = sha256.hmac("out", entropy)
|
|
62
90
|
entropy = tostring(sha256.digest(entropy))
|
|
@@ -64,8 +92,4 @@ local function random()
|
|
|
64
92
|
return result
|
|
65
93
|
end
|
|
66
94
|
|
|
67
|
-
return
|
|
68
|
-
seed = seed,
|
|
69
|
-
save = save,
|
|
70
|
-
random = random,
|
|
71
|
-
}
|
|
95
|
+
return random
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
--!native
|
|
2
|
+
|
|
1
3
|
-- SHA-256, HMAC and PBKDF2 functions in ComputerCraft
|
|
2
4
|
-- By Anavrins
|
|
3
5
|
-- For help and details, you can PM me on the CC forums
|
|
@@ -5,6 +7,8 @@
|
|
|
5
7
|
-- http://www.computercraft.info/forums2/index.php?/user/12870-anavrins
|
|
6
8
|
-- http://pastebin.com/6UV4qfNF
|
|
7
9
|
-- Last update: October 10, 2017
|
|
10
|
+
-- Updated by Quenty December 4th, 2023
|
|
11
|
+
|
|
8
12
|
local twoPower = require(script.Parent.twoPower)
|
|
9
13
|
local util = require(script.Parent.util)
|
|
10
14
|
|
|
@@ -6,9 +6,10 @@ local twoPower = setmetatable({}, {
|
|
|
6
6
|
end,
|
|
7
7
|
})
|
|
8
8
|
|
|
9
|
+
-- NOTE: This takes somewhere between 1.5 ms to 4 ms
|
|
9
10
|
-- precache
|
|
10
|
-
for index = -512, 512 do
|
|
11
|
-
|
|
12
|
-
end
|
|
11
|
+
-- for index = -512, 512 do
|
|
12
|
+
-- twoPower[index] = 2 ^ index
|
|
13
|
+
-- end
|
|
13
14
|
|
|
14
15
|
return twoPower
|