From 8dd5e7a87ee5626e89c14d2a989b4795bebd5c05 Mon Sep 17 00:00:00 2001 From: Simon Wilkinson Date: Wed, 22 Sep 2010 09:03:27 +0100 Subject: [PATCH] Add an LWP version of the hcrypto library hcrypto uses a single pthread mutex, which is only required when we're running in a pthreaded world (in a cooperative threading world such as LWP, there's no way that two processes can both access the Fortuna PRNG at the same time) So, build an LWP version of hcrypto which just disables the mutexes. Change-Id: I0b894cfa0d16ba6d16544a4d725191c965ac6e50 Reviewed-on: http://gerrit.openafs.org/2833 Tested-by: BuildBot Reviewed-by: Derrick Brashear Tested-by: Derrick Brashear --- src/crypto/hcrypto/Makefile.in | 36 ++++++++++++++++++++++++------- src/crypto/hcrypto/heim_threads.h | 15 +++++++++++++ 2 files changed, 43 insertions(+), 8 deletions(-) diff --git a/src/crypto/hcrypto/Makefile.in b/src/crypto/hcrypto/Makefile.in index 436ffe4e8..64581325c 100644 --- a/src/crypto/hcrypto/Makefile.in +++ b/src/crypto/hcrypto/Makefile.in @@ -35,7 +35,9 @@ HEADERS= ${TOP_INCDIR}/hcrypto/aes.h \ SHLIBOBJ= libafshcrypto.${SHLIB_SUFFIX}.${LIBMAJOR}.${LIBMINOR} -all: ${HEADERS} ${TOP_LIBDIR}/${SHLIBOBJ} ${TOP_LIBDIR}/libafshcrypto.a +all: ${HEADERS} ${TOP_LIBDIR}/${SHLIBOBJ} \ + ${TOP_LIBDIR}/libafshcrypto.a \ + ${TOP_LIBDIR}/libafshcrypto_lwp.a install: libafshcrypto.a ${SHLIBOBJ} ${TOP_OBJDIR}/src/config/shlib-install -d ${DESTDIR}${libdir} \ @@ -51,17 +53,23 @@ clean: $(RM) -f ${OBJECTS} ${SHLIBOBJ} libafshcrypto.a libafshcrypto.exp \ test_cipher test_cipher.o hex.o -# Ignore for now : rand-egd.o +COMMON_OBJS= aes.o camellia.o camellia-ntt.o des.o engine.o evp.o \ + evp-hcrypto.o evp-cc.o hmac.o md2.o md4.o md5.o pkcs5.o \ + rand-egd.o rand-timer.o rand-unix.o rand.o \ + rc2.o rc4.o rijndael-alg-fst.o rnd_keys.o sha.o sha256.o ui.o \ + cloexec.o ct.o issuid.o net_read.o net_write.o strlcpy.o -OBJECTS= aes.o camellia.o camellia-ntt.o des.o engine.o evp.o \ - evp-hcrypto.o evp-cc.o hmac.o md2.o md4.o md5.o pkcs5.o \ - rand-egd.o rand-fortuna.o rand-timer.o rand-unix.o rand.o \ - rc2.o rc4.o rijndael-alg-fst.o rnd_keys.o sha.o sha256.o ui.o \ - cloexec.o ct.o issuid.o net_read.o net_write.o strlcpy.o +OBJECTS = $(COMMON_OBJS) rand-fortuna.o + +LWP_OBJS = $(COMMON_OBJS) rand-fortuna_lwp.o UPSTREAM= ${TOP_SRCDIR}/external/heimdal -CCRULE = ${CC} -I${TOP_INCDIR}/hcrypto ${CFLAGS} -I${UPSTREAM}/hcrypto -c $? +CFLAGS=$(COMMON_CFLAGS) $(MT_CFLAGS) $(SHLIB_CFLAGS) +CCRULE = $(MT_CC) -I${TOP_INCDIR}/hcrypto ${CFLAGS} -I${UPSTREAM}/hcrypto -c $? + +LWPRULE=$(CC) $(COMMON_CFLAGS) $(XCFLAGS) $(ARCHFLAGS) \ + -I$(TOP_INCDIR)/hcrypto -I$(UPSTREAM)/hcrypto -c $? ${TOP_LIBDIR}/${SHLIBOBJ}: ${SHLIBOBJ} ${TOP_OBJDIR}/src/config/shlib-install -d ${TOP_LIBDIR} \ @@ -77,6 +85,11 @@ libafshcrypto.a: ${OBJECTS} $(AR) crv $@ ${OBJECTS} $(RANLIB) $@ +libafshcrypto_lwp.a: $(LWP_OBJS) + $(RM) -f $@ + $(AR) crv $@ $(LWP_OBJS) + $(RANLIB) $@ + test_cipher: test_cipher.o hex.o libafshcrypto.a ${CC} ${LDFLAGS} -o test_cipher test_cipher.o hex.o libafshcrypto.a @@ -143,6 +156,10 @@ ${TOP_INCDIR}/hcrypto/ui.h: ${UPSTREAM}/hcrypto/ui.h ${TOP_LIBDIR}/libafshcrypto.a: libafshcrypto.a ${INSTALL_DATA} $? $@ +${TOP_LIBDIR}/libafshcrypto_lwp.a: libafshcrypto_lwp.a + ${INSTALL_DATA} $? $@ + + aes.o: ${UPSTREAM}/hcrypto/aes.c ${CCRULE} @@ -200,6 +217,9 @@ rand-egd.o: ${UPSTREAM}/hcrypto/rand-egd.c rand-fortuna.o: ${UPSTREAM}/hcrypto/rand-fortuna.c ${CCRULE} +rand-fortuna_lwp.o: ${UPSTREAM}/hcrypto/rand-fortuna.c + ${LWPRULE} -o rand-fortuna_lwp.o + rand-timer.o: ${UPSTREAM}/hcrypto/rand-timer.c ${CCRULE} diff --git a/src/crypto/hcrypto/heim_threads.h b/src/crypto/hcrypto/heim_threads.h index 94108975c..fe85b5bb8 100644 --- a/src/crypto/hcrypto/heim_threads.h +++ b/src/crypto/hcrypto/heim_threads.h @@ -1,3 +1,4 @@ +#ifdef AFS_PTHREAD_ENV #include #define HEIMDAL_MUTEX pthread_mutex_t @@ -6,3 +7,17 @@ #define HEIMDAL_MUTEX_lock(m) pthread_mutex_lock(m) #define HEIMDAL_MUTEX_unlock(m) pthread_mutex_unlock(m) #define HEIMDAL_MUTEX_destroy(m) pthread_mutex_destroy(m) +#else +/* The one location in hcrypto which uses mutexes is the PRNG + * code. As this code takes no locks, never yields, and does no + * I/O through the LWP IO Manager, it cannot be pre-empted, so + * it is safe to simply remove the locks in this case + */ +#define HEIMDAL_MUTEX int +#define HEIMDAL_MUTEX_INITIALIZER 0 +#define HEIMDAL_MUTEX_init(m) do { (void)(m); } while(0) +#define HEIMDAL_MUTEX_lock(m) do { (void)(m); } while(0) +#define HEIMDAL_MUTEX_unlock(m) do { (void)(m); } while(0) +#define HEIMDAL_MUTEX_destroy(m) do { (void)(m); } while(0) +#endif + -- 2.39.5