Browse code

updated version providing better performance on x86-64

git-svn: trunk@2559

Tomasz Kojm authored on 2006/12/16 08:55:25
Showing 3 changed files
... ...
@@ -1,3 +1,8 @@
1
+Sat Dec 16 00:47:04 CET 2006 (tk)
2
+---------------------------------
3
+  * libclamav/md5.c: updated version providing better performance on x86-64
4
+		     Thanks to Solar Designer
5
+
1 6
 Fri Dec 15 22:38:41 CET 2006 (tk)
2 7
 ---------------------------------
3 8
   * libclamav/mspack: remove files
... ...
@@ -1,6 +1,6 @@
1 1
 /*
2 2
  * This is an OpenSSL-compatible implementation of the RSA Data Security,
3
- * Inc. MD5 Message-Digest Algorithm.
3
+ * Inc. MD5 Message-Digest Algorithm (RFC 1321).
4 4
  *
5 5
  * Written by Solar Designer <solar at openwall.com> in 2001, and placed
6 6
  * in the public domain.  There's absolutely no warranty.
... ...
@@ -15,18 +15,16 @@
15 15
  * and avoid compile-time configuration.
16 16
  */
17 17
 
18
-#if HAVE_CONFIG_H
19
-#include "clamav-config.h"
20
-#endif
21
-
22 18
 #include <string.h>
19
+
23 20
 #include "md5.h"
24 21
 
25 22
 /*
26 23
  * The basic MD5 functions.
27 24
  *
28
- * F is optimized compared to its RFC 1321 definition just like in Colin
29
- * Plumb's implementation.
25
+ * F and G are optimized compared to their RFC 1321 definitions for
26
+ * architectures that lack an AND-NOT instruction, just like in Colin Plumb's
27
+ * implementation.
30 28
  */
31 29
 #define F(x, y, z)			((z) ^ ((x) & ((y) ^ (z))))
32 30
 #define G(x, y, z)			((y) ^ ((z) & ((x) ^ (y))))
... ...
@@ -45,11 +43,11 @@
45 45
  * SET reads 4 input bytes in little-endian byte order and stores them
46 46
  * in a properly aligned word in host byte order.
47 47
  *
48
- * The check for little-endian architectures which tolerate unaligned
48
+ * The check for little-endian architectures that tolerate unaligned
49 49
  * memory accesses is just an optimization.  Nothing will break if it
50 50
  * doesn't work.
51 51
  */
52
-#if defined(__i386__) || defined(__vax__)
52
+#if defined(__i386__) || defined(__x86_64__) || defined(__vax__)
53 53
 #define SET(n) \
54 54
 	(*(MD5_u32plus *)&ptr[(n) * 4])
55 55
 #define GET(n) \
... ...
@@ -67,7 +65,7 @@
67 67
 
68 68
 /*
69 69
  * This processes one or more 64-byte data blocks, but does NOT update
70
- * the bit counters.  There're no alignment requirements.
70
+ * the bit counters.  There are no alignment requirements.
71 71
  */
72 72
 static void *body(MD5_CTX *ctx, void *data, unsigned long size)
73 73
 {
... ...
@@ -1,16 +1,18 @@
1 1
 /*
2 2
  * This is an OpenSSL-compatible implementation of the RSA Data Security,
3
- * Inc. MD5 Message-Digest Algorithm.
3
+ * Inc. MD5 Message-Digest Algorithm (RFC 1321).
4 4
  *
5 5
  * Written by Solar Designer <solar at openwall.com> in 2001, and placed
6
- * in the public domain.  See md5.c for more information.
6
+ * in the public domain.  There's absolutely no warranty.
7
+ *
8
+ * See md5.c for more information.
7 9
  */
8 10
 
9 11
 #ifndef __MD5_H
10 12
 #define __MD5_H
11 13
 
12 14
 /* Any 32-bit or wider unsigned integer data type will do */
13
-typedef unsigned long MD5_u32plus;
15
+typedef unsigned int MD5_u32plus;
14 16
 
15 17
 typedef struct {
16 18
 	MD5_u32plus lo, hi;