Skip to content

Commit

Permalink
Be sane with checking messageLen in SHA modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Dekkonot committed Oct 1, 2023
1 parent 0c924cb commit 190b9dc
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion modules/sha1/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ local function sha1(message: string): (string, { number })

local messageLen = #message
local leftover = messageLen % 64
if messageLen / 64 >= 1 then
if messageLen >= 64 then
processBlocks(digest, message, 1, messageLen - leftover)
end

Expand Down
2 changes: 1 addition & 1 deletion modules/sha224/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ local function sha224(message: string): (string, { number })

local messageLen = #message
local leftover = messageLen % 64
if messageLen / 64 > 1 then
if messageLen >= 64 then
processBlocks(digest, message, 1, messageLen - leftover)
end

Expand Down
2 changes: 1 addition & 1 deletion modules/sha256/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ local function sha256(message: string): (string, { number })

local messageLen = #message
local leftover = messageLen % 64
if messageLen / 64 > 1 then
if messageLen >= 64 then
processBlocks(digest, message, 1, messageLen - leftover)
end

Expand Down
2 changes: 1 addition & 1 deletion modules/sha384/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ local function sha384(message: string): string

-- SHA-384 has a block size of 1024 bits or 128 bytes
local leftover = messageLen % 128
if messageLen / 128 > 1 then
if messageLen >= 128 then
processBlocks(digest_front, digest_back, message, 1, messageLen - leftover)
end
local finalMessage = {
Expand Down
2 changes: 1 addition & 1 deletion modules/sha512/init.luau
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ local function sha512(message: string): string

-- SHA-512 has a block size of 1024 bits or 128 bytes
local leftover = messageLen % 128
if messageLen / 128 > 1 then
if messageLen >= 128 then
processBlocks(digest_front, digest_back, message, 1, messageLen - leftover)
end
local finalMessage = {
Expand Down

0 comments on commit 190b9dc

Please sign in to comment.