diff options
author | Keir Fraser <keir.fraser@citrix.com> | 2008-06-30 11:39:10 +0100 |
---|---|---|
committer | Keir Fraser <keir.fraser@citrix.com> | 2008-06-30 11:39:10 +0100 |
commit | 04465fbeb9188b148101cff73994496c40355582 (patch) | |
tree | 37acd840b347676ad7d4678cb207639b5be30e6a | |
parent | dd258ce6c05ebf242793751676de1136d519a2ee (diff) | |
download | xen-04465fbeb9188b148101cff73994496c40355582.tar.gz xen-04465fbeb9188b148101cff73994496c40355582.tar.bz2 xen-04465fbeb9188b148101cff73994496c40355582.zip |
blktap: Fall back to libcrypto if libgcrypt is not installed.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
-rw-r--r-- | tools/blktap/drivers/Makefile | 10 | ||||
-rw-r--r-- | tools/blktap/drivers/block-qcow.c | 40 | ||||
-rw-r--r-- | tools/blktap/drivers/check_gcrypt | 14 |
3 files changed, 62 insertions, 2 deletions
diff --git a/tools/blktap/drivers/Makefile b/tools/blktap/drivers/Makefile index 548f080e7c..b1f4410cc9 100644 --- a/tools/blktap/drivers/Makefile +++ b/tools/blktap/drivers/Makefile @@ -17,8 +17,16 @@ CFLAGS += -D_GNU_SOURCE CFLAGS += -Wp,-MD,.$(@F).d DEPS = .*.d +ifeq ($(shell . ./check_gcrypt),"yes") +CFLAGS += -DUSE_GCRYPT +CRYPT_LIB := -lgcrypt +else +CRYPT_LIB := -lcrypto +$(warning *** libgcrypt not installed: falling back to libcrypto ***) +endif + LDFLAGS_blktapctrl := $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenstore) -L../lib -lblktap -LDFLAGS_img := $(LIBAIO_DIR)/libaio.a -lgcrypt -lpthread -lz +LDFLAGS_img := $(LIBAIO_DIR)/libaio.a $(CRYPT_LIB) -lpthread -lz BLK-OBJS-y := block-aio.o BLK-OBJS-y += block-sync.o diff --git a/tools/blktap/drivers/block-qcow.c b/tools/blktap/drivers/block-qcow.c index dd6c6c7c07..1f3b46936c 100644 --- a/tools/blktap/drivers/block-qcow.c +++ b/tools/blktap/drivers/block-qcow.c @@ -33,7 +33,6 @@ #include <zlib.h> #include <inttypes.h> #include <libaio.h> -#include <gcrypt.h> #include "bswap.h" #include "aes.h" #include "tapdisk.h" @@ -146,6 +145,10 @@ struct tdqcow_state { static int decompress_cluster(struct tdqcow_state *s, uint64_t cluster_offset); +#ifdef USE_GCRYPT + +#include <gcrypt.h> + static uint32_t gen_cksum(char *ptr, int len) { int i; @@ -167,6 +170,41 @@ static uint32_t gen_cksum(char *ptr, int len) return md[0]; } +#else /* use libcrypto */ + +#include <openssl/md5.h> + +static uint32_t gen_cksum(char *ptr, int len) +{ + int i; + unsigned char *md; + uint32_t ret; + + md = malloc(MD5_DIGEST_LENGTH); + if(!md) return 0; + + /* Convert L1 table to big endian */ + for(i = 0; i < len / sizeof(uint64_t); i++) { + cpu_to_be64s(&((uint64_t*) ptr)[i]); + } + + /* Generate checksum */ + if (MD5((unsigned char *)ptr, len, md) != md) + ret = 0; + else + memcpy(&ret, md, sizeof(uint32_t)); + + /* Convert L1 table back to native endianess */ + for(i = 0; i < len / sizeof(uint64_t); i++) { + be64_to_cpus(&((uint64_t*) ptr)[i]); + } + + free(md); + return ret; +} + +#endif + static int get_filesize(char *filename, uint64_t *size, struct stat *st) { int fd; diff --git a/tools/blktap/drivers/check_gcrypt b/tools/blktap/drivers/check_gcrypt new file mode 100644 index 0000000000..154ba2492a --- /dev/null +++ b/tools/blktap/drivers/check_gcrypt @@ -0,0 +1,14 @@ +#!/bin/sh + +cat > .gcrypt.c << EOF +#include <gcrypt.h> +int main(void) { return 0; } +EOF + +if $1 -o .gcrypt .gcrypt.c -lgcrypt 2>/dev/null ; then + echo "yes" +else + echo "no" +fi + +rm -f .gcrypt* |