summaryrefslogtreecommitdiffstats
path: root/libglusterfs
diff options
context:
space:
mode:
authorKaleb KEITHLEY <kkeithle@redhat.com>2012-03-27 11:14:23 -0400
committerAnand Avati <avati@redhat.com>2012-04-04 16:13:21 -0700
commit69f70038171862daedcbbccf0eaba3d1f8d885f5 (patch)
tree02d65653ee21abd3f44836bc99d97150df51879a /libglusterfs
parent3c5aed7d8226e50296c6a7106e0d59682732e9b5 (diff)
Replace GPLV3 MD5 with OpenSSL MD5
Ric asked me to look at replacing the GPL licensed MD5 code with something better, i.e. perhaps faster, and with a less restrictive license, etc. So I took a couple hour holiday from working on wrapping up the client_t and did this. OpenSSL (nee SSLeay) is released under the OpenSSL license, a BSD/MIT style license. OpenSSL (libcrypto.so) is used on Linux, OS X and *BSD, Open Solaris, etc. IOW it's universally available on the platforms we care about. It's written by Eric Young (eay), now at EMC/RSA, and I can say from experience that the OpenSSL implementation of MD5 (at least) is every bit as fast as RSA's proprietary implementation (primarily because the implementations are very, very similar.) The last time I surveyed MD5 implementations I found they're all pretty much the same speed. I changed the APIs (and ABIs) for the strong and weak checksums. Strictly speaking I didn't need to do that. They're only called on short strings of data, i.e. pathnames, so using int32_t and uint32_t is ostensibly okay. My change is arguably a better, more general API for this sort of thing. It's also what bit me when gerrit/jenkins validation failed due to glusterfs segv-ing. (I didn't pay close enough attention to the implementation of the weak checksum. But it forced me to learn what gerrit/jenkins are doing and going forward I can do better testing before submitting to gerrit.) Now resubmitting with a BZ Change-Id: I545fade1604e74fc68399894550229bd57a5e0df BUG: 807718 Signed-off-by: Kaleb KEITHLEY <kkeithle@redhat.com> Reviewed-on: http://review.gluster.com/3019 Tested-by: Gluster Build System <jenkins@build.gluster.com> Reviewed-by: Jeff Darcy <jdarcy@redhat.com>
Diffstat (limited to 'libglusterfs')
-rw-r--r--libglusterfs/src/Makefile.am7
-rw-r--r--libglusterfs/src/call-stub.c4
-rw-r--r--libglusterfs/src/checksum.c34
-rw-r--r--libglusterfs/src/checksum.h6
-rw-r--r--libglusterfs/src/common-utils.c14
-rw-r--r--libglusterfs/src/common-utils.h2
6 files changed, 24 insertions, 43 deletions
diff --git a/libglusterfs/src/Makefile.am b/libglusterfs/src/Makefile.am
index c7f3d9ba70b..2dab8735c96 100644
--- a/libglusterfs/src/Makefile.am
+++ b/libglusterfs/src/Makefile.am
@@ -4,8 +4,7 @@ libglusterfs_la_CFLAGS = -fPIC -Wall -g -shared -nostartfiles $(GF_CFLAGS) \
libglusterfs_la_CPPFLAGS = -D_FILE_OFFSET_BITS=64 -D__USE_FILE_OFFSET64 \
-D_GNU_SOURCE -DXLATORDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/xlator\" \
-D$(GF_HOST_OS) -I$(CONTRIBDIR)/rbtree \
- -DSCHEDULERDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/scheduler\" \
- -I$(CONTRIBDIR)/md5
+ -DSCHEDULERDIR=\"$(libdir)/glusterfs/$(PACKAGE_VERSION)/scheduler\"
libglusterfs_la_LIBADD = @LEXLIB@
@@ -17,7 +16,7 @@ libglusterfs_la_SOURCES = dict.c xlator.c logging.c \
hashfn.c defaults.c common-utils.c timer.c inode.c call-stub.c \
compat.c fd.c compat-errno.c event.c mem-pool.c gf-dirent.c syscall.c \
iobuf.c globals.c statedump.c stack.c checksum.c daemon.c \
- $(CONTRIBDIR)/md5/md5.c $(CONTRIBDIR)/rbtree/rb.c rbthash.c latency.c \
+ $(CONTRIBDIR)/rbtree/rb.c rbthash.c latency.c \
graph.c $(CONTRIBDIR)/uuid/clear.c $(CONTRIBDIR)/uuid/copy.c \
$(CONTRIBDIR)/uuid/gen_uuid.c $(CONTRIBDIR)/uuid/pack.c \
$(CONTRIBDIR)/uuid/parse.c $(CONTRIBDIR)/uuid/unparse.c \
@@ -33,7 +32,7 @@ noinst_HEADERS = common-utils.h defaults.h dict.h glusterfs.h hashfn.h \
logging.h xlator.h stack.h timer.h list.h inode.h call-stub.h compat.h \
fd.h revision.h compat-errno.h event.h mem-pool.h byte-order.h \
gf-dirent.h locking.h syscall.h iobuf.h globals.h statedump.h \
- checksum.h daemon.h $(CONTRIBDIR)/md5/md5.h $(CONTRIBDIR)/rbtree/rb.h \
+ checksum.h daemon.h $(CONTRIBDIR)/rbtree/rb.h \
rbthash.h iatt.h latency.h mem-types.h $(CONTRIBDIR)/uuid/uuidd.h \
$(CONTRIBDIR)/uuid/uuid.h $(CONTRIBDIR)/uuid/uuidP.h \
$(CONTRIB_BUILDDIR)/uuid/uuid_types.h syncop.h graph-utils.h trie.h run.h \
diff --git a/libglusterfs/src/call-stub.c b/libglusterfs/src/call-stub.c
index 01e919d6943..308a9ad1fc1 100644
--- a/libglusterfs/src/call-stub.c
+++ b/libglusterfs/src/call-stub.c
@@ -22,9 +22,9 @@
#include "config.h"
#endif
+#include <openssl/md5.h>
#include <inttypes.h>
-#include "md5.h"
#include "call-stub.h"
#include "mem-types.h"
@@ -2124,7 +2124,7 @@ fop_rchecksum_cbk_stub (call_frame_t *frame,
weak_checksum;
stub->args.rchecksum_cbk.strong_checksum =
- memdup (strong_checksum, MD5_DIGEST_LEN);
+ memdup (strong_checksum, MD5_DIGEST_LENGTH);
}
if (xdata)
stub->xdata = dict_ref (xdata);
diff --git a/libglusterfs/src/checksum.c b/libglusterfs/src/checksum.c
index cea782293bd..7575b2f15b1 100644
--- a/libglusterfs/src/checksum.c
+++ b/libglusterfs/src/checksum.c
@@ -17,12 +17,10 @@
<http://www.gnu.org/licenses/>.
*/
-#include <inttypes.h>
+#include <openssl/md5.h>
+#include <stdint.h>
#include "glusterfs.h"
-#include "md5.h"
-#include "checksum.h"
-
/*
* The "weak" checksum required for the rsync algorithm,
@@ -31,22 +29,26 @@
*
* "a simple 32 bit checksum that can be upadted from either end
* (inspired by Mark Adler's Adler-32 checksum)"
+ *
+ * Note: these functions are only called to compute checksums on
+ * pathnames; they don't need to handle arbitrarily long strings of
+ * data. Thus int32_t and uint32_t are sufficient
*/
uint32_t
-gf_rsync_weak_checksum (char *buf1, int32_t len)
+gf_rsync_weak_checksum (unsigned char *buf, size_t len)
{
- int32_t i;
+ int32_t i = 0;
uint32_t s1, s2;
- signed char *buf = (signed char *) buf1;
uint32_t csum;
s1 = s2 = 0;
- for (i = 0; i < (len-4); i+=4) {
- s2 += 4*(s1 + buf[i]) + 3*buf[i+1] + 2*buf[i+2] + buf[i+3];
-
- s1 += buf[i+0] + buf[i+1] + buf[i+2] + buf[i+3];
+ if (len >= 4) {
+ for (; i < (len-4); i+=4) {
+ s2 += 4*(s1 + buf[i]) + 3*buf[i+1] + 2*buf[i+2] + buf[i+3];
+ s1 += buf[i+0] + buf[i+1] + buf[i+2] + buf[i+3];
+ }
}
for (; i < len; i++) {
@@ -66,13 +68,7 @@ gf_rsync_weak_checksum (char *buf1, int32_t len)
*/
void
-gf_rsync_strong_checksum (char *buf, int32_t len, uint8_t *sum)
+gf_rsync_strong_checksum (unsigned char *data, size_t len, unsigned char *md5)
{
- md_context m;
-
- md5_begin (&m);
- md5_update (&m, (unsigned char *) buf, len);
- md5_result (&m, (unsigned char *) sum);
-
- return;
+ MD5(data, len, md5);
}
diff --git a/libglusterfs/src/checksum.h b/libglusterfs/src/checksum.h
index 3542036bffc..19221b92235 100644
--- a/libglusterfs/src/checksum.h
+++ b/libglusterfs/src/checksum.h
@@ -20,8 +20,10 @@
#ifndef __CHECKSUM_H__
#define __CHECKSUM_H__
-uint32_t gf_rsync_weak_checksum (char *buf, int32_t len);
+uint32_t
+gf_rsync_weak_checksum (unsigned char *buf, size_t len);
-void gf_rsync_strong_checksum (char *buf, int32_t len, uint8_t *sum);
+void
+gf_rsync_strong_checksum (unsigned char *buf, size_t len, unsigned char *sum);
#endif /* __CHECKSUM_H__ */
diff --git a/libglusterfs/src/common-utils.c b/libglusterfs/src/common-utils.c
index f26d2bdc318..c5080246a2f 100644
--- a/libglusterfs/src/common-utils.c
+++ b/libglusterfs/src/common-utils.c
@@ -52,7 +52,6 @@
#include "glusterfs.h"
#include "stack.h"
#include "globals.h"
-#include "md5.h"
#include "lkowner.h"
#ifndef AI_ADDRCONFIG
@@ -1786,19 +1785,6 @@ lkowner_utoa_r (gf_lkowner_t *lkowner, char *dst, int len)
return dst;
}
-void _get_md5_str (char *out_str, size_t outlen,
- const uint8_t *input, int n)
-{
- uint8_t out[MD5_DIGEST_LEN] = {0};
- int j = 0;
-
- GF_ASSERT (outlen >= (2*MD5_DIGEST_LEN + 1));
- get_md5 (out, input, n);
- for (j = 0; j < MD5_DIGEST_LEN; j++)
- snprintf(out_str + j * 2, outlen-j*2, "%02x", out[j]);
-
-}
-
void* gf_array_elem (void *a, int index, size_t elem_size)
{
uint8_t* ptr = a;
diff --git a/libglusterfs/src/common-utils.h b/libglusterfs/src/common-utils.h
index 3aa0143d2ed..9d98975e14f 100644
--- a/libglusterfs/src/common-utils.h
+++ b/libglusterfs/src/common-utils.h
@@ -482,8 +482,6 @@ char *uuid_utoa_r (uuid_t uuid, char *dst);
char *lkowner_utoa (gf_lkowner_t *lkowner);
char *lkowner_utoa_r (gf_lkowner_t *lkowner, char *dst, int len);
-void _get_md5_str (char *out_str, size_t outlen,
- const uint8_t *input, int n);
void gf_array_insertionsort (void *a, int l, int r, size_t elem_size,
gf_cmp cmp);
int gf_is_str_int (const char *value);