dovecot-2.2: Added guid_128_host_hash_get().
dovecot at dovecot.org
dovecot at dovecot.org
Mon Feb 18 08:46:15 EET 2013
details: http://hg.dovecot.org/dovecot-2.2/rev/80344aedd8fd
changeset: 15830:80344aedd8fd
user: Timo Sirainen <tss at iki.fi>
date: Mon Feb 18 08:45:54 2013 +0200
description:
Added guid_128_host_hash_get().
diffstat:
src/lib/guid.c | 21 ++++++++++++++-------
src/lib/guid.h | 6 ++++++
2 files changed, 20 insertions(+), 7 deletions(-)
diffs (68 lines):
diff -r a6b40687c0a4 -r 80344aedd8fd src/lib/guid.c
--- a/src/lib/guid.c Mon Feb 18 07:20:03 2013 +0200
+++ b/src/lib/guid.c Mon Feb 18 08:45:54 2013 +0200
@@ -34,12 +34,23 @@
pid, my_hostname);
}
+void guid_128_host_hash_get(const char *host,
+ unsigned char hash_r[GUID_128_HOST_HASH_SIZE])
+{
+ unsigned char full_hash[SHA1_RESULTLEN];
+
+ sha1_get_digest(host, strlen(host), full_hash);
+ memcpy(hash_r, full_hash + sizeof(full_hash)-GUID_128_HOST_HASH_SIZE,
+ GUID_128_HOST_HASH_SIZE);
+}
+
void guid_128_generate(guid_128_t guid_r)
{
+#if GUID_128_HOST_HASH_SIZE != 4
+# error GUID_128_HOST_HASH_SIZE must be 4
+#endif
static struct timespec ts = { 0, 0 };
static uint8_t guid_static[8];
- unsigned char hostdomain_hash[SHA1_RESULTLEN];
- const char *hostdomain;
uint32_t pid;
/* we'll use the current time in nanoseconds as the initial 64bit
@@ -48,16 +59,12 @@
if (clock_gettime(CLOCK_REALTIME, &ts) < 0)
i_fatal("clock_gettime() failed: %m");
pid = getpid();
- 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;
- memcpy(guid_static+4,
- hostdomain_hash+sizeof(hostdomain_hash)-4, 4);
+ guid_128_host_hash_get(my_hostdomain(), guid_static+4);
} else if ((uint32_t)ts.tv_nsec < (uint32_t)-1) {
ts.tv_nsec++;
} else {
diff -r a6b40687c0a4 -r 80344aedd8fd src/lib/guid.h
--- a/src/lib/guid.h Mon Feb 18 07:20:03 2013 +0200
+++ b/src/lib/guid.h Mon Feb 18 08:45:54 2013 +0200
@@ -4,6 +4,8 @@
#define GUID_128_SIZE 16
typedef uint8_t guid_128_t[GUID_128_SIZE];
+#define GUID_128_HOST_HASH_SIZE 4
+
/* Generate a GUID (contains host name) */
const char *guid_generate(void);
/* Generate 128 bit GUID */
@@ -20,4 +22,8 @@
unsigned int guid_128_hash(const uint8_t *guid);
int guid_128_cmp(const uint8_t *guid1, const uint8_t *guid2);
+/* Return the hash of host used by guid_128_generate(). */
+void guid_128_host_hash_get(const char *host,
+ unsigned char hash_r[GUID_128_HOST_HASH_SIZE]);
+
#endif
More information about the dovecot-cvs
mailing list