For data integrity, specifically for small blocks of data, rather than using a SHA-256 hash, or simply truncating a SHA-512 hash, I am playing with the following idea:
function saferHash(data) {
let hash1Entropy = 42; // sha512:42
let hash2Entropy = 4; // 4B extra possible protected outcomes in case of highly unlikely collision in hash 1
const hash1 = sha512(data).slice(0,hash1Entropy); // for 42 byte entropy, truncated to save space + prevent length extension vulnerabilities
const hash2 = blake3(data).slice(0,hash2Entropy); // cheapest extra forgery prevention in case of sha512:42 hash collision, truncated to save space + prevent length extension vulnerabilities
return new Uint8Array([...hash1,...hash2]); // 46 byte total hash
}
Is this totally overengineering the whole thing or is it actually not too bad of an idea to increase the entropy to +32 bytes and use an additional cheap hash function (blake3) to increase the difficulty of creating a collision even more?