Subversion Repositories mdb

Rev

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

Rev 21 Rev 22
Line 20... Line 20...
20
#include <syslog.h>
20
#include <syslog.h>
21
#include <errno.h>
21
#include <errno.h>
22
#include <ctype.h>
22
#include <ctype.h>
23
#include <iconv.h>
23
#include <iconv.h>
24
#include "helplib.h"
24
#include "helplib.h"
25
 
-
 
26
#if defined(__APPLE__)
-
 
27
#  define COMMON_DIGEST_FOR_OPENSSL
-
 
28
#  include <CommonCrypto/CommonDigest.h>
-
 
29
#  define SHA1 CC_SHA1
-
 
30
#else
-
 
31
#  include <openssl/ripemd.h>
25
#include "lookup3.h"
32
#endif
-
 
33
 
-
 
34
 
26
 
35
iconv_t initialize (void);
27
iconv_t initialize (void);
36
char *conv2utf8 (iconv_t conv_desc, const char *euc);
28
char *conv2utf8 (iconv_t conv_desc, const char *euc);
37
void finalize (iconv_t conv_desc);
29
void finalize (iconv_t conv_desc);
38
 
30
 
Line 471... Line 463...
471
	
463
	
472
	/* Truncated division is intentional */
464
	/* Truncated division is intentional */
473
	return x / bin_size;
465
	return x / bin_size;
474
}
466
}
475
 
467
 
476
char *str2md5(const char *str, int length)
468
char *str2hash(const char *str, int length)
477
{
469
{
478
	int n;
470
	uint32_t a, b;
479
	RIPEMD160_CTX c;
-
 
480
	unsigned char digest[16];
471
	char *out, digest1[9], digest2[9];
481
	char *out;
-
 
482
 
472
 
483
	if ((out = (char *)malloc(33)) == NULL)
473
	if ((out = (char *)malloc(17)) == NULL)
484
	{
474
	{
485
		syslog(LOG_DAEMON, "Error allocating 33 Bytes for MD5 calculation: %s", strerror(errno));
475
		syslog(LOG_DAEMON, "Error allocating 33 Bytes for MD5 calculation: %s", strerror(errno));
486
		return NULL;
476
		return NULL;
487
	}
477
	}
488
 
478
 
489
	memset(out, 0, 33);
479
	memset(out, 0, 17);
490
	RIPEMD160_Init(&c);
480
	a = 0x2e96a73d; b = 0x130f36db;			/* Individual seeds to be able to reproduse the hashes */
491
	
-
 
492
	while (length > 0)
481
	hashlittle2(str, length, &a, &b);
493
	{
-
 
494
		if (length > 512)
-
 
495
			RIPEMD160_Update(&c, str, 512);
482
	sprintf(out, "%.8lx%.8lx", a, b);
496
		else
-
 
497
			RIPEMD160_Update(&c, str, length);
-
 
498
 
483
 
499
		length -= 512;
-
 
500
		str += 512;
-
 
501
	}
-
 
502
	
-
 
503
	RIPEMD160_Final(digest, &c);
-
 
504
	
-
 
505
	for (n = 0; n < 16; ++n)
-
 
506
		snprintf(&(out[n*2]), 16*2, "%02x", (unsigned int)digest[n]);
-
 
507
	
-
 
508
	return out;
484
	return out;
509
}
485
}