dovecot-2.1: guid_128_generate(): Use 32bit sha1(host at domain) in...
dovecot at dovecot.org
dovecot at dovecot.org
Wed Feb 1 18:56:02 EET 2012
details: http://hg.dovecot.org/dovecot-2.1/rev/acc60bd684fb
changeset: 14036:acc60bd684fb
user: Timo Sirainen <tss at iki.fi>
date: Wed Feb 01 18:55:54 2012 +0200
description:
guid_128_generate(): Use 32bit sha1(host at domain) instead of crc32(hostname)
diffstat:
src/lib/guid.c | 16 +++++++++-------
1 files changed, 9 insertions(+), 7 deletions(-)
diffs (45 lines):
diff -r 8be75a2ea2dd -r acc60bd684fb src/lib/guid.c
--- a/src/lib/guid.c Mon Jan 30 20:09:04 2012 +0200
+++ b/src/lib/guid.c Wed Feb 01 18:55:54 2012 +0200
@@ -2,7 +2,7 @@
#include "lib.h"
#include "buffer.h"
-#include "crc32.h"
+#include "sha1.h"
#include "hash.h"
#include "hex-binary.h"
#include "hostpid.h"
@@ -38,7 +38,9 @@
{
static struct timespec ts = { 0, 0 };
static uint8_t guid_static[8];
- uint32_t pid, host_crc;
+ unsigned char hostdomain_hash[SHA1_RESULTLEN];
+ const char *hostdomain;
+ uint32_t pid;
/* we'll use the current time in nanoseconds as the initial 64bit
counter. */
@@ -46,16 +48,16 @@
if (clock_gettime(CLOCK_REALTIME, &ts) < 0)
i_fatal("clock_gettime() failed: %m");
pid = getpid();
- host_crc = crc32_str(my_hostname);
+ hostdomain = my_hostdomain();
+ sha1_get_digest(hostdomain, strlen(hostdomain),
+ hostdomain_hash);
guid_static[0] = (pid & 0x000000ff);
guid_static[1] = (pid & 0x0000ff00) >> 8;
guid_static[2] = (pid & 0x00ff0000) >> 16;
guid_static[3] = (pid & 0xff000000) >> 24;
- guid_static[4] = (host_crc & 0x000000ff);
- guid_static[5] = (host_crc & 0x0000ff00) >> 8;
- guid_static[6] = (host_crc & 0x00ff0000) >> 16;
- guid_static[7] = (host_crc & 0xff000000) >> 24;
+ memcpy(guid_static+4,
+ hostdomain_hash+sizeof(hostdomain_hash)-4, 4);
} else if ((uint32_t)ts.tv_nsec < (uint32_t)-1) {
ts.tv_nsec++;
} else {
More information about the dovecot-cvs
mailing list