Subversion Repositories mdb

Rev

Rev 14 | Rev 22 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 14 Rev 21
Line 26... Line 26...
26
#if defined(__APPLE__)
26
#if defined(__APPLE__)
27
#  define COMMON_DIGEST_FOR_OPENSSL
27
#  define COMMON_DIGEST_FOR_OPENSSL
28
#  include <CommonCrypto/CommonDigest.h>
28
#  include <CommonCrypto/CommonDigest.h>
29
#  define SHA1 CC_SHA1
29
#  define SHA1 CC_SHA1
30
#else
30
#else
31
#  include <openssl/md5.h>
31
#  include <openssl/ripemd.h>
32
#endif
32
#endif
33
 
33
 
34
 
34
 
35
iconv_t initialize (void);
35
iconv_t initialize (void);
36
char *conv2utf8 (iconv_t conv_desc, const char *euc);
36
char *conv2utf8 (iconv_t conv_desc, const char *euc);
Line 474... Line 474...
474
}
474
}
475
 
475
 
476
char *str2md5(const char *str, int length)
476
char *str2md5(const char *str, int length)
477
{
477
{
478
	int n;
478
	int n;
479
	MD5_CTX c;
479
	RIPEMD160_CTX c;
480
	unsigned char digest[16];
480
	unsigned char digest[16];
481
	char *out;
481
	char *out;
482
 
482
 
483
	if ((out = (char *)malloc(33)) == NULL)
483
	if ((out = (char *)malloc(33)) == NULL)
484
	{
484
	{
485
		syslog(LOG_DAEMON, "Error allocating 33 Bytes for MD5 calculation: %s", strerror(errno));
485
		syslog(LOG_DAEMON, "Error allocating 33 Bytes for MD5 calculation: %s", strerror(errno));
486
		return NULL;
486
		return NULL;
487
	}
487
	}
488
 
488
 
489
	memset(out, 0, 33);
489
	memset(out, 0, 33);
490
	MD5_Init(&c);
490
	RIPEMD160_Init(&c);
491
	
491
	
492
	while (length > 0)
492
	while (length > 0)
493
	{
493
	{
494
		if (length > 512)
494
		if (length > 512)
495
			MD5_Update(&c, str, 512);
495
			RIPEMD160_Update(&c, str, 512);
496
		else
496
		else
497
			MD5_Update(&c, str, length);
497
			RIPEMD160_Update(&c, str, length);
498
 
498
 
499
		length -= 512;
499
		length -= 512;
500
		str += 512;
500
		str += 512;
501
	}
501
	}
502
	
502
	
503
	MD5_Final(digest, &c);
503
	RIPEMD160_Final(digest, &c);
504
	
504
	
505
	for (n = 0; n < 16; ++n)
505
	for (n = 0; n < 16; ++n)
506
		snprintf(&(out[n*2]), 16*2, "%02x", (unsigned int)digest[n]);
506
		snprintf(&(out[n*2]), 16*2, "%02x", (unsigned int)digest[n]);
507
	
507
	
508
	return out;
508
	return out;