Fastest SHA256 Hash
This is over 4x times faster than Hashlib and the input has to be a buffer!
local Message: string = "Hello World"
local MessageBuffer: buffer = buffer.fromstring("Hello World")
local OptionalSalt: string = "Salt"
local OptionalSaltBuffer: buffer = buffer.fromstring("Salt")
assert(SHA256(MessageBuffer) == SHA256(buffer.fromstring(Message)))
assert(SHA256(MessageBuffer, OptionalSaltBuffer) == SHA256(buffer.fromstring(Message .. OptionalSalt)))
assert(SHA256(MessageBuffer, OptionalSaltBuffer) == SHA256(buffer.fromstring(Message), buffer.fromstring(OptionalSalt)))
assert(SHA256(buffer.fromstring("The quick brown fox jumps over the lazy dog.")) == "ef537f25c895bfa782526529a9b63d97aa631564d5d789c2b765448c8635fb6c")
Benchmark Results
Iterations: 500
Message Length: 29204
HashLib took: 1,492,559 microseconds
The old version took: 332,778 microseconds - 348.5% faster than HashLib
Dekkonot’s SHA256 took: 346,156 microseconds
This version took: 276,341 microseconds - 23.2% faster than Dekkonot’s SHA256 - 428.8% faster than HashLib
Download:
SHA256.rbxm (5.3 KB)