summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-05-10 08:03:54 +0200
committerThomas Haller <thaller@redhat.com>2019-05-12 09:56:36 +0200
commit8ed23cb9874f25ad048ce359d1102c8f487915ec (patch)
tree854ec963e25bf83f717a7d8e12264c01cdb4b7d0
parente4ac1c7df015f38cc22a5be3f1accb11b277ff5a (diff)
downloadNetworkManager-th/authchain-cleanup.tar.gz
shared: use union instead of _nm_alignas() for static hash-seedth/authchain-cleanup
We want the the hash-seed array is alined so it can be used both as guint, guint32, and guint64 directly. Don't use _nm_alignas() but instead just add the fields to the union so we get proper alignment. While at at, also let the seed argument to c_siphash_init() be aligned to 64 integers. c_siphash_init() does not require that, but it tries to read the seed as (unaligned) LE 64 bit integers. So, it doesn't hurt.
-rw-r--r--shared/nm-glib-aux/nm-hash-utils.c16
-rw-r--r--shared/nm-glib-aux/nm-hash-utils.h2
2 files changed, 12 insertions, 6 deletions
diff --git a/shared/nm-glib-aux/nm-hash-utils.c b/shared/nm-glib-aux/nm-hash-utils.c
index 6e728e6b20..3ab39db712 100644
--- a/shared/nm-glib-aux/nm-hash-utils.c
+++ b/shared/nm-glib-aux/nm-hash-utils.c
@@ -45,7 +45,10 @@ _get_hash_key_init (void)
* to use it as guint* or guint64* pointer. */
static union {
guint8 v8[HASH_KEY_SIZE];
- } g_arr _nm_alignas (guint64);
+ guint _align_as_uint;
+ guint32 _align_as_uint32;
+ guint64 _align_as_uint64;
+ } g_arr;
const guint8 *g;
union {
guint8 v8[HASH_KEY_SIZE];
@@ -125,14 +128,17 @@ void
nm_hash_siphash42_init (CSipHash *h, guint static_seed)
{
const guint8 *g;
- guint seed[HASH_KEY_SIZE_GUINT];
+ union {
+ guint64 _align_as_uint64;
+ guint arr[HASH_KEY_SIZE_GUINT];
+ } seed;
nm_assert (h);
g = _get_hash_key ();
- memcpy (seed, g, HASH_KEY_SIZE);
- seed[0] ^= static_seed;
- c_siphash_init (h, (const guint8 *) seed);
+ memcpy (&seed, g, HASH_KEY_SIZE);
+ seed.arr[0] ^= static_seed;
+ c_siphash_init (h, (const guint8 *) &seed);
}
guint
diff --git a/shared/nm-glib-aux/nm-hash-utils.h b/shared/nm-glib-aux/nm-hash-utils.h
index af115a7c67..07518868cf 100644
--- a/shared/nm-glib-aux/nm-hash-utils.h
+++ b/shared/nm-glib-aux/nm-hash-utils.h
@@ -34,7 +34,7 @@ void nm_hash_siphash42_init (CSipHash *h, guint static_seed);
*
* Note, that this is guaranteed to use siphash42 under the hood (contrary to
* all other NMHash API, which leave this undefined). That matters at the point,
- * where the caller needs to be sure that a reasonably strong hasing algorithm
+ * where the caller needs to be sure that a reasonably strong hashing algorithm
* is used. (Yes, NMHash is all about siphash24, but otherwise that is not promised
* anywhere).
*