forked from Mirrors/btrfs-progs
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>master
parent
785073f658
commit
ae9f8bff30
2
Makefile
2
Makefile
|
@ -157,7 +157,7 @@ libbtrfs_objects = send-stream.o send-utils.o kernel-lib/rbtree.o btrfs-list.o \
|
||||||
kernel-lib/raid56.o kernel-lib/tables.o \
|
kernel-lib/raid56.o kernel-lib/tables.o \
|
||||||
common/device-scan.o common/path-utils.o \
|
common/device-scan.o common/path-utils.o \
|
||||||
common/utils.o libbtrfsutil/subvolume.o libbtrfsutil/stubs.o \
|
common/utils.o libbtrfsutil/subvolume.o libbtrfsutil/stubs.o \
|
||||||
crypto/hash.o crypto/xxhash.o
|
crypto/hash.o crypto/xxhash.o crypto/sha224-256.o
|
||||||
libbtrfs_headers = send-stream.h send-utils.h send.h kernel-lib/rbtree.h btrfs-list.h \
|
libbtrfs_headers = send-stream.h send-utils.h send.h kernel-lib/rbtree.h btrfs-list.h \
|
||||||
crypto/crc32c.h kernel-lib/list.h kerncompat.h \
|
crypto/crc32c.h kernel-lib/list.h kerncompat.h \
|
||||||
kernel-lib/radix-tree.h kernel-lib/sizes.h kernel-lib/raid56.h \
|
kernel-lib/radix-tree.h kernel-lib/sizes.h kernel-lib/raid56.h \
|
||||||
|
|
|
@ -316,6 +316,7 @@ static bool is_valid_csum_type(u16 csum_type)
|
||||||
switch (csum_type) {
|
switch (csum_type) {
|
||||||
case BTRFS_CSUM_TYPE_CRC32:
|
case BTRFS_CSUM_TYPE_CRC32:
|
||||||
case BTRFS_CSUM_TYPE_XXHASH:
|
case BTRFS_CSUM_TYPE_XXHASH:
|
||||||
|
case BTRFS_CSUM_TYPE_SHA256:
|
||||||
return true;
|
return true;
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "crypto/hash.h"
|
#include "crypto/hash.h"
|
||||||
#include "crypto/crc32c.h"
|
#include "crypto/crc32c.h"
|
||||||
#include "crypto/xxhash.h"
|
#include "crypto/xxhash.h"
|
||||||
|
#include "crypto/sha.h"
|
||||||
|
|
||||||
int hash_crc32c(const u8* buf, size_t length, u8 *out)
|
int hash_crc32c(const u8* buf, size_t length, u8 *out)
|
||||||
{
|
{
|
||||||
|
@ -25,3 +26,14 @@ int hash_xxhash(const u8 *buf, size_t length, u8 *out)
|
||||||
|
|
||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
|
|
@ -7,5 +7,6 @@
|
||||||
|
|
||||||
int hash_crc32c(const u8 *buf, size_t length, u8 *out);
|
int hash_crc32c(const u8 *buf, size_t length, u8 *out);
|
||||||
int hash_xxhash(const u8 *buf, size_t length, u8 *out);
|
int hash_xxhash(const u8 *buf, size_t length, u8 *out);
|
||||||
|
int hash_sha256(const u8 *buf, size_t length, u8 *out);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -40,8 +40,8 @@
|
||||||
* to hash the final few bits of the input.
|
* to hash the final few bits of the input.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "tests/sha.h"
|
#include "crypto/sha.h"
|
||||||
#include "tests/sha-private.h"
|
#include "crypto/sha-private.h"
|
||||||
|
|
||||||
/* Define the SHA shift, rotate left, and rotate right macros */
|
/* Define the SHA shift, rotate left, and rotate right macros */
|
||||||
#define SHA256_SHR(bits,word) ((word) >> (bits))
|
#define SHA256_SHR(bits,word) ((word) >> (bits))
|
||||||
|
|
1
ctree.c
1
ctree.c
|
@ -44,6 +44,7 @@ static const struct btrfs_csum {
|
||||||
} btrfs_csums[] = {
|
} btrfs_csums[] = {
|
||||||
[BTRFS_CSUM_TYPE_CRC32] = { 4, "crc32c" },
|
[BTRFS_CSUM_TYPE_CRC32] = { 4, "crc32c" },
|
||||||
[BTRFS_CSUM_TYPE_XXHASH] = { 8, "xxhash64" },
|
[BTRFS_CSUM_TYPE_XXHASH] = { 8, "xxhash64" },
|
||||||
|
[BTRFS_CSUM_TYPE_SHA256] = { 32, "sha256" },
|
||||||
};
|
};
|
||||||
|
|
||||||
u16 btrfs_super_csum_size(const struct btrfs_super_block *sb)
|
u16 btrfs_super_csum_size(const struct btrfs_super_block *sb)
|
||||||
|
|
1
ctree.h
1
ctree.h
|
@ -168,6 +168,7 @@ struct btrfs_free_space_ctl;
|
||||||
enum btrfs_csum_type {
|
enum btrfs_csum_type {
|
||||||
BTRFS_CSUM_TYPE_CRC32 = 0,
|
BTRFS_CSUM_TYPE_CRC32 = 0,
|
||||||
BTRFS_CSUM_TYPE_XXHASH = 1,
|
BTRFS_CSUM_TYPE_XXHASH = 1,
|
||||||
|
BTRFS_CSUM_TYPE_SHA256 = 2,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define BTRFS_EMPTY_DIR_SIZE 0
|
#define BTRFS_EMPTY_DIR_SIZE 0
|
||||||
|
|
|
@ -148,6 +148,8 @@ int btrfs_csum_data(u16 csum_type, const u8 *data, u8 *out, size_t len)
|
||||||
return hash_crc32c(data, len, out);
|
return hash_crc32c(data, len, out);
|
||||||
case BTRFS_CSUM_TYPE_XXHASH:
|
case BTRFS_CSUM_TYPE_XXHASH:
|
||||||
return hash_xxhash(data, len, out);
|
return hash_xxhash(data, len, out);
|
||||||
|
case BTRFS_CSUM_TYPE_SHA256:
|
||||||
|
return hash_sha256(data, len, out);
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "ERROR: unknown csum type: %d\n", csum_type);
|
fprintf(stderr, "ERROR: unknown csum type: %d\n", csum_type);
|
||||||
ASSERT(0);
|
ASSERT(0);
|
||||||
|
|
|
@ -395,6 +395,8 @@ static enum btrfs_csum_type parse_csum_type(const char *s)
|
||||||
} else if (strcasecmp(s, "xxhash64") == 0 ||
|
} else if (strcasecmp(s, "xxhash64") == 0 ||
|
||||||
strcasecmp(s, "xxhash") == 0) {
|
strcasecmp(s, "xxhash") == 0) {
|
||||||
return BTRFS_CSUM_TYPE_XXHASH;
|
return BTRFS_CSUM_TYPE_XXHASH;
|
||||||
|
} else if (strcasecmp(s, "sha256") == 0) {
|
||||||
|
return BTRFS_CSUM_TYPE_SHA256;
|
||||||
} else {
|
} else {
|
||||||
error("unknown csum type %s", s);
|
error("unknown csum type %s", s);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
|
Loading…
Reference in New Issue