Index: trunk/psLib/src/math/psMD5.c
===================================================================
--- trunk/psLib/src/math/psMD5.c	(revision 12430)
+++ trunk/psLib/src/math/psMD5.c	(revision 12502)
@@ -6,12 +6,5 @@
 #include <string.h>
 
-#ifdef HAVE_SYS_MD5_H
-// Seems to be the case for Solaris
-#include <sys/md5.h>
-#else
-// Seems to be the case for most others
-#include <openssl/md5.h>
-#endif // HAVE_SYS_MD5_H
-
+#include "md5.h"
 
 #include "psAssert.h"
@@ -24,12 +17,13 @@
 
 
+#define MD5_DIGEST_LENGTH 16            // Length of an MD5 digest, in bytes
+
 psVector *psStringMD5(const char *string)
 {
     psVector *hash = psVectorAlloc(MD5_DIGEST_LENGTH, PS_TYPE_U8); // The resultant MD5 hash
-    if (!MD5((const unsigned char *)string, strlen(string), &hash->data.U8[0])) {
-        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to generate md5 hash.\n");
-        psFree(hash);
-        return NULL;
-    }
+    md5_state_t buffer;                 // Calculation buffer
+    md5_init(&buffer);
+    md5_append(&buffer, (psU8*)string, strlen(string));
+    md5_finish(&buffer, &hash->data.U8[0]);
     return hash;
 }
@@ -40,9 +34,8 @@
 
     psVector *hash = psVectorAlloc(MD5_DIGEST_LENGTH, PS_TYPE_U8); // The resultant MD5 hash
-    if (!MD5(vector->data.U8, vector->n * PSELEMTYPE_SIZEOF(vector->type.type), &hash->data.U8[0])) {
-        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to generate md5 hash.\n");
-        psFree(hash);
-        return NULL;
-    }
+    md5_state_t buffer;                 // Calculation buffer
+    md5_init(&buffer);
+    md5_append(&buffer, vector->data.U8, vector->n * PSELEMTYPE_SIZEOF(vector->type.type));
+    md5_finish(&buffer, &hash->data.U8[0]);
     return hash;
 }
@@ -54,20 +47,17 @@
 
     psVector *hash = psVectorAlloc(MD5_DIGEST_LENGTH, PS_TYPE_U8); // The resultant MD5 hash
+    md5_state_t buffer;                 // Calculation buffer
+    md5_init(&buffer);
     if (!image->parent) {
         // No parent means image is contiguous
-        if (!MD5(&image->data.U8[0][0], image->numCols * image->numRows * PSELEMTYPE_SIZEOF(image->type.type),
-                 &hash->data.U8[0])) {
-            psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to generate md5 hash.\n");
-            psFree(hash);
-            return NULL;
+        md5_append(&buffer, image->data.U8[0],
+                   image->numCols * image->numRows * PSELEMTYPE_SIZEOF(image->type.type));
+    } else {
+        for (int row = 0; row < image->numRows; row++) {
+            md5_append(&buffer, image->data.U8[row],
+                       image->numCols * PSELEMTYPE_SIZEOF(image->type.type));
         }
-    } else {
-        MD5_CTX ctx;                    // MD5 calculator
-        MD5_Init(&ctx);
-        for (int row = 0; row < image->numRows; row++) {
-            MD5_Update(&ctx, image->data.U8[row], image->numCols * PSELEMTYPE_SIZEOF(image->type.type));
-        }
-        MD5_Final(&hash->data.U8[0], &ctx);
     }
+    md5_finish(&buffer, &hash->data.U8[0]);
 
     return hash;
