ia64/xen-unstable

changeset 17930:51b392ab1912

blktap: Fall back to libcrypto if libgcrypt is not installed.
Signed-off-by: Keir Fraser <keir.fraser@citrix.com>
author Keir Fraser <keir.fraser@citrix.com>
date Mon Jun 30 11:39:10 2008 +0100 (2008-06-30)
parents 81d47e75ce1a
children c33a40b4c22b
files tools/blktap/drivers/Makefile tools/blktap/drivers/block-qcow.c tools/blktap/drivers/check_gcrypt
line diff
     1.1 --- a/tools/blktap/drivers/Makefile	Mon Jun 30 10:02:21 2008 +0100
     1.2 +++ b/tools/blktap/drivers/Makefile	Mon Jun 30 11:39:10 2008 +0100
     1.3 @@ -17,8 +17,16 @@ CFLAGS   += -D_GNU_SOURCE
     1.4  CFLAGS   += -Wp,-MD,.$(@F).d
     1.5  DEPS      = .*.d
     1.6  
     1.7 +ifeq ($(shell . ./check_gcrypt),"yes")
     1.8 +CFLAGS += -DUSE_GCRYPT
     1.9 +CRYPT_LIB := -lgcrypt
    1.10 +else
    1.11 +CRYPT_LIB := -lcrypto
    1.12 +$(warning *** libgcrypt not installed: falling back to libcrypto ***)
    1.13 +endif
    1.14 +
    1.15  LDFLAGS_blktapctrl := $(LDFLAGS_libxenctrl) $(LDFLAGS_libxenstore) -L../lib -lblktap
    1.16 -LDFLAGS_img := $(LIBAIO_DIR)/libaio.a -lgcrypt -lpthread -lz
    1.17 +LDFLAGS_img := $(LIBAIO_DIR)/libaio.a $(CRYPT_LIB) -lpthread -lz
    1.18  
    1.19  BLK-OBJS-y  := block-aio.o
    1.20  BLK-OBJS-y  += block-sync.o
     2.1 --- a/tools/blktap/drivers/block-qcow.c	Mon Jun 30 10:02:21 2008 +0100
     2.2 +++ b/tools/blktap/drivers/block-qcow.c	Mon Jun 30 11:39:10 2008 +0100
     2.3 @@ -33,7 +33,6 @@
     2.4  #include <zlib.h>
     2.5  #include <inttypes.h>
     2.6  #include <libaio.h>
     2.7 -#include <gcrypt.h>
     2.8  #include "bswap.h"
     2.9  #include "aes.h"
    2.10  #include "tapdisk.h"
    2.11 @@ -146,6 +145,10 @@ struct tdqcow_state {
    2.12  
    2.13  static int decompress_cluster(struct tdqcow_state *s, uint64_t cluster_offset);
    2.14  
    2.15 +#ifdef USE_GCRYPT
    2.16 +
    2.17 +#include <gcrypt.h>
    2.18 +
    2.19  static uint32_t gen_cksum(char *ptr, int len)
    2.20  {
    2.21  	int i;
    2.22 @@ -167,6 +170,41 @@ static uint32_t gen_cksum(char *ptr, int
    2.23  	return md[0];
    2.24  }
    2.25  
    2.26 +#else /* use libcrypto */
    2.27 +
    2.28 +#include <openssl/md5.h>
    2.29 +
    2.30 +static uint32_t gen_cksum(char *ptr, int len)
    2.31 +{
    2.32 +	int i;
    2.33 +	unsigned char *md;
    2.34 +	uint32_t ret;
    2.35 +
    2.36 +	md = malloc(MD5_DIGEST_LENGTH);
    2.37 +	if(!md) return 0;
    2.38 +
    2.39 +	/* Convert L1 table to big endian */
    2.40 +	for(i = 0; i < len / sizeof(uint64_t); i++) {
    2.41 +		cpu_to_be64s(&((uint64_t*) ptr)[i]);
    2.42 +	}
    2.43 +
    2.44 +	/* Generate checksum */
    2.45 +	if (MD5((unsigned char *)ptr, len, md) != md)
    2.46 +		ret = 0;
    2.47 +	else
    2.48 +		memcpy(&ret, md, sizeof(uint32_t));
    2.49 +
    2.50 +	/* Convert L1 table back to native endianess */
    2.51 +	for(i = 0; i < len / sizeof(uint64_t); i++) {
    2.52 +		be64_to_cpus(&((uint64_t*) ptr)[i]);
    2.53 +	}
    2.54 +
    2.55 +	free(md);
    2.56 +	return ret;
    2.57 +}
    2.58 +
    2.59 +#endif
    2.60 +
    2.61  static int get_filesize(char *filename, uint64_t *size, struct stat *st)
    2.62  {
    2.63  	int fd;
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/tools/blktap/drivers/check_gcrypt	Mon Jun 30 11:39:10 2008 +0100
     3.3 @@ -0,0 +1,14 @@
     3.4 +#!/bin/sh
     3.5 +
     3.6 +cat > .gcrypt.c << EOF
     3.7 +#include <gcrypt.h>
     3.8 +int main(void) { return 0; }
     3.9 +EOF
    3.10 +
    3.11 +if $1 -o .gcrypt .gcrypt.c -lgcrypt 2>/dev/null ; then
    3.12 +  echo "yes"
    3.13 +else
    3.14 +  echo "no"
    3.15 +fi
    3.16 +
    3.17 +rm -f .gcrypt*