btrfs-progs/crypto/hash.c
Johannes Thumshirn ae9f8bff30 btrfs-progs: add sha256 as supported checksumming algorithm
Add the definition to the checksum types and let mkfs accept it.

Signed-off-by: Johannes Thumshirn <jthumshirn@suse.de>
Signed-off-by: David Sterba <dsterba@suse.com>
2019-11-18 19:20:40 +01:00

40 lines
717 B
C

#include "crypto/hash.h"
#include "crypto/crc32c.h"
#include "crypto/xxhash.h"
#include "crypto/sha.h"
int hash_crc32c(const u8* buf, size_t length, u8 *out)
{
u32 crc = ~0;
crc = crc32c(~0, buf, length);
put_unaligned_le32(~crc, out);
return 0;
}
int hash_xxhash(const u8 *buf, size_t length, u8 *out)
{
XXH64_hash_t hash;
hash = XXH64(buf, length, 0);
/*
* NOTE: we're not taking the canonical form here but the plain hash to
* be compatible with the kernel implementation!
*/
memcpy(out, &hash, 8);
return 0;
}
int hash_sha256(const u8 *buf, size_t len, u8 *out)
{
SHA256Context context;
SHA256Reset(&context);
SHA256Input(&context, buf, len);
SHA256Result(&context, out);
return 0;
}