Expand description
SHA-1 digest helpers. Exposed because the operator-side wire layer (kevy-rt’s SCRIPT LOAD / EVALSHA codec) needs to convert between the 20-byte digest used as a cache key and the 40-char ASCII hex Redis uses on the wire. Hand-rolled SHA-1 (RFC 3174 / FIPS 180-1).
Used by the SCRIPT LOAD / EVALSHA cache key and the
redis.sha1hex host fn. Kevy’s L2 lockdown forbids crates.io
third-party deps; SHA-1 is short enough to write once and lint
against well-known test vectors.
§NOT a security primitive
SHA-1 is broken for collision resistance (SHAttered, 2017+). That doesn’t matter here — kevy uses it as a content-addressed cache key the same way Redis does, where collisions would only cause cross-script cache hits (which never produces a security issue) and Redis itself uses SHA-1 for the same reason.
If kevy ever needs SHA-1 / SHA-256 for an actual security-bearing
purpose, that’s a separate kevy-crypto stone, not here.
use kevy_lua::sha1;
let digest = sha1::sha1(b"abc");
let hex = sha1::hex(&digest);
assert_eq!(&hex, b"a9993e364706816aba3e25717850c26c9cd0d89d");
assert_eq!(sha1::parse_hex(&hex), Some(digest));