btrfs-progs: tests: fssum, switch from MD5 to SHA256

Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
David Sterba 2017-03-15 12:21:50 +01:00
parent 4ddd6055c3
commit b5d4b3cef3
2 changed files with 9 additions and 10 deletions

View File

@ -466,10 +466,9 @@ library-test.static: library-test.c messages.static.o $(libs_static)
@echo " [TEST CLEAN] $@" @echo " [TEST CLEAN] $@"
$(Q)$(RM) -rf -- $(TMPD) $(Q)$(RM) -rf -- $(TMPD)
fssum: tests/fssum.c fssum: tests/fssum.c tests/sha224-256.c
@echo " [LD] $@" @echo " [LD] $@"
# FIXME: no configure-time check for libcrypto from SSL $(Q)$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
$(Q)$(CC) $(CFLAGS) -o $@ $< $(LDFLAGS) -lcrypto
test-build: test-build-pre test-build-real test-build: test-build-pre test-build-real

View File

@ -25,12 +25,12 @@
#include <dirent.h> #include <dirent.h>
#include <errno.h> #include <errno.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <openssl/md5.h>
#include <assert.h> #include <assert.h>
#include <time.h> #include <time.h>
#include <stdint.h> #include <stdint.h>
#include "tests/sha.h"
#define CS_SIZE 16 #define CS_SIZE 32
#define CHUNKS 128 #define CHUNKS 128
#ifndef SEEK_DATA #ifndef SEEK_DATA
@ -47,8 +47,8 @@ struct excludes {
}; };
typedef struct _sum { typedef struct _sum {
MD5_CTX md5; SHA256Context sha;
unsigned char out[16]; unsigned char out[CS_SIZE];
} sum_t; } sum_t;
typedef int (*sum_file_data_t)(int fd, sum_t *dst); typedef int (*sum_file_data_t)(int fd, sum_t *dst);
@ -173,19 +173,19 @@ alloc(size_t sz)
void void
sum_init(sum_t *cs) sum_init(sum_t *cs)
{ {
MD5_Init(&cs->md5); SHA256Reset(&cs->sha);
} }
void void
sum_fini(sum_t *cs) sum_fini(sum_t *cs)
{ {
MD5_Final(cs->out, &cs->md5); SHA256Result(&cs->sha, cs->out);
} }
void void
sum_add(sum_t *cs, void *buf, int size) sum_add(sum_t *cs, void *buf, int size)
{ {
MD5_Update(&cs->md5, buf, size); SHA256Input(&cs->sha, buf, size);
} }
void void