IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Mar 19, 2007, 3:13:54 PM (19 years ago)
Author:
Paul Price
Message:

Pulling out openssl/crypto dependency (we've had SO much trouble getting it to behave with us) in favour of libmd5-rfc. I put the source code (from sourceforge.net/projects/libmd5-rfc/) directly into the tree, because the original distribution doesn't build a library, and we don't want the user to have to go and grab it. The license (zlib/libpng) is compatible with the GPL, so no problems there. Changed the source code a little bit so that it behaves a little bit better with 32/64 bit issues ('unsigned int' --> 'uint32_t'), and got it to use the autoconf WORDS_BIGENDIAN flag.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/math/psMD5.c

    r12430 r12502  
    66#include <string.h>
    77
    8 #ifdef HAVE_SYS_MD5_H
    9 // Seems to be the case for Solaris
    10 #include <sys/md5.h>
    11 #else
    12 // Seems to be the case for most others
    13 #include <openssl/md5.h>
    14 #endif // HAVE_SYS_MD5_H
    15 
     8#include "md5.h"
    169
    1710#include "psAssert.h"
     
    2417
    2518
     19#define MD5_DIGEST_LENGTH 16            // Length of an MD5 digest, in bytes
     20
    2621psVector *psStringMD5(const char *string)
    2722{
    2823    psVector *hash = psVectorAlloc(MD5_DIGEST_LENGTH, PS_TYPE_U8); // The resultant MD5 hash
    29     if (!MD5((const unsigned char *)string, strlen(string), &hash->data.U8[0])) {
    30         psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to generate md5 hash.\n");
    31         psFree(hash);
    32         return NULL;
    33     }
     24    md5_state_t buffer;                 // Calculation buffer
     25    md5_init(&buffer);
     26    md5_append(&buffer, (psU8*)string, strlen(string));
     27    md5_finish(&buffer, &hash->data.U8[0]);
    3428    return hash;
    3529}
     
    4034
    4135    psVector *hash = psVectorAlloc(MD5_DIGEST_LENGTH, PS_TYPE_U8); // The resultant MD5 hash
    42     if (!MD5(vector->data.U8, vector->n * PSELEMTYPE_SIZEOF(vector->type.type), &hash->data.U8[0])) {
    43         psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to generate md5 hash.\n");
    44         psFree(hash);
    45         return NULL;
    46     }
     36    md5_state_t buffer;                 // Calculation buffer
     37    md5_init(&buffer);
     38    md5_append(&buffer, vector->data.U8, vector->n * PSELEMTYPE_SIZEOF(vector->type.type));
     39    md5_finish(&buffer, &hash->data.U8[0]);
    4740    return hash;
    4841}
     
    5447
    5548    psVector *hash = psVectorAlloc(MD5_DIGEST_LENGTH, PS_TYPE_U8); // The resultant MD5 hash
     49    md5_state_t buffer;                 // Calculation buffer
     50    md5_init(&buffer);
    5651    if (!image->parent) {
    5752        // No parent means image is contiguous
    58         if (!MD5(&image->data.U8[0][0], image->numCols * image->numRows * PSELEMTYPE_SIZEOF(image->type.type),
    59                  &hash->data.U8[0])) {
    60             psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to generate md5 hash.\n");
    61             psFree(hash);
    62             return NULL;
     53        md5_append(&buffer, image->data.U8[0],
     54                   image->numCols * image->numRows * PSELEMTYPE_SIZEOF(image->type.type));
     55    } else {
     56        for (int row = 0; row < image->numRows; row++) {
     57            md5_append(&buffer, image->data.U8[row],
     58                       image->numCols * PSELEMTYPE_SIZEOF(image->type.type));
    6359        }
    64     } else {
    65         MD5_CTX ctx;                    // MD5 calculator
    66         MD5_Init(&ctx);
    67         for (int row = 0; row < image->numRows; row++) {
    68             MD5_Update(&ctx, image->data.U8[row], image->numCols * PSELEMTYPE_SIZEOF(image->type.type));
    69         }
    70         MD5_Final(&hash->data.U8[0], &ctx);
    7160    }
     61    md5_finish(&buffer, &hash->data.U8[0]);
    7262
    7363    return hash;
Note: See TracChangeset for help on using the changeset viewer.