Merge pull request #1 from migeyel/develop

Various fixes
This commit is contained in:
Miguel Oliveira 2023-07-18 21:14:49 -03:00 committed by GitHub
commit 9d7943920f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 3 deletions

View file

@ -95,7 +95,7 @@ if not string.pack or pcall(string.dump, string.pack) then
local w = {} local w = {}
for i in fmt:gmatch("I([%d]+)") do for i in fmt:gmatch("I([%d]+)") do
local n = tonumber(i) or 4 local n = tonumber(i) or 4
assert(n > 0 and n <= 4, "integral size out of limits") assert(n > 0 and n <= 16, "integral size out of limits")
w[#w + 1] = n w[#w + 1] = n
end end
return fn(w, e == ">") return fn(w, e == ">")

View file

@ -30,6 +30,7 @@ end
--- Mixes extra entropy into the generator state. --- Mixes extra entropy into the generator state.
--- @param data string The additional entropy to mix. --- @param data string The additional entropy to mix.
local function mix(data) local function mix(data)
expect(1, data, "string")
state = blake3.digestKeyed(state, data) state = blake3.digestKeyed(state, data)
end end
@ -39,7 +40,7 @@ end
local function random(len) local function random(len)
expect(1, len, "number") expect(1, len, "number")
lassert(initialized, "attempt to use an uninitialized random generator", 2) lassert(initialized, "attempt to use an uninitialized random generator", 2)
local msg = ("\0"):rep(len + 32) local msg = ("\0"):rep(math.max(len, 0) + 32)
local nonce = ("\0"):rep(12) local nonce = ("\0"):rep(12)
local out = chacha20.crypt(state, nonce, msg, 8, 0) local out = chacha20.crypt(state, nonce, msg, 8, 0)
state = out:sub(1, 32) state = out:sub(1, 32)

View file

@ -1,7 +1,7 @@
--- General utilities for handling byte strings. --- General utilities for handling byte strings.
local expect = require "cc.expect".expect local expect = require "cc.expect".expect
local random = require "cryptolib.random" local random = require "ccryptolib.random"
local poly1305 = require "ccryptolib.poly1305" local poly1305 = require "ccryptolib.poly1305"
--- Returns the hexadecimal version of a string. --- Returns the hexadecimal version of a string.