diff options
author | Thomas Haller <thaller@redhat.com> | 2018-08-31 10:59:31 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-09-04 07:38:30 +0200 |
commit | 08c80dd2e32d4b50786c8c8fd5308e513c1bc90d (patch) | |
tree | 06a762143a05fc5adf2d3fbe77a28400e95a73d9 | |
parent | 858d5c3e917a60f076c80873149a911c0dc2f497 (diff) | |
download | NetworkManager-08c80dd2e32d4b50786c8c8fd5308e513c1bc90d.tar.gz |
libnm/crypto: rework endianness detection for crypto_verify_pkcs12()
At other places, we already use __BYTE_ORDER define to detect endianness.
We don't need multiple mechanisms.
Also note that meson did not do the correct thing as AC_C_BIGENDIAN,
so meson + nss + big-endian was possibly broken.
-rw-r--r-- | config.h.meson | 12 | ||||
-rw-r--r-- | configure.ac | 5 | ||||
-rw-r--r-- | libnm-core/nm-crypto-nss.c | 15 | ||||
-rw-r--r-- | libnm-util/crypto_nss.c | 15 |
4 files changed, 16 insertions, 31 deletions
diff --git a/config.h.meson b/config.h.meson index c5fbf5fab3..ce77952bec 100644 --- a/config.h.meson +++ b/config.h.meson @@ -226,18 +226,6 @@ /* Define if you have iwd support */ #mesondefine WITH_IWD -/* Define WORDS_BIGENDIAN to 1 if your processor stores words with the most - significant byte first (like Motorola and SPARC, unlike Intel). */ -#if defined AC_APPLE_UNIVERSAL_BUILD -# if defined __BIG_ENDIAN__ -# define WORDS_BIGENDIAN 1 -# endif -#else -# ifndef WORDS_BIGENDIAN -/* # undef WORDS_BIGENDIAN */ -# endif -#endif - /* Define to 1 if on MINIX. */ #mesondefine _MINIX diff --git a/configure.ac b/configure.ac index 62c7e0392e..c104c9b930 100644 --- a/configure.ac +++ b/configure.ac @@ -109,11 +109,6 @@ GETTEXT_PACKAGE=NetworkManager AC_SUBST(GETTEXT_PACKAGE) AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [Gettext package]) -dnl -dnl Make sha1.c happy on big endian systems -dnl -AC_C_BIGENDIAN - # Add runstatedir if not specified manually in autoconf < 2.70 AS_IF([test -z "$runstatedir"], runstatedir="$localstatedir/run") AC_SUBST(runstatedir) diff --git a/libnm-core/nm-crypto-nss.c b/libnm-core/nm-crypto-nss.c index 1260b3b45f..feb081e621 100644 --- a/libnm-core/nm-crypto-nss.c +++ b/libnm-core/nm-crypto-nss.c @@ -414,9 +414,6 @@ _nm_crypto_verify_pkcs12 (const guint8 *data, SECStatus s; gunichar2 *ucs2_password; long ucs2_chars = 0; -#ifndef WORDS_BIGENDIAN - guint16 *p; -#endif /* WORDS_BIGENDIAN */ if (error) g_return_val_if_fail (*error == NULL, FALSE); @@ -446,10 +443,14 @@ _nm_crypto_verify_pkcs12 (const guint8 *data, nm_explicit_bzero (ucs2_password, ucs2_chars); g_free (ucs2_password); -#ifndef WORDS_BIGENDIAN - for (p = (guint16 *) pw.data; p < (guint16 *) (pw.data + pw.len); p++) - *p = GUINT16_SWAP_LE_BE (*p); -#endif /* WORDS_BIGENDIAN */ +#if __BYTE_ORDER == __LITTLE_ENDIAN + { + guint16 *p; + + for (p = (guint16 *) pw.data; p < (guint16 *) (pw.data + pw.len); p++) + *p = GUINT16_SWAP_LE_BE (*p); + } +#endif } else { /* NULL password */ pw.data = NULL; diff --git a/libnm-util/crypto_nss.c b/libnm-util/crypto_nss.c index 5736db4f89..01bb28c33d 100644 --- a/libnm-util/crypto_nss.c +++ b/libnm-util/crypto_nss.c @@ -442,9 +442,6 @@ crypto_verify_pkcs12 (const GByteArray *data, SECStatus s; char *ucs2_password; long ucs2_chars = 0; -#ifndef WORDS_BIGENDIAN - guint16 *p; -#endif /* WORDS_BIGENDIAN */ if (error) g_return_val_if_fail (*error == NULL, FALSE); @@ -470,10 +467,14 @@ crypto_verify_pkcs12 (const GByteArray *data, memset (ucs2_password, 0, ucs2_chars); g_free (ucs2_password); -#ifndef WORDS_BIGENDIAN - for (p = (guint16 *) pw.data; p < (guint16 *) (pw.data + pw.len); p++) - *p = GUINT16_SWAP_LE_BE (*p); -#endif /* WORDS_BIGENDIAN */ +#if __BYTE_ORDER == __LITTLE_ENDIAN + { + guint16 *p; + + for (p = (guint16 *) pw.data; p < (guint16 *) (pw.data + pw.len); p++) + *p = GUINT16_SWAP_LE_BE (*p); + } +#endif } else { /* NULL password */ pw.data = NULL; |