about summary refs log tree commit diff
path: root/src/libnm-glib-aux/nm-hash-utils.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/libnm-glib-aux/nm-hash-utils.c')
-rw-r--r--src/libnm-glib-aux/nm-hash-utils.c42
1 files changed, 29 insertions, 13 deletions
diff --git a/src/libnm-glib-aux/nm-hash-utils.c b/src/libnm-glib-aux/nm-hash-utils.c
index a6949ebd..68b33998 100644
--- a/src/libnm-glib-aux/nm-hash-utils.c
+++ b/src/libnm-glib-aux/nm-hash-utils.c
@@ -139,12 +139,6 @@ nm_hash_str(const char *str)
 }
 
 guint
-nm_str_hash(gconstpointer str)
-{
-    return nm_hash_str(str);
-}
-
-guint
 nm_hash_ptr(gconstpointer ptr)
 {
     NMHashState h;
@@ -156,12 +150,6 @@ nm_hash_ptr(gconstpointer ptr)
     return nm_hash_complete(&h);
 }
 
-guint
-nm_direct_hash(gconstpointer ptr)
-{
-    return nm_hash_ptr(ptr);
-}
-
 /*****************************************************************************/
 
 guint
@@ -257,7 +245,7 @@ nm_ppdirect_equal(gconstpointer a, gconstpointer b)
 guint
 nm_g_bytes_hash(gconstpointer p)
 {
-    GBytes *      ptr = (GBytes *) p;
+    GBytes       *ptr = (GBytes *) p;
     gconstpointer arr;
     gsize         len;
 
@@ -284,3 +272,31 @@ nm_pg_bytes_equal(gconstpointer a, gconstpointer b)
 
     return g_bytes_equal(*ptr_a, *ptr_b);
 }
+
+/*****************************************************************************/
+
+guint64
+nm_hash_obfuscate_ptr(guint static_seed, gconstpointer val)
+{
+    NMHashState h;
+
+    if (NM_MORE_ASSERTS > 0) {
+        static int obfuscate_static = -1;
+        int        obfuscate;
+
+again:
+        obfuscate = g_atomic_int_get(&obfuscate_static);
+        if (G_UNLIKELY(obfuscate == -1)) {
+            obfuscate = _nm_utils_ascii_str_to_int64(g_getenv("NM_OBFUSCATE_PTR"), 10, 0, 1, 1);
+            if (!g_atomic_int_compare_and_exchange(&obfuscate_static, -1, obfuscate))
+                goto again;
+        }
+
+        if (!obfuscate)
+            return (uintptr_t) val;
+    }
+
+    nm_hash_init(&h, static_seed);
+    nm_hash_update_val(&h, val);
+    return nm_hash_complete_u64(&h);
+}