]> git.michaelhowe.org Git - packages/o/openafs.git/commitdiff
Add an LWP version of the hcrypto library
authorSimon Wilkinson <sxw@your-file-system.com>
Wed, 22 Sep 2010 08:03:27 +0000 (09:03 +0100)
committerDerrick Brashear <shadow@dementia.org>
Thu, 23 Sep 2010 09:35:19 +0000 (02:35 -0700)
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 <buildbot@rampaginggeek.com>
Reviewed-by: Derrick Brashear <shadow@dementia.org>
Tested-by: Derrick Brashear <shadow@dementia.org>
src/crypto/hcrypto/Makefile.in
src/crypto/hcrypto/heim_threads.h

index 436ffe4e8324c9caeab764e65e530b939b8d6823..64581325cf204939c4d9d52f9cdcf6118b950a15 100644 (file)
@@ -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}
 
index 94108975cb182b215961e82157f76b4fb5e74c3e..fe85b5bb89fc9efaac18d780c8d6811399c63925 100644 (file)
@@ -1,3 +1,4 @@
+#ifdef AFS_PTHREAD_ENV
 #include <pthread.h>
 
 #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
+