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.
This commit is contained in:
Thomas Haller 2018-08-31 10:59:31 +02:00
parent 858d5c3e91
commit 08c80dd2e3
4 changed files with 16 additions and 31 deletions

View file

@ -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

View file

@ -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)

View file

@ -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;

View file

@ -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;